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 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( 15 inferior_args=["sleep:60"]) 16 self.assertIsNotNone(procs) 17 18 # Make sure the target process has been launched. 19 inferior = procs.get("inferior") 20 self.assertIsNotNone(inferior) 21 self.assertTrue(inferior.pid > 0) 22 self.assertTrue( 23 lldbgdbserverutils.process_is_running( 24 inferior.pid, True)) 25 26 # Add attach packets. 27 self.test_sequence.add_log_lines([ 28 # Do the attach. 29 "read packet: $vAttach;{:x}#00".format(inferior.pid), 30 # Expect a stop notification from the attach. 31 {"direction": "send", 32 "regex": r"^\$T([0-9a-fA-F]{2})[^#]*#[0-9a-fA-F]{2}$", 33 "capture": {1: "stop_signal_hex"}}, 34 ], True) 35 self.add_process_info_collection_packets() 36 37 # Run the stream 38 context = self.expect_gdbremote_sequence() 39 self.assertIsNotNone(context) 40 41 # Gather process info response 42 process_info = self.parse_process_info_response(context) 43 self.assertIsNotNone(process_info) 44 45 # Ensure the process id matches what we expected. 46 pid_text = process_info.get('pid', None) 47 self.assertIsNotNone(pid_text) 48 reported_pid = int(pid_text, base=16) 49 self.assertEqual(reported_pid, inferior.pid) 50