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
12class TestUnregisteredMacho(TestBase):
13
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        frame = thread.GetFrameAtIndex(0)
25        macho_buf = frame.GetValueForVariablePath("macho_buf")
26        macho_addr = macho_buf.GetValueAsUnsigned()
27        invalid_macho_addr = macho_buf.GetValueAsUnsigned() + 4
28        gdb_packet = "process plugin packet send 'jGetLoadedDynamicLibrariesInfos:{\"solib_addresses\":[%d]}]'" % macho_addr
29
30        # Send the jGetLoadedDynamicLibrariesInfos packet
31        # to debugserver, asking it to parse the mach-o binary
32        # at this address and give us the UUID etc, even though
33        # dyld doesn't think there is a binary at that address.
34        # We won't get a pathname for the binary (from dyld), but
35        # we will get to the LC_UUID and include that.
36        self.expect (gdb_packet, substrs=['"pathname":""', '"uuid":"1B4E28BA-2FA1-11D2-883F-B9A761BDE3FB"'])
37
38        no_macho_gdb_packet = "process plugin packet send 'jGetLoadedDynamicLibrariesInfos:{\"solib_addresses\":[%d]}]'" % invalid_macho_addr
39        self.expect (no_macho_gdb_packet, substrs=['response: {"images":[]}'])
40
41        # Test that we get back the information for the properly
42        # formatted Mach-O binary in memory, but do not get an
43        # entry for the invalid Mach-O address.
44        both_gdb_packet = "process plugin packet send 'jGetLoadedDynamicLibrariesInfos:{\"solib_addresses\":[%d,%d]}]'" % (macho_addr, invalid_macho_addr)
45        self.expect (both_gdb_packet, substrs=['"load_address":%d,' % macho_addr])
46        self.expect (both_gdb_packet, substrs=['"load_address":%d,' % invalid_macho_addr], matching=False)
47
48