<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/71562>71562</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Supports viewing class member variables in lambda when using the vs debugger
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          GkvJwa
      </td>
    </tr>
</table>

<pre>
    I use clang to compile the following code on windows

```
#include <stdio.h>

class foo {
 public:
 void fun() {
    auto f = [=] {
      int c = a;
      int d = b;
      printf("%d %d\n", c, d);
    };
    f();
  }

 private:
  int a = 1;
  int b = 2;
};

int main() {
  foo f;
  f.fun();
  return 0;
}
```

If during debugging, the execution reaches the breakpoint inside the lambda function.
```
breakpoint at:
      int c = a;
      int d = b;
```
When my mouse is located on member variable a, there is no way to display the value of variable a.
Then I checked the assembly and the recognition support for this pointer, it shows this may only be used inside a nonstatic member function
![unnamed](https://github.com/llvm/llvm-project/assets/22285132/8f124719-11ce-434a-bbd5-f1efa81b024a)

It looks like the same code cannot be compiled with by msvc. Can display the class structure normally, similarly, when I move the mouse over a variable, I can see the value of the variable.

---
So, I asked the relevant personnel at Microsoft for advice on this problem.
After they were able to reproduce it, they told me that the debugger could identify the lambda by whether it could find "__this"
```
IDiaSym.findChildren(SymTagData, L"__this", ...)
```

---
Then I used llvm-pdbutil to view this detail
```
msvc:
  0x3B17 | LF_FIELDLIST [size = 112, hash = 0x3D8EB]
          - LF_ONEMETHOD [name = `operator()`]
 type = 0x3B0D, vftable offset = -1, attrs = public
          - LF_METHOD [name = `<lambda_1>`, # overloads = 2, overload list = 0x3B12]
          - LF_MEMBER [name = `__this`, Type = 0x3B08, offset = 0, attrs = private]
 - LF_ONEMETHOD [name = `operator=`]
            type = 0x3B16, vftable offset = -1, attrs = public
          - LF_ONEMETHOD [name = `__autoclassinit2`]
            type = 0x3B0E, vftable offset = -1, attrs = public compiler-generated
  0x3B18 | LF_CLASS [size = 96, hash = 0xFC7A] `foo::fun::__l2::<lambda_1>`
clang:
   0x1009 | LF_FIELDLIST [size = 20, hash = 0x11D9]
            - LF_MEMBER [name = `this`, Type = 0x1008, offset = 0, attrs = private]
   0x100A | LF_CLASS [size = 80, hash = 0x2636D] `foo::fun::<lambda_1>`
            unique name: `.?AV<lambda_1>@?0??fun@foo@@QEAAXXZ@`
            vtable: <no type>, base list: <no type>, field list: 0x1009
            options: has ctor / dtor | has unique name | scoped, sizeof 8
   0x100B | LF_CLASS [size = 80, hash = 0x2DD4A] `foo::fun::<lambda_1>`
            unique name: `.?AV<lambda_1>@?0??fun@foo@@QEAAXXZ@`
```
The pdb file compiled by msvc does have "__this" symbol, but clang does not

After that, I debugged the code for llvm to generate pdb, and simply replaced the information with "__this" when constructing DataMemberRecord. Recompile, it work

Of course, my patch may not be good
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEV1tv47gV_jX0y4ENifL1wQ-OHbcpJh10E7SLvgSUeGSxoUiXpOzx_vriULIje5zFBn3YYEYWb-f68ZxPwnu1M4hLNnlgk81ANKGybvmX98PfjmKQW3laPkHjEQotzA6ChcLWe6URQoVQWq3tUZkdFFYiWANHZaQ9epZsWLLqntOk-9cOeaZMoRuJwLK1D1LZUcWyx_6RQgvvobQW2OyhnYJ9k2tVsKzbAgerJJSNYXzO-KK3EQBEEyyUwLINkF_Zhk021zsAlAlQxC2CZT-tyLiS36zsnTKhjBo54xMJ9GCTtYnjNRT0kIwvrs6x2eZq3Aro76EdPfdJz0EE_HA22iSiTWnvHM3mcZZfZvva2iftqoW6EymKcNmTV44uAe3NOgyNM5Bcqbib2vh8KkE2jkAhMW92O2V2FBbCC_7AognKGnAoigp9nM0dive9JTOV8Uq22NKizqWgDBd0YnRXY--oCL1wfT3BN4L_VaGB-gS1JfArD9oWIqAkjNdY5-jgIJwSuUYQnXsubjQWjuJEN0Uqv9f0Wi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