Learn with SHAKTI

Debugging an ASM Program with GDB


Debugging with GDB is more of a real time debugging, where the debugger takes control of the system. To debug a C or Assembly program, RISC-V GDB, spike and OpenOCD are required.

  • spike simulates a real hardware.
  • OpenOCD (Open On-Chip Debugger) is open-source software that is needed to enter into the debug mode in the hardware.

Before starting Debugging session with RISC-V GDB. Please ensure example.elf is generated as described in previous section.


STEP 1: Building the boot image.


The necessary files to compile and simulate an ASM program in spike environment, are hosted inside the spiking folder. Please ensure spiking folder is downloaded.

To update the spiking folder:

bootload.S:


There is an assembly file named bootload.S in the spiking folder. This assembly file contains the actual boot code for our simulation. The example.elf is the application, which we are going to debug using GDB.

The contents of the bootload.S is listed below.

Compiling bootload.S and generating bootload.elf:

Note: Alternatively, "make" command can be used to compile all programs in the spiking folder

STEP 2: Debugging


If you face any error while running any command, Please refer FAQ section

  • TERMINAL 1: Open a new terminal and move to spiking folder. Now, run spike telling it to listen for OpenOCD.

  • TERMINAL 2: In a new terminal, move to spiking folder. Here, run OpenOCD with the spike.cfg.

  • TERMINAL 3: Open a new terminal and switch to spiking folder. Now start the gdb debugging session by running below command.