How to debug the QCopter with OpenOCD and GDB

Starting debugging up

  1. Start the copter connected to the JTAG adapter.
  2. Run "start_jtag.bat" to start OpenOCD in console mode. This will reset and halt the copter. (There may be the error "Error: arm_jtag.c:38 arm_jtag_set_instr_error_handler(): setting the new JTAG instruction failed, debugging is likely to be broken". I've not looked into this issue but it can be ignored atm.)

  3. Connect to the running console via telnet on localhost, port 4444. (e.g. use putty)

  4. In the bin folder run the gdb with the elf file of the copter firmware: "arm-elf-gdb core-flash.elf"

  5. Attach the gdb to OpenOCD by typing the following command in the gdb console:

    target remote localhost:3333
    

    The gdb console will show you the line of the source code in which the copter is haltet. E.g. the output looks like this:

    (gdb) target remote localhost:3333
    Remote debugging using localhost:3333
    spi_init_transfer (outbuf=0x200400 "          ", inbuf=0x201d82 "", len=1,    handler=<value optimized out>) at src/com/spi_master.c:76
    76              AT91C_BASE_SPI->SPI_TPR = (unsigned int) outbuf;
    
  6. Let the copter firmware continue by typing the following command int the gdb console:

    continue
    

Halt and debug

Now you can stop the copter at any time by typing the command "halt" in the OpenOCD console or by pressing CTRL-C in the gdb console. The you can inspect the current line in code in the gdb console. To continue the program type "continue" in the gdb console. Use the commands "up" and "down" in the gdb console, when the copter is halted to inspect the stack (to see which function has called the current function).

Reseting the copter

If you have to reset the copter because you want to debug a starting sequence then halt the program first. Restart the copter and type "continue" in the gdb console (even if the program is running already).

Shutting the debugger down

  1. Halt the copter CTRL-c and quit the gdb console with the quit command.

  2. Type "shutdown" in the OpenOCD console. ("exit" will only close the telnet session but leaves OpenOCD running)

gdbHowto (last edited 2010-09-25 10:53:03 by StefanEngelke)