Microsoft MVP성태의 닷넷 이야기
디버깅 기술: 29. Windbg - Hyper-V 윈도우 7 원격 디버깅 구성 [링크 복사], [링크+제목 복사],
조회: 23107
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 3개 있습니다.)
(시리즈 글이 8개 있습니다.)
디버깅 기술: 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

디버깅 기술: 211. Windbg - 커널 모드 디버깅 상태에서 사용자 프로그램을 디버깅하는 방법
; https://www.sysnet.pe.kr/2/0/13851




Windbg - Hyper-V 윈도우 7 원격 디버깅 구성

예전에 Virtual Server에서 호스팅하고 있는 가상 PC에 windbg를 연결하는 방법을 설명했었는데요.

원격 컴퓨터 디버깅 - VPC 설정 
; https://www.sysnet.pe.kr/2/0/265

방법은 Hyper-V에서도 유사합니다. 단지, 윈도우 7에서의 boot.ini가 제거되는 바람에 약간 추가적인 작업이 필요한 정도인데요.

가상 머신의 COM 포트와 호스트 운영체제 측의 로컬 Named pipe 자원을 연결하는 설정은 이전과 다름없이 아래에서처럼 비슷하게 설정 방법이 제공됩니다. (Generation 2 VM의 경우 PowerShell 명령어로 설정)

windbg_hyperv_win7_1.png

Named pipe 경로: \\.\pipe\se2

이제, 대상이 되는 VM 운영체제에서 다음과 같은 명령을 관리자 권한으로 실행한 후, "재부팅" 해줍니다.

// COM1 포트에 \\.\pipe\se2를 연결한 경우
C:\Windows\system32> bcdedit /dbgsettings SERIAL DEBUGPORT:1 BAUDRATE:115200 
The operation completed successfully.

C:\Windows\system32> bcdedit /dbgsettings
debugtype               Serial
debugport               1
baudrate                115200
The operation completed successfully.

C:\Windows\system32> bcdedit /set debug on
The operation completed successfully.

C:\Windows\system32> bcdedit /set testsigning on
The operation completed successfully.

C:\Windows\system32> bcdedit
...[생략]...

Windows Boot Loader
-------------------
identifier              {current}
device                  partition=C:
...[생략]...
testsigning             Yes
isolatedcontext         Yes
...[생략]...
debug                   Yes

끝났군요. ^^ (Hyper-V를 호스팅하는 측에서) 마지막으로 windbg를 명령행에 다음과 같이 실행해 대기하거나,

...[설치경로]...\windbg.exe -k com:pipe,port=\\.\pipe\se2 -b

// 또는,

"C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\windbg" -Q -k "com:port=\\.\pipe\se2,baud=115200,pipe,reconnect"

또는 windbg 실행 후, "File" / "Kernel Debug..." 메뉴를 이용하여 다음과 같이 설정해서 연결을 대기할 수 있습니다.

windbg_hyperv_win7_2.png

명령행에서 "-b" 옵션을 주지 않거나, 대화 상자에서 "Reconnect" 옵션을 끄고 실행한다면, 다음과 같이 "Waiting to reconnect..." / "Debuggee not connected" 메시지로 계속 대기를 하게 되는데요.

windbg_hyperv_win7_3.png

잘못된 것이 아니고 ^^ "Debug" / " Break" 메뉴 (단축키: Ctrl+Break)를 실행해 주면 대상이 되는 가상 PC의 실행을 완전히 멈추게 되고 다음과 같이 프롬프트가 떨어지게 됩니다.

windbg_hyperv_win7_4.png

만약, 명령행에서 "-b" 옵션을 주거나 대화 상자에서 "Reconnect" 옵션을 체크했다면 Windbg.exe는 원격 컴퓨터에 연결하자마자 "Break"를 하게 됩니다.

다시 가상 PC를 실행상태로 만들려면 "g" 명령어를 주면 됩니다. ^^




참고로, 원격 디버깅의 경우 반드시 관리자 권한으로 실행해 주어야 하는데, 그렇지 않으면 다음과 같은 오류가 발생합니다.

Could not start kernel debugging using com:pipe,port=\\.\pipe\se2
parameters, Win32 error 0n5

Access is denied.




참고로 /dbgsettings만 해서는 안 되고 debug on을 해야만 원격 디버깅이 동작합니다.

// 관리자 권한으로 실행

// 이 옵션을 설정해야만 원격 디버깅도 가능 (Secure Boot가 꺼져 있어야 함)
c:\temp> bcdedit /set debug on

// 기왕이면, 테스트 서명을 허용하는 옵션도 설정
c:\temp> bcdedit /set testsigning on

그리고 주의해야 할 사항!

반드시 windbg 종료할 때 "g" 명령어로 시스템을 활성화시켜주어야 합니다. 그렇지 않으면 계속 스케쥴링이 멈춘 체로 VM이 유지되고 풀어주려면 다시 windbg 실행해서 "g" 명령어를 내려야 합니다. ^^

예전에 Virtual Server 이야기 하면서 VM이 멈춰진 상태에서 CPU 부하가 심하다는 이야기를 한 적이 있는데요. 다행히 Hyper-V에서는 이런 현상이 없습니다. 테스트 삼아서, "Windows Virtual PC" 환경은 어떨까 싶어서 호스팅 되고 있는 "XP Mode" 가상 PC에 windbg를 걸어보았는데 이건 여전히 CPU를 13% 소비하는 현상이 있습니다. (8-core에서 13%는 단일 CPU에서의 100% 현상입니다.)

음... CPU 소비를 고려한다면, windbg로 원격 디버깅하는 환경은 Hyper-V가 이상적일 수 있다는 거군요. ^^



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

[연관 글]






[최초 등록일: ]
[최종 수정일: 1/18/2025]

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

비밀번호

댓글 작성자
 



2020-01-14 10시05분
Windows - Kernel Debugging In Hyper-V
; https://t0rchwo0d.github.io/windows/Windows-Kernel-Debugging-In-Hyper-V/

입문자를 위한 윈도우 디바이스 드라이버 2장(커널디버거)
; https://www.youtube.com/watch?v=hJkSmz0BM5w

USB 키보드 크래시 덤프 (재부팅 후, Ctrl 키를 누른 상태에서 Scroll Lock 키를 두 번 연속 누르면 덤프 생성)
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\kbdhid\Parameters
CrashOnCtrlScroll (REG_DWORD 0x01)

Why can’t I trigger a manual blue screen crash by injecting the magic key sequence?
; https://devblogs.microsoft.com/oldnewthing/20240219-00/?p=109424

이더넷 연결
; https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/bcdedit--dbgsettings
; https://learn.microsoft.com/en-us/windows-hardware/drivers/debugger/setting-up-network-debugging-of-a-virtual-machine-host

[Debuggee]
C:\Windows\System32> bcdedit /dbgsettings net hostip:192.168.100.50 port:65100 key:t.e.s.t

C:\Windows\System32> bcdedit /dbgsettings
key t.e.s.t
debugtype NET
hostip 192.168.100.50
port 65100
badmemoryaccess Yes
dhcp Yes
The operation completed successfully.

[Debugger]
windbg 실행 후 Ctrl + K(Kernel Debug...) 메뉴를 통해 "NET" 설정


// COM 1 포트에 pipe 연결한 경우
bcdedit /dbgsettings SERIAL DEBUGPORT:1 BAUDRATE:115200

// COM 2 포트에 pipe 연결한 경우
bcdedit /dbgsettings SERIAL DEBUGPORT:2 BAUDRATE:115200
정성태

... 61  62  63  [64]  65  66  67  68  69  70  71  72  73  74  75  ...
NoWriterDateCnt.TitleFile(s)
12310정성태9/3/202016467오류 유형: 644. Windows could not start the Elasticsearch 7.9.0 (elasticsearch-service-x64) service on Local Computer.
12309정성태9/3/202016436개발 환경 구성: 507. Elasticsearch 6.6부터 기본 추가된 한글 형태소 분석기 노리(nori) 사용법
12308정성태9/2/202017461개발 환경 구성: 506. Windows - 단일 머신에서 단일 바이너리로 여러 개의 ElasticSearch 노드를 실행하는 방법
12307정성태9/2/202018251오류 유형: 643. curl - json_parse_exception / Invalid UTF-8 start byte
12306정성태9/1/202016248오류 유형: 642. SQL Server 시작 오류 - error code 10013
12305정성태9/1/202017426Windows: 172. "Administered port exclusions"이 아닌 포트 범위 항목을 삭제하는 방법
12304정성태8/31/202015739개발 환경 구성: 505. 윈도우 - (네트워크 어댑터의 우선순위로 인한) 열거되는 IP 주소 순서를 조정하는 방법
12303정성태8/30/202016305개발 환경 구성: 504. ETW - 닷넷 프레임워크 기반의 응용 프로그램을 위한 명령행 도구 etrace 소개
12302정성태8/30/202016323.NET Framework: 936. C# - ETW 관련 Win32 API 사용 예제 코드 (5) - Private Logger파일 다운로드1
12301정성태8/30/202016760오류 유형: 641. error MSB4044: The "Fody.WeavingTask" task was not given a value for the required parameter "IntermediateDir".
12300정성태8/29/202016263.NET Framework: 935. C# - ETW 관련 Win32 API 사용 예제 코드 (4) CLR ETW Consumer파일 다운로드1
12299정성태8/27/202017451.NET Framework: 934. C# - ETW 관련 Win32 API 사용 예제 코드 (3) ETW Consumer 구현파일 다운로드1
12298정성태8/27/202016348오류 유형: 640. livekd - Could not resolve symbols for ntoskrnl.exe: MmPfnDatabase
12297정성태8/25/202016015개발 환경 구성: 503. SHA256 테스트 인증서 생성 방법
12296정성태8/24/202017079.NET Framework: 933. C# - ETW 관련 Win32 API 사용 예제 코드 (2) NT Kernel Logger파일 다운로드1
12295정성태8/24/202015858오류 유형: 639. Bitvise - Address is already in use; bind() in ListeningSocket::StartListening() failed: Windows error 10013: An attempt was made to access a socket ,,,
12293정성태8/24/202016910Windows: 171. "Administered port exclusions" 설명
12292정성태8/20/202019775.NET Framework: 932. C# - ETW 관련 Win32 API 사용 예제 코드 (1)파일 다운로드2
12291정성태8/15/202017108오류 유형: 638. error 1297: Device driver does not install on any devices, use primitive driver if this is intended.
12290정성태8/11/202017903.NET Framework: 931. C# - IP 주소에 따른 국가별 위치 확인 [8]파일 다운로드1
12289정성태8/6/202014740개발 환경 구성: 502. Portainer에 윈도우 컨테이너를 등록하는 방법
12288정성태8/5/202015004오류 유형: 637. WCF - The protocol 'net.tcp' does not have an implementation of HostedTransportConfiguration type registered.
12287정성태8/5/202015666오류 유형: 636. C# - libdl.so를 DllImport로 연결 시 docker container 내에서 System.DllNotFoundException 예외 발생
12286정성태8/5/202017008개발 환경 구성: 501. .NET Core 용 container 이미지 만들 때 unzip이 필요한 경우
12285정성태8/4/202017221오류 유형: 635. 윈도우 10 업데이트 - 0xc1900209 [2]
12284정성태8/4/202016697디버깅 기술: 169. Hyper-V의 VM에 대한 메모리 덤프를 뜨는 방법
... 61  62  63  [64]  65  66  67  68  69  70  71  72  73  74  75  ...