]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Print capability pointers as capabilities
authorLuis Machado <luis.machado@arm.com>
Thu, 5 Nov 2020 19:18:18 +0000 (16:18 -0300)
committerJohn Baldwin <jhb@FreeBSD.org>
Thu, 1 Sep 2022 22:53:23 +0000 (15:53 -0700)
Print capability pointers as capabilities, so the user can see the
decoded fields of the capability.

gdb/ChangeLog:

2020-11-11  Luis Machado  <luis.machado@arm.com>

* c-valprint.c (c_value_print_ptr): Adjust to print capability
pointers as capabilities.
(c_value_print_inner): Handle TYPE_CODE_CAPABILITY.
* findvar.c (extract_integer): Truncate scalars instead of erroring out.
* valprint.c (generic_value_print_capability): Make non-static and
print additional space.
* valprint.h (generic_value_print_capability): New prototype.

gdb/c-valprint.c
gdb/findvar.c
gdb/valprint.c
gdb/valprint.h

index 0d30700c06d17f68ccbb3389b648834f68659df5..46187f5a52bf03c133de8b797580b76e7c0121dd 100644 (file)
@@ -326,13 +326,19 @@ static void
 c_value_print_ptr (struct value *val, struct ui_file *stream, int recurse,
                   const struct value_print_options *options)
 {
+  struct type *type = check_typedef (value_type (val));
+
+  /* If we have a pointer to a capability, handle it as a capability.  */
+  if (options->format == 0 && (type->code () == TYPE_CODE_PTR
+                             && TYPE_CAPABILITY (type)))
+    generic_value_print_capability (val, stream, options);
+
   if (options->format && options->format != 's')
     {
       value_print_scalar_formatted (val, options, 0, stream);
       return;
     }
 
-  struct type *type = check_typedef (value_type (val));
   const gdb_byte *valaddr = value_contents_for_printing (val).data ();
 
   if (options->vtblprint && cp_is_vtbl_ptr_type (type))
@@ -460,6 +466,7 @@ c_value_print_inner (struct value *val, struct ui_file *stream, int recurse,
     case TYPE_CODE_ERROR:
     case TYPE_CODE_UNDEF:
     case TYPE_CODE_COMPLEX:
+    case TYPE_CODE_CAPABILITY:
     default:
       generic_value_print (val, stream, recurse, options, &c_decorations);
       break;
index 6660b00679578d5472fa8beec145b877d4cafe1c..7ac62e75ad0b5a6541e2c9997fd1a93c6885eaee 100644 (file)
 
 /* Basic byte-swapping routines.  All 'extract' functions return a
    host-format integer from a target-format integer at ADDR which is
-   LEN bytes long.  */
+   LEN bytes long.
+
+   FIXME-Morello: This is a temporary hack to address GDB's inability to cope
+   with 128-bit scalar types.  Instead of erroring out and giving up, just
+   truncate the scalar to the size of T.  */
 
 #if TARGET_CHAR_BIT != 8 || HOST_CHAR_BIT != 8
   /* 8 bit characters are a pretty safe assumption these days, so we
@@ -51,11 +55,7 @@ T
 extract_integer (gdb::array_view<const gdb_byte> buf, enum bfd_endian byte_order)
 {
   typename std::make_unsigned<T>::type retval = 0;
-
-  if (buf.size () > (int) sizeof (T))
-    error (_("\
-That operation is not available on integers of more than %d bytes."),
-          (int) sizeof (T));
+  size_t len = (buf.size () > sizeof (T)) ? sizeof (T) : buf.size ();
 
   /* Start at the most significant end of the integer, and work towards
      the least significant.  */
@@ -69,12 +69,12 @@ That operation is not available on integers of more than %d bytes."),
          retval = ((LONGEST) buf[i] ^ 0x80) - 0x80;
          ++i;
        }
-      for (; i < buf.size (); ++i)
+      for (; i < len; ++i)
        retval = (retval << 8) | buf[i];
     }
   else
     {
-      ssize_t i = buf.size () - 1;
+      ssize_t i = len - 1;
 
       if (std::is_signed<T>::value)
        {
index 5ee5a71af359635f8391c06965f3121a83c4f640..d7993f39edf8d0426ad65b2fe681346c28a887f8 100644 (file)
@@ -495,7 +495,7 @@ generic_value_print_ptr (struct value *val, struct ui_file *stream,
 
 /* generic_value_print helper for TYPE_CODE_CAPABILITY.  */
 
-static void
+void
 generic_value_print_capability (struct value *val, struct ui_file *stream,
                                const struct value_print_options *options)
 {
@@ -528,7 +528,7 @@ generic_value_print_capability (struct value *val, struct ui_file *stream,
       uint128_t dummy_cap;
       memcpy (&dummy_cap, contents, length);
       capability cap (dummy_cap, tag);
-      fprintf_filtered (stream, "%s", cap.to_str (true).c_str ());
+      fprintf_filtered (stream, "%s ", cap.to_str (true).c_str ());
     }
 
   return;
index 0586836f9e6d68c48f1ad198125f4d5dc7be0750..f81cabb727d8e81afe33791486cdad124d0712e0 100644 (file)
@@ -242,6 +242,10 @@ extern void generic_printstr (struct ui_file *stream, struct type *type,
                              int quote_char, int c_style_terminator,
                              const struct value_print_options *options);
 
+extern void generic_value_print_capability (struct value *val,
+                                          struct ui_file *stream,
+                                          const struct value_print_options *options);
+
 /* Run the "output" command.  ARGS and FROM_TTY are the usual
    arguments passed to all command implementations, except ARGS is
    const.  */