TipsAndTricks/DebugNativeRecipeWithGdb: Difference between revisions

From Yocto Project
Jump to navigationJump to search
mNo edit summary
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 calling during the build.
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) teach gdb where to look for files.
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) teach gdb where to look for files.


To debug a native binary with gdb you first need to ensure that the binaries in the sysroot don't have their debugging symbols stripped.
To debug a native binary with gdb you first need to ensure that the binaries in the sysroot don't have their debugging symbols stripped.
You can do this for all staged binaries by setting INHIBIT_SYSROOT_STRIP = "1" in your local.conf
You can do this for all staged binaries by setting <code>INHIBIT_SYSROOT_STRIP = "1"</code> in your <pre>local.conf</pre>


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 <pre>OVERRIDES</pre> such as:


  INHIBIT_SYSROOT_STRIP_pn-swupd-server-native = "1"
  INHIBIT_SYSROOT_STRIP_pn-swupd-server-native = "1"
Line 25: Line 25:


  set solib-search-path /path/to/build/tmp/sysroots/x86_64-linux/usr/lib:/usr/lib64/:/lib
  set solib-search-path /path/to/build/tmp/sysroots/x86_64-linux/usr/lib:/usr/lib64/:/lib
With those commands run I was ready to operate gbd as usual and quickly narrowed down the cause of the crash.


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"]

Revision as of 11:57, 27 June 2016

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) teach gdb where to look for files.

To debug a native binary with gdb you first need to ensure that the binaries in the sysroot don't have their debugging symbols stripped.

You can do this for all staged binaries by setting 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.

Once you have binaries with debugging symbols you can start a gdb session and teach it where to look for files.

I pointed gdb at our native sysroot with (from within a gsb session):

set sysroot /path/to/build/tmp/sysroots/x86_64-linux

As native binaries can also link to host libraries, especially libc, I also told gdb to look in both the sysroot and the host for shared libraries:

set solib-search-path /path/to/build/tmp/sysroots/x86_64-linux/usr/lib:/usr/lib64/:/lib

With those commands run I was ready to operate gbd as usual and quickly narrowed down the cause of the crash.

For more information on the gdb commands above see the gdb manual section "Commands to Specify Files"