Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debug a lambda capturing this

Tags:

c++

c++11

lldb

I have a lambda that captures this. When I debug it I have trouble seeing members of the captures object: if I do a p *this, LLDB prints:

((anonymous class)) $1 = {
  this = 0x17ebb62c
}

So apparently I have the lambda's class that contain only one member, which is the this pointer it has captured. Seems legit, so I tried p this->this and then it reports:

error: expected unqualified-id

I fear that LLDB is lost because this is both a keyword and a member of my anonymous class. Is that the case? What can I do to circumvent that?

like image 381
Guillaume Guigue Avatar asked Oct 17 '22 14:10

Guillaume Guigue


1 Answers

Suppose the following code:

struct S
{
    auto f() { return [this](){ return ++i; }; }
    int i = 0;
};

I find it sometimes necessary to proceed in two passes:

> break S::f
> continue
...
> print *this
((anonymous class)) $1 = {
  this = 0x17ebb62c
}
> print (S*)0x17ebb62c
S $2 = {
    i = 0
}
like image 51
YSC Avatar answered Oct 20 '22 20:10

YSC