Exemplo n.º 1
0
    def launch(self, target, signal):
        # launch the process, do not stop at entry point.
        # If we have gotten the default for this signal, reset that as well.
        if len(self.default_pass) != 0:
            lldbutil.set_actions_for_signal(self, signal, self.default_pass, self.default_stop, self.default_notify)

        process = target.LaunchSimple(
            [signal], None, self.get_process_working_directory())
        self.assertTrue(process, PROCESS_IS_VALID)
        self.assertEqual(process.GetState(), lldb.eStateStopped)
        thread = lldbutil.get_stopped_thread(
            process, lldb.eStopReasonBreakpoint)
        self.assertTrue(
            thread.IsValid(),
            "Thread should be stopped due to a breakpoint")
        return process
Exemplo n.º 2
0
    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()

        # Make sure we don't accept signal values by signo with no process - we don't know what the
        # mapping will be so we can't do the right thing with bare numbers:
        lldbutil.set_actions_for_signal(self,
                                        "9",
                                        "true",
                                        None,
                                        None,
                                        expect_success=False)

        # First, I need a reference value so I can see whether changes actually took:
        (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")

        # Let's change the value here, then exit and make sure the changed value sticks:
        new_value = "false"
        if default_pass == "true":
            new_value = "false"

        # First make sure we get an error for bogus values when running:
        lldbutil.set_actions_for_signal(self,
                                        "NOTSIGSEGV",
                                        new_value,
                                        None,
                                        None,
                                        expect_success=False)

        # Then set the one we intend to change.
        lldbutil.set_actions_for_signal(self, "SIGSEGV", new_value, None, None)

        process.Continue()

        self.assertEqual(process.GetState(), lldb.eStateExited)
        self.assertEqual(process.GetExitStatus(), 0)

        # Check that we preserved the setting:
        (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")

        # Run again and make sure that we prime the new process with these settings:
        process = lldbutil.run_to_breakpoint_do_run(self, target, bkpt)

        # We check the process settings now, to see what got copied into the process:
        (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")

        # Now kill this target, set the handling and make sure the values get copied from the dummy into the new target.
        success = self.dbg.DeleteTarget(target)
        self.assertTrue(success, "Deleted the target")
        self.assertEqual(self.dbg.GetNumTargets(), 0,
                         "We did delete all the targets.")

        # The signal settings should be back at their default - we were only setting this on the target:
        lldbutil.get_actions_for_signal(self,
                                        "SIGSEGV",
                                        from_target=True,
                                        expected_absent=True)
        # Set a valid one:
        lldbutil.set_actions_for_signal(self, "SIGSEGV", new_value, None, None)
        # Set a bogus one - we don't have a way to check pre-run so this is allowed
        # but we should get an error message when launching:
        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)
        # Now make a new process and make sure the right values got copied into the new target
        (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")
        # Also make sure we didn't accidentally add this bogus setting to the process.
        lldbutil.set_actions_for_signal(self,
                                        "SIGNOTSIG",
                                        "true",
                                        "true",
                                        "true",
                                        expect_success=False)

        # Check that they went into the target:
        (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")

        # And the process:
        # Check that they went into the target:
        (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")

        # Now clear the handling, and make sure that we get the right signal values again:
        self.runCmd("process handle -c SIGSEGV")
        # Check that there is no longer configuration for SIGSEGV in the target:
        lldbutil.get_actions_for_signal(self,
                                        "SIGSEGV",
                                        from_target=True,
                                        expected_absent=True)
        # Make a new process, to make sure we did indeed reset the values:
        (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")

        # Finally remove this from the dummy target as well, and make sure it was cleared from there:
        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")
Exemplo n.º 3
0
    def signal_test(self, signal, test_passing):
        """Test that we handle inferior raising signals"""
        exe = self.getBuildArtifact("a.out")

        # Create a target by the debugger.
        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)
        lldbutil.run_break_set_by_symbol(self, "main")
        self.default_pass = ""
        self.default_stop = ""
        self.default_notify = ""

        # launch
        process = self.launch(target, signal)
        signo = process.GetUnixSignals().GetSignalNumberFromName(signal)

        # retrieve default signal disposition
        (self.default_pass, self.default_stop,
         self.default_notify) = lldbutil.get_actions_for_signal(self, signal)

        # Make sure we stop at the signal
        lldbutil.set_actions_for_signal(self, signal, "false", "true", "true")
        process.Continue()
        self.assertState(process.GetState(), lldb.eStateStopped)
        thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonSignal)
        self.assertTrue(thread.IsValid(),
                        "Thread should be stopped due to a signal")
        self.assertTrue(thread.GetStopReasonDataCount() >= 1,
                        "There was data in the event.")
        self.assertEqual(thread.GetStopReasonDataAtIndex(0), signo,
                         "The stop signal was %s" % signal)

        # Continue until we exit.
        process.Continue()
        self.assertState(process.GetState(), lldb.eStateExited)
        self.assertEqual(process.GetExitStatus(), 0)

        process = self.launch(target, signal)

        # Make sure we do not stop at the signal. We should still get the
        # notification.
        lldbutil.set_actions_for_signal(self, signal, "false", "false", "true")
        self.expect("process continue",
                    substrs=["stopped and restarted", signal])
        self.assertState(process.GetState(), lldb.eStateExited)
        self.assertEqual(process.GetExitStatus(), 0)

        # launch again
        process = self.launch(target, signal)

        # Make sure we do not stop at the signal, and we do not get the
        # notification.
        lldbutil.set_actions_for_signal(self, signal, "false", "false",
                                        "false")
        self.expect("process continue",
                    substrs=["stopped and restarted"],
                    matching=False)
        self.assertState(process.GetState(), lldb.eStateExited)
        self.assertEqual(process.GetExitStatus(), 0)

        if not test_passing:
            # reset signal handling to default
            lldbutil.set_actions_for_signal(self, signal, self.default_pass,
                                            self.default_stop,
                                            self.default_notify)
            return

        # launch again
        process = self.launch(target, signal)

        # Make sure we stop at the signal
        lldbutil.set_actions_for_signal(self, signal, "true", "true", "true")
        process.Continue()
        self.assertState(process.GetState(), lldb.eStateStopped)
        thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonSignal)
        self.assertTrue(thread.IsValid(),
                        "Thread should be stopped due to a signal")
        self.assertTrue(thread.GetStopReasonDataCount() >= 1,
                        "There was data in the event.")
        self.assertEqual(
            thread.GetStopReasonDataAtIndex(0),
            process.GetUnixSignals().GetSignalNumberFromName(signal),
            "The stop signal was %s" % signal)

        # Continue until we exit. The process should receive the signal.
        process.Continue()
        self.assertState(process.GetState(), lldb.eStateExited)
        self.assertEqual(process.GetExitStatus(), signo)

        # launch again
        process = self.launch(target, signal)

        # Make sure we do not stop at the signal. We should still get the notification. Process
        # should receive the signal.
        lldbutil.set_actions_for_signal(self, signal, "true", "false", "true")
        self.expect("process continue",
                    substrs=["stopped and restarted", signal])
        self.assertState(process.GetState(), lldb.eStateExited)
        self.assertEqual(process.GetExitStatus(), signo)

        # launch again
        process = self.launch(target, signal)

        # Make sure we do not stop at the signal, and we do not get the notification. Process
        # should receive the signal.
        lldbutil.set_actions_for_signal(self, signal, "true", "false", "false")
        self.expect("process continue",
                    substrs=["stopped and restarted"],
                    matching=False)
        self.assertState(process.GetState(), lldb.eStateExited)
        self.assertEqual(process.GetExitStatus(), signo)

        # reset signal handling to default
        lldbutil.set_actions_for_signal(self, signal, self.default_pass,
                                        self.default_stop, self.default_notify)