63 lines · python
1"""Test that debugserver will parse a mach-o in inferior memory even if it's not loaded."""2 3import os4import re5import subprocess6 7import lldb8from lldbsuite.test.decorators import *9from lldbsuite.test.lldbtest import *10from lldbsuite.test import lldbutil11 12 13class TestUnregisteredMacho(TestBase):14 # newer debugserver required for jGetLoadedDynamicLibrariesInfos15 # to support this16 @no_debug_info_test17 @skipUnlessDarwin18 def test(self):19 self.build()20 target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(21 self, "// break here", lldb.SBFileSpec("main.c")22 )23 24 frame = thread.GetFrameAtIndex(0)25 macho_buf = frame.GetValueForVariablePath("macho_buf")26 macho_addr = macho_buf.GetValueAsUnsigned()27 invalid_macho_addr = macho_buf.GetValueAsUnsigned() + 428 gdb_packet = (29 "process plugin packet send 'jGetLoadedDynamicLibrariesInfos:{\"solib_addresses\":[%d]}]'"30 % macho_addr31 )32 33 # Send the jGetLoadedDynamicLibrariesInfos packet34 # to debugserver, asking it to parse the mach-o binary35 # at this address and give us the UUID etc, even though36 # dyld doesn't think there is a binary at that address.37 # We won't get a pathname for the binary (from dyld), but38 # we will get to the LC_UUID and include that.39 self.expect(40 gdb_packet,41 substrs=['"pathname":""', '"uuid":"1B4E28BA-2FA1-11D2-883F-B9A761BDE3FB"'],42 )43 44 no_macho_gdb_packet = (45 "process plugin packet send 'jGetLoadedDynamicLibrariesInfos:{\"solib_addresses\":[%d]}]'"46 % invalid_macho_addr47 )48 self.expect(no_macho_gdb_packet, substrs=['response: {"images":[]}'])49 50 # Test that we get back the information for the properly51 # formatted Mach-O binary in memory, but do not get an52 # entry for the invalid Mach-O address.53 both_gdb_packet = (54 "process plugin packet send 'jGetLoadedDynamicLibrariesInfos:{\"solib_addresses\":[%d,%d]}]'"55 % (macho_addr, invalid_macho_addr)56 )57 self.expect(both_gdb_packet, substrs=['"load_address":%d,' % macho_addr])58 self.expect(59 both_gdb_packet,60 substrs=['"load_address":%d,' % invalid_macho_addr],61 matching=False,62 )63