Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set breakpoint on function in a shared library which has not been loaded in gdb

Tags:

I have a shared library libtest.so which will be loaded into the the main program using dlopen. Function test() reside in libtest.so and will be called in the main program through dlsym. Is there any way I could set up a break point on test?

Please note that the main programm has not been linked to libtest.so during linking time. Otherwise , I should be able to set the break point although it is a pending action. In my case, when I do b test, gdb will tell me Function "test" not defined.

like image 859
pierrotlefou Avatar asked Apr 15 '10 05:04

pierrotlefou


People also ask

How do I set a break point in GDB?

You can also set breakpoints on function names. To do this, just type "break [functionname]". gdb will stop your program just before that function is called. Breakpoints stay set when your program ends, so you do not have to reset them unless you quit gdb and restart it.

How do you activate a breakpoint?

To set a breakpoint in source code: Click in the far left margin next to a line of code. You can also select the line and press F9, select Debug > Toggle Breakpoint, or right-click and select Breakpoint > Insert breakpoint. The breakpoint appears as a red dot in the left margin.

What command do you use to set a breakpoint?

Breakpoints are set with the break command (abbreviated b ). The debugger convenience variable `$bpnum' records the number of the breakpoint you've set most recently; see section Convenience variables, for a discussion of what you can do with convenience variables.

How do I add a breakpoint to all methods in visual studio?

Press F3 and then press F9 to add a breakpoint.


1 Answers

Actually gdb should tell you that it's able to resolve the symbol in the future, when new libraries are loaded:

(gdb) b test
Function "test" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (test) pending.
(gdb) r

And later on once the .so object is loaded, it will resolve the breakpoint, e.g.:

Reading symbols for shared libraries . done
Breakpoint 1 at 0xcafebebe
Pending breakpoint 1 - "test" resolved
like image 95
diciu Avatar answered Sep 25 '22 12:09

diciu