GDB可以调试C ++ lambda吗? [英] Can GDB debug C++ lambdas?

查看:296
本文介绍了GDB可以调试C ++ lambda吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我积极使用C ++ 11功能。我在Visual Studio 2013中创建了程序,该程序依赖于lambda来运行多个线程(lambda表示任务,并且线程接收必须运行的lambda实例)。 Lambda在静态库中定义,并链接到可执行文件中,该可执行文件从该可执行文件创建的线程中调用它。
当我尝试使用GDB调试此应用程序的Linux版本时,GDB似乎无法进入包含lambda的方法。它无法在此函数中设置断点,而当我尝试进入该函数时,它甚至进入了lambda从其主体调用的方法,但是在这些方法中 return 之后,它没有'不是去lambda主体,而是去了lambda调用的下一个方法,等等。
是否可以用GDB调试lambdas主体?

方案

我之前已经在堆栈跟踪中看到它们,因此它至少了解它们。我从未尝试在其中设置一个正常的断点。这有点像骇客,但您可以在x86(-64)上使用 asm volatile( int $ 3); 来在一个(或任何地方)设置断点。 / p>

下面是一个示例程序:

  int main(){
auto f = [](){
asm volatile( int $ 3);
};
f();
返回0;
}

这里是回溯到断点的位置:

 #0在main :: {lambda()#1} :: operator()()const()
#1 0x000000000040058d在main ()


I use C++ 11 features actively. I have program created in Visual Studio 2013 that relies on lambdas to run multiple threads (lambda represents task, and thread receives lambda instance that it has to run). Lambda is defined in static library and linked in executable file that calls it from thread created by this executable file. When I try to debug Linux version of this application with GDB, it looks like GDB can not step into method that contains lambda. It can not set breakpoints in this function, and when I try to step into, it even steps in methods that lambda calls from its body, but after return from these methods it doesn't go to lambda body, it goes to next method that lambda calls, etc. Are there any way to debug lambdas body with GDB?

解决方案

I've seen them in stack traces before, so it does at least know about them. I've never tried setting a normal breakpoint in one. It's sort of a hack, but you can set a breakpoint in one (or anywhere) by using asm volatile("int $3"); on x86(-64).

Here's an example program:

int main(){
    auto f = [](){
        asm volatile("int $3");
    };
    f();
    return 0;
}

Here's it's backtrace when it hits that breakpoint:

#0  0x0000000000400577 in main::{lambda()#1}::operator()() const ()
#1  0x000000000040058d in main ()

这篇关于GDB可以调试C ++ lambda吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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