Microsoft MVP성태의 닷넷 이야기
디버깅 기술: 67. windbg - 덤프 파일과 handle 정보 [링크 복사], [링크+제목 복사],
조회: 19154
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 1개 있습니다.)

windbg - 덤프 파일과 handle 정보

풀 덤프를 남길 때,

풀 덤프 파일을 남기는 방법
; https://www.sysnet.pe.kr/2/0/991

작업 관리자의 풀 덤프를 기능을 이용하는 경우, 핸들 정보가 보이질 않습니다.

Loading Dump File [C:\temp\test2.dmp]
User Mini Dump File with Full Memory: Only application data is available

Symbol search path is: SRV*e:\Symbols*http://msdl.microsoft.com/download/symbols
Executable search path is: 
Windows 8 Version 9200 MP (8 procs) Free x64
Product: WinNt, suite: SingleUserTS
Built by: 6.3.9600.17031 (winblue_gdr.140221-1952)
Machine Name:
Debug session time: Sat Jan  3 13:30:27.000 2015 (UTC + 9:00)
System Uptime: 10 days 20:59:12.564
Process Uptime: 0 days 1:22:47.000
.........................
Loading unloaded module list
...
This dump file has a breakpoint exception stored in it.
The stored exception information can be accessed via .ecxr.
ntdll!DbgBreakPoint:
00007ffa`cfb231a0 cc              int     3

0:004> !handle 20c f
ERROR: !handle: extension exception 0x80004002.
    "Unable to read handle information"

아마도, 작업 관리자의 경우 MiniDumpWriteDump 호출 시 MiniDumpWithHandleData 옵션은 추가하지 않는 것 같습니다. 그래서, 기왕이면 Process Explorer (또는, ProcDump)를 이용하는 것이 좋습니다. 그런 경우에는 이렇게 핸들 정보가 남습니다.

Loading Dump File [C:\temp\ConsoleApplication1.dmp]
User Mini Dump File with Full Memory: Only application data is available

...[생략]...

0:000> !handle
Handle 0000000000000004
  Type         	File
Handle 0000000000000008
  Type         	Directory
...[생략]...
  Type         	Event
Handle 0000000000000208
  Type         	Event
Handle 000000000000020c
  Type         	Event
129 Handles
Type                    	Count
None                    	25
Event                   	61
Section                 	2
File                    	7
Directory               	3
Mutant                  	5
WindowStation           	2
Key                     	8
Thread                  	5
Desktop                 	1
IoCompletion            	2
TpWorkerFactory         	2
ALPC Port               	1
WaitCompletionPacket    	5

그리고 개별 항목에 대해 상세하게 조회하는 것이 가능합니다.

0:000> !handle 000000000000020c 7
Handle 000000000000020c
  Type         	Event
  Attributes   	0
  GrantedAccess	0x1f0003:
         Delete,ReadControl,WriteDac,WriteOwner,Synch
         QueryState,ModifyState
  HandleCount  	2
  PointerCount 	65538
  Name         	<none>

닷넷 응용 프로그램의 경우 핸들 정보를 알려면 해당 객체에서 (대개) private 멤버로 보관하고 있는 handle 정보를 우선 알아야 합니다. 예를 들어 다음의 출력 결과에서,

0:000> !dso
OS Thread Id: 0x2d38 (0)
RSP/REG          Object           Name
000000000083E3F0 00000000026e2ef0 Microsoft.Win32.SafeHandles.SafeWaitHandle
000000000083E410 00000000026e2ef0 Microsoft.Win32.SafeHandles.SafeWaitHandle
000000000083E6A0 00000000026e2ef0 Microsoft.Win32.SafeHandles.SafeWaitHandle
000000000083E880 00000000026e2ef0 Microsoft.Win32.SafeHandles.SafeWaitHandle
000000000083E8C0 00000000026e2ea0 System.Threading.ManualResetEvent
000000000083E8E0 00000000026e2ea0 System.Threading.ManualResetEvent
000000000083E8E8 00000000026e2ea0 System.Threading.ManualResetEvent
000000000083E8F0 00000000026e2ea0 System.Threading.ManualResetEvent
000000000083E910 00000000026e2e80 System.Object[]    (System.String[])
000000000083EA48 00000000026e2e80 System.Object[]    (System.String[])
000000000083EB58 00000000026e2e80 System.Object[]    (System.String[])
000000000083ED28 00000000026e2e80 System.Object[]    (System.String[])
000000000083ED48 00000000026e2308 System.Security.Policy.Evidence
000000000083F2F8 00000000026e1440 System.SharedStatics

Microsoft.Win32.SafeHandles.SafeWaitHandle 인스턴스의 Object 주소(00000000026e2ef0)로 조회한 후,

0:000> !do 00000000026e2ef0 
Name:        Microsoft.Win32.SafeHandles.SafeWaitHandle
MethodTable: 00007ffac16e89c8
EEClass:     00007ffac1116d98
Size:        32(0x20) bytes
File:        C:\WINDOWS\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll
Fields:
              MT    Field   Offset                 Type VT     Attr            Value Name
00007ffac16d4848  4000612        8        System.IntPtr  1 instance              20c handle
00007ffac16d37c8  4000613       10         System.Int32  1 instance                8 _state
00007ffac16cf370  4000614       14       System.Boolean  1 instance                1 _ownsHandle
00007ffac16cf370  4000615       15       System.Boolean  1 instance                1 _fullyInitialized
00007ffac16cf370  4001a8b       16       System.Boolean  1 instance                0 bIsMutex
00007ffac16cf370  4001a8c       17       System.Boolean  1 instance                0 bIsReservedMutex

이렇게 handle 필드로 있는 20c 값이 프로세스의 핸들 테이블에 있는 정보입니다. 그래서 역시 이 값으로부터도 !handle 명령어를 통해 정보를 얻을 수 있습니다.

0:000> !handle 000000000000020c 7
Handle 000000000000020c
  Type         	Event
  Attributes   	0
  GrantedAccess	0x1f0003:
         Delete,ReadControl,WriteDac,WriteOwner,Synch
         QueryState,ModifyState
  HandleCount  	2
  PointerCount 	65538
  Name         	<none>

하지만 안타까운 점이 있다면, 객체 고유의 성격에 따른 정보는 구하질 못한다는 것입니다. 아래의 글에서도 설명하고 있지만,

Windows System Events + Windbg Debugging 
; http://samscode.blogspot.kr/2012/03/windows-system-events-windbg-debugging.html

Checking an Event's Signaled State in KM w/ WinDBG 
; http://samscode.blogspot.kr/2013/03/checking-events-signaled-state-in-km-w.html

가령, 위에서 예를 든 "!handle 000000000000020c 7" 출력의 경우 Event이지만 해당 이벤트가 Signaled 상태인지를 알 수 있는 방법이 없습니다. 왜냐하면 이 정보는 커널에 담겨 있기 때문에 EXE 프로세스의 핸들 테이블 정보만으로는 이를 구할 수 없기 때문입니다.

따라서, 거기까지 정보를 알아내려면 User-mode의 덤프가 아닌 Kernel-mode의 덤프가 필요합니다. (혹은, 라이브 디버깅을 해야 합니다. 라이브인 경우 API 호출로 알아내는 것도 가능합니다. "I have the handle to a file; how can I get the file name from the debugger?") 또한 usermode에서 그러니까, 가끔 블루스크린이 떴을 때 덤프 남긴다면서 퍼센트 올라가던... 바로 그 덤프 파일입니다.

고객에게... Process Explorer로 덤프를 남기신 후에 핸들 정보까지 필요하니 커널 모드 덤프를 얻기 위해 시스템 크래시를 시켜 재부팅하라고 할 수 있다면??? 그것이 가능하다면 이럴 때 쓸 수 있는 도구가 바로 Sysinternals의 NotMyFault입니다.

NotMyFault
; http://download.sysinternals.com/files/NotMyFault.zip

How to generate a kernel or a complete memory dump file in Windows Server 2008 and Windows Server 2008 R2 
; http://support.microsoft.com/kb/969028

Notmyfault로 full 덤프 생성 방법
; http://jkmoon.tistory.com/319

하지만, 대부분의 환경에서 현실적이지 못할 것입니다.

어쨌든, 이것이 덤프 파일 디버깅의 한계입니다. 커널 객체의 상태 정보를 반드시 확인해야 할 필요가 있다면, 그나마 NotMyFault보다 더 현실적인 방법은 해당 프로세스가 살아 있을 때 windbg 등을 통해 "attach" 시켜 라이브 디버깅 상태에서 진행하는 것입니다. 그렇게 하면 다음과 같이 해당 커널 객체의 타입에 따라 "Object Specific Information"을 추가로 얻을 수 있습니다.

0:004> !handle 20c ff
Handle 20c
  Type         	Event
  Attributes   	0
  GrantedAccess	0x1f0003:
         Delete,ReadControl,WriteDac,WriteOwner,Synch
         QueryState,ModifyState
  HandleCount  	2
  PointerCount 	65537
  Name         	<none>
  Object Specific Information
    Event Type Manual Reset
    Event is Waiting




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

[연관 글]






[최초 등록일: ]
[최종 수정일: 11/24/2022]

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

비밀번호

댓글 작성자
 




... 16  17  18  19  20  21  22  23  24  25  26  27  28  [29]  30  ...
NoWriterDateCnt.TitleFile(s)
12916정성태1/12/20225678오류 유형: 784. TFS - One or more source control bindings for this solution are not valid and are listed below.
12915정성태1/11/20225980오류 유형: 783. Visual Studio - We didn't find any interpreters
12914정성태1/11/20227987VS.NET IDE: 172. 비주얼 스튜디오 2022의 파이선 개발 환경 지원
12913정성태1/11/20228497.NET Framework: 1133. C# - byte * (바이트 포인터)를 FileStream으로 쓰는 방법 [1]
12912정성태1/11/20229147개발 환경 구성: 623. ffmpeg.exe를 사용해 비디오 파일의 이미지를 PGM(Portable Gray Map) 파일 포맷으로 출력하는 방법 [1]
12911정성태1/11/20226386VS.NET IDE: 171. 비주얼 스튜디오 - 더 이상 만들 수 없는 "ASP.NET Core 3.1 Web Application (.NET Framework)" 프로젝트
12910정성태1/10/20226859제니퍼 .NET: 30. 제니퍼 닷넷 적용 사례 (8) - CPU high와 DB 쿼리 성능에 문제가 함께 있는 사이트
12909정성태1/10/20228250오류 유형: 782. Visual Studio 2022 설치 시 "Couldn't install Microsoft.VisualCpp.Redist.14.Latest"
12908정성태1/10/20226081.NET Framework: 1132. C# - ref/out 매개변수의 IL 코드 처리
12907정성태1/9/20226605오류 유형: 781. (youtube-dl.exe) 실행 시 "This app can't run on your PC" / "Access is denied." 오류 발생
12906정성태1/9/20227255.NET Framework: 1131. C# - 네임스페이스까지 동일한 타입을 2개의 DLL에서 제공하는 경우 충돌을 우회하는 방법 [1]파일 다운로드1
12905정성태1/8/20226915오류 유형: 780. Could not load file or assembly 'Microsoft.VisualStudio.TextTemplating.VSHost.15.0, Version=16.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.
12904정성태1/8/20228892개발 환경 구성: 623. Visual Studio 2022 빌드 환경을 위한 github Actions 설정 [1]
12903정성태1/7/20227509.NET Framework: 1130. C# - ELEMENT_TYPE_INTERNAL 유형의 사용 예
12902정성태1/7/20227546오류 유형: 779. SQL 서버 로그인 에러 - provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe.
12901정성태1/5/20227567오류 유형: 778. C# - .NET 5+에서 warning CA1416: This call site is reachable on all platforms. '...' is only supported on: 'windows' 경고 발생
12900정성태1/5/20229255개발 환경 구성: 622. vcpkg로 ffmpeg를 빌드하는 경우 생성될 구성 요소 제어하는 방법
12899정성태1/3/20228751개발 환경 구성: 621. windbg에서 python 스크립트 실행하는 방법 - pykd (2)
12898정성태1/2/20229326.NET Framework: 1129. C# - ffmpeg(FFmpeg.AutoGen)를 이용한 비디오 인코딩 예제(encode_video.c) [1]파일 다운로드1
12897정성태1/2/20228157.NET Framework: 1128. C# - 화면 캡처한 이미지를 ffmpeg(FFmpeg.AutoGen)로 동영상 처리 [4]파일 다운로드1
12896정성태1/1/202211107.NET Framework: 1127. C# - FFmpeg.AutoGen 라이브러리를 이용한 기본 프로젝트 구성파일 다운로드1
12895정성태12/31/20219532.NET Framework: 1126. C# - snagit처럼 화면 캡처를 연속으로 수행해 동영상 제작 [1]파일 다운로드1
12894정성태12/30/20217504.NET Framework: 1125. C# - DefaultObjectPool<T>의 IDisposable 개체에 대한 풀링 문제 [3]파일 다운로드1
12893정성태12/27/20219105.NET Framework: 1124. C# - .NET Platform Extension의 ObjectPool<T> 사용법 소개파일 다운로드1
12892정성태12/26/20217096기타: 83. unsigned 형의 이전 값이 최댓값을 넘어 0을 지난 경우, 값의 차이를 계산하는 방법
12891정성태12/23/20216995스크립트: 38. 파이썬 - uwsgi의 --master 옵션
... 16  17  18  19  20  21  22  23  24  25  26  27  28  [29]  30  ...