12c4226f8SPavel Labathimport gdbremote_testcase 22c4226f8SPavel Labathfrom lldbsuite.test.decorators import * 32c4226f8SPavel Labathfrom lldbsuite.test.lldbtest import * 42c4226f8SPavel Labathfrom lldbsuite.test import lldbutil 52c4226f8SPavel Labath 62c4226f8SPavel Labathsupported_linux_archs = ["x86_64", "i386"] 74e0e79ddSPavel Labathsupported_oses = ["linux", "windows"] + lldbplatformutil.getDarwinOSTriples() 82c4226f8SPavel Labath 92c4226f8SPavel Labath 10*2238dcc3SJonas Devlieghereclass TestGdbRemoteMemoryAllocation(gdbremote_testcase.GdbRemoteTestCaseBase): 112c4226f8SPavel Labath def allocate(self, size, permissions): 12*2238dcc3SJonas Devlieghere self.test_sequence.add_log_lines( 13*2238dcc3SJonas Devlieghere [ 14*2238dcc3SJonas Devlieghere "read packet: $_M{:x},{}#00".format(size, permissions), 15*2238dcc3SJonas Devlieghere { 16*2238dcc3SJonas Devlieghere "direction": "send", 17*2238dcc3SJonas Devlieghere "regex": r"^\$([0-9a-f]+)#[0-9a-fA-F]{2}$", 18*2238dcc3SJonas Devlieghere "capture": {1: "addr"}, 19*2238dcc3SJonas Devlieghere }, 202c4226f8SPavel Labath ], 21*2238dcc3SJonas Devlieghere True, 22*2238dcc3SJonas Devlieghere ) 232c4226f8SPavel Labath context = self.expect_gdbremote_sequence() 242c4226f8SPavel Labath self.assertIsNotNone(context) 252c4226f8SPavel Labath 262c4226f8SPavel Labath addr = int(context.get("addr"), 16) 27*2238dcc3SJonas Devlieghere self.test_sequence.add_log_lines( 28*2238dcc3SJonas Devlieghere [ 29*2238dcc3SJonas Devlieghere "read packet: $qMemoryRegionInfo:{:x}#00".format(addr), 30*2238dcc3SJonas Devlieghere { 31*2238dcc3SJonas Devlieghere "direction": "send", 32*2238dcc3SJonas Devlieghere "regex": r"^\$start:([0-9a-fA-F]+);size:([0-9a-fA-F]+);permissions:([rwx]*);.*#[0-9a-fA-F]{2}$", 33*2238dcc3SJonas Devlieghere "capture": {1: "addr", 2: "size", 3: "permissions"}, 34*2238dcc3SJonas Devlieghere }, 352c4226f8SPavel Labath "read packet: $_m{:x}#00".format(addr), 362c4226f8SPavel Labath "send packet: $OK#00", 372c4226f8SPavel Labath ], 38*2238dcc3SJonas Devlieghere True, 39*2238dcc3SJonas Devlieghere ) 402c4226f8SPavel Labath context = self.expect_gdbremote_sequence() 412c4226f8SPavel Labath self.assertIsNotNone(context) 422c4226f8SPavel Labath 432c4226f8SPavel Labath self.assertEqual(addr, int(context.get("addr"), 16)) 442c4226f8SPavel Labath self.assertLessEqual(size, int(context.get("size"), 16)) 452c4226f8SPavel Labath self.assertEqual(permissions, context.get("permissions")) 462c4226f8SPavel Labath 472c4226f8SPavel Labath @skipIf(oslist=no_match(supported_oses)) 482c4226f8SPavel Labath @skipIf(oslist=["linux"], archs=no_match(supported_linux_archs)) 49*2238dcc3SJonas Devlieghere @expectedFailureDarwin( 50*2238dcc3SJonas Devlieghere archs=["arm64", "arm64e"] 51*2238dcc3SJonas Devlieghere ) # Memory cannot be writable and executable 52*2238dcc3SJonas Devlieghere @expectedFailureAll( 53*2238dcc3SJonas Devlieghere oslist=["windows"] 54*2238dcc3SJonas Devlieghere ) # Memory allocated with incorrect permissions 552c4226f8SPavel Labath def test_supported(self): 562c4226f8SPavel Labath """Make sure (de)allocation works on platforms where it's supposed to 572c4226f8SPavel Labath work""" 582c4226f8SPavel Labath self.build() 592c4226f8SPavel Labath self.set_inferior_startup_launch() 602c4226f8SPavel Labath procs = self.prep_debug_monitor_and_inferior() 612c4226f8SPavel Labath 622c4226f8SPavel Labath self.allocate(0x1000, "r") 632c4226f8SPavel Labath self.allocate(0x2000, "rw") 642c4226f8SPavel Labath self.allocate(0x100, "rx") 652c4226f8SPavel Labath self.allocate(0x1100, "rwx") 662c4226f8SPavel Labath 672c4226f8SPavel Labath @skipIf(oslist=["linux"], archs=supported_linux_archs) 68a1ab2b77SPavel Labath @skipIf(oslist=supported_oses) 692c4226f8SPavel Labath def test_unsupported(self): 702c4226f8SPavel Labath """Make sure we get an "unsupported" error on platforms where the 712c4226f8SPavel Labath feature is not implemented.""" 722c4226f8SPavel Labath 732c4226f8SPavel Labath self.build() 742c4226f8SPavel Labath self.set_inferior_startup_launch() 752c4226f8SPavel Labath procs = self.prep_debug_monitor_and_inferior() 762c4226f8SPavel Labath 77*2238dcc3SJonas Devlieghere self.test_sequence.add_log_lines( 78*2238dcc3SJonas Devlieghere [ 79*2238dcc3SJonas Devlieghere "read packet: $_M1000,rw#00", 802c4226f8SPavel Labath "send packet: $#00", 812c4226f8SPavel Labath ], 82*2238dcc3SJonas Devlieghere True, 83*2238dcc3SJonas Devlieghere ) 842c4226f8SPavel Labath self.expect_gdbremote_sequence() 852c4226f8SPavel Labath 862c4226f8SPavel Labath def test_bad_packet(self): 872c4226f8SPavel Labath """Make sure we get a proper error for malformed packets.""" 882c4226f8SPavel Labath 892c4226f8SPavel Labath self.build() 902c4226f8SPavel Labath self.set_inferior_startup_launch() 912c4226f8SPavel Labath procs = self.prep_debug_monitor_and_inferior() 922c4226f8SPavel Labath 932c4226f8SPavel Labath def e(): 94*2238dcc3SJonas Devlieghere return { 95*2238dcc3SJonas Devlieghere "direction": "send", 96*2238dcc3SJonas Devlieghere "regex": r"^\$E([0-9a-fA-F]+){2}#[0-9a-fA-F]{2}$", 97*2238dcc3SJonas Devlieghere } 982c4226f8SPavel Labath 99*2238dcc3SJonas Devlieghere self.test_sequence.add_log_lines( 100*2238dcc3SJonas Devlieghere [ 101*2238dcc3SJonas Devlieghere "read packet: $_M#00", 102*2238dcc3SJonas Devlieghere e(), 103*2238dcc3SJonas Devlieghere "read packet: $_M1x#00", 104*2238dcc3SJonas Devlieghere e(), 105*2238dcc3SJonas Devlieghere "read packet: $_M1:#00", 106*2238dcc3SJonas Devlieghere e(), 107*2238dcc3SJonas Devlieghere "read packet: $_M1,q#00", 108*2238dcc3SJonas Devlieghere e(), 109*2238dcc3SJonas Devlieghere "read packet: $_m#00", 110*2238dcc3SJonas Devlieghere e(), 111*2238dcc3SJonas Devlieghere ], 112*2238dcc3SJonas Devlieghere True, 113*2238dcc3SJonas Devlieghere ) 1142c4226f8SPavel Labath self.expect_gdbremote_sequence() 115