Preventing GDB from stepping into a function (or file)

后端 未结 5 1558
心在旅途
心在旅途 2020-11-27 21:14

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());
}
<
相关标签:
5条回答
  • 2020-11-27 21:52

    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.

    0 讨论(0)
  • 2020-11-27 21:53

    (I think this might be better suited as a comment rather than an answer, but I don't have enough reputation to add a comment yet.)

    So I've also been wanting to ignore STL, Boost, et al (collectively '3rd Party') files when debugging for a while. Yesterday I finally decided to look for a solution and it seems the nearest capability is the 'skip' command in GDB.

    I found the 'skip' ability in GDB to be helpful, but it's still a nuisance for me because my program uses a lot of STL and other "3rd Party" template code. In this case I have to mark a bunch of files as skip. After the 2nd time doing so I realized it would be more helpful to be able to skip an entire directory--and most helpful to skip a directory and all subdirectories. That way I can skip, for example, /usr since none of my code lives there and I typically have no interest in debugging through 3rd party code. So I extended the 'skip' command in gdb to support a new type 'dir'. I can now do this in gdb:

    skip dir /usr
    

    and then I'm never stopped in any of my 3rd party headers.

    Here's a webpage w/ this info + the patch if it helps anyone: info & patch to skip directories in GDB

    0 讨论(0)
  • It appears that this isn't possible in GDB. I've filed a bug.

    0 讨论(0)
  • 2020-11-27 22:14

    Meanwhile, gdb has the skip function command. Just execute it when you are inside the uninteresting function and it will not bother you again.

    skip file is also very useful to get rid of the STL internals.

    As Justin has said, it has been added in gdb 7.4. For more details, take a look at the documentation.

    0 讨论(0)
  • 2020-11-27 22:16

    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

    0 讨论(0)
提交回复
热议问题