diff options
author | Ulrich Weigand <ulrich.weigand@de.ibm.com> | 2017-11-06 16:00:47 +0100 |
---|---|---|
committer | Ulrich Weigand <ulrich.weigand@de.ibm.com> | 2017-11-06 16:00:47 +0100 |
commit | 14ad9311720fc17bd646b2ff08483fe60a489959 (patch) | |
tree | 1092793393df19bbcfa96f188eaf3eb2fbfdceee /gdb/guile | |
parent | 50eff16b85073287b1b184a257a8fd80e960fe02 (diff) | |
download | gdb-14ad9311720fc17bd646b2ff08483fe60a489959.zip gdb-14ad9311720fc17bd646b2ff08483fe60a489959.tar.gz gdb-14ad9311720fc17bd646b2ff08483fe60a489959.tar.bz2 |
Target FP: Handle interfaces to scripting languages
The last remaing use for DOUBLEST is in the code that interfaces to the
scripting languages (Python and Guile). The problem here is that we
expose interfaces to convert a GDB value to and from native values of
floating-point type in those languages, and those by definition use
the host floating-point format.
While we cannot completely eliminate conversions to/from the host
floating-point format here, we still need to get rid of the uses
of value_as_double / value_from_double, since those will go away.
This patch implements two new target-float.c routine:
- target_float_to_host_double
- target_float_from_host_double
which convert to/from a host "double". Those should only ever be
used where a host "double" is mandated by an external interface.
gdb/ChangeLog:
2017-11-06 Ulrich Weigand <uweigand@de.ibm.com>
* target-float.c (floatformat_to_host_double): New function.
(floatformat_from_host_double): Likewise.
(target_float_to_host_double): Likewise.
(target_float_from_host_double): Likewise.
* target-float.h (target_float_to_host_double): Add prototype.
(target_float_from_host_double): Likewise.
* guile/scm-value.c: Include "target-float.h".
(gdbscm_value_to_real): Use target_float_to_host_double.
Handle integer source values via value_as_long.
* guile/scm-math.c: Include "target-float.h". Do not include
"doublest.h", "dfp.h", and "expression.h".
(vlscm_convert_typed_number): Use target_float_from_host_double.
(vlscm_convert_number): Likewise.
* python/py-value.c (valpy_float): Use target_float_to_host_double.
(convert_value_from_python): Use target_float_from_host_double.
Diffstat (limited to 'gdb/guile')
-rw-r--r-- | gdb/guile/scm-math.c | 20 | ||||
-rw-r--r-- | gdb/guile/scm-value.c | 23 |
2 files changed, 35 insertions, 8 deletions
diff --git a/gdb/guile/scm-math.c b/gdb/guile/scm-math.c index c4dfe71..ef27d68 100644 --- a/gdb/guile/scm-math.c +++ b/gdb/guile/scm-math.c @@ -24,9 +24,7 @@ #include "arch-utils.h" #include "charset.h" #include "cp-abi.h" -#include "doublest.h" /* Needed by dfp.h. */ -#include "expression.h" /* Needed by dfp.h. */ -#include "dfp.h" +#include "target-float.h" #include "symtab.h" /* Needed by language.h. */ #include "language.h" #include "valprint.h" @@ -599,7 +597,13 @@ vlscm_convert_typed_number (const char *func_name, int obj_arg_pos, SCM obj, } } else if (TYPE_CODE (type) == TYPE_CODE_FLT) - return value_from_double (type, scm_to_double (obj)); + { + struct value *value = allocate_value (type); + target_float_from_host_double (value_contents_raw (value), + value_type (value), + scm_to_double (obj)); + return value; + } else { *except_scmp = gdbscm_make_type_error (func_name, obj_arg_pos, obj, @@ -679,7 +683,13 @@ vlscm_convert_number (const char *func_name, int obj_arg_pos, SCM obj, gdbscm_scm_to_ulongest (obj)); } else if (scm_is_real (obj)) - return value_from_double (bt->builtin_double, scm_to_double (obj)); + { + struct value *value = allocate_value (bt->builtin_double); + target_float_from_host_double (value_contents_raw (value), + value_type (value), + scm_to_double (obj)); + return value; + } *except_scmp = gdbscm_make_out_of_range_error (func_name, obj_arg_pos, obj, _("value not a number representable on the target")); diff --git a/gdb/guile/scm-value.c b/gdb/guile/scm-value.c index 3732666..0cf7547 100644 --- a/gdb/guile/scm-value.c +++ b/gdb/guile/scm-value.c @@ -24,6 +24,7 @@ #include "arch-utils.h" #include "charset.h" #include "cp-abi.h" +#include "target-float.h" #include "infcall.h" #include "symtab.h" /* Needed by language.h. */ #include "language.h" @@ -1019,7 +1020,8 @@ gdbscm_value_to_real (SCM self) = vlscm_get_value_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME); struct value *value = v_smob->value; struct type *type; - DOUBLEST d = 0; + double d = 0; + struct value *check = nullptr; type = value_type (value); @@ -1038,7 +1040,22 @@ gdbscm_value_to_real (SCM self) TRY { - d = value_as_double (value); + if (is_floating_value (value)) + { + d = target_float_to_host_double (value_contents (value), type); + check = allocate_value (type); + target_float_from_host_double (value_contents_raw (check), type, d); + } + else if (TYPE_UNSIGNED (type)) + { + d = (ULONGEST) value_as_long (value); + check = value_from_ulongest (type, (ULONGEST) d); + } + else + { + d = value_as_long (value); + check = value_from_longest (type, (LONGEST) d); + } } CATCH (except, RETURN_MASK_ALL) { @@ -1047,7 +1064,7 @@ gdbscm_value_to_real (SCM self) END_CATCH /* TODO: Is there a better way to check if the value fits? */ - if (d != (double) d) + if (!value_equal (value, check)) gdbscm_out_of_range_error (FUNC_NAME, SCM_ARG1, self, _("number can't be converted to a double")); |