Skip to content

Commit 59315c5

Browse files
[lldb][gnustep][PDB] Parse ObjC base classes and recognize NSObject type
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. Differential Revision: https://reviews.llvm.org/D146297
1 parent 820d765 commit 59315c5

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,10 @@ static bool IsAnonymousNamespaceName(llvm::StringRef name) {
338338
return name == "`anonymous namespace'" || name == "`anonymous-namespace'";
339339
}
340340

341+
static bool IsSpecialNameObjC(llvm::StringRef name) {
342+
return name == "objc_object" || name == "objc_class";
343+
}
344+
341345
static clang::CallingConv TranslateCallingConvention(PDB_CallingConv pdb_cc) {
342346
switch (pdb_cc) {
343347
case llvm::codeview::CallingConvention::NearC:
@@ -386,16 +390,16 @@ lldb::TypeSP PDBASTParser::CreateLLDBTypeFromPDBType(const PDBSymbol &type) {
386390
// union Union { short Row; short Col; }
387391
// Such symbols will be handled here.
388392

389-
// Some UDT with trival ctor has zero length. Just ignore.
390-
if (udt->getLength() == 0)
391-
return nullptr;
392-
393393
// Ignore unnamed-tag UDTs.
394394
std::string name =
395395
std::string(MSVCUndecoratedNameParser::DropScope(udt->getName()));
396396
if (name.empty())
397397
return nullptr;
398398

399+
// Some UDT with trival ctor has zero length. Just ignore.
400+
if (udt->getLength() == 0 && !IsSpecialNameObjC(name))
401+
return nullptr;
402+
399403
auto decl_context = GetDeclContextContainingSymbol(type);
400404

401405
// PDB has no attribute to encode the language per symbol. We assume
@@ -1403,6 +1407,12 @@ void PDBASTParser::AddRecordBases(
14031407
TypeSystemClang::CompleteTagDeclarationDefinition(base_comp_type);
14041408
}
14051409

1410+
if (TypeSystemClang::IsObjCObjectOrInterfaceType(base_comp_type)) {
1411+
m_ast.SetObjCSuperClass(record_type, base_comp_type);
1412+
assert(bases_enum.getNext() == nullptr && "Single inheritance only");
1413+
return;
1414+
}
1415+
14061416
auto access = TranslateMemberAccess(base->getAccess());
14071417

14081418
auto is_virtual = base->isVirtualBaseClass();

lldb/test/Shell/Expr/objc-gnustep-print-pdb.m

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,30 @@ - (int)ok {
4141
}
4242
@end
4343

44-
// RUN: %lldb -b -o "b objc-gnustep-print-pdb.m:67" -o "run" -o "p ptr" -o "p *ptr" -- %t | FileCheck %s
44+
// RUN: %lldb -b -o "b objc-gnustep-print-pdb.m:72" -o "run" -o "p ptr" -o "p *ptr" -- %t | FileCheck %s
4545
//
46-
// CHECK: (lldb) b objc-gnustep-print-pdb.m:67
47-
// CHECK: Breakpoint {{.*}} at objc-gnustep-print-pdb.m:67
46+
// CHECK: (lldb) b objc-gnustep-print-pdb.m:72
47+
// CHECK: Breakpoint {{.*}} at objc-gnustep-print-pdb.m:72
4848
//
4949
// CHECK: (lldb) run
5050
// CHECK: Process {{[0-9]+}} stopped
51-
// CHECK: frame #0: {{.*}}`main at objc-gnustep-print-pdb.m:67
51+
// CHECK: frame #0: {{.*}}`main at objc-gnustep-print-pdb.m:72
5252
//
5353
// CHECK: (lldb) p ptr
5454
// CHECK: (TestObj *) $0 = 0x{{[0-9]+}}
5555
//
5656
// CHECK: (lldb) p *ptr
5757
// CHECK: (TestObj) $1 = {
58-
// CHECK: _int
59-
// CHECK: _float
60-
// CHECK: _char
61-
// CHECK: _ptr_void
62-
// CHECK: _ptr_nsobject
63-
// CHECK: _id_objc
58+
// CHECK: NSObject = {
59+
// CHECK: isa = 0x{{[0-9]+}}
60+
// CHECK: refcount
61+
// CHECK: }
62+
// CHECK: _int = 0
63+
// CHECK: _float = 0
64+
// CHECK: _char = '\0'
65+
// CHECK: _ptr_void = 0x{{0+}}
66+
// CHECK: _ptr_nsobject = nil
67+
// CHECK: _id_objc = nil
6468
// CHECK: }
6569

6670
int main() {

0 commit comments

Comments
 (0)