1
2
3import gdbremote_testcase
4import lldbgdbserverutils
5from lldbsuite.test.decorators import *
6from lldbsuite.test.lldbtest import *
7from lldbsuite.test import lldbutil
8
9
10class TestGdbRemoteAttach(gdbremote_testcase.GdbRemoteTestCaseBase):
11
12    mydir = TestBase.compute_mydir(__file__)
13
14    @skipIfDarwinEmbedded # <rdar://problem/34539270> lldb-server tests not updated to work on ios etc yet
15    def attach_with_vAttach(self):
16        # Start the inferior, start the debug monitor, nothing is attached yet.
17        procs = self.prep_debug_monitor_and_inferior(
18            inferior_args=["sleep:60"])
19        self.assertIsNotNone(procs)
20
21        # Make sure the target process has been launched.
22        inferior = procs.get("inferior")
23        self.assertIsNotNone(inferior)
24        self.assertTrue(inferior.pid > 0)
25        self.assertTrue(
26            lldbgdbserverutils.process_is_running(
27                inferior.pid, True))
28
29        # Add attach packets.
30        self.test_sequence.add_log_lines([
31            # Do the attach.
32            "read packet: $vAttach;{:x}#00".format(inferior.pid),
33            # Expect a stop notification from the attach.
34            {"direction": "send",
35             "regex": r"^\$T([0-9a-fA-F]{2})[^#]*#[0-9a-fA-F]{2}$",
36             "capture": {1: "stop_signal_hex"}},
37        ], True)
38        self.add_process_info_collection_packets()
39
40        # Run the stream
41        context = self.expect_gdbremote_sequence()
42        self.assertIsNotNone(context)
43
44        # Gather process info response
45        process_info = self.parse_process_info_response(context)
46        self.assertIsNotNone(process_info)
47
48        # Ensure the process id matches what we expected.
49        pid_text = process_info.get('pid', None)
50        self.assertIsNotNone(pid_text)
51        reported_pid = int(pid_text, base=16)
52        self.assertEqual(reported_pid, inferior.pid)
53
54    @debugserver_test
55    def test_attach_with_vAttach_debugserver(self):
56        self.init_debugserver_test()
57        self.build()
58        self.set_inferior_startup_attach_manually()
59        self.attach_with_vAttach()
60
61    @expectedFailureNetBSD
62    @llgs_test
63    def test_attach_with_vAttach_llgs(self):
64        self.init_llgs_test()
65        self.build()
66        self.set_inferior_startup_attach_manually()
67        self.attach_with_vAttach()
68