[Bug symtab/24810] New: add-symbol-file for shared lib has no effect

vries at gcc dot gnu.org sourceware-bugzilla@sourceware.org
Mon Jul 15 16:08:00 GMT 2019


https://sourceware.org/bugzilla/show_bug.cgi?id=24810

            Bug ID: 24810
           Summary: add-symbol-file for shared lib has no effect
           Product: gdb
           Version: HEAD
            Status: NEW
          Severity: normal
          Priority: P2
         Component: symtab
          Assignee: unassigned at sourceware dot org
          Reporter: vries at gcc dot gnu.org
  Target Milestone: ---

I.

Consider test sources main.c:
...
#include <stddef.h>
extern void foo (int *p);
int
main ()
{
  foo (NULL);
  return 0;
}
...

and foo.c:
...
void
foo (int *p)
{
  *p = 1;
}
...


II.

If we compile it to one executable a.out:
...
$ gcc -g foo.c main.c
...

and create an executable b.out without debug info, and c.out without debuginfo
but with debuginfo linked using .gnu_debuglink:
...
$ objcopy --only-keep-debug a.out a.debug
$ objcopy --strip-debug a.out b.out
$ objcopy --add-gnu-debuglink=a.debug b.out c.out
...

then when running the exec without debuginfo, we can load the symbol-file with
the linked debuginfo, and get a better backtrace:
...
$ gdb -batch b.out -ex r -ex bt -ex 'symbol-file c.out' -ex bt

Program received signal SIGSEGV, Segmentation fault.
0x00000000004004a3 in foo ()
#0  0x00000000004004a3 in foo ()
#1  0x00000000004004ba in main ()
#0  0x00000000004004a3 in foo (p=0x0) at foo.c:4
#1  0x00000000004004ba in main () at main.c:6
...


III.

Now using the same sources, let's build an executable and a shared library:
...
$ pwd=$(pwd -P)
$ gcc -c -fPIC foo.c -g
$ gcc -shared -o libfoo.so foo.o -g
$ gcc main.c -lfoo -L$pwd -Wl,-rpath=$pwd -g
...

and create a libfoo without debug info:
...
$ cp libfoo.so libfoo.orig.so
$ objcopy --only-keep-debug libfoo.so libfoo.so.debug
$ objcopy --strip-debug libfoo.so libfoo.so.stripped
$ objcopy --add-gnu-debuglink=libfoo.so.debug libfoo.so.stripped
libfoo.so.with-gnu-debuglink
...

Now, when when running with the shared lib without debuginfo, we can load the
symbol-file with the linked debuginfo, but we do not get a better backtrace:
...
$ cp libfoo.so.stripped libfoo.so
$ ./gdb -batch a.out -ex r -ex bt -ex 'add-symbol-file
libfoo.so.with-gnu-debuglink' -ex bt

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7bd5596 in foo () from /data/gdb_versions/devel/libfoo.so
#0  0x00007ffff7bd5596 in foo () from /data/gdb_versions/devel/libfoo.so
#1  0x0000000000400585 in main () at main.c:6
add symbol table from file "libfoo.so.with-gnu-debuglink"
#0  0x00007ffff7bd5596 in foo () from /data/gdb_versions/devel/libfoo.so
#1  0x0000000000400585 in main () at main.c:6
...

The same if we use libfoo.orig.so as symbol file.

The same if we run symbol-file a.out before add-symbol-file.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the Gdb-prs mailing list