Debugging shared libraries with gdb (451 Views)
Reply
Occasional Visitor tlo
Occasional Visitor
tlo
Posts: 3
Registered: ‎11-29-2012
Message 1 of 5 (451 Views)
Accepted Solution

Debugging shared libraries with gdb

[ Edited ]

HP-UX 11.23, ia64.

 

I am using gcc 4.7.0 and gdb 7.5, and I am having problems debugging anything inside a shared library.

 

The creation of the shared library:

  $ gcc -c -g3 -fPIC hello.c

  $ gcc -g3 -shared hello.o -o libhello.so


I then compiled and linked an executable against it:

  $ gcc -c -g3 foo.c

  $ gcc -g3 foo.o -lhello -L.

 

 

I can post the contents of hello.c and foo.c if necessary, but I doubt it will matter. The main() in foo.c calls a function in hello.c

 

When I try to set a breakpoint in gdb, I get this:

(gdb) break hello
Function "hello" not defined.
Make breakpoint pending on future shared library load? (y or [n])

 

Even if I answer yes, the breakpoint is never reached, even though the function is called on execution.  Also, if I attempt to step through the statements in foo.c, it steps over the call into the shared library.

 

I have also attempted chatr +dbg enable on both the resulting binary and the shared object itself, with the same result. What do I need to do in order to debug a shared library?

 

 

P.S.This thread has been moved from HP-UX>System Administration to HP-UX > languages- HP Forums Moderator

 

 

Acclaimed Contributor
Dennis Handly
Posts: 25,283
Registered: ‎03-06-2006
Message 2 of 5 (437 Views)

Re: Debugging shared libraries with gdb

>I am using gcc 4.7.0 and gdb 7.5,

 

What happens when you used HP's gdb instead?

 

>What do I need to do in order to debug a shared library?

 

Use HP's gdb instead, that works.

Occasional Visitor tlo
Occasional Visitor
tlo
Posts: 3
Registered: ‎11-29-2012
Message 3 of 5 (416 Views)

Re: Debugging shared libraries with gdb

The gdb 6.3 from the HP WDB package does work. Functions from shared libraries are not immediately recognizable (.i.e., I still get "Breakpoint deferred until a shared library containing "hello" is loaded."), but that's only a minor annoyance as program execution actually does break when it hits that function.

 

Thanks for the assistance.

 

Acclaimed Contributor
Dennis Handly
Posts: 25,283
Registered: ‎03-06-2006
Message 4 of 5 (411 Views)

Re: Debugging shared libraries with gdb

>Thanks for the assistance.

 

If you are happy with your answers, please click on the Kudos star.

 

Was there a particular feature you wanted in gdb 7.5?

Occasional Visitor tlo
Occasional Visitor
tlo
Posts: 3
Registered: ‎11-29-2012
Message 5 of 5 (406 Views)

Re: Debugging shared libraries with gdb

Was there a particular feature you wanted in gdb 7.5?

 

Nothing in particular, no. Python scripting support and reversible debugging would be nice, but they're not essential.

 

I just downloaded and installed the latest version I could find on the Porting and Archive Centre, rather than going to the official HP packages. It usually works for everything else, and since the debugger seemed to work and run, I expected that it would work for more or less all features.  I knew that HP had some people working on GDB and other open source projects a long time ago (I was a member of the initial HP Caliper team on the same floor as you, Dennis), but I didn't know that it continued to this day.

 

The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.