6

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

5
  • cutting edge, probably better off asking on g++ or gdb mailing list Commented Jun 20, 2011 at 21:58
  • Can you elaborate on exactly what went wrong? Commented Jun 20, 2011 at 22:00
  • @templatetypedef I couldn't do step by step into the lambda function. Commented Jun 20, 2011 at 22:26
  • did you try putting break point inside lambda? Commented Jun 21, 2011 at 0:43
  • Possible duplicate of Can GDB debug lambda? Commented Aug 28, 2018 at 17:39

1 Answer 1

4

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      }
Sign up to request clarification or add additional context in comments.

1 Comment

I have to use this inside the lambda to access captures btw. Using the same captured symbol yields garbage.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.