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

비밀번호

댓글 작성자
 




... 31  32  33  34  35  36  [37]  38  39  40  41  42  43  44  45  ...
NoWriterDateCnt.TitleFile(s)
13135정성태10/5/202222844.NET Framework: 2053. 리눅스 환경의 .NET Core 3/5+ 메모리 덤프를 분석하는 방법 - 두 번째 이야기 [1]
13134정성태10/4/202217270오류 유형: 820. There is a problem with AMD Radeon RX 5600 XT device. For more information, search for 'graphics device driver error code 31'
13133정성태10/4/202220400Windows: 211. Windows - (commit이 아닌) reserved 메모리 사용량 확인 방법 [1]
13132정성태10/3/202219490스크립트: 42. 파이썬 - latexify-py 패키지 소개 - 함수를 mathjax 식으로 표현
13131정성태10/3/202224322.NET Framework: 2052. C# - Windows Forms의 데이터 바인딩 지원(DataBinding, DataSource) [2]파일 다운로드1
13130정성태9/28/202220331.NET Framework: 2051. .NET Core/5+ - 에러 로깅을 위한 Middleware가 동작하지 않는 경우파일 다운로드1
13129정성태9/27/202220766.NET Framework: 2050. .NET Core를 IIS에서 호스팅하는 경우 .NET Framework CLR이 함께 로드되는 환경
13128정성태9/23/202224357C/C++: 158. Visual C++ - IDL 구문 중 "unsigned long"을 인식하지 못하는 #import [1]파일 다운로드1
13127정성태9/22/202221574Windows: 210. WSL에 systemd 도입
13126정성태9/15/202221908.NET Framework: 2049. C# 11 - 정적 메서드에 대한 delegate 처리 시 cache 적용
13125정성태9/14/202222354.NET Framework: 2048. C# 11 - 구조체 필드의 자동 초기화(auto-default structs)
13124정성태9/13/202222749.NET Framework: 2047. Golang, Python, C#에서의 CRC32 사용
13123정성태9/8/202222812.NET Framework: 2046. C# 11 - 멤버(속성/필드)에 지정할 수 있는 required 예약어 추가
13122정성태8/26/202223915.NET Framework: 2045. C# 11 - 메서드 매개 변수에 대한 nameof 지원
13121정성태8/23/202217713C/C++: 157. Golang - 구조체의 slice 필드를 Reflection을 이용해 변경하는 방법
13120정성태8/19/202223171Windows: 209. Windows NT Service에서 UI를 다루는 방법 [3]
13119정성태8/18/202223207.NET Framework: 2044. .NET Core/5+ 프로젝트에서 참조 DLL이 보관된 공통 디렉터리를 지정하는 방법
13118정성태8/18/202218618.NET Framework: 2043. WPF Color의 기본 색 영역은 (sRGB가 아닌) scRGB [2]
13117정성태8/17/202223313.NET Framework: 2042. C# 11 - 파일 범위 내에서 유효한 타입 정의 (File-local types)파일 다운로드1
13116정성태8/4/202223506.NET Framework: 2041. C# - Socket.Close 시 Socket.Receive 메서드에서 예외가 발생하는 문제파일 다운로드1
13115정성태8/3/202224502.NET Framework: 2040. C# - ValueTask와 Task의 성능 비교 [1]파일 다운로드1
13114정성태8/2/202225029.NET Framework: 2039. C# - Task와 비교해 본 ValueTask 사용법파일 다운로드1
13113정성태7/31/202224287.NET Framework: 2038. C# 11 - Span 타입에 대한 패턴 매칭 (Pattern matching on ReadOnlySpan<char>)
13112정성태7/30/202226207.NET Framework: 2037. C# 11 - 목록 패턴(List patterns) [1]파일 다운로드1
13111정성태7/29/202225739.NET Framework: 2036. C# 11 - IntPtr/UIntPtr과 nint/nuint의 통합파일 다운로드1
13110정성태7/27/202223217.NET Framework: 2035. C# 11 - 새로운 연산자 ">>>" (Unsigned Right Shift)파일 다운로드1
... 31  32  33  34  35  36  [37]  38  39  40  41  42  43  44  45  ...