Re: Help with debugging LD_PRELOADed shared C libraries

Russell Shaw
2006-07-14T01:22:43Z

Thomas Ackermann wrote:
> Hello,
> at first i asked at gcc-help, but it seems to be gdb-related:
>
> I have a problem to debug my shared C libary which i use to fix an
> existing binary.
> I am loading this library via LD_PRELOAD variable, but sometimes the
> programm crashes. Now i wan to find and fix the problem with gdb.
>
> Regardless how i prelaod the library for the gdb session, gdb always
> only gives "Cannot access memory at address ..." messages.
>
> I tried "export LD_PRELOAD=/.../mylib.so" and then started "gdb mybin
> core" or tried to set it within gdb: "set environment
> LD_PRELOAD /.../mylib.so" and then continue with "file mybin" and "core
> core", but:
>
> Program terminated with signal 11, Segmentation fault.
> #0 0x400cc9b8 in ?? ()
> #0 0x400cc9b8 in ?? ()
> End of crash report
>
> That should be outputs from "bt", "info locals", "info
> sharedlibrary" and "info frame".
>
> Here in detail:
>
> gdb mybin core
> <...>
> Program terminated with signal 11, Segmentation fault.
> Cannot access memory at address 0x4001738c
> #0 0x400cc9b8 in ?? ()
> (gdb) bt
> #0 0x400cc9b8 in ?? ()
> Cannot access memory at address 0xbfffeddc
> (gdb) info locals
> No symbol table info available.
>
> Both binary mybin and library mylib DO contain symbolic information as
> confirmed via "nm".
>
> The library was created with: "gcc -g3 -Wall -Wuninitialized
> -D_GNU_SOURCE -fPIC -shared -ldl -o mylib.so mylib.c"
>
> Can anybody give me a hint?

Whenever i've got a segfault that showed question marks:

> #0 0x400cc9b8 in ?? ()
> #0 0x400cc9b8 in ?? ()

i just restarted ddd/gdb, and then doing the same run will
result in meaningful function names.