[Lldb-commits] [PATCH] D146297: [lldb][gnustep][PDB] Parse ObjC base classes and recognize NSObject type

Stefan Gränitz via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Fri Mar 17 07:17:11 PDT 2023


sgraenitz created this revision.
sgraenitz added reviewers: aleksandr.urakov, rnk, teemperor, DavidSpickett, aprantl, zturner.
Herald added a project: All.
sgraenitz requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: jplehr, sstefan1.
Herald added a project: LLDB.

While C++ base classes are registered with CreateBaseClassSpecifier(), we have to use SetObjCSuperClass() for ObjC. The isa member of NSObject is a zero-length UDT. Special handling for ObjC id type will be added in one of the next patches.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146297

Files:
  lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
  lldb/test/Shell/Expr/objc-gnustep-print-pdb.m


Index: lldb/test/Shell/Expr/objc-gnustep-print-pdb.m
===================================================================
--- lldb/test/Shell/Expr/objc-gnustep-print-pdb.m
+++ lldb/test/Shell/Expr/objc-gnustep-print-pdb.m
@@ -41,26 +41,30 @@
 }
 @end
 
-// RUN: %lldb -b -o "b objc-gnustep-print-pdb.m:67" -o "run" -o "p ptr" -o "p *ptr" -- %t | FileCheck %s
+// RUN: %lldb -b -o "b objc-gnustep-print-pdb.m:72" -o "run" -o "p ptr" -o "p *ptr" -- %t | FileCheck %s
 //
-// CHECK: (lldb) b objc-gnustep-print-pdb.m:67
-// CHECK: Breakpoint {{.*}} at objc-gnustep-print-pdb.m:67
+// CHECK: (lldb) b objc-gnustep-print-pdb.m:72
+// CHECK: Breakpoint {{.*}} at objc-gnustep-print-pdb.m:72
 //
 // CHECK: (lldb) run
 // CHECK: Process {{[0-9]+}} stopped
-// CHECK: frame #0: {{.*}}`main  at objc-gnustep-print-pdb.m:67
+// CHECK: frame #0: {{.*}}`main  at objc-gnustep-print-pdb.m:72
 //
 // CHECK: (lldb) p ptr
 // CHECK: (TestObj *) $0 = 0x{{[0-9]+}}
 //
 // CHECK: (lldb) p *ptr
 // CHECK: (TestObj) $1 = {
-// CHECK:   _int
-// CHECK:   _float
-// CHECK:   _char
-// CHECK:   _ptr_void
-// CHECK:   _ptr_nsobject
-// CHECK:   _id_objc
+// CHECK:   NSObject = {
+// CHECK:     isa = 0x{{[0-9]+}}
+// CHECK:     refcount
+// CHECK:   }
+// CHECK:   _int = 0
+// CHECK:   _float = 0
+// CHECK:   _char = '\0'
+// CHECK:   _ptr_void = 0x{{0+}}
+// CHECK:   _ptr_nsobject = nil
+// CHECK:   _id_objc = nil
 // CHECK: }
 
 int main() {
Index: lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
+++ lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
@@ -345,6 +345,10 @@
   return name == "`anonymous namespace'" || name == "`anonymous-namespace'";
 }
 
+static bool IsSpecialNameObjC(llvm::StringRef name) {
+  return name == "objc_object" || name == "objc_class";
+}
+
 static clang::CallingConv TranslateCallingConvention(PDB_CallingConv pdb_cc) {
   switch (pdb_cc) {
   case llvm::codeview::CallingConvention::NearC:
@@ -393,16 +397,16 @@
     //    union Union { short Row; short Col; }
     // Such symbols will be handled here.
 
-    // Some UDT with trival ctor has zero length. Just ignore.
-    if (udt->getLength() == 0)
-      return nullptr;
-
     // Ignore unnamed-tag UDTs.
     std::string name =
         std::string(MSVCUndecoratedNameParser::DropScope(udt->getName()));
     if (name.empty())
       return nullptr;
 
+    // Some UDT with trival ctor has zero length. Just ignore.
+    if (udt->getLength() == 0 && !IsSpecialNameObjC(name))
+      return nullptr;
+
     auto decl_context = GetDeclContextContainingSymbol(type);
 
     // PDB has no attribute to encode the language per symbol. We assume
@@ -1406,6 +1410,12 @@
         TypeSystemClang::CompleteTagDeclarationDefinition(base_comp_type);
     }
 
+    if (TypeSystemClang::IsObjCObjectOrInterfaceType(base_comp_type)) {
+      m_ast.SetObjCSuperClass(record_type, base_comp_type);
+      assert(bases_enum.getNext() == nullptr && "Single inheritance only");
+      return;
+    }
+
     auto access = TranslateMemberAccess(base->getAccess());
 
     auto is_virtual = base->isVirtualBaseClass();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146297.506079.patch
Type: text/x-patch
Size: 3202 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230317/1aa1ed7b/attachment-0001.bin>


More information about the lldb-commits mailing list