Learn with SHAKTI

Debugging a C Program with GDB


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


STEP 1: Building the executables.


sample.c is a C file in spiking folder. Run the below commands to compile sample.c. This will generate sample.elf. sample.c is a simple c file with while loops and if statements.

bootload.elf is the bootimage. Run the below command to generate it:

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


STEP 2: Debugging


If you face any error while execution, Please refer FAQ section.

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

  • TERMINAL 2: Open another terminal. Now move to spiking folder and run OpenOCD with the appropriate configuration file. 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 move to spiking folder. Now start the gdb debugging session by running the below command. What are the most used RISC-V GDB Commands?