Arkhan
Arkhan

Reputation: 109

How to prevent GDB from stepping into every single function

My GDB debugger automatically steps into most functions (particularly my external libraries, the standard library). This is quite annoying since I know those libraries are way better written than my code. How is it possible to prevent GDB from doing that?

Upvotes: 5

Views: 2930

Answers (1)

Tom Tromey
Tom Tromey

Reputation: 22589

There are two ways to get what you want.

One is to use next rather than step. step will step into a function call, but next will step over it. Choosing the stepping command you want to use next is by far the most common way to deal with this issue.

Now, this isn't always exactly what you want. In particular, you might be on a line that has a number of calls on it, and there is some subset of the calls that you always want to skip over. This is typical in C++, where there are often many tiny accessors and trivial constructors that are essentially uninteresting -- but you must nevertheless laboriously step through each one to get into the call you do care about.

For this more complicated scenario, GDB has the skip command. This can be used to "blacklist" certain functions (or entire files). When a function is blacklisted, step will not step into it. See the manual for more details on how to use skip.

One final very heavy way to achieve the same effect is to make sure that you do not have any debug information for libraries that you don't want to debug. GDB will automatically not step into functions for which there is no debug information.

Upvotes: 6

Related Questions