For example, with:
#include <functional>
#include <iostream>
int myfunc(int i){ return i + 1; }
int main() {
std::function<int(int)> f = myfunc;
int i = f(1);
std::cout << i << std::endl;
}
compiled with:
g++ -ggdb3 -O0 -std=c++11 -Wall -Wextra -pedantic -o main.out main.cpp
if I try to do a step
into the call f(1)
, then it first leads me in to C++ standard library code, and I either have to think really hard and do the right next
/step
sequence, or be dumb and hit step
17 times before reaching the actual myfunc
call.
Is there an easier way to go about this, maybe with some existing GDB/Python script?
This was basically done by Microsoft people for Visual Studio as mentioned at: https://devblogs.microsoft.com/cppblog/improving-the-debugging-experience-for-stdfunction/
I like it that is is possible to step into the stdlibc++ by default in Ubuntu and have already used it before, but it would be awesome if GDB could step into std::function
user code by default, and have some other mechanism to go into libstdc++ for this specific case.
I'm tempted to go a bit cheeky and just use the following Python GDB script that repeats a command n times: gdb - perform a command n times which allows me to do:
repeat-cmd 17 s
Related: QtCreator debugger: step into std::function
Tested in Ubuntu 18.04, GDB 8.1, GCC 7.4.