Can GDB debug C++ lambdas?

后端 未结 3 449
小鲜肉
小鲜肉 2021-02-07 02:48

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 i

相关标签:
3条回答
  • 2021-02-07 02:59

    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 ()
    
    0 讨论(0)
  • 2021-02-07 03:08

    Step into Lamba's .run() go next/step (jump initializations) until the following call:

    std::forward<>(args)(...)
    

    Step into this one. It will lead you to you lambda body code.

    0 讨论(0)
  • 2021-02-07 03:15

    From my experience, gdb cannot step into lambdas -- it just skips over them. Not only that, stepping into a lambda definition seems to confuse gdb and it proceeds to the end of the current function. You can, however, place a breakpoint explicitly inside a lambda, and if you hit that point, you will stop. This is obviously far from ideal.

    0 讨论(0)
提交回复
热议问题