]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/expression_command/call-throws/TestCallThatThrows.py
Vendor import of lldb release_39 branch r276489:
[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
9 import lldb
10 from lldbsuite.test.decorators import *
11 from lldbsuite.test.lldbtest import *
12 from lldbsuite.test import lldbutil
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 (self.orig_frame_pc == frame.GetPC(), "Restored the zeroth frame correctly")
35
36         
37     def call_function(self):
38         """Test calling function that throws."""
39         exe_name = "a.out"
40         exe = os.path.join(os.getcwd(), exe_name)
41
42         target = self.dbg.CreateTarget(exe)
43         self.assertTrue(target, VALID_TARGET)
44
45         breakpoint = target.BreakpointCreateBySourceRegex('I am about to throw.',self.main_source_spec)
46         self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT)
47
48         # Launch the process, and do not stop at the entry point.
49         process = target.LaunchSimple (None, None, self.get_process_working_directory())
50
51         self.assertTrue(process, PROCESS_IS_VALID)
52
53         # Frame #0 should be at our breakpoint.
54         threads = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint)
55         
56         self.assertTrue(len(threads) == 1)
57         self.thread = threads[0]
58         
59         options = lldb.SBExpressionOptions()
60         options.SetUnwindOnError(True)
61
62         frame = self.thread.GetFrameAtIndex(0)
63         # Store away the PC to check that the functions unwind to the right place after calls
64         self.orig_frame_pc = frame.GetPC()
65
66         value = frame.EvaluateExpression ("[my_class callMeIThrow]", options)
67         self.assertTrue (value.IsValid())
68         self.assertTrue (value.GetError().Success() == False)
69
70         self.check_after_call()
71
72         # Okay, now try with a breakpoint in the called code in the case where
73         # we are ignoring breakpoint hits.
74         handler_bkpt = target.BreakpointCreateBySourceRegex("I felt like it", self.main_source_spec)
75         self.assertTrue (handler_bkpt.GetNumLocations() > 0)
76         options.SetIgnoreBreakpoints(True)
77         options.SetUnwindOnError(True)
78
79         value = frame.EvaluateExpression ("[my_class callMeIThrow]", options)
80
81         self.assertTrue (value.IsValid() and value.GetError().Success() == False)
82         self.check_after_call()
83
84         # Now set the ObjC language breakpoint and make sure that doesn't interfere with the call:
85         exception_bkpt = target.BreakpointCreateForException (lldb.eLanguageTypeObjC, False, True)
86         self.assertTrue(exception_bkpt.GetNumLocations() > 0)
87
88         options.SetIgnoreBreakpoints(True)
89         options.SetUnwindOnError(True)
90
91         value = frame.EvaluateExpression ("[my_class callMeIThrow]", options)
92
93         self.assertTrue (value.IsValid() and value.GetError().Success() == False)
94         self.check_after_call()
95
96
97         # Now turn off exception trapping, and call a function that catches the exceptions,
98         # and make sure the function actually completes, and we get the right value:
99         options.SetTrapExceptions(False)
100         value = frame.EvaluateExpression ("[my_class iCatchMyself]", options)
101         self.assertTrue (value.IsValid())
102         self.assertTrue (value.GetError().Success() == True)
103         self.assertTrue (value.GetValueAsUnsigned() == 57)
104         self.check_after_call()
105         options.SetTrapExceptions(True)
106
107         # Now set this unwind on error to false, and make sure that we stop where the exception was thrown
108         options.SetUnwindOnError(False)
109         value = frame.EvaluateExpression ("[my_class callMeIThrow]", options)
110
111
112         self.assertTrue (value.IsValid() and value.GetError().Success() == False)
113         self.check_after_call()