Відлагодження з GDB
The GNU DeBugger (GDB) comes installed with the compiler toolchain in the form of the arm-none-eabi-gdb
binary. Налагоджувач читає символи відладки у файлі формату виконання ELF щоб зрозуміти статичну та динамічну структуру пам'яті прошивки PX4. To access the PX4 autopilot microcontroller, it needs to connect to a Remote Target, which is provided by a SWD debug probe.
Плин інформації виглядає таким чином:
sh
Developer <=> GDB <=> GDB Server <=> Debug Probe <=> SWD <=> PX4 Autopilot.
Швидкий старт
Для початку сеансу налагодження вам зазвичай потрібно:
- Need a specialized SWD debug probe.
- Find and connect to the SWD debug port. You may need a debug adapter.
- Налаштувати та запустити зонд налагодження для створення сервера GDB.
- Запустити GDB та під'єднатись до сервера GDB як віддаленої цілі.
- Налагоджувати прошивку інтерактивно.
Дивіться документацію зонда налагодження для додаткової інформації як налаштувати з'єднання для налагодження:
- SEGGER J-Link: commercial probe, no built-in serial console, requires adapter.
- Black Magic Probe: integrated GDB server and serial console, requires adapter.
- STLink: best value, integrated serial console, adapter must be soldered.
Рекомендуємо використовувати J-Link з адаптером налагодження Pixhawk або STLinkv3-MINIE зі спеціально спаяним кабелем.
Після підключення ви можете використовувати звичайні команди GDB, такі як:
continue
to continue program executionrun
to start from the beginningbacktrace
to see the backtracebreak somewhere.cpp:123
to set a breakpointdelete somewhere.cpp:123
to remove it againinfo locals
to print local variablesinfo registers
to print the registers
Consult the GDB documentation for more details.
TIP
To avoid having to type all commands to connect in GDB each time, you can write them into ~/.gdbinit
.
Наступні кроки
Ви під'єднали контролер польоту до налагоджувального зонда SWD!
Наступні розділи пояснюють, як розпочати налагодження на цільовій платформі:
Відео
The following video provides an overview of the tooling available for advanced debugging of PX4 via GDB. It was presented at the PX4 Developer Conference 2023.
Overview: The inspection tools built into PX4 via Mavlink Shell (NSH) as well as interpretation of the PX4 uLog after a flight require PX4 to still be functioning. However, the most problematic bugs often manifest themselves in a (partially) hanging or crashed system. Therefore, we present the open-source Embedded Debug Tools project, which manages and configures probe, debugging and analysis tools for PX4 and NuttX:
- Debug interfaces (SWD) and the associated debug probes (J-Link, STLink) and libraries (JLinkGDBServer, OpenOCD).
- How to install and configure
arm-none-eabi-gdb(-py3)
for debugging your ELF. - Commonly used GDB commands and scripts.
- Advanced GDB scripting via its Python API.
- Inspection of NuttX RTOS component internals: tasks, semaphores, scheduler.
- Inspecting peripheral state with CMSIS-SVD files and custom visualizations.
- Coredumping for post-mortem debugging via CrashDebug.
- Hardfault analysis in a live system and via the hardfault log.
- Remote GDB scripting via the Machine Interface.
- Automated HiL testing of PX4 via combined GDB and NSH scripting.
- ITM profiling over SWO pin using Orbuculum.
- Thread/IRQ/Workqueue/Heap visualization and latency analysis using perfetto.
- High-bandwidth ETM tracing over TRACE pins: J-Trace and ORBtrace mini.
- We conclude with an overview of interesting related project and an outlook on the future of PX4 debugging.
Вбудовані інструменти налагодження
The Embedded Debug Tools connect several software and hardware debugging tools together in a user friendly Python package to more easily enable advanced use cases for ARM Cortex-M microcontrollers and related devices.
Ця бібліотека організовує запуск та налаштування апаратних зондів налагодження та зондів трасування, налагоджувачів, логічних аналізаторів, генераторів сигналу та надає інструменти аналізу, перетворювачі та плагіни для отримання суттєвого розуміння стану програмного та апаратного забезпечення під час або після виконання.
The emdbg
library contains many useful GDB plugins that make debugging PX4 easier. It also provides tools for profiling PX4 in real-time.