2 Test stopping at a breakpoint in an expression, and unwinding from there.
10 from lldbsuite.test.decorators import *
11 from lldbsuite.test.lldbtest import *
12 from lldbsuite.test import lldbutil
15 class UnwindFromExpressionTest(TestBase):
17 mydir = TestBase.compute_mydir(__file__)
18 main_spec = lldb.SBFileSpec("main.cpp", False)
20 def build_and_run_to_bkpt(self):
23 (target, process, self.thread, bkpt) = lldbutil.run_to_source_breakpoint(self,
24 "// Set a breakpoint here to get started", self.main_spec)
26 # Next set a breakpoint in this function, set up Expression options to stop on
27 # breakpoint hits, and call the function.
28 self.fun_bkpt = self.target().BreakpointCreateBySourceRegex(
29 "// Stop inside the function here.", self.main_spec)
30 self.assertTrue(self.fun_bkpt, VALID_BREAKPOINT)
34 @expectedFailureAll(bugnumber="llvm.org/pr33164")
35 def test_conditional_bktp(self):
37 Test conditional breakpoint handling in the IgnoreBreakpoints = False case
39 self.build_and_run_to_bkpt()
41 self.fun_bkpt.SetCondition("0") # Should not get hit
42 options = lldb.SBExpressionOptions()
43 options.SetIgnoreBreakpoints(False)
44 options.SetUnwindOnError(False)
46 main_frame = self.thread.GetFrameAtIndex(0)
47 val = main_frame.EvaluateExpression("second_function(47)", options)
49 val.GetError().Success(),
50 "We did complete the execution.")
51 self.assertEquals(47, val.GetValueAsSigned())
54 @add_test_categories(['pyapi'])
56 def test_unwind_expression(self):
57 """Test unwinding from an expression."""
58 self.build_and_run_to_bkpt()
60 # Run test with varying one thread timeouts to also test the halting
61 # logic in the IgnoreBreakpoints = False case
62 self.do_unwind_test(self.thread, self.fun_bkpt, 1000)
63 self.do_unwind_test(self.thread, self.fun_bkpt, 100000)
65 def do_unwind_test(self, thread, bkpt, timeout):
67 # Use Python API to evaluate expressions while stopped in a stack frame.
69 main_frame = thread.GetFrameAtIndex(0)
71 options = lldb.SBExpressionOptions()
72 options.SetIgnoreBreakpoints(False)
73 options.SetUnwindOnError(False)
74 options.SetOneThreadTimeoutInMicroSeconds(timeout)
76 val = main_frame.EvaluateExpression("a_function_to_call()", options)
79 val.GetError().Fail(),
80 "We did not complete the execution.")
81 error_str = val.GetError().GetCString()
83 "Execution was interrupted, reason: breakpoint" in error_str,
84 "And the reason was right.")
86 thread = lldbutil.get_one_thread_stopped_at_breakpoint(
90 "We are indeed stopped at our breakpoint")
92 # Now unwind the expression, and make sure we got back to where we
94 error = thread.UnwindInnermostExpression()
95 self.assertTrue(error.Success(), "We succeeded in unwinding")
97 cur_frame = thread.GetFrameAtIndex(0)
99 cur_frame.IsEqual(main_frame),
100 "We got back to the main frame.")