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. Learn more about spike, vim editor, RISC-V GDB and OpenOCD!

  • 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. What are the commands used in debugging with RISC-V GDB?

  • 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. Read how RISC-V GDB and OpenOCD work together to establish a connection between the Microprocessor and Host PC.

  • TERMINAL 3: Open a new terminal and switch to spiking folder. Now start the gdb debugging session by running below command. What are the most used RISC-V GDB Commands?