Skip to content

[lldb] Improve handling of artificial subclasses #7451

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1527,6 +1527,11 @@ CompilerType SwiftLanguageRuntimeImpl::GetChildCompilerTypeAtIndex(
lldb::addr_t pointer = valobj->GetPointerValue();
reflection_ctx->ForEachSuperClassType(
&tip, pointer, [&](SuperClassType sc) -> bool {
// If the typeref is invalid, we don't want to process it (for
// example, this could be an artifical ObjC class).
if (!sc.get_typeref())
return false;

if (!found_start) {
// The ValueObject always points to the same class instance,
// even when querying base classes. Drop base classes until we
Expand Down Expand Up @@ -2013,7 +2018,8 @@ bool SwiftLanguageRuntimeImpl::GetDynamicTypeAndAddress_Class(
}
Log *log(GetLog(LLDBLog::Types));
ThreadSafeReflectionContext reflection_ctx = GetReflectionContext();
const auto *typeref = reflection_ctx->readTypeFromInstance(instance_ptr);
const auto *typeref =
reflection_ctx->readTypeFromInstance(instance_ptr, true);
if (!typeref) {
LLDB_LOGF(log,
"could not read typeref for type: %s (instance_ptr = 0x%" PRIx64
Expand Down
2 changes: 2 additions & 0 deletions lldb/test/API/lang/swift/artificial_subclass/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SWIFT_SOURCES := main.swift
include Makefile.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import lldb
from lldbsuite.test.lldbtest import *
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbutil as lldbutil
import unittest2


class TestSwiftArtificialSubclass(TestBase):
@skipUnlessObjCInterop
@swiftTest
def test(self):
""" Test that displaying an artificial type works correctly"""
self.build()
_, _, _, _ = lldbutil.run_to_source_breakpoint(
self, "break here", lldb.SBFileSpec("main.swift")
)


self.expect(
"frame variable m",
substrs=["Subclass)", "Superclass", "a = 42", "b = 97"]
)
19 changes: 19 additions & 0 deletions lldb/test/API/lang/swift/artificial_subclass/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import ObjectiveC

class Superclass {
let a = 42
}

class Subclass: Superclass {
let b = 97

override init() {
super.init()
let c: AnyClass = objc_allocateClassPair(Subclass.self, "DynamicSubclass", 0)!
objc_registerClassPair(c);
object_setClass(self, c)
}
}

let m = Subclass()
print(m) // break here