gpt4 book ai didi

lambda - 使用 gdb 调试 lambdas 有什么好运气吗?

转载 作者:行者123 更新时间:2023-12-04 15:26:34 32 4
gpt4 key购买 nike

为 debian 尝试了 7.2,但似乎无法进入 c++0x lambdas。

最佳答案

我能够在一个非常简单的程序(带有 -g 标志的 ubuntu 10.04、gdb-7.1、gcc-4.6)中进入 lambda。

#include <iostream>

void sayhello()
{
std::cout << "Hello world" << std::endl;
}

int main ()
{
std::cout << "=========" << std::endl;
([](void (*f)()) {
std::cout << "---------" << std::endl;
f();
std::cout << "---------" << std::endl;
})(sayhello);
}

这是 session 记录。
(gdb) br main
Breakpoint 1 at 0x804869e: file hello.C, line 10.
(gdb) r
Starting program: /tmp/hello

Breakpoint 1, main () at hello.C:10
10 std::cout << "=========" << std::endl;
(gdb) n
=========
15 })(sayhello);
(gdb) s
operator() (this=0xbffff24f, f=0x8048614 <sayhello()>) at hello.C:12
12 std::cout << "---------" << std::endl;
(gdb) n
---------
13 f();
(gdb) s
sayhello () at hello.C:5
5 std::cout << "Hello world" << std::endl;
(gdb) n
Hello world
6 }
(gdb) s
operator() (this=0xbffff24f, f=0x8048614 <sayhello()>) at hello.C:14
14 std::cout << "---------" << std::endl;
(gdb) n
---------
15 })(sayhello);
(gdb) n
main () at hello.C:16
16 }

关于lambda - 使用 gdb 调试 lambdas 有什么好运气吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6418035/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com