Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (seongtaejeong at gmail.com)
홈페이지
첨부 파일
 

WinDbg - 덤프 분석 중인 닷넷 어셈블리가 Debug 빌드인지, Release 빌드인지 알아내는 방법

혹시, WinDbg에서도 분석 중인 모듈의 빌드 상태를 알아낼 수 있을까요?

해당 어셈블리가 Debug 빌드인지, Release 빌드인지 알아내는 방법
; https://www.sysnet.pe.kr/2/0/1227

일단, lm 명령어로는 딱히 나오는 것이 없습니다.

0:000> lmDvmConsoleApp1
Browse full module list
start             end                 module name
000001c2`6e4e0000 000001c2`6e4e8000   ConsoleApp1   (deferred)             
    Image path: c:\temp\builds\ConsoleApp1\AnyCPU\Debug\ConsoleApp1.dll
    Image name: ConsoleApp1.dll
    Browse all global symbols  functions  data  Symbol Reload
    Using CLR debugging support for all symbols
    Has CLR image header, track-debug-data flag not set
    Image was built with /Brepro flag.
    Timestamp:        A845CF62 (This is a reproducible build file hash, not a timestamp)
    CheckSum:         00000000
    ImageSize:        00008000
    Mapping Form:     Loaded
    File version:     1.0.0.0
    Product version:  1.0.0.0
    File flags:       0 (Mask 3F)
    File OS:          4 Unknown Win32
    File type:        1.0 App
    File date:        00000000.00000000
    Translations:     0000.04b0
    Information from resource tables:
        CompanyName:      ConsoleApp1
        ProductName:      ConsoleApp1
        InternalName:     ConsoleApp1.dll
        OriginalFilename: ConsoleApp1.dll
        ProductVersion:   1.0.0
        FileVersion:      1.0.0.0
        FileDescription:  ConsoleApp1
        LegalCopyright:    

중간에 "track-debug-data flag not set"이라는 문구가 있는데, Debug/Release 모두 동일한 문자열이 나왔습니다. 이제 남은 것은 sos 확장 명령어인데요, 그나마 쓸모 있는 정보가 DumpModule의 TransientFlags로 나오는 듯합니다.

// Debug 빌드인 경우

0:000> !DumpModule /d 00007ffe2c7b7770
Name: c:\temp\builds\ConsoleApp1\AnyCPU\Debug\ConsoleApp1.dll
Attributes:              PEFile 
TransientFlags:          00209019 IS_EDIT_AND_CONTINUE
Assembly:                000001c26cb3d3c0
BaseAddress:             000001C26E4E0000
LoaderHeap:              0000000000000000
TypeDefToMethodTableMap: 00007FFE2C7A2240
TypeRefToMethodTableMap: 00007FFE2C7A2270
MethodDefToDescMap:      00007FFE2C7A2358
FieldDefToDescMap:       00007FFE2C7A23B0
MemberRefToDescMap:      0000000000000000
FileReferencesMap:       00007FFE2C7A23D8
AssemblyReferencesMap:   00007FFE2C7A23E0
MetaData start address:  000001C26E4E21BC (2664 bytes)

// Release 빌드인 경우

0:000> !DumpModule /d 00007ffe2c7f7778
Name: c:\temp\builds\ConsoleApp1\AnyCPU\Release\ConsoleApp1.dll
Attributes:              PEFile 
TransientFlags:          00208811 
Assembly:                00000227fc48bca0
BaseAddress:             00000227FDF50000
LoaderHeap:              0000000000000000
TypeDefToMethodTableMap: 00007FFE2C7E2240
TypeRefToMethodTableMap: 00007FFE2C7E2270
MethodDefToDescMap:      00007FFE2C7E2348
FieldDefToDescMap:       00007FFE2C7E23A0
MemberRefToDescMap:      0000000000000000
FileReferencesMap:       00007FFE2C7E23C8
AssemblyReferencesMap:   00007FFE2C7E23D0
MetaData start address:  00000227FDF5219C (2572 bytes)

위의 경우, "IS_EDIT_AND_CONTINUE"는 Visual Studio에서 "Edit and Continue" 옵션을 켠 경우에 나타난 것입니다. 그게 꺼져 있다면 출력은 이런 식으로 바뀝니다. (각자의 빌드 옵션에 따라 다릅니다.)

// ("Enable Hot Reload" 옵션을 끈) Debug 빌드인 경우

0:007> !DumpModule /d 00007ffe2c7d7770
Name: c:\temp\builds\ConsoleApp1\AnyCPU\Debug\ConsoleApp1.dll
Attributes:              PEFile 
TransientFlags:          00209011 
Assembly:                000001b13553ac80
BaseAddress:             000001B137040000
LoaderHeap:              0000000000000000
TypeDefToMethodTableMap: 00007FFE2C7C2240
TypeRefToMethodTableMap: 00007FFE2C7C2270
MethodDefToDescMap:      00007FFE2C7C2370
FieldDefToDescMap:       00007FFE2C7C23C8
MemberRefToDescMap:      0000000000000000
FileReferencesMap:       00007FFE2C7C23F0
AssemblyReferencesMap:   00007FFE2C7C23F8
MetaData start address:  000001B1370421D4 (2792 bytes)

그렇다면, 관련해서 TransientFlags 내부에 디버그 빌드에 준하는 정보가 남아 있지 않을까요? ^^ 이를 알아 보기 위해 sos 소스 코드에서 다음과 같은 enum 정보를 찾았는데요,

src/SOS/Strike/strike.cpp
; https://github.com/dotnet/diagnostics/blob/ea6796b6d0556f8ab3c01d0c0d8f234fdfdf1d73/src/SOS/Strike/strike.cpp#L3918

enum {
    // These are the values set in m_dwTransientFlags.
    // Note that none of these flags survive a prejit save/restore.

    MODULE_IS_TENURED           = 0x00000001,   // Set once we know for sure the Module will not be freed until the appdomain itself exits
    // unused                   = 0x00000002,
    CLASSES_FREED               = 0x00000004,
    IS_EDIT_AND_CONTINUE        = 0x00000008,   // is EnC Enabled for this module

    IS_PROFILER_NOTIFIED        = 0x00000010,
    IS_ETW_NOTIFIED             = 0x00000020,

    //
    // Note: the order of these must match the order defined in
    // cordbpriv.h for DebuggerAssemblyControlFlags. The three
    // values below should match the values defined in
    // DebuggerAssemblyControlFlags when shifted right
    // DEBUGGER_INFO_SHIFT bits.
    //
    DEBUGGER_USER_OVERRIDE_PRIV = 0x00000400,
    DEBUGGER_ALLOW_JIT_OPTS_PRIV= 0x00000800,
    DEBUGGER_TRACK_JIT_INFO_PRIV= 0x00001000,
    DEBUGGER_ENC_ENABLED_PRIV   = 0x00002000,   // this is what was attempted to be set.  IS_EDIT_AND_CONTINUE is actual result.
    DEBUGGER_PDBS_COPIED        = 0x00004000,
    DEBUGGER_IGNORE_PDBS        = 0x00008000,
    DEBUGGER_INFO_MASK_PRIV     = 0x0000Fc00,
    DEBUGGER_INFO_SHIFT_PRIV    = 10,

    // Used to indicate that this module has had it's IJW fixups properly installed.
    IS_IJW_FIXED_UP             = 0x00080000,
    IS_BEING_UNLOADED           = 0x00100000,

    // Used to indicate that the module is loaded sufficiently for generic candidate instantiations to work
    MODULE_READY_FOR_TYPELOAD  = 0x00200000,

    // Used during NGen only
    TYPESPECS_TRIAGED           = 0x40000000,
    MODULE_SAVED                = 0x80000000,
};

이에 비춰서 TransientFlags 값을 분석하면 각각 다음과 같이 펼쳐집니다.

// Debug 빌드인 경우

TransientFlags:          00209019
    - MODULE_READY_FOR_TYPELOAD
    - DEBUGGER_IGNORE_PDBS
    - DEBUGGER_TRACK_JIT_INFO_PRIV
    - IS_PROFILER_NOTIFIED
    - IS_EDIT_AND_CONTINUE
    - MODULE_IS_TENURED

// Release 빌드인 경우

TransientFlags:          00208811 
    - MODULE_READY_FOR_TYPELOAD
    - DEBUGGER_IGNORE_PDBS
    - DEBUGGER_ALLOW_JIT_OPTS_PRIV
    - IS_PROFILER_NOTIFIED
    - MODULE_IS_TENURED

// ("Enable Hot Reload" 옵션을 끈) Debug 빌드인 경우

TransientFlags:          00209011 
    - MODULE_READY_FOR_TYPELOAD
    - DEBUGGER_IGNORE_PDBS
    - DEBUGGER_TRACK_JIT_INFO_PRIV
    - IS_PROFILER_NOTIFIED
    - MODULE_IS_TENURED

확신할 수는 없지만, 그냥 저 결과만 보면 DEBUGGER_TRACK_JIT_INFO_PRIV 옵션 유무로 Debug 빌드를 느슨하게 판정할 수는 있을 듯합니다.

참고로, 위의 방법 이외에도 그냥 대상 .NET Assembly를 파일로 덤프시킨 다음,

windbg - 풀 덤프 파일로부터 .NET DLL을 추출/저장하는 방법
; https://www.sysnet.pe.kr/2/0/10943

거기서 Debuggable 특성의 값을 확인하는 것도 고려할 수 있을 것입니다.




유의해야 할 점은, Debug 빌드는 다양한 옵션의 조합이기 때문에 어떤 특정 옵션만을 가지고 Debug 빌드라고 단정할 수는 없습니다. "해당 어셈블리가 Debug 빌드인지, Release 빌드인지 알아내는 방법" 글에서도, DisableOptimizations, EnableEditAndContinue, Default 옵션이 Debuggable 특성에 있는 정도로 판정하는 수준에 불과합니다.




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







[최초 등록일: ]
[최종 수정일: 11/10/2025]

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

비밀번호

댓글 작성자
 




1  2  3  4  5  6  7  8  9  10  11  12  13  [14]  15  ...
NoWriterDateCnt.TitleFile(s)
13716정성태8/21/202412216C/C++: 167. Visual C++ - 윈도우 환경에서 _execv 동작 [1]
13715정성태8/19/202414836Linux: 78. 리눅스 C/C++ - 특정 버전의 glibc 빌드 (docker-glibc-builder)
13714정성태8/19/202412369닷넷: 2295. C# 12 - 기본 생성자(Primary constructors) (책 오타 수정) [3]
13713정성태8/16/202415299개발 환경 구성: 721. WSL 2에서의 Hyper-V Socket 연동
13712정성태8/14/202413190개발 환경 구성: 720. Synology NAS - docker 원격 제어를 위한 TCP 바인딩 추가
13711정성태8/13/202414305Linux: 77. C# / Linux - zombie process (defunct process) [1]파일 다운로드1
13710정성태8/8/202415499닷넷: 2294. C# 13 - (6) iterator 또는 비동기 메서드에서 ref와 unsafe 사용을 부분적으로 허용파일 다운로드1
13709정성태8/7/202413228닷넷: 2293. C# - safe/unsafe 문맥에 대한 C# 13의 (하위 호환을 깨는) 변화파일 다운로드1
13708정성태8/7/202414140개발 환경 구성: 719. ffmpeg / YoutubeExplode - mp4 동영상 파일로부터 Audio 파일 추출
13707정성태8/6/202413711닷넷: 2292. C# - 자식 프로세스의 출력이 4,096보다 많은 경우 Process.WaitForExit 호출 시 hang 현상파일 다운로드1
13706정성태8/5/202412945개발 환경 구성: 718. Hyper-V - 리눅스 VM에 새로운 디스크 추가
13705정성태8/4/202413538닷넷: 2291. C# 13 - (5) params 인자 타입으로 컬렉션 허용 [2]파일 다운로드1
13704정성태8/2/202414976닷넷: 2290. C# - 간이 dotnet-dump 프로그램 만들기파일 다운로드1
13703정성태8/1/202413435닷넷: 2289. "dotnet-dump ps" 명령어가 닷넷 프로세스를 찾는 방법
13702정성태7/31/202414667닷넷: 2288. Collection 식을 지원하는 사용자 정의 타입을 CollectionBuilder 특성으로 성능 보완파일 다운로드1
13701정성태7/30/202416138닷넷: 2287. C# 13 - (4) Indexer를 이용한 개체 초기화 구문에서 System.Index 연산자 허용파일 다운로드1
13700정성태7/29/202415315디버깅 기술: 200. DLL Export/Import의 Hint 의미
13699정성태7/27/202416082닷넷: 2286. C# 13 - (3) Monitor를 대체할 Lock 타입파일 다운로드1
13698정성태7/27/202414681닷넷: 2285. C# - async 메서드에서의 System.Threading.Lock 잠금 처리파일 다운로드1
13697정성태7/26/202413145닷넷: 2284. C# - async 메서드에서의 lock/Monitor.Enter/Exit 잠금 처리파일 다운로드1
13696정성태7/26/202413871오류 유형: 920. dotnet publish - error NETSDK1047: Assets file '...\obj\project.assets.json' doesn't have a target for '...'
13695정성태7/25/202413480닷넷: 2283. C# - Lock / Wait 상태에서도 STA COM 메서드 호출 처리파일 다운로드1
13694정성태7/25/202413363닷넷: 2282. C# - ASP.NET Core Web App의 Request 용량 상한값 (Kestrel, IIS)
13693정성태7/24/202413053개발 환경 구성: 717. Visual Studio - C# 프로젝트에서 레지스트리에 등록하지 않은 COM 개체 참조 및 사용 방법파일 다운로드1
13692정성태7/24/202415051디버깅 기술: 199. Windbg - 리눅스에서 뜬 닷넷 응용 프로그램 덤프 파일에 포함된 DLL의 Export Directory 탐색
13691정성태7/23/202413897디버깅 기술: 198. Windbg - 스레드의 Win32 Message Queue 정보 조회
1  2  3  4  5  6  7  8  9  10  11  12  13  [14]  15  ...