gdb中的C ++ lambda“ __closure”地址

时间:2018-09-13 06:10:22

标签: c++ lambda gdb

我知道在C ++ 11或更高版本中有一个隐藏的lambda闭包类。但 在调用Lambda时在gdb __clousre中进行调试时,0x0的值何时?是什么意思?

// 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();
}

在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

0 个答案:

没有答案