2 Test calling a function that hits a signal set to auto-restart, make sure the call completes.
7 from lldbsuite
.test
.decorators
import *
8 from lldbsuite
.test
.lldbtest
import *
9 from lldbsuite
.test
import lldbutil
12 class ExprCommandThatRestartsTestCase(TestBase
):
13 NO_DEBUG_INFO_TESTCASE
= True
16 # Call super's setUp().
19 self
.main_source
= "lotta-signals.c"
20 self
.main_source_spec
= lldb
.SBFileSpec(self
.main_source
)
22 @skipIfDarwin # llvm.org/pr19246: intermittent failure
23 @skipIfWindows # Test relies on signals, unsupported on Windows
24 @expectedFlakeyAndroid(bugnumber
="llvm.org/pr19246")
27 """Test calling function that hits a signal and restarts."""
31 def check_after_call(self
, num_sigchld
):
32 after_call
= self
.sigchld_no
.GetValueAsSigned(-1)
34 after_call
- self
.start_sigchld_no
,
36 "Really got %d SIGCHLD signals through the call." % (num_sigchld
),
38 self
.start_sigchld_no
= after_call
40 # Check that we are back where we were before:
41 frame
= self
.thread
.GetFrameAtIndex(0)
43 self
.orig_frame_pc
, frame
.GetPC(), "Restored the zeroth frame correctly"
46 def call_function(self
):
47 (target
, process
, self
.thread
, bkpt
) = lldbutil
.run_to_source_breakpoint(
48 self
, "Stop here in main.", self
.main_source_spec
51 # Make sure the SIGCHLD behavior is pass/no-stop/no-notify:
52 self
.runCmd("process handle SIGCHLD -s 0 -p 1 -n 0")
54 # The sigchld_no variable should be 0 at this point.
55 self
.sigchld_no
= target
.FindFirstGlobalVariable("sigchld_no")
56 self
.assertTrue(self
.sigchld_no
.IsValid(), "Got a value for sigchld_no")
58 self
.start_sigchld_no
= self
.sigchld_no
.GetValueAsSigned(-1)
60 self
.start_sigchld_no
, -1, "Got an actual value for sigchld_no"
63 options
= lldb
.SBExpressionOptions()
64 # processing 30 signals takes a while, increase the expression timeout
66 options
.SetTimeoutInMicroSeconds(3000000) # 3s
67 options
.SetUnwindOnError(True)
69 frame
= self
.thread
.GetFrameAtIndex(0)
70 # Store away the PC to check that the functions unwind to the right
72 self
.orig_frame_pc
= frame
.GetPC()
75 value
= frame
.EvaluateExpression("call_me (%d)" % (num_sigchld
), options
)
76 self
.assertTrue(value
.IsValid())
77 self
.assertSuccess(value
.GetError())
78 self
.assertEqual(value
.GetValueAsSigned(-1), num_sigchld
)
80 self
.check_after_call(num_sigchld
)
82 # Okay, now try with a breakpoint in the called code in the case where
83 # we are ignoring breakpoint hits.
84 handler_bkpt
= target
.BreakpointCreateBySourceRegex(
85 "Got sigchld %d.", self
.main_source_spec
87 self
.assertGreater(handler_bkpt
.GetNumLocations(), 0)
88 options
.SetIgnoreBreakpoints(True)
89 options
.SetUnwindOnError(True)
91 value
= frame
.EvaluateExpression("call_me (%d)" % (num_sigchld
), options
)
93 self
.assertTrue(value
.IsValid())
94 self
.assertSuccess(value
.GetError())
95 self
.assertEqual(value
.GetValueAsSigned(-1), num_sigchld
)
96 self
.check_after_call(num_sigchld
)
98 # Now set the signal to print but not stop and make sure that calling
100 self
.runCmd("process handle SIGCHLD -s 0 -p 1 -n 1")
102 value
= frame
.EvaluateExpression("call_me (%d)" % (num_sigchld
), options
)
104 self
.assertTrue(value
.IsValid())
105 self
.assertSuccess(value
.GetError())
106 self
.assertEqual(value
.GetValueAsSigned(-1), num_sigchld
)
107 self
.check_after_call(num_sigchld
)
109 # Now set this unwind on error to false, and make sure that we still
111 options
.SetUnwindOnError(False)
112 value
= frame
.EvaluateExpression("call_me (%d)" % (num_sigchld
), options
)
114 self
.assertTrue(value
.IsValid())
115 self
.assertSuccess(value
.GetError())
116 self
.assertEqual(value
.GetValueAsSigned(-1), num_sigchld
)
117 self
.check_after_call(num_sigchld
)
119 # Okay, now set UnwindOnError to true, and then make the signal behavior to stop
120 # and see that now we do stop at the signal point:
122 self
.runCmd("process handle SIGCHLD -s 1 -p 1 -n 1")
124 value
= frame
.EvaluateExpression("call_me (%d)" % (num_sigchld
), options
)
125 self
.assertTrue(value
.IsValid())
126 self
.assertFalse(value
.GetError().Success())
128 # Set signal handling back to no-stop, and continue and we should end
129 # up back in out starting frame:
130 self
.runCmd("process handle SIGCHLD -s 0 -p 1 -n 1")
132 error
= process
.Continue()
133 self
.assertSuccess(error
, "Continuing after stopping for signal succeeds.")
135 frame
= self
.thread
.GetFrameAtIndex(0)
139 "Continuing returned to the place we started.",