Introduce the DW_AT_LLVM_lambda_name
The proposed attribute points to the name of the lambda expression from C++ source code.
Let’s compile a basic C++ code using a lambda expression with CLANG:
$ cat basic.cpp #include <iostream> int main() { auto printNum = [](int num) { std::cout << num << '\n'; }; for (int i = 0; i < 5; ++i) printNum(i); return 0; } $ clang++ -g -O2 basic.cpp
Basically, before this set of patches a debug session on this simple example looks like:
$ gdb a.out ... Breakpoint 1 at 0x401195: file basic.cpp, line 6. (gdb) r Starting program: a.out Breakpoint 1, main::$_0::operator() (this=<optimized out>, num=0) at basic.cpp:6 6 std::cout << num << '\n'; (gdb) bt #0 main::$_0::operator() (this=<optimized out>, num=0) at basic.cpp:6 #1 main () at basic.cpp:10
Using the lldb is not much better since we are missing the info from compiler:
$ lldb a.out ... (lldb) bt * thread #1, name = 'a.out', stop reason = breakpoint 1.1 * frame #0: 0x0000000000401195 a.out`main [inlined] main::$_0::operator(this=<unavailable>, num=0)(int) const at basic.cpp:6:15 frame #1: 0x0000000000401190 a.out`main at basic.cpp:10 frame #2: 0x00007ffff7a961e3 libc.so.6`__libc_start_main + 243 frame #3: 0x00000000004010ce a.out`_start + 46
Currently, debuggers print mangled name (main::$_0::operator), which is not that useful in this backtrace.
After applying the set of patches and using the LLDB, debugging session on the same test case looks:
$ clang++ -glldb -O2 basic.cpp $ lldb a.out .. (lldb) bt * thread #1, name = ‘a.out’, stop reason = breakpoint 1.1 * frame #0: 0x0000000000401195 a.out `main [inlined] [lambda] printNum(this=<unavailable>, num=0) at basic.cpp:6:15 [opt] //<== by adding this feature, I was able to add the [lambda] attribute and the name of lambda ‘printNum’// frame #1: 0x0000000000401190 a.out `main at basic.cpp:10 [opt] frame #2: 0x00007ffff7a961e3 libc.so.6`__libc_start_main + 243 frame #3: 0x00000000004010ce a.out _start + 46
The GCC + GDB combination does a bit better job when processing lambdas. GCC adds hardcoded DW_AT_name “<lambda>” of corresponding DWARF TAG, referring to the type created for the lambda expression. That is not proposed by DWARF standard, but GDB knows how to parse it and print that into the backtrace.