import lldb
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
from lldbsuite.test.decorators import *
class TestProcessHandle(TestBase):
@no_debug_info_test
@skipIfWindows
def test_process_handle(self):
"""Test that calling process handle before we have a target, and before we
have a process will affect the process. Also that the signal settings
are preserved on rerun."""
self.build()
lldbutil.set_actions_for_signal(self, "9", "true", None, None, expect_success=False)
(target, process, _, bkpt) = lldbutil.run_to_source_breakpoint(self, '// break here', lldb.SBFileSpec("main.cpp"))
(default_pass, default_stop, default_notify) = lldbutil.get_actions_for_signal(self, "SIGSEGV")
new_value = "false"
if default_pass == "true":
new_value = "false"
lldbutil.set_actions_for_signal(self, "NOTSIGSEGV", new_value, None, None, expect_success=False)
lldbutil.set_actions_for_signal(self, "SIGSEGV", new_value, None, None)
process.Continue()
self.assertState(process.GetState(), lldb.eStateExited)
self.assertEqual(process.GetExitStatus(), 0)
(curr_pass, curr_stop, curr_notify) = lldbutil.get_actions_for_signal(self, "SIGSEGV",from_target=True)
self.assertEqual(curr_pass, new_value, "Pass was set correctly")
self.assertEqual(curr_stop, "not set", "Stop was not set by us")
self.assertEqual(curr_notify, "not set", "Notify was not set by us")
process = lldbutil.run_to_breakpoint_do_run(self, target, bkpt)
(curr_pass, curr_stop, curr_notify) = lldbutil.get_actions_for_signal(self, "SIGSEGV")
self.assertEqual(curr_pass, new_value, "Pass was set correctly")
self.assertEqual(curr_stop, default_stop, "Stop was its default value")
self.assertEqual(curr_notify, default_notify, "Notify was its default value")
success = self.dbg.DeleteTarget(target)
self.assertTrue(success, "Deleted the target")
self.assertEqual(self.dbg.GetNumTargets(), 0, "We did delete all the targets.")
lldbutil.get_actions_for_signal(self, "SIGSEGV", from_target=True, expected_absent=True)
lldbutil.set_actions_for_signal(self, "SIGSEGV", new_value, None, None)
lldbutil.set_actions_for_signal(self, "SIGNOTSIG", new_value, None, None)
out_filename = self.getBuildArtifact('output')
success = True
try:
f = open(out_filename, 'w')
except:
success = False
if not success:
self.fail("Couldn't open error output file for writing.")
self.dbg.SetErrorFileHandle(f, False)
(target, process, _, bkpt) = lldbutil.run_to_source_breakpoint(self, '// break here', lldb.SBFileSpec("main.cpp"))
f.write("TESTPATTERN\n")
f.flush()
f.close()
try:
f = open(out_filename, 'r')
except:
success = False
if not success:
self.fail("Couldn't open error output file for reading")
errors = f.read()
f.close()
self.assertIn("SIGNOTSIG", errors, "We warned about the unset signal")
lldbutil.set_actions_for_signal(self, "SIGNOTSIG", "true", "true", "true", expect_success=False)
(curr_pass, curr_stop, curr_notify) = lldbutil.get_actions_for_signal(self, "SIGSEGV",from_target=True)
self.assertEqual(curr_pass, new_value, "Pass was set correctly")
self.assertEqual(curr_stop, "not set", "Stop was not set by us")
self.assertEqual(curr_notify, "not set", "Notify was not set by us")
(curr_pass, curr_stop, curr_notify) = lldbutil.get_actions_for_signal(self, "SIGSEGV")
self.assertEqual(curr_pass, new_value, "Pass was set correctly")
self.assertEqual(curr_stop, default_stop, "Stop was its default value")
self.assertEqual(curr_notify, default_notify, "Notify was its default value")
self.runCmd("process handle -c SIGSEGV")
lldbutil.get_actions_for_signal(self, "SIGSEGV",from_target=True, expected_absent=True)
(target, process, _, bkpt) = lldbutil.run_to_source_breakpoint(self, '// break here', lldb.SBFileSpec("main.cpp"))
(curr_pass, curr_stop, curr_notify) = lldbutil.get_actions_for_signal(self, "SIGSEGV")
self.assertEqual(curr_pass, new_value, "Pass was set correctly")
self.assertEqual(curr_stop, default_stop, "Stop was its default value")
self.assertEqual(curr_notify, default_notify, "Notify was its default value")
self.runCmd("process handle -c -d SIGSEGV")
error = process.Kill()
self.assertSuccess(error, "Killed the process")
success = self.dbg.DeleteTarget(target)
self.assertTrue(success, "Destroyed the target.")
(target, process, _, bkpt) = lldbutil.run_to_source_breakpoint(self, '// break here', lldb.SBFileSpec("main.cpp"))
(curr_pass, curr_stop, curr_notify) = lldbutil.get_actions_for_signal(self, "SIGSEGV")
self.assertEqual(curr_pass, default_pass, "Pass was set correctly")
self.assertEqual(curr_stop, default_stop, "Stop was its default value")
self.assertEqual(curr_notify, default_notify, "Notify was its default value")