From f17f05b79401f03acebe6983d0a9ce06a95cdbcc Mon Sep 17 00:00:00 2001 From: John Baldwin Date: Thu, 28 Jul 2022 18:00:42 -0700 Subject: [PATCH] Use gdbarch_print_cap* methods when printing capabilities. For pointers, use gdbarch_print_cap_attributes after printing the pointer's address normally. For printing a raw capability, use gdbarch_print_cap. I removed the fetch of the tag from memory explicitly in generic_value_print_capability as it should already be fetched for memory values in value_fetch_lazy_memory. --- gdb/c-valprint.c | 21 +++++++++++++++------ gdb/valprint.c | 49 +++++++++++++----------------------------------- 2 files changed, 28 insertions(+), 42 deletions(-) diff --git a/gdb/c-valprint.c b/gdb/c-valprint.c index 46187f5a52b..519e1ba5cd6 100644 --- a/gdb/c-valprint.c +++ b/gdb/c-valprint.c @@ -139,7 +139,8 @@ static const struct generic_val_print_decorations c_decorations = static void print_unpacked_pointer (struct type *type, struct type *elttype, struct type *unresolved_elttype, - const gdb_byte *valaddr, int embedded_offset, + const gdb_byte *valaddr, bool valtag, + int embedded_offset, CORE_ADDR address, struct ui_file *stream, int recurse, const struct value_print_options *options) { @@ -150,6 +151,8 @@ print_unpacked_pointer (struct type *type, struct type *elttype, { /* Try to print what function it points to. */ print_function_pointer_address (options, gdbarch, address, stream); + if (TYPE_CAPABILITY (type)) + gdbarch_print_cap_attributes (type->arch (), valaddr, valtag, stream); return; } @@ -162,6 +165,9 @@ print_unpacked_pointer (struct type *type, struct type *elttype, want_space = 1; } + if (TYPE_CAPABILITY (type)) + gdbarch_print_cap_attributes (type->arch (), valaddr, valtag, stream); + /* For a pointer to a textual type, also print the string pointed to, unless pointer is null. */ @@ -316,6 +322,7 @@ c_value_print_array (struct value *val, { /* Array of unspecified length: treat like pointer to first elt. */ print_unpacked_pointer (type, elttype, unresolved_elttype, valaddr, + value_tag (val), 0, address, stream, recurse, options); } } @@ -328,11 +335,6 @@ c_value_print_ptr (struct value *val, struct ui_file *stream, int recurse, { 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); @@ -350,6 +352,9 @@ c_value_print_ptr (struct value *val, struct ui_file *stream, int recurse, CORE_ADDR addr = extract_typed_address (valaddr, type); print_function_pointer_address (options, type->arch (), addr, stream); + if (TYPE_CAPABILITY (type)) + gdbarch_print_cap_attributes (type->arch (), valaddr, + value_tag (val), stream); } else { @@ -358,6 +363,7 @@ c_value_print_ptr (struct value *val, struct ui_file *stream, int recurse, CORE_ADDR addr = unpack_pointer (type, valaddr); print_unpacked_pointer (type, elttype, unresolved_elttype, valaddr, + value_tag (val), 0, addr, stream, recurse, options); } } @@ -384,6 +390,9 @@ c_value_print_struct (struct value *val, struct ui_file *stream, int recurse, CORE_ADDR addr = extract_typed_address (valaddr + offset, field_type); print_function_pointer_address (options, type->arch (), addr, stream); + if (TYPE_CAPABILITY (type)) + gdbarch_print_cap_attributes (type->arch (), valaddr, + value_tag (val), stream); } else cp_print_value_fields (val, stream, recurse, options, NULL, 0); diff --git a/gdb/valprint.c b/gdb/valprint.c index 6a33e011e59..cbbc03e325d 100644 --- a/gdb/valprint.c +++ b/gdb/valprint.c @@ -46,8 +46,6 @@ #include "gdbsupport/selftest.h" #include "selftest-arch.h" -#include "gdbsupport/capability.h" - /* Maximum number of wchars returned from wchar_iterate. */ #define MAX_WCHARS 4 @@ -482,6 +480,13 @@ generic_val_print_array (struct value *val, /* Array of unspecified length: treat like pointer to first elt. */ print_unpacked_pointer (type, elttype, value_address (val), stream, options); + if (TYPE_CAPABILITY (type)) + { + const gdb_byte *valaddr = value_contents_for_printing (val).data (); + + gdbarch_print_cap_attributes (type->arch (), valaddr, + value_tag (val), stream); + } } } @@ -503,6 +508,9 @@ generic_value_print_ptr (struct value *val, struct ui_file *stream, CORE_ADDR addr = unpack_pointer (type, valaddr); print_unpacked_pointer (type, elttype, addr, stream, options); + if (TYPE_CAPABILITY (type)) + gdbarch_print_cap_attributes (type->arch (), valaddr, value_tag (val), + stream); } } @@ -516,45 +524,14 @@ generic_value_print_capability (struct value *val, struct ui_file *stream, /* Account for the tag bit in the length. */ int length = TYPE_LENGTH (type); const gdb_byte *contents = value_contents_for_printing (val).data (); + bool tag = value_tag (val); enum bfd_endian byte_order = type_byte_order (type); - bool tag = false; - - switch (VALUE_LVAL (val)) - { - case not_lval: - case lval_register: - case lval_internalvar: - if (value_tagged (val)) - tag = value_tag (val); - break; - case lval_memory: - { - if (!value_lazy (val) && value_tagged (val)) - tag = value_tag (val); - else - { - struct gdbarch *gdbarch = type->arch (); - tag = gdbarch_get_cap_tag_from_address (gdbarch, - value_address (val)); - } - } - break; - default: - break; - } 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, tag); - fprintf_filtered (stream, "%s ", - cap.to_str (options->compact_capabilities).c_str ()); - } - - return; + gdbarch_print_cap (type->arch (), contents, tag, + options->compact_capabilities, stream); } /* Print '@' followed by the address contained in ADDRESS_BUFFER. */ -- 2.47.2