tags:

views:

406

answers:

3

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?

A: 

Use next instead of step. next executes the next statement without stepping inside it. next is effectively a "step over."

EDIT: Doesn't seem like above is what you're looking for. You might have to simply set a breakpoint inside foo(), and do a continue before calling foo().

sheepsimulator
next will step over foo(), as well as baz.get(). As he states, he'd like to step into the code for foo(), but skip debugging the code for baz.get(), which gets invoked first when evaluating the arguments to pass into the frame for foo().
Nick Bastin
+4  A: 

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.

Nick Bastin
That's pretty cool! It's not exactly what I'm looking for -- even with GDB's function name, typing in the whole name is somewhat tedious, so I'd prefer to blacklist functions or entire files. But it's a lot better than what I had.
Justin L.
A: 

It appears that this isn't possible in GDB. I've filed a bug.

Justin L.