Hyper-V를 이용한 커널 디버깅
Hyper-V
Hyper-V는 Windows 10 이상부터 OS에서 지원하는 가상 머신입니다. 가상화 타입1(Bare-Metal)에 해당하기 때문에 높은 성능, 빠른 속도를 자랑합니다.
다음과 같이 [Windows 기능 켜기/끄기]를 통해 Hyper-V를 활성화하여 사용합니다.
Create a virtual machine in Hyper-V
Hyper-V가 활성화되면 미리 준비한 ISO 파일을 통해 새 가상 컴퓨터를 생성합니다.
해당 글에서는 1세대 가상 머신을 기준으로 작성되었기 때문에, 생성 시 다음과 같이 설정합니다.
가상 머신이 생성되면, 부팅하여 Windows OS를 설치합니다.
COM Port
Hyper-V는 가상 머신과 Host PC가 통신할수 있도록 가상 COM 포트를 지원합니다.
다음과 같이 설정하여 com1이라는 파이프를 생성합니다.
이후에 Windows를 부팅하고, msconfig를 통해 다음과 같이 디버깅 옵션을 설정합니다.
Windbg
Hyper-V 및 Windows에서 디버깅 설정이 완료되었다면, windbg를 관리자 권한으로 실행합니다.
이후에 다음과 같이 이전에 생성한 com1 파이프를 입력합니다.
입력하면 다음과 같이 운영체제가 부팅될 때까지 대기합니다.
이 상태에서 운영체제를 부팅하면 커널 디버깅이 정상적으로 동작합니다.
Break를 통해 시스템을 중지하고, 명령을 통해 디버깅 작업을 수행할 수 있습니다.
Generation 2 Virtual Machines
2세대 가상 머신에서는 COM 포트 설정이 GUI에 표시되지 않는다고 합니다.
따라서, MSDN에서는 다음과 같이 PowerShell 명령을 통해 직접 활성화하는 방식을 권장하고 있습니다.
Disable Secure Boot by entering this PowerShell command:
Set-VMFirmware –Vmname VmName –EnableSecureBoot Off
where VmName is the name of your virtual machine.
Add a COM port to the virtual machine by entering this PowerShell command:
Set-VMComPort –VMName VmName 1 \.\pipe\PipeName
For example, the following command configures the first COM port on virtual machine TestVM to connect to named pipe TestPipe on the local computer.
Set-VMComPort –VMName TestVM 1 \.\pipe\TestPipe
Once the debugger is attached and running, stop and cold start the VM to activate the COM ports in the VM. The emulated UARTS aren’t available for debugging unless at least one is actually configured with a pipe name and they cannot be hot-added.
Re-enable secure boot, once you are done updating the configuration changes.
자세한 내용은 Setting Up Kernel-Mode Debugging of a Virtual Machine Manually using a Virtual COM Port을 참고하세용.