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:41 -0600
commit4f412b6e31369f27725872391a70f0520883701c (patch)
tree5f3b475c66c12df90bda568d0059aa1262859684 /gdb/valprint.c
parentf5354008862defe83fc6d3620d51da52f860f5bf (diff)
downloadgdb-4f412b6e31369f27725872391a70f0520883701c.zip
gdb-4f412b6e31369f27725872391a70f0520883701c.tar.gz
gdb-4f412b6e31369f27725872391a70f0520883701c.tar.bz2
Introduce generic_value_print_complex
This adds generic_value_print_complex, a value-based analogue of generic_val_print_complex. gdb/ChangeLog 2020-03-13 Tom Tromey <tom@tromey.com> * valprint.c (generic_value_print_complex): New function. (generic_value_print): Use it.
Diffstat (limited to 'gdb/valprint.c')
-rw-r--r--gdb/valprint.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/gdb/valprint.c b/gdb/valprint.c
index f759e0a..5bf874e 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -966,6 +966,30 @@ generic_val_print_complex (struct type *type,
fprintf_filtered (stream, "%s", decorations->complex_suffix);
}
+/* generic_value_print helper for TYPE_CODE_COMPLEX. */
+
+static void
+generic_value_print_complex (struct value *val, struct ui_file *stream,
+ const struct value_print_options *options,
+ const struct generic_val_print_decorations
+ *decorations)
+{
+ fprintf_filtered (stream, "%s", decorations->complex_prefix);
+
+ struct type *type = check_typedef (value_type (val));
+ struct value *real_part
+ = value_from_component (val, TYPE_TARGET_TYPE (type), 0);
+ value_print_scalar_formatted (real_part, options, 0, stream);
+ fprintf_filtered (stream, "%s", decorations->complex_infix);
+
+ struct value *imag_part
+ = value_from_component (val, TYPE_TARGET_TYPE (type),
+ TYPE_LENGTH (TYPE_TARGET_TYPE (type)));
+
+ value_print_scalar_formatted (imag_part, options, 0, stream);
+ fprintf_filtered (stream, "%s", decorations->complex_suffix);
+}
+
/* A generic val_print that is suitable for use by language
implementations of the la_val_print method. This function can
handle most type codes, though not all, notably exception
@@ -1206,8 +1230,7 @@ generic_value_print (struct value *val, struct ui_file *stream, int recurse,
break;
case TYPE_CODE_COMPLEX:
- generic_val_print_complex (type, 0, stream,
- val, options, decorations);
+ generic_value_print_complex (val, stream, options, decorations);
break;
case TYPE_CODE_UNION: