blob: 596c3ef8e5fd82b6eea9c632a1b0b76fa4c22394 [file] [log] [blame]
Jim Ingham0ac57092013-02-14 03:05:42 +00001"""
2Test calling a function that hits a signal set to auto-restart, make sure the call completes.
3"""
4
5import unittest2
6import lldb
7import lldbutil
8from lldbtest import *
9
10class ExprCommandWithTimeoutsTestCase(TestBase):
11
12 mydir = os.path.join("expression_command", "call-throws")
13
14 def setUp(self):
15 # Call super's setUp().
16 TestBase.setUp(self)
17
18 self.main_source = "call-throws.m"
19 self.main_source_spec = lldb.SBFileSpec (self.main_source)
20
21
22 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
23 @dsym_test
24 def test_with_dsym(self):
25 """Test calling std::String member function."""
26 self.buildDsym()
27 self.call_function()
28
Daniel Malea654b12c2013-02-15 19:37:48 +000029 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin due to ObjC test case")
Jim Ingham0ac57092013-02-14 03:05:42 +000030 @dwarf_test
31 def test_with_dwarf(self):
32 """Test calling std::String member function."""
33 self.buildDwarf()
34 self.call_function()
35
36 def check_after_call (self):
37 # Check that we are back where we were before:
38 frame = self.thread.GetFrameAtIndex(0)
39 self.assertTrue (self.orig_frame_pc == frame.GetPC(), "Restored the zeroth frame correctly")
40
41
42 def call_function(self):
43 """Test calling function with timeout."""
44 exe_name = "a.out"
45 exe = os.path.join(os.getcwd(), exe_name)
46
47 target = self.dbg.CreateTarget(exe)
48 self.assertTrue(target, VALID_TARGET)
49
50 breakpoint = target.BreakpointCreateBySourceRegex('I am about to throw.',self.main_source_spec)
51 self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT)
52
53 # Launch the process, and do not stop at the entry point.
54 process = target.LaunchSimple(None, None, os.getcwd())
55
56 self.assertTrue(process, PROCESS_IS_VALID)
57
58 # Frame #0 should be at our breakpoint.
59 threads = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint)
60
61 self.assertTrue(len(threads) == 1)
62 self.thread = threads[0]
63
64 options = lldb.SBExpressionOptions()
65 options.SetUnwindOnError(True)
66
67 frame = self.thread.GetFrameAtIndex(0)
68 # Store away the PC to check that the functions unwind to the right place after calls
69 self.orig_frame_pc = frame.GetPC()
70
71 value = frame.EvaluateExpression ("[my_class callMeIThrow]", options)
72 self.assertTrue (value.IsValid())
73 self.assertTrue (value.GetError().Success() == False)
74
75 self.check_after_call()
76
77 # Okay, now try with a breakpoint in the called code in the case where
78 # we are ignoring breakpoint hits.
79 handler_bkpt = target.BreakpointCreateBySourceRegex("I felt like it", self.main_source_spec)
80 self.assertTrue (handler_bkpt.GetNumLocations() > 0)
81 options.SetIgnoreBreakpoints(True)
82 options.SetUnwindOnError(True)
83
84 value = frame.EvaluateExpression ("[my_class callMeIThrow]", options)
85
86 self.assertTrue (value.IsValid() and value.GetError().Success() == False)
87 self.check_after_call()
88
89 # Now set this unwind on error to false, and make sure that we stop where the exception was thrown
90 options.SetUnwindOnError(False)
91 value = frame.EvaluateExpression ("[my_class callMeIThrow]", options)
92
93
94 self.assertTrue (value.IsValid() and value.GetError().Success() == False)
95 self.check_after_call()
96
97if __name__ == '__main__':
98 import atexit
99 lldb.SBDebugger.Initialize()
100 atexit.register(lambda: lldb.SBDebugger.Terminate())
101 unittest2.main()