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