Using PyCortexMDebug with Zephyr RTOS

In this blog I will shortly document how to setup PyCortexMDebug with the Zephyr toolchain (specifically arm-zephyr-eabi-gdb).

OS: Ubuntu 22.04

For a more general introduction, see this blog (which I will borrow from heavily).

Using SVD files during debugging session of a Cortex-M microcontroller allows easy access to system registers value. The SVD file is an XML file that contains the necessary information about the register’s name and address. Using SVD, the IDE can read the value of system registers and display it during the debugging session. I will show here how to use SVD during GDB debug session.


  1. Download PyCortexMDebug
# Original repo:
#git clone 
# Does not work due to issue with "lxml"
# See:
# Use this:
git clone
# Another fork here:
  1. Install the module
cd PyCortexMDebug
python install
  1. Setup .gdbinit as follows:
# Setup GDB to interpret in Python
import os,subprocess,sys
# Execute a Python using the user's shell and pull out the sys.path (for site-packages)
paths = subprocess.check_output('python -c "import os,sys;print(os.linesep.join(sys.path).strip())"',shell=True).decode("utf-8").split()
# Extend GDB's Python's search path
home_directory = os.path.expanduser("~")
sys.path.append(os.path.join(home_directory, 'PyCortexMDebug'))  # Important to add the correct path!

# load svd tools
from cmdebug.svd_gdb import LoadSVD
from cmdebug.dwt_gdb import DWT
  1. If we now try to use it, you will most likely get the following error:

  1. Intall
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install libpython3.8-dev
  1. If we now try to launch gdb, we will see the following:

  1. Add safe path in your config
cd ~/.config
mkdir gdb
cd gdb
touch gdbinit
nano gdbinit 
# Add the following line to gdbinit:
add-auto-load-safe-path /home/legend27/fluxgrip_software/.gdbinit
  1. Launch gdb:
arm-zephyr-eabi-gdb-py ./build/zephyr/zephyr.elf -tui -ex "tar ext:3333" -ex "load"
(gdb) source /home/legend27/PyCortexMDebug/scripts/
(gdb) svd
(gdb) svd TCCO

1 Like