Microsoft MVP성태의 닷넷 이야기
디버깅 기술: 27. Windbg - Local Kernel Debug 모드 [링크 복사], [링크+제목 복사]
조회: 27209
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 9개 있습니다.)
(시리즈 글이 7개 있습니다.)
디버깅 기술: 3. 원격 컴퓨터 디버깅 - VPC 설정
; https://www.sysnet.pe.kr/2/0/265

디버깅 기술: 3.1. Managed 원격 디버깅과 WinDBG 원격 디버깅
; https://www.sysnet.pe.kr/2/0/314

디버깅 기술: 27. Windbg - Local Kernel Debug 모드
; https://www.sysnet.pe.kr/2/0/934

디버깅 기술: 29. Windbg - Hyper-V 윈도우 7 원격 디버깅 구성
; https://www.sysnet.pe.kr/2/0/938

Windows: 57. 새로 추가된 네트워크 커널 디버깅 및 PowerShell 3.0
; https://www.sysnet.pe.kr/2/0/1259

디버깅 기술: 62. windbg - 사용자 모드 원격 디버깅
; https://www.sysnet.pe.kr/2/0/1602

디버깅 기술: 192. Windbg - Hyper-V VM으로 이더넷 원격 디버깅 연결하는 방법
; https://www.sysnet.pe.kr/2/0/13343




Windbg - Local Kernel Debug 모드

windbg 가지고 실습을 하는데, 일단 notepad.exe 켜고 디버거를 붙였습니다. 그리고는 책에 나온 대로 "!process" 명령을 실행하는데, ^^; 처음부터 막히는군요. 다음과 같이 오류가 발생합니다.

0:002> !process
No export process found

너무 일반적인 단어들로 이뤄진 오류 메시지라서, 원인을 찾기 힘들었는데요. 다음의 글에서 ^^ 설명을 볼 수 있습니다.

Windbg:how can I load a process from LKD? - Sysinternals Forums
; http://84.45.57.224/windbghow-can-i-load-a-process-from-lkd_topic868_post2547.html

그러니까, "!process" 명령어가 실행되려면 커널 모드로 진입된 상태여야 한다고 합니다. 그래서, 커널 모드로 BP 상태를 진행시키기 위해 ".attach -k" 명령을 내리고 "g" 명령을 연이어 해주면 해결됩니다.

.attach -k
Attach will occur on next execution
||0:0:002> g
Connected to Windows 7 7600 x64 target at (Sun Oct 10 20:07:28.437 2010 (GMT+9)), ptr64 TRUE
Symbol search path is: ...[생략]...
Executable search path is: 
Windows 7 Kernel Version 7600 MP (8 procs) Free x64
Product: ...
Built by: ...
Machine Name:
Kernel base = 0xfffff800`03053000 PsLoadedModuleList = 0xfffff800`03290e50
Debug session time: Sun Oct 10 20:07:38.156 2010 (GMT+9)
System Uptime: 0 days 0:10:16.280

자... ^^ 이제 커널로 진입한 상태이기 때문에 정상적으로 "!process" 명령이 통하게 됩니다.

||1:lkd> !process
PROCESS fffffa800761fb30
    SessionId: 1  Cid: 0dd4    Peb: 7fffffd5000  ParentCid: 0878
    DirBase: 7a1d3000  ObjectTable: fffff8a004701480  HandleCount: 317.
    Image: notepad.exe
    VadRoot fffffa80070a16a0 Vads 168 Clone 0 Private 6805. Modified 2840. Locked 1.
    DeviceMap fffff8a002ce0700
    Token                             fffff8a004ff84d0
    ElapsedTime                       00:10:43.548
    UserTime                          00:00:00.000
    KernelTime                        00:00:00.000
    QuotaPoolUsage[PagedPool]         0
    QuotaPoolUsage[NonPagedPool]      0
    Working Set Sizes (now,min,max)  (10622, 50, 345) (42488KB, 200KB, 1380KB)
    PeakWorkingSetSize                10626
    VirtualSize                       155 Mb
    PeakVirtualSize                   155 Mb
    PageFaultCount                    14688
    MemoryPriority                    BACKGROUND
    BasePriority                      13
    CommitCharge                      7422
... [생략] ...

참고로, ".attach -k" 명령은 윈도우가 "-debug on" 모드로 부팅되어야 합니다. 그래서, Vista 이상의 운영체제에서는 미리 관리자 권한의 명령행에서 "bcdedit -debug on" 실행하고 재부팅해야 합니다. 또한, WOW64 지원을 하지 못하므로 64비트에서 32비트 응용 프로그램을 대상으로는 ".attach -k" 명령어가 동작하지 않습니다. 만약, 이런 제약이 걸리는 상황에서 ".attach -k" 명령을 내리면 다음과 같이 친절하게 오류 메시지를 출력해 줍니다. ^^

0:014> .attach -k
The system does not support local kernel debugging.
Local kernel debugging requires Windows XP, Administrative privileges.
Local kernel debugging dose not support WOW64, please run local kernel debugging from 64-bit native debugger.
Only a single local kernel debugging session can run at a time.
Local kernel debugging is disabled by default since Windows Vista, you must run "bcdedit -debug on" and reboot to enable it.
Unable to initialize target, HRESULT 0x80004001




특정 프로세스에 attach 시킨 후에 커널 모드로 진입하는 경우에는 위와 같은 방법을 사용해야 하지만, Windbg 실행 후 처음부터 커널 모드로 진입하는 간단한 방법도 있습니다.

아래와 같이 "File" / "Kernel Debug..."를 선택하고,

windbg_kernel_debug_mode_1.png

"Local" 탭을 선택 후 "OK" 버튼을 누르면 됩니다.

windbg_kernel_debug_mode_2.png

그럼, Windbg 명령창의 프롬프트가 "lkd>"라고 "local kernel debugging" 상태임을 확인할 수 있습니다. ^^

windbg_kernel_debug_mode_3.png

LKD 기능은 Windows XP 이상의 운영체제에서 제공되는데, Windows 2000을 실습 대상으로 설명하는 책에서는 당연히 windbg로 테스트 할 때 2대 이상의 PC에서 하는 것을 전제로 하기 때문에 "No export process found"와 같은 오류가 발생할 일이 없어서 그와 관련된 설명이 없었던 것입니다.

끝으로 중요한 점 하나!
LKD를 활성화하기 위해 "bcdedit -debug on" 모드로 부팅되고 나면, Visual Studio에서 ".NET 응용 프로그램(Managed App)"들에 대해서 디버깅이 불가능해집니다.



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

[연관 글]






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

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

비밀번호

댓글 작성자
 



2017-04-03 11시51분
정성태
2020-07-08 01시14분
Hardware breakpoints and exceptions on Windows
; https://ling.re/hardware-breakpoints/

#WinDbg tip: edit %LOCALAPPDATA%\DBG\DbgX.xml and change CommandWindowExperimental -> CommandIntellisense2 from false to true, and get a nice helper menu when typing your command in #WinDbgX
; https://twitter.com/windbgtips/status/1631810570239332358?s=20
정성태

1  2  3  [4]  5  6  7  8  9  10  11  12  13  14  15  ...
NoWriterDateCnt.TitleFile(s)
13528정성태1/14/20242033Linux: 68. busybox 컨테이너에서 실행 가능한 C++, Go 프로그램 빌드
13527정성태1/14/20241961오류 유형: 892. Visual Studio - Failed to launch debug adapter. Additional information may be available in the output window.
13526정성태1/14/20242051닷넷: 2201. C# - Facebook 연동 / 사용자 탈퇴 처리 방법
13525정성태1/13/20242021오류 유형: 891. Visual Studio - Web Application을 실행하지 못하는 IISExpress
13524정성태1/12/20242066오류 유형: 890. 한국투자증권 KIS Developers OpenAPI - GW라우팅 중 오류가 발생했습니다.
13523정성태1/12/20241889오류 유형: 889. Visual Studio - error : A project with that name is already opened in the solution.
13522정성태1/11/20242030닷넷: 2200. C# - HttpClient.PostAsJsonAsync 호출 시 "Transfer-Encoding: chunked" 대신 "Content-Length" 헤더 처리
13521정성태1/11/20242110닷넷: 2199. C# - 한국투자증권 KIS Developers OpenAPI의 WebSocket Ping, Pong 처리
13520정성태1/10/20241858오류 유형: 888. C# - Unable to resolve service for type 'Microsoft.Extensions.ObjectPool.ObjectPool`....'
13519정성태1/10/20241939닷넷: 2198. C# - Reflection을 이용한 ClientWebSocket의 Ping 호출파일 다운로드1
13518정성태1/9/20242174닷넷: 2197. C# - ClientWebSocket의 Ping, Pong 처리
13517정성태1/8/20242017스크립트: 63. Python - 공개 패키지를 이용한 위성 이미지 생성 (pystac_client, odc.stac)
13516정성태1/7/20242104닷넷: 2196. IIS - AppPool의 "Disable Overlapped Recycle" 옵션의 부작용
13515정성태1/6/20242376닷넷: 2195. async 메서드 내에서 C# 7의 discard 구문 활용 사례 [1]
13514정성태1/5/20242065개발 환경 구성: 702. IIS - AppPool의 "Disable Overlapped Recycle" 옵션
13513정성태1/5/20242006닷넷: 2194. C# - WebActivatorEx / System.Web의 PreApplicationStartMethod 특성
13512정성태1/4/20241979개발 환경 구성: 701. IIS - w3wp.exe 프로세스의 ASP.NET 런타임을 항상 Warmup 모드로 유지하는 preload Enabled 설정
13511정성태1/4/20241997닷넷: 2193. C# - ASP.NET Web Application + OpenAPI(Swashbuckle) 스펙 제공
13510정성태1/3/20241937닷넷: 2192. C# - 특정 실행 파일이 있는지 확인하는 방법 (Linux)
13509정성태1/3/20241966오류 유형: 887. .NET Core 2 이하의 프로젝트에서 System.Runtime.CompilerServices.Unsafe doesn't support netcoreapp2.0.
13508정성태1/3/20242016오류 유형: 886. ORA-28000: the account is locked
13507정성태1/2/20242701닷넷: 2191. C# - IPGlobalProperties를 이용해 netstat처럼 사용 중인 Socket 목록 구하는 방법파일 다운로드1
13506정성태12/29/20232191닷넷: 2190. C# - 닷넷 코어/5+에서 달라지는 System.Text.Encoding 지원
13505정성태12/27/20232707닷넷: 2189. C# - WebSocket 클라이언트를 닷넷으로 구현하는 예제 (System.Net.WebSockets)파일 다운로드1
13504정성태12/27/20232322닷넷: 2188. C# - ASP.NET Core SignalR로 구현하는 채팅 서비스 예제파일 다운로드1
13503정성태12/27/20232191Linux: 67. WSL 환경 + mlocate(locate) 도구의 /mnt 디렉터리 검색 문제
1  2  3  [4]  5  6  7  8  9  10  11  12  13  14  15  ...