# 使用 GDB 调试

GNU DeBugger(GDB) (opens new window)是用编译器工具链安装的形式为二进制arm-none-eabi-gdb。 调试器读取ELF文件内的调试富豪,以了解PX4固件的静态和动态内存布局。 要访问PX4自动驾驶仪微控制器,需要连接到远程目标 (opens new window),这是由SWD 调试探测器提供的。

信息流看起来像这样:

Developer <=> GDB <=> GDB Server <=> Debug Probe <=> SWD <=> PX4 Autopilot.

# 快速入门

要启动调试会话,您通常需要:

  1. 需要特定的SWD 调试探针
  2. 查找并连接到 SWD 调试端口 您可能需要一个调试适配器
  3. 配置并启动调试探测来创建 GDB 服务。
  4. 启动GDB并作为远程目标连接到 GDB 服务。
  5. 以交互方式调试您的固件。

See the debug probe documentation for details on how to setup your debug connection:

  • 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.

We recommend using the J-Link with the Pixhawk Debug Adapter or the STLinkv3-MINIE with a soldered custom cable.

Once connected, you can use the usual GDB commands such as:

  • continue to continue program execution
  • run to start from the beginning
  • backtrace to see the backtrace
  • break somewhere.cpp:123 to set a breakpoint
  • delete somewhere.cpp:123 to remove it again
  • info locals to print local variables
  • info registers to print the registers

Consult the GDB documentation (opens new window) for more details.

提示

To avoid having to type all commands to connect in GDB each time, you can write them into ~/.gdbinit.

# Next Steps

You've now connected the flight controller to an SWD debug probe!

The following topics explain how to start on-target debugging:

# Embedded Debug Tools

The Embedded Debug Tools (opens new window) 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 library orchestrates the launch and configuration of hardware debug and trace probes, debuggers, logic analyzers, and waveform generators and provides analysis tools, converters, and plugins to provide significant insight into the software and hardware state during or after execution.

The emdbg library contains many useful GDB plugins (opens new window) that make debugging PX4 easier. It also provides tools for profiling PX4 in real-time (opens new window).