From: Luis Machado Date: Thu, 5 Nov 2020 19:18:18 +0000 (-0300) Subject: Print capability pointers as capabilities X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3f7b6f76046377b041cffcfafbfdbf8b4b1d0837;p=thirdparty%2Fbinutils-gdb.git Print capability pointers as capabilities Print capability pointers as capabilities, so the user can see the decoded fields of the capability. gdb/ChangeLog: 2020-11-11 Luis Machado * 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. --- diff --git a/gdb/c-valprint.c b/gdb/c-valprint.c index 0d30700c06d..46187f5a52b 100644 --- a/gdb/c-valprint.c +++ b/gdb/c-valprint.c @@ -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; diff --git a/gdb/findvar.c b/gdb/findvar.c index 6660b006795..7ac62e75ad0 100644 --- a/gdb/findvar.c +++ b/gdb/findvar.c @@ -36,7 +36,11 @@ /* 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 buf, enum bfd_endian byte_order) { typename std::make_unsigned::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::value) { diff --git a/gdb/valprint.c b/gdb/valprint.c index 5ee5a71af35..d7993f39edf 100644 --- a/gdb/valprint.c +++ b/gdb/valprint.c @@ -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; diff --git a/gdb/valprint.h b/gdb/valprint.h index 0586836f9e6..f81cabb727d 100644 --- a/gdb/valprint.h +++ b/gdb/valprint.h @@ -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. */