xref: /llvm-project/lldb/test/API/lang/objc/real-definition/TestRealDefinition.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
1"""Test that types defined in shared libraries work correctly."""
2
3
4import lldb
5from lldbsuite.test.decorators import *
6from lldbsuite.test.lldbtest import *
7from lldbsuite.test import lldbutil
8
9
10class TestRealDefinition(TestBase):
11    def test_frame_var_after_stop_at_interface(self):
12        """Test that we can find the implementation for an objective C type"""
13        if self.getArchitecture() == "i386":
14            self.skipTest("requires modern objc runtime")
15        self.build()
16
17        lldbutil.run_to_source_breakpoint(
18            self,
19            "// Set breakpoint where Bar is an interface",
20            lldb.SBFileSpec("Foo.m", False),
21        )
22
23        # Break inside the foo function which takes a bar_ptr argument.
24        self.expect('breakpoint set -p "// Set breakpoint in main"')
25        self.runCmd("continue", RUN_SUCCEEDED)
26
27        # Run at stop at main
28        lldbutil.check_breakpoint(self, bpno=1, expected_hit_count=1)
29
30        self.runCmd("settings set target.prefer-dynamic-value no-dynamic-values")
31
32        # This should display correctly.
33        self.expect(
34            "frame variable foo->_bar->_hidden_ivar",
35            VARIABLES_DISPLAYED_CORRECTLY,
36            substrs=["(NSString *)", "foo->_bar->_hidden_ivar = 0x"],
37        )
38
39    def test_frame_var_after_stop_at_implementation(self):
40        """Test that we can find the implementation for an objective C type"""
41        if self.getArchitecture() == "i386":
42            self.skipTest("requires modern objc runtime")
43        self.build()
44
45        lldbutil.run_to_source_breakpoint(
46            self,
47            "// Set breakpoint where Bar is an implementation",
48            lldb.SBFileSpec("Bar.m", False),
49        )
50
51        self.expect('breakpoint set -p "// Set breakpoint in main"')
52        self.runCmd("continue", RUN_SUCCEEDED)
53
54        # Run at stop at main
55        lldbutil.check_breakpoint(self, bpno=1, expected_hit_count=1)
56
57        self.runCmd("settings set target.prefer-dynamic-value no-dynamic-values")
58
59        # This should display correctly.
60        self.expect(
61            "frame variable foo->_bar->_hidden_ivar",
62            VARIABLES_DISPLAYED_CORRECTLY,
63            substrs=["(NSString *)", "foo->_bar->_hidden_ivar = 0x"],
64        )
65