blob: 5e04a6703b91ff287c0d38734dca1a9c7fda6f14 [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
29 @dwarf_test
30 def test_with_dwarf(self):
31 """Test calling std::String member function."""
32 self.buildDwarf()
33 self.call_function()
34
35 def check_after_call (self):
36 # Check that we are back where we were before:
37 frame = self.thread.GetFrameAtIndex(0)
38 self.assertTrue (self.orig_frame_pc == frame.GetPC(), "Restored the zeroth frame correctly")
39
40
41 def call_function(self):
42 """Test calling function with timeout."""
43 exe_name = "a.out"
44 exe = os.path.join(os.getcwd(), exe_name)
45
46 target = self.dbg.CreateTarget(exe)
47 self.assertTrue(target, VALID_TARGET)
48
49 breakpoint = target.BreakpointCreateBySourceRegex('I am about to throw.',self.main_source_spec)
50 self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT)
51
52 # Launch the process, and do not stop at the entry point.
53 process = target.LaunchSimple(None, None, os.getcwd())
54
55 self.assertTrue(process, PROCESS_IS_VALID)
56
57 # Frame #0 should be at our breakpoint.
58 threads = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint)
59
60 self.assertTrue(len(threads) == 1)
61 self.thread = threads[0]
62
63 options = lldb.SBExpressionOptions()
64 options.SetUnwindOnError(True)
65
66 frame = self.thread.GetFrameAtIndex(0)
67 # Store away the PC to check that the functions unwind to the right place after calls
68 self.orig_frame_pc = frame.GetPC()
69
70 value = frame.EvaluateExpression ("[my_class callMeIThrow]", options)
71 self.assertTrue (value.IsValid())
72 self.assertTrue (value.GetError().Success() == False)
73
74 self.check_after_call()
75
76 # Okay, now try with a breakpoint in the called code in the case where
77 # we are ignoring breakpoint hits.
78 handler_bkpt = target.BreakpointCreateBySourceRegex("I felt like it", self.main_source_spec)
79 self.assertTrue (handler_bkpt.GetNumLocations() > 0)
80 options.SetIgnoreBreakpoints(True)
81 options.SetUnwindOnError(True)
82
83 value = frame.EvaluateExpression ("[my_class callMeIThrow]", options)
84
85 self.assertTrue (value.IsValid() and value.GetError().Success() == False)
86 self.check_after_call()
87
88 # Now set this unwind on error to false, and make sure that we stop where the exception was thrown
89 options.SetUnwindOnError(False)
90 value = frame.EvaluateExpression ("[my_class callMeIThrow]", options)
91
92
93 self.assertTrue (value.IsValid() and value.GetError().Success() == False)
94 self.check_after_call()
95
96if __name__ == '__main__':
97 import atexit
98 lldb.SBDebugger.Initialize()
99 atexit.register(lambda: lldb.SBDebugger.Terminate())
100 unittest2.main()