|
| 1 | +# Debugging Refloat |
| 2 | + |
| 3 | +The package can be debugged in GDB the standard way if the package symbols are loaded from the package .elf file. |
| 4 | + |
| 5 | +## 1. Start the OpenOCD server |
| 6 | + |
| 7 | +Start the OpenOCD server using the configuration file from the repository: |
| 8 | +```sh |
| 9 | +$ openocd -f openocd.cfg |
| 10 | +``` |
| 11 | + |
| 12 | +Keep this process running in its own terminal. |
| 13 | + |
| 14 | +## 2. Connect to OpenOCD server with GDB |
| 15 | + |
| 16 | +An ARM version of GDB is needed, and it needs to have a working Python scripting support. |
| 17 | + |
| 18 | +In a second terminal, change to the `refloat` repo directory. It contains the `.gdbinit` file with commands to load the package .elf and for debuging it. |
| 19 | + |
| 20 | +The correct firmware .elf file is needed, it's built along with the firmware binary for the ESC in question: |
| 21 | +```sh |
| 22 | +$ arm-none-eabi-gdb path/to/bldc/build/ESC/ESC.elf -ex 'target extended-remote localhost:3333' |
| 23 | +``` |
| 24 | + |
| 25 | +## 3. Load the package .elf |
| 26 | + |
| 27 | +Once inside GDB, load the symbols for the package itself: |
| 28 | +```gdb |
| 29 | +(gdb) load-package-elf src/package_lib.elf |
| 30 | +``` |
| 31 | + |
| 32 | +## 4. Debug the package |
| 33 | + |
| 34 | +You can now use package symbols, set breakpoints, decode package frames in stack traces etc. The package has a global `data` struct, managed and made available through the firmware. The `.gdbinit` file provides a helper command to access this data easily at any point: |
| 35 | +- Type `data` to print the contents of the whole struct |
| 36 | +- Type `data PROPERTY` to print any property of the data struct, even nested, e.g.: |
| 37 | + ```gdb |
| 38 | + (gdb) data imu |
| 39 | + $1 = { |
| 40 | + pitch = 21.3763847, |
| 41 | + balance_pitch = 21.2723846, |
| 42 | + roll = -1.01360452, |
| 43 | + yaw = 32.8550987, |
| 44 | + pitch_rate = 0.0440952145, |
| 45 | + flywheel_pitch_offset = 0, |
| 46 | + flywheel_roll_offset = 0 |
| 47 | + } |
| 48 | + (gdb) data imu.pitch |
| 49 | + $2 = 21.3763847 |
| 50 | + ``` |
| 51 | +_Note: A recent enough GCC version is needed for compiling the package, otherwise reading the `Data` struct in GDB won't work (it doesn't work with GCC 7)._ |
0 commit comments