Learn with SHAKTI

Debugging a 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, a risc-v gdb, spike and OpenOCD are required. spike simulates a real hardware and OpenOCD is needed to enter into debug mode in the hardware. Before starting, "Debugging with gdb". Please ensure that, the example.elf is generated as described in previous section.

STEP 1: Building the boot image.


The necessary files to compile and simulate a C 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. 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.