aboutsummaryrefslogtreecommitdiff
path: root/gdb/target-float.c
diff options
context:
space:
mode:
authorUlrich Weigand <ulrich.weigand@de.ibm.com>2017-11-06 16:00:47 +0100
committerUlrich Weigand <ulrich.weigand@de.ibm.com>2017-11-06 16:00:47 +0100
commit14ad9311720fc17bd646b2ff08483fe60a489959 (patch)
tree1092793393df19bbcfa96f188eaf3eb2fbfdceee /gdb/target-float.c
parent50eff16b85073287b1b184a257a8fd80e960fe02 (diff)
downloadgdb-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/target-float.c')
-rw-r--r--gdb/target-float.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/gdb/target-float.c b/gdb/target-float.c
index ad04f8f..d2c1064 100644
--- a/gdb/target-float.c
+++ b/gdb/target-float.c
@@ -59,6 +59,27 @@ floatformat_from_ulongest (const struct floatformat *fmt, gdb_byte *addr,
floatformat_from_doublest (fmt, &d, addr);
}
+/* Convert the byte-stream ADDR, interpreted as floating-point format FMT,
+ to a floating-point value in the host "double" format. */
+static double
+floatformat_to_host_double (const struct floatformat *fmt,
+ const gdb_byte *addr)
+{
+ DOUBLEST d;
+ floatformat_to_doublest (fmt, addr, &d);
+ return (double) d;
+}
+
+/* Convert floating-point value VAL in the host "double" format to a target
+ floating-number of format FMT and store it as byte-stream ADDR. */
+static void
+floatformat_from_host_double (const struct floatformat *fmt, gdb_byte *addr,
+ double val)
+{
+ DOUBLEST d = (DOUBLEST) val;
+ floatformat_from_doublest (fmt, &d, addr);
+}
+
/* Convert a floating-point number of format FROM_FMT from the target
byte-stream FROM to a floating-point number of format TO_FMT, and
store it to the target byte-stream TO. */
@@ -299,6 +320,42 @@ target_float_from_ulongest (gdb_byte *addr, const struct type *type,
gdb_assert_not_reached ("unexpected type code");
}
+/* Convert the byte-stream ADDR, interpreted as floating-point type TYPE,
+ to a floating-point value in the host "double" format. */
+double
+target_float_to_host_double (const gdb_byte *addr,
+ const struct type *type)
+{
+ if (TYPE_CODE (type) == TYPE_CODE_FLT)
+ return floatformat_to_host_double (floatformat_from_type (type), addr);
+
+ /* We don't support conversions between target decimal floating-point
+ types and the host double type here. */
+
+ gdb_assert_not_reached ("unexpected type code");
+}
+
+/* Convert floating-point value VAL in the host "double" format to a target
+ floating-number of type TYPE and store it as byte-stream ADDR. */
+void
+target_float_from_host_double (gdb_byte *addr, const struct type *type,
+ double val)
+{
+ /* Ensure possible padding bytes in the target buffer are zeroed out. */
+ memset (addr, 0, TYPE_LENGTH (type));
+
+ if (TYPE_CODE (type) == TYPE_CODE_FLT)
+ {
+ floatformat_from_host_double (floatformat_from_type (type), addr, val);
+ return;
+ }
+
+ /* We don't support conversions between target decimal floating-point
+ types and the host double type here. */
+
+ gdb_assert_not_reached ("unexpected type code");
+}
+
/* Convert a floating-point number of type FROM_TYPE from the target
byte-stream FROM to a floating-point number of type TO_TYPE, and
store it to the target byte-stream TO. */