Using SVD file in GDB for Cortex-m debugging

Using SVD file in GDB for Cortex-m debugging

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.

Installation

  • Download and install the following project from PyCortexMDebug.
  • Setup the file .gdbinit as the following
# 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)

# load svd tools
from cmdebug.svd_gdb import LoadSVD
from cmdebug.dwt_gdb import DWT
DWT()
LoadSVD()

Example

Here is an example of using it in the project of PSOC5. In the case of PSoc5, the PSoC Creators generate a specific SVD according to system configuration. Type the following in the GDB console

(gdb) svd_load /path/to/pso5/project/Project.cydsn/codegentemp/Project.svd

And to display the registers type.

Loading SVD file /path/to/pso5/project/Project.cydsn/codegentemp/Project.svd...
(gdb) svd
Available Peripherals:
        BAT_ANA_TEMP_adc:   SAR ADC
        Timer_2:            No description available
        ADC_SAR_Seq_1_SAR:  SAR ADC
        UART_1:             UART
        USBFS_1:            USBFS
        Timer_1:            No description available
        AD5204_CTL_CS:      No description available

(gdb)

Here are the registers of Timer_1

(gdb) svd/x Timer_1
Registers in Timer_1:
        Timer_1_GLOBAL_ENABLE:    0x01  PM.ACT.CFG
        Timer_1_CONTROL:          0x01  TMRx.CFG0
        Timer_1_CONTROL2:         0x81  TMRx.CFG1
        Timer_1_CONTROL3_:        0x00  TMRx.CFG2
        Timer_1_PERIOD:         0x0C1B  TMRx.PER0 - Assigned Period
        Timer_1_COUNTER:        0x066E  TMRx.CNT_CMP0 - Current Down Counter Value
Comments
comments powered by Disqus