Skip to content

Commit 7d19566

Browse files
committed
[lldb] Ignore non-address bits in "memory find" arguments
This removes the non-address bits before we try to use the addresses. Meaning that when results are shown, those results won't show non-address bits either. This follows what "memory read" has done. On the grounds that non-address bits are a property of a pointer, not the memory pointed to. I've added testing and merged the find and read tests into one file. Note that there are no API side changes because "memory find" does not have an equivalent API call. Reviewed By: omjavaid Differential Revision: https://reviews.llvm.org/D117299
1 parent aa50b93 commit 7d19566

File tree

4 files changed

+46
-8
lines changed

4 files changed

+46
-8
lines changed

lldb/source/Commands/CommandObjectMemory.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,12 @@ class CommandObjectMemoryFind : public CommandObjectParsed {
10321032
return false;
10331033
}
10341034

1035+
ABISP abi = m_exe_ctx.GetProcessPtr()->GetABI();
1036+
if (abi) {
1037+
low_addr = abi->FixDataAddress(low_addr);
1038+
high_addr = abi->FixDataAddress(high_addr);
1039+
}
1040+
10351041
if (high_addr <= low_addr) {
10361042
result.AppendError(
10371043
"starting address must be smaller than ending address");

lldb/test/API/linux/aarch64/tagged_memory_read/TestAArch64LinuxTaggedMemoryRead.py renamed to lldb/test/API/linux/aarch64/tagged_memory_access/TestAArch64LinuxTaggedMemoryAccess.py

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
"""
2-
Test that "memory read" removes non address bits from
3-
memory read arguments.
2+
Test that "memory read" and "memory find" remove non address bits from
3+
address arguments.
4+
5+
These tests use the top byte ignore feature of AArch64. Which Linux
6+
always enables.
47
"""
58

69

@@ -17,10 +20,7 @@ class AArch64LinuxTaggedMemoryReadTestCase(TestBase):
1720

1821
NO_DEBUG_INFO_TESTCASE = True
1922

20-
# AArch64 Linux always enables top byte ignore
21-
@skipUnlessArch("aarch64")
22-
@skipUnlessPlatform(["linux"])
23-
def test_tagged_memory_read(self):
23+
def setup_test(self):
2424
self.build()
2525
self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
2626

@@ -37,6 +37,11 @@ def test_tagged_memory_read(self):
3737
substrs=['stopped',
3838
'stop reason = breakpoint'])
3939

40+
@skipUnlessArch("aarch64")
41+
@skipUnlessPlatform(["linux"])
42+
def test_tagged_memory_read(self):
43+
self.setup_test()
44+
4045
# If we do not remove non address bits, this can fail in two ways.
4146
# 1. We attempt to read much more than 16 bytes, probably more than
4247
# the default 1024 byte read size. Which will error.
@@ -53,3 +58,26 @@ def test_tagged_memory_read(self):
5358
# Would fail if we don't remove non address bits because 0x56... > 0x34...
5459
self.expect("memory read ptr2 ptr1+16", patterns=[tagged_addr_pattern], matching=False)
5560
self.expect("memory read", patterns=[tagged_addr_pattern], matching=False)
61+
62+
@skipUnlessArch("aarch64")
63+
@skipUnlessPlatform(["linux"])
64+
def test_tagged_memory_find(self):
65+
self.setup_test()
66+
67+
# If memory find doesn't remove non-address bits one of two
68+
# things happen.
69+
# 1. It tries to search a gigantic amount of memory.
70+
# We're not going to test for this because a failure
71+
# would take a very long time and perhaps even find the
72+
# target value randomly.
73+
# 2. It thinks high address <= low address, which we check below.
74+
75+
self.runCmd("memory find -s '?' ptr2 ptr1+32")
76+
77+
self.assertTrue(self.res.Succeeded())
78+
out = self.res.GetOutput()
79+
# memory find does not fail when it doesn't find the data.
80+
# First check we actually got something.
81+
self.assertRegexpMatches(out, "data found at location: 0x[0-9A-Fa-f]+")
82+
# Then that the location found does not display the tag bits.
83+
self.assertNotRegexpMatches(out, "data found at location: 0x(34|56)[0-9A-Fa-f]+")

lldb/test/API/linux/aarch64/tagged_memory_read/main.c renamed to lldb/test/API/linux/aarch64/tagged_memory_access/main.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@ static char *set_non_address_bits(char *ptr, size_t tag) {
55
return (char *)((size_t)ptr | (tag << 56));
66
}
77

8-
int main(int argc, char const *argv[]) {
9-
char buf[32];
8+
// Global to zero init
9+
char buf[32];
1010

11+
int main(int argc, char const *argv[]) {
1112
char *ptr1 = set_non_address_bits(buf, 0x34);
1213
char *ptr2 = set_non_address_bits(buf, 0x56);
1314

15+
// Target value for "memory find"
16+
buf[15] = '?';
17+
1418
return 0; // Set break point at this line.
1519
}

0 commit comments

Comments
 (0)