Microsoft

Microsoft Docs

Overview

Debugging USB drivers is essential for ensuring reliable communication between Windows and USB devices. This guide walks you through the tools, techniques, and best practices for diagnosing and fixing common USB driver issues.

Prerequisites

  • Windows 10, version 1809 or later
  • Latest Windows SDK
  • WinDbg Preview (installed from Microsoft Store)
  • USB device under test with driver source available

Set up WinDbg

Install WinDbg Preview and configure symbol paths:

set _NT_SYMBOL_PATH=srv*C:\Symbols*https://msdl.microsoft.com/download/symbols
!symfix C:\Symbols
.sympath

Capture USB traffic

Use the built‑in usbview tool or the logusb kernel driver to capture traffic.

Using LogUSB

logusb -start MyCapture.etl
# Perform the actions that trigger the issue
logusb -stop

Convert the ETL file to a readable format with tracerpt:

tracerpt MyCapture.etl -o MyCapture.txt -of text

Analyze logs

Open the ETL file in WinDbg:

windbg -z MyCapture.etl

Typical commands:

!usb -list
!usb -showdev
!usb -view

Sample code

Minimal skeleton for a KMDF USB client driver:

#include <wdf.h>
#include <usb.h>

DRIVER_INITIALIZE DriverEntry;
EVT_WDF_DRIVER_DEVICE_ADD EvtDeviceAdd;

NTSTATUS
DriverEntry(
    _In_  PDRIVER_OBJECT  DriverObject,
    _In_  PUNICODE_STRING RegistryPath)
{
    WDF_DRIVER_CONFIG config;
    WDF_DRIVER_CONFIG_INIT(&config, EvtDeviceAdd);
    return WdfDriverCreate(DriverObject, RegistryPath, WDF_NO_OBJECT_ATTRIBUTES, &config, WDF_NO_HANDLE);
}

NTSTATUS
EvtDeviceAdd(
    _In_    WDFDRIVER       Driver,
    _Inout_ PWDFDEVICE_INIT DeviceInit)
{
    WDFDEVICE device;
    NTSTATUS status;

    UNREFERENCED_PARAMETER(Driver);
    WdfDeviceInitSetDeviceType(DeviceInit, FILE_DEVICE_UNKNOWN);
    status = WdfDeviceCreate(&DeviceInit, WDF_NO_OBJECT_ATTRIBUTES, &device);
    return status;
}

References