Click here to Skip to main content
Click here to Skip to main content

Kernel-Mode Debugging in a VM using Visual Studio 2012

By , 16 Feb 2013
 

Introduction

This article is about how to setup Kernel-Mode debugging in a VM using Visual Studio 2012. This article will be helpful for people new to driver development that wish to create, build, deploy, and debug a simple "HelloKernel". project. 

Background 

The setup process can be divided to three parts:  

  • Setting up the Virtual Machine 
  • Setting up Visual Studio 2012 
  • Setting up your HelloKernel Project 

Each part will be explained step by step.  

How to Setup the Virtual Machine 

The Virtual Machine setup was tested on VMWare 9.0 running Windows 7 x64 OS.

  • Create a new VM, use default settings (tested on VmWare, Win7 x64)
  • Add a serial port to the VM, follow these steps:
    • Right click VM -> Settings -> Add -> Serial Port -> Output to named pipe
    • Named pipe = \\.\pipe\com_2
    • First Combobox = The end is the server
    • Second Combobox = The other end is an application
    • Connect at power on = Checked
    • Finish
    • Yield CPU on poll = Checked
  • In the VM, in an elevated Command Prompt window, enter the following commands:
    • bcdedit /debug on
    • bcdedit /dbgsettings serial debugport:2 baudrate:115200
  • In Windows, search for "Manage advanced sharing settings":
    • -Set "Turn on file and printer sharing"
    • -Set "Turn off password protected sharing"
  • In Windows, search for "Computer Management":
    • -Local Users and Groups -> Users:
    • -Administrator -> Right Click -> Properties -> Uncheck Account is disabled
    • -Administrator -> Right Click -> Set Password -> Set your password
  • Reboot the VM

How to Setup Visual Studio 2012  

  • Install Visual Studio 2012 and WDK 8.
  • On the main toolbar, press Driver-> Test -> Configure Computers -> Add New Computer:
    • Computer name = VM name
    • Select Provision computer and choose debugger settings
    • Next
    • Connection Type = Serial
    • Pipe = Checked
    • Reconnect = Checked
    • Port = \\.\pipe\com_2
    • Target Port = com2
    • Next -> Finish

(Don't worry if Status is Undetermined)

  • You may be prompt for Username\Password, enter Administrator\YourPassword
  • Important! Currently Visual Studio 2012 has a weird defect that causes the steps above to fail if your Windows username has spaces in it, The active username must have no spaces!

How to Setup Your HelloKernel Project 

  • Use the following tutorial to create your HelloKernel project: http://msdn.microsoft.com/en-us/library/windows/hardware/hh439665(v=vs.85).aspx
  • In order to debug your project do the following: -Press F5 -When VS12 changes to DebugMode, on the main toolbar press Debug -> Break All -In the "Debugger Immediate Window" write the following commands:
    • -bu HelloKernel!DriverEntry (tells the debugger to break on DriverEntry)
    • -g (Tells the debugger to continue).
  • Your code should break on DriverEntry, and you can start debugging

Summary 

I hope this article will help people new to driver development getting started quickly.

It may seem straight forward, but I must say I encountered many problems trying to setup my environment, with nearly no useful and complete help found on the web. 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Michael Engstler
Team Leader
Israel Israel
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 4memberMathew D28 Apr '13 - 3:25 
Not much explanatory but it is worth than having nothing. And I finally achieved the same but one problem is there.
 
In Debug one windows is showing named as "No Source Available". What is this? and what should come here?

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 16 Feb 2013
Article Copyright 2013 by Michael Engstler
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid