https://github.com/hokein updated https://github.com/llvm/llvm-project/pull/70779
>From 2ff56f181659a0079c66ce646d50780844ffb080 Mon Sep 17 00:00:00 2001 From: Haojian Wu <hokein...@gmail.com> Date: Tue, 31 Oct 2023 11:15:45 +0100 Subject: [PATCH 1/4] [LLDB] Don't ignore artificial variables and members for coroutines * always populate all fields for the generated coroutine frame type; * make the artificial variables `__promise`, `__coro_frame` visible, so that they are present in the `frame var` command; --- .../Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.cpp | 5 ++++- lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp | 3 ++- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp | 4 ++++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h | 3 +++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.cpp index c2488eaa9f5b50d..c7d9eb37f9b5199 100644 --- a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.cpp +++ b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.cpp @@ -41,7 +41,10 @@ CPPLanguageRuntime::CPPLanguageRuntime(Process *process) : LanguageRuntime(process) {} bool CPPLanguageRuntime::IsAllowedRuntimeValue(ConstString name) { - return name == g_this; + // FIXME: use a list when the list grows more. + return name == g_this || + name == ConstString("__promise") || + name == ConstString("__coro_frame"); } bool CPPLanguageRuntime::GetObjectDescription(Stream &str, diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp index 3174c18c97d888c..48e85cac7b4256f 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp @@ -3061,7 +3061,8 @@ void DWARFASTParserClang::ParseSingleMember( // artificial member with (unnamed bitfield) padding. // FIXME: This check should verify that this is indeed an artificial member // we are supposed to ignore. - if (attrs.is_artificial) { + if (attrs.is_artificial && + !TypeSystemClang::IsCoroutineFrameType(class_clang_type)) { last_field_info.SetIsArtificial(true); return; } diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp index 6f65587c4acedd1..590ba1f6a986ea5 100644 --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp @@ -771,6 +771,10 @@ TypeSystemClang *TypeSystemClang::GetASTContext(clang::ASTContext *ast) { return clang_ast; } +bool TypeSystemClang::IsCoroutineFrameType(const CompilerType &Type) { + return Type.GetTypeName().GetStringRef().ends_with(".coro_frame_ty"); +} + clang::MangleContext *TypeSystemClang::getMangleContext() { if (m_mangle_ctx_up == nullptr) m_mangle_ctx_up.reset(getASTContext().createMangleContext()); diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h index 0ec2d026e996105..6168a065eb522e9 100644 --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h @@ -154,6 +154,9 @@ class TypeSystemClang : public TypeSystem { static TypeSystemClang *GetASTContext(clang::ASTContext *ast_ctx); + // Returns true if the given type is a coroutine frame debug type. + static bool IsCoroutineFrameType(const CompilerType &Type); + /// Returns the display name of this TypeSystemClang that indicates what /// purpose it serves in LLDB. Used for example in logs. llvm::StringRef getDisplayName() const { return m_display_name; } >From ac813b4acd5dbe79fb6d3559e00a454169985067 Mon Sep 17 00:00:00 2001 From: Haojian Wu <hokein...@gmail.com> Date: Fri, 3 Nov 2023 12:07:23 +0100 Subject: [PATCH 2/4] Add and use `ShouldIgnoreArtificialField` API to ignore the indeed artificial members we should ignore. --- lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp | 4 +--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp | 4 ++-- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h | 5 +++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp index 48e85cac7b4256f..63260f28a7da85d 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp @@ -3059,10 +3059,8 @@ void DWARFASTParserClang::ParseSingleMember( // This needs to be done after updating FieldInfo which keeps track of where // field start/end so we don't later try to fill the space of this // artificial member with (unnamed bitfield) padding. - // FIXME: This check should verify that this is indeed an artificial member - // we are supposed to ignore. if (attrs.is_artificial && - !TypeSystemClang::IsCoroutineFrameType(class_clang_type)) { + TypeSystemClang::ShouldIgnoreArtificialField(attrs.name)) { last_field_info.SetIsArtificial(true); return; } diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp index 590ba1f6a986ea5..c62c89ad4455067 100644 --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp @@ -771,8 +771,8 @@ TypeSystemClang *TypeSystemClang::GetASTContext(clang::ASTContext *ast) { return clang_ast; } -bool TypeSystemClang::IsCoroutineFrameType(const CompilerType &Type) { - return Type.GetTypeName().GetStringRef().ends_with(".coro_frame_ty"); +bool TypeSystemClang::ShouldIgnoreArtificialField(llvm::StringRef Name) { + return Name.starts_with("_vptr$"); } clang::MangleContext *TypeSystemClang::getMangleContext() { diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h index 6168a065eb522e9..477b655bb7c86ea 100644 --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h @@ -154,8 +154,9 @@ class TypeSystemClang : public TypeSystem { static TypeSystemClang *GetASTContext(clang::ASTContext *ast_ctx); - // Returns true if the given type is a coroutine frame debug type. - static bool IsCoroutineFrameType(const CompilerType &Type); + // Returns true if the given artificial field name should be ignored when + // parsing the DWARF. + static bool ShouldIgnoreArtificialField(llvm::StringRef FieldName); /// Returns the display name of this TypeSystemClang that indicates what /// purpose it serves in LLDB. Used for example in logs. >From e74494c01f8b81ce8d77b047bb24df4e54410fe3 Mon Sep 17 00:00:00 2001 From: Haojian Wu <hokein...@gmail.com> Date: Thu, 9 Nov 2023 14:07:40 +0100 Subject: [PATCH 3/4] Handle the vptr gdb case, and add test. and remove the change in CPPLanguageRuntim.cpp. --- .../CPlusPlus/CPPLanguageRuntime.cpp | 5 +---- .../TypeSystem/Clang/TypeSystemClang.cpp | 4 +++- .../DWARF/ignored_artificial_fields.test | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 lldb/test/Shell/SymbolFile/DWARF/ignored_artificial_fields.test diff --git a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.cpp index c7d9eb37f9b5199..c2488eaa9f5b50d 100644 --- a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.cpp +++ b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.cpp @@ -41,10 +41,7 @@ CPPLanguageRuntime::CPPLanguageRuntime(Process *process) : LanguageRuntime(process) {} bool CPPLanguageRuntime::IsAllowedRuntimeValue(ConstString name) { - // FIXME: use a list when the list grows more. - return name == g_this || - name == ConstString("__promise") || - name == ConstString("__coro_frame"); + return name == g_this; } bool CPPLanguageRuntime::GetObjectDescription(Stream &str, diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp index c62c89ad4455067..e81fdc7bdfd8e40 100644 --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp @@ -772,7 +772,9 @@ TypeSystemClang *TypeSystemClang::GetASTContext(clang::ASTContext *ast) { } bool TypeSystemClang::ShouldIgnoreArtificialField(llvm::StringRef Name) { - return Name.starts_with("_vptr$"); + return Name.starts_with("_vptr$") + // gdb emit vtable pointer as "_vptr.classname" + || Name.starts_with("_vptr."); } clang::MangleContext *TypeSystemClang::getMangleContext() { diff --git a/lldb/test/Shell/SymbolFile/DWARF/ignored_artificial_fields.test b/lldb/test/Shell/SymbolFile/DWARF/ignored_artificial_fields.test new file mode 100644 index 000000000000000..e7d3bc4b796224a --- /dev/null +++ b/lldb/test/Shell/SymbolFile/DWARF/ignored_artificial_fields.test @@ -0,0 +1,17 @@ +# UNSUPPORTED: system-darwin, system-windows + +# Make sure the artifical field `vptr.ClassName` from gcc debug info is ignored. +# RUN: %build --compiler=gcc %S/Inputs/debug-types-expressions.cpp -o %t +# RUN: %lldb %t -s %s -o exit | FileCheck %s + +breakpoint set -n foo +process launch + +# CHECK: Process {{.*}} stopped + +frame variable *a +# CHECK-LABEL: frame variable *a +# CHECK: (B) *a = { +# CHECK-NEXT: A = (i = 47) +# CHECK-NEXT: j = 42 +# CHECK-NEXT: } >From 04318e301eaaa19614ef7fd7c0815d3f9610016d Mon Sep 17 00:00:00 2001 From: Haojian Wu <hokein...@gmail.com> Date: Thu, 9 Nov 2023 15:06:46 +0100 Subject: [PATCH 4/4] Move the ShouldIgnoreArtificialField from TypeSystemClang to DWARFASTParserClang. --- .../Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp | 11 +++++++++-- .../Plugins/TypeSystem/Clang/TypeSystemClang.cpp | 6 ------ .../source/Plugins/TypeSystem/Clang/TypeSystemClang.h | 4 ---- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp index 63260f28a7da85d..a70dc9832f425c6 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp @@ -133,6 +133,14 @@ static lldb::ModuleSP GetContainingClangModule(const DWARFDIE &die) { return lldb::ModuleSP(); } +// Returns true if the given artificial field name should be ignored when +// parsing the DWARF. +static bool ShouldIgnoreArtificialField(llvm::StringRef FieldName) { + return FieldName.starts_with("_vptr$") + // gdb emit vtable pointer as "_vptr.classname" + || FieldName.starts_with("_vptr."); +} + TypeSP DWARFASTParserClang::ParseTypeFromClangModule(const SymbolContext &sc, const DWARFDIE &die, Log *log) { @@ -3059,8 +3067,7 @@ void DWARFASTParserClang::ParseSingleMember( // This needs to be done after updating FieldInfo which keeps track of where // field start/end so we don't later try to fill the space of this // artificial member with (unnamed bitfield) padding. - if (attrs.is_artificial && - TypeSystemClang::ShouldIgnoreArtificialField(attrs.name)) { + if (attrs.is_artificial && ShouldIgnoreArtificialField(attrs.name)) { last_field_info.SetIsArtificial(true); return; } diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp index e81fdc7bdfd8e40..6f65587c4acedd1 100644 --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp @@ -771,12 +771,6 @@ TypeSystemClang *TypeSystemClang::GetASTContext(clang::ASTContext *ast) { return clang_ast; } -bool TypeSystemClang::ShouldIgnoreArtificialField(llvm::StringRef Name) { - return Name.starts_with("_vptr$") - // gdb emit vtable pointer as "_vptr.classname" - || Name.starts_with("_vptr."); -} - clang::MangleContext *TypeSystemClang::getMangleContext() { if (m_mangle_ctx_up == nullptr) m_mangle_ctx_up.reset(getASTContext().createMangleContext()); diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h index 477b655bb7c86ea..0ec2d026e996105 100644 --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h @@ -154,10 +154,6 @@ class TypeSystemClang : public TypeSystem { static TypeSystemClang *GetASTContext(clang::ASTContext *ast_ctx); - // Returns true if the given artificial field name should be ignored when - // parsing the DWARF. - static bool ShouldIgnoreArtificialField(llvm::StringRef FieldName); - /// Returns the display name of this TypeSystemClang that indicates what /// purpose it serves in LLDB. Used for example in logs. llvm::StringRef getDisplayName() const { return m_display_name; } _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits