title: Cannot Debug Shared Library - Symbols Not Loading Properly
body: <p>I am currently writing a small library, and I want to check it for leaks (among other things); however, for some reason, <code>gdb</code> is not loading the library symbols. I have read many other posts on here (and various other places on the internet) about this, however, I cannot seem to find a solution. Here is what is going on:</p>
  
  <p>I am compiling the shared library with the following flags (these are included in both the final shared library as well as all object files):</p>
  
  <pre><code>CFLAGS=-Wall -O0 -g -fPIC
  </code></pre>
  
  <p>Likewise, I am compiling the binary <code>memtest</code> (the client application for the library) to check for memory leaks and such with these flags</p>
  
  <pre><code>CFLAGS=-Wall -O0 -g
  </code></pre>
  
  <p>Now, I inserted a NULL pointer into the library to test if I could trace through it and "debug" the pointer (i.e. it's making it crash). So I try to run it through gdb, but it's a no go. The output of <code>info sharedlibrary</code> is the same for both the executable and the core:</p>
  
  <pre><code>(gdb) info sharedlibrary
  From        To          Syms Read   Shared Object Library
  ... Some libraries I am not worried about debugging...
  0x00d37340  0x00d423a4  Yes (*)     /home/raged/MyLIB/memtest/../lib/libMyLIB.so.0 &lt;--- My lib
  .... and some more....
  (*): Shared library is missing debugging information.
  </code></pre>
  
  <p>As you can see, it's not loading the debug information. I am uncertain as to why this is. I have built and linked everything with the <code>-g</code> flag, and I even try <code>-ggdb</code> and <code>-g3</code> but nothing seems to work properly. When I load in a core dump, this is what I see:</p>
  
  <pre><code>...some libs...
  Reading symbols from /home/raged/MyLIB/memtest/../lib/libMyLIB.so.0...done.
  Loaded symbols for /home/raged/MyLIB/memtest/../lib/libMyLIB.so.0
  Reading symbols from /usr/lib/libstdc++.so.6...(no debugging symbols found)...done.
  ...some more libs...
  </code></pre>
  
  <p>Notice how my library does not give a <code>(no debugging symbols found)</code> error - anyone have any ideas why? As I said before, I am unable to debug this through running the program <code>gdb ./memtest</code> or through debugging the core file.</p>
  
  <p>Thanks for your help.</p>
  
  <p><strong>EDIT</strong> It may also be important to note, that (if you didn't realize by path) this library is a local shared library (i.e. I'm using <code>-Wl,-rpath</code> to link/load it)</p>
  
  <p><strong>EDIT2</strong> It seems my version of GDB was out-of-date. Now, I have updated to the latest version from the CVS server (I have also tried latest release <code>version 7.2</code>) and it can "load" symbols. My <code>info sharedlibrary</code> now reads this:</p>
  
  <pre><code>0x00e418b0  0x00e4be74  Yes         /home/raged/MyLIB/memtest/../lib/libMyLIB.so.0
  </code></pre>
  
  <p>However, I am still unable to step through any functions (in the shared library) - anyone have any ideas?</p>
  
  <p><strong>EDIT3</strong> I have also tried to step through linking against a <em>static</em> library (libMyLIB.a) but it still isn't working. My OS is CentOS 5.6; does anyone know of any issues with this system? Also, just another confirmation that my symbols are being loaded (it just can't step through any shared lib function for some reason)</p>
  
  <pre><code>(gdb) sharedlibrary MyLIB
  Symbols already loaded for /home/raged/MyLIB/memtest/../lib/libMyLIB.so.0
  </code></pre>