Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Debugging shared libraries?

Status
Not open for further replies.

DZH

Programmer
Apr 12, 2002
26
ZA
I would like to be able to set a breakpoint in a function contained within a shared library. I am using GVD and GDB under Solaris. I have compiled the shared libraries with the -g option enabled.
The aim is to start an application which links to the shared library to debugged. Even if the application was not compiled with the -g option enabled. What's the best way of achieving this?
 
Start your application under the debugger and immediately set the breakpoint to the function you want to debug in libc. Let the program run,when it hits the breakpoint it will give U the prompt,and you can debug line by line.
If it doesnt work try setting the breakpoint for the function through which the application enters the library.

I assmume you ar ensuring that Ur new libraries are being used by setting LD_LIBRARY_PATH etc.

cheers

amit
crazy_indian@lycos.com

to bug is human to debug devine
 
One possible problem is that, when the debugger is lauch, the dynamic (shared) libraries are not loaded until you run your program.
Code:
$ gdb myProg
(gdb) b fprintf
Breakpoint 1 (deferred) at "fprintf" ("fprintf" was not found).
Breakpoint deferred until a shared library containing "fprintf" is loaded.

I do not know if all version of gdb can "deffer" a breakpoint. I remember that older version I used were not able to do this.

One solution is then to set a breakpoint in your main (it should not matter if it is was not compiled with -g: you will just not be able to see the source) then run, then put a breakpoint in the shared library function.

Code:
$ gcc -O3 myProg.c -o myProg
$ gdb myProg
(gdb) b main
Breakpoint 1 at 0x2358
(gdb) run myArgs
Starting program: myProg
Breakpoint 1, 0x2358 in main ()
(gdb) b fprintf
Breakpoint 2 at 0x7afe7858
(gdb) cont

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top