4

this post briefly discusses the same trouble I am facing. Essentially, is there a default setting or a hack for gdb to stop stepping inside every single glib library and only step inside user files? I know I can call finish each time it steps inside one but it's some wasted keystrokes I'd rather avoid.

It's already annoying as it is to deal with g++'s output. If this exhibitionism cannot be stopped, are there good alternatives to these gnu tools? I do hear good things about eclipse, but I'm just a student looking for quick and dirty fixes with minimal effort.

Silver Flash
  • 871
  • 3
  • 7
  • 16

1 Answers1

6

If you have GDB 7.12.1 or above you can add the following to your ~/.gdbinit file:

skip -gfi /usr/include/c++/*/*/*
skip -gfi /usr/include/c++/*/*
skip -gfi /usr/include/c++/*

Double check that these are in fact the right places for those libs. This answer comes from here.

Some options without editing gdb init

If you want to "step over" a line (like std::vector<int> a;) without stepping into it, you can use next.

If you have a situation like int b = is_negative(a[0]) and you want to stop in is_negative you have a few options:

  1. Step into the a[0] function then use finish to step out again.
  2. Use tbreak is_negative to create a temporary breakpoint on the is_negative function then use next to step which will break on the breakpoint.

2 is faster in the case where you have something with many sub calls in a function like:

is_negative(a[b.at(2)] * c[3]);
Fantastic Mr Fox
  • 32,495
  • 27
  • 95
  • 175
  • That is a nice trick! However, it still doesn't answer my question. In fact, one could even argue that `tbreak function` is worse for a sloth like me as oppose to using a single `finish` – Silver Flash May 18 '20 at 09:56
  • I mean the answer to the question "can i avoid stepping into stdlib with GDB" is probably just "no". These are some alternatives. – Fantastic Mr Fox May 18 '20 at 09:58
  • 1
    You can have a look at something like [this](https://reversed.top/2016-05-26/skipping-standard-library-in-gdb/) but it is not so easy to set up compared with writing finish a couple of times. – Fantastic Mr Fox May 18 '20 at 10:04
  • That is what I was after. Put it in your answer, I will vote it now since implementing this would take time. – Silver Flash May 18 '20 at 10:10
  • Edit: it works, I am finally free from this curse! I use gdb version 9.1 so the simple solution at the end does the trick – Silver Flash May 18 '20 at 10:17