[PATCH] [GDB,AArch64] Fix off-by-one when calculating tag granules.

Luis Machado luis.machado@linaro.org
Tue May 11 13:20:26 GMT 2021


When we want to fetch tags from a memory range, the last address in that
range is not included.

There is a off-by-one error in aarch64_mte_get_tag_granules, which this
patch fixes.

gdb/ChangeLog:

YYYY-MM-DD  Luis Machado  <luis.machado@linaro.org>

	* arch/aarch64-mte-linux.c (aarch64_mte_get_tag_granules): Don't
	include the last address in the range.
---
 gdb/arch/aarch64-mte-linux.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/gdb/arch/aarch64-mte-linux.c b/gdb/arch/aarch64-mte-linux.c
index 959c0247ed5..7c2ae9a7058 100644
--- a/gdb/arch/aarch64-mte-linux.c
+++ b/gdb/arch/aarch64-mte-linux.c
@@ -31,9 +31,10 @@ aarch64_mte_get_tag_granules (CORE_ADDR addr, size_t len, size_t granule_size)
   /* Start address */
   CORE_ADDR s_addr = align_down (addr, granule_size);
   /* End address */
-  CORE_ADDR e_addr = align_down (addr + len, granule_size);
+  CORE_ADDR e_addr = align_down (addr + len - 1, granule_size);
 
-  /* We always have at least 1 granule.  */
+  /* We always have at least 1 granule because len is non-zero at this
+     point.  */
   return 1 + (e_addr - s_addr) / granule_size;
 }
 
-- 
2.25.1



More information about the Gdb-patches mailing list