Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 

(시리즈 글이 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 - Hyper-V VM으로 이더넷 원격 디버깅 연결하는 방법

예전에는 COM 포트를 이용했었는데요,

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

이번에는 이더넷을 이용한 연결 방법을 시도해 봤습니다. 사실 이에 대해서는 아래의 공식 문서에서 잘 설명하고 있습니다.

BCDEdit /dbgsettings
; https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/bcdedit--dbgsettings

Setting Up Network Debugging of a Virtual Machine - KDNET
; https://learn.microsoft.com/en-us/windows-hardware/drivers/debugger/setting-up-network-debugging-of-a-virtual-machine-host

문서에 따라, Windbg가 설치돼 있는 호스트 측에서 다음의 경로에 있는 (같은 위치의 VerifiedNICList.xml을 사용하는) kdnet.exe로,

C:\Program Files (x86)\Windows Kits\10\Debuggers\x64

자신의 PC에 장착한 이더넷 카드가 네트워크 디버깅을 지원하는지 알아볼 수 있습니다.

C:\Program Files (x86)\Windows Kits\10\Debuggers\x64> kdnet

Network debugging is supported on the following NICs:
busparams=9.0.0, Realtek PCIe 2.5GbE Family Controller #2, Cable status unknown.

Network debugging is supported on the following USB controllers:
busparams=4.0.0, AMD USB 3.10 eXtensible Host Controller - 1.10 (Microsoft)
busparams=10.0.4, AMD USB 3.10 eXtensible Host Controller - 1.10 (Microsoft)
busparams=10.0.3, AMD USB 3.10 eXtensible Host Controller - 1.10 (Microsoft)

This Microsoft hypervisor supports using KDNET in guest VMs.

위의 결과에서는 9.0.0 버스에 연결된 Realtek 어댑터가 지원하고, 그 외에도 USB 컨트롤러도 네트워크 디버깅을 지원한다고 나옵니다.




따라서 호스트 측에서는 windbg를 실행해 두고 임의의 포트와 Key를 선정해 다음과 같이 대기해 둡니다.

hyperv_windbg_net_1.png

특이하게도 Key의 경우에는 '.'을 구분자로 (마치 IP처럼) 4개의 값을 줘야 한다고 합니다. 그래서 위의 경우 "test"라고 하지 않고 "t.e.s.t"라고 설정한 것입니다.

그다음, Debuggee 측에서는 호스트 측에서 대기하고 있는 설정대로 연결할 수 있도록 연결 정보를 전달해 kdnet.exe를 실행합니다. 이때 kdnet 실행을 위해 Windows SDK를 설치할 필요 없이 호스트 측에 있는 kdnet.exe와 VerifiedNICList.xml 파일을 복사해 실행하면 됩니다.

// 호스트 측의 IP가 192.168.100.50이라고 가정

c:\temp> kdnet 192.168.100.50 65100

Enabling network debugging on Network debugging is supported by this Microsoft Hypervisor Virtual Machine.

To debug this vm, run the following command on your debugger host machine.
windbg -k net:port=65100,key=xxxxxxx.xxxxxxx.xxxxxxx.xxxxxxx

Then restart this VM by running shutdown -r -t 0 from this command prompt.

이때 key 값이 무작위로 "xxxxxxx.xxxxxxx.xxxxxxx.xxxxxxx" 긴 문자열이 나오는데요, 이것을 다음의 명령어로 (호스트 측에 지정한 것과 동일하게) 새롭게 지정합니다.

c:\temp> bcdedit /set "{dbgsettings}" key t.e.s.t

잘 설정이 되었는지 마지막으로 확인해 주고,

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

재부팅합니다. 일단, 호스트 측에 실행해 둔 windbg는 다음의 출력과 함께 멈춰 있을 텐데요,

Microsoft (R) Windows Debugger Version 10.0.25324.1001 AMD64
Copyright (c) Microsoft Corporation. All rights reserved.

Using NET for debugging
Opened WinSock 2.0
Waiting to reconnect...

Debuggee 측이 재부팅하면 곧바로 192.168.100.50:65100으로 연결하게 되고 다음과 같은 호스트 측의 출력을 확인할 수 있습니다.

Connected to target 192.168.100.100 on port 65100 on local IP 192.168.100.50.
You can get the target MAC address by running .kdtargetmac command.
Connected to Windows 10 19041 x64 target at (Tue May  9 11:59:21.915 2023 (UTC + 9:00)), ptr64 TRUE
Kernel Debugger connection established.

...[생략]...

*******************************************************************************
*                                                                             *
*   You are seeing this message because you pressed either                    *
*       CTRL+C (if you run console kernel debugger) or,                       *
*       CTRL+BREAK (if you run GUI kernel debugger),                          *
*   on your debugger machine's keyboard.                                      *
*                                                                             *
*                   THIS IS NOT A BUG OR A SYSTEM CRASH                       *
*                                                                             *
* If you did not intend to break into the debugger, press the "g" key, then   *
* press the "Enter" key now.  This message might immediately reappear.  If it *
* does, press "g" and "Enter" again.                                          *
*                                                                             *
*******************************************************************************
nt!DbgBreakPointWithStatus:
fffff804`114051b0 cc              int     3

이때, Debuggee 측의 운영체제 자체가 멈춰버리기 때문에 호스트 측의 windbg 명령행에서 'g' 키를 입력해 실행을 계속하면 됩니다.

(참고로, 이때의 통신은 TCP가 아닌 UDP입니다.)




그런데, kdnet.exe를 Debuggee PC 측에서 실행했을 때 다음과 같은 오류가 나올 수 있습니다.

c:\temp> kdnet

Network debugging is supported by this Microsoft Hypervisor Virtual Machine

KDNET transport initialization failed during a previous boot.  Status = 0xC00000B5.
InitializeNetwork failed to get the MAC address of the host debugger. Check the dbgsettings hostip!

이런 오류가 Hyper-V VM 환경에서 발생한다면, VM 측에 할당한 네트워크 유형을 살펴야 합니다. 문서에도 나오지만, 이더넷을 이용한 디버깅은 이것을 지원하는 "물리 어댑터"의 기능을 이용하는 것이기 때문에 반드시 그 어댑터와 연결된 Virtual Switch를 VM에 할당해 줘야 합니다. 기본적으로 External 유형에만 물리 어댑터가 연결되므로 그 외의 "Internal", "Private" 유형을 VM에 할당한 경우에는 동작하지 않습니다.




경우에 따라, Internal과 External 2개의 어댑터를 연결한 VM에서도 kdnet.exe가 0xC00000B5 오류를 보고할 수 있습니다. 이럴 때 ipconfig을 실행해 보면,

c:\temp> ipconfig

Windows IP Configuration

Ethernet adapter Ethernet (Kernel Debugger):

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::eab0:c8d9:e6d1:8bc0%4
   Autoconfiguration IPv4 Address. . : 169.254.169.55
   Subnet Mask . . . . . . . . . . . : 255.255.0.0
   Default Gateway . . . . . . . . . :

Ethernet adapter Ethernet 2:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::7fc9:901c:7365:5f2f%6
   IPv4 Address. . . . . . . . . . . : 192.168.100.100
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.100.1

"Kernel Debugger"가 "Internal" 네트워크로 설정한 어댑터로 연결되었을 것입니다. 이것을 물리 어댑터와 연결된 External 네트워크로 변경해야 하는데요, 위의 경우 "Ethernet adapter Ethernet 2"로 붙여야 합니다.

그런데, 딱히 이게 kdnet.exe 측에서는 설정하는 방법이 없습니다. 일단은, 저 규칙을 보면 우선순위가 높은 네트워크로 붙는 건데요, 따라서 다음의 글에 따라,

윈도우 - (네트워크 어댑터의 우선순위로 인한) 열거되는 IP 주소 순서를 조정하는 방법
; https://www.sysnet.pe.kr/2/0/12304

PowerShell을 이용해 InterfaceMetric을 확인하고,

PS C:\Windows\System32> Get-NetIPInterface | where {$_.ConnectionState -eq "Connected" -and $_.AddressFamily -eq "IPv4" } | select ifIndex,InterfaceAlias,InterfaceMetric,AddressFamily,ConnectionState | sort InterfaceMetric | FT

ifIndex InterfaceAlias              InterfaceMetric AddressFamily ConnectionState
------- --------------              --------------- ------------- ---------------
      6 Ethernet                                 15          IPv4       Connected
     11 Ethernet 2                               35          IPv4       Connected
      1 Loopback Pseudo-Interface 1              75          IPv4       Connected

위에서 6번 우선순위를 "Ethernet 2"보다 낮게(숫자는 크게) 설정하면 됩니다.

PS C:\Windows\System32> Set-NetIPInterface -InterfaceIndex 6 -InterfaceMetric 45

이후 ipconfig으로 우선순위가 바뀐 것을 확인하고,

c:\temp> ipconfig

Windows IP Configuration

Ethernet adapter Ethernet 2:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::5245:f089:a376:aca5%11
   IPv4 Address. . . . . . . . . . . : 192.168.100.100
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.100.1

Ethernet adapter Ethernet:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::7fc9:901c:7365:5f2f%6
   Autoconfiguration IPv4 Address. . : 169.254.169.55
   Subnet Mask . . . . . . . . . . . : 255.255.0.0
   Default Gateway . . . . . . . . . :

재부팅하면 정상적으로 동작하게 됩니다. 제 경우에 일단 "bcdedit /dbgsettings ..."로 해둔 설정을 삭제 및 재부팅 후 저 설정을 한 다음에 다시 "bcdedit /dbgsettings ..." 설정을 했는데요, 아마 저 상태에서 재부팅해도 잘되지 않을까... 싶습니다.




"bcdedit /dbgsettings ..."를 삭제하고 싶다면 /deletevalue 옵션을 4개의 값에 대해 일일이 지워야 합니다.

bcdedit /deletevalue {dbgsettings} key
bcdedit /deletevalue {dbgsettings} debugtype
bcdedit /deletevalue {dbgsettings} hostip 
bcdedit /deletevalue {dbgsettings} port

아니면, 그냥 LOCAL 설정으로 덮어쓰는 것도 좋겠고!

bcdedit /dbgsettings LOCAL

참고로, 본문에서는 "kdnet + bcdedit" 번에 걸쳐서 Debuggee 측의 설정을 했지만 그냥 다음과 같이 bcdedit 한 번으로 끝낼 수 있습니다.

bcdedit /dbgsettings NET HOSTIP:ip PORT:port [KEY:key]





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







[최초 등록일: ]
[최종 수정일: 5/9/2023]

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)
13602정성태4/20/2024201닷넷: 2244. C# - PCM 오디오 데이터를 연속(Streaming) 재생 (Windows Multimedia)파일 다운로드1
13601정성태4/19/2024242닷넷: 2243. C# - PCM 사운드 재생(NAudio)파일 다운로드1
13600정성태4/18/2024297닷넷: 2242. C# - 관리 스레드와 비관리 스레드
13599정성태4/17/2024365닷넷: 2241. C# - WAV 파일의 PCM 사운드 재생(Windows Multimedia)파일 다운로드1
13598정성태4/16/2024399닷넷: 2240. C# - WAV 파일 포맷 + LIST 헤더파일 다운로드2
13597정성태4/15/2024459닷넷: 2239. C# - WAV 파일의 PCM 데이터 생성 및 출력파일 다운로드1
13596정성태4/14/2024823닷넷: 2238. C# - WAV 기본 파일 포맷파일 다운로드1
13595정성태4/13/2024948닷넷: 2237. C# - Audio 장치 열기 (Windows Multimedia, NAudio)파일 다운로드1
13594정성태4/12/20241024닷넷: 2236. C# - Audio 장치 열람 (Windows Multimedia, NAudio)파일 다운로드1
13593정성태4/8/20241051닷넷: 2235. MSBuild - AccelerateBuildsInVisualStudio 옵션
13592정성태4/2/20241208C/C++: 165. CLion으로 만든 Rust Win32 DLL을 C#과 연동
13591정성태4/2/20241169닷넷: 2234. C# - WPF 응용 프로그램에 Blazor App 통합파일 다운로드1
13590정성태3/31/20241073Linux: 70. Python - uwsgi 응용 프로그램이 k8s 환경에서 OOM 발생하는 문제
13589정성태3/29/20241143닷넷: 2233. C# - 프로세스 CPU 사용량을 나타내는 성능 카운터와 Win32 API파일 다운로드1
13588정성태3/28/20241197닷넷: 2232. C# - Unity + 닷넷 App(WinForms/WPF) 간의 Named Pipe 통신파일 다운로드1
13587정성태3/27/20241157오류 유형: 900. Windows Update 오류 - 8024402C, 80070643
13586정성태3/27/20241301Windows: 263. Windows - 복구 파티션(Recovery Partition) 용량을 늘리는 방법
13585정성태3/26/20241096Windows: 262. PerformanceCounter의 InstanceName에 pid를 추가한 "Process V2"
13584정성태3/26/20241050개발 환경 구성: 708. Unity3D - C# Windows Forms / WPF Application에 통합하는 방법파일 다운로드1
13583정성태3/25/20241158Windows: 261. CPU Utilization이 100% 넘는 경우를 성능 카운터로 확인하는 방법
13582정성태3/19/20241421Windows: 260. CPU 사용률을 나타내는 2가지 수치 - 사용량(Usage)과 활용률(Utilization)파일 다운로드1
13581정성태3/18/20241588개발 환경 구성: 707. 빌드한 Unity3D 프로그램을 C++ Windows Application에 통합하는 방법
13580정성태3/15/20241138닷넷: 2231. C# - ReceiveTimeout, SendTimeout이 적용되지 않는 Socket await 비동기 호출파일 다운로드1
13579정성태3/13/20241494오류 유형: 899. HTTP Error 500.32 - ANCM Failed to Load dll
13578정성태3/11/20241631닷넷: 2230. C# - 덮어쓰기 가능한 환형 큐 (Circular queue)파일 다운로드1
[1]  2  3  4  5  6  7  8  9  10  11  12  13  14  15  ...