# Debugging Apps with gdb

## How to analyze an app with GDB

The instructions below use the **global\_navigation** example application for the Auterion SDK. The method explained is valid for any C++ application for AuterionOS.

1. Remove the CMD line for the executable you would like to debug from your Dockerfile so you can start it manually:

```docker
CMD . /opt/ros/humble/setup.sh && \
    /opt/sysroot/app/build/global_navigation
```

2. Install gdb by adding this line to the end of your app's Dockerfile:

```docker
RUN apt update && apt install -y gdb && \
    apt clean && \
    rm -rf /var/lib/apt/lists/*
```

3. Compile with debugging flags, for use with gdb by adding `-DCMAKE_BUILD_TYPE=Debug` to cmake in your dockerfile:

```docker
RUN . /opt/sysroot/opt/ros/humble/setup.sh && \
    cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=/Toolchain_$TARGETARCH.cmake 
    -DCMAKE_BUILD_TYPE=Debug && cmake --build build
```

4. Copy the source code from the build stage of your Dockerfile:

```docker
COPY --from=build-stage /opt/sysroot/app/src /opt/sysroot/app/src
```

5. Start a container with the docker image of the modified app:

```bash
root@skynode-111261566:~# docker run -it 0d47ef72670b

root@2fdac2bb88c5:/# source /opt/ros/humble/setup.sh
```

6. Start gdb with your executable:

```bash
root@2fdac2bb88c5:/# gdb /opt/sysroot/app/build/global_navigation
GNU gdb (Ubuntu 12.1-0ubuntu1~22.04.2) 12.1
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-linux-gnu".
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"...
Reading symbols from /opt/sysroot/app/build/global_navigation...
```

7. Add breakpoints and run your executable:

```
(gdb) break main
Breakpoint 1 at 0x2d28: file /opt/sysroot/app/src/global_navigation.cpp, line 61.

(gdb) run
Starting program: /opt/sysroot/app/build/global_navigation
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.auterion.com/app-development/app-framework/debugging-apps-with-gdb.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
