1"""Test that debugserver will parse a mach-o in inferior memory even if it's not loaded.""" 2 3import os 4import re 5import subprocess 6 7import lldb 8from lldbsuite.test.decorators import * 9from lldbsuite.test.lldbtest import * 10from lldbsuite.test import lldbutil 11 12 13class TestUnregisteredMacho(TestBase): 14 # newer debugserver required for jGetLoadedDynamicLibrariesInfos 15 # to support this 16 @skipIfOutOfTreeDebugserver 17 @no_debug_info_test 18 @skipUnlessDarwin 19 def test(self): 20 self.build() 21 target, process, thread, bkpt = lldbutil.run_to_source_breakpoint( 22 self, "// break here", lldb.SBFileSpec("main.c") 23 ) 24 25 frame = thread.GetFrameAtIndex(0) 26 macho_buf = frame.GetValueForVariablePath("macho_buf") 27 macho_addr = macho_buf.GetValueAsUnsigned() 28 invalid_macho_addr = macho_buf.GetValueAsUnsigned() + 4 29 gdb_packet = ( 30 "process plugin packet send 'jGetLoadedDynamicLibrariesInfos:{\"solib_addresses\":[%d]}]'" 31 % macho_addr 32 ) 33 34 # Send the jGetLoadedDynamicLibrariesInfos packet 35 # to debugserver, asking it to parse the mach-o binary 36 # at this address and give us the UUID etc, even though 37 # dyld doesn't think there is a binary at that address. 38 # We won't get a pathname for the binary (from dyld), but 39 # we will get to the LC_UUID and include that. 40 self.expect( 41 gdb_packet, 42 substrs=['"pathname":""', '"uuid":"1B4E28BA-2FA1-11D2-883F-B9A761BDE3FB"'], 43 ) 44 45 no_macho_gdb_packet = ( 46 "process plugin packet send 'jGetLoadedDynamicLibrariesInfos:{\"solib_addresses\":[%d]}]'" 47 % invalid_macho_addr 48 ) 49 self.expect(no_macho_gdb_packet, substrs=['response: {"images":[]}']) 50 51 # Test that we get back the information for the properly 52 # formatted Mach-O binary in memory, but do not get an 53 # entry for the invalid Mach-O address. 54 both_gdb_packet = ( 55 "process plugin packet send 'jGetLoadedDynamicLibrariesInfos:{\"solib_addresses\":[%d,%d]}]'" 56 % (macho_addr, invalid_macho_addr) 57 ) 58 self.expect(both_gdb_packet, substrs=['"load_address":%d,' % macho_addr]) 59 self.expect( 60 both_gdb_packet, 61 substrs=['"load_address":%d,' % invalid_macho_addr], 62 matching=False, 63 ) 64