1"""Test that lldb command 'process signal SIGUSR1' to send a signal to the inferior works.""" 2 3import os, time, signal 4import unittest2 5import lldb 6from lldbtest import * 7import lldbutil 8 9class SendSignalTestCase(TestBase): 10 11 mydir = os.path.join("functionalities", "signal") 12 13 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") 14 @dsym_test 15 def test_with_dsym_and_run_command(self): 16 """Test that lldb command 'process signal SIGUSR1' sends a signal to the inferior process.""" 17 self.buildDsym() 18 self.send_signal() 19 20 @dwarf_test 21 def test_with_dwarf_and_run_command(self): 22 """Test that lldb command 'process signal SIGUSR1' sends a signal to the inferior process.""" 23 self.buildDwarf() 24 self.send_signal() 25 26 def setUp(self): 27 # Call super's setUp(). 28 TestBase.setUp(self) 29 # Find the line number to break inside main(). 30 self.line = line_number('main.c', 'Put breakpoint here') 31 32 def send_signal(self): 33 """Test that lldb command 'process signal SIGUSR1' sends a signal to the inferior process.""" 34 35 exe = os.path.join(os.getcwd(), "a.out") 36 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) 37 38 # Break inside the main() function and immediately send a signal to the inferior after resuming. 39 lldbutil.run_break_set_by_file_and_line (self, "main.c", self.line, num_expected_locations=1, loc_exact=True) 40 41 self.runCmd("run", RUN_SUCCEEDED) 42 self.runCmd("thread backtrace") 43 44 # The stop reason of the thread should be breakpoint. 45 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, 46 substrs = ['stopped', 47 'stop reason = breakpoint']) 48 49 # The breakpoint should have a hit count of 1. 50 self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE, 51 substrs = [' resolved, hit count = 1']) 52 53 self.runCmd("process status") 54 output = self.res.GetOutput() 55 pid = re.match("Process (.*) stopped", output).group(1) 56 57 # After resuming the process, send it a SIGUSR1 signal. 58 59 # It is necessary at this point to make command interpreter interaction 60 # be asynchronous, because we want to resume the process and to send it 61 # a signal. 62 self.dbg.SetAsync(True) 63 self.runCmd("process continue") 64 # Insert a delay of 1 second before doing the signaling stuffs. 65 time.sleep(1) 66 67 self.runCmd("process handle -n False -p True -s True SIGUSR1") 68 #os.kill(int(pid), signal.SIGUSR1) 69 self.runCmd("process signal SIGUSR1") 70 71 # Insert a delay of 1 second before checking the process status. 72 time.sleep(1) 73 # Make the interaction mode be synchronous again. 74 self.dbg.SetAsync(False) 75 self.expect("process status", STOPPED_DUE_TO_SIGNAL, 76 startstr = "Process %s stopped" % pid, 77 substrs = ['stop reason = signal SIGUSR1']) 78 self.expect("thread backtrace", STOPPED_DUE_TO_SIGNAL, 79 substrs = ['stop reason = signal SIGUSR1']) 80 81 82if __name__ == '__main__': 83 import atexit 84 lldb.SBDebugger.Initialize() 85 atexit.register(lambda: lldb.SBDebugger.Terminate()) 86 unittest2.main() 87