]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
x: Print CHERI memory tags using a similar format to MTE.
authorJohn Baldwin <jhb@FreeBSD.org>
Wed, 10 Aug 2022 19:33:07 +0000 (12:33 -0700)
committerJohn Baldwin <jhb@FreeBSD.org>
Thu, 1 Sep 2022 23:47:42 +0000 (16:47 -0700)
gdb/printcmd.c

index 6af7e181ee00c49055ad243e622775f21c65160c..751a43f4d3dbcf5f4907dc4751bc95b0735ba386 100644 (file)
@@ -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");
     }