如何在跳过所有内部实现的同时跳入GDB中std :: function内部的函数? [英] How can I jump into a function held inside std::function in GDB while skipping all the internal implementation?

查看:98
本文介绍了如何在跳过所有内部实现的同时跳入GDB中std :: function内部的函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用此代码:

#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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆