> ## Documentation Index
> Fetch the complete documentation index at: https://dragonwingdocs.qualcomm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 使用 GNU 调试器调试

默认情况下,构建会启用 GNU 调试器(GDB)。如果未启用 GDB,请在 Linux 主机计算机上按照以下步骤启用 GDB:

1. 转到 `meta-qcom-distro/recipes-products/packagegroups` 目录并打开 `packagegroup-qcom-utilities.bb` 文件。
2. 修改 `packagegroup-qcom-utilities.bb` 文件,在软件包列表中添加 `gdb`。如果软件包名称已存在于软件包列表中,请跳过此步骤。
3. 确保构建包含调试符号。
   ```text theme={null}
   readelf --debug-dump=decodedline <BIN_FILE>
   ```
   或
   ```text theme={null}
   objdump --syms <BIN_NAME> | grep -i 'debug'
   ```
   如果未启用调试符号,请使用 `-g` 编译器标志编译所有所需的可执行文件或共享库。要将调试符号推送到设备,请参阅[配置调试符号](https://dragonwingdocs.qualcomm.com/System/Debug-Subsystem/configure-debug-symbols#configure-debug-symbols)。
4. 重新编译并将构建烧录到设备上。
5. 要使用 GDB 调试,请在设备上运行以下命令:
   ```text theme={null}
   gdb --pid 502
   ```
   **示例输出:**
   ```text theme={null}
   gdb: warning: Couldn't determine a path for the index cache directory.
   Copyright (C) 2022 Free Software Foundation, Inc.
   License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
   This is free software: you are free to change and redistribute it.
   There is NO WARRANTY, to the extent permitted by law.
   Type "show copying" and "show warranty" for details.
   This GDB was configured as "aarch64-qcom-linux".
   Type "show configuration" for configuration details.
   For bug reporting instructions, please see:
   <https://www.gnu.org/software/gdb/bugs/>.
   Find the GDB manual and other documentation resources online at:
      <http://www.gnu.org/software/gdb/documentation/>.
   For help, type "help".
   Type "apropos word" to search for commands related to "word".
   Attaching to process 502
   Reading symbols from /usr/bin/tqftpserv...
   (No debugging symbols found in /usr/bin/tqftpserv)
   Reading symbols from /usr/lib/libqrtr.so.1...
   (No debugging symbols found in /usr/lib/libqrtr.so.1)
   Reading symbols from /lib/libc.so.6...
   Reading symbols from /lib/.debug/libc.so.6...
   Reading symbols from /lib/ld-linux-aarch64.so.1...
   Reading symbols from /lib/.debug/ld-linux-aarch64.so.1...
   [Thread debugging using libthread_db enabled]
   Using host libthread_db library "/lib/libthread_db.so.1".
   0x0000ffffab00ef34 in __GI___select (nfds=4, readfds=0xffffc2ec14f8, writefds=0x0, exceptfds=0x0, timeout=0x0) at ../sysdeps/unix/sysv/linux/select.c:69
   69      ../sysdeps/unix/sysv/linux/select.c: No such file or directory.
   (gdb)
   (gdb)
   (gdb)
   (gdb)
   ```

## **GDB 命令**

下表列出了常用的 GDB 命令。

**表:常用 GDB 命令**

|              **命令**              |       **描述**      |
| :------------------------------: | :---------------: |
|            `(gdb) bt`            |     提供当前线程的回溯     |
|       `(gdb) info threads`       |    列出当前已知线程的 ID   |
|         `(gdb) thread 2`         |      切换到线程 2      |
|           `(gdb) where`          | 显示当前行号以及当前正在执行的函数 |
| `(gdb) thread apply all bt full` |     提供所有线程的回溯     |
|    `(gdb) info sharedlibrary`    |    列出所使用的共享库的名称   |
|         `(gdb) info reg`         |     列出 CPU 寄存器    |

有关更多信息,请参阅 [Linux 手册页](https://man7.org/linux/man-pages/man1/gdb.1.html)。
