Skip to content

Debugging with GDB

Eric Ponce edited this page Nov 22, 2017 · 1 revision

This pages covers some rough instruction to using OpenOCD combined with arm-none-eabi-gdb to debug your code

.gdbinit file

A .gdbinit file should be placed within the main directory of your project. It contains setup commands for gdb. A fairly sufficient example is shown below:

# connect to the remote debug server
target remote localhost:3333

# firmware .elf file
file bin/uart_hal.elf

# reset and halt the device
mon reset halt

# set a breakpoint at main()
tbreak main

# continue until break
c

# define reset within gdb
define reset
	mon reset halt
end

Starting the debug server

To get started debugging, you need to create a debug server that GDB can use to communicate with the device. OpenOCD takes care of that for us with the following command (assuming your configuration file is correct)

openocd -s $(OCD_DIR) -f openocd.cfg -c "init" -c "reset halt" -c 'sleep 10'

Connecting to the debug server

Now that you've got a server and config file, start gdb with the following command

arm-none-eabi-gdb -x ./$(GDBINIT)

Actually debugging

http://darkdust.net/files/GDB%20Cheat%20Sheet.pdf

Last Edited by Eric Ponce on 11/22/17

Clone this wiki locally