How to Debug a Release Version Without a Symbol Table in the GDB?

Because of memory limitations, the release I want to publish cannot contain symbol tables.So I stripped the symbol table after cargo build --release.

The specific steps are as follows:

cargo build --release
//Generate a symbol table.
objcopy --only-keep-debug target/release/example_bin symbol_info.dbg
/ / Stripping symbol table
strip target/release/example_bin

Run the release version.
./target/release/example_bin

GDB debugging:
gdb -s symbol_info.dbg -e target/release/example_bin

Here's the output:

root@szxphis00500:/home/temp/release_debug# gdb -s release_info.dbg -e target/release/release_debug att 16848
GNU gdb (Ubuntu 8.1.1-0ubuntu1) 8.1.1
Copyright (C) 2018 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 "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://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"...
att: No such file or directory.
Attaching to process 16848
Reading symbols from /home/temp/release_debug/target/release/release_debug...(no debugging symbols found)...done.
Reading symbols from /lib/libachk.so...done.
Reading symbols from /lib/x86_64-linux-gnu/libgcc_s.so.1...(no debugging symbols found)...done.
Reading symbols from /lib/x86_64-linux-gnu/librt.so.1...Reading symbols from /usr/lib/debug//lib/x86_64-linux-gnu/librt-2.27.so...done.
done.
Reading symbols from /lib/x86_64-linux-gnu/libpthread.so.0...Reading symbols from /usr/lib/debug/.build-id/68/f36706eb2e6eee4046c4fdca2a19540b2f6113.debug...done.
done.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Reading symbols from /lib/x86_64-linux-gnu/libdl.so.2...Reading symbols from /usr/lib/debug//lib/x86_64-linux-gnu/libdl-2.27.so...done.
done.
Reading symbols from /lib/x86_64-linux-gnu/libc.so.6...Reading symbols from /usr/lib/debug//lib/x86_64-linux-gnu/libc-2.27.so...done.
done.
Reading symbols from /lib64/ld-linux-x86-64.so.2...Reading symbols from /usr/lib/debug//lib/x86_64-linux-gnu/ld-2.27.so...done.
done.
Reading symbols from /lib/x86_64-linux-gnu/libnss_compat.so.2...Reading symbols from /usr/lib/debug//lib/x86_64-linux-gnu/libnss_compat-2.27.so...done.
done.
Reading symbols from /lib/x86_64-linux-gnu/libnss_nis.so.2...Reading symbols from /usr/lib/debug//lib/x86_64-linux-gnu/libnss_nis-2.27.so...done.
done.
Reading symbols from /lib/x86_64-linux-gnu/libnsl.so.1...Reading symbols from /usr/lib/debug//lib/x86_64-linux-gnu/libnsl-2.27.so...done.
done.
Reading symbols from /lib/x86_64-linux-gnu/libnss_files.so.2...Reading symbols from /usr/lib/debug//lib/x86_64-linux-gnu/libnss_files-2.27.so...done.
done.
0x00007f7ff2531d21 in __GI___nanosleep (requested_time=0x7ffcef77b280, remaining=0x7ffcef77b280) at ../sysdeps/unix/sysv/linux/nanosleep.c:28
28      ../sysdeps/unix/sysv/linux/nanosleep.c: No such file or directory.
(gdb) bt
#0  0x00007f7ff2531d21 in __GI___nanosleep (requested_time=0x7ffcef77b280, remaining=0x7ffcef77b280) at ../sysdeps/unix/sysv/linux/nanosleep.c:28
#1  0x0000562161561750 in ?? ()
#2  0x0000562161551169 in ?? ()
#3  0x00005621615511d3 in ?? ()
#4  0x00005621615511a9 in ?? ()
#5  0x000056216156526b in ?? ()
#6  0x0000562161551192 in ?? ()
#7  0x00007f7ff1f4cbf7 in __libc_start_main (main=0x562161551170, argc=1, argv=0x7ffcef77b438, init=<optimized out>, fini=<optimized out>,
    rtld_fini=<optimized out>, stack_end=0x7ffcef77b428) at ../csu/libc-start.c:310
#8  0x000056216155106a in ?? ()

with objcopy --only-keep-debug you can move debug info to a separate file, and then add a reference to it with objcopy --add-gnu-debuglink.

With this I've had success with lldb using the debug symbols from an external file.

2 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.