Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 3개 있습니다.)
(시리즈 글이 15개 있습니다.)
디버깅 기술: 22. VS.NET SP1 + .NET Framework 소스 코드 디버깅
; https://www.sysnet.pe.kr/2/0/623

개발 환경 구성: 112. Visual Studio 2010 - .NET Framework 소스 코드 디버깅
; https://www.sysnet.pe.kr/2/0/1009

디버깅 기술: 47. .NET Reflector를 이용한 "소스 코드가 없는" 어셈블리 디버깅
; https://www.sysnet.pe.kr/2/0/1201

개발 환경 구성: 143. Visual Studio 2010 - .NET Framework 소스 코드 디버깅 - 두 번째 이야기
; https://www.sysnet.pe.kr/2/0/1243

개발 환경 구성: 297. 소스 코드가 없는 닷넷 어셈블리를 디버깅할 때 지역 변숫값을 확인하는 방법
; https://www.sysnet.pe.kr/2/0/11036

개발 환경 구성: 391. (GitHub 등과 직접 연동해) 소스 코드 디버깅을 쉽게 해 주는 SourceLink
; https://www.sysnet.pe.kr/2/0/11630

VS.NET IDE: 126. 디컴파일된 소스에 탐색을 사용하도록 설정(Enable navigation to decompiled sources)
; https://www.sysnet.pe.kr/2/0/11689

VS.NET IDE: 145. NuGet + Github 라이브러리 디버깅 관련 옵션 3가지 - "Enable Just My Code" / "Enable Source Link support" / "Suppress JIT optimization on module load (Managed only)"
; https://www.sysnet.pe.kr/2/0/12200

VS.NET IDE: 149. ("Binary was not built with debug information" 상태로) 소스 코드 디버깅이 안되는 경우
; https://www.sysnet.pe.kr/2/0/12278

개발 환경 구성: 500. (PDB 연결이 없는) DLL의 소스 코드 디버깅을 dotPeek 도구로 해결하는 방법
; https://www.sysnet.pe.kr/2/0/12281

VS.NET IDE: 153. 닷넷 응용 프로그램에서의 "My Code" 범위와 "Enable Just My Code"의 역할
; https://www.sysnet.pe.kr/2/0/12401

VS.NET IDE: 170. Visual Studio에서 .NET Core/5+ 역어셈블 소스코드 확인하는 방법
; https://www.sysnet.pe.kr/2/0/12880

VS.NET IDE: 177. 비주얼 스튜디오 2022를 이용한 (소스 코드가 없는) 닷넷 모듈 디버깅 - "외부 원본(External Sources)"
; https://www.sysnet.pe.kr/2/0/13109

VS.NET IDE: 180. Visual Studio - 닷넷 소스 코드 디버깅 중 "Decompile source code"가 동작하는 않는 문제
; https://www.sysnet.pe.kr/2/0/13247

VS.NET IDE: 189. Visual Studio - 닷넷 소스코드 디컴파일 찾기가 안 될 때
; https://www.sysnet.pe.kr/2/0/13554




닷넷 응용 프로그램에서의 "My Code" 범위와 "Enable Just My Code"의 역할

예전에 "Enable Just My Code" 옵션을 설명한 적이 있는데,

NuGet + Github 라이브러리 디버깅 관련 옵션 3가지 - "Enable Just My Code" / "Enable Source Link support" / "Suppress JIT optimization on module load (Managed only)"
; https://www.sysnet.pe.kr/2/0/12200#enable_just_my_code

enable_just_my_code_1.png

도대체 여기서 언급하는 "My Code"의 범위가 어떻게 될까요? 이에 대해서는 다음의 문서에서 밝히고 있습니다.

Debug only user code with Just My Code
; https://learn.microsoft.com/en-us/visualstudio/debugger/just-my-code

In .NET projects, Just My Code uses symbol (.pdb) files and program optimizations to classify user and non-user code. The .NET debugger considers optimized binaries and non-loaded .pdb files to be non-user code.


그 대상이 최적화된 바이너리이고 pdb 파일이 없다면 "My Code"가 아니라고 판단한다고 되어 있는데, 실제로 해보면 pdb 파일의 유무로만 판단이 됩니다. 가령 디버그 모드로 빌드한 dll이어도 pdb 파일이 없으면 그것은 "My Code"로 분류하지 않고 그 반대로 릴리스 모드로 빌드했어도 pdb 파일만 있다면 "My Code"로 분류됩니다.




그렇다면, My Code가 어떤 의미가 있을까요?

우선, 디버거 입장에서 "My Code"냐 아니냐에 따라, 즉 PDB 파일의 유무에 따라 해당 DLL에 구현된 코드로 Step-into를 이용해 진입하려는 시도를 결정하게 됩니다. 그러니까, pdb 파일이 있는 dll의 메서드에 대해 step-into를 시도하면 소스 코드를 로드하거나, 소스 코드가 없으면 decompile 옵션을 보여주고 사용자가 선택했을 때 진입하게 됩니다.

그런데, 이 과정에서 "Enable Just My Code" 옵션은 아무런 의미가 없습니다. 그 옵션의 on/off에 상관없이 무조건 비주얼 스튜디오는 PDB 유무만 보고 step-into를 시도합니다. 이 옵션이 의미가 있는 경우는, "My Code"로 분류된 바이너리이지만 대상 메서드에 DebuggerNonUserCode 특성을 사용했을 때입니다. 가령 여러분이 다음과 같은 메서드를 현재 프로젝트에서 만들었을 때,

[DebuggerNonUserCode]
static void MyMethod()
{
    Console.WriteLine("do");
}

이 메서드를 호출하는 코드 "MyClass.MyMethod();"에서 F11 키를 눌러 step-into로 들어가려고 하면 "Enable Just My Code" 옵션이 on 일 때는 그냥 넘어가지만 off 일 때는 디버거가 진입을 하게 됩니다. (또한, "Enable Just My Code" 옵션이 on 일 때는 DebuggerNonUserCode 특성을 부여한 메서드의 경우 BP 설정도 안 됩니다.)

"Enable Just My Code" 옵션이 효력을 발휘하는 또 다른 경우는 "call stack"을 보여줄 때입니다. 해당 옵션이 꺼져(off) 있는 경우, 비주얼 스튜디오는 "My Code"가 아닌 메서드는 단순히 "[External Code]"로 보여줍니다.

callstack_external_code_1.png

하지만, 메뉴에서 제공하는 "Show External Code" 항목을 켜는 경우 "Enable Just My Code" 옵션은 이제 더 이상 아무런 의미가 없습니다. 즉, on/off에 상관없이 무조건 모든 콜 스택을 보여줍니다.




정리하면, 만약 DebuggerNonUserCode 특성을 사용하지 않고 (and) "Show External Code"를 언제나 켜고 사용하는 개발자라면, "Enable Just My Code" 옵션은 아무런 의미가 없고 오직 중요한 것은 PDB 파일의 유무라는 점입니다.




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 5/11/2023]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 



2022-07-14 08시56분
https://twitter.com/VS_Debugger/status/1547311810277085184?s=20&t=X_oplYBJHXUHqlew1IIxsQ

If you've ever needed to debug WPF or other NGEN/R2R images in VS, it's now even easier with our new option.

You can disable the load of NGEN/ R2R using the
settings under Tools >Options>Debugging >General> Prevent using precompiled images on module load
정성태

1  2  3  4  [5]  6  7  8  9  10  11  12  13  14  15  ...
NoWriterDateCnt.TitleFile(s)
13853정성태12/26/20244773디버깅 기술: 213. Windbg - swapgs 명령어와 (Ring 0 커널 모드의) FS, GS Segment 레지스터
13852정성태12/25/20245861디버깅 기술: 212. Windbg - (Ring 3 사용자 모드의) FS, GS Segment 레지스터파일 다운로드1
13851정성태12/23/20245074디버깅 기술: 211. Windbg - 커널 모드 디버깅 상태에서 사용자 프로그램을 디버깅하는 방법
13850정성태12/23/20246183오류 유형: 940. "Application Information" 서비스를 중지한 경우, "This file does not have an app associated with it for performing this action."
13849정성태12/20/20246180디버깅 기술: 210. Windbg - 논리(가상) 주소를 Segmentation을 거쳐 선형 주소로 변경
13848정성태12/18/20245675디버깅 기술: 209. Windbg로 알아보는 Prototype PTE파일 다운로드2
13847정성태12/18/20245753오류 유형: 939. golang - 빌드 시 "unknown directive: toolchain" 오류 빌드 시 이런 오류가 발생한다면?
13846정성태12/17/20246296디버깅 기술: 208. Windbg로 알아보는 Trans/Soft PTE와 2가지 Page Fault 유형파일 다운로드1
13845정성태12/16/20245139디버깅 기술: 207. Windbg로 알아보는 PTE (_MMPTE)
13844정성태12/14/20246622디버깅 기술: 206. Windbg로 알아보는 PFN (_MMPFN)파일 다운로드1
13843정성태12/13/20245164오류 유형: 938. Docker container 내에서 빌드 시 error MSB3021: Unable to copy file "..." to "...". Access to the path '...' is denied.
13842정성태12/12/20245341디버깅 기술: 205. Windbg - KPCR, KPRCB
13841정성태12/11/20245918오류 유형: 937. error MSB4044: The "ValidateValidArchitecture" task was not given a value for the required parameter "RemoteTarget"
13840정성태12/11/20245249오류 유형: 936. msbuild - Your project file doesn't list 'win' as a "RuntimeIdentifier"
13839정성태12/11/20246131오류 유형: 936. msbuild - error CS1617: Invalid option '12.0' for /langversion. Use '/langversion:?' to list supported values.
13838정성태12/4/20245914오류 유형: 935. Windbg - Breakpoint 0's offset expression evaluation failed.
13837정성태12/3/20246737디버깅 기술: 204. Windbg - 윈도우 핸들 테이블 (3) - Windows 10 이상인 경우
13836정성태12/3/20245284디버깅 기술: 203. Windbg - x64 가상 주소를 물리 주소로 변환 (페이지 크기가 2MB인 경우)
13835정성태12/2/20246686오류 유형: 934. Azure - rm: cannot remove '...': Directory not empty
13834정성태11/29/20246691Windows: 275. C# - CUI 애플리케이션과 Console 윈도우 (Windows 10 미만의 Classic Console 모드인 경우) [1]파일 다운로드1
13833정성태11/29/20246058개발 환경 구성: 737. Azure Web App에서 Scale-out으로 늘어난 리눅스 인스턴스에 SSH 접속하는 방법
13832정성태11/27/20245684Windows: 274. Windows 7부터 도입한 conhost.exe
13831정성태11/27/20245046Linux: 111. eBPF - BPF_MAP_TYPE_PERF_EVENT_ARRAY, BPF_MAP_TYPE_RINGBUF에 대한 다양한 용어들
13830정성태11/25/20246539개발 환경 구성: 736. 파이썬 웹 앱을 Azure App Service에 배포하기
13829정성태11/25/20246646스크립트: 67. 파이썬 - Windows 버전에서 함께 설치되는 py.exe
13828정성태11/25/20245176개발 환경 구성: 735. Azure - 압축 파일을 이용한 web app 배포 시 디렉터리 구분이 안 되는 문제파일 다운로드1
1  2  3  4  [5]  6  7  8  9  10  11  12  13  14  15  ...