Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GDB C++ How to Stop Stepping Inside Standard Libraries

Tags:

c++

gdb

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.

like image 598
Silver Flash Avatar asked Sep 21 '25 01:09

Silver Flash


1 Answers

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]);
like image 112
Fantastic Mr Fox Avatar answered Sep 22 '25 16:09

Fantastic Mr Fox