def module_info(self): procs = self.prep_debug_monitor_and_inferior() self.add_process_info_collection_packets() context = self.expect_gdbremote_sequence() info = self.parse_process_info_response(context) self.test_sequence.add_log_lines([ 'read packet: $jModulesInfo:%s]#00' % json.dumps([{ "file": lldbutil.append_to_process_working_directory(self, "a.out"), "triple": seven.unhexlify(info["triple"]) }]), { "direction": "send", "regex": r'^\$\[{(.*)}\]\]#[0-9A-Fa-f]{2}', "capture": { 1: "spec" } }, ], True) context = self.expect_gdbremote_sequence() spec = context.get("spec") self.assertRegexpMatches(spec, '"file_path":".*"') self.assertRegexpMatches(spec, '"file_offset":\d+') self.assertRegexpMatches(spec, '"file_size":\d+') self.assertRegexpMatches(spec, '"triple":"\w*-\w*-.*"') self.assertRegexpMatches(spec, '"uuid":"[A-Fa-f0-9]+"')
def _handle_output_packet_string(packet_contents): if (not packet_contents) or (len(packet_contents) < 1): return None elif packet_contents[0] != "O": return None elif packet_contents == "OK": return None else: return seven.unhexlify(packet_contents[1:])
def test_m_packet_reads_memory(self): self.build() self.set_inferior_startup_launch() # This is the memory we will write into the inferior and then ensure we # can read back with $m. MEMORY_CONTENTS = "Test contents 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz" # Start up the inferior. procs = self.prep_debug_monitor_and_inferior( inferior_args=[ "set-message:%s" % MEMORY_CONTENTS, "get-data-address-hex:g_message", "sleep:5"]) # Run the process self.test_sequence.add_log_lines( [ # Start running after initial stop. "read packet: $c#63", # Match output line that prints the memory address of the message buffer within the inferior. # Note we require launch-only testing so we can get inferior otuput. {"type": "output_match", "regex": self.maybe_strict_output_regex(r"data address: 0x([0-9a-fA-F]+)\r\n"), "capture": {1: "message_address"}}, # Now stop the inferior. "read packet: {}".format(chr(3)), # And wait for the stop notification. {"direction": "send", "regex": r"^\$T([0-9a-fA-F]{2})thread:([0-9a-fA-F]+);", "capture": {1: "stop_signo", 2: "stop_thread_id"}}], True) # Run the packet stream. context = self.expect_gdbremote_sequence() self.assertIsNotNone(context) # Grab the message address. self.assertIsNotNone(context.get("message_address")) message_address = int(context.get("message_address"), 16) # Grab contents from the inferior. self.reset_test_sequence() self.test_sequence.add_log_lines( ["read packet: $m{0:x},{1:x}#00".format(message_address, len(MEMORY_CONTENTS)), {"direction": "send", "regex": r"^\$(.+)#[0-9a-fA-F]{2}$", "capture": {1: "read_contents"}}], True) # Run the packet stream. context = self.expect_gdbremote_sequence() self.assertIsNotNone(context) # Ensure what we read from inferior memory is what we wrote. self.assertIsNotNone(context.get("read_contents")) read_contents = seven.unhexlify(context.get("read_contents")) self.assertEqual(read_contents, MEMORY_CONTENTS)