[Lldb-commits] [lldb] 8704281 - [LLDB][NativePDB] Global ctor and dtor should be global decls.
Zequan Wu via lldb-commits
lldb-commits at lists.llvm.org
Thu Sep 15 22:36:10 PDT 2022
Author: Zequan Wu
Date: 2022-09-15T22:35:58-07:00
New Revision: 8704281c567705822a1c23b9ec40f5bdc5d58352
URL: https://github.com/llvm/llvm-project/commit/8704281c567705822a1c23b9ec40f5bdc5d58352
DIFF: https://github.com/llvm/llvm-project/commit/8704281c567705822a1c23b9ec40f5bdc5d58352.diff
LOG: [LLDB][NativePDB] Global ctor and dtor should be global decls.
This fixes a crash that mistaken global ctor/dtor as funciton methods.
Differential Revision: https://reviews.llvm.org/D133446
Added:
lldb/test/Shell/SymbolFile/NativePDB/global-ctor-dtor.cpp
Modified:
lldb/source/Plugins/Language/CPlusPlus/MSVCUndecoratedNameParser.cpp
lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
Removed:
################################################################################
diff --git a/lldb/source/Plugins/Language/CPlusPlus/MSVCUndecoratedNameParser.cpp b/lldb/source/Plugins/Language/CPlusPlus/MSVCUndecoratedNameParser.cpp
index 8ecf6712eace2..72afc6fe75acc 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/MSVCUndecoratedNameParser.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/MSVCUndecoratedNameParser.cpp
@@ -11,6 +11,13 @@
#include <stack>
MSVCUndecoratedNameParser::MSVCUndecoratedNameParser(llvm::StringRef name) {
+ // Global ctor and dtor are global functions.
+ if (name.contains("dynamic initializer for") ||
+ name.contains("dynamic atexit destructor for")) {
+ m_specifiers.emplace_back(name, name);
+ return;
+ }
+
std::size_t last_base_start = 0;
std::stack<std::size_t> stack;
diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp b/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
index 1be80e31c7fcc..ab467f20990c4 100644
--- a/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
+++ b/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
@@ -537,7 +537,7 @@ PdbAstBuilder::CreateDeclInfoForUndecoratedName(llvm::StringRef name) {
MSVCUndecoratedNameParser parser(name);
llvm::ArrayRef<MSVCUndecoratedNameSpecifier> specs = parser.GetSpecifiers();
- auto context = FromCompilerDeclContext(GetTranslationUnitDecl());
+ auto *context = FromCompilerDeclContext(GetTranslationUnitDecl());
llvm::StringRef uname = specs.back().GetBaseName();
specs = specs.drop_back();
@@ -1226,7 +1226,6 @@ PdbAstBuilder::GetOrCreateFunctionDecl(PdbCompilandSymId func_id) {
llvm::StringRef proc_name = proc.Name;
proc_name.consume_front(context_name);
proc_name.consume_front("::");
-
clang::FunctionDecl *function_decl =
CreateFunctionDecl(func_id, proc_name, proc.FunctionType, func_ct,
func_type->getNumParams(), storage, false, parent);
diff --git a/lldb/test/Shell/SymbolFile/NativePDB/global-ctor-dtor.cpp b/lldb/test/Shell/SymbolFile/NativePDB/global-ctor-dtor.cpp
new file mode 100644
index 0000000000000..15b4d330fabb0
--- /dev/null
+++ b/lldb/test/Shell/SymbolFile/NativePDB/global-ctor-dtor.cpp
@@ -0,0 +1,30 @@
+// clang-format off
+// REQUIRES: lld, x86
+
+// Global ctor and dtor should be globals decls.
+// RUN: %clang_cl --target=x86_64-windows-msvc -Od -Z7 -GS- -fno-addrsig -c /Fo%t.obj -- %s
+// RUN: lld-link -debug:full -nodefaultlib -entry:main %t.obj -out:%t.exe -pdb:%t.pdb -force
+// RUN: env LLDB_USE_NATIVE_PDB_READER=1 lldb-test symbols --dump-ast %t.exe | FileCheck %s
+
+struct A {
+ ~A() {};
+};
+struct B {
+ static A glob;
+};
+
+A B::glob = A();
+int main() {
+ return 0;
+}
+
+// CHECK: static void B::`dynamic initializer for 'glob'();
+// CHECK-NEXT: static void B::`dynamic atexit destructor for 'glob'();
+// CHECK-NEXT: int main();
+// CHECK-NEXT: static void _GLOBAL__sub_I_global_ctor_dtor.cpp();
+// CHECK-NEXT: struct A {
+// CHECK-NEXT: ~A();
+// CHECK-NEXT: };
+// CHECK-NEXT: struct B {
+// CHECK-NEXT: static A glob;
+// CHECK-NEXT: };
More information about the lldb-commits
mailing list