Skip to content

Commit 3708b80

Browse files
Merge pull request #7451 from augusto2112/5.9-artificial-class
[lldb] Improve handling of artificial subclasses
2 parents ff35dfd + 898a7d8 commit 3708b80

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntimeDynamicTypeResolution.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1527,6 +1527,11 @@ CompilerType SwiftLanguageRuntimeImpl::GetChildCompilerTypeAtIndex(
15271527
lldb::addr_t pointer = valobj->GetPointerValue();
15281528
reflection_ctx->ForEachSuperClassType(
15291529
&tip, pointer, [&](SuperClassType sc) -> bool {
1530+
// If the typeref is invalid, we don't want to process it (for
1531+
// example, this could be an artifical ObjC class).
1532+
if (!sc.get_typeref())
1533+
return false;
1534+
15301535
if (!found_start) {
15311536
// The ValueObject always points to the same class instance,
15321537
// even when querying base classes. Drop base classes until we
@@ -2013,7 +2018,8 @@ bool SwiftLanguageRuntimeImpl::GetDynamicTypeAndAddress_Class(
20132018
}
20142019
Log *log(GetLog(LLDBLog::Types));
20152020
ThreadSafeReflectionContext reflection_ctx = GetReflectionContext();
2016-
const auto *typeref = reflection_ctx->readTypeFromInstance(instance_ptr);
2021+
const auto *typeref =
2022+
reflection_ctx->readTypeFromInstance(instance_ptr, true);
20172023
if (!typeref) {
20182024
LLDB_LOGF(log,
20192025
"could not read typeref for type: %s (instance_ptr = 0x%" PRIx64
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SWIFT_SOURCES := main.swift
2+
include Makefile.rules
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import lldb
2+
from lldbsuite.test.lldbtest import *
3+
from lldbsuite.test.decorators import *
4+
import lldbsuite.test.lldbutil as lldbutil
5+
import unittest2
6+
7+
8+
class TestSwiftArtificialSubclass(TestBase):
9+
@skipUnlessObjCInterop
10+
@swiftTest
11+
def test(self):
12+
""" Test that displaying an artificial type works correctly"""
13+
self.build()
14+
_, _, _, _ = lldbutil.run_to_source_breakpoint(
15+
self, "break here", lldb.SBFileSpec("main.swift")
16+
)
17+
18+
19+
self.expect(
20+
"frame variable m",
21+
substrs=["Subclass)", "Superclass", "a = 42", "b = 97"]
22+
)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import ObjectiveC
2+
3+
class Superclass {
4+
let a = 42
5+
}
6+
7+
class Subclass: Superclass {
8+
let b = 97
9+
10+
override init() {
11+
super.init()
12+
let c: AnyClass = objc_allocateClassPair(Subclass.self, "DynamicSubclass", 0)!
13+
objc_registerClassPair(c);
14+
object_setClass(self, c)
15+
}
16+
}
17+
18+
let m = Subclass()
19+
print(m) // break here

0 commit comments

Comments
 (0)