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    @skipIfAsan # The output looks different under ASAN.
15    @skipUnlessDarwin
16    def test_ptr_refs(self):
17        """Test format string functionality."""
18        self.build()
19        exe = self.getBuildArtifact("a.out")
20
21        target = self.dbg.CreateTarget(exe)
22        self.assertTrue(target, VALID_TARGET)
23
24        main_file_spec = lldb.SBFileSpec('main.c')
25        breakpoint = target.BreakpointCreateBySourceRegex(
26            'break', main_file_spec)
27        self.assertTrue(breakpoint and
28                        breakpoint.GetNumLocations() == 1,
29                        VALID_BREAKPOINT)
30
31        process = target.LaunchSimple(
32            None, None, self.get_process_working_directory())
33        self.assertTrue(process, PROCESS_IS_VALID)
34
35        # Frame #0 should be on self.line1 and the break condition should hold.
36        thread = lldbutil.get_stopped_thread(
37            process, lldb.eStopReasonBreakpoint)
38        self.assertTrue(
39            thread.IsValid(),
40            "There should be a thread stopped due to breakpoint condition")
41
42        frame = thread.GetFrameAtIndex(0)
43
44        self.runCmd("command script import lldb.macosx.heap")
45        self.expect("ptr_refs my_ptr", substrs=["malloc", "stack"])
46