xref: /llvm-project/lldb/test/API/tools/lldb-server/TestGdbRemoteAttach.py (revision 9c2468821ec51defd09c246fea4a47886fff8c01)
1import gdbremote_testcase
2import lldbgdbserverutils
3from lldbsuite.test.decorators import *
4from lldbsuite.test.lldbtest import *
5from lldbsuite.test import lldbutil
6
7
8class TestGdbRemoteAttach(gdbremote_testcase.GdbRemoteTestCaseBase):
9    def test_attach_with_vAttach(self):
10        self.build()
11        self.set_inferior_startup_attach_manually()
12
13        # Start the inferior, start the debug monitor, nothing is attached yet.
14        procs = self.prep_debug_monitor_and_inferior(inferior_args=["sleep:60"])
15        self.assertIsNotNone(procs)
16
17        # Make sure the target process has been launched.
18        inferior = procs.get("inferior")
19        self.assertIsNotNone(inferior)
20        self.assertGreater(inferior.pid, 0)
21        self.assertTrue(lldbgdbserverutils.process_is_running(inferior.pid, True))
22
23        # Add attach packets.
24        self.test_sequence.add_log_lines(
25            [
26                # Do the attach.
27                "read packet: $vAttach;{:x}#00".format(inferior.pid),
28                # Expect a stop notification from the attach.
29                {
30                    "direction": "send",
31                    "regex": r"^\$T([0-9a-fA-F]{2})[^#]*#[0-9a-fA-F]{2}$",
32                    "capture": {1: "stop_signal_hex"},
33                },
34            ],
35            True,
36        )
37        self.add_process_info_collection_packets()
38
39        # Run the stream
40        context = self.expect_gdbremote_sequence()
41        self.assertIsNotNone(context)
42
43        # Gather process info response
44        process_info = self.parse_process_info_response(context)
45        self.assertIsNotNone(process_info)
46
47        # Ensure the process id matches what we expected.
48        pid_text = process_info.get("pid", None)
49        self.assertIsNotNone(pid_text)
50        reported_pid = int(pid_text, base=16)
51        self.assertEqual(reported_pid, inferior.pid)
52