This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Don't call value_address in x_command


When I examine the usage of value_address and value_as_address in gdb
code base, I happen to find that we can simplify the code in x_command
a little bit.  With this patch, we can get value address from
value_as_address unconditionally.  The code this patch removed was
added in 1989, predates CVS repository,

+       * printcmd.c (x_command): Use variable itself rather
+       than treating it as a pointer only if it is a function.
+       (See comment "this makes x/i main work").

+      /* In rvalue contexts, such as this, functions are coerced into
+        pointers to functions.  This makes "x/i main" work.  */
+      if (/* last_format == 'i'
+         && */ TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_FUNC
+         && VALUE_LVAL (val) == lval_memory)
+       next_address = VALUE_ADDRESS (val);
+      else
+       next_address = value_as_pointer (val);

looks we don't need these special handling today because we record
function address in value, so value_as_address can get the function
address.

Regression tested on x86_64-linux and ppc64-linux.

gdb:

2016-10-27  Yao Qi  <yao.qi@linaro.org>

	* printcmd.c (x_command): Don't call value_address.
---
 gdb/printcmd.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index a256bed..67fd5a3 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -1711,14 +1711,8 @@ x_command (char *exp, int from_tty)
       val = evaluate_expression (expr);
       if (TYPE_CODE (value_type (val)) == TYPE_CODE_REF)
 	val = coerce_ref (val);
-      /* In rvalue contexts, such as this, functions are coerced into
-         pointers to functions.  This makes "x/i main" work.  */
-      if (/* last_format == 'i'  && */ 
-	  TYPE_CODE (value_type (val)) == TYPE_CODE_FUNC
-	   && VALUE_LVAL (val) == lval_memory)
-	next_address = value_address (val);
-      else
-	next_address = value_as_address (val);
+
+      next_address = value_as_address (val);
 
       next_gdbarch = expr->gdbarch;
       do_cleanups (old_chain);
-- 
1.9.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]