def test_with_run_command(self):
        self.build()
        exe = os.path.join(os.getcwd(), "a.out")
        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target and target.IsValid(), "Target is valid")

        file_spec = lldb.SBFileSpec ("main.cpp", False)
        breakpoint1 = target.BreakpointCreateBySourceRegex('// Set break point at this line.', file_spec)
        self.assertTrue(breakpoint1 and breakpoint1.IsValid())
        breakpoint2 = target.BreakpointCreateBySourceRegex('// Set second break point at this line.', file_spec)
        self.assertTrue(breakpoint2 and breakpoint2.IsValid())

        # Run the program, it should stop at breakpoint 1.
        process = target.LaunchSimple(None, None, self.get_process_working_directory())
        lldbutil.skip_if_library_missing(self, target, lldbutil.PrintableRegex("libc\+\+"))
        self.assertTrue(process and process.IsValid(), PROCESS_IS_VALID)
        self.assertEquals(len(lldbutil.get_threads_stopped_at_breakpoint(process, breakpoint1)), 1)

        # verify our list is displayed correctly
        self.expect("frame variable *numbers_list", substrs=['[0] = 1', '[1] = 2', '[2] = 3', '[3] = 4', '[5] = 6'])

        # Continue to breakpoint 2.
        process.Continue()
        self.assertTrue(process and process.IsValid(), PROCESS_IS_VALID)
        self.assertEquals(len(lldbutil.get_threads_stopped_at_breakpoint(process, breakpoint2)), 1)

        # The list is now inconsistent. However, we should be able to get the first three
        # elements at least (and most importantly, not crash).
        self.expect("frame variable *numbers_list", substrs=['[0] = 1', '[1] = 2', '[2] = 3'])

        # Run to completion.
        process.Continue()
        self.assertEqual(process.GetState(), lldb.eStateExited, PROCESS_EXITED)
예제 #2
0
    def test_formatters_api(self):
        """Test that SBFrame::FindValue finds things but does not duplicate the entire variables list"""
        self.build()
        self.setTearDownCleanup()

        exe_name = "a.out"
        exe = os.path.join(os.getcwd(), exe_name)

        # Create the target
        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)
        
        # Set the breakpoints
        breakpoint = target.BreakpointCreateBySourceRegex('Set breakpoint here', lldb.SBFileSpec("main.cpp"))
        self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT)

        # Launch the process, and do not stop at the entry point.
        process = target.LaunchSimple(None, None, self.get_process_working_directory())

        self.assertTrue(process, PROCESS_IS_VALID)

        # Frame #0 should be at our breakpoint.
        threads = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint)
        
        self.assertTrue(len(threads) == 1)
        self.thread = threads[0]
        self.frame = self.thread.frames[0]
        self.assertTrue(self.frame, "Frame 0 is valid.")

        self.assertTrue(self.frame.GetVariables(True,True,False,True).GetSize() == 2, "variable count is off")
        self.assertFalse(self.frame.FindValue("NoSuchThing",lldb.eValueTypeVariableArgument,lldb.eDynamicCanRunTarget).IsValid(), "found something that should not be here")
        self.assertTrue(self.frame.GetVariables(True,True,False,True).GetSize() == 2, "variable count is off after failed FindValue()")
        self.assertTrue(self.frame.FindValue("a",lldb.eValueTypeVariableArgument,lldb.eDynamicCanRunTarget).IsValid(), "FindValue() didn't find an argument")
        self.assertTrue(self.frame.GetVariables(True,True,False,True).GetSize() == 2, "variable count is off after successful FindValue()")
예제 #3
0
    def check_goroutines(self):
        self.assertLess(len(self.process().threads), 20)
        self.process().Continue()

        # Make sure we stopped at the 2nd breakpoint
        thread_list = lldbutil.get_threads_stopped_at_breakpoint(
            self.process(), self.bpt2)
        self.assertTrue(
            len(thread_list) != 0, "No thread stopped at our breakpoint.")
        self.assertTrue(
            len(thread_list) == 1,
            "More than one thread stopped at our breakpoint.")

        # There's (at least) 21 goroutines.
        self.assertGreater(len(self.process().threads), 20)
        # self.dbg.HandleCommand("log enable lldb os")

        # Now test that stepping works if the memory thread moves to a different backing thread.
        for i in xrange(11):
            self.thread().StepOver()
            self.assertEqual(lldb.eStopReasonPlanComplete,
                             self.thread().GetStopReason(),
                             self.thread().GetStopDescription(100))

        # Disable the plugin and make sure the goroutines disappear
        self.dbg.HandleCommand(
            "settings set plugin.os.goroutines.enable false")
        self.thread().StepInstruction(False)
        self.assertLess(len(self.process().threads), 20)
예제 #4
0
    def test_with_python_api(self):
        """Test function call thread safety."""
        self.build()
        exe = os.path.join(os.getcwd(), "a.out")

        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)
        self.main_source_spec = lldb.SBFileSpec (self.main_source)
        break1 = target.BreakpointCreateByName ("stopper", 'a.out')
        self.assertTrue(break1, VALID_BREAKPOINT)
        process = target.LaunchSimple (None, None, self.get_process_working_directory())
        self.assertTrue(process, PROCESS_IS_VALID)
        threads = lldbutil.get_threads_stopped_at_breakpoint (process, break1)
        if len(threads) != 1:
            self.fail ("Failed to stop at breakpoint 1.")

        self.check_number_of_threads(process)

        main_thread = lldb.SBThread()
        select_thread = lldb.SBThread()
        for idx in range (0, process.GetNumThreads()):
            t = process.GetThreadAtIndex (idx)
            if t.GetName() == "main thread":
                main_thread = t
            if t.GetName() == "select thread":
                select_thread = t

        self.assertTrue(main_thread.IsValid() and select_thread.IsValid(), "Got both expected threads")

        self.safe_to_call_func_on_main_thread (main_thread)
        self.safe_to_call_func_on_select_thread (select_thread)
예제 #5
0
    def run_to_main(self):
        """Test that expr uses the correct property getters and setters"""
        exe = os.path.join(os.getcwd(), "a.out")

        # Create a target from the debugger.

        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        # Set up our breakpoints:

        main_bkpt = target.BreakpointCreateBySourceRegex(
            "Set a breakpoint here.", lldb.SBFileSpec(self.source_name))
        self.assertTrue(main_bkpt and main_bkpt.GetNumLocations() == 1,
                        VALID_BREAKPOINT)

        # Now launch the process, and do not stop at the entry point.
        process = target.LaunchSimple(None, None,
                                      self.get_process_working_directory())

        self.assertTrue(process.GetState() == lldb.eStateStopped,
                        PROCESS_STOPPED)

        threads = lldbutil.get_threads_stopped_at_breakpoint(
            process, main_bkpt)
        self.assertTrue(len(threads) == 1)
        thread = threads[0]
        return thread
예제 #6
0
    def objc_builtin_types(self):
        """Test expression parser respect for ObjC built-in types."""
        exe = os.path.join(os.getcwd(), "a.out")

        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        bpt = target.BreakpointCreateByLocation(self.main_source,
                                                self.break_line)
        self.assertTrue(bpt, VALID_BREAKPOINT)

        # Now launch the process, and do not stop at entry point.
        process = target.LaunchSimple(None, None, os.getcwd())

        self.assertTrue(process, PROCESS_IS_VALID)

        # The stop reason of the thread should be breakpoint.
        thread_list = lldbutil.get_threads_stopped_at_breakpoint(process, bpt)

        # Make sure we stopped at the first breakpoint.
        self.assertTrue(
            len(thread_list) != 0, "No thread stopped at our breakpoint.")
        self.assertTrue(
            len(thread_list) == 1,
            "More than one thread stopped at our breakpoint.")

        # Now make sure we can call a function in the class method we've stopped in.
        frame = thread_list[0].GetFrameAtIndex(0)
        self.assertTrue(frame, "Got a valid frame 0 frame.")

        self.expect("expr (foo)", patterns=["\(ns::id\) \$.* = 0"])

        self.expect("expr id my_id = 0; my_id", patterns=["\(id\) \$.* = 0x0"])
예제 #7
0
    def objc_static_method(self):
        """Test calling functions in static methods."""
        exe = os.path.join(os.getcwd(), "a.out")

        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        bpt = target.BreakpointCreateByLocation(self.main_source, self.break_line)
        self.assertTrue(bpt, VALID_BREAKPOINT)

        # Now launch the process, and do not stop at entry point.
        process = target.LaunchSimple (None, None, os.getcwd())

        self.assertTrue(process, PROCESS_IS_VALID)

        # The stop reason of the thread should be breakpoint.
        thread_list = lldbutil.get_threads_stopped_at_breakpoint (process, bpt)

        # Make sure we stopped at the first breakpoint.
        self.assertTrue (len(thread_list) != 0, "No thread stopped at our breakpoint.")
        self.assertTrue (len(thread_list) == 1, "More than one thread stopped at our breakpoint.")
            
        # Now make sure we can call a function in the static method we've stopped in.
        frame = thread_list[0].GetFrameAtIndex(0)
        self.assertTrue (frame, "Got a valid frame 0 frame.")

        cmd_value = frame.EvaluateExpression ("(char *) sel_getName (_cmd)")
        self.assertTrue (cmd_value.IsValid())
        sel_name = cmd_value.GetSummary()
        self.assertTrue (sel_name == "\"doSomethingWithString:\"", "Got the right value for the selector as string.")

        cmd_value = frame.EvaluateExpression ("[self doSomethingElseWithString:string]")
        self.assertTrue (cmd_value.IsValid())
        string_length = cmd_value.GetValueAsUnsigned()
        self.assertTrue (string_length == 27, "Got the right value from another class method on the same class.")
예제 #8
0
    def objc_ivar_offsets(self):
        """Test that we can find stripped Objective-C ivars in the runtime"""
        exe = os.path.join(os.getcwd(), "a.out.stripped")

        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        self.dbg.HandleCommand("add-dsym a.out.dSYM")

        breakpoint = target.BreakpointCreateByLocation(self.main_source, self.stop_line)
        self.assertTrue(breakpoint.IsValid() and breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT)

        process = target.LaunchSimple (None, None, self.get_process_working_directory())
        self.assertTrue (process, "Created a process.")
        self.assertTrue (process.GetState() == lldb.eStateStopped, "Stopped it too.")

        thread_list = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint)
        self.assertTrue (len(thread_list) == 1)
        thread = thread_list[0]
        
        frame = thread.GetFrameAtIndex(0)
        self.assertTrue (frame, "frame 0 is valid")
        
        # Test the expression for mc->_foo

        error = lldb.SBError()

        ivar = frame.EvaluateExpression ("(mc->_foo)")
        self.assertTrue(ivar, "Got result for mc->_foo")
        ivar_value = ivar.GetValueAsSigned (error)
        self.assertTrue (error.Success())
        self.assertTrue (ivar_value == 3)
예제 #9
0
    def child_by_name(self):
        exe = os.path.join (os.getcwd(), "a.out")
        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        break_in_main = target.BreakpointCreateBySourceRegex ('// Set breakpoint 2 here.', lldb.SBFileSpec("main.c"))
        self.assertTrue(break_in_main, VALID_BREAKPOINT)

        process = target.LaunchSimple (None, None, os.getcwd())
        self.assertTrue (process, PROCESS_IS_VALID)

        threads = lldbutil.get_threads_stopped_at_breakpoint (process, break_in_main)
        if len(threads) != 1:
            self.fail ("Failed to stop at breakpoint in main.")

        thread = threads[0]
        frame = thread.frames[0]

        if not frame.IsValid():
            self.fail ("Failed to get frame 0.")

        var_n = frame.FindVariable("n")
        if not var_n.IsValid():
            self.fail ("Failed to get the variable 'n'")

        elem_a = var_n.GetChildMemberWithName("a")
        if not elem_a.IsValid():
            self.fail ("Failed to get the element a in n")

        error = lldb.SBError()
        value = elem_a.GetValueAsSigned(error, 1000)
        if not error.Success() or value != 0:
            self.fail ("failed to get the correct value for element a in n")
    def objc_class_method(self):
        """Test calling class methods."""
        exe = os.path.join(os.getcwd(), "a.out")

        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        bpt = target.BreakpointCreateByLocation(self.main_source,
                                                self.break_line)
        self.assertTrue(bpt, VALID_BREAKPOINT)

        # Now launch the process, and do not stop at entry point.
        process = target.LaunchSimple(None, None, os.getcwd())

        self.assertTrue(process, PROCESS_IS_VALID)

        # The stop reason of the thread should be breakpoint.
        thread_list = lldbutil.get_threads_stopped_at_breakpoint(process, bpt)

        # Make sure we stopped at the first breakpoint.
        self.assertTrue(
            len(thread_list) != 0, "No thread stopped at our breakpoint.")
        self.assertTrue(
            len(thread_list) == 1,
            "More than one thread stopped at our breakpoint.")

        # Now make sure we can call a function in the class method we've stopped in.
        frame = thread_list[0].GetFrameAtIndex(0)
        self.assertTrue(frame, "Got a valid frame 0 frame.")

        cmd_value = frame.EvaluateExpression(
            "(int)[Foo doSomethingWithString:@\"Hello\"]")
        self.assertTrue(cmd_value.IsValid())
        self.assertTrue(cmd_value.GetValueAsUnsigned() == 5)
예제 #11
0
    def do_test(self, dictionary=None):
        """These basic expression commands should work as expected."""
        self.buildDefault(dictionary = dictionary)

        target = self.dbg.CreateTarget(self.exe)
        self.assertTrue(target)

        breakpoint = target.BreakpointCreateBySourceRegex('// Break here', self.main_source_spec)
        self.assertTrue(breakpoint)

        # Launch the process, and do not stop at the entry point.
        process = target.LaunchSimple(None, None, self.get_process_working_directory())
        self.assertTrue(process)

        threads = lldbutil.get_threads_stopped_at_breakpoint(process, breakpoint)
        self.assertEqual(len(threads), 1)

        frame = threads[0].GetFrameAtIndex(0)

        value = frame.EvaluateExpression("foo(c)")
        self.assertTrue(value.IsValid())
        self.assertTrue(value.GetError().Success())
        self.assertEqual(value.GetValueAsSigned(0), 1)

        value = frame.EvaluateExpression("foo(sc)")
        self.assertTrue(value.IsValid())
        self.assertTrue(value.GetError().Success())
        self.assertEqual(value.GetValueAsSigned(0), 2)

        value = frame.EvaluateExpression("foo(uc)")
        self.assertTrue(value.IsValid())
        self.assertTrue(value.GetError().Success())
        self.assertEqual(value.GetValueAsSigned(0), 3)
예제 #12
0
    def run_to_main (self):
        """Test that expr uses the correct property getters and setters"""
        exe = os.path.join(os.getcwd(), "a.out")

        # Create a target from the debugger.

        target = self.dbg.CreateTarget (exe)
        self.assertTrue(target, VALID_TARGET)

        # Set up our breakpoints:
        
        main_bkpt = target.BreakpointCreateBySourceRegex ("Set a breakpoint here.", lldb.SBFileSpec (self.source_name))
        self.assertTrue(main_bkpt and
                        main_bkpt.GetNumLocations() == 1,
                        VALID_BREAKPOINT)

        # Now launch the process, and do not stop at the entry point.
        process = target.LaunchSimple (None, None, os.getcwd())

        self.assertTrue(process.GetState() == lldb.eStateStopped,
                        PROCESS_STOPPED)

        threads = lldbutil.get_threads_stopped_at_breakpoint (process, main_bkpt)
        self.assertTrue (len(threads) == 1)
        thread = threads[0]
        return thread
예제 #13
0
    def step_in_template(self):
        """Use Python APIs to test stepping in to templated functions."""
        exe = os.path.join(os.getcwd(), "a.out")

        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        break_1_in_main = target.BreakpointCreateBySourceRegex ('// Call max_value template', self.main_source_spec)
        self.assertTrue(break_1_in_main, VALID_BREAKPOINT)
        
        break_2_in_main = target.BreakpointCreateBySourceRegex ('// Call max_value specialized', self.main_source_spec)
        self.assertTrue(break_2_in_main, VALID_BREAKPOINT)

        # Now launch the process, and do not stop at entry point.
        self.process = target.LaunchSimple (None, None, self.get_process_working_directory())
        self.assertTrue(self.process, PROCESS_IS_VALID)

        # The stop reason of the thread should be breakpoint.
        threads = lldbutil.get_threads_stopped_at_breakpoint (self.process, break_1_in_main)

        if len(threads) != 1:
            self.fail ("Failed to stop at first breakpoint in main.")

        self.thread = threads[0]

        step_sequence = [["// In max_value template", "into"]]
        self.run_step_sequence(step_sequence)
        
        threads = lldbutil.continue_to_breakpoint (self.process, break_2_in_main)
        self.assertEqual(len(threads), 1, "Successfully ran to call site of second caller_trivial_1 call.")
        self.thread = threads[0]
        
        step_sequence = [["// In max_value specialized", "into"]]
        self.run_step_sequence(step_sequence)
예제 #14
0
    def inline_stepping_step_over(self):
        """Use Python APIs to test stepping over and hitting breakpoints."""
        exe = os.path.join(os.getcwd(), "a.out")

        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        break_1_in_main = target.BreakpointCreateBySourceRegex ('// At second call of caller_ref_1 in main.', self.main_source_spec)
        self.assertTrue(break_1_in_main, VALID_BREAKPOINT)

        # Now launch the process, and do not stop at entry point.
        self.process = target.LaunchSimple (None, None, self.get_process_working_directory())

        self.assertTrue(self.process, PROCESS_IS_VALID)

        # The stop reason of the thread should be breakpoint.
        threads = lldbutil.get_threads_stopped_at_breakpoint (self.process, break_1_in_main)

        if len(threads) != 1:
            self.fail ("Failed to stop at first breakpoint in main.")

        self.thread = threads[0]

        step_sequence = [["// In caller_ref_1.", "into"],
                         ["// In caller_ref_2.", "into"],
                         ["// At increment in caller_ref_2.", "over"]]
        self.run_step_sequence (step_sequence)
예제 #15
0
    def test_formatters_api(self):
        """Test that SBFrame::FindValue finds things but does not duplicate the entire variables list"""
        self.build()
        self.setTearDownCleanup()

        exe_name = "a.out"
        exe = os.path.join(os.getcwd(), exe_name)

        # Create the target
        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)
        
        # Set the breakpoints
        breakpoint = target.BreakpointCreateBySourceRegex('Set breakpoint here', lldb.SBFileSpec("main.cpp"))
        self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT)

        # Launch the process, and do not stop at the entry point.
        process = target.LaunchSimple(None, None, self.get_process_working_directory())

        self.assertTrue(process, PROCESS_IS_VALID)

        # Frame #0 should be at our breakpoint.
        threads = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint)
        
        self.assertTrue(len(threads) == 1)
        self.thread = threads[0]
        self.frame = self.thread.frames[0]
        self.assertTrue(self.frame, "Frame 0 is valid.")

        self.assertTrue(self.frame.GetVariables(True,True,False,True).GetSize() == 2, "variable count is off")
        self.assertFalse(self.frame.FindValue("NoSuchThing",lldb.eValueTypeVariableArgument,lldb.eDynamicCanRunTarget).IsValid(), "found something that should not be here")
        self.assertTrue(self.frame.GetVariables(True,True,False,True).GetSize() == 2, "variable count is off after failed FindValue()")
        self.assertTrue(self.frame.FindValue("a",lldb.eValueTypeVariableArgument,lldb.eDynamicCanRunTarget).IsValid(), "FindValue() didn't find an argument")
        self.assertTrue(self.frame.GetVariables(True,True,False,True).GetSize() == 2, "variable count is off after successful FindValue()")
예제 #16
0
    def do_test(self, dictionary=None):
        """These basic expression commands should work as expected."""
        self.buildDefault(dictionary = dictionary)

        target = self.dbg.CreateTarget(self.exe)
        self.assertTrue(target)

        breakpoint = target.BreakpointCreateBySourceRegex('// Break here', self.main_source_spec)
        self.assertTrue(breakpoint)

        # Launch the process, and do not stop at the entry point.
        process = target.LaunchSimple(None, None, self.get_process_working_directory())
        self.assertTrue(process)

        threads = lldbutil.get_threads_stopped_at_breakpoint(process, breakpoint)
        self.assertEqual(len(threads), 1)

        frame = threads[0].GetFrameAtIndex(0)

        value = frame.EvaluateExpression("foo(c)")
        self.assertTrue(value.IsValid())
        self.assertTrue(value.GetError().Success())
        self.assertEqual(value.GetValueAsSigned(0), 1)

        value = frame.EvaluateExpression("foo(sc)")
        self.assertTrue(value.IsValid())
        self.assertTrue(value.GetError().Success())
        self.assertEqual(value.GetValueAsSigned(0), 2)

        value = frame.EvaluateExpression("foo(uc)")
        self.assertTrue(value.IsValid())
        self.assertTrue(value.GetError().Success())
        self.assertEqual(value.GetValueAsSigned(0), 3)
예제 #17
0
    def step_in_template(self):
        """Use Python APIs to test stepping in to templated functions."""
        exe = os.path.join(os.getcwd(), "a.out")

        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        break_1_in_main = target.BreakpointCreateBySourceRegex("// Call max_value template", self.main_source_spec)
        self.assertTrue(break_1_in_main, VALID_BREAKPOINT)

        break_2_in_main = target.BreakpointCreateBySourceRegex("// Call max_value specialized", self.main_source_spec)
        self.assertTrue(break_2_in_main, VALID_BREAKPOINT)

        # Now launch the process, and do not stop at entry point.
        self.process = target.LaunchSimple(None, None, self.get_process_working_directory())
        self.assertTrue(self.process, PROCESS_IS_VALID)

        # The stop reason of the thread should be breakpoint.
        threads = lldbutil.get_threads_stopped_at_breakpoint(self.process, break_1_in_main)

        if len(threads) != 1:
            self.fail("Failed to stop at first breakpoint in main.")

        self.thread = threads[0]

        step_sequence = [["// In max_value template", "into"]]
        self.run_step_sequence(step_sequence)

        threads = lldbutil.continue_to_breakpoint(self.process, break_2_in_main)
        self.assertEqual(len(threads), 1, "Successfully ran to call site of second caller_trivial_1 call.")
        self.thread = threads[0]

        step_sequence = [["// In max_value specialized", "into"]]
        self.run_step_sequence(step_sequence)
예제 #18
0
    def launchProcess(self):
        exe = os.path.join(os.getcwd(), "a.out")

        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        bpt1 = target.BreakpointCreateByLocation(self.main_source, self.break_line1)
        self.assertTrue(bpt1, VALID_BREAKPOINT)
        bpt2 = target.BreakpointCreateByLocation(self.main_source, self.break_line2)
        self.assertTrue(bpt2, VALID_BREAKPOINT)

        # Now launch the process, and do not stop at entry point.
        process = target.LaunchSimple (None, None, self.get_process_working_directory())

        self.assertTrue(process, PROCESS_IS_VALID)

        # The stop reason of the thread should be breakpoint.
        thread_list = lldbutil.get_threads_stopped_at_breakpoint (process, bpt1)

        # Make sure we stopped at the first breakpoint.
        self.assertTrue (len(thread_list) != 0, "No thread stopped at our breakpoint.")
        self.assertTrue (len(thread_list) == 1, "More than one thread stopped at our breakpoint.")

        frame = thread_list[0].GetFrameAtIndex(0)
        self.assertTrue (frame, "Got a valid frame 0 frame.")
예제 #19
0
    def test_with_python_api(self):
        """Test calling methods on super."""
        self.build()
        exe = os.path.join(os.getcwd(), "a.out")

        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        bpt = target.BreakpointCreateByLocation(self.main_source, self.break_line)
        self.assertTrue(bpt, VALID_BREAKPOINT)

        # Now launch the process, and do not stop at entry point.
        process = target.LaunchSimple (None, None, self.get_process_working_directory())

        self.assertTrue(process, PROCESS_IS_VALID)

        # The stop reason of the thread should be breakpoint.
        thread_list = lldbutil.get_threads_stopped_at_breakpoint (process, bpt)

        # Make sure we stopped at the first breakpoint.
        self.assertTrue (len(thread_list) != 0, "No thread stopped at our breakpoint.")
        self.assertTrue (len(thread_list) == 1, "More than one thread stopped at our breakpoint.")
            
        # Now make sure we can call a function in the class method we've stopped in.
        frame = thread_list[0].GetFrameAtIndex(0)
        self.assertTrue (frame, "Got a valid frame 0 frame.")

        cmd_value = frame.EvaluateExpression ("[self get]")
        self.assertTrue (cmd_value.IsValid())
        self.assertTrue (cmd_value.GetValueAsUnsigned() == 2)

        cmd_value = frame.EvaluateExpression ("[super get]")
        self.assertTrue (cmd_value.IsValid())
        self.assertTrue (cmd_value.GetValueAsUnsigned() == 1)
예제 #20
0
    def launchProcess(self):
        exe = os.path.join(os.getcwd(), "a.out")

        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        bpt1 = target.BreakpointCreateByLocation(self.main_source,
                                                 self.break_line1)
        self.assertTrue(bpt1, VALID_BREAKPOINT)
        bpt2 = target.BreakpointCreateByLocation(self.main_source,
                                                 self.break_line2)
        self.assertTrue(bpt2, VALID_BREAKPOINT)

        # Now launch the process, and do not stop at entry point.
        process = target.LaunchSimple(None, None,
                                      self.get_process_working_directory())

        self.assertTrue(process, PROCESS_IS_VALID)

        # The stop reason of the thread should be breakpoint.
        thread_list = lldbutil.get_threads_stopped_at_breakpoint(process, bpt1)

        # Make sure we stopped at the first breakpoint.
        self.assertTrue(
            len(thread_list) != 0, "No thread stopped at our breakpoint.")
        self.assertTrue(
            len(thread_list) == 1,
            "More than one thread stopped at our breakpoint.")

        frame = thread_list[0].GetFrameAtIndex(0)
        self.assertTrue(frame, "Got a valid frame 0 frame.")
예제 #21
0
    def objc_class_method(self):
        """Test calling class methods."""
        exe = os.path.join(os.getcwd(), "a.out")

        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        bpt = target.BreakpointCreateByLocation(self.main_source,
                                                self.break_line)
        self.assertTrue(bpt, VALID_BREAKPOINT)

        # Now launch the process, and do not stop at entry point.
        process = target.LaunchSimple(None, None,
                                      self.get_process_working_directory())

        self.assertTrue(process, PROCESS_IS_VALID)

        # The stop reason of the thread should be breakpoint.
        thread_list = lldbutil.get_threads_stopped_at_breakpoint(process, bpt)

        # Make sure we stopped at the first breakpoint.
        self.assertTrue(
            len(thread_list) != 0, "No thread stopped at our breakpoint.")
        self.assertTrue(
            len(thread_list) == 1,
            "More than one thread stopped at our breakpoint.")

        frame = thread_list[0].GetFrameAtIndex(0)
        self.assertTrue(frame, "Got a valid frame 0 frame.")

        # Now make sure we can call a method that returns a struct without crashing.
        cmd_value = frame.EvaluateExpression("[provider getRange]")
        self.assertTrue(cmd_value.IsValid())
예제 #22
0
    def child_by_name(self):
        exe = os.path.join (os.getcwd(), "a.out")
        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        break_in_main = target.BreakpointCreateBySourceRegex ('// Set breakpoint 2 here.', lldb.SBFileSpec("main.c"))
        self.assertTrue(break_in_main, VALID_BREAKPOINT)

        process = target.LaunchSimple (None, None, os.getcwd())
        self.assertTrue (process, PROCESS_IS_VALID)

        threads = lldbutil.get_threads_stopped_at_breakpoint (process, break_in_main)
        if len(threads) != 1:
            self.fail ("Failed to stop at breakpoint in main.")

        thread = threads[0]
        frame = thread.frames[0]

        if not frame.IsValid():
            self.fail ("Failed to get frame 0.")

        var_n = frame.FindVariable("n")
        if not var_n.IsValid():
            self.fail ("Failed to get the variable 'n'")

        elem_a = var_n.GetChildMemberWithName("a")
        if not elem_a.IsValid():
            self.fail ("Failed to get the element a in n")

        error = lldb.SBError()
        value = elem_a.GetValueAsSigned(error, 1000)
        if not error.Success() or value != 0:
            self.fail ("failed to get the correct value for element a in n")
    def objc_ivar_offsets(self):
        """Test that we can find stripped Objective-C ivars in the runtime"""
        exe = os.path.join(os.getcwd(), "a.out.stripped")

        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        self.dbg.HandleCommand("add-dsym a.out.dSYM")

        breakpoint = target.BreakpointCreateByLocation(self.main_source, self.stop_line)
        self.assertTrue(breakpoint.IsValid() and breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT)

        process = target.LaunchSimple (None, None, self.get_process_working_directory())
        self.assertTrue (process, "Created a process.")
        self.assertTrue (process.GetState() == lldb.eStateStopped, "Stopped it too.")

        thread_list = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint)
        self.assertTrue (len(thread_list) == 1)
        thread = thread_list[0]
        
        frame = thread.GetFrameAtIndex(0)
        self.assertTrue (frame, "frame 0 is valid")
        
        # Test the expression for mc->_foo

        error = lldb.SBError()

        ivar = frame.EvaluateExpression ("(mc->_foo)")
        self.assertTrue(ivar, "Got result for mc->_foo")
        ivar_value = ivar.GetValueAsSigned (error)
        self.assertTrue (error.Success())
        self.assertTrue (ivar_value == 3)
예제 #24
0
    def test_with_python_api(self):
        """Test expression parser respect for ObjC built-in types."""
        self.build()
        exe = os.path.join(os.getcwd(), "a.out")

        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        bpt = target.BreakpointCreateByLocation(self.main_source, self.break_line)
        self.assertTrue(bpt, VALID_BREAKPOINT)

        # Now launch the process, and do not stop at entry point.
        process = target.LaunchSimple (None, None, self.get_process_working_directory())

        self.assertTrue(process, PROCESS_IS_VALID)

        # The stop reason of the thread should be breakpoint.
        thread_list = lldbutil.get_threads_stopped_at_breakpoint (process, bpt)

        # Make sure we stopped at the first breakpoint.
        self.assertTrue (len(thread_list) != 0, "No thread stopped at our breakpoint.")
        self.assertTrue (len(thread_list) == 1, "More than one thread stopped at our breakpoint.")
            
        # Now make sure we can call a function in the class method we've stopped in.
        frame = thread_list[0].GetFrameAtIndex(0)
        self.assertTrue (frame, "Got a valid frame 0 frame.")

        self.expect("expr (foo)", patterns = ["\(ns::id\) \$.* = 0"])

        self.expect("expr id my_id = 0; my_id", patterns = ["\(id\) \$.* = nil"])
예제 #25
0
    def inline_stepping_step_over(self):
        """Use Python APIs to test stepping over and hitting breakpoints."""
        exe = os.path.join(os.getcwd(), "a.out")

        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        break_1_in_main = target.BreakpointCreateBySourceRegex ('// At second call of caller_ref_1 in main.', self.main_source_spec)
        self.assertTrue(break_1_in_main, VALID_BREAKPOINT)

        # Now launch the process, and do not stop at entry point.
        self.process = target.LaunchSimple (None, None, os.getcwd())

        self.assertTrue(self.process, PROCESS_IS_VALID)

        # The stop reason of the thread should be breakpoint.
        threads = lldbutil.get_threads_stopped_at_breakpoint (self.process, break_1_in_main)

        if len(threads) != 1:
            self.fail ("Failed to stop at first breakpoint in main.")

        self.thread = threads[0]

        step_sequence = [["// In caller_ref_1.", "into"],
                         ["// In caller_ref_2.", "into"],
                         ["// At increment in caller_ref_2.", "over"]]
        self.run_step_sequence (step_sequence)
    def objc_static_method_stripped(self):
        """Test calling functions in static methods with a stripped binary."""
        exe = os.path.join(os.getcwd(), "a.out.stripped")

        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        bpt = target.BreakpointCreateByLocation(self.main_source, self.break_line)
        self.assertTrue(bpt, VALID_BREAKPOINT)

        # Now launch the process, and do not stop at entry point.
        process = target.LaunchSimple (None, None, os.getcwd())

        self.assertTrue(process, PROCESS_IS_VALID)

        # The stop reason of the thread should be breakpoint.
        thread_list = lldbutil.get_threads_stopped_at_breakpoint (process, bpt)

        # Make sure we stopped at the first breakpoint.
        self.assertTrue (len(thread_list) != 0, "No thread stopped at our breakpoint.")
        self.assertTrue (len(thread_list) == 1, "More than one thread stopped at our breakpoint.")
            
        # Now make sure we can call a function in the static method we've stopped in.
        frame = thread_list[0].GetFrameAtIndex(0)
        self.assertTrue (frame, "Got a valid frame 0 frame.")

        cmd_value = frame.EvaluateExpression ("(char *) sel_getName (_cmd)")
        self.assertTrue (cmd_value.IsValid())
        sel_name = cmd_value.GetSummary()
        self.assertTrue (sel_name == "\"doSomethingWithString:\"", "Got the right value for the selector as string.")

        cmd_value = frame.EvaluateExpression ("[Foo doSomethingElseWithString:string]")
        self.assertTrue (cmd_value.IsValid())
        string_length = cmd_value.GetValueAsUnsigned()
        self.assertTrue (string_length == 27, "Got the right value from another class method on the same class.")
예제 #27
0
    def test_with_python_api(self):
        """Test passing structs to Objective-C methods."""
        self.build()
        exe = os.path.join(os.getcwd(), "a.out")

        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        bpt = target.BreakpointCreateByLocation(self.main_source, self.break_line)
        self.assertTrue(bpt, VALID_BREAKPOINT)

        # Now launch the process, and do not stop at entry point.
        process = target.LaunchSimple(None, None, self.get_process_working_directory())

        self.assertTrue(process, PROCESS_IS_VALID)

        # The stop reason of the thread should be breakpoint.
        thread_list = lldbutil.get_threads_stopped_at_breakpoint(process, bpt)

        # Make sure we stopped at the first breakpoint.
        self.assertTrue(len(thread_list) != 0, "No thread stopped at our breakpoint.")
        self.assertTrue(len(thread_list) == 1, "More than one thread stopped at our breakpoint.")

        frame = thread_list[0].GetFrameAtIndex(0)
        self.assertTrue(frame, "Got a valid frame 0 frame.")

        self.expect("p [summer sumThings:tts]", substrs=["9"])

        self.expect("po [NSValue valueWithRect:rect]", substrs=["NSRect: {{0, 0}, {10, 20}}"])

        # Now make sure we can call a method that returns a struct without crashing.
        cmd_value = frame.EvaluateExpression("[provider getRange]")
        self.assertTrue(cmd_value.IsValid())
예제 #28
0
    def objc_class_method(self):
        """Test calling class methods."""
        exe = os.path.join(os.getcwd(), "a.out")

        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        bpt = target.BreakpointCreateByLocation(self.main_source, self.break_line)
        self.assertTrue(bpt, VALID_BREAKPOINT)

        # Now launch the process, and do not stop at entry point.
        process = target.LaunchSimple (None, None, self.get_process_working_directory())

        self.assertTrue(process, PROCESS_IS_VALID)

        # The stop reason of the thread should be breakpoint.
        thread_list = lldbutil.get_threads_stopped_at_breakpoint (process, bpt)

        # Make sure we stopped at the first breakpoint.
        self.assertTrue (len(thread_list) != 0, "No thread stopped at our breakpoint.")
        self.assertTrue (len(thread_list) == 1, "More than one thread stopped at our breakpoint.")
            
        frame = thread_list[0].GetFrameAtIndex(0)
        self.assertTrue (frame, "Got a valid frame 0 frame.")

        # Now make sure we can call a method that returns a struct without crashing.
        cmd_value = frame.EvaluateExpression ("[provider getRange]")
        self.assertTrue (cmd_value.IsValid())
예제 #29
0
    def call_function(self):
        """Test calling function with timeout."""
        exe_name = "a.out"
        exe = os.path.join(os.getcwd(), exe_name)

        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        breakpoint = target.BreakpointCreateBySourceRegex(
            'stop here in main.', self.main_source_spec)
        self.assertTrue(breakpoint, VALID_BREAKPOINT)
        self.runCmd("breakpoint list")

        # Launch the process, and do not stop at the entry point.
        process = target.LaunchSimple(None, None,
                                      self.get_process_working_directory())

        self.assertTrue(process, PROCESS_IS_VALID)

        # Frame #0 should be on self.step_out_of_malloc.
        threads = lldbutil.get_threads_stopped_at_breakpoint(
            process, breakpoint)

        self.assertTrue(len(threads) == 1)
        thread = threads[0]

        # First set the timeout too short, and make sure we fail.
        options = lldb.SBExpressionOptions()
        options.SetTimeoutInMicroSeconds(100)
        options.SetUnwindOnError(True)

        frame = thread.GetFrameAtIndex(0)

        value = frame.EvaluateExpression("wait_a_while (10000)", options)
        self.assertTrue(value.IsValid())
        self.assertTrue(value.GetError().Success() == False)

        # Now do the same thing with the command line command, and make sure it works too.
        interp = self.dbg.GetCommandInterpreter()

        result = lldb.SBCommandReturnObject()
        return_value = interp.HandleCommand(
            "expr -t 100 -u true -- wait_a_while(10000)", result)
        self.assertTrue(return_value == lldb.eReturnStatusFailed)

        # Okay, now do it again with long enough time outs:

        options.SetTimeoutInMicroSeconds(1000000)
        value = frame.EvaluateExpression("wait_a_while (1000)", options)
        self.assertTrue(value.IsValid())
        self.assertTrue(value.GetError().Success() == True)

        # Now do the same thingwith the command line command, and make sure it works too.
        interp = self.dbg.GetCommandInterpreter()

        result = lldb.SBCommandReturnObject()
        return_value = interp.HandleCommand(
            "expr -t 1000000 -u true -- wait_a_while(1000)", result)
        self.assertTrue(return_value == lldb.eReturnStatusSuccessFinishResult)
예제 #30
0
    def objc_ivar_offsets(self):
        """Use Python APIs to test stepping into ObjC methods."""
        exe = os.path.join(os.getcwd(), "a.out")

        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        breakpoint = target.BreakpointCreateByLocation(self.main_source,
                                                       self.stop_line)
        self.assertTrue(breakpoint, VALID_BREAKPOINT)

        process = target.LaunchSimple(None, None, os.getcwd())
        self.assertTrue(process, "Created a process.")
        self.assertTrue(process.GetState() == lldb.eStateStopped,
                        "Stopped it too.")

        thread_list = lldbutil.get_threads_stopped_at_breakpoint(
            process, breakpoint)
        self.assertTrue(len(thread_list) == 1)
        thread = thread_list[0]

        frame = thread.GetFrameAtIndex(0)
        self.assertTrue(frame, "frame 0 is valid")

        mine = thread.GetFrameAtIndex(0).FindVariable("mine")
        self.assertTrue(mine, "Found local variable mine.")

        # Test the value object value for BaseClass->_backed_int

        error = lldb.SBError()

        mine_backed_int = mine.GetChildMemberWithName("_backed_int")
        self.assertTrue(mine_backed_int,
                        "Found mine->backed_int local variable.")
        backed_value = mine_backed_int.GetValueAsSigned(error)
        self.assertTrue(error.Success())
        self.assertTrue(backed_value == 1111)

        # Test the value object value for DerivedClass->_derived_backed_int

        mine_derived_backed_int = mine.GetChildMemberWithName(
            "_derived_backed_int")
        self.assertTrue(mine_derived_backed_int,
                        "Found mine->derived_backed_int local variable.")
        derived_backed_value = mine_derived_backed_int.GetValueAsSigned(error)
        self.assertTrue(error.Success())
        self.assertTrue(derived_backed_value == 3333)

        # Make sure we also get bit-field offsets correct:

        mine_flag2 = mine.GetChildMemberWithName("flag2")
        self.assertTrue(mine_flag2, "Found mine->flag2 local variable.")
        flag2_value = int(mine_flag2.GetValue(), 0)
        self.assertTrue(flag2_value == 7)

        # GetValueAsUnsigned fails for bit-fields:
        flag2_value = mine_flag2.GetValueAsUnsigned(error)
        self.assertTrue(error.Success())
        self.assertTrue(flag2_value == 7)
예제 #31
0
    def test_11581_commands(self):
        # This is the function to remove the custom commands in order to have a
        # clean slate for the next test case.
        def cleanup():
            self.runCmd('type synthetic clear', check=False)


        # Execute the cleanup function during test case tear down.
        self.addTearDownHook(cleanup)

        """valobj.AddressOf() should return correct values."""
        self.buildDefault()
        
        exe = os.path.join(os.getcwd(), "a.out")
        
        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        breakpoint = target.BreakpointCreateBySourceRegex('Set breakpoint here.',lldb.SBFileSpec ("main.cpp", False))
        
        process = target.LaunchSimple (None, None, os.getcwd())
        self.assertTrue (process, "Created a process.")
        self.assertTrue (process.GetState() == lldb.eStateStopped, "Stopped it too.")

        thread_list = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint)
        self.assertTrue (len(thread_list) == 1)
        thread = thread_list[0]

        self.runCmd("command script import --allow-reload s11588.py")
        self.runCmd("type synthetic add --python-class s11588.Issue11581SyntheticProvider StgClosure")

        self.expect("expr --show-types -- *((StgClosure*)(r14-1))",
            substrs = ["(StgClosure) $",
            "(StgClosure *) &$","0x",
            "addr = ",
            "load_address = "])


        target = lldb.debugger.GetSelectedTarget()
        process = target.GetProcess()
# register r14 does not exist on 32-bit architectures, it is an x86_64 extension
# let's skip this part of the test if we are in 32-bit mode
        if process.GetAddressByteSize() == 8:
                frame = process.GetSelectedThread().GetSelectedFrame()
                pointer = frame.FindVariable("r14")
                addr = pointer.GetValueAsUnsigned(0)
                self.assertTrue(addr != 0, "could not read pointer to StgClosure")
                addr = addr - 1
                self.runCmd("register write r14 %d" % addr)
                self.expect("register read r14",
                    substrs = ["0x",hex(addr)[2:].rstrip("L")])  # Remove trailing 'L' if it exists
                self.expect("expr --show-types -- *(StgClosure*)$r14",
                    substrs = ["(StgClosure) $",
                    "(StgClosure *) &$","0x",
                    "addr = ",
                    "load_address = ",
                    hex(addr)[2:].rstrip("L"),
                    str(addr)])
    def queues(self):
        """Test queues inspection SB APIs without libBacktraceRecording."""
        exe = os.path.join(os.getcwd(), "a.out")

        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)
        self.main_source_spec = lldb.SBFileSpec(self.main_source)
        break1 = target.BreakpointCreateByName("stopper", 'a.out')
        self.assertTrue(break1, VALID_BREAKPOINT)
        process = target.LaunchSimple(None, None,
                                      self.get_process_working_directory())
        self.assertTrue(process, PROCESS_IS_VALID)
        threads = lldbutil.get_threads_stopped_at_breakpoint(process, break1)
        if len(threads) != 1:
            self.fail("Failed to stop at breakpoint 1.")

        queue_submittor_1 = lldb.SBQueue()
        queue_performer_1 = lldb.SBQueue()
        queue_performer_2 = lldb.SBQueue()
        queue_performer_3 = lldb.SBQueue()
        for idx in range(0, process.GetNumQueues()):
            q = process.GetQueueAtIndex(idx)
            if q.GetName() == "com.apple.work_submittor_1":
                queue_submittor_1 = q
            if q.GetName() == "com.apple.work_performer_1":
                queue_performer_1 = q
            if q.GetName() == "com.apple.work_performer_2":
                queue_performer_2 = q
            if q.GetName() == "com.apple.work_performer_3":
                queue_performer_3 = q

        self.assertTrue(
            queue_submittor_1.IsValid() and queue_performer_1.IsValid()
            and queue_performer_2.IsValid() and queue_performer_3.IsValid(),
            "Got all four expected queues: %s %s %s %s" %
            (queue_submittor_1.IsValid(), queue_performer_1.IsValid(),
             queue_performer_2.IsValid(), queue_performer_3.IsValid()))

        self.check_queue_for_valid_queue_id(queue_submittor_1)
        self.check_queue_for_valid_queue_id(queue_performer_1)
        self.check_queue_for_valid_queue_id(queue_performer_2)
        self.check_queue_for_valid_queue_id(queue_performer_3)

        self.check_number_of_threads_owned_by_queue(queue_submittor_1, 1)
        self.check_number_of_threads_owned_by_queue(queue_performer_1, 1)
        self.check_number_of_threads_owned_by_queue(queue_performer_2, 1)
        self.check_number_of_threads_owned_by_queue(queue_performer_3, 4)

        self.check_queue_kind(queue_submittor_1, lldb.eQueueKindSerial)
        self.check_queue_kind(queue_performer_1, lldb.eQueueKindSerial)
        self.check_queue_kind(queue_performer_2, lldb.eQueueKindSerial)
        self.check_queue_kind(queue_performer_3, lldb.eQueueKindConcurrent)

        self.check_queues_threads_match_queue(queue_submittor_1)
        self.check_queues_threads_match_queue(queue_performer_1)
        self.check_queues_threads_match_queue(queue_performer_2)
        self.check_queues_threads_match_queue(queue_performer_3)
예제 #33
0
    def ivars_in_blocks (self):
        """Test printing the ivars of the self when captured in blocks"""
        exe = os.path.join(os.getcwd(), "a.out")

        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        breakpoint = target.BreakpointCreateBySourceRegex ('// Break here inside the block.', self.class_source_file_spec)
        self.assertTrue(breakpoint, VALID_BREAKPOINT)

        process = target.LaunchSimple (None, None, os.getcwd())
        self.assertTrue (process, "Created a process.")
        self.assertTrue (process.GetState() == lldb.eStateStopped, "Stopped it too.")

        thread_list = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint)
        self.assertTrue (len(thread_list) == 1)
        thread = thread_list[0]
        
        frame = thread.GetFrameAtIndex(0)
        self.assertTrue (frame, "frame 0 is valid")
        
        # First use the FindVariable API to see if we can find the ivar by undecorated name:
        direct_blocky = frame.GetValueForVariablePath ("blocky_ivar")
        self.assertTrue(direct_blocky, "Found direct access to blocky_ivar.")
        
        # Now get it as a member of "self" and make sure the two values are equal:
        self_var = frame.GetValueForVariablePath ("self")
        self.assertTrue (self_var, "Found self in block.")
        indirect_blocky = self_var.GetChildMemberWithName ("blocky_ivar")
        self.assertTrue (indirect_blocky, "Found blocky_ivar through self")
        
        error = lldb.SBError()
        direct_value = direct_blocky.GetValueAsSigned(error)
        self.assertTrue (error.Success(), "Got direct value for blocky_ivar")

        indirect_value = indirect_blocky.GetValueAsSigned (error)
        self.assertTrue (error.Success(), "Got indirect value for blocky_ivar")
        
        self.assertTrue (direct_value == indirect_value, "Direct and indirect values are equal.")

        # Now make sure that we can get at the captured ivar through the expression parser.
        # Doing a little trivial math will force this into the real expression parser:
        direct_expr = frame.EvaluateExpression ("blocky_ivar + 10")
        self.assertTrue (direct_expr, "Got blocky_ivar through the expression parser")
        
        # Again, get the value through self directly and make sure they are the same:
        indirect_expr = frame.EvaluateExpression ("self->blocky_ivar + 10")
        self.assertTrue (indirect_expr, "Got blocky ivar through expression parser using self.")
        
        direct_value = direct_expr.GetValueAsSigned (error)
        self.assertTrue (error.Success(), "Got value from direct use of expression parser")

        indirect_value = indirect_expr.GetValueAsSigned (error)
        self.assertTrue (error.Success(), "Got value from indirect access using the expression parser")

        self.assertTrue (direct_value == indirect_value, "Direct ivar access and indirect through expression parser produce same value.")
예제 #34
0
    def test_with_python_api(self):
        """Test that adding, deleting and modifying watchpoints sends the appropriate events."""
        self.build()

        exe = os.path.join(os.getcwd(), "a.out")

        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        self.main_source_spec = lldb.SBFileSpec(self.main_source)

        break_in_main = target.BreakpointCreateBySourceRegex(
            '// Put a breakpoint here.', self.main_source_spec)
        self.assertTrue(break_in_main, VALID_BREAKPOINT)

        # Now launch the process, and do not stop at entry point.
        process = target.LaunchSimple(None, None,
                                      self.get_process_working_directory())

        self.assertTrue(process, PROCESS_IS_VALID)

        # The stop reason of the thread should be breakpoint.
        threads = lldbutil.get_threads_stopped_at_breakpoint(
            process, break_in_main)

        if len(threads) != 1:
            self.fail("Failed to stop at first breakpoint in main.")

        thread = threads[0]
        frame = thread.GetFrameAtIndex(0)
        local_var = frame.FindVariable("local_var")
        self.assertTrue(local_var.IsValid())

        self.listener = lldb.SBListener("com.lldb.testsuite_listener")
        self.target_bcast = target.GetBroadcaster()
        self.target_bcast.AddListener(
            self.listener, lldb.SBTarget.eBroadcastBitWatchpointChanged)
        self.listener.StartListeningForEvents(
            self.target_bcast, lldb.SBTarget.eBroadcastBitWatchpointChanged)

        error = lldb.SBError()
        local_watch = local_var.Watch(True, True, True, error)
        if not error.Success():
            self.fail("Failed to make watchpoint for local_var: %s" %
                      (error.GetCString()))

        self.GetWatchpointEvent(lldb.eWatchpointEventTypeAdded)
        # Now change some of the features of this watchpoint and make sure we get events:
        local_watch.SetEnabled(False)
        self.GetWatchpointEvent(lldb.eWatchpointEventTypeDisabled)

        local_watch.SetIgnoreCount(10)
        self.GetWatchpointEvent(lldb.eWatchpointEventTypeIgnoreChanged)

        local_watch.SetCondition("1 == 2")
        self.GetWatchpointEvent(lldb.eWatchpointEventTypeConditionChanged)
예제 #35
0
    def call_function(self):
        """Test calling function with timeout."""
        exe_name = "a.out"
        exe = os.path.join(os.getcwd(), exe_name)

        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        breakpoint = target.BreakpointCreateBySourceRegex('stop here in main.',self.main_source_spec)
        self.assertTrue(breakpoint, VALID_BREAKPOINT)
        self.runCmd("breakpoint list")

        # Launch the process, and do not stop at the entry point.
        process = target.LaunchSimple (None, None, self.get_process_working_directory())

        self.assertTrue(process, PROCESS_IS_VALID)

        # Frame #0 should be on self.step_out_of_malloc.
        threads = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint)
        
        self.assertTrue(len(threads) == 1)
        thread = threads[0]
        
        # First set the timeout too short, and make sure we fail.
        options = lldb.SBExpressionOptions()
        options.SetTimeoutInMicroSeconds(100)
        options.SetUnwindOnError(True)

        frame = thread.GetFrameAtIndex(0)
        
        value = frame.EvaluateExpression ("wait_a_while (10000)", options)
        self.assertTrue (value.IsValid())
        self.assertTrue (value.GetError().Success() == False)

        # Now do the same thing with the command line command, and make sure it works too.
        interp = self.dbg.GetCommandInterpreter()

        result = lldb.SBCommandReturnObject()
        return_value = interp.HandleCommand ("expr -t 100 -u true -- wait_a_while(10000)", result)
        self.assertTrue (return_value == lldb.eReturnStatusFailed)

        # Okay, now do it again with long enough time outs:

        options.SetTimeoutInMicroSeconds(1000000)
        value = frame.EvaluateExpression ("wait_a_while (1000)", options)
        self.assertTrue(value.IsValid())
        self.assertTrue (value.GetError().Success() == True)
        
        # Now do the same thingwith the command line command, and make sure it works too.
        interp = self.dbg.GetCommandInterpreter()

        result = lldb.SBCommandReturnObject()
        return_value = interp.HandleCommand ("expr -t 1000000 -u true -- wait_a_while(1000)", result)
        self.assertTrue(return_value == lldb.eReturnStatusSuccessFinishResult)
예제 #36
0
    def return_and_test_struct_value(self, func_name):
        """Pass in the name of the function to return from - takes in value, returns value."""

        # Set the breakpoint, run to it, finish out.
        bkpt = self.target.BreakpointCreateByName(func_name)
        self.assertTrue(bkpt.GetNumResolvedLocations() > 0)

        self.process.Continue()

        thread_list = lldbutil.get_threads_stopped_at_breakpoint(
            self.process, bkpt)

        self.assertTrue(len(thread_list) == 1)
        thread = thread_list[0]

        self.target.BreakpointDelete(bkpt.GetID())

        in_value = thread.GetFrameAtIndex(0).FindVariable("value")

        self.assertTrue(in_value.IsValid())
        num_in_children = in_value.GetNumChildren()

        # This is a little hokey, but if we don't get all the children now, then
        # once we've stepped we won't be able to get them?

        for idx in range(0, num_in_children):
            in_child = in_value.GetChildAtIndex(idx)
            in_child_str = in_child.GetValue()

        thread.StepOut()

        self.assertTrue(self.process.GetState() == lldb.eStateStopped)
        self.assertTrue(thread.GetStopReason() == lldb.eStopReasonPlanComplete)

        # Assuming all these functions step out to main.  Could figure out the caller dynamically
        # if that would add something to the test.
        frame = thread.GetFrameAtIndex(0)
        fun_name = frame.GetFunctionName()
        self.assertTrue(fun_name == "main")

        frame = thread.GetFrameAtIndex(0)
        ret_value = thread.GetStopReturnValue()

        self.assertTrue(ret_value.IsValid())

        num_ret_children = ret_value.GetNumChildren()
        self.assertTrue(num_in_children == num_ret_children)
        for idx in range(0, num_ret_children):
            in_child = in_value.GetChildAtIndex(idx)
            ret_child = ret_value.GetChildAtIndex(idx)
            in_child_str = in_child.GetValue()
            ret_child_str = ret_child.GetValue()

            self.assertTrue(in_child_str == ret_child_str)
예제 #37
0
    def objc_ivar_offsets(self):
        """Use Python APIs to test stepping into ObjC methods."""
        exe = os.path.join(os.getcwd(), "a.out")

        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        breakpoint = target.BreakpointCreateByLocation(self.main_source, self.stop_line)
        self.assertTrue(breakpoint, VALID_BREAKPOINT)

        process = target.LaunchSimple (None, None, os.getcwd())
        self.assertTrue (process, "Created a process.")
        self.assertTrue (process.GetState() == lldb.eStateStopped, "Stopped it too.")

        thread_list = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint)
        self.assertTrue (len(thread_list) == 1)
        thread = thread_list[0]
        
        frame = thread.GetFrameAtIndex(0)
        self.assertTrue (frame, "frame 0 is valid")
        
        mine = thread.GetFrameAtIndex(0).FindVariable("mine")
        self.assertTrue(mine, "Found local variable mine.")
        
        # Test the value object value for BaseClass->_backed_int

        error = lldb.SBError()

        mine_backed_int = mine.GetChildMemberWithName ("_backed_int")
        self.assertTrue(mine_backed_int, "Found mine->backed_int local variable.")
        backed_value = mine_backed_int.GetValueAsSigned (error)
        self.assertTrue (error.Success())
        self.assertTrue (backed_value == 1111)
        
        # Test the value object value for DerivedClass->_derived_backed_int

        mine_derived_backed_int = mine.GetChildMemberWithName ("_derived_backed_int")
        self.assertTrue(mine_derived_backed_int, "Found mine->derived_backed_int local variable.")
        derived_backed_value = mine_derived_backed_int.GetValueAsSigned (error)
        self.assertTrue (error.Success())
        self.assertTrue (derived_backed_value == 3333)

        # Make sure we also get bit-field offsets correct:

        mine_flag2 = mine.GetChildMemberWithName ("flag2")
        self.assertTrue(mine_flag2, "Found mine->flag2 local variable.")
        flag2_value = int (mine_flag2.GetValue (), 0)
        self.assertTrue (flag2_value == 7)

        # GetValueAsUnsigned fails for bit-fields:
        flag2_value = mine_flag2.GetValueAsUnsigned (error)
        self.assertTrue (error.Success())
        self.assertTrue (flag2_value == 7)
예제 #38
0
    def cpp_exceptions(self):
        """Test lldb exception breakpoint command for CPP."""
        exe = os.path.join(os.getcwd(), "a.out")

        # Create a target from the debugger.

        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        exception_bkpt = target.BreakpointCreateForException(
            lldb.eLanguageTypeC_plus_plus, True, True)
        self.assertTrue(exception_bkpt, "Made an exception breakpoint")

        # Now run, and make sure we hit our breakpoint:
        process = target.LaunchSimple(None, None,
                                      self.get_process_working_directory())
        self.assertTrue(process, "Got a valid process")

        stopped_threads = []
        stopped_threads = lldbutil.get_threads_stopped_at_breakpoint(
            process, exception_bkpt)
        self.assertTrue(
            len(stopped_threads) == 1, "Stopped at our exception breakpoint.")
        thread = stopped_threads[0]
        # Make sure our throw function is still above us on the stack:

        frame_functions = lldbutil.get_function_names(thread)
        self.assertTrue(
            frame_functions.count("throws_exception_on_even(int)") == 1,
            "Our throw function is still on the stack.")

        # Okay we hit our exception throw breakpoint, now make sure we get our catch breakpoint.
        # One potential complication is that we might hit a couple of the exception breakpoints in getting out of the throw.
        # so loop till we don't see the throws function on the stack.  We should stop one more time for our exception breakpoint
        # and that should be the catch...

        while frame_functions.count("throws_exception_on_even(int)") == 1:
            stopped_threads = lldbutil.continue_to_breakpoint(
                process, exception_bkpt)
            self.assertTrue(len(stopped_threads) == 1)

            thread = stopped_threads[0]
            frame_functions = lldbutil.get_function_names(thread)

        self.assertTrue(
            frame_functions.count("throws_exception_on_even(int)") == 0,
            "At catch our throw function is off the stack")
        self.assertTrue(
            frame_functions.count("intervening_function(int)") == 0,
            "At catch our intervening function is off the stack")
        self.assertTrue(
            frame_functions.count("catches_exception(int)") == 1,
            "At catch our catch function is on the stack")
예제 #39
0
    def return_and_test_struct_value (self, func_name):
        """Pass in the name of the function to return from - takes in value, returns value."""
        
        # Set the breakpoint, run to it, finish out.
        bkpt = self.target.BreakpointCreateByName (func_name)
        self.assertTrue (bkpt.GetNumResolvedLocations() > 0)

        self.process.Continue ()

        thread_list = lldbutil.get_threads_stopped_at_breakpoint (self.process, bkpt)

        self.assertTrue (len(thread_list) == 1)
        thread = thread_list[0]

        self.target.BreakpointDelete (bkpt.GetID())

        in_value = thread.GetFrameAtIndex(0).FindVariable ("value")
        
        self.assertTrue (in_value.IsValid())
        num_in_children = in_value.GetNumChildren()

        # This is a little hokey, but if we don't get all the children now, then
        # once we've stepped we won't be able to get them?
        
        for idx in range(0, num_in_children):
            in_child = in_value.GetChildAtIndex (idx)
            in_child_str = in_child.GetValue()

        thread.StepOut()
        
        self.assertTrue (self.process.GetState() == lldb.eStateStopped)
        self.assertTrue (thread.GetStopReason() == lldb.eStopReasonPlanComplete)

        # Assuming all these functions step out to main.  Could figure out the caller dynamically
        # if that would add something to the test.
        frame = thread.GetFrameAtIndex(0)
        fun_name = frame.GetFunctionName()
        self.assertTrue (fun_name == "main")

        frame = thread.GetFrameAtIndex(0)
        ret_value = thread.GetStopReturnValue()

        self.assertTrue (ret_value.IsValid())

        num_ret_children = ret_value.GetNumChildren()
        self.assertTrue (num_in_children == num_ret_children)
        for idx in range(0, num_ret_children):
            in_child = in_value.GetChildAtIndex(idx)
            ret_child = ret_value.GetChildAtIndex(idx)
            in_child_str = in_child.GetValue()
            ret_child_str = ret_child.GetValue()

            self.assertEqual(in_child_str, ret_child_str)
예제 #40
0
    def test_python(self):
        """Test that we obey thread conditioned breakpoints."""
        self.build()
        exe = os.path.join(os.getcwd(), "a.out")

        self.dbg.HandleCommand(
            "log enable -f /tmp/lldb-testsuite-log.txt lldb step breakpoint process"
        )
        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        main_source_spec = lldb.SBFileSpec("main.cpp")

        # Set a breakpoint in the thread body, and make it active for only the first thread.
        break_thread_body = target.BreakpointCreateBySourceRegex(
            "Break here in thread body.", main_source_spec)
        self.assertTrue(
            break_thread_body.IsValid()
            and break_thread_body.GetNumLocations() > 0,
            "Failed to set thread body breakpoint.")

        process = target.LaunchSimple(None, None,
                                      self.get_process_working_directory())

        self.assertTrue(process, PROCESS_IS_VALID)

        threads = lldbutil.get_threads_stopped_at_breakpoint(
            process, break_thread_body)

        victim_thread = threads[0]

        # Pick one of the threads, and change the breakpoint so it ONLY stops for this thread,
        # but add a condition that it won't stop for this thread's my_value.  The other threads
        # pass the condition, so they should stop, but if the thread-specification is working
        # they should not stop.  So nobody should hit the breakpoint anymore, and we should
        # just exit cleanly.

        frame = victim_thread.GetFrameAtIndex(0)
        value = frame.FindVariable("my_value").GetValueAsSigned(0)
        self.assertTrue(value > 0 and value < 11,
                        "Got a reasonable value for my_value.")

        cond_string = "my_value != %d" % (value)

        break_thread_body.SetThreadID(victim_thread.GetThreadID())
        break_thread_body.SetCondition(cond_string)

        process.Continue()

        next_stop_state = process.GetState()
        self.assertTrue(next_stop_state == lldb.eStateExited,
                        "We should have not hit the breakpoint again.")
    def test_step_inst(self):
        self.build(dictionary=self.getBuildFlags())
        exe = os.path.join(os.getcwd(), "a.out")
        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target and target.IsValid(), "Target is valid")

        # This should create a breakpoint in the stepping thread.
        breakpoint = target.BreakpointCreateByName("main")
        self.assertTrue(breakpoint and breakpoint.IsValid(),
                        "Breakpoint is valid")

        # Run the program.
        process = target.LaunchSimple(None, None,
                                      self.get_process_working_directory())
        self.assertTrue(process and process.IsValid(), PROCESS_IS_VALID)

        # The stop reason of the thread should be breakpoint.
        self.assertEqual(process.GetState(), lldb.eStateStopped,
                         PROCESS_STOPPED)

        threads = lldbutil.get_threads_stopped_at_breakpoint(
            process, breakpoint)
        self.assertEquals(len(threads), 1, STOPPED_DUE_TO_BREAKPOINT)

        thread = threads[0]
        self.assertTrue(thread and thread.IsValid(), "Thread is valid")

        # Make sure we see only one threads
        self.assertEqual(
            process.GetNumThreads(), 1,
            'Number of expected threads and actual threads do not match.')

        # Keep stepping until we see the thread creation
        while process.GetNumThreads() < 2:
            thread.StepInstruction(False)
            self.assertEqual(process.GetState(), lldb.eStateStopped,
                             PROCESS_STOPPED)
            self.assertEqual(thread.GetStopReason(),
                             lldb.eStopReasonPlanComplete,
                             "Step operation succeeded")
            if self.TraceOn():
                self.runCmd("disassemble --pc")

        if self.TraceOn():
            self.runCmd("thread list")

        # We have successfully caught thread creation. Now just run to completion
        process.Continue()

        # At this point, the inferior process should have exited.
        self.assertEqual(process.GetState(), lldb.eStateExited, PROCESS_EXITED)
예제 #42
0
    def queues(self):
        """Test queues inspection SB APIs without libBacktraceRecording."""
        exe = os.path.join(os.getcwd(), "a.out")

        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)
        self.main_source_spec = lldb.SBFileSpec (self.main_source)
        break1 = target.BreakpointCreateByName ("stopper", 'a.out')
        self.assertTrue(break1, VALID_BREAKPOINT)
        process = target.LaunchSimple (None, None, self.get_process_working_directory())
        self.assertTrue(process, PROCESS_IS_VALID)
        threads = lldbutil.get_threads_stopped_at_breakpoint (process, break1)
        if len(threads) != 1:
            self.fail ("Failed to stop at breakpoint 1.")

        queue_submittor_1 = lldb.SBQueue()
        queue_performer_1 = lldb.SBQueue()
        queue_performer_2 = lldb.SBQueue()
        queue_performer_3 = lldb.SBQueue()
        for idx in range (0, process.GetNumQueues()):
          q = process.GetQueueAtIndex(idx)
          if q.GetName() == "com.apple.work_submittor_1":
            queue_submittor_1 = q
          if q.GetName() == "com.apple.work_performer_1":
            queue_performer_1 = q
          if q.GetName() == "com.apple.work_performer_2":
            queue_performer_2 = q
          if q.GetName() == "com.apple.work_performer_3":
            queue_performer_3 = q

        self.assertTrue(queue_submittor_1.IsValid() and queue_performer_1.IsValid() and queue_performer_2.IsValid() and queue_performer_3.IsValid(), "Got all four expected queues: %s %s %s %s" % (queue_submittor_1.IsValid(), queue_performer_1.IsValid(), queue_performer_2.IsValid(), queue_performer_3.IsValid()))

        self.check_queue_for_valid_queue_id (queue_submittor_1)
        self.check_queue_for_valid_queue_id (queue_performer_1)
        self.check_queue_for_valid_queue_id (queue_performer_2)
        self.check_queue_for_valid_queue_id (queue_performer_3)

        self.check_number_of_threads_owned_by_queue (queue_submittor_1, 1)
        self.check_number_of_threads_owned_by_queue (queue_performer_1, 1)
        self.check_number_of_threads_owned_by_queue (queue_performer_2, 1)
        self.check_number_of_threads_owned_by_queue (queue_performer_3, 4)

        self.check_queue_kind (queue_submittor_1, lldb.eQueueKindSerial)
        self.check_queue_kind (queue_performer_1, lldb.eQueueKindSerial)
        self.check_queue_kind (queue_performer_2, lldb.eQueueKindSerial)
        self.check_queue_kind (queue_performer_3, lldb.eQueueKindConcurrent)
        
        self.check_queues_threads_match_queue (queue_submittor_1)
        self.check_queues_threads_match_queue (queue_performer_1)
        self.check_queues_threads_match_queue (queue_performer_2)
        self.check_queues_threads_match_queue (queue_performer_3)
예제 #43
0
    def test_with_python_api(self):
        """Test that adding, deleting and modifying watchpoints sends the appropriate events."""
        self.build()
        
        exe = os.path.join(os.getcwd(), "a.out")

        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        self.main_source_spec = lldb.SBFileSpec (self.main_source)

        break_in_main = target.BreakpointCreateBySourceRegex ('// Put a breakpoint here.', self.main_source_spec)
        self.assertTrue(break_in_main, VALID_BREAKPOINT)

        # Now launch the process, and do not stop at entry point.
        process = target.LaunchSimple (None, None, self.get_process_working_directory())

        self.assertTrue(process, PROCESS_IS_VALID)

        # The stop reason of the thread should be breakpoint.
        threads = lldbutil.get_threads_stopped_at_breakpoint (process, break_in_main)

        if len(threads) != 1:
            self.fail ("Failed to stop at first breakpoint in main.")

        thread = threads[0]
        frame = thread.GetFrameAtIndex(0)
        local_var = frame.FindVariable ("local_var")
        self.assertTrue (local_var.IsValid())

        self.listener = lldb.SBListener("com.lldb.testsuite_listener")
        self.target_bcast = target.GetBroadcaster()
        self.target_bcast.AddListener (self.listener, lldb.SBTarget.eBroadcastBitWatchpointChanged)
        self.listener.StartListeningForEvents (self.target_bcast, lldb.SBTarget.eBroadcastBitWatchpointChanged)

        error = lldb.SBError()
        local_watch = local_var.Watch(True, True, True, error)
        if not error.Success():
            self.fail ("Failed to make watchpoint for local_var: %s"%(error.GetCString()))

        self.GetWatchpointEvent (lldb.eWatchpointEventTypeAdded)
        # Now change some of the features of this watchpoint and make sure we get events:
        local_watch.SetEnabled(False)
        self.GetWatchpointEvent (lldb.eWatchpointEventTypeDisabled)

        local_watch.SetIgnoreCount(10)
        self.GetWatchpointEvent (lldb.eWatchpointEventTypeIgnoreChanged)

        local_watch.SetCondition ("1 == 2")
        self.GetWatchpointEvent (lldb.eWatchpointEventTypeConditionChanged)
예제 #44
0
    def test_objc_checker(self):
        """Test that checkers catch unrecognized selectors"""
        if self.getArchitecture() == 'i386':
            self.skipTest("requires Objective-C 2.0 runtime")

        self.build()
        exe = os.path.join(os.getcwd(), "a.out")

        # Create a target from the debugger.

        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        # Set up our breakpoints:

        main_bkpt = target.BreakpointCreateBySourceRegex(
            "Set a breakpoint here.", lldb.SBFileSpec(self.source_name))
        self.assertTrue(main_bkpt and main_bkpt.GetNumLocations() == 1,
                        VALID_BREAKPOINT)

        # Now launch the process, and do not stop at the entry point.
        process = target.LaunchSimple(None, None,
                                      self.get_process_working_directory())

        self.assertTrue(process.GetState() == lldb.eStateStopped,
                        PROCESS_STOPPED)

        threads = lldbutil.get_threads_stopped_at_breakpoint(
            process, main_bkpt)
        self.assertTrue(len(threads) == 1)
        thread = threads[0]

        #
        #  The class Simple doesn't have a count method.  Make sure that we don't
        #  actually try to send count but catch it as an unrecognized selector.

        frame = thread.GetFrameAtIndex(0)
        expr_value = frame.EvaluateExpression("(int) [my_simple count]", False)
        expr_error = expr_value.GetError()

        self.assertTrue(expr_error.Fail())

        # Make sure the call produced no NSLog stdout.
        stdout = process.GetSTDOUT(100)
        self.assertTrue(len(stdout) == 0)

        # Make sure the error is helpful:
        err_string = expr_error.GetCString()
        self.assertTrue("selector" in err_string)
예제 #45
0
    def find_global_variables(self, exe_name):
        """Exercise SBTaget.FindGlobalVariables() API."""
        exe = os.path.join(os.getcwd(), exe_name)

        # Create a target by the debugger.
        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        #rdar://problem/9700873
        # Find global variable value fails for dwarf if inferior not started
        # (Was CrashTracer: [USER] 1 crash in Python at _lldb.so: lldb_private::MemoryCache::Read + 94)
        #
        # Remove the lines to create a breakpoint and to start the inferior
        # which are workarounds for the dwarf case.

        breakpoint = target.BreakpointCreateByLocation('main.c', self.line1)
        self.assertTrue(breakpoint, VALID_BREAKPOINT)

        # Now launch the process, and do not stop at entry point.
        process = target.LaunchSimple(None, None,
                                      self.get_process_working_directory())
        self.assertTrue(process, PROCESS_IS_VALID)
        # Make sure we hit our breakpoint:
        thread_list = lldbutil.get_threads_stopped_at_breakpoint(
            process, breakpoint)
        self.assertTrue(len(thread_list) == 1)

        value_list = target.FindGlobalVariables('my_global_var_of_char_type',
                                                3)
        self.assertTrue(value_list.GetSize() == 1)
        my_global_var = value_list.GetValueAtIndex(0)
        self.DebugSBValue(my_global_var)
        self.assertTrue(my_global_var)
        self.expect(my_global_var.GetName(),
                    exe=False,
                    startstr="my_global_var_of_char_type")
        self.expect(my_global_var.GetTypeName(), exe=False, startstr="char")
        self.expect(my_global_var.GetValue(), exe=False, startstr="'X'")

        # While we are at it, let's also exercise the similar SBModule.FindGlobalVariables() API.
        for m in target.module_iter():
            if os.path.normpath(m.GetFileSpec().GetDirectory()) == os.getcwd(
            ) and m.GetFileSpec().GetFilename() == exe_name:
                value_list = m.FindGlobalVariables(
                    target, 'my_global_var_of_char_type', 3)
                self.assertTrue(value_list.GetSize() == 1)
                self.assertTrue(
                    value_list.GetValueAtIndex(0).GetValue() == "'X'")
                break
    def do_cpp_exception_bkpt(self):
        exe = os.path.join(os.getcwd(), "a.out")
        error = lldb.SBError()

        self.target = self.dbg.CreateTarget(exe)
        self.assertTrue(self.target, VALID_TARGET)

        exception_bkpt = self.target.BreakpointCreateForException(lldb.eLanguageTypeC_plus_plus, False, True)
        self.assertTrue(exception_bkpt.IsValid(), "Created exception breakpoint.")

        process = self.target.LaunchSimple(None, None, self.get_process_working_directory())
        self.assertTrue(process, PROCESS_IS_VALID)

        thread_list = lldbutil.get_threads_stopped_at_breakpoint(process, exception_bkpt)
        self.assertTrue(len(thread_list) == 1, "One thread stopped at the exception breakpoint.")
    def do_cpp_exception_bkpt (self):
        exe = os.path.join(os.getcwd(), "a.out")
        error = lldb.SBError()

        self.target = self.dbg.CreateTarget(exe)
        self.assertTrue(self.target, VALID_TARGET)

        exception_bkpt = self.target.BreakpointCreateForException(lldb.eLanguageTypeC_plus_plus, False, True)
        self.assertTrue (exception_bkpt.IsValid(), "Created exception breakpoint.")

        process = self.target.LaunchSimple (None, None, self.get_process_working_directory())
        self.assertTrue(process, PROCESS_IS_VALID)
        
        thread_list = lldbutil.get_threads_stopped_at_breakpoint (process, exception_bkpt)
        self.assertTrue (len(thread_list) == 1, "One thread stopped at the exception breakpoint.")
예제 #48
0
    def test_objc_checker(self):
        """Test that checkers catch unrecognized selectors"""
        if self.getArchitecture() == 'i386':
            self.skipTest("requires Objective-C 2.0 runtime")

        self.build()
        exe = os.path.join(os.getcwd(), "a.out")

        # Create a target from the debugger.

        target = self.dbg.CreateTarget (exe)
        self.assertTrue(target, VALID_TARGET)

        # Set up our breakpoints:

        
        main_bkpt = target.BreakpointCreateBySourceRegex ("Set a breakpoint here.", lldb.SBFileSpec (self.source_name))
        self.assertTrue(main_bkpt and
                        main_bkpt.GetNumLocations() == 1,
                        VALID_BREAKPOINT)

        # Now launch the process, and do not stop at the entry point.
        process = target.LaunchSimple (None, None, self.get_process_working_directory())

        self.assertTrue(process.GetState() == lldb.eStateStopped,
                        PROCESS_STOPPED)

        threads = lldbutil.get_threads_stopped_at_breakpoint (process, main_bkpt)
        self.assertTrue (len(threads) == 1)
        thread = threads[0]

        #
        #  The class Simple doesn't have a count method.  Make sure that we don't 
        #  actually try to send count but catch it as an unrecognized selector.

        frame = thread.GetFrameAtIndex(0)
        expr_value = frame.EvaluateExpression("(int) [my_simple count]", False)
        expr_error = expr_value.GetError()

        self.assertTrue (expr_error.Fail())
        
        # Make sure the call produced no NSLog stdout.
        stdout = process.GetSTDOUT(100)
        self.assertTrue (len(stdout) == 0)
        
        # Make sure the error is helpful:
        err_string = expr_error.GetCString()
        self.assertTrue ("selector" in err_string)
예제 #49
0
    def test_expr_options(self):
        """These expression command options should work as expected."""
        self.build()

        # Set debugger into synchronous mode
        self.dbg.SetAsync(False)

        # Create a target by the debugger.
        target = self.dbg.CreateTarget(self.exe)
        self.assertTrue(target, VALID_TARGET)

        # Set breakpoints inside main.
        breakpoint = target.BreakpointCreateBySourceRegex(
            '// breakpoint_in_main', self.main_source_spec)
        self.assertTrue(breakpoint)

        # Now launch the process, and do not stop at entry point.
        process = target.LaunchSimple(None, None,
                                      self.get_process_working_directory())
        self.assertTrue(process, PROCESS_IS_VALID)

        threads = lldbutil.get_threads_stopped_at_breakpoint(
            process, breakpoint)
        self.assertEqual(len(threads), 1)

        frame = threads[0].GetFrameAtIndex(0)
        options = lldb.SBExpressionOptions()

        # test --language on C++ expression using the SB API's

        # Make sure we can evaluate 'ns::func'.
        val = frame.EvaluateExpression('foo != nullptr')
        self.assertTrue(val.IsValid())
        self.assertTrue(val.GetError().Success())
        self.DebugSBValue(val)

        # Make sure it still works if language is set to C++11:
        options.SetLanguage(lldb.eLanguageTypeC_plus_plus_11)
        val = frame.EvaluateExpression('foo != nullptr', options)
        self.assertTrue(val.IsValid())
        self.assertTrue(val.GetError().Success())
        self.DebugSBValue(val)

        # Make sure it fails if language is set to C:
        options.SetLanguage(lldb.eLanguageTypeC)
        val = frame.EvaluateExpression('foo != nullptr', options)
        self.assertTrue(val.IsValid())
        self.assertFalse(val.GetError().Success())
예제 #50
0
    def test_find_global_variables_then_object_description(self):
        """Exercise SBTarget.FindGlobalVariables() API."""
        d = {'EXE': 'b.out'}
        self.build(dictionary=d)
        self.setTearDownCleanup(dictionary=d)
        exe = os.path.join(os.getcwd(), 'b.out')

        # Create a target by the debugger.
        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        breakpoint = target.BreakpointCreateByLocation(self.source, self.line)
        self.assertTrue(breakpoint, VALID_BREAKPOINT)

        # Now launch the process, and do not stop at entry point.
        process = target.LaunchSimple(None, None,
                                      self.get_process_working_directory())
        self.assertTrue(process, PROCESS_IS_VALID)
        # Make sure we hit our breakpoint:
        thread_list = lldbutil.get_threads_stopped_at_breakpoint(
            process, breakpoint)
        self.assertTrue(len(thread_list) == 1)

        thread = thread_list[0]
        frame0 = thread.GetFrameAtIndex(0)

        # Note my_global_str's object description prints fine here.
        value_list1 = frame0.GetVariables(True, True, True, True)
        for v in value_list1:
            self.DebugSBValue(v)
            if self.TraceOn():
                print "val:", v
                print "object description:", v.GetObjectDescription()
            if v.GetName() == 'my_global_str':
                self.assertTrue(
                    v.GetObjectDescription() == 'This is a global string')

        # But not here!
        value_list2 = target.FindGlobalVariables('my_global_str', 3)
        for v in value_list2:
            self.DebugSBValue(v)
            if self.TraceOn():
                print "val:", v
                print "object description:", v.GetObjectDescription()
            if v.GetName() == 'my_global_str':
                self.assertTrue(
                    v.GetObjectDescription() == 'This is a global string')
예제 #51
0
    def test_expr_options(self):
        """These expression command options should work as expected."""
        self.build()

        # Set debugger into synchronous mode
        self.dbg.SetAsync(False)

        # Create a target by the debugger.
        target = self.dbg.CreateTarget(self.exe)
        self.assertTrue(target, VALID_TARGET)

        # Set breakpoints inside main.
        breakpoint = target.BreakpointCreateBySourceRegex('// breakpoint_in_main', self.main_source_spec)
        self.assertTrue(breakpoint)

        # Now launch the process, and do not stop at entry point.
        process = target.LaunchSimple(None, None, self.get_process_working_directory())
        self.assertTrue(process, PROCESS_IS_VALID)

        threads = lldbutil.get_threads_stopped_at_breakpoint(process, breakpoint)
        self.assertEqual(len(threads), 1)

        frame = threads[0].GetFrameAtIndex(0)
        options = lldb.SBExpressionOptions()

        # test --language on C++ expression using the SB API's

        # Make sure we can evaluate 'ns::func'.
        val = frame.EvaluateExpression('foo != nullptr')
        self.assertTrue(val.IsValid())
        self.assertTrue(val.GetError().Success())
        self.DebugSBValue(val)

        # Make sure it still works if language is set to C++11:
        options.SetLanguage(lldb.eLanguageTypeC_plus_plus_11)
        val = frame.EvaluateExpression('foo != nullptr', options)
        self.assertTrue(val.IsValid())
        self.assertTrue(val.GetError().Success())
        self.DebugSBValue(val)

        # Make sure it fails if language is set to C:
        options.SetLanguage(lldb.eLanguageTypeC)
        val = frame.EvaluateExpression('foo != nullptr', options)
        self.assertTrue(val.IsValid())
        self.assertFalse(val.GetError().Success())
예제 #52
0
    def find_global_variables(self, exe_name):
        """Exercise SBTaget.FindGlobalVariables() API."""
        exe = os.path.join(os.getcwd(), exe_name)

        # Create a target by the debugger.
        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        #rdar://problem/9700873
        # Find global variable value fails for dwarf if inferior not started
        # (Was CrashTracer: [USER] 1 crash in Python at _lldb.so: lldb_private::MemoryCache::Read + 94)
        #
        # Remove the lines to create a breakpoint and to start the inferior
        # which are workarounds for the dwarf case.

        breakpoint = target.BreakpointCreateByLocation('main.c', self.line1)
        self.assertTrue(breakpoint, VALID_BREAKPOINT)

        # Now launch the process, and do not stop at entry point.
        process = target.LaunchSimple(None, None, os.getcwd())
        self.assertTrue(process, PROCESS_IS_VALID)
        # Make sure we hit our breakpoint:
        thread_list = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint)
        self.assertTrue (len(thread_list) == 1)

        value_list = target.FindGlobalVariables('my_global_var_of_char_type', 3)
        self.assertTrue(value_list.GetSize() == 1)
        my_global_var = value_list.GetValueAtIndex(0)
        self.DebugSBValue(my_global_var)
        self.assertTrue(my_global_var)
        self.expect(my_global_var.GetName(), exe=False,
            startstr = "my_global_var_of_char_type")
        self.expect(my_global_var.GetTypeName(), exe=False,
            startstr = "char")
        self.expect(my_global_var.GetValue(), exe=False,
            startstr = "'X'")

        # While we are at it, let's also exercise the similar SBModule.FindGlobalVariables() API.
        for m in target.module_iter():
            if m.GetFileSpec().GetDirectory() == os.getcwd() and m.GetFileSpec().GetFilename() == exe_name:
                value_list = m.FindGlobalVariables(target, 'my_global_var_of_char_type', 3)
                self.assertTrue(value_list.GetSize() == 1)
                self.assertTrue(value_list.GetValueAtIndex(0).GetValue() == "'X'")
                break
    def do_set_python_command_from_python (self):
        exe = os.path.join(os.getcwd(), "a.out")
        error = lldb.SBError()

        self.target = self.dbg.CreateTarget(exe)
        self.assertTrue(self.target, VALID_TARGET)

        body_bkpt = self.target.BreakpointCreateBySourceRegex("Set break point at this line.", self.main_source_spec)
        self.assertTrue(body_bkpt, VALID_BREAKPOINT)

        func_bkpt = self.target.BreakpointCreateBySourceRegex("Set break point at this line.", self.main_source_spec)
        self.assertTrue(func_bkpt, VALID_BREAKPOINT)

        PythonBreakpointCommandSettingTestCase.my_var = 10
        error = lldb.SBError()
        error = body_bkpt.SetScriptCallbackBody("\
import TestBreakpointCommandsFromPython\n\
TestBreakpointCommandsFromPython.PythonBreakpointCommandSettingTestCase.my_var = 20\n\
print 'Hit breakpoint'")
        self.assertTrue (error.Success(), "Failed to set the script callback body: %s."%(error.GetCString()))

        self.dbg.HandleCommand("command script import --allow-reload ./bktptcmd.py")
        func_bkpt.SetScriptCallbackFunction("bktptcmd.function")

        # We will use the function that touches a text file, so remove it first:
        self.RemoveTempFile("output2.txt")

        # Now launch the process, and do not stop at entry point.
        self.process = self.target.LaunchSimple (None, None, self.get_process_working_directory())

        self.assertTrue(self.process, PROCESS_IS_VALID)

        # Now finish, and make sure the return value is correct.
        threads = lldbutil.get_threads_stopped_at_breakpoint (self.process, body_bkpt)
        self.assertTrue(len(threads) == 1, "Stopped at inner breakpoint.")
        self.thread = threads[0]
    
        self.assertTrue(PythonBreakpointCommandSettingTestCase.my_var == 20)

        # Check for the function version as well, which produced this file:
        # Remember to clean up after ourselves...
        self.assertTrue(os.path.isfile("output2.txt"),
                        "'output2.txt' exists due to breakpoint command for breakpoint function.")
        self.RemoveTempFile("output2.txt")
    def do_thread_specific_break(self):
        """Test that we obey thread conditioned breakpoints."""
        exe = os.path.join(os.getcwd(), "a.out")

        self.dbg.HandleCommand("log enable -f /tmp/lldb-testsuite-log.txt lldb step breakpoint process")
        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        main_source_spec = lldb.SBFileSpec("main.c")

        # Set a breakpoint in the thread body, and make it active for only the first thread.
        break_thread_body = target.BreakpointCreateBySourceRegex("Break here in thread body.", main_source_spec)
        self.assertTrue(
            break_thread_body.IsValid() and break_thread_body.GetNumLocations() > 0,
            "Failed to set thread body breakpoint.",
        )

        process = target.LaunchSimple(None, None, self.get_process_working_directory())

        self.assertTrue(process, PROCESS_IS_VALID)

        threads = lldbutil.get_threads_stopped_at_breakpoint(process, break_thread_body)

        victim_thread = threads[0]

        # Pick one of the threads, and change the breakpoint so it ONLY stops for this thread,
        # but add a condition that it won't stop for this thread's my_value.  The other threads
        # pass the condition, so they should stop, but if the thread-specification is working
        # they should not stop.  So nobody should hit the breakpoint anymore, and we should
        # just exit cleanly.

        frame = victim_thread.GetFrameAtIndex(0)
        value = frame.FindVariable("my_value").GetValueAsSigned(0)
        self.assertTrue(value > 0 and value < 11, "Got a reasonable value for my_value.")

        cond_string = "my_value != %d" % (value)

        break_thread_body.SetThreadID(victim_thread.GetThreadID())
        break_thread_body.SetCondition(cond_string)

        process.Continue()

        next_stop_state = process.GetState()
        self.assertTrue(next_stop_state == lldb.eStateExited, "We should have not hit the breakpoint again.")
예제 #55
0
    def get_to_starting_point (self):
        exe = os.path.join(os.getcwd(), "a.out")
        error = lldb.SBError()

        self.target = self.dbg.CreateTarget(exe)
        self.assertTrue(self.target, VALID_TARGET)

        inner_bkpt = self.target.BreakpointCreateBySourceRegex("Stop here and step out of me", self.main_source_spec)
        self.assertTrue(inner_bkpt, VALID_BREAKPOINT)

        # Now launch the process, and do not stop at entry point.
        self.process = self.target.LaunchSimple (None, None, self.get_process_working_directory())

        self.assertTrue(self.process, PROCESS_IS_VALID)

        # Now finish, and make sure the return value is correct.
        threads = lldbutil.get_threads_stopped_at_breakpoint (self.process, inner_bkpt)
        self.assertTrue(len(threads) == 1, "Stopped at inner breakpoint.")
        self.thread = threads[0]
예제 #56
0
    def test_find_global_variables_then_object_description(self):
        """Exercise SBTarget.FindGlobalVariables() API."""
        d = {'EXE': 'b.out'}
        self.build(dictionary=d)
        self.setTearDownCleanup(dictionary=d)
        exe = os.path.join(os.getcwd(), 'b.out')

        # Create a target by the debugger.
        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        breakpoint = target.BreakpointCreateByLocation(self.source, self.line)
        self.assertTrue(breakpoint, VALID_BREAKPOINT)

        # Now launch the process, and do not stop at entry point.
        process = target.LaunchSimple (None, None, self.get_process_working_directory())
        self.assertTrue(process, PROCESS_IS_VALID)
        # Make sure we hit our breakpoint:
        thread_list = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint)
        self.assertTrue (len(thread_list) == 1)

        thread = thread_list[0]
        frame0 = thread.GetFrameAtIndex(0)

        # Note my_global_str's object description prints fine here.
        value_list1 = frame0.GetVariables(True, True, True, True)
        for v in value_list1:
            self.DebugSBValue(v)
            if self.TraceOn():
                print "val:", v
                print "object description:", v.GetObjectDescription()
            if v.GetName() == 'my_global_str':
                self.assertTrue(v.GetObjectDescription() == 'This is a global string')

        # But not here!
        value_list2 = target.FindGlobalVariables('my_global_str', 3)
        for v in value_list2:
            self.DebugSBValue(v)
            if self.TraceOn():
                print "val:", v
                print "object description:", v.GetObjectDescription()
            if v.GetName() == 'my_global_str':
                self.assertTrue(v.GetObjectDescription() == 'This is a global string')