有没有运气调试lambdas与gdb?

时间:2011-06-20 21:55:31

标签: lambda c++11 gdb

尝试使用7.2进行debian,但似乎无法进入c ++ 0x lambdas。

1 个答案:

答案 0 :(得分:4)

我能够在一个非常简单的程序(ubuntu 10.04,gdb-7.1,带有-g标志的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);
}

这是会议记录。

(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      }