title: using gdb to step into 3rd party functions with shared libraries
body: <p>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.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p><strong>Here are the details:</strong></p>
  
  <p>I have the openjpeg library, debug info and devel packages installed.</p>
  
  <pre><code># 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
  </code></pre>
  
  <p>I have a shared library libjna_openjpeg linked to libopenjpeg.</p>
  
  <p>I have a test program "pathtest" linked to libopenjpeg and libjna_openjpeg</p>
  
  <p>I compiled each with "gcc -g ..." and also tried "gcc -ggdb ..."</p>
  
  <pre><code>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
  </code></pre>
  
  <p>A snippet of my shared library code with some comments removed:</p>
  
  <pre><code>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 );
  </code></pre>
  
  <p>running gdb</p>
  
  <pre><code>$ 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
  </code></pre>
  
  <p>gdb version</p>
  
  <pre><code># gdb --version
  GNU gdb (GDB) SUSE (7.3-41.1.2)
  ...    
  </code></pre>