Can GDB debug C++ lambdas?

后端 未结 3 452
小鲜肉
小鲜肉 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 ()
    

提交回复
热议问题