aboutsummaryrefslogtreecommitdiff
path: root/gdb/valprint.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2020-03-13 17:39:52 -0600
committerTom Tromey <tom@tromey.com>2020-03-13 18:03:40 -0600
commit4f9ae810130bc4202ec1c5eae934900c542a9016 (patch)
tree902dd418b78f104a7bcdc7b4357b4a443bd522f9 /gdb/valprint.c
parent156bfec999186e3eccaf51fa3b81280bf51dbaa4 (diff)
downloadgdb-4f9ae810130bc4202ec1c5eae934900c542a9016.zip
gdb-4f9ae810130bc4202ec1c5eae934900c542a9016.tar.gz
gdb-4f9ae810130bc4202ec1c5eae934900c542a9016.tar.bz2
Introduce value_print_scalar_formatted
This introduces a value_print_scalar_formatted, which is an analogue of val_print_scalar_formatted that uses the value API. gdb/ChangeLog 2020-03-13 Tom Tromey <tom@tromey.com> * valprint.h (value_print_scalar_formatted): Declare. * valprint.c (value_print_scalar_formatted): New function.
Diffstat (limited to 'gdb/valprint.c')
-rw-r--r--gdb/valprint.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/gdb/valprint.c b/gdb/valprint.c
index 7b0365a..9cdf18e 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -1394,6 +1394,46 @@ val_print_scalar_formatted (struct type *type,
options, size, stream);
}
+/* See valprint.h. */
+
+void
+value_print_scalar_formatted (struct value *val,
+ const struct value_print_options *options,
+ int size,
+ struct ui_file *stream)
+{
+ struct type *type = check_typedef (value_type (val));
+
+ gdb_assert (val != NULL);
+
+ /* If we get here with a string format, try again without it. Go
+ all the way back to the language printers, which may call us
+ again. */
+ if (options->format == 's')
+ {
+ struct value_print_options opts = *options;
+ opts.format = 0;
+ opts.deref_ref = 0;
+ common_val_print (val, stream, 0, &opts, current_language);
+ return;
+ }
+
+ /* value_contents_for_printing fetches all VAL's contents. They are
+ needed to check whether VAL is optimized-out or unavailable
+ below. */
+ const gdb_byte *valaddr = value_contents_for_printing (val);
+
+ /* A scalar object that does not have all bits available can't be
+ printed, because all bits contribute to its representation. */
+ if (value_bits_any_optimized_out (val, 0,
+ TARGET_CHAR_BIT * TYPE_LENGTH (type)))
+ val_print_optimized_out (val, stream);
+ else if (!value_bytes_available (val, 0, TYPE_LENGTH (type)))
+ val_print_unavailable (stream);
+ else
+ print_scalar_formatted (valaddr, type, options, size, stream);
+}
+
/* Print a number according to FORMAT which is one of d,u,x,o,b,h,w,g.
The raison d'etre of this function is to consolidate printing of
LONG_LONG's into this one function. The format chars b,h,w,g are