]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/expression_command/call-throws/TestCallThatThrows.py
Vendor import of lldb trunk r338536:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / expression_command / call-throws / TestCallThatThrows.py
1 """
2 Test calling a function that throws an ObjC exception, make sure that it doesn't propagate the exception.
3 """
4
5 from __future__ import print_function
6
7
8 import lldb
9 from lldbsuite.test.decorators import *
10 from lldbsuite.test.lldbtest import *
11 from lldbsuite.test import lldbutil
12
13
14 class ExprCommandWithThrowTestCase(TestBase):
15
16     mydir = TestBase.compute_mydir(__file__)
17
18     def setUp(self):
19         # Call super's setUp().
20         TestBase.setUp(self)
21
22         self.main_source = "call-throws.m"
23         self.main_source_spec = lldb.SBFileSpec(self.main_source)
24
25     @skipUnlessDarwin
26     def test(self):
27         """Test calling a function that throws and ObjC exception."""
28         self.build()
29         self.call_function()
30
31     def check_after_call(self):
32         # Check that we are back where we were before:
33         frame = self.thread.GetFrameAtIndex(0)
34         self.assertTrue(
35             self.orig_frame_pc == frame.GetPC(),
36             "Restored the zeroth frame correctly")
37
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)
42
43         options = lldb.SBExpressionOptions()
44         options.SetUnwindOnError(True)
45
46         frame = self.thread.GetFrameAtIndex(0)
47         # Store away the PC to check that the functions unwind to the right
48         # place after calls
49         self.orig_frame_pc = frame.GetPC()
50
51         value = frame.EvaluateExpression("[my_class callMeIThrow]", options)
52         self.assertTrue(value.IsValid())
53         self.assertTrue(value.GetError().Success() == False)
54
55         self.check_after_call()
56
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)
64
65         value = frame.EvaluateExpression("[my_class callMeIThrow]", options)
66
67         self.assertTrue(
68             value.IsValid() and value.GetError().Success() == False)
69         self.check_after_call()
70
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)
76
77         options.SetIgnoreBreakpoints(True)
78         options.SetUnwindOnError(True)
79
80         value = frame.EvaluateExpression("[my_class callMeIThrow]", options)
81
82         self.assertTrue(
83             value.IsValid() and value.GetError().Success() == False)
84         self.check_after_call()
85
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
88         # value:
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)
96
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)
101
102         self.assertTrue(
103             value.IsValid() and value.GetError().Success() == False)
104         self.check_after_call()