コード例 #1
0
    def reverse_connect_works(self):
        # Indicate stub startup should do a reverse connect.
        appended_stub_args = ["--reverse-connect"]
        if self.debug_monitor_extra_args:
            self.debug_monitor_extra_args += appended_stub_args
        else:
            self.debug_monitor_extra_args = appended_stub_args

        self.stub_hostname = "127.0.0.1"
        self.port = self.listener_port

        triple = self.dbg.GetSelectedPlatform().GetTriple()
        if re.match(".*-.*-.*-android", triple):
            self.forward_adb_port(self.port, self.port, "reverse",
                                  self.stub_device)

        # Start the stub.
        server = self.launch_debug_monitor(logfile=sys.stdout)
        self.assertIsNotNone(server)
        self.assertTrue(lldbgdbserverutils.process_is_running(
            server.pid, True))

        # Listen for the stub's connection to us.
        (stub_socket, address) = self.listener_socket.accept()
        self.assertIsNotNone(stub_socket)
        self.assertIsNotNone(address)
        print("connected to stub {} on {}".format(address,
                                                  stub_socket.getsockname()))

        # Verify we can do the handshake.  If that works, we'll call it good.
        self.do_handshake(stub_socket, timeout_seconds=self._DEFAULT_TIMEOUT)

        # Clean up.
        stub_socket.shutdown(socket.SHUT_RDWR)
コード例 #2
0
    def attach_commandline_kill_after_initial_stop(self):
        reg_expr = r"^\$[XW][0-9a-fA-F]+([^#]*)#[0-9A-Fa-f]{2}"
        procs = self.prep_debug_monitor_and_inferior()
        self.test_sequence.add_log_lines([
            "read packet: $k#6b",
            {"direction": "send", "regex": reg_expr},
        ], True)

        if self.stub_sends_two_stop_notifications_on_kill:
            # Add an expectation for a second X result for stubs that send two
            # of these.
            self.test_sequence.add_log_lines([
                {"direction": "send", "regex": reg_expr},
            ], True)

        self.expect_gdbremote_sequence()

        # Wait a moment for completed and now-detached inferior process to
        # clear.
        time.sleep(self.DEFAULT_SLEEP)

        if not lldb.remote_platform:
            # Process should be dead now. Reap results.
            poll_result = procs["inferior"].poll()
            self.assertIsNotNone(poll_result)

        # Where possible, verify at the system level that the process is not
        # running.
        self.assertFalse(
            lldbgdbserverutils.process_is_running(
                procs["inferior"].pid, False))
コード例 #3
0
    def attach_commandline_kill_after_initial_stop(self):
        procs = self.prep_debug_monitor_and_inferior()
        self.test_sequence.add_log_lines([
            "read packet: $k#6b",
            {"direction":"send", "regex":r"^\$X[0-9a-fA-F]+([^#]*)#[0-9A-Fa-f]{2}" },
            ], True)

        if self.stub_sends_two_stop_notifications_on_kill:
            # Add an expectation for a second X result for stubs that send two of these.
            self.test_sequence.add_log_lines([
                {"direction":"send", "regex":r"^\$X[0-9a-fA-F]+([^#]*)#[0-9A-Fa-f]{2}" },
                ], True)

        self.expect_gdbremote_sequence()

        # Wait a moment for completed and now-detached inferior process to clear.
        time.sleep(1)

        if not lldb.remote_platform:
            # Process should be dead now. Reap results.
            poll_result = procs["inferior"].poll()
            self.assertIsNotNone(poll_result)

        # Where possible, verify at the system level that the process is not running.
        self.assertFalse(lldbgdbserverutils.process_is_running(procs["inferior"].pid, False))
コード例 #4
0
    def attach_with_vAttach(self):
        # Start the inferior, start the debug monitor, nothing is attached yet.
        procs = self.prep_debug_monitor_and_inferior(inferior_args=["sleep:60"])
        self.assertIsNotNone(procs)

        # Make sure the target process has been launched.
        inferior = procs.get("inferior")
        self.assertIsNotNone(inferior)
        self.assertTrue(inferior.pid > 0)
        self.assertTrue(lldbgdbserverutils.process_is_running(inferior.pid, True))

        # Add attach packets.
        self.test_sequence.add_log_lines([
            # Do the attach.
            "read packet: $vAttach;{:x}#00".format(inferior.pid),
            # Expect a stop notification from the attach.
            { "direction":"send", "regex":r"^\$T([0-9a-fA-F]{2})[^#]*#[0-9a-fA-F]{2}$", "capture":{1:"stop_signal_hex"} },
            ], True)
        self.add_process_info_collection_packets()

        # Run the stream
        context = self.expect_gdbremote_sequence()
        self.assertIsNotNone(context)

        # Gather process info response
        process_info = self.parse_process_info_response(context)
        self.assertIsNotNone(process_info)

        # Ensure the process id matches what we expected.
        pid_text = process_info.get('pid', None)
        self.assertIsNotNone(pid_text)
        reported_pid = int(pid_text, base=16)
        self.assertEqual(reported_pid, inferior.pid)
コード例 #5
0
    def reverse_connect_works(self):
        # Indicate stub startup should do a reverse connect.
        appended_stub_args = ["--reverse-connect"]
        if self.debug_monitor_extra_args:
            self.debug_monitor_extra_args += appended_stub_args
        else:
            self.debug_monitor_extra_args = appended_stub_args

        self.stub_hostname = "127.0.0.1"
        self.port = self.listener_port

        triple = self.dbg.GetSelectedPlatform().GetTriple()
        if re.match(".*-.*-.*-android", triple):
            self.forward_adb_port(self.port, self.port, "reverse")

        # Start the stub.
        server = self.launch_debug_monitor(logfile=sys.stdout)
        self.assertIsNotNone(server)
        self.assertTrue(lldbgdbserverutils.process_is_running(server.pid, True))

        # Listen for the stub's connection to us.
        (stub_socket, address) = self.listener_socket.accept()
        self.assertIsNotNone(stub_socket)
        self.assertIsNotNone(address)
        print "connected to stub {} on {}".format(address, stub_socket.getsockname())

        # Verify we can do the handshake.  If that works, we'll call it good.
        self.do_handshake(stub_socket, timeout_seconds=self._DEFAULT_TIMEOUT)

        # Clean up.
        stub_socket.shutdown(socket.SHUT_RDWR)
コード例 #6
0
    def attach_with_vAttach(self):
        # Start the inferior, start the debug monitor, nothing is attached yet.
        procs = self.prep_debug_monitor_and_inferior(inferior_args=["sleep:60"])
        self.assertIsNotNone(procs)

        # Make sure the target process has been launched.
        inferior = procs.get("inferior")
        self.assertIsNotNone(inferior)
        self.assertTrue(inferior.pid > 0)
        self.assertTrue(lldbgdbserverutils.process_is_running(inferior.pid, True))

        # Add attach packets.
        self.test_sequence.add_log_lines([
            # Do the attach.
            "read packet: $vAttach;{:x}#00".format(inferior.pid),
            # Expect a stop notification from the attach.
            { "direction":"send", "regex":r"^\$T([0-9a-fA-F]{2})[^#]*#[0-9a-fA-F]{2}$", "capture":{1:"stop_signal_hex"} },
            ], True)
        self.add_process_info_collection_packets()

        # Run the stream
        context = self.expect_gdbremote_sequence()
        self.assertIsNotNone(context)

        # Gather process info response
        process_info = self.parse_process_info_response(context)
        self.assertIsNotNone(process_info)

        # Ensure the process id matches what we expected.
        pid_text = process_info.get('pid', None)
        self.assertIsNotNone(pid_text)
        reported_pid = int(pid_text, base=16)
        self.assertEqual(reported_pid, inferior.pid)
コード例 #7
0
 def _launch_inferior(self, args):
     inferior = self.spawnSubprocess(
         self.getBuildArtifact(self._exe_to_run), args)
     self.assertIsNotNone(inferior)
     self.assertTrue(inferior.pid > 0)
     self.assertTrue(
         lldbgdbserverutils.process_is_running(inferior.pid, True))
     return inferior
コード例 #8
0
 def launch_inferior():
     inferior = self.launch_process_for_attach(
         inferior_args=["sleep:60"],
         exe_path=self.getBuildArtifact(exe))
     self.assertIsNotNone(inferior)
     self.assertTrue(inferior.pid > 0)
     self.assertTrue(
         lldbgdbserverutils.process_is_running(inferior.pid, True))
     return inferior
    def test_launch_after_attach_with_vAttachOrWait(self):
        exe = '%s_%d' % (self.testMethodName, os.getpid())
        self.build(dictionary={'EXE': exe})
        self.set_inferior_startup_attach_manually()

        server = self.connect_to_debug_monitor()
        self.assertIsNotNone(server)

        self.add_no_ack_remote_stream()
        self.test_sequence.add_log_lines(
            [
                # Do the attach.
                "read packet: $vAttachOrWait;{}#00".format(
                    lldbgdbserverutils.gdbremote_hex_encode_string(exe)),
            ],
            True)
        # Run the stream until attachWait.
        context = self.expect_gdbremote_sequence()
        self.assertIsNotNone(context)

        # Sleep so we're sure that the inferior is launched after we ask for the attach.
        sleep(1)

        # Launch the inferior.
        inferior = self.launch_process_for_attach(
            inferior_args=["sleep:60"], exe_path=self.getBuildArtifact(exe))
        self.assertIsNotNone(inferior)
        self.assertTrue(inferior.pid > 0)
        self.assertTrue(
            lldbgdbserverutils.process_is_running(inferior.pid, True))

        # Make sure the attach succeeded.
        self.test_sequence.add_log_lines([
            {
                "direction": "send",
                "regex": r"^\$T([0-9a-fA-F]{2})[^#]*#[0-9a-fA-F]{2}$",
                "capture": {
                    1: "stop_signal_hex"
                }
            },
        ], True)
        self.add_process_info_collection_packets()

        # Run the stream sending the response..
        context = self.expect_gdbremote_sequence()
        self.assertIsNotNone(context)

        # Gather process info response.
        process_info = self.parse_process_info_response(context)
        self.assertIsNotNone(process_info)

        # Ensure the process id matches what we expected.
        pid_text = process_info.get('pid', None)
        self.assertIsNotNone(pid_text)
        reported_pid = int(pid_text, base=16)
        self.assertEqual(reported_pid, inferior.pid)
コード例 #10
0
    def get_stub_sid(self, extra_stub_args=None):
        # Launch debugserver
        if extra_stub_args:
            self.debug_monitor_extra_args += extra_stub_args

        server = self.launch_debug_monitor()
        self.assertIsNotNone(server)
        self.assertTrue(lldbgdbserverutils.process_is_running(server.pid, True))

        # Get the process id for the stub.
        return os.getsid(server.pid)
コード例 #11
0
ファイル: TestStubSetSID.py プロジェクト: prograholic/lldb
    def get_stub_sid(self, extra_stub_args=None):
        # Launch debugserver
        if extra_stub_args:
            self.debug_monitor_extra_args += extra_stub_args

        server = self.launch_debug_monitor()
        self.assertIsNotNone(server)
        self.assertTrue(lldbgdbserverutils.process_is_running(server.pid, True))

        # Get the process id for the stub.
        return os.getsid(server.pid)
    def test_launch_before_attach_with_vAttachOrWait(self):
        exe = '%s_%d' % (self.testMethodName, os.getpid())
        self.build(dictionary={'EXE': exe})
        self.set_inferior_startup_attach_manually()

        # Start the inferior, start the debug monitor, nothing is attached yet.
        procs = self.prep_debug_monitor_and_inferior(
            inferior_args=["sleep:60"],
            inferior_exe_path=self.getBuildArtifact(exe))
        self.assertIsNotNone(procs)

        # Make sure the target process has been launched.
        inferior = procs.get("inferior")
        self.assertIsNotNone(inferior)
        self.assertTrue(inferior.pid > 0)
        self.assertTrue(
            lldbgdbserverutils.process_is_running(inferior.pid, True))

        # Add attach packets.
        self.test_sequence.add_log_lines(
            [
                # Do the attach.
                "read packet: $vAttachOrWait;{}#00".format(
                    lldbgdbserverutils.gdbremote_hex_encode_string(exe)),
                # Expect a stop notification from the attach.
                {
                    "direction": "send",
                    "regex": r"^\$T([0-9a-fA-F]{2})[^#]*#[0-9a-fA-F]{2}$",
                    "capture": {
                        1: "stop_signal_hex"
                    }
                },
            ],
            True)
        self.add_process_info_collection_packets()

        # Run the stream
        context = self.expect_gdbremote_sequence()
        self.assertIsNotNone(context)

        # Gather process info response
        process_info = self.parse_process_info_response(context)
        self.assertIsNotNone(process_info)

        # Ensure the process id matches what we expected.
        pid_text = process_info.get('pid', None)
        self.assertIsNotNone(pid_text)
        reported_pid = int(pid_text, base=16)
        self.assertEqual(reported_pid, inferior.pid)
コード例 #13
0
    def qProcessInfo_returns_running_process(self):
        procs = self.prep_debug_monitor_and_inferior()
        self.add_process_info_collection_packets()

        # Run the stream
        context = self.expect_gdbremote_sequence()
        self.assertIsNotNone(context)

        # Gather process info response
        process_info = self.parse_process_info_response(context)
        self.assertIsNotNone(process_info)

        # Ensure the process id looks reasonable.
        pid_text = process_info.get("pid")
        self.assertIsNotNone(pid_text)
        pid = int(pid_text, base=16)
        self.assertNotEqual(0, pid)

        # If possible, verify that the process is running.
        self.assertTrue(lldbgdbserverutils.process_is_running(pid, True))
コード例 #14
0
    def test_attach_commandline_continue_app_exits(self):
        self.build()
        self.set_inferior_startup_attach()
        procs = self.prep_debug_monitor_and_inferior()
        self.test_sequence.add_log_lines(
            ["read packet: $vCont;c#a8", "send packet: $W00#00"], True)
        self.expect_gdbremote_sequence()

        # Wait a moment for completed and now-detached inferior process to
        # clear.
        time.sleep(1)

        if not lldb.remote_platform:
            # Process should be dead now. Reap results.
            poll_result = procs["inferior"].poll()
            self.assertIsNotNone(poll_result)

        # Where possible, verify at the system level that the process is not
        # running.
        self.assertFalse(
            lldbgdbserverutils.process_is_running(procs["inferior"].pid,
                                                  False))