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:

CMD . /opt/ros/humble/setup.sh && \
    /opt/sysroot/app/build/global_navigation
  1. Install gdb by adding this line to the end of your app's Dockerfile:

RUN apt update && apt install -y gdb && \
    apt clean && \
    rm -rf /var/lib/apt/lists/*
  1. Compile with debugging flags, for use with gdb by adding -DCMAKE_BUILD_TYPE=Debug to cmake in your dockerfile:

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
  1. Copy the source code from the build stage of your Dockerfile:

COPY --from=build-stage /opt/sysroot/app/src /opt/sysroot/app/src
  1. Start a container with the docker image of the modified app:

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

root@2fdac2bb88c5:/# source /opt/ros/humble/setup.sh
  1. Start gdb with your executable:

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

Last updated