[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 7 12:35:05 PDT 2022


zequanwu created this revision.
zequanwu added reviewers: labath, rnk.
Herald added a project: All.
zequanwu requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

This fixes a crash that mistaken global ctor/dtor as funciton methods.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133446

Files:
  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 -opt:icf -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:      struct B {
+// CHECK-NEXT:     static A glob;
+// CHECK-NEXT: };
+// CHECK-NEXT: static void `dynamic initializer for 'glob'();
+// CHECK-NEXT: static void `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: };
Index: lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
+++ lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
@@ -1226,7 +1226,10 @@
   llvm::StringRef proc_name = proc.Name;
   proc_name.consume_front(context_name);
   proc_name.consume_front("::");
-
+  // Global ctor and dtor are global decls.
+  if (proc_name.contains("dynamic initializer for") ||
+      proc_name.contains("dynamic atexit destructor for"))
+    parent = FromCompilerDeclContext(GetTranslationUnitDecl());
   clang::FunctionDecl *function_decl =
       CreateFunctionDecl(func_id, proc_name, proc.FunctionType, func_ct,
                          func_type->getNumParams(), storage, false, parent);


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


More information about the lldb-commits mailing list