aboutsummaryrefslogtreecommitdiff
path: root/gdb/valprint.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2022-03-10 09:23:45 -0700
committerTom Tromey <tromey@adacore.com>2022-03-14 06:58:12 -0600
commit79a0742380b5304c734ce6f4359d437325cc7121 (patch)
treee3184cf4db3b81553d449cd4c4dc100633b80348 /gdb/valprint.c
parentbab22d0640914384d467e09c3e796585fd08e7c6 (diff)
downloadgdb-79a0742380b5304c734ce6f4359d437325cc7121.zip
gdb-79a0742380b5304c734ce6f4359d437325cc7121.tar.gz
gdb-79a0742380b5304c734ce6f4359d437325cc7121.tar.bz2
Correctly print subrange types in generic_value_print
I noticed that generic_value_print assumes that a subrange type is always a subrange of an integer type. However, this isn't necessarily the case. In Ada, for example, one has subranges of character and enumeration types. This code isn't often exercised, I think, because languages with real subrange types tend to implement their own printers. However, it still seemed worth fixing.
Diffstat (limited to 'gdb/valprint.c')
-rw-r--r--gdb/valprint.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/gdb/valprint.c b/gdb/valprint.c
index d6ec648..c2ffe62 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -888,6 +888,14 @@ generic_value_print (struct value *val, struct ui_file *stream, int recurse,
if (is_fixed_point_type (type))
type = type->fixed_point_type_base_type ();
+ /* Widen a subrange to its target type, then use that type's
+ printer. */
+ while (type->code () == TYPE_CODE_RANGE)
+ {
+ type = check_typedef (TYPE_TARGET_TYPE (type));
+ val = value_cast (type, val);
+ }
+
switch (type->code ())
{
case TYPE_CODE_ARRAY:
@@ -936,7 +944,6 @@ generic_value_print (struct value *val, struct ui_file *stream, int recurse,
generic_value_print_bool (val, stream, options, decorations);
break;
- case TYPE_CODE_RANGE:
case TYPE_CODE_INT:
generic_value_print_int (val, stream, options);
break;