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

비밀번호

댓글 작성자
 




... 106  107  108  109  110  111  112  113  114  115  116  117  [118]  119  120  ...
NoWriterDateCnt.TitleFile(s)
11092정성태11/3/201638752.NET Framework: 618. C# - NAudio를 이용한 MP3 파일 재생 [5]파일 다운로드1
11091정성태11/3/201630820VC++: 104. std::call_once를 이용해 thread-safe한 Singleton 객체 생성파일 다운로드1
11090정성태11/1/201632475VC++: 103. C++ CreateTimerQueue, CreateTimerQueueTimer 예제 코드 [9]파일 다운로드1
11089정성태11/1/201633390디버깅 기술: 82. Windows 10을 위한 Symbol(PDB) 파일 내려받는 방법 [2]
11088정성태11/1/201634990.NET Framework: 617. C# - AForge.NET을 이용한 MP4 동영상 파일 재생 [7]파일 다운로드1
11087정성태11/1/201629685.NET Framework: 616. AForge.Video.FFMPEG를 최신 버전의 ffmpeg 파일로 의존성을 변경하는 방법파일 다운로드1
11086정성태11/1/201624387오류 유형: 366. The Microsoft Passport Container service terminated with the following error: General access denied error
11085정성태10/27/201639893.NET Framework: 615. C# - AForge.NET을 이용한 웹캠 영상 출력 [2]파일 다운로드1
11084정성태10/26/201627143오류 유형: 365. The User Profile Service service failed to the sign-in.
11083정성태10/26/201633969Windows: 131. 윈도우 10에서 사라진 "Adapters and Bindings" 네트워크 우선 순위 조정 기능 [1]
11082정성태10/26/201637386.NET Framework: 614. C# - DateTime.Ticks의 정밀도 [4]파일 다운로드1
11081정성태10/26/201626064오류 유형: 364. You need to fix your Microsoft Account for apps on your other devices to be able to launch apps and continue experiences on this device.
11080정성태10/24/201630723Windows: 130. Windows Server 2016 Nano 서버 설치 방법
11079정성태10/21/201627440Windows: 129. Windows Server 2016 설치 CD에 있는 Convert-WindowsImage.ps1 사용 방법 정리
11078정성태10/21/201628471Windows: 128. Windows Server 2016 Nano 서버 VHD 이미지 만드는 방법 - TP5 기준
11077정성태10/21/201625466오류 유형: 363. Active Directory 서버의 NETLOGON 서비스가 멈췄을 때 발생하는 문제
11076정성태10/21/201626741오류 유형: 362. 윈도우 백업 시 오류 - 0x80780040
11075정성태10/20/201626410Windows: 127. Convert-WindowsImage.ps1 사용 방법 정리
11074정성태10/20/201635729Windows: 126. Windows Server 2016 평가판을 정식 버전으로 라이선스 변경하는 방법
11073정성태10/20/201632263.NET Framework: 613. 윈도우 데스크톱 응용 프로그램(예: Console)에서 알림 메시지(Toast notifications) 띄우기 [1]파일 다운로드1
11072정성태10/20/201629234VC++: 102. 새로 추가한 ATL COM 객체가 regsvr32.exe로 등록이 안 되는 문제
11071정성태10/20/201632158.NET Framework: 612. UWP(유니버설 윈도우 플랫폼) 앱에서 콜백 함수 내에서의 UI 요소 접근 방법 [1]
11070정성태10/20/201625381Windows: 125. 윈도우 서버 2016 마이그레이션
11069정성태10/19/201633506.NET Framework: 611. C++ 개발자들을 위한 C# Thread 동작 방식 [2]
11068정성태10/19/201635927Windows: 124. 윈도우 운영체제의 시간 함수 (5) - TSC(Time Stamp Counter)와 QueryPerformanceCounter [12]파일 다운로드1
11067정성태10/18/201631089Windows: 123. 윈도우 운영체제의 시간 함수 (4) - RTC, TSC, PM Clock, HPET Timer [2]
... 106  107  108  109  110  111  112  113  114  115  116  117  [118]  119  120  ...