This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH] New function value_has_address
- From: Yao Qi <qiyaoltc at gmail dot com>
- To: gdb-patches at sourceware dot org
- Date: Thu, 27 Oct 2016 09:39:31 +0100
- Subject: [PATCH] New function value_has_address
- Authentication-results: sourceware.org; auth=none
This patch is to move duplicated condition checking in three functions
to a single new function, value_has_address.
The patch is obvious. I'll push it in later today, in case that people
think function value_has_address is not named properly.
gdb:
2016-10-27 Yao Qi <yao.qi@linaro.org>
* value.c (value_has_address): New function.
(value_address): Call value_has_address.
(value_raw_address): Likewise.
(set_value_address): Likewise.
---
gdb/value.c | 22 +++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)
diff --git a/gdb/value.c b/gdb/value.c
index b825aec..4b5cbde 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -1538,12 +1538,20 @@ value_lval_const (const struct value *value)
return value->lval;
}
+/* Return true if VALUE has address, otherwise return false. */
+
+static int
+value_has_address (const struct value *value)
+{
+ return (value->lval != lval_internalvar
+ && value->lval != lval_internalvar_component
+ && value->lval != lval_xcallable);
+}
+
CORE_ADDR
value_address (const struct value *value)
{
- if (value->lval == lval_internalvar
- || value->lval == lval_internalvar_component
- || value->lval == lval_xcallable)
+ if (!value_has_address (value))
return 0;
if (value->parent != NULL)
return value_address (value->parent) + value->offset;
@@ -1559,9 +1567,7 @@ value_address (const struct value *value)
CORE_ADDR
value_raw_address (const struct value *value)
{
- if (value->lval == lval_internalvar
- || value->lval == lval_internalvar_component
- || value->lval == lval_xcallable)
+ if (!value_has_address (value))
return 0;
return value->location.address;
}
@@ -1569,9 +1575,7 @@ value_raw_address (const struct value *value)
void
set_value_address (struct value *value, CORE_ADDR addr)
{
- gdb_assert (value->lval != lval_internalvar
- && value->lval != lval_internalvar_component
- && value->lval != lval_xcallable);
+ gdb_assert (value_has_address (value));
value->location.address = addr;
}
--
1.9.1