Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preventing GDB from stepping into a function (or file)

Tags:

I have some C++ code like this that I'm stepping through with GDB:

void foo(int num) { ... }  void main() {   Baz baz;   foo (baz.get()); } 

When I'm in main(), I want to step into foo(), but I want to step over baz.get().

The GDB docs say that "the step command only enters a function if there is line number information for the function", so I'd be happy if I could remove the line number information for baz.get() from my executable. But ideally, I'd be able to tell GDB "never step into any function in the Baz class".

Does anyone know how to do this?

like image 801
Justin L. Avatar asked Jul 15 '09 19:07

Justin L.


People also ask

How do I stop GDB execution?

To stop your program while it is running, type "(ctrl) + c" (hold down the ctrl key and press c). gdb will stop your program at whatever line it has just executed. From here you can examine variables and move through your program. To specify other places where gdb should stop, see the section on breakpoints below.

How do I skip a function call in GDB?

The skip command lets you tell GDB to skip a function, all functions in a file or a particular function in a particular file when stepping. Suppose you wish to step into the functions foo and bar , but you are not interested in stepping through boring .

What does jump do in GDB?

Description. This command jumps the program counter to the specified location. The debugger resumes program execution at that point unless it encounters a breakpoint there.

What is the difference between the GDB step and Stepi Commands?

The difference is how call is treated: stepi dives into call. nexti runs call but doesn't walk you through its code.


2 Answers

Starting with GDB 7.4, skip can be used.

Run info skip, or check out the manual for details: https://sourceware.org/gdb/onlinedocs/gdb/Skipping-Over-Functions-and-Files.html

like image 97
Justin L. Avatar answered Sep 28 '22 04:09

Justin L.


Instead of choosing to "step", you can use the "until" command to usually behave in the way that you desire:

(gdb) until foo 

I don't know of any way to permanently configure gdb to skip certain symbols (aside from eliding their debugging information).

Edit: actually, the GDB documentation states that you can't use until to jump to locations that aren't in the same frame. I don't think this is true, but in the event that it is, you can use advance for the same purpose:

(gdb) advance foo 

Page 85 of the GDB manual defines what can be used as "location" arguments for commands that take them. Just putting "foo" will make it look for a function named foo, so as long as it can find it, you should be fine. Alternatively you're stuck typing things like the filename:linenum for foo, in which case you might just be better off setting a breakpoint on foo and using continue to advance to it.

like image 22
Nick Bastin Avatar answered Sep 28 '22 02:09

Nick Bastin