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.
# Original repo:
#git clone git@github.com:bnahill/PyCortexMDebug.git
# Does not work due to issue with "lxml"
# See: https://flameeyes.blog/2023/09/10/remote-debugging-with-gdb-part-3-swd/
# Use this:
git clone https://github.com/Flameeyes/PyCortexMDebug
# Another fork here: https://github.com/maksimdrachov/PyCortexMDebug
cd PyCortexMDebug
python setup.py install
.gdbinit
as follows:# Setup GDB to interpret in Python
pi
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
sys.path.extend(paths)
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
DWT()
LoadSVD()
libpython3.8.so
:sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install libpython3.8-dev
gdb
, we will see the following: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
arm-zephyr-eabi-gdb-py ./build/zephyr/zephyr.elf -tui -ex "tar ext:3333" -ex "load"
(gdb) source /home/legend27/PyCortexMDebug/scripts/gdb.py
(gdb) svd
(gdb) svd TCCO