I have a source file shared_lib_test.c in which there’s some code like below:
10 void test_function(void)
11 {
12 do_me();
13 skip_me();
14 return;
15 }
I want to use the gdb to skip the line 13, how should I do this? This function belongs to a shared library not a binary.
If this function belongs to a binary then I could use the following command to do it:
b shared_lib_test.c:13
commands 1
jump 14
continue
end
But as it belongs to shared library, I could not set a break point on the exact line number of the source file, I tried ‘b test_function +2’ but it seems illegal to gdb.
For Debugging shared libraries, you need to use
set breakpoint pending— Set debugger’s behavior regarding pending breakpoints.It’s quite common to have a breakpoint inside a shared library. Shared libraries can be loaded and unloaded explicitly, and possibly repeatedly, as the program is executed. To support this use case, gdb updates breakpoint locations whenever any shared library is loaded or unloaded. Typically, you would set a breakpoint in a shared library at the beginning of your debugging session, when the library is not loaded, and when the symbols from the library are not available. When you try to set breakpoint, gdb will ask you if you want to set a so called pending breakpoint—breakpoint whose address is not yet resolved.
gdb provides some additional commands for controlling what happens when the `break’ command cannot resolve breakpoint address specification to an address:
set breakpoint pending autoThis is the default behavior. When gdb cannot find the breakpoint location, it queries you whether a pending breakpoint should be created.
set breakpoint pending onThis indicates that an unrecognized breakpoint location should automatically result in a pending breakpoint being created.
set breakpoint pending offThis indicates that pending breakpoints are not to be created. Any unrecognized breakpoint location results in an error. This setting does not affect any pending breakpoints previously created.
show breakpoint pendingShow the current behavior setting for creating pending breakpoints.
Coming to your question. i.e Skipping a line
use
jump +1when your code reaches before that shared library line(skip_me()).References
http://wiki.documentfoundation.org/Development/How_to_debug
gdb: how to set breakpoints on future shared libraries with a –command flag
http://bhushanverma.blogspot.in/2009/08/how-to-debug-shared-library-using-gdb.html
http://www.toptip.ca/2010/06/gdb-skip-instructions-or-lines-while.html
Can I use gdb to skip a line?