Microsoft MVP성태의 닷넷 이야기
디버깅 기술: 29. Windbg - Hyper-V 윈도우 7 원격 디버깅 구성 [링크 복사], [링크+제목 복사],
조회: 24652
글쓴 사람
정성태 (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)
12410정성태11/12/202017582디버깅 기술: 174. windbg - System.TypeLoadException 예외 분석 사례
12409정성태11/12/202019424.NET Framework: 968. C# 9.0의 Function pointer를 이용한 함수 주소 구하는 방법파일 다운로드1
12408정성태11/9/202034672도서: 시작하세요! C# 9.0 프로그래밍 [8]
12407정성태11/9/202019769.NET Framework: 967. "clr!JIT_DbgIsJustMyCode" 호출이 뭘까요?
12406정성태11/8/202020755.NET Framework: 966. C# 9.0 - (15) 최상위 문(Top-level statements) [5]파일 다운로드1
12405정성태11/8/202018629.NET Framework: 965. C# 9.0 - (14) 부분 메서드에 대한 새로운 기능(New features for partial methods)파일 다운로드1
12404정성태11/7/202019249.NET Framework: 964. C# 9.0 - (13) 모듈 이니셜라이저(Module initializers)파일 다운로드1
12403정성태11/7/202018155.NET Framework: 963. C# 9.0 - (12) foreach 루프에 대한 GetEnumerator 확장 메서드 지원(Extension GetEnumerator)파일 다운로드1
12402정성태11/7/202019641.NET Framework: 962. C# 9.0 - (11) 공변 반환 형식(Covariant return types) [1]파일 다운로드1
12401정성태11/5/202018909VS.NET IDE: 153. 닷넷 응용 프로그램에서의 "My Code" 범위와 "Enable Just My Code"의 역할 [1]
12400정성태11/5/202015135오류 유형: 679. Visual Studio - "Source Not Found" 창에 "Decompile source code" 링크가 없는 경우
12399정성태11/5/202018658.NET Framework: 961. C# 9.0 - (10) 대상으로 형식화된 조건식(Target-typed conditional expressions)파일 다운로드1
12398정성태11/4/202018167오류 유형: 678. Windows Server 2008 R2 환경에서 Powershell을 psexec로 원격 실행할 때 hang이 발생하는 문제
12397정성태11/4/202018189.NET Framework: 960. C# - 조건 연산자(?:)를 사용하는 경우 달라지는 메서드 선택 사례파일 다운로드1
12396정성태11/3/202015208VS.NET IDE: 152. Visual Studio - "Tools" / "External Tools..."에 등록된 외부 명령어에 대한 단축키 설정 방법
12395정성태11/3/202017985오류 유형: 677. SSMS로 DB 접근 시 The server principal "..." is not able to access the database "..." under the current security context.
12394정성태11/3/202015616오류 유형: 676. cacls - The Recycle Bin on ... is corrupted. Do you want to empty the Recycle Bin for this drive?
12393정성태11/3/202015282오류 유형: 675. Visual Studio - 닷넷 응용 프로그램 디버깅 시 Disassembly 창에서 BP 설정할 때 "Error while processing breakpoint." 오류
12392정성태11/2/202019825.NET Framework: 959. C# 9.0 - (9) 레코드(Records) [4]파일 다운로드1
12390정성태11/1/202019478디버깅 기술: 173. windbg - System.Configuration.ConfigurationErrorsException 예외 분석 방법
12389정성태11/1/202018624.NET Framework: 958. C# 9.0 - (8) 정적 익명 함수 (static anonymous functions)파일 다운로드1
12388정성태10/29/202017674오류 유형: 674. 어느 순간부터 닷넷 응용 프로그램 실행 시 System.Configuration.ConfigurationErrorsException 예외가 발생한다면?
12387정성태10/28/202018461.NET Framework: 957. C# - static 필드의 정보가 GC Heap에 저장될까요? [3]파일 다운로드1
12386정성태10/28/202019201Linux: 34. 사용자 정보를 함께 출력하는 리눅스의 ps 명령어 사용 방법
12385정성태10/28/202016548오류 유형: 673. openssl - req: No value provided for Subject Attribute CN, skipped
12384정성태10/27/202018871오류 유형: 672. AllowPartiallyTrustedCallers 특성이 적용된 어셈블리의 struct 멤버 메서드를 재정의하면 System.Security.VerificationException 예외 발생
... [61]  62  63  64  65  66  67  68  69  70  71  72  73  74  75  ...