Skip to content

[QEMU WIN] Integrating debugging to VSCode

Antonio Giacomelli edited this page May 10, 2025 · 36 revisions

🟦 Debugging with VS Code on Windows

This tutorial shows how to integrate VSCode with GDB+QEMU on Windows.


Using WSL

The easiest way is using the WSL subsystem.

  • In this case, I prefer connecting VSCode to the WSL (and having the source code in the subsystem instead of accessing a /mnt/ partition in Win).

  • Install the same packages as described for Debian-based Linux

  • For .json files, follow the same setup for macOS, replacing arm-none-eabi-gdb for gdb-multi-arch.

  • You call code from the WSL bash terminal. It will dispatch the VSCode installed on your Windows:

antonio@winbox:~$ uname -a
Linux winbox 5.15.167.4-microsoft-standard-WSL2 #1 SMP Tue Nov 5 00:21:55 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
antonio@winbox:~$ which code
/mnt/c/Users/anton/AppData/Local/Programs/Microsoft VS Code/bin/code

image VSCode forwarded to WSL and GDB server

The following steps work if you do not wish to use WSL for some reason

To be compatible with the Makefile, these steps install a UNIX-like bash environment for Windows (MSYS2), configure it, and set MSYS2 bash as the VSCode terminal.

Use MSYS2/MINGW64

  1. Install Chocolatey

At a Win PowerShell:

Set-ExecutionPolicy Bypass -Scope Process -Force; `
[System.Net.ServicePointManager]::SecurityProtocol = `
[System.Net.ServicePointManager]::SecurityProtocol -bor 3072; `
iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
  1. Install toolchain and QEMU
choco install gcc-arm-embedded
choco install msys2
choco install qemu

Configure MSYS2 as the VS Code Terminal

In VS Code:

  1. Open Settings
  2. Search for: terminal.integrated.profiles.windows
  3. Edit your settings.json:
"terminal.integrated.profiles.windows": {
  "MSYS2 Bash": {
    "path": "C:\\msys64\\usr\\bin\\bash.exe",
    "args": ["--login", "-i"],
    "env": {
      "MSYSTEM": "MINGW64",
      "CHERE_INVOKING": "1"
    }
  }
},
"terminal.integrated.defaultProfile.windows": "MSYS2 Bash"

Set PATH for ARM Toolchain in MSYS2

Edit your MSYS2 ~/.bashrc:

export PATH=$PATH:/c/ProgramData/chocolatey/bin  # adjust path if needed

Then reload:

source ~/.bashrc

Configure Debugging in VS Code

Install the extensions cortex-debug and C/C++.

Option 1: Using Cortex-Debug

Create .vscode/launch.json:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Debug RK0 (QEMU ARMv7-M)",
      "type": "cortex-debug",
      "request": "launch",
      "servertype": "external",
      "gdbPath": "arm-none-eabi-gdb", 
      "cwd": "${workspaceRoot}",
      "executable": "${workspaceRoot}/build/armv7m/rk0_demo.elf",
      "armToolchainPath": "C:/ProgramData/chocolatey/bin",
      "device": "Cortex-M3"
    }
  ]
}

Option 2: Using cppdbg

{
  "name": "Debug RK0 (cppdbg - ARMv7M)",
  "type": "cppdbg",
  "request": "launch",
  "program": "${workspaceRoot}/build/armv7m/rk0_demo.elf",
  "miDebuggerPath": "arm-none-eabi-gdb",
  "miDebuggerServerAddress": "localhost:1234",
  "cwd": "${workspaceRoot}",
  "stopAtEntry": false,
  "environment": [],
  "MIMode": "gdb",
  "setupCommands": [
    {
      "description": "Enable pretty-printing for GDB",
      "text": "-enable-pretty-printing",
      "ignoreFailures": true
    }
  ]
}

Running

  1. Start QEMU in Debug Mode
make qemu-debug
  1. Launch Debugger in VS Code

Open the Run panel and press F5.


UART + GDB integration VS Code attached to QEMU GDB server, UART output visible.