1"""
2Test the ptr_refs tool on Darwin with Objective-C
3"""
4
5
6import lldb
7from lldbsuite.test.decorators import *
8from lldbsuite.test.lldbtest import *
9from lldbsuite.test import lldbutil
10
11
12class TestPtrRefsObjC(TestBase):
13
14    @skipIfAsan # The output looks different under ASAN.
15    def test_ptr_refs(self):
16        """Test the ptr_refs tool on Darwin with Objective-C"""
17        self.build()
18        exe = self.getBuildArtifact("a.out")
19
20        target = self.dbg.CreateTarget(exe)
21        self.assertTrue(target, VALID_TARGET)
22
23        main_file_spec = lldb.SBFileSpec('main.m')
24        breakpoint = target.BreakpointCreateBySourceRegex(
25            'break', main_file_spec)
26        self.assertTrue(breakpoint and
27                        breakpoint.GetNumLocations() == 1,
28                        VALID_BREAKPOINT)
29
30        process = target.LaunchSimple(
31            None, None, self.get_process_working_directory())
32        self.assertTrue(process, PROCESS_IS_VALID)
33
34        # Frame #0 should be on self.line1 and the break condition should hold.
35        thread = lldbutil.get_stopped_thread(
36            process, lldb.eStopReasonBreakpoint)
37        self.assertTrue(
38            thread.IsValid(),
39            "There should be a thread stopped due to breakpoint condition")
40
41        frame = thread.GetFrameAtIndex(0)
42
43        self.runCmd("command script import lldb.macosx.heap")
44        self.expect("ptr_refs self", substrs=["malloc", "stack"])
45
46