aboutsummaryrefslogtreecommitdiff
path: root/lldb/test/API/tools/lldb-server/TestGdbRemoteAttach.py
blob: 5aa790b1c97e541329bd8e6a888d40512e8cb932 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import gdbremote_testcase
import lldbgdbserverutils
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil


class TestGdbRemoteAttach(gdbremote_testcase.GdbRemoteTestCaseBase):
    def test_attach_with_vAttach(self):
        self.build()
        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"])
        self.assertIsNotNone(procs)

        # Make sure the target process has been launched.
        inferior = procs.get("inferior")
        self.assertIsNotNone(inferior)
        self.assertGreater(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)