Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug shared libraries compiled with debug information

I'm compiling a program with debug simbols that links to a shared library (liballegro) also compiled with debug symbols. When I try to step into a function of this shared library I can't see any code.

file myBin 
mybin: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=d4133ef127e81ffb007c4c17e10f4ddaefac6a0f, with debug_info, not stripped

file lib/liballegro-debug.so
liballegro-debug.so.5.2.2: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=dd75ca87e0ed86832ed02a1c40548a055ad4f551, with debug_info, not stripped

GDB shows how this lib is loaded with debug information:

(gdb) info shared
From                To                  Syms Read   Shared Object Library
0x00007ffff7dd9b40  0x00007ffff7df5110  Yes (*)     /lib64/ld-linux-x86-64.so.2
0x00007ffff7a5a0d0  0x00007ffff7b84591  Yes         correct/path/to/liballegro-debug.so
0x00007ffff76ffd60  0x00007ffff7778eef  Yes (*)     /usr/lib/libm.so.6
0x00007ffff74e1640  0x00007ffff74eefb1  Yes (*)     /usr/lib/libpthread.so.0
[...]

So I put a breakpoint in a function call who lives in the shared library (al_load_bitmap):

90      level->tileset.parent = al_load_bitmap(filename);

The source code of al_load_bitmap is in the file path/to/src/bitmap_io.c which is listed in the output of gdb info sources

And step into it:

(gdb) si
0x0000555555555f00 in al_load_bitmap@plt ()

At this point I can't figure how to see the source code of this function, as list comand show nothing.

How can I debug what happens inside this function?

PD: I tried also with lldb and is the same result, so I'm missing something.

Thank you.

like image 770
Bungow Avatar asked Jul 19 '17 09:07

Bungow


People also ask

How can I tell if a program was compiled with debug symbols?

To check if there's debug info inside the kernel object, you can add the following at the end of the objdump command: | grep debug . If this string is found, you know the kernel object contains debug information. If not, then it's a "clean" kernel object.

What is a debug library?

This debugging library helps you understand, or debug, the execution of applications and dependencies. Although the type of information displayed using this library is expected to remain constant, the exact format of the information might change slightly from release to release.

How do you know if binary is debug or Release?

If it is debug, it will display all the actual source code call you do. If it is release, it will just display the founded symbol from the symbol table.


1 Answers

al_load_bitmap@plt is the PLT stub (located in the main program, not the shared object), which does not have debugging information. You need to step over several instructions, then you'll reach the actual function, which hopefully has debugging information. You may also encounter the dynamic linker if lazy binding is active (it can be disabled with the LD_BIND_NOW=1 environment variable setting).

For these reasons, it is much easier to use the s (step) command to enter the function (if the called function has debugging information).

There are some cases when file reports the presence of debugging information, but you still don't get useful behavior from GDB (such as line numbers or local variable access). That's because there are several types of debugging information, and some distributions/developers perform partial stripping or debuginfo separation, leaving only the bare minimum to generate backtraces in the ELF file (which is what file reports as not stripped).

like image 138
Florian Weimer Avatar answered Oct 10 '22 22:10

Florian Weimer