[Lldb-commits] [PATCH] D113930: [LLDB][NativePDB] Fix function decl creation for class methods

Zequan Wu via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Nov 15 12:25:14 PST 2021


zequanwu created this revision.
zequanwu added a reviewer: labath.
zequanwu requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

This is a split of D113724 <https://reviews.llvm.org/D113724>. Calling `TypeSystemClang::AddMethodToCXXRecordType`
to create function decls for class methods.

`lldb-test symbols --dump-ast` also triggers that crash.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113930

Files:
  lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
  lldb/test/Shell/SymbolFile/NativePDB/ast-methods.cpp


Index: lldb/test/Shell/SymbolFile/NativePDB/ast-methods.cpp
===================================================================
--- lldb/test/Shell/SymbolFile/NativePDB/ast-methods.cpp
+++ lldb/test/Shell/SymbolFile/NativePDB/ast-methods.cpp
@@ -4,7 +4,9 @@
 // RUN: %clang_cl --target=x86_64-windows-msvc -Od -Z7 -GR- -c /Fo%t.obj -- %s
 // RUN: lld-link -debug:full -nodefaultlib -entry:main %t.obj -out:%t.exe -pdb:%t.pdb
 // RUN: env LLDB_USE_NATIVE_PDB_READER=1 %lldb -f %t.exe -s \
-// RUN:     %p/Inputs/ast-methods.lldbinit 2>&1 | FileCheck %s
+// RUN:     %p/Inputs/ast-methods.lldbinit 2>&1 | FileCheck %s --check-prefix=AST
+
+// RUN: env LLDB_USE_NATIVE_PDB_READER=1 lldb-test symbol --dump-ast %t.exe | FileCheck %s --check-prefix=SYMBOL
 
 struct Struct {
   void simple_method() {}
@@ -24,14 +26,25 @@
   return 0;
 }
 
-// CHECK: TranslationUnitDecl
-// CHECK: |-CXXRecordDecl {{.*}} struct Struct definition
-// CHECK: | |-CXXMethodDecl {{.*}} simple_method 'void (){{.*}}'
-// CHECK: | |-CXXMethodDecl {{.*}} virtual_method 'void (){{.*}}' virtual
-// CHECK: | |-CXXMethodDecl {{.*}} static_method 'void ()' static
-// CHECK: | |-CXXMethodDecl {{.*}} overloaded_method 'int (){{.*}}'
-// CHECK: | |-CXXMethodDecl {{.*}} overloaded_method 'int (char){{.*}}'
-// CHECK: | | `-ParmVarDecl {{.*}} 'char'
-// CHECK: | `-CXXMethodDecl {{.*}} overloaded_method 'int (char, int, ...)'
-// CHECK: |   |-ParmVarDecl {{.*}} 'char'
-// CHECK: |   `-ParmVarDecl {{.*}} 'int'
+// AST: TranslationUnitDecl
+// AST: |-CXXRecordDecl {{.*}} struct Struct definition
+// AST: | |-CXXMethodDecl {{.*}} simple_method 'void (){{.*}}'
+// AST: | |-CXXMethodDecl {{.*}} virtual_method 'void (){{.*}}' virtual
+// AST: | |-CXXMethodDecl {{.*}} static_method 'void ()' static
+// AST: | |-CXXMethodDecl {{.*}} overloaded_method 'int (){{.*}}'
+// AST: | |-CXXMethodDecl {{.*}} overloaded_method 'int (char){{.*}}'
+// AST: | | `-ParmVarDecl {{.*}} 'char'
+// AST: | `-CXXMethodDecl {{.*}} overloaded_method 'int (char, int, ...)'
+// AST: |   |-ParmVarDecl {{.*}} 'char'
+// AST: |   `-ParmVarDecl {{.*}} 'int'
+
+// SYMBOL:      int main(int argc, char **argv);
+// SYMBOL-NEXT: struct Struct {
+// SYMBOL-NEXT:     void virtual_method();
+// SYMBOL-NEXT:     void simple_method();
+// SYMBOL-NEXT:     virtual void virtual_method();
+// SYMBOL-NEXT:     static void static_method();
+// SYMBOL-NEXT:     int overloaded_method();
+// SYMBOL-NEXT:     int overloaded_method(char);
+// SYMBOL-NEXT:     int overloaded_method(char, int, ...);
+// SYMBOL-NEXT: };
\ No newline at end of file
Index: lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
+++ lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
@@ -1014,8 +1014,24 @@
   proc_name.consume_front(context_name);
   proc_name.consume_front("::");
 
-  clang::FunctionDecl *function_decl = m_clang.CreateFunctionDeclaration(
-      parent, OptionalClangModuleID(), proc_name, func_ct, storage, false);
+  clang::FunctionDecl *function_decl = nullptr;
+  if (parent->isRecord()) {
+    clang::QualType parent_qt = llvm::dyn_cast<clang::TypeDecl>(parent)
+                                    ->getTypeForDecl()
+                                    ->getCanonicalTypeInternal();
+    // TODO: Get other information for this method.
+    function_decl = m_clang.AddMethodToCXXRecordType(
+        ToCompilerType(parent_qt).GetOpaqueQualType(), proc_name,
+        /*mangled_name=*/nullptr, func_ct, lldb::AccessType::eAccessPublic,
+        /*is_virtual=*/false, /*is_static=*/false,
+        /*is_inline=*/false, /*is_explicit=*/false,
+        /*is_attr_used=*/false, /*is_artificial=*/false);
+  } else {
+    function_decl = m_clang.CreateFunctionDeclaration(
+        parent, OptionalClangModuleID(), proc_name, func_ct, storage, false);
+    CreateFunctionParameters(func_id, *function_decl,
+                             func_type->getNumParams());
+  }
 
   lldbassert(m_uid_to_decl.count(toOpaqueUid(func_id)) == 0);
   m_uid_to_decl[toOpaqueUid(func_id)] = function_decl;
@@ -1024,8 +1040,6 @@
   status.uid = toOpaqueUid(func_id);
   m_decl_to_status.insert({function_decl, status});
 
-  CreateFunctionParameters(func_id, *function_decl, func_type->getNumParams());
-
   return function_decl;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113930.387352.patch
Type: text/x-patch
Size: 4398 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20211115/562f2ef5/attachment.bin>


More information about the lldb-commits mailing list