Debugging Windows 10 IoT Core on Raspberry Pi2 using WinDbg

WinDbg provides a powerful tool to debug Windows 10 IoT Core on Raspberry Pi2. Since the debugger runs over serial cable debugging network issues is also possible.

ms-iot.github.io

Hardware

Raspberry Pi2
USB - TTL cable

Software

Visual Studio 2015
PowerShell
Edge Browser
Windows 10 IoT Core 10586 image

Install

Download and install WDK and WinDbg

Check USB-Serial Device driver

Make sure that the USB-Serial device driver is working. I had to change the driver on my PC.

Make sure the cable is connected correctly to Raspberry Pi

Enable Serial debugging on Raspberry Pi

Create connection to Raspberry Pi using PowerShell (run as Administrator) and enable serial debugging

bcdedit -dbgsettings serial

bcdedit -debug on

Example app

In this example the app is really simple looping app.

bool doSomething(int *counter)
{
    std::cout << "Hello, World!" << std::endl;

    *counter++;
    if (*counter == 10000000) return false;
    else return true;
}

int main(int argc, char **argv)
{
    int counter = 0;
    bool b = true;
    while (b)
    {
        b = doSomething(&counter);
    }
}

Deploy the app

If you have a fresh IoT Core image create first an Universal app and deploy it to Raspberry Pi with Visual Studio. That will install the needed Remote Debugger components to Raspberry Pi.

Open Browser to Raspberry Pi and start Remote Debugger

Set the debugging properties in Visual Studio project Debug/AppName Properties...

Deploy app Build/Deploy AppName

Init connection

I noticed that kd initializes the serial connection better than windbg. So I run it before windbg to make sure connection is ok.

Open Command Prompt

cd C:\Program Files (x86)\Windows Kits\10\Debuggers\x86

kd -k com:port=1,baud=921600

Power up Raspberry Pi

press Ctrl-C to break the debugger

press q to exit kd

Debug app

Start app

Create connection to Raspberry Pi using PowerShell (run as administrator) and start the app.

Note that you need to have .\ before the app name

Start WinDbg

windbg -k com:port=1,baud=921600

Enter !process 0 0 ConsoleApplication1.exe in the Command window to find process ID

Enter .process /i processID to switch context

Enter g to proceed

Load the application symbols File/Symbol File Path... Ctrl+S

Enter .context to set User-Mode address context

Enter !peb to display a formatted view of the information in the process environment block (PEB).

Memory

Breakpoints

There are several ways to set breakpoints:

  1. kd interface bp ConsoleApplication1!doSomething
  2. Either on source or disassemply window select line and press the hand icon
  3. Use menu option Edit/Breakpoints...