[lldb][AArch64] Correct top nibble setting in memory tag read tests
authorDavid Spickett <david.spickett@linaro.org>
Wed, 12 Jan 2022 12:17:52 +0000 (12:17 +0000)
committerDavid Spickett <david.spickett@linaro.org>
Wed, 12 Jan 2022 12:28:13 +0000 (12:28 +0000)
Due to a missing cast the << 60 always resulted in zero leaving
the top nibble empty. So we weren't actually testing that lldb
ignores those bits in addition to the tag bits.

Correct that and also set the top nibbles to ascending values
so that we can catch if lldb only removes one of the tag bits
and top nibble, but not both.

In future the tag manager will likely only remove the tag bits
and leave non-address bits to the ABI plugin but for now make
sure we're testing what we claim to implement.

lldb/test/API/linux/aarch64/mte_tag_access/TestAArch64LinuxMTEMemoryTagAccess.py
lldb/test/API/linux/aarch64/mte_tag_access/main.c

index b0ce9c1..29c19aa 100644 (file)
@@ -122,10 +122,11 @@ class AArch64LinuxMTEMemoryTagAccessTestCase(TestBase):
                           "\[0x[0-9A-Fa-f]+f0, 0x[0-9A-Fa-f]+00\): 0xf \(mismatch\)\n"
                           "\[0x[0-9A-Fa-f]+00, 0x[0-9A-Fa-f]+10\): 0x0 \(mismatch\)$"])
 
-        # Tags in start/end are ignored when creating the range.
-        # So this is not an error despite start/end having different tags
-        self.expect("memory tag read mte_buf mte_buf_alt_tag+16",
-                patterns=["Logical tag: 0x9\n"
+        # Top byte is ignored when creating the range, not just the 4 tag bits.
+        # So even though these two pointers have different top bytes
+        # and the start's is > the end's, this is not an error.
+        self.expect("memory tag read mte_buf_alt_tag mte_buf+16",
+                patterns=["Logical tag: 0xa\n"
                           "Allocation tags:\n"
                           "\[0x[0-9A-Fa-f]+00, 0x[0-9A-Fa-f]+10\): 0x0 \(mismatch\)$"])
 
index ecafe3a..493733d 100644 (file)
@@ -67,16 +67,20 @@ int main(int argc, char const *argv[]) {
 
   // Tag the original pointer with 9
   mte_buf = __arm_mte_create_random_tag(mte_buf, ~(1 << 9));
-  // A different tag so that buf_alt_tag > buf if you don't handle the tag
+  // A different tag so that mte_buf_alt_tag > mte_buf if you don't handle the
+  // tag
   char *mte_buf_alt_tag = __arm_mte_create_random_tag(mte_buf, ~(1 << 10));
 
   // lldb should be removing the whole top byte, not just the tags.
   // So fill 63-60 with something non zero so we'll fail if we only remove tags.
-#define SET_TOP_NIBBLE(ptr) (char *)((size_t)(ptr) | (0xA << 60))
-  mte_buf = SET_TOP_NIBBLE(mte_buf);
-  mte_buf_alt_tag = SET_TOP_NIBBLE(mte_buf_alt_tag);
-  mte_buf_2 = SET_TOP_NIBBLE(mte_buf_2);
-  mte_read_only = SET_TOP_NIBBLE(mte_read_only);
+#define SET_TOP_NIBBLE(ptr, value)                                             \
+  (char *)((size_t)(ptr) | ((size_t)((value)&0xf) << 60))
+  // mte_buf_alt_tag's nibble > mte_buf to check that lldb isn't just removing
+  // tag bits but the whole top byte when making ranges.
+  mte_buf = SET_TOP_NIBBLE(mte_buf, 0xA);
+  mte_buf_alt_tag = SET_TOP_NIBBLE(mte_buf_alt_tag, 0xB);
+  mte_buf_2 = SET_TOP_NIBBLE(mte_buf_2, 0xC);
+  mte_read_only = SET_TOP_NIBBLE(mte_read_only, 0xD);
 
   // Breakpoint here
   return 0;