Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any luck debugging lambdas with gdb?

Tags:

c++11

lambda

gdb

Tried with 7.2 for debian, but seems is not possible to step into c++0x lambdas.

like image 986
piotr Avatar asked Jun 20 '11 21:06

piotr


1 Answers

I was able to step into a lambda in a very simple program (ubuntu 10.04, gdb-7.1, gcc-4.6 with -g flag).

#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);
}

And here's a session transcript.

(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      }
like image 174
n. 1.8e9-where's-my-share m. Avatar answered Oct 27 '22 09:10

n. 1.8e9-where's-my-share m.