From: Andrew Burgess <andrew.burgess@embecosm.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>,
Andrew Burgess <andrew.burgess@embecosm.com>
Subject: [PATCH] gdb: Move value_from_host_double into value.c and make more use of it
Date: Thu, 07 Mar 2019 15:23:00 -0000 [thread overview]
Message-ID: <20190307152328.12891-1-andrew.burgess@embecosm.com> (raw)
In-Reply-To: <87y35rom1h.fsf@tromey.com>
Something like this?
---
The function value_from_host_double can be moved from f-lang.c into
value.c as a generally useful function, and then used more widely.
Tested on X86-64/GNU Linux with no regressions.
gdb/ChangeLog:
* f-lang.c (value_from_host_double): Moved to...
* value.c (value_from_host_double): ...here.
* value.h (value_from_host_double): Declare.
* guile/scm-math.c (vlscm_convert_typed_number): Use
value_from_host_double.
(vlscm_convert_number): Likewise.
* guile/scm-value.c (gdbscm_value_to_real): Likewise.
* python/py-value.c (convert_value_from_python): Likewise.
---
gdb/ChangeLog | 11 +++++++++++
gdb/f-lang.c | 14 --------------
gdb/guile/scm-math.c | 16 ++--------------
gdb/guile/scm-value.c | 3 +--
gdb/python/py-value.c | 6 +-----
gdb/value.c | 13 +++++++++++++
gdb/value.h | 1 +
7 files changed, 29 insertions(+), 35 deletions(-)
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 24f0e61a46b..7bd119690b4 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -241,20 +241,6 @@ f_collect_symbol_completion_matches (completion_tracker &tracker,
text, word, ":", code);
}
-/* Create and return a value object of TYPE containing the value D. The
- TYPE must be of TYPE_CODE_FLT, and must be large enough to hold D once
- it is converted to target format. */
-
-static struct value *
-value_from_host_double (struct type *type, double d)
-{
- struct value *value = allocate_value (type);
- gdb_assert (TYPE_CODE (type) == TYPE_CODE_FLT);
- target_float_from_host_double (value_contents_raw (value),
- value_type (value), d);
- return value;
-}
-
/* Special expression evaluation cases for Fortran. */
struct value *
evaluate_subexp_f (struct type *expect_type, struct expression *exp,
diff --git a/gdb/guile/scm-math.c b/gdb/guile/scm-math.c
index a31a1455487..d351ed0522c 100644
--- a/gdb/guile/scm-math.c
+++ b/gdb/guile/scm-math.c
@@ -559,13 +559,7 @@ vlscm_convert_typed_number (const char *func_name, int obj_arg_pos, SCM obj,
}
}
else if (TYPE_CODE (type) == TYPE_CODE_FLT)
- {
- struct value *value = allocate_value (type);
- target_float_from_host_double (value_contents_raw (value),
- value_type (value),
- scm_to_double (obj));
- return value;
- }
+ return value_from_host_double (type, scm_to_double (obj));
else
{
*except_scmp = gdbscm_make_type_error (func_name, obj_arg_pos, obj,
@@ -645,13 +639,7 @@ vlscm_convert_number (const char *func_name, int obj_arg_pos, SCM obj,
gdbscm_scm_to_ulongest (obj));
}
else if (scm_is_real (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;
- }
+ return value_from_host_double (bt->builtin_double, scm_to_double (obj));
*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 294e3e7cafc..658924b1197 100644
--- a/gdb/guile/scm-value.c
+++ b/gdb/guile/scm-value.c
@@ -903,8 +903,7 @@ gdbscm_value_to_real (SCM self)
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);
+ check = value_from_host_double (type, d);
}
else if (TYPE_UNSIGNED (type))
{
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index 63a9952e513..dd6a536b6ad 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -1739,11 +1739,7 @@ convert_value_from_python (PyObject *obj)
double d = PyFloat_AsDouble (obj);
if (! PyErr_Occurred ())
- {
- value = allocate_value (builtin_type_pyfloat);
- target_float_from_host_double (value_contents_raw (value),
- value_type (value), d);
- }
+ value = value_from_host_double (builtin_type_pyfloat, d);
}
else if (gdbpy_is_string (obj))
{
diff --git a/gdb/value.c b/gdb/value.c
index 50e47a936aa..dc297dfe0f9 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -3430,6 +3430,19 @@ value_from_pointer (struct type *type, CORE_ADDR addr)
return val;
}
+/* Create and return a value object of TYPE containing the value D. The
+ TYPE must be of TYPE_CODE_FLT, and must be large enough to hold D once
+ it is converted to target format. */
+
+struct value *
+value_from_host_double (struct type *type, double d)
+{
+ struct value *value = allocate_value (type);
+ gdb_assert (TYPE_CODE (type) == TYPE_CODE_FLT);
+ target_float_from_host_double (value_contents_raw (value),
+ value_type (value), d);
+ return value;
+}
/* Create a value of type TYPE whose contents come from VALADDR, if it
is non-null, and whose memory address (in the inferior) is
diff --git a/gdb/value.h b/gdb/value.h
index 1ca91e041a1..d3905cc354a 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -669,6 +669,7 @@ extern void pack_long (gdb_byte *buf, struct type *type, LONGEST num);
extern struct value *value_from_longest (struct type *type, LONGEST num);
extern struct value *value_from_ulongest (struct type *type, ULONGEST num);
extern struct value *value_from_pointer (struct type *type, CORE_ADDR addr);
+extern struct value *value_from_host_double (struct type *type, double d);
extern struct value *value_from_history_ref (const char *, const char **);
extern struct value *value_from_component (struct value *, struct type *,
LONGEST);
--
2.14.5
next prev parent reply other threads:[~2019-03-07 15:23 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-12 16:11 [PATCH 00/11] Fortran Parser Cleanup, KIND Support, and Intrinsic Functions Andrew Burgess
2019-02-12 16:11 ` [PATCH 11/11] gdb/fortran: Handle older TYPE*SIZE typenames Andrew Burgess
2019-02-12 16:11 ` [PATCH 01/11] gdb/fortran: Remove some duplicate tests Andrew Burgess
2019-02-12 16:11 ` [PATCH 05/11] gdb/fortran: Enable debugging of the Fortran parser Andrew Burgess
2019-02-12 16:11 ` [PATCH 10/11] gdb/fortran: Add support for the ABS intrinsic function Andrew Burgess
2019-02-12 16:11 ` [PATCH 07/11] gdb/fortran: Expand the set of types that support (kind=N) Andrew Burgess
2019-02-12 16:11 ` [PATCH 04/11] gdb/fortran: Add new function to evaluate Fortran expressions Andrew Burgess
2019-02-12 16:11 ` [PATCH 08/11] gdb/fortran: Add builtin 8-byte integer type with (kind=8) support Andrew Burgess
2019-02-12 16:11 ` [PATCH 02/11] gdb/fortran: Cleanup code for parsing logical constants Andrew Burgess
2019-02-12 16:11 ` [PATCH 03/11] gdb/fortran: Simplify handling of Fortran dot operations and keywords Andrew Burgess
2019-02-12 16:11 ` [PATCH 06/11] gdb/fortran: Add Fortran 'kind' intrinsic and keyword Andrew Burgess
2019-02-12 16:11 ` [PATCH 09/11] gdb/fortran: Use TYPE_CODE_CHAR for character types Andrew Burgess
2019-03-06 18:15 ` [PUSHED 04/11] gdb/fortran: Add new function to evaluate Fortran expressions Andrew Burgess
2019-03-06 18:15 ` [PUSHED 01/11] gdb/fortran: Remove some duplicate tests Andrew Burgess
2019-03-06 18:15 ` [PUSHED 02/11] gdb/fortran: Cleanup code for parsing logical constants Andrew Burgess
2019-03-06 18:15 ` [PUSHED 00/11] Fortran Parser Cleanup, KIND Support, and Intrinsic Functions Andrew Burgess
2019-03-06 18:16 ` [PUSHED 09/11] gdb/fortran: Use TYPE_CODE_CHAR for character types Andrew Burgess
2019-03-06 18:16 ` [PUSHED 05/11] gdb/fortran: Enable debugging of the Fortran parser Andrew Burgess
2019-03-06 18:16 ` [PUSHED 03/11] gdb/fortran: Simplify handling of Fortran dot operations and keywords Andrew Burgess
2019-03-06 18:16 ` [PUSHED 06/11] gdb/fortran: Add Fortran 'kind' intrinsic and keyword Andrew Burgess
2019-03-06 18:16 ` [PUSHED 11/11] gdb/fortran: Handle older TYPE*SIZE typenames Andrew Burgess
2019-03-06 18:16 ` [PUSHED 07/11] gdb/fortran: Expand the set of types that support (kind=N) Andrew Burgess
2019-03-06 18:16 ` [PUSHED 10/11] gdb/fortran: Add support for the ABS intrinsic function Andrew Burgess
2019-03-06 19:11 ` Tom Tromey
2019-03-07 15:23 ` Andrew Burgess [this message]
2019-03-07 15:49 ` [PATCH] gdb: Move value_from_host_double into value.c and make more use of it Tom Tromey
2019-03-06 18:16 ` [PUSHED 08/11] gdb/fortran: Add builtin 8-byte integer type with (kind=8) support Andrew Burgess
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190307152328.12891-1-andrew.burgess@embecosm.com \
--to=andrew.burgess@embecosm.com \
--cc=gdb-patches@sourceware.org \
--cc=tom@tromey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox