Difference between revisions of "DevGuide/GDB OpenOCD Debug"

From PaparazziUAV
Jump to: navigation, search
(JTAG adapters)
(Useful commands)
Line 27: Line 27:
 
# Now we can run the program which will stop at the break point we set.
 
# Now we can run the program which will stop at the break point we set.
 
#:<pre>continue</pre>
 
#:<pre>continue</pre>
 +
 +
=== Black Magic Probe ===
 +
# GDB for arm.
 +
#: Open GDB with the correct binary file
 +
#:<pre>/opt/paparazzi/arm-multilib/bin/arm-none-eabi-gdb ./var/AIRFRAME/ap/ap.elf</pre>
 +
#: Set Black Magic Probe as Target over the serial link (see ls /dev/ttyACM*):
 +
#:<pre>target extended-remote /dev/ttyACM0</pre>
 +
#: Probe via JTAG to get a list of devices:
 +
#:<pre>mon jtag_scan</pre>
 +
#: Attach to a device:
 +
#:<pre>attach 1</pre>
  
 
=== Useful commands ===
 
=== Useful commands ===
Line 39: Line 50:
 
* In some cases you may not be able to access some memory areas in the mcu, in that case you should try:
 
* In some cases you may not be able to access some memory areas in the mcu, in that case you should try:
 
*:<pre>set mem inaccessible-by-default off</pre>
 
*:<pre>set mem inaccessible-by-default off</pre>
 +
 +
Commands can often be issued without typing the entire command. Here are some commonly used commands; many of them can be invoked using only the first letter:
 +
(gdb) quit – exit the debugger
 +
(gdb) file – load an executable file
 +
(gdb) break line-number/function name -- Set a break-point on a line/at start of function
 +
(gdb) run <args> -- start running the program; if there are command-line arguments, put them after the run invocation
 +
(gdb) cont -- continue running, after a break
 +
(gdb) next -- Next program line (step over function calls)
 +
(gdb) step -- Step into function calls.
 +
(gdb) finish - Step out of the present function
 +
(gdb) print expression -- Show value of a variable or expression
 +
(gdb) list – List 10 lines of the program being debugged. The sixth line is the preset statement. Subsequent, consecutive entry of list will list the next 10 lines.
 +
(gdb) where – obtain a backtrace showing all function calls before the current statement
 +
(gdb) up – Move to the function that called the present function. Useful if your program crashes in a library function; use up to get to the last function call in your program
 +
(gdb) down – Reverses the action of up
 +
(gdb) delete – Removes breakpoint by number (see example following). If no number, all deleted.
 +
(gdb) kill – Terminates the program.
  
  
 
[[Category:Hardware]] [[Category:Software]] [[Category:Developer_Documentation]]
 
[[Category:Hardware]] [[Category:Software]] [[Category:Developer_Documentation]]

Revision as of 08:39, 4 September 2012

JTAG adapters

Recently some new JTAG adapters that use the FTDI2232 USB-parallel converter were introduced through OpenOCD (you can try your Wiggler with that, too). USB JTAG adapters include Floss-JTAG, Olimex or Amontec and also fine with Windows (Yagarto).

Also see DevGuide/OpenOCD for installation and configuration instructions.

Debugging with GDB over JTAG

Procedure

  1. Start openocd in a new shell since this process needs to remain running.
    To connect to the Lisa/L board run the command
    openocd -f interface/lisa-l.cfg -f board/lisa-l.cfg
    To connect to the Lisa/M board via FLOSS-JTAG run the command:
    openocd -f interface/flossjtag.cfg -f board/lisa-l.cfg
  1. Start GDB with an argument of the elf file created and uploaded to the board.
    If you programmed with the ap target then the command would be along the lines of
    /opt/paparazzi/arm-multilib/bin/arm-none-eabi-gdb var/<airframe>/ap/ap.elf
    Replace <airframe> with the name of the airframe that has been built.
  2. Now connect GDB to the board
    target remote localhost:3333
  3. Now we need to set some break points in the code.
    In this example the ap target was part of the rotorcraft and main.c contains the main program. Open rotorcraft sw/airborne/firmwares/rotorcraft/main.c and find a line at which you'd like to set a break point.
    break main.c:113
  4. Stop the currently running code
    monitor reset halt
  5. Reset the code back to the start
    monitor reset init
  6. Now we can run the program which will stop at the break point we set.
    continue

Black Magic Probe

  1. GDB for arm.
    Open GDB with the correct binary file
    /opt/paparazzi/arm-multilib/bin/arm-none-eabi-gdb ./var/AIRFRAME/ap/ap.elf
    Set Black Magic Probe as Target over the serial link (see ls /dev/ttyACM*):
    target extended-remote /dev/ttyACM0
    Probe via JTAG to get a list of devices:
    mon jtag_scan
    Attach to a device:
    attach 1

Useful commands

  • We probably want to ignore the interrupt calls for the moment so we can step through the code as it's being called. Note that we don't always want to do this. (STM32 command only)
    monitor cortex_m3 maskisr on
  • A stack trace can be printed with the command
    bt
  • show the variable of a variable
    print i2c1.status
  • Show (eXamine) the value of the 9 bytes hardware register at address 0x40005800 and show them in hex format:
    x/9x 0x40005800
  • In some cases you may not be able to access some memory areas in the mcu, in that case you should try:
    set mem inaccessible-by-default off

Commands can often be issued without typing the entire command. Here are some commonly used commands; many of them can be invoked using only the first letter:

(gdb) quit – exit the debugger
(gdb) file – load an executable file
(gdb) break line-number/function name -- Set a break-point on a line/at start of function
(gdb) run <args> -- start running the program; if there are command-line arguments, put them after the run invocation
(gdb) cont -- continue running, after a break
(gdb) next -- Next program line (step over function calls)
(gdb) step -- Step into function calls.
(gdb) finish - Step out of the present function
(gdb) print expression -- Show value of a variable or expression
(gdb) list – List 10 lines of the program being debugged. The sixth line is the preset statement. Subsequent, consecutive entry of list will list the next 10 lines.
(gdb) where – obtain a backtrace showing all function calls before the current statement
(gdb) up – Move to the function that called the present function. Useful if your program crashes in a library function; use up to get to the last function call in your program
(gdb) down – Reverses the action of up
(gdb) delete – Removes breakpoint by number (see example following). If no number, all deleted.
(gdb) kill – Terminates the program.