aboutsummaryrefslogtreecommitdiff
path: root/gdb/ada-valprint.c
diff options
context:
space:
mode:
authorUlrich Weigand <ulrich.weigand@de.ibm.com>2017-11-06 15:59:36 +0100
committerUlrich Weigand <ulrich.weigand@de.ibm.com>2017-11-06 16:00:12 +0100
commit50eff16b85073287b1b184a257a8fd80e960fe02 (patch)
treea25945447d908edd2a5a0c878b311dfacc205147 /gdb/ada-valprint.c
parent66c02b9ed1eabf1d7981c0c27ec9fd3c17fc5d35 (diff)
downloadgdb-50eff16b85073287b1b184a257a8fd80e960fe02.zip
gdb-50eff16b85073287b1b184a257a8fd80e960fe02.tar.gz
gdb-50eff16b85073287b1b184a257a8fd80e960fe02.tar.bz2
Target FP: Perform Ada fixed-point scaling in target format
One of the few still remaining uses of DOUBLEST in GDB is the Ada front-end code that handles scaling of Ada fixed-point types. The target format for those types is some integer format; to convert those values to standard floating-point representation, that integer needs to be multiplied by a rational scale factor, given as a pair of numerator and denominator. To avoid having to deal with long integer arithmetic, the current Ada front-end code currently performs those scaling operations in host DOUBLEST arithmetic. To eliminate this use of DOUBLEST, this patch changes the front-end to instead perform those operations in the *target* floating-point format (chosing to use the target "long double"). The implementation is mostly straight-forward, using value_cast and value_binop to perform the target operations. Scanning in the scale numerator and denominator is now done into a host "long long" instead of a DOUBLEST, which should be large enough to hold all possible values. (Otherwise, this can be replaced by target-format target_float_from_string operations as well.) Printing fixed-point types and values should be completely unchanges, using target_float_to_string with the same format strings as current code. gdb/ChangeLog: 2017-11-06 Ulrich Weigand <uweigand@de.ibm.com> * ada-lang.c (cast_to_fixed): Reimplement in target arithmetic. (cast_from_fixed): Likewise. (ada_scaling_type): New function. (ada_delta): Return value instead of DOUBLEST. Perform target arithmetic instead of host arithmetic. (scaling_factor): Rename to ... (ada_scaling_factor) ... this. Make non-static. Return value instead of DOUBLEST. Perform target arithmetic instead of host arithmetic. (ada_fixed_to_float): Remove. (ada_float_to_fixed): Remove. * ada-lang.h (ada_fixed_to_float): Remove. (ada_float_to_fixed): Remove. (ada_delta): Return value instead of DOUBLEST. (ada_scaling_factor): Add prototype. * ada-typeprint.c: Include "target-float.h". (print_fixed_point_type): Perform target arithmetic instead of host arithmetic. * ada-valprint.c: Include "target-float.h". (ada_val_print_num): Perform target arithmetic instead of host arithmetic for fixed-point types.
Diffstat (limited to 'gdb/ada-valprint.c')
-rw-r--r--gdb/ada-valprint.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c
index 8095eed..91dc301 100644
--- a/gdb/ada-valprint.c
+++ b/gdb/ada-valprint.c
@@ -31,6 +31,7 @@
#include "c-lang.h"
#include "infcall.h"
#include "objfiles.h"
+#include "target-float.h"
static int print_field_values (struct type *, const gdb_byte *,
int,
@@ -796,10 +797,15 @@ ada_val_print_num (struct type *type, const gdb_byte *valaddr,
{
if (ada_is_fixed_point_type (type))
{
- LONGEST v = unpack_long (type, valaddr + offset_aligned);
-
- fprintf_filtered (stream, TYPE_LENGTH (type) < 4 ? "%.11g" : "%.17g",
- (double) ada_fixed_to_float (type, v));
+ struct value *scale = ada_scaling_factor (type);
+ struct value *v = value_from_contents (type, valaddr + offset_aligned);
+ v = value_cast (value_type (scale), v);
+ v = value_binop (v, scale, BINOP_MUL);
+
+ const char *fmt = TYPE_LENGTH (type) < 4 ? "%.11g" : "%.17g";
+ std::string str
+ = target_float_to_string (value_contents (v), value_type (v), fmt);
+ fputs_filtered (str.c_str (), stream);
return;
}
else if (TYPE_CODE (type) == TYPE_CODE_RANGE)