aboutsummaryrefslogtreecommitdiff
path: root/gdb/valprint.c
diff options
context:
space:
mode:
authorJoel Brobecker <brobecker@adacore.com>2020-11-15 03:12:52 -0500
committerJoel Brobecker <brobecker@adacore.com>2020-11-15 03:12:52 -0500
commit0958441403b92163dff851f0a78241c7fcb4e8eb (patch)
treed5e81a519e48f52e665f16ddc8a15cc378e45a7f /gdb/valprint.c
parente55c6530dbf96bfbe2e4a232c0feb19c0a4a2294 (diff)
downloadgdb-0958441403b92163dff851f0a78241c7fcb4e8eb.zip
gdb-0958441403b92163dff851f0a78241c7fcb4e8eb.tar.gz
gdb-0958441403b92163dff851f0a78241c7fcb4e8eb.tar.bz2
Add support for printing value of DWARF-based fixed-point type objects
This commit introduces a new kind of type, meant to describe fixed-point types, using a new code added specifically for this purpose (TYPE_CODE_FIXED_POINT). It then adds handling of fixed-point base types in the DWARF reader. And finally, as a first step, this commit adds support for printing the value of fixed-point type objects. Note that this commit has a known issue: Trying to print the value of a fixed-point object with a format letter (e.g. "print /x NAME") causes the wrong value to be printed because the scaling factor is not applied. Since the fix for this issue is isolated, and this is not a regression, the fix will be made in a pach of its own. This is meant to simplify review and archeology. Also, other functionalities related to fixed-point type handling (ptype, arithmetics, etc), will be added piecemeal as well, for the same reasons (faciliate reviews and archeology). Related to this, the testcase gdb.ada/fixed_cmp.exp is adjusted to compile the test program with -fgnat-encodings=all, so as to force the use of GNAT encodings, rather than rely on the compiler's default to use them. The intent is to enhance this testcase to also test the pure DWARF approach using -fgnat-encodings=minimal as soon as the corresponding suport gets added in. Thus, the modification to the testcase is made in a way that it prepares this testcase to be tested in both modes. gdb/ChangeLog: * ada-valprint.c (ada_value_print_1): Add fixed-point type handling. * dwarf2/read.c (get_dwarf2_rational_constant) (get_dwarf2_unsigned_rational_constant, finish_fixed_point_type) (has_zero_over_zero_small_attribute): New functions. read_base_type, set_die_type): Add fixed-point type handling. * gdb-gdb.py.in: Add fixed-point type handling. * gdbtypes.c: #include "gmp-utils.h". (create_range_type, set_type_code): Add fixed-point type handling. (init_fixed_point_type): New function. (is_integral_type, is_scalar_type): Add fixed-point type handling. (print_fixed_point_type_info): New function. (recursive_dump_type, copy_type_recursive): Add fixed-point type handling. (fixed_point_type_storage): New typedef. (fixed_point_objfile_key): New static global. (allocate_fixed_point_type_info, is_fixed_point_type): New functions. (fixed_point_type_base_type, fixed_point_scaling_factor): New functions. * gdbtypes.h: #include "gmp-utils.h". (enum type_code) <TYPE_SPECIFIC_FIXED_POINT>: New enum. (union type_specific) <fixed_point_info>: New field. (struct fixed_point_type_info): New struct. (INIT_FIXED_POINT_SPECIFIC, TYPE_FIXED_POINT_INFO): New macros. (init_fixed_point_type, is_fixed_point_type) (fixed_point_type_base_type, fixed_point_scaling_factor) (allocate_fixed_point_type_info): Add declarations. * valprint.c (generic_val_print_fixed_point): New function. (generic_value_print): Add fixed-point type handling. * value.c (value_as_address, unpack_long): Add fixed-point type handling. gdb/testsuite/ChangeLog: * gdb.ada/fixed_cmp.exp: Force compilation to use -fgnat-encodings=all. * gdb.ada/fixed_points.exp: Add fixed-point variables printing tests. * gdb.ada/fixed_points/pck.ads, gdb.ada/fixed_points/pck.adb: New files. * gdb.ada/fixed_points/fixed_points.adb: Add use of package Pck. * gdb.dwarf2/dw2-fixed-point.c, gdb.dwarf2/dw2-fixed-point.exp: New files.
Diffstat (limited to 'gdb/valprint.c')
-rw-r--r--gdb/valprint.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/gdb/valprint.c b/gdb/valprint.c
index 2d9d1fb..38ae0bd 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -794,6 +794,31 @@ generic_val_print_float (struct type *type, struct ui_file *stream,
print_floating (valaddr, type, stream);
}
+/* generic_val_print helper for TYPE_CODE_FIXED_POINT. */
+
+static void
+generic_val_print_fixed_point (struct value *val, struct ui_file *stream,
+ const struct value_print_options *options)
+{
+ if (options->format)
+ value_print_scalar_formatted (val, options, 0, stream);
+ else
+ {
+ struct type *type = value_type (val);
+
+ const gdb_byte *valaddr = value_contents_for_printing (val);
+ gdb_mpf f;
+
+ f.read_fixed_point (valaddr, TYPE_LENGTH (type),
+ type_byte_order (type), type->is_unsigned (),
+ fixed_point_scaling_factor (type));
+
+ const char *fmt = TYPE_LENGTH (type) < 4 ? "%.11Fg" : "%.17Fg";
+ gdb::unique_xmalloc_ptr<char> str = gmp_string_asprintf (fmt, f.val);
+ fprintf_filtered (stream, "%s", str.get ());
+ }
+}
+
/* generic_value_print helper for TYPE_CODE_COMPLEX. */
static void
@@ -844,6 +869,10 @@ generic_value_print (struct value *val, struct ui_file *stream, int recurse,
struct type *type = value_type (val);
type = check_typedef (type);
+
+ if (is_fixed_point_type (type))
+ type = fixed_point_type_base_type (type);
+
switch (type->code ())
{
case TYPE_CODE_ARRAY:
@@ -909,6 +938,10 @@ generic_value_print (struct value *val, struct ui_file *stream, int recurse,
generic_val_print_float (type, stream, val, options);
break;
+ case TYPE_CODE_FIXED_POINT:
+ generic_val_print_fixed_point (val, stream, options);
+ break;
+
case TYPE_CODE_VOID:
fputs_filtered (decorations->void_name, stream);
break;