2010-10-14 01:22:03 +00:00
|
|
|
"""Test that lldb command 'process signal SIGUSR1' to send a signal to the inferior works."""
|
|
|
|
|
|
|
|
import os, time, signal
|
|
|
|
import unittest2
|
|
|
|
import lldb
|
|
|
|
from lldbtest import *
|
2012-09-22 00:05:11 +00:00
|
|
|
import lldbutil
|
2010-10-14 01:22:03 +00:00
|
|
|
|
|
|
|
class SendSignalTestCase(TestBase):
|
|
|
|
|
2011-06-27 22:10:42 +00:00
|
|
|
mydir = os.path.join("functionalities", "signal")
|
2010-10-14 01:22:03 +00:00
|
|
|
|
|
|
|
@unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
|
2012-04-06 00:56:05 +00:00
|
|
|
@dsym_test
|
2010-10-14 01:22:03 +00:00
|
|
|
def test_with_dsym_and_run_command(self):
|
|
|
|
"""Test that lldb command 'process signal SIGUSR1' sends a signal to the inferior process."""
|
|
|
|
self.buildDsym()
|
|
|
|
self.send_signal()
|
|
|
|
|
2012-04-06 00:56:05 +00:00
|
|
|
@dwarf_test
|
2010-10-14 01:22:03 +00:00
|
|
|
def test_with_dwarf_and_run_command(self):
|
|
|
|
"""Test that lldb command 'process signal SIGUSR1' sends a signal to the inferior process."""
|
|
|
|
self.buildDwarf()
|
|
|
|
self.send_signal()
|
|
|
|
|
|
|
|
def setUp(self):
|
2010-10-14 17:31:24 +00:00
|
|
|
# Call super's setUp().
|
|
|
|
TestBase.setUp(self)
|
2010-10-14 01:22:03 +00:00
|
|
|
# Find the line number to break inside main().
|
|
|
|
self.line = line_number('main.c', 'Put breakpoint here')
|
|
|
|
|
|
|
|
def send_signal(self):
|
|
|
|
"""Test that lldb command 'process signal SIGUSR1' sends a signal to the inferior process."""
|
|
|
|
|
|
|
|
exe = os.path.join(os.getcwd(), "a.out")
|
|
|
|
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
|
|
|
|
|
|
|
|
# Break inside the main() function and immediately send a signal to the inferior after resuming.
|
2012-09-22 00:05:11 +00:00
|
|
|
lldbutil.run_break_set_by_file_and_line (self, "main.c", self.line, num_expected_locations=1, loc_exact=True)
|
2010-10-14 01:22:03 +00:00
|
|
|
|
|
|
|
self.runCmd("run", RUN_SUCCEEDED)
|
2010-12-07 17:10:46 +00:00
|
|
|
self.runCmd("thread backtrace")
|
2010-10-14 01:22:03 +00:00
|
|
|
|
|
|
|
# The stop reason of the thread should be breakpoint.
|
|
|
|
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
|
Centralized a lot of the status information for processes,
threads, and stack frame down in the lldb_private::Process,
lldb_private::Thread, lldb_private::StackFrameList and the
lldb_private::StackFrame classes. We had some command line
commands that had duplicate versions of the process status
output ("thread list" and "process status" for example).
Removed the "file" command and placed it where it should
have been: "target create". Made an alias for "file" to
"target create" so we stay compatible with GDB commands.
We can now have multple usable targets in lldb at the
same time. This is nice for comparing two runs of a program
or debugging more than one binary at the same time. The
new command is "target select <target-idx>" and also to see
a list of the current targets you can use the new "target list"
command. The flow in a debug session can be:
(lldb) target create /path/to/exe/a.out
(lldb) breakpoint set --name main
(lldb) run
... hit breakpoint
(lldb) target create /bin/ls
(lldb) run /tmp
Process 36001 exited with status = 0 (0x00000000)
(lldb) target list
Current targets:
target #0: /tmp/args/a.out ( arch=x86_64-apple-darwin, platform=localhost, pid=35999, state=stopped )
* target #1: /bin/ls ( arch=x86_64-apple-darwin, platform=localhost, pid=36001, state=exited )
(lldb) target select 0
Current targets:
* target #0: /tmp/args/a.out ( arch=x86_64-apple-darwin, platform=localhost, pid=35999, state=stopped )
target #1: /bin/ls ( arch=x86_64-apple-darwin, platform=localhost, pid=36001, state=exited )
(lldb) bt
* thread #1: tid = 0x2d03, 0x0000000100000b9a a.out`main + 42 at main.c:16, stop reason = breakpoint 1.1
frame #0: 0x0000000100000b9a a.out`main + 42 at main.c:16
frame #1: 0x0000000100000b64 a.out`start + 52
Above we created a target for "a.out" and ran and hit a
breakpoint at "main". Then we created a new target for /bin/ls
and ran it. Then we listed the targest and selected our original
"a.out" program, so we showed two concurent debug sessions
going on at the same time.
llvm-svn: 129695
2011-04-18 08:33:37 +00:00
|
|
|
substrs = ['stopped',
|
2010-10-14 01:22:03 +00:00
|
|
|
'stop reason = breakpoint'])
|
|
|
|
|
|
|
|
# The breakpoint should have a hit count of 1.
|
2011-02-04 22:59:41 +00:00
|
|
|
self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
|
2010-10-14 01:22:03 +00:00
|
|
|
substrs = [' resolved, hit count = 1'])
|
|
|
|
|
|
|
|
self.runCmd("process status")
|
|
|
|
output = self.res.GetOutput()
|
2010-10-18 15:44:42 +00:00
|
|
|
pid = re.match("Process (.*) stopped", output).group(1)
|
2010-10-14 01:22:03 +00:00
|
|
|
|
2010-10-14 15:58:53 +00:00
|
|
|
# After resuming the process, send it a SIGUSR1 signal.
|
|
|
|
|
|
|
|
# It is necessary at this point to make command interpreter interaction
|
|
|
|
# be asynchronous, because we want to resume the process and to send it
|
|
|
|
# a signal.
|
2010-10-14 01:22:03 +00:00
|
|
|
self.dbg.SetAsync(True)
|
|
|
|
self.runCmd("process continue")
|
2010-10-14 15:58:53 +00:00
|
|
|
# Insert a delay of 1 second before doing the signaling stuffs.
|
|
|
|
time.sleep(1)
|
|
|
|
|
2010-10-14 01:22:03 +00:00
|
|
|
self.runCmd("process handle -n False -p True -s True SIGUSR1")
|
|
|
|
#os.kill(int(pid), signal.SIGUSR1)
|
|
|
|
self.runCmd("process signal SIGUSR1")
|
|
|
|
|
2010-10-14 15:58:53 +00:00
|
|
|
# Insert a delay of 1 second before checking the process status.
|
2010-10-14 01:22:03 +00:00
|
|
|
time.sleep(1)
|
2010-10-14 15:58:53 +00:00
|
|
|
# Make the interaction mode be synchronous again.
|
2010-10-14 01:22:03 +00:00
|
|
|
self.dbg.SetAsync(False)
|
|
|
|
self.expect("process status", STOPPED_DUE_TO_SIGNAL,
|
2010-10-18 15:44:42 +00:00
|
|
|
startstr = "Process %s stopped" % pid,
|
2010-10-14 01:22:03 +00:00
|
|
|
substrs = ['stop reason = signal SIGUSR1'])
|
|
|
|
self.expect("thread backtrace", STOPPED_DUE_TO_SIGNAL,
|
|
|
|
substrs = ['stop reason = signal SIGUSR1'])
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import atexit
|
|
|
|
lldb.SBDebugger.Initialize()
|
|
|
|
atexit.register(lambda: lldb.SBDebugger.Terminate())
|
|
|
|
unittest2.main()
|