Debugging Your WPD Driver with Visual Studio 8

WPD drivers are based on the Windows Driver Foundation (WDF) – User-Mode Driver Framework (UMDF) platform. UMDF drivers provide greater stability and security than kernel-mode drivers while providing comparable performance. And, UMDF drivers allow the use of user-mode debuggers such as Visual Studio 8. (Debugging a driver in user-mode tends to be faster than debugging in kernel-mode because an error only affects the current process rather than the entire computer.)

General Visual Studio 8 Debugging Tips
Once your driver is installed, you can create a debugging project in Visual Studio 8 by following these steps:

1.       Open Visual Studio 8 and select “File/New/Project from Existing Code…” menu.

2.       Follow the steps in the “Welcome to the Create Project form Existing Code Files Wizard” (specifying the language, the location of your driver source files, a project name, and so on).

3.       Open your newly created project.

4.       Select the “Debug/Attach to Process…” menu and then choose WudfHost.exe in the list of Available Processes that appears in the “Attach to Process” dialog.

Once you complete the above steps, you can begin setting breakpoints in your driver’s source code and debug your driver.

Tips for Debugging WPD Driver Initialization Code
A WPD driver’s initialization code (for example, the code found in WpdBaseDriver::Initialize() in the two WPD sample drivers that ship with the Windows Driver Kit), executes during the installation of your driver. In order to debug this initialization code, you’ll need to accomplish the following tasks:

1.       Create a debugging project in Visual Studio 8 (as described in the previous section).

2.       Open an instance of regedit.exe and specify a delay period (in seconds) for the WudfHost.exe process. This delay is specified using the following key: \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\WUDF\Services\{193a…}\HostProcessDbgBreakOnStart

3.       Force the WUDFHost.exe process to reload.  This can be done in a couple of ways, depending on what your device configuration is:

a)   From Device Manager, Disable and then Enable your device's WPD devnode

b)   If your device has a physical connection to the PC, unplug and then re-reconnect your device.

4.       Upon driver reload, start Visual Studio 8, open your debug project, and attach to the WudfHost.exe process.   As a side effect, you may see Device Manager hanging when you reload the driver, while WudfHost.exe is waiting for a debugger to connect.

The delay which you set for the …\HostProcessDbgBreakOnStart value provides the necessary time to start the debugger prior to the installation of your driver. (For example, a value of 0x00000040 would delay the installation for 64 seconds.) This delay allows you time to attach to the process, set a breakpoint in your initialization code, and begin debugging.

For more information about the HostProcessDbgBreakOnStart value, refer to this MSDN topic.

Update [August 7, 2009]:  The WDF team has provided an excellent tool that makes debugging both kernel mode and user mode WDF drivers much easier. The WDFVerifier is available in the Windows Driver Kit (WDK). For details, refer to the WDFVerifier MSDN page. In addition, we recommend these in-depth posts by Bob Kjelgaard, an SDET from the WDF team, covering basic and advanced usages of WdfVerifier:


This posting is provided "AS IS" with no warranties, and confers no rights.

Comments (0)

Skip to main content