Michael Buch bf2d84db8e
[lldb][ObjC] Consult Objective-C runtime decl vendor when completing type (#164011)
(Note, this upstreams code that has been deployed on Apple's Swift LLDB
for many years at this point).

When a `ValueObject` computes its "complete type"
(`MaybeCalculateCompleteType`), it gives the language runtimes a chance
to override the type known to it. The current implementation of
`ObjCLanguageRuntime::GetRuntimeType`, however, didn't consult the
`AppleObjCDeclVendor` to look for types.

As demonstrated in the attached test, when we don't have debug-info for
a base class type (most commonly happens when inheriting from system
framework types) we would not be able to deduce ivars of that type.
However, the runtime knows about the ivars, so we should be able to
retrieve them.

There's still a couple of caveats for future follow-up/investigation:
1. `frame var` isn't able to access such backing ivars explicitly (even
if they do exist)
2. When compiling with `-gmodules`, LLDB gets confused about what is
correct source of information for these decls is.

rdar://162069497
2025-10-17 23:27:57 +01:00

40 lines
1.4 KiB
Python

import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class TestIvarInFrameworkBase(TestBase):
"""
Tests whether LLDB's data inspection commands can correctly retrieve
information about ivars from the Objective-C runtime.
In this test-case we have a base class type for which we don't have access
to the debug-info of the implementation (mimicking the scenario of subclassing
a type from a system framework). LLDB won't be able to see the backing ivar for
'fooProp' from just debug-info, but it will fall back on the runtime to get the
necessary information.
"""
def test_frame_var(self):
self.build()
lldbutil.run_to_source_breakpoint(self, "break here", lldb.SBFileSpec("main.m"))
self.expect("frame variable *bar", substrs=["_fooProp = 10", "_barProp = 15"])
def test_expr(self):
self.build()
lldbutil.run_to_source_breakpoint(self, "break here", lldb.SBFileSpec("main.m"))
self.expect_expr(
"*bar",
result_type="Bar",
result_children=[
ValueCheck(
name="Foo",
children=[
ValueCheck(name="NSObject"),
ValueCheck(name="_fooProp", value="10"),
],
),
ValueCheck(name="_barProp", value="15"),
],
)