[Lldb-commits] [lldb] [lldb] Ignore the top byte in address_ranges_helper.py (PR #185802)

via lldb-commits lldb-commits at lists.llvm.org
Tue Mar 10 21:58:54 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: Jonas Devlieghere (JDevlieghere)

<details>
<summary>Changes</summary>

Update address_ranges_helper.py to work when running under ARM's Memory Tagging Extension (MTE), which relies on Top Byte Ignore (TBI) to store a tag in the most significant part of the address. The helper was doing pointer arithmetic on addresses, which requires stripping the top byte.

This fixes TestFindInMemory.py and TestFindRangesInMemory.py when running the LLDB test suite with MTE.

---
Full diff: https://github.com/llvm/llvm-project/pull/185802.diff


1 Files Affected:

- (modified) lldb/test/API/python_api/find_in_memory/address_ranges_helper.py (+12-7) 


``````````diff
diff --git a/lldb/test/API/python_api/find_in_memory/address_ranges_helper.py b/lldb/test/API/python_api/find_in_memory/address_ranges_helper.py
index 102f2b0edd4c6..fb2753731b162 100644
--- a/lldb/test/API/python_api/find_in_memory/address_ranges_helper.py
+++ b/lldb/test/API/python_api/find_in_memory/address_ranges_helper.py
@@ -5,6 +5,12 @@
 ALIGNED_INSTANCE_PATTERN_HEAP = "i_am_unaligned_string_on_the_heap"
 UNALIGNED_INSTANCE_PATTERN_HEAP = ALIGNED_INSTANCE_PATTERN_HEAP[1:]
 
+TBI_MASK = 0xFF00000000000000
+
+
+def strip_tbi(addr):
+    return addr & ~TBI_MASK
+
 
 def GetAlignedRange(test_base, shrink=False):
     frame = test_base.thread.GetSelectedFrame()
@@ -31,21 +37,20 @@ def GetRangeFromAddrValue(test_base, addr, shrink=False):
     If 'shrink' is True, the address range will be reduced to not exceed 2K.
     """
     region = lldb.SBMemoryRegionInfo()
+    addr_val = strip_tbi(addr.GetValueAsUnsigned())
     test_base.assertTrue(
-        test_base.process.GetMemoryRegionInfo(
-            addr.GetValueAsUnsigned(), region
-        ).Success(),
+        test_base.process.GetMemoryRegionInfo(addr_val, region).Success(),
     )
 
     test_base.assertTrue(region.IsReadable())
     test_base.assertFalse(region.IsExecutable())
 
-    base = region.GetRegionBase()
-    end = region.GetRegionEnd()
+    base = strip_tbi(region.GetRegionBase())
+    end = strip_tbi(region.GetRegionEnd())
 
     if shrink:
-        addr2 = addr.GetValueAsUnsigned()
-        addr2 -= addr2 % 512
+        addr2 = addr_val
+        addr2 -= addr_val % 512
         base = max(base, addr2 - 1024)
         end = min(end, addr2 + 1024)
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/185802


More information about the lldb-commits mailing list