Petr, I’m pretty sure that Brandon was interested in debugging a guest, not the host. And while it is possible to debug the Hyper-V parent partition using network debugging, it’s more interesting for most people to debug the guest.
If the guest is Windows 8 or Server 2012, or if you manually copy kdvm.dll from Windows 8 to Windows 7, you can debug the guest as if it were a network debugging target, but without ever putting it on a network. We’ve added a debugger transport DLL which passes packets to the Hyper-V parent for placement on the network. This requires a little extra setup, and the integration didn’t make it all the way into Visual Studio. So if you’re comfortable using Windbg or Kd, you can enable another debugging path which is very fast and which doesn’t incur the overhead of the emulated serial port for the guest.
To set it up in the guest OS, you type, for example:
bcdedit /set dbgtransport kdvm.dll
bcdedit /set {default} loadoptions host_ip=“1.2.3.4”,host_port=“50000”,encryption_key=“cl.ea.rt.ext”
bcdedit /set debug on
The encryption key is up to you, but must be validly formed. The port is a dummy value which is ignored.
In the host OS, you tell it which guest(s) you want to enable this for and which ports to use, using the Hyper-V WMI interface. The port is actually used here. (Pick a useful and valid port.) I use a PowerShell script to do this, and it is below.
To start windbg or kd.exe in a way that will connect to this, type:
windbg -k net:port=50000,target=nameofhostmachinehere,key=cl.ea.rt.ext
Note again that this isn’t talking to the guest’s networking stack. It’s talking to the parent OS’s networking stack, using the parent OS’s name. The guest can be network connected, or not.
You can run the debugger itself either in the Parent OS or somewhere else. To the debugger, this is just another network debugging session.
- Jake Oshins
Windows Hyper-V Team
Powershell script begins here:
Argument initialization
$nextarg = “none”
$DebugPort = “unassigned”
$targetcomputer = “.”
$VMName = “”
$AutoAssign = “false”
$DebugOff = “false”
function funHelp()
{
$helpText=@"
DESCRIPTION:
NAME: synthdebug.ps1
Displays (and optionally sets) the debugport for synthetic debugging.
PARAMETERS:
-computerName Specifies the name of the computer upon which to run the script
-help prints help file
-vmname name of the VM of interest
-port (optional) ID of the channel to use for debugging
-debugoff
-autoassign
SYNTAX:
synthdebug.ps1 [-computerName targetcomputer] -vmname NameOfVM [-port PortNumber]
"@
$helpText
exit
}
foreach ($argument in $args)
{
parse commands with no following arguments
switch ($argument)
{
“?” {funHelp}
“help” {funHelp}
“-help” {funHelp}
“/?” {funHelp}
“-?” {funHelp}
“autoassign” {$AutoAssign = “true”}
“-autoassign” {$AutoAssign = “true”}
“/autoassign” {$AutoAssign = “true”}
“debugoff” {$DebugOff = “true”}
“-debugoff” {$DebugOff = “true”}
“/debugoff” {$DebugOff = “true”}
default {}
}
parse values that followed a switch
switch ($nextarg)
{
“vmname” {$VMName = $argument}
“-vmname” {$VMName = $argument}
“/vmname” {$VMName = $argument}
“port” {$DebugPort = $argument}
“-port” {$DebugPort = $argument}
“/port” {$DebugPort = $argument}
“-computername” {$targetcomputer = $argument}
default {}
}
$nextarg = $argument
}
if ($VMName -eq “”)
{
funHelp
}
#Get a VMManagementService object
$VMManagementService = gwmi -class “Msvm_VirtualSystemManagementService” -namespace “root\virtualization” -computername $targetcomputer
#Get the VM object that we want to modify
$query = “SELECT * FROM Msvm_ComputerSystem WHERE ElementName='” + $VMName + “'”
$VM = gwmi -query $query -namespace “root\virtualization” -computername $targetcomputer
#Get the VirtualSystemGlobalSettingData of the VM we want to modify
$query = “Associators of {$VM} WHERE AssocClass=MSVM_ElementSettingData ResultClass=Msvm_VirtualSystemGlobalSettingData”
$VMSystemGlobalSettingData = gwmi -query $query -namespace “root\virtualization” -computername $targetcomputer
Set a new debugport
if ($DebugPort -ne “unassigned”)
{
#Change the ElementName property
$VMSystemGlobalSettingData.DebugPort = $DebugPort
$VMSystemGlobalSettingData.DebugPortEnabled = 1
#Update the VM with ModifyVirtualSystem
$Result = $VMManagementService.ModifyVirtualSystem($VM.__PATH,$VMSystemGlobalSettingData.psbase.GetText(1))
}
Enable auto assigned debug ports
if ($AutoAssign -ne “false”)
{
#Change the ElementName property
$VMSystemGlobalSettingData.DebugPortEnabled = 2
#Update the VM with ModifyVirtualSystem
$Result = $VMManagementService.ModifyVirtualSystem($VM.__PATH,$VMSystemGlobalSettingData.psbase.GetText(1))
}
Turn off debugging
if ($DebugOff -ne “false”)
{
#Change the ElementName property
$VMSystemGlobalSettingData.DebugPortEnabled = 0
#Update the VM with ModifyVirtualSystem
$Result = $VMManagementService.ModifyVirtualSystem($VM.__PATH,$VMSystemGlobalSettingData.psbase.GetText(1))
}
$VMSystemGlobalSettingData
exit
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Petr Kurtin
Sent: Tuesday, November 6, 2012 4:59 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Hyper-V Kernel Debugging
please read new windbg help topic for Hyper-V role: “Setting Up Network Debugging of a Virtual Machine Host”
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Brandon Falk
Sent: Monday, November 05, 2012 7:18 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Hyper-V Kernel Debugging
I’ve decided to try out Hyper-V this week, and I’ve heard here and there that Hyper-V allows for really quick kernel debugging. Is this true? How do I go about kernel debugging ‘properly’ on Hyper-V?
-Brandon
— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer