TipsAndTricks/DebugNativeRecipeWithGdb: Difference between revisions
Joshua Lock (talk | contribs) (Add tip for debugging binaries produced by native recipes with gdb) |
(update by Alex) |
||
(4 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
=How to debug native recipes with gdb= | =How to debug native recipes with gdb= | ||
I recently had the need to debug a crash in a native binary that a layer was | I recently had the need to debug a crash in a native binary that a layer I was working on invokes during the build. | ||
To debug the crash with gdb I had to do two things; 1) have the build system generate a binary with debug symbols and 2) | To debug the crash with gdb I had to do two things; 1) have the build system generate a binary with debug symbols and 2) not have them stripped during installation to sysroot. | ||
To debug | To enable debug symbols, usually one needs to add "-g" to the list of compiler flags. Unforunately how this is done is specific to each project - you need to inspect the | ||
source code tree and look for clues. For autoconf-based projects adding to CFLAGS environment variable is enough. | |||
After the build has completed, inspect the compilation log to verify that -g is indeed there. | |||
To ensure that the binaries in the sysroot don't have their debugging symbols stripped you need to set <code>INHIBIT_SYSROOT_STRIP = "1"</code> in your local.conf | |||
Alternatively you might want to only inhibit stripping for specific recipes, this can be achieved using recipe OVERRIDES such as: | Alternatively you might want to only inhibit stripping for specific recipes, this can be achieved using recipe OVERRIDES such as: | ||
Line 15: | Line 19: | ||
Note: you'll need to ensure any binaries you wish to debug are (re-)staged into the sysroot after changing this setting. | Note: you'll need to ensure any binaries you wish to debug are (re-)staged into the sysroot after changing this setting. | ||
For more information on the gdb commands above see the gdb manual section [https://sourceware.org/gdb/current/onlinedocs/gdb/Files.html#Files "Commands to Specify Files"] | For more information on the gdb commands above see the gdb manual section [https://sourceware.org/gdb/current/onlinedocs/gdb/Files.html#Files "Commands to Specify Files"] |
Latest revision as of 14:16, 15 February 2017
How to debug native recipes with gdb
I recently had the need to debug a crash in a native binary that a layer I was working on invokes during the build.
To debug the crash with gdb I had to do two things; 1) have the build system generate a binary with debug symbols and 2) not have them stripped during installation to sysroot.
To enable debug symbols, usually one needs to add "-g" to the list of compiler flags. Unforunately how this is done is specific to each project - you need to inspect the source code tree and look for clues. For autoconf-based projects adding to CFLAGS environment variable is enough.
After the build has completed, inspect the compilation log to verify that -g is indeed there.
To ensure that the binaries in the sysroot don't have their debugging symbols stripped you need to set INHIBIT_SYSROOT_STRIP = "1"
in your local.conf
Alternatively you might want to only inhibit stripping for specific recipes, this can be achieved using recipe OVERRIDES such as:
INHIBIT_SYSROOT_STRIP_pn-swupd-server-native = "1"
I used the former as it allowed me to be certain of having all debugging symbols available.
Note: you'll need to ensure any binaries you wish to debug are (re-)staged into the sysroot after changing this setting.
For more information on the gdb commands above see the gdb manual section "Commands to Specify Files"