summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Baldwin <jhb@FreeBSD.org>2022-08-10 12:33:07 -0700
committerJohn Baldwin <jhb@FreeBSD.org>2022-09-01 16:47:42 -0700
commitc4b319952eab99f83d25fc63e5e90c85d12d4607 (patch)
tree8b70688ba951cf9449f2709bce7f68c85a0fb65e
parent085e57a4449252928d3d70bf1fe63e508b594636 (diff)
downloadbinutils-gdb-c4b319952eab99f83d25fc63e5e90c85d12d4607.tar.gz
x: Print CHERI memory tags using a similar format to MTE.
-rw-r--r--gdb/printcmd.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 6af7e181ee0..751a43f4d3d 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -1110,6 +1110,10 @@ do_examine (struct format_data fmt, struct gdbarch *gdbarch, CORE_ADDR addr)
bool print_range_tag = true;
uint32_t gsize = gdbarch_memtag_granule_size (gdbarch);
+ /* Memory tag information for CHERI tags. */
+ bool print_cheri_tag = true;
+ uint32_t cap_size = gdbarch_capability_bit (gdbarch) / TARGET_CHAR_BIT;
+
/* Print as many objects as specified in COUNT, at most maxelts per line,
with the address of the next one at the start of each line. */
@@ -1149,6 +1153,23 @@ do_examine (struct format_data fmt, struct gdbarch *gdbarch, CORE_ADDR addr)
print_range_tag = false;
}
+ CORE_ADDR cap_haddr = 0;
+
+ /* Print CHERI capability tags if requested. */
+ if (fmt.print_tags && print_cheri_tag && cap_size != 0)
+ {
+ CORE_ADDR cap_laddr = align_down (next_address, cap_size);
+ cap_haddr = cap_laddr + cap_size;
+
+ gdb::byte_vector cap = target_read_capability (cap_laddr);
+ if (cap.size () != 0)
+ printf_filtered (_("<CHERI Tag %u for range [%s,%s)>\n"),
+ cap[0] != 0,
+ paddress (gdbarch, cap_laddr),
+ paddress (gdbarch, cap_haddr));
+ print_cheri_tag = false;
+ }
+
if (format == 'i')
puts_filtered (pc_prefix (next_address));
print_address (next_gdbarch, next_address, gdb_stdout);
@@ -1184,6 +1205,9 @@ do_examine (struct format_data fmt, struct gdbarch *gdbarch, CORE_ADDR addr)
processed. */
if (tag_haddr <= next_address)
print_range_tag = true;
+
+ if (cap_haddr <= next_address)
+ print_cheri_tag = true;
}
printf_filtered ("\n");
}