1 2import gdbremote_testcase 3from lldbsuite.test.decorators import * 4from lldbsuite.test.lldbtest import * 5from lldbsuite.test import lldbutil 6 7 8supported_linux_archs = ["x86_64", "i386"] 9supported_oses = ["linux", "windows"] 10 11class TestGdbRemoteMemoryAllocation(gdbremote_testcase.GdbRemoteTestCaseBase): 12 13 mydir = TestBase.compute_mydir(__file__) 14 15 def allocate(self, size, permissions): 16 self.test_sequence.add_log_lines(["read packet: $_M{:x},{}#00".format(size, permissions), 17 {"direction": "send", 18 "regex": 19 r"^\$([0-9a-f]+)#[0-9a-fA-F]{2}$", 20 "capture": { 21 1: "addr"}}, 22 ], 23 True) 24 context = self.expect_gdbremote_sequence() 25 self.assertIsNotNone(context) 26 27 addr = int(context.get("addr"), 16) 28 self.test_sequence.add_log_lines(["read packet: $qMemoryRegionInfo:{:x}#00".format(addr), 29 {"direction": "send", 30 "regex": 31 r"^\$start:([0-9a-fA-F]+);size:([0-9a-fA-F]+);permissions:([rwx]*);.*#[0-9a-fA-F]{2}$", 32 "capture": { 33 1: "addr", 34 2: "size", 35 3: "permissions"}}, 36 "read packet: $_m{:x}#00".format(addr), 37 "send packet: $OK#00", 38 ], 39 True) 40 context = self.expect_gdbremote_sequence() 41 self.assertIsNotNone(context) 42 43 self.assertEqual(addr, int(context.get("addr"), 16)) 44 self.assertLessEqual(size, int(context.get("size"), 16)) 45 self.assertEqual(permissions, context.get("permissions")) 46 47 @skipIf(oslist=no_match(supported_oses)) 48 @skipIf(oslist=["linux"], archs=no_match(supported_linux_archs)) 49 @llgs_test 50 def test_supported(self): 51 """Make sure (de)allocation works on platforms where it's supposed to 52 work""" 53 self.init_llgs_test() 54 self.build() 55 self.set_inferior_startup_launch() 56 procs = self.prep_debug_monitor_and_inferior() 57 58 self.allocate(0x1000, "r") 59 self.allocate(0x2000, "rw") 60 self.allocate(0x100, "rx") 61 self.allocate(0x1100, "rwx") 62 63 @skipIf(oslist=["linux"], archs=supported_linux_archs) 64 @llgs_test 65 def test_unsupported(self): 66 """Make sure we get an "unsupported" error on platforms where the 67 feature is not implemented.""" 68 69 self.init_llgs_test() 70 self.build() 71 self.set_inferior_startup_launch() 72 procs = self.prep_debug_monitor_and_inferior() 73 74 self.test_sequence.add_log_lines(["read packet: $_M1000,rw#00", 75 "send packet: $#00", 76 ], 77 True) 78 self.expect_gdbremote_sequence() 79 80 @llgs_test 81 def test_bad_packet(self): 82 """Make sure we get a proper error for malformed packets.""" 83 84 self.init_llgs_test() 85 self.build() 86 self.set_inferior_startup_launch() 87 procs = self.prep_debug_monitor_and_inferior() 88 89 def e(): 90 return {"direction": "send", 91 "regex": 92 r"^\$E([0-9a-fA-F]+){2}#[0-9a-fA-F]{2}$"} 93 94 self.test_sequence.add_log_lines([ 95 "read packet: $_M#00", e(), 96 "read packet: $_M1x#00", e(), 97 "read packet: $_M1:#00", e(), 98 "read packet: $_M1,q#00", e(), 99 "read packet: $_m#00", e(), 100 ], True) 101 self.expect_gdbremote_sequence() 102