[Lldb-commits] [PATCH] D133446: [LLDB][NativePDB] Global ctor and dtor should be global decls.

Zequan Wu via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Wed Sep 14 10:43:06 PDT 2022


zequanwu updated this revision to Diff 460152.
zequanwu added a comment.

Move the logic into `MSVCUndecoratedNameParser`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133446/new/

https://reviews.llvm.org/D133446

Files:
  lldb/source/Plugins/Language/CPlusPlus/MSVCUndecoratedNameParser.cpp
  lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
  lldb/test/Shell/SymbolFile/NativePDB/global-ctor-dtor.cpp


Index: lldb/test/Shell/SymbolFile/NativePDB/global-ctor-dtor.cpp
===================================================================
--- /dev/null
+++ 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: };
Index: lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
+++ lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
@@ -537,7 +537,7 @@
   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 @@
   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);
Index: lldb/source/Plugins/Language/CPlusPlus/MSVCUndecoratedNameParser.cpp
===================================================================
--- lldb/source/Plugins/Language/CPlusPlus/MSVCUndecoratedNameParser.cpp
+++ 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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133446.460152.patch
Type: text/x-patch
Size: 2769 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220914/cf777b1b/attachment.bin>


More information about the lldb-commits mailing list