Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: Mark Kettenis <mark.kettenis@xs4all.nl>,
	        Jim Blandy <jimb@codesourcery.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [patch] Cut memory address width
Date: Thu, 28 Sep 2006 17:27:00 -0000	[thread overview]
Message-ID: <20060928172725.GA18498@host0.dyn.jankratochvil.net> (raw)
In-Reply-To: <m3mz8lyuxg.fsf@codesourcery.com> <200609271901.k8RJ1BD1030473@elgar.sibelius.xs4all.nl>

[-- Attachment #1: Type: text/plain, Size: 990 bytes --]

Hi,

On Wed, 27 Sep 2006 21:01:11 +0200, Mark Kettenis wrote:
...
> This should almost certainly be handled in value.c:value_as_address().
> You could add an i386-specific integer_to_address(), that would
> truncate the address to 32 bits.  But in fact, I can't think of a
> reason why truncating to the size of a pointer shouldn't be the
> default behaviour.

Made the default way, I also do not see the reason to keep larger addresses.
There is some note about `ADDR_BITS_REMOVE' but I believe it is only about the
lowest (0-2 or so) bits and the high bits should not hurt anyone.


On Wed, 27 Sep 2006 21:24:27 +0200, Jim Blandy wrote:
...
> Just as a sanity check: what does 'show architecture' say when you're
> debugging an i386 inferior on gdb/amd64?

as expected:
	The target architecture is set automatically (currently i386)

...
> Is there some code there assuming that host == target?

I do not believe so, it is handled everything by `LONGEST' / `unpack_long'.



Regards,
Jan

[-- Attachment #2: gdb-6.5-memory-address-width-v2.patch --]
[-- Type: text/plain, Size: 3734 bytes --]

2006-09-28  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb/utils.c (paddress): Disable cutting of the printed addresses
	to the target's address bit size; user wants to see everything.
	* gdb/value.c (value_as_address_core): Original `value_as_address'.
	(value_as_address): New `value_as_address' wrapper - cut memory address
	to the target's address bit size, bugreport by John Reiser.


Index: gdb/utils.c
===================================================================
RCS file: /cvs/src/src/gdb/utils.c,v
retrieving revision 1.169
diff -u -p -r1.169 utils.c
--- gdb/utils.c	21 Sep 2006 13:50:51 -0000	1.169
+++ gdb/utils.c	28 Sep 2006 17:06:03 -0000
@@ -2596,6 +2596,14 @@ paddr_nz (CORE_ADDR addr)
 const char *
 paddress (CORE_ADDR addr)
 {
+  /* Do no cut the address as the user should see all the information
+     available.  Otherwise 64-bit gdb debugging 32-bit inferior would
+     report for `x/x 0xffffffffffffce70' error
+     `Cannot access memory at 0xffffce70' while the error occured just
+     because of the higher order bits 0xffffffff00000000 there.
+     This specific error no longer occurs as the address is now cut
+     during execution by `value_as_address'.  */
+#if 0
   /* Truncate address to the size of a target address, avoiding shifts
      larger or equal than the width of a CORE_ADDR.  The local
      variable ADDR_BIT stops the compiler reporting a shift overflow
@@ -2609,6 +2617,8 @@ paddress (CORE_ADDR addr)
 
   if (addr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT))
     addr &= ((CORE_ADDR) 1 << addr_bit) - 1;
+#endif
+
   return hex_string (addr);
 }
 
Index: gdb/value.c
===================================================================
RCS file: /cvs/src/src/gdb/value.c,v
retrieving revision 1.36
diff -u -p -r1.36 value.c
--- gdb/value.c	31 Mar 2006 10:36:18 -0000	1.36
+++ gdb/value.c	28 Sep 2006 17:06:03 -0000
@@ -950,11 +950,10 @@ value_as_double (struct value *val)
     error (_("Invalid floating value found in program."));
   return foo;
 }
-/* Extract a value as a C pointer. Does not deallocate the value.  
-   Note that val's type may not actually be a pointer; value_as_long
-   handles all the cases.  */
-CORE_ADDR
-value_as_address (struct value *val)
+
+/* See `value_as_address' below - core of value to C pointer extraction.  */
+static CORE_ADDR
+value_as_address_core (struct value *val)
 {
   /* Assume a CORE_ADDR can fit in a LONGEST (for now).  Not sure
      whether we want this to be true eventually.  */
@@ -1054,6 +1053,33 @@ value_as_address (struct value *val)
   return unpack_long (value_type (val), value_contents (val));
 #endif
 }
+
+/* Extract a value as a C pointer. Does not deallocate the value.  
+   Note that val's type may not actually be a pointer; value_as_long
+   handles all the cases.  */
+CORE_ADDR
+value_as_address (struct value *val)
+{
+  CORE_ADDR addr;
+
+  addr = value_as_address_core (val);
+
+  /* Truncate address to the size of a target address, avoiding shifts
+     larger or equal than the width of a CORE_ADDR.  The local
+     variable ADDR_BIT stops the compiler reporting a shift overflow
+     when it won't occur. */
+  /* NOTE: This assumes that the significant address information is
+     kept in the least significant bits of ADDR - the upper bits were
+     either zero or sign extended.  Should ADDRESS_TO_POINTER() or
+     some ADDRESS_TO_PRINTABLE() be used to do the conversion?  */
+
+  int addr_bit = TARGET_ADDR_BIT;
+
+  if (addr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT))
+    addr &= ((CORE_ADDR) 1 << addr_bit) - 1;
+
+  return addr;
+}
 \f
 /* Unpack raw data (copied from debugee, target byte order) at VALADDR
    as a long, or as a double, assuming the raw data is described

  reply	other threads:[~2006-09-28 17:27 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-27 16:15 Jan Kratochvil
2006-09-27 18:20 ` Michael Snyder
2006-09-27 18:22   ` Daniel Jacobowitz
2006-09-27 18:37     ` Jan Kratochvil
2006-09-27 18:55       ` Daniel Jacobowitz
2006-09-27 20:19         ` Jim Blandy
2006-09-27 19:01 ` Mark Kettenis
2006-09-28 17:27   ` Jan Kratochvil [this message]
2006-10-05 22:26     ` Daniel Jacobowitz
2006-09-27 19:23 ` Jim Blandy

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=20060928172725.GA18498@host0.dyn.jankratochvil.net \
    --to=jan.kratochvil@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=jimb@codesourcery.com \
    --cc=mark.kettenis@xs4all.nl \
    /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