2 Test calling a function that throws an ObjC exception, make sure that it doesn't propagate the exception.
5 from __future__ import print_function
9 from lldbsuite.test.decorators import *
10 from lldbsuite.test.lldbtest import *
11 from lldbsuite.test import lldbutil
14 class ExprCommandWithThrowTestCase(TestBase):
16 mydir = TestBase.compute_mydir(__file__)
19 # Call super's setUp().
22 self.main_source = "call-throws.m"
23 self.main_source_spec = lldb.SBFileSpec(self.main_source)
27 """Test calling a function that throws and ObjC exception."""
31 def check_after_call(self):
32 # Check that we are back where we were before:
33 frame = self.thread.GetFrameAtIndex(0)
35 self.orig_frame_pc == frame.GetPC(),
36 "Restored the zeroth frame correctly")
38 def call_function(self):
39 """Test calling function that throws."""
40 (target, process, self.thread, bkpt) = lldbutil.run_to_source_breakpoint(self,
41 'I am about to throw.', self.main_source_spec)
43 options = lldb.SBExpressionOptions()
44 options.SetUnwindOnError(True)
46 frame = self.thread.GetFrameAtIndex(0)
47 # Store away the PC to check that the functions unwind to the right
49 self.orig_frame_pc = frame.GetPC()
51 value = frame.EvaluateExpression("[my_class callMeIThrow]", options)
52 self.assertTrue(value.IsValid())
53 self.assertTrue(value.GetError().Success() == False)
55 self.check_after_call()
57 # Okay, now try with a breakpoint in the called code in the case where
58 # we are ignoring breakpoint hits.
59 handler_bkpt = target.BreakpointCreateBySourceRegex(
60 "I felt like it", self.main_source_spec)
61 self.assertTrue(handler_bkpt.GetNumLocations() > 0)
62 options.SetIgnoreBreakpoints(True)
63 options.SetUnwindOnError(True)
65 value = frame.EvaluateExpression("[my_class callMeIThrow]", options)
68 value.IsValid() and value.GetError().Success() == False)
69 self.check_after_call()
71 # Now set the ObjC language breakpoint and make sure that doesn't
72 # interfere with the call:
73 exception_bkpt = target.BreakpointCreateForException(
74 lldb.eLanguageTypeObjC, False, True)
75 self.assertTrue(exception_bkpt.GetNumLocations() > 0)
77 options.SetIgnoreBreakpoints(True)
78 options.SetUnwindOnError(True)
80 value = frame.EvaluateExpression("[my_class callMeIThrow]", options)
83 value.IsValid() and value.GetError().Success() == False)
84 self.check_after_call()
86 # Now turn off exception trapping, and call a function that catches the exceptions,
87 # and make sure the function actually completes, and we get the right
89 options.SetTrapExceptions(False)
90 value = frame.EvaluateExpression("[my_class iCatchMyself]", options)
91 self.assertTrue(value.IsValid())
92 self.assertTrue(value.GetError().Success())
93 self.assertTrue(value.GetValueAsUnsigned() == 57)
94 self.check_after_call()
95 options.SetTrapExceptions(True)
97 # Now set this unwind on error to false, and make sure that we stop
98 # where the exception was thrown
99 options.SetUnwindOnError(False)
100 value = frame.EvaluateExpression("[my_class callMeIThrow]", options)
103 value.IsValid() and value.GetError().Success() == False)
104 self.check_after_call()