[clang] Supports viewing class member variables in lambda when using the vs debugger (PR #71564)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 14 05:56:59 PST 2023
https://github.com/GkvJwa updated https://github.com/llvm/llvm-project/pull/71564
>From 60fca5e4300aa88f18daa53f86b56a764834515a Mon Sep 17 00:00:00 2001
From: GkvJwa <gkvjwa at gmail.com>
Date: Wed, 8 Nov 2023 01:37:19 +0800
Subject: [PATCH] Supports viewing class member in lambda when using the vs
debugger
Use "__this" in the DataMemberRecord when generating pdb, so that the vs debugger can parse the member vars in lambda normally
---
clang/lib/CodeGen/CGDebugInfo.cpp | 4 +-
clang/test/CodeGenCXX/lambda-this-info.cpp | 48 ++++++++++++++++++++++
2 files changed, 51 insertions(+), 1 deletion(-)
create mode 100644 clang/test/CodeGenCXX/lambda-this-info.cpp
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index 84a166d3ac3659c..774bc0eae157f49 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1657,8 +1657,10 @@ void CGDebugInfo::CollectRecordLambdaFields(
FieldDecl *f = *Field;
llvm::DIFile *VUnit = getOrCreateFile(f->getLocation());
QualType type = f->getType();
+ StringRef ThisName =
+ CGM.getCodeGenOpts().EmitCodeView ? "__this" : "this";
llvm::DIType *fieldType = createFieldType(
- "this", type, f->getLocation(), f->getAccess(),
+ ThisName, type, f->getLocation(), f->getAccess(),
layout.getFieldOffset(fieldno), VUnit, RecordTy, CXXDecl);
elements.push_back(fieldType);
diff --git a/clang/test/CodeGenCXX/lambda-this-info.cpp b/clang/test/CodeGenCXX/lambda-this-info.cpp
new file mode 100644
index 000000000000000..4de4c69e6170c3c
--- /dev/null
+++ b/clang/test/CodeGenCXX/lambda-this-info.cpp
@@ -0,0 +1,48 @@
+// RUN: %clang_cl --target=x86_64-windows-msvc /c /Z7 -o %t.obj -- %s
+// RUN: llvm-pdbutil dump -all %t.obj | FileCheck %s
+
+class Foo {
+ public:
+ void foo() {
+ int aa = 4;
+ int bb = 5;
+ int cc = 6;
+ auto f = [=] {
+ int aaa = a + aa;
+ int bbb = b + bb;
+ int ccc = c + cc;
+ };
+ f();
+ }
+
+ private:
+ int a = 1;
+ int b = 2;
+ int c = 3;
+};
+
+int main() {
+ Foo f;
+ f.foo();
+
+ return 0;
+}
+
+// CHECK: Types (.debug$T)
+// CHECK-NEXT: ============================================================
+// CHECK:[[FooIndex:0x[^ ]*]] | LF_CLASS [size = 36] `Foo`
+// CHECK: unique name: `.?AVFoo@@`
+// CHECK:[[FooIndex:0x[^ ]*]] | LF_FIELDLIST [size = 52]
+// CHECK: - LF_MEMBER [name = `a`, Type = 0x0074 (int), offset = 0, attrs = private]
+// CHECK: - LF_MEMBER [name = `b`, Type = 0x0074 (int), offset = 4, attrs = private]
+// CHECK: - LF_MEMBER [name = `c`, Type = 0x0074 (int), offset = 8, attrs = private]
+// CHECK: - LF_ONEMETHOD [name = `foo`]
+// CHECK:[[FooIndex:0x[^ ]*]] | LF_POINTER [size = 12]
+// CHECK: referent = [[FooIndex:0x[^ ]*]], mode = pointer, opts = None, kind = ptr64
+// CHECK:[[FooIndex:0x[^ ]*]] | LF_CLASS [size = 80] `Foo::foo::<lambda_1>`
+// CHECK: unique name: `.?AV<lambda_1>@?0??foo at Foo@@QEAAXXZ@`
+// CHECK:[[FooIndex:0x[^ ]*]] | LF_FIELDLIST [size = 72]
+// CHECK: - LF_MEMBER [name = `__this`, Type = [[FooIndex:0x[^ ]*]], offset = 0, attrs = private]
+// CHECK: - LF_MEMBER [name = `aa`, Type = 0x0074 (int), offset = 8, attrs = private]
+// CHECK: - LF_MEMBER [name = `bb`, Type = 0x0074 (int), offset = 12, attrs = private]
+// CHECK: - LF_MEMBER [name = `cc`, Type = 0x0074 (int), offset = 16, attrs = private]
More information about the cfe-commits
mailing list