9

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)
...    
2
  • Have you tried using si (step instruction) instead of s? Commented Oct 23, 2012 at 18:34
  • si seems to step into libopenjpeg, but I don't think it's useful at that point... I need line numbers, variable names, or something to help me understand what the code is doing. So I think gdb is missing the debugging info... I want to know how to connect it to the .so file or gdb. Here is my test with "si": pastebin.com/yaCBkZr4 Commented Oct 24, 2012 at 10:07

2 Answers 2

12

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.