Skip to content

Commit 5a87f39

Browse files
committed
Address PR feedback
1 parent 90b6396 commit 5a87f39

File tree

3 files changed

+24
-23
lines changed

3 files changed

+24
-23
lines changed

lldb/test/API/macosx/mte/TestDarwinMTE.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ def test_memory_read_with_tags(self):
5050
patterns=[r"(.*\(tag: 0x[0-9a-f]\)\n){4}"],
5151
)
5252

53-
def _parse_pointer_tag(self):
54-
return re.search(r"Logical tag: (0x[0-9a-f])", self.res.GetOutput()).group(1)
53+
def _parse_pointer_tag(self, output):
54+
return re.search(r"Logical tag: (0x[0-9a-f])", output).group(1)
5555

56-
def _parse_memory_tags(self, expected_tag_count):
57-
tags = re.findall(r"\): (0x[0-9a-f])", self.res.GetOutput())
56+
def _parse_memory_tags(self, output, expected_tag_count):
57+
tags = re.findall(r"\): (0x[0-9a-f])", output)
5858
self.assertEqual(len(tags), expected_tag_count)
5959
return tags
6060

@@ -77,18 +77,20 @@ def test_memory_tag_read(self):
7777
substrs=["Logical tag: 0x", "Allocation tags:", "(mismatch)"],
7878
patterns=[r"(\[.*\): 0x[0-9a-f].*\n){4}"],
7979
)
80-
self.assertEqual(self.res.GetOutput().count("(mismatch)"), 2)
81-
ptr_tag = self._parse_pointer_tag()
82-
tags = self._parse_memory_tags(4)
80+
output = self.res.GetOutput()
81+
self.assertEqual(output.count("(mismatch)"), 2)
82+
ptr_tag = self._parse_pointer_tag(output)
83+
tags = self._parse_memory_tags(output, 4)
8384
self.assertEqual(tags[1], ptr_tag)
8485
self.assertEqual(tags[2], ptr_tag)
85-
self.assertNotEqual(tags[0], ptr_tag)
86-
self.assertNotEqual(tags[3], ptr_tag)
86+
self.assertNotEqual(tags[0], ptr_tag) # Memory that comes before/after
87+
self.assertNotEqual(tags[3], ptr_tag) # allocation has different tag.
8788

8889
# Continue running until MTE fault
89-
self.runCmd("process continue")
90+
self.expect("process continue", substrs=["stop reason = EXC_ARM_MTE_TAG_FAULT"])
9091

9192
self.runCmd("memory tag read ptr-1 ptr+33")
92-
self.assertEqual(self.res.GetOutput().count("(mismatch)"), 4)
93-
tags = self._parse_memory_tags(4)
93+
output = self.res.GetOutput()
94+
self.assertEqual(output.count("(mismatch)"), 4)
95+
tags = self._parse_memory_tags(output, 4)
9496
self.assertTrue(all(t != ptr_tag for t in tags))

lldb/test/API/macosx/mte/main.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,20 @@
55

66
// Produce some names on the trace
77
const size_t tag_granule = 16;
8-
uint8_t *my_malloc(void) { return malloc(2 * tag_granule); }
9-
uint8_t *allocate(void) { return my_malloc(); }
8+
static uint8_t *my_malloc(void) { return malloc(2 * tag_granule); }
9+
static uint8_t *allocate(void) { return my_malloc(); }
1010

11-
void my_free(void *ptr) { free(ptr); }
12-
void deallocate(void *ptr) { my_free(ptr); }
11+
static void my_free(void *ptr) { free(ptr); }
12+
static void deallocate(void *ptr) { my_free(ptr); }
1313

14-
void touch_memory(uint8_t *ptr) { ptr[7] = 1; } // invalid access
15-
void modify(uint8_t *ptr) { touch_memory(ptr); }
14+
static void touch_memory(uint8_t *ptr) { ptr[7] = 1; } // invalid access
15+
static void modify(uint8_t *ptr) { touch_memory(ptr); }
1616

1717
int main() {
1818
uint8_t *ptr = allocate();
19-
printf("ptr: %p\n", ptr);
2019

21-
strcpy((char *)ptr, "Hello");
22-
strcpy((char *)ptr + 16, "World");
20+
strncpy((char *)ptr, "Hello", 16);
21+
strncpy((char *)ptr + 16, "World", 16);
2322

2423
deallocate(ptr); // before free
2524

lldb/tools/debugserver/source/MacOSX/MachTask.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,15 +213,15 @@
213213
}
214214

215215
//----------------------------------------------------------------------
216-
// MachTask::GetMemoryRegionInfo
216+
// MachTask::MemoryRegionInfo
217217
//----------------------------------------------------------------------
218218
int MachTask::GetMemoryRegionInfo(nub_addr_t addr, DNBRegionInfo *region_info) {
219219
task_t task = TaskPort();
220220
if (task == TASK_NULL)
221221
return -1;
222222

223223
int ret = m_vm_memory.GetMemoryRegionInfo(task, addr, region_info);
224-
DNBLogThreadedIf(LOG_MEMORY, "MachTask::GetMemoryRegionInfo ( addr = 0x%8.8llx "
224+
DNBLogThreadedIf(LOG_MEMORY, "MachTask::MemoryRegionInfo ( addr = 0x%8.8llx "
225225
") => %i (start = 0x%8.8llx, size = 0x%8.8llx, "
226226
"permissions = %u)",
227227
(uint64_t)addr, ret, (uint64_t)region_info->addr,

0 commit comments

Comments
 (0)