Setting Up Kernel-Mode Debugging of a Virtual Machine in Visual Studio
You can use Microsoft Visual Studio to set up and perform kernel-mode debugging of a virtual machine. The virtual machine can be located on the same physical computer as the debugger or on a different computer that is connected to the same network. To use Visual Studio for kernel-mode debugging, you must have the Windows Driver Kit (WDK) integrated with Visual Studio. For information about how to install the integrated environment, see Windows Driver Development.
As an alternative to using Visual Studio to set up debugging of a virtual machine, you can do the setup manually. For more information, see Setting Up Kernel-Mode Debugging of a Virtual Machine Manually.
The computer that runs the debugger is called the host computer, and the virtual machine that is being debugged is called the target virtual machine.
Configuring the Target Virtual Machine
In the virtual machine, in an elevated Command Prompt window, enter the following commands.
bcdedit /debug on
bcdedit /dbgsettings serial debugport:n baudrate:115200
where n is the number of a COM port on the virtual machine.
Reboot the virtual machine.
- In the virtual machine, configure the COM port to map to a named pipe. The debugger will connect through this pipe. For more information about how to create this pipe, see your virtual machine's documentation.
Configuring the Host Computer
The host computer can be the same physical computer that is running the virtual machine, or it can be a separate computer.
- On the host computer, in Visual Studio, on the Driver menu, choose Test > Configure Computer.
- Click Add New Computer.
- For Computer name, enter the name of the physical computer that is running the target virtual machine.
- Select Manually configure debuggers and do not provision, and click Next.
- For Connection Type, select Serial.
- Check Pipe, and check Reconnect.
If the debugger is running on the same computer as the virtual machine, enter the following for Pipe name:
If the debugger is running on a different computer from the virtual machine, enter the following for Pipe name:
where, VMHost is the name of the physical computer that is running the target virtual machine, and PipeName is the name of the pipe that you associated with the COM port on the target virtual machine.
Click Next. Click Finish.
Starting the Debugging Session
- On the host computer, in Visual Studio, on the Debug menu, choose Attach to Process.
- For Transport, choose Windows Kernel Mode Debugger.
- For Qualifier, select the name of the physical computer that is running the target virtual machine.
- Click Attach.
Generation 2 Virtual Machines
By default, COM ports are not presented in generation 2 virtual machines. You can add COM ports through PowerShell or WMI. For the COM ports to be displayed in the Hyper-V Manager console, they must be created with a path.
To enable kernel debugging using a COM port on a generation 2 virtual machine, follow these steps:
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
For more information, see Generation 2 Virtual Machine Overview.