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

# Debug using GNU debugger

By default, the build enables the GNU debugger (GDB). If GDB is not enabled, follow these steps on the Linux host computer to enable GDB:

1. Go to the `meta-qcom-distro/recipes-products/packagegroups` directory and open the `packagegroup-qcom-utilities.bb` file.
2. Modify the `packagegroup-qcom-utilities.bb` file to add `gdb` in the package list. Skip this step if the package name is already present in the package list.
3. Ensure that the build incorporates the debug symbols.
   ```text theme={null}
   readelf --debug-dump=decodedline <BIN_FILE>
   ```
   Or
   ```text theme={null}
   objdump --syms <BIN_NAME> | grep -i 'debug'
   ```
   If the debug symbols aren't enabled, compile all required executables or shared libraries with the `-g` compiler flag. To push debug symbols to the device, see [Configure debug symbols](https://dragonwingdocs.qualcomm.com/System/Debug-Subsystem/configure-debug-symbols#configure-debug-symbols).
4. Recompile and flash the build on the device.
5. To debug using GDB, run the following command on the device:
   ```text theme={null}
   gdb --pid 502
   ```
   **Sample output:**
   ```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 commands**

The following table lists the commonly used GDB commands.

**Table: Common GDB commands**

|            **Command**           |                                   **Description**                                   |
| :------------------------------: | :---------------------------------------------------------------------------------: |
|            `(gdb) bt`            |                      Provides a backtrace of the current thread                     |
|       `(gdb) info threads`       |                       Lists the IDs of currently known threads                      |
|         `(gdb) thread 2`         |                                 Switches to thread 2                                |
|           `(gdb) where`          | Shows the current line number and the function in which you are currently executing |
| `(gdb) thread apply all bt full` |                         Provides a backtrace of all threads                         |
|    `(gdb) info sharedlibrary`    |                       Lists the names of shared libraries used                      |
|         `(gdb) info reg`         |                               Lists the CPU registers                               |

For more information, see [Linux manual page](https://man7.org/linux/man-pages/man1/gdb.1.html).
