public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Don't call value_address in x_command
@ 2016-10-27 13:57 Yao Qi
  0 siblings, 0 replies; only message in thread
From: Yao Qi @ 2016-10-27 13:57 UTC (permalink / raw)
  To: gdb-patches

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2016-10-27 13:57 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-27 13:57 [PATCH] Don't call value_address in x_command Yao Qi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).