]> 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)
committerLuis Machado <luis.machado@linaro.org>
Tue, 8 Dec 2020 18:02:58 +0000 (15:02 -0300)
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/ChangeLog
gdb/c-valprint.c
gdb/findvar.c
gdb/valprint.c
gdb/valprint.h

index bf9ed064c910d6617f905a0c0abc4656d1bded69..49963f5e74ab5d66d5da50252b75a7fec5350de9 100644 (file)
@@ -1,3 +1,13 @@
+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.
+
 2020-11-11  Luis Machado  <luis.machado@arm.com>
 
        * valprint.c (generic_value_print_capability): Use compact form.
index 01b1071cb70878dc727a3bff70a170c31d03fc0e..89d4a7e3e181babc6fa8daf81d53692eaefb916c 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));
   struct gdbarch *arch = get_type_arch (type);
   const gdb_byte *valaddr = value_contents_for_printing (val);
 
@@ -461,6 +467,7 @@ c_value_print_inner (struct value *val, struct ui_file *stream, int recurse,
     case TYPE_CODE_UNDEF:
     case TYPE_CODE_COMPLEX:
     case TYPE_CODE_CHAR:
+    case TYPE_CODE_CAPABILITY:
     default:
       generic_value_print (val, stream, recurse, options, &c_decorations);
       break;
index 5c3a8848a5b749f3b37b210d40bfd64f152a5fe5..18ae8e2ffb4c01913b3d519c3c84e09f0c67150a 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
@@ -53,18 +57,14 @@ extract_integer (const gdb_byte *addr, int len, enum bfd_endian byte_order)
   typename std::make_unsigned<T>::type retval = 0;
   const unsigned char *p;
   const unsigned char *startaddr = addr;
+  size_t max_len = (len > sizeof (T))? sizeof (T) : len;
   const unsigned char *endaddr = startaddr + len;
 
-  if (len > (int) sizeof (T))
-    error (_("\
-That operation is not available on integers of more than %d bytes."),
-          (int) sizeof (T));
-
   /* Start at the most significant end of the integer, and work towards
      the least significant.  */
   if (byte_order == BFD_ENDIAN_BIG)
     {
-      p = startaddr;
+      p = endaddr - max_len;
       if (std::is_signed<T>::value)
        {
          /* Do the sign extension once at the start.  */
@@ -76,7 +76,7 @@ That operation is not available on integers of more than %d bytes."),
     }
   else
     {
-      p = endaddr - 1;
+      p = startaddr + max_len - 1;
       if (std::is_signed<T>::value)
        {
          /* Do the sign extension once at the start.  */
index 7e3170083603fa07c4d5e095d2013e30d2efda8c..b28d987e9c2e5be8d752131a174742561e111475 100644 (file)
@@ -480,7 +480,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)
 {
@@ -513,7 +513,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 489d14ba0e908f1c661ad9f0561d95d03e8b9325..ff7be2b6cf90ef30b5238d803fb176a2526fea97 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.  */