diff options
author | Andrew Burgess <andrew.burgess@embecosm.com> | 2021-08-11 13:24:33 +0100 |
---|---|---|
committer | Andrew Burgess <andrew.burgess@embecosm.com> | 2021-09-28 12:21:22 +0100 |
commit | abbbd4a3e0ca51132e7fb31a43f896d29894dae0 (patch) | |
tree | 95373a55ae00731fc4a37d1f361bbd81314a7f5d /gdb/configure | |
parent | 890026e31759ae00c6bbb7eb41b5fe89580a256f (diff) | |
download | fsf-binutils-gdb-abbbd4a3e0ca51132e7fb31a43f896d29894dae0.zip fsf-binutils-gdb-abbbd4a3e0ca51132e7fb31a43f896d29894dae0.tar.gz fsf-binutils-gdb-abbbd4a3e0ca51132e7fb31a43f896d29894dae0.tar.bz2 |
gdb: use libbacktrace to create a better backtrace for fatal signals
GDB recently gained the ability to print a backtrace when a fatal
signal is encountered. This backtrace is produced using the backtrace
and backtrace_symbols_fd API available in glibc.
However, in order for this API to actually map addresses to symbol
names it is required that the application (GDB) be compiled with
-rdynamic, which GDB is not by default.
As a result, the backtrace produced often looks like this:
Fatal signal: Bus error
----- Backtrace -----
./gdb/gdb[0x80ec00]
./gdb/gdb[0x80ed56]
/lib64/libc.so.6(+0x3c6b0)[0x7fc2ce1936b0]
/lib64/libc.so.6(__poll+0x4f)[0x7fc2ce24da5f]
./gdb/gdb[0x15495ba]
./gdb/gdb[0x15489b8]
./gdb/gdb[0x9b794d]
./gdb/gdb[0x9b7a6d]
./gdb/gdb[0x9b943b]
./gdb/gdb[0x9b94a1]
./gdb/gdb[0x4175dd]
/lib64/libc.so.6(__libc_start_main+0xf3)[0x7fc2ce17e1a3]
./gdb/gdb[0x4174de]
---------------------
This is OK if you have access to the exact same build of GDB, you can
manually map the addresses back to symbols, however, it is next to
useless if all you have is a backtrace copied into a bug report.
GCC uses libbacktrace for printing a backtrace when it encounters an
error. In recent commits I added this library into the binutils-gdb
repository, and in this commit I allow this library to be used by
GDB. Now (when GDB is compiled with debug information) the backtrace
looks like this:
----- Backtrace -----
0x80ee08 gdb_internal_backtrace
../../src/gdb/event-top.c:989
0x80ef0b handle_fatal_signal
../../src/gdb/event-top.c:1036
0x7f24539dd6af ???
0x7f2453a97a5f ???
0x154976f gdb_wait_for_event
../../src/gdbsupport/event-loop.cc:613
0x1548b6d _Z16gdb_do_one_eventv
../../src/gdbsupport/event-loop.cc:237
0x9b7b02 start_event_loop
../../src/gdb/main.c:421
0x9b7c22 captured_command_loop
../../src/gdb/main.c:481
0x9b95f0 captured_main
../../src/gdb/main.c:1353
0x9b9656 _Z8gdb_mainP18captured_main_args
../../src/gdb/main.c:1368
0x4175ec main
../../src/gdb/gdb.c:32
---------------------
Which seems much more useful.
Use of libbacktrace is optional. If GDB is configured with
--disable-libbacktrace then the libbacktrace directory will not be
built, and GDB will not try to use this library. In this case GDB
would try to use the old backtrace and backtrace_symbols_fd API.
All of the functions related to writing the backtrace of GDB itself
have been moved into the new files gdb/by-utils.{c,h}.
Diffstat (limited to 'gdb/configure')
-rwxr-xr-x | gdb/configure | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/gdb/configure b/gdb/configure index f0b1af4..7c8335f 100755 --- a/gdb/configure +++ b/gdb/configure @@ -636,6 +636,8 @@ LIBCTF LTLIBBABELTRACE LIBBABELTRACE HAVE_LIBBABELTRACE +LIBBACKTRACE_LIB +LIBBACKTRACE_INC HAVE_NATIVE_GCORE_HOST NAT_GENERATED_FILES XM_CLIBS @@ -925,6 +927,7 @@ with_tcl with_tk with_x enable_sim +enable_libbacktrace with_babeltrace with_libbabeltrace_prefix with_libbabeltrace_type @@ -1601,6 +1604,8 @@ Optional Features: gcc is used --enable-ubsan enable undefined behavior sanitizer (auto/yes/no) --enable-sim link gdb with simulator + --enable-libbacktrace use libbacktrace to write a backtrace after a fatal + signal. --enable-libctf Handle .ctf type-info sections [default=yes] --enable-unit-tests Enable the inclusion of unit tests when compiling GDB @@ -18659,6 +18664,33 @@ _ACEOF fi +# Setup possible use of libbacktrace. +# Check whether --enable-libbacktrace was given. +if test "${enable_libbacktrace+set}" = set; then : + enableval=$enable_libbacktrace; case "${enableval}" in + yes) enable_libbacktrace=yes ;; + no) enable_libbacktrace=no ;; + *) as_fn_error $? "bad value ${enableval} for --enable-libbacktrace option" "$LINENO" 5 ;; +esac +else + enable_libbacktrace=yes +fi + + +if test "${enable_libbacktrace}" == "yes"; then + LIBBACKTRACE_INC="-I$srcdir/../libbacktrace/ -I../libbacktrace/" + LIBBACKTRACE_LIB=../libbacktrace/.libs/libbacktrace.a + +$as_echo "#define HAVE_LIBBACKTRACE 1" >>confdefs.h + +else + LIBBACKTRACE_INC= + LIBBACKTRACE_LIB= +fi + + + + # Check for babeltrace and babeltrace-ctf # Check whether --with-babeltrace was given. |