]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[General] More capability type handling (merge with others)
authorLuis Machado <luis.machado@arm.com>
Thu, 2 Jul 2020 19:31:11 +0000 (16:31 -0300)
committerJohn Baldwin <jhb@FreeBSD.org>
Thu, 1 Sep 2022 22:53:22 +0000 (15:53 -0700)
Teach more parts of GDB how to handle capabilities properly, add a function
to print capabilities in their natural format and initialize capability types
properly.

gdb/ChangeLog:

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

* c-typeprint.c (c_type_print_varspec_prefix)
(c_type_print_varspec_suffix): Handle capability type.
* dwarf2/read.c (read_base_type): Call init_capability_type for
capabilities.
* gdbtypes.c (init_capability_type): New function.
(type_align): Handle capability type.
(recursive_dump_type): Likewise.
(arch_capability_type): New function.
(gdbtypes_post_init): Call arch_capability_type for capability
types.
* gdbtypes.h (init_capability_type, arch_capability_type):  New
prototypes.
* valprint.c: Include gdbsupport/capability.h.
(generic_value_print_capability): New function.
(generic_value_print): Handle capability types.

gdb/c-typeprint.c
gdb/dwarf2/read.c
gdb/gdbtypes.c
gdb/gdbtypes.h
gdb/valprint.c

index a16c53b8f44d612407dc5adc52b355333d821171..38f6d7ede9a5c7cabdf45831b75d43fa8759dd5c 100644 (file)
@@ -467,6 +467,7 @@ c_type_print_varspec_prefix (struct type *type,
     case TYPE_CODE_NAMESPACE:
     case TYPE_CODE_DECFLOAT:
     case TYPE_CODE_FIXED_POINT:
+    case TYPE_CODE_CAPABILITY:
       /* These types need no prefix.  They are listed here so that
         gcc -Wall will reveal any types that haven't been handled.  */
       break;
@@ -856,6 +857,7 @@ c_type_print_varspec_suffix (struct type *type,
     case TYPE_CODE_NAMESPACE:
     case TYPE_CODE_DECFLOAT:
     case TYPE_CODE_FIXED_POINT:
+    case TYPE_CODE_CAPABILITY:
       /* These types do not need a suffix.  They are listed so that
         gcc -Wall will report types that may not have been
         considered.  */
index 139fee4685e26c9605314825006f3798ccb34893..7cb63053c25f0c3669222b36c8b34711bfa15c3e 100644 (file)
@@ -18285,13 +18285,11 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
        break;
 
       case DW_ATE_CHERI_signed_intcap:
+         type = init_capability_type (objfile, bits, false, name);
+         break;
       case DW_ATE_CHERI_unsigned_intcap:
-       {
-         /* Turn DW_ATE_CHERI_*_intcap into a void * pointer.  */
-         type = init_type (objfile, TYPE_CODE_VOID, TARGET_CHAR_BIT, NULL);
-         type = init_pointer_type (objfile, bits, name, type);
+         type = init_capability_type (objfile, bits, true, name);
          break;
-       }
 
       default:
        complaint (_("unsupported DW_AT_encoding: '%s'"),
index 83b1c28af4623e23ee4df1d15e14a268fd989070..d42d9eda5028c840c90ceaff59e525d3b929754d 100644 (file)
@@ -3521,6 +3521,22 @@ init_fixed_point_type (struct objfile *objfile,
   return t;
 }
 
+/* Allocate a TYPE_CODE_CAPABILITY type structure associated with OBJFILE.
+   BIT is the type size in bits.  If UNSIGNED_P is non-zero, set
+   the type's TYPE_UNSIGNED flag.  NAME is the type name.  */
+
+struct type *
+init_capability_type (struct objfile *objfile,
+                     int bit, bool unsigned_p, const char *name)
+{
+  struct type *t;
+
+  t = init_type (objfile, TYPE_CODE_CAPABILITY, bit, name);
+  t->set_is_unsigned (unsigned_p);
+
+  return t;
+}
+
 /* See gdbtypes.h.  */
 
 unsigned
@@ -3549,6 +3565,7 @@ type_align (struct type *type)
   switch (type->code ())
     {
     case TYPE_CODE_PTR:
+    case TYPE_CODE_CAPABILITY:
     case TYPE_CODE_FUNC:
     case TYPE_CODE_FLAGS:
     case TYPE_CODE_INT:
@@ -5237,6 +5254,9 @@ recursive_dump_type (struct type *type, int spaces)
     case TYPE_CODE_FIXED_POINT:
       printf_filtered ("(TYPE_CODE_FIXED_POINT)");
       break;
+    case TYPE_CODE_CAPABILITY:
+      printf_filtered ("(TYPE_CODE_CAPABILITY)");
+      break;
     default:
       printf_filtered ("(UNKNOWN TYPE CODE)");
       break;
@@ -5840,6 +5860,21 @@ arch_pointer_type (struct gdbarch *gdbarch,
   return t;
 }
 
+/* Allocate a TYPE_CODE_CAPABILITY type structure associated with GDBARCH.
+   BIT is the type size in bits.  If UNSIGNED_P is non-zero, set
+   the type's TYPE_UNSIGNED flag.  NAME is the type name.  */
+
+struct type *
+arch_capability_type (struct gdbarch *gdbarch,
+                     int bit, bool unsigned_p, const char *name)
+{
+  struct type *t;
+
+  t = arch_type (gdbarch, TYPE_CODE_CAPABILITY, bit, name);
+  t->set_is_unsigned (unsigned_p);
+  return t;
+}
+
 /* Allocate a TYPE_CODE_FLAGS type structure associated with GDBARCH.
    NAME is the type name.  BIT is the size of the flag word in bits.  */
 
@@ -6204,9 +6239,9 @@ gdbtypes_post_init (struct gdbarch *gdbarch)
 
   /* Capability types.  */
   builtin_type->builtin_intcap_t
-    = arch_integer_type (gdbarch, 128, 0, "__intcap_t");
+    = arch_capability_type (gdbarch, 128, 0, "__intcap_t");
   builtin_type->builtin_uintcap_t
-    = arch_integer_type (gdbarch, 128, 1, "__uintcap_t");
+    = arch_capability_type (gdbarch, 128, 1, "__uintcap_t");
 
   /* Capability pointer types.  */
   builtin_type->builtin_data_addr_capability
index d434413f71d37b24b48da808d01c9196349b517c..d7c2199585dadf3762ecf90cc83d8099408cf000 100644 (file)
@@ -2498,6 +2498,8 @@ extern struct type *init_pointer_type (struct objfile *, int, const char *,
                                       struct type *);
 extern struct type *init_fixed_point_type (struct objfile *, int, int,
                                           const char *);
+extern struct type *init_capability_type (struct objfile *objfile, int bit,
+                                         bool unsigned_p, const char *name);
 
 /* Helper functions to construct architecture-owned types.  */
 extern struct type *arch_type (struct gdbarch *, enum type_code, int,
@@ -2513,6 +2515,8 @@ extern struct type *arch_float_type (struct gdbarch *, int, const char *,
 extern struct type *arch_decfloat_type (struct gdbarch *, int, const char *);
 extern struct type *arch_pointer_type (struct gdbarch *, int, const char *,
                                       struct type *);
+extern struct type *arch_capability_type (struct gdbarch *gdbarch, int bit,
+                                         bool unsigned_p, const char *name);
 
 /* Helper functions to construct a struct or record type.  An
    initially empty type is created using arch_composite_type().
index c2ffe6224bf79919eff439f2770056e0d17636aa..01a4a12b52159eca1611c385be5f18dd6ac5c4d2 100644 (file)
@@ -46,6 +46,8 @@
 #include "gdbsupport/selftest.h"
 #include "selftest-arch.h"
 
+#include "gdbsupport/capability.h"
+
 /* Maximum number of wchars returned from wchar_iterate.  */
 #define MAX_WCHARS 4
 
@@ -491,6 +493,29 @@ generic_value_print_ptr (struct value *val, struct ui_file *stream,
     }
 }
 
+/* generic_value_print helper for TYPE_CODE_CAPABILITY.  */
+
+static void
+generic_value_print_capability (struct value *val, struct ui_file *stream,
+                               const struct value_print_options *options)
+{
+  struct type *type = check_typedef (value_type (val));
+  int length = TYPE_LENGTH (type);
+  const gdb_byte *contents = value_contents_for_printing (val).data ();
+  enum bfd_endian byte_order = type_byte_order (type);
+
+  if (options->format && options->format == 'x')
+      print_hex_chars (stream, contents, length, byte_order, 0);
+  else
+    {
+      uint128_t dummy_cap;
+      memcpy (&dummy_cap, contents, length);
+      capability cap (dummy_cap, false);
+      fprintf_filtered (stream, "%s", cap.to_str ().c_str ());
+    }
+
+  return;
+}
 
 /* Print '@' followed by the address contained in ADDRESS_BUFFER.  */
 
@@ -911,6 +936,10 @@ generic_value_print (struct value *val, struct ui_file *stream, int recurse,
       generic_value_print_ptr (val, stream, options);
       break;
 
+    case TYPE_CODE_CAPABILITY:
+      generic_value_print_capability (val, stream, options);
+      break;
+
     case TYPE_CODE_REF:
     case TYPE_CODE_RVALUE_REF:
       generic_val_print_ref (type, 0, stream, recurse,