1

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.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
user1726366
  • 2,256
  • 4
  • 15
  • 17
  • Try using the b fileName.cpp:lineNumber on shared library instead of using function name. It must break. Then you can use usual set of instructions. Why are you trying to put breakpoint at function in case it is shared library? – kumar_m_kiran Nov 06 '12 at 10:07
  • Thanks for the comment, the reason I'm doing this is that I want to save time changing the logic inside a shared library without compiling it. – user1726366 Nov 06 '12 at 10:35

1 Answers1

2

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 auto This is the default behavior. When gdb cannot find the breakpoint location, it queries you whether a pending breakpoint should be created.

set breakpoint pending on This indicates that an unrecognized breakpoint location should automatically result in a pending breakpoint being created.

set breakpoint pending off This 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 pending Show the current behavior setting for creating pending breakpoints.

Coming to your question. i.e Skipping a line

use jump +1 when 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?

Community
  • 1
  • 1
Jeyaram
  • 9,158
  • 7
  • 41
  • 63