4

Take this code:

#include <iostream>
#include <memory>
#include <functional>

std::function<int()> getint = []
{
    return 5;
};

void foo(int i)
{
    std::cout<<i<<std::endl;
}

int main()
{
    foo(getint());
}

I'm stopped at a breakpoint at line 17. I want to step into the getint function. Using gdb's step by default takes me through a bunch of std::function's internal crap that I'm not interested in. If I continue stepping, I will eventually get through to the lambda, but having to do this for every std::function call is extremely annoying.

I tried using the skip command:

skip -rfu ^std::.*

but this causes step to jump straight into foo, completely skipping the lambda inside std::function.

Is it possible to configure gdb in a way, where step at line 17 would take me straight to the lambda at line 7?

user697683
  • 1,423
  • 13
  • 24

1 Answers1

4

Ok, I managed to solve this using a simple python script:

import gdb
import re

def stop_handler(event):
    frame_name = gdb.selected_frame().name();
    if re.search("(^std::.*)|(^boost::.*)", frame_name) != None:
        gdb.execute("step")

gdb.events.stop.connect(stop_handler)
user697683
  • 1,423
  • 13
  • 24
  • 1
    Doesn't work for me (gdb 8.0.1). I'm getting strange breaks into __gnu_cxx::__is_null_pointer and __subvdi3, followed by gdb segfault. So I'd be happy to see any other attempts. – Dan Stahlke Feb 26 '19 at 22:22
  • Works on my side in gdb 8.2 . It is really fun to watch it in IDE, when it shows dozen of files skipped in a second :)) – random Mar 31 '19 at 00:46