如何在跳过所有内部实现的同时跳入GDB中std :: function内部的函数? [英] How can I jump into a function held inside std::function in GDB while skipping all the internal implementation?
问题描述
使用此代码:
#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());
}
我在第17行的断点处停止.我想进入getint
函数.默认情况下,使用gdb的step
会带我经历一堆我不感兴趣的内部std::function
废话.如果继续执行,最终我将了解lambda,但必须对每个std::function
呼叫非常烦人.
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.
我尝试使用skip
命令:
skip -rfu ^std::.*
但这会导致step
直接跳入foo
,完全跳过std::function
内部的lambda.
but this causes step
to jump straight into foo
, completely skipping the lambda inside std::function
.
是否可以以某种方式配置gdb,使第17行的step
带我直接进入第7行的lambda?
Is it possible to configure gdb in a way, where step
at line 17 would take me straight to the lambda at line 7?
推荐答案
好,我设法使用一个简单的python脚本解决了这个问题:
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)
这篇关于如何在跳过所有内部实现的同时跳入GDB中std :: function内部的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!