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)
13916정성태4/23/20256740디버깅 기술: 221. WinDbg 분석 사례 - ASP.NET HttpCookieCollection을 다중 스레드에서 사용할 경우 무한 루프 현상 - 두 번째 이야기
13915정성태4/13/20258303닷넷: 2331. C# - 실행 시에 메서드 가로채기 (.NET 9)파일 다운로드1
13914정성태4/11/20258496디버깅 기술: 220. windbg 분석 사례 - x86 ASP.NET 웹 응용 프로그램의 CPU 100% 현상 (4)
13913정성태4/10/20256762오류 유형: 950. Process Explorer - 64비트 윈도우에서 32비트 프로세스의 덤프를 뜰 때 "Error writing dump file: Access is denied." 오류
13912정성태4/9/20256178닷넷: 2330. C# - 실행 시에 메서드 가로채기 (.NET 5 ~ .NET 8)파일 다운로드1
13911정성태4/8/20257309오류 유형: 949. WinDbg - .NET Core/5+ 응용 프로그램 디버깅 시 sos 확장을 자동으로 로드하지 못하는 문제
13910정성태4/8/20256553디버깅 기술: 219. WinDbg - 명령어 내에서 환경 변수 사용법
13909정성태4/7/20259045닷넷: 2329. C# - 실행 시에 메서드 가로채기 (.NET Framework 4.8)파일 다운로드1
13908정성태4/2/20259546닷넷: 2328. C# - MailKit: SMTP, POP3, IMAP 지원 라이브러리
13907정성태3/29/20259911VS.NET IDE: 198. (OneDrive, Dropbox 등의 공유 디렉터리에 있는) C# 프로젝트의 출력 경로 변경하기
13906정성태3/27/20259253닷넷: 2327. C# - 초기화되지 않은 메모리에 접근하는 버그?파일 다운로드1
13905정성태3/26/20259462Windows: 281. C++ - Windows / Critical Section의 안정화를 위해 도입된 "Keyed Event"파일 다운로드1
13904정성태3/25/20258784디버깅 기술: 218. Windbg로 살펴보는 Win32 Critical Section파일 다운로드1
13903정성태3/24/20258781VS.NET IDE: 197. (OneDrive, Dropbox 등의 공유 디렉터리에 있는) C++ 프로젝트의 출력 경로 변경하기
13902정성태3/24/20258474개발 환경 구성: 742. Oracle - 테스트용 hr 계정 및 데이터 생성파일 다운로드1
13901정성태3/9/20258796Windows: 280. Hyper-V의 3가지 Thread Scheduler (Classic, Core, Root)
13900정성태3/8/202510957스크립트: 72. 파이썬 - SQLAlchemy + oracledb 연동
13899정성태3/7/20257521스크립트: 71. 파이썬 - asyncio의 ContextVar 전달
13898정성태3/5/20258009오류 유형: 948. Visual Studio - Proxy Authentication Required: dotnetfeed.blob.core.windows.net
13897정성태3/5/20259949닷넷: 2326. C# - PowerShell과 연동하는 방법 (두 번째 이야기)파일 다운로드1
13896정성태3/5/20259982Windows: 279. Hyper-V Manager - VM 목록의 CPU Usage 항목이 항상 0%로 나오는 문제
13895정성태3/4/20259669Linux: 117. eBPF (bpf2go) - Map에 추가된 요소의 개수를 확인하는 방법
13894정성태2/28/20258602Linux: 116. eBPF (bpf2go) - BTF Style Maps 정의 구문과 데이터 정렬 문제
13893정성태2/27/20257862Linux: 115. eBPF (bpf2go) - ARRAY / HASH map 기본 사용법
13892정성태2/24/202511201닷넷: 2325. C# - PowerShell과 연동하는 방법파일 다운로드1
13891정성태2/23/20258556닷넷: 2324. C# - 프로세스의 성능 카운터용 인스턴스 이름을 구하는 방법파일 다운로드1
1  2  3  4  5  [6]  7  8  9  10  11  12  13  14  15  ...