1import gdbremote_testcase 2import lldbgdbserverutils 3from lldbsuite.test.decorators import * 4from lldbsuite.test.lldbtest import * 5from lldbsuite.test import lldbutil 6 7class TestGdbRemoteAttach(gdbremote_testcase.GdbRemoteTestCaseBase): 8 9 mydir = TestBase.compute_mydir(__file__) 10 11 def test_attach_with_vAttach(self): 12 self.build() 13 self.set_inferior_startup_attach_manually() 14 15 # Start the inferior, start the debug monitor, nothing is attached yet. 16 procs = self.prep_debug_monitor_and_inferior( 17 inferior_args=["sleep:60"]) 18 self.assertIsNotNone(procs) 19 20 # Make sure the target process has been launched. 21 inferior = procs.get("inferior") 22 self.assertIsNotNone(inferior) 23 self.assertTrue(inferior.pid > 0) 24 self.assertTrue( 25 lldbgdbserverutils.process_is_running( 26 inferior.pid, True)) 27 28 # Add attach packets. 29 self.test_sequence.add_log_lines([ 30 # Do the attach. 31 "read packet: $vAttach;{:x}#00".format(inferior.pid), 32 # Expect a stop notification from the attach. 33 {"direction": "send", 34 "regex": r"^\$T([0-9a-fA-F]{2})[^#]*#[0-9a-fA-F]{2}$", 35 "capture": {1: "stop_signal_hex"}}, 36 ], True) 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