Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using gdb to step into 3rd party functions with shared libraries

I am using gdb and some shared libraries. I can get gdb to step into my own shared library, but not a 3rd party one.

When using gdb, I expect "s" (step) to step into the 3rd party library and show me the lines it is executing inside these opj_* functions instead of just going to the next line in my own shared library code.

I'm pretty sure I'm just missing something during compiling, having to do with linking (getting gcc to pass some debug flags to ld), but I don't know what it is, or something when running gdb to tell it where the debug symbols are.

Here are the details:

I have the openjpeg library, debug info and devel packages installed.

# zypper search -si openjpeg
Loading repository data...
Reading installed packages...

S | Name                     | Type    | Version   | Arch   | Repository
--+--------------------------+---------+-----------+--------+-----------
i | libopenjpeg2_0           | package | 2.0.0-1.4 | x86_64 | packman   
i | libopenjpeg2_0-debuginfo | package | 2.0.0-1.4 | x86_64 | packman   
i | openjpeg2-devel          | package | 2.0.0-1.4 | x86_64 | packman   

# rpm -ql libopenjpeg2_0
/usr/lib64/libopenjpeg.so.2.0
/usr/lib64/libopenjpeg.so.2.0.0

# rpm -ql openjpeg2-devel
/usr/include/openjpeg-2.0
/usr/include/openjpeg-2.0/openjpeg.h
/usr/lib64/libopenjpeg.so
/usr/lib64/openjpeg-2.0
/usr/lib64/openjpeg-2.0/OpenJPEGConfig.cmake
/usr/lib64/openjpeg-2.0/OpenJPEGTargets-release.cmake
/usr/lib64/openjpeg-2.0/OpenJPEGTargets.cmake

# rpm -ql libopenjpeg2_0-debuginfo
/usr/lib/debug
/usr/lib/debug/.build-id
/usr/lib/debug/.build-id/85/f8603c75aadee0bd66653332d7ce16d0292752
/usr/lib/debug/.build-id/85/f8603c75aadee0bd66653332d7ce16d0292752.debug
/usr/lib/debug/usr/lib64/libopenjpeg.so.2.0.0.debug

I have a shared library libjna_openjpeg linked to libopenjpeg.

I have a test program "pathtest" linked to libopenjpeg and libjna_openjpeg

I compiled each with "gcc -g ..." and also tried "gcc -ggdb ..."

gcc -ggdb -c -fpic -I/usr/include/openjpeg-2.0 jna_openjpeg.c -lopenjpeg
gcc -ggdb -shared -o libjna_openjpeg.so jna_openjpeg.o -lopenjpeg
gcc -ggdb -I/usr/include/openjpeg-2.0 -L. -o pathtest pathtest.c -ljna_openjpeg -lopenjpeg

A snippet of my shared library code with some comments removed:

opj_stream_t* p_stream = opj_stream_create_default_file_stream( p_file, p_is_read_stream );

opj_codec_t *p_decompressor = opj_create_decompress(CODEC_J2K);

// my bug I want to debug is here... this always returns 0
p_image =  opj_decode( p_decompressor, p_stream );

running gdb

$ gdp pathtest

...

(gdb) s
52          opj_codec_t *p_decompressor = opj_create_decompress(CODEC_J2K);
(gdb) s
59          p_image =  opj_decode( p_decompressor, p_stream );
(gdb) s

gdb version

# gdb --version
GNU gdb (GDB) SUSE (7.3-41.1.2)
...    
like image 878
Peter Avatar asked Oct 23 '12 15:10

Peter


2 Answers

can you try by enabling step-mode on ?

(gdb) set step-mode on

This causes the step command to stop at the first instruction of a function which contains no debug line information(usually 3rd party like libc) rather than stepping over it.

like image 197
Gyan Gupta Avatar answered Sep 21 '22 17:09

Gyan Gupta


You didn't give your gdb version. Apparently this could have been a bug in gdb, because I had the same problem with 7.0.1 but upgrading to 7.3.50 fixed it.

like image 21
Jester Avatar answered Sep 22 '22 17:09

Jester