'C++ lambda "__closure" address in gdb
I understand that there's a hidden closure class in C++11 or above for lambdas. But
when is the value of __closure when debugging in gdb 0x0 when calling a lambda? What does that mean?
// a.cpp
#include <iostream>
using std::cout;
int main() {
auto l1 = []() {
cout << "lambda 1\n";
};
auto l2 = []() {
cout << "lambda 2\n";
};
l1();
l2();
using F = void (*)();
F lv = l2;
lv();
}
In gdb:
Breakpoint 1, <lambda()>::operator()(void) const (
__closure=0x7fffffffd83e) at a.cpp:7
7 cout << "lambda 1\n";
(gdb) c
Continuing.
lambda 1
Breakpoint 2, <lambda()>::operator()(void) const (
__closure=0x7fffffffd83f) at a.cpp:10
10 cout << "lambda 2\n";
(gdb) c
Continuing.
lambda 2
Breakpoint 2, <lambda()>::operator()(void) const (__closure=0x0)
at a.cpp:10
10 cout << "lambda 2\n";
(gdb) c
Continuing.
lambda 2
[Inferior 1 (process 27152) exited normally]
g++ & gdb:
$ g++ --version
g++ (GCC) 8.2.0
$ g++ -g -O0 -std=c++17 a.cpp -o a
$ gdb --version
GNU gdb (GDB) 8.1.1
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
