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

비밀번호

댓글 작성자
 




... 61  62  63  64  65  66  67  68  [69]  70  71  72  73  74  75  ...
NoWriterDateCnt.TitleFile(s)
11927정성태6/5/201912107스크립트: 15. PowerShell ISE의 스크립트를 복사 후 PPT/Word에 붙여 넣으면 한글이 깨지는 문제 [1]
11926정성태6/4/201913483오류 유형: 542. Visual Studio - pointer to incomplete class type is not allowed
11925정성태6/4/201912276VC++: 131. Visual C++ - uuid 확장 속성과 __uuidof 확장 연산자파일 다운로드1
11924정성태5/30/201914081Math: 57. C# - 해석학적 방법을 이용한 최소 자승법 [1]파일 다운로드1
11923정성태5/30/201913709Math: 56. C# - 그래프 그리기로 알아보는 경사 하강법의 최소/최댓값 구하기파일 다운로드1
11922정성태5/29/201911754.NET Framework: 840. ML.NET 데이터 정규화파일 다운로드1
11921정성태5/28/201916748Math: 55. C# - 다항식을 위한 최소 자승법(Least Squares Method)파일 다운로드1
11920정성태5/28/201910257.NET Framework: 839. C# - PLplot 색상 제어
11919정성태5/27/201913445Math: 54. C# - 최소 자승법의 1차 함수에 대한 매개변수를 단순 for 문으로 구하는 방법 [1]파일 다운로드1
11918정성태5/25/201914594Math: 53. C# - 행렬식을 이용한 최소 자승법(LSM: Least Square Method)파일 다운로드1
11917정성태5/24/201914780Math: 52. MathNet을 이용한 간단한 통계 정보 처리 - 분산/표준편차파일 다운로드1
11916정성태5/24/201912786Math: 51. MathNET + OxyPlot을 이용한 간단한 통계 정보 처리 - Histogram파일 다운로드1
11915정성태5/24/201915129Linux: 11. 리눅스의 환경 변수 관련 함수 정리 - putenv, setenv, unsetenv
11914정성태5/24/201914786Linux: 10. 윈도우의 GetTickCount와 리눅스의 clock_gettime파일 다운로드1
11913정성태5/23/201912413.NET Framework: 838. C# - 숫자형 타입의 bit(2진) 문자열, 16진수 문자열 구하는 방법파일 다운로드1
11912정성태5/23/201912043VS.NET IDE: 137. Visual Studio 2019 버전 16.1부터 리눅스 C/C++ 프로젝트에 추가된 WSL 지원
11911정성태5/23/201911124VS.NET IDE: 136. Visual Studio 2019 - 리눅스 C/C++ 프로젝트에 인텔리센스가 동작하지 않는 경우
11910정성태5/23/201919844Math: 50. C# - MathNet.Numerics의 Matrix(행렬) 연산 [1]파일 다운로드1
11909정성태5/22/201914103.NET Framework: 837. C# - PLplot 사용 예제 [1]파일 다운로드1
11908정성태5/22/201912596.NET Framework: 836. C# - Python range 함수 구현파일 다운로드1
11907정성태5/22/201910353오류 유형: 541. msbuild - MSB4024 The imported project file "...targets" could not be loaded
11906정성태5/21/201910321.NET Framework: 835. .NET Core/C# - 리눅스 syslog에 로그 남기는 방법
11905정성태5/21/201910964.NET Framework: 834. C# - 폴더 경로 문자열에서 "..", "." 표기를 고려한 최종 문자열을 얻는 방법 - 두 번째 이야기
11904정성태5/21/201917346.NET Framework: 833. C# - Open Hardware Monitor를 이용한 CPU 온도 정보 [1]파일 다운로드1
11903정성태5/21/201912216오류 유형: 540. .NET Core - System.PlatformNotSupportedException: The named version of this synchronization primitive is not supported on this platform.
11902정성태5/21/201911377오류 유형: 539. mstest 실행 시 "The directory name is invalid." 오류 발생
... 61  62  63  64  65  66  67  68  [69]  70  71  72  73  74  75  ...