public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* FYI: inferior call of subprogram with pointer as argument
@ 2010-04-20 22:42 Joel Brobecker
  0 siblings, 0 replies; only message in thread
From: Joel Brobecker @ 2010-04-20 22:42 UTC (permalink / raw)
  To: gdb-patches

On AVR, the gdb view of an address is different from the machine view of the
same address.  We need to use special machinery implemented by value_pointer
to take the pointer of a value.

For instance, considering the following function...

  procedure Trace (Unit    : T; Message : String);

... where T is an access Integer (a pointer to an integer), call to this
function currently triggers the following warnings:

    (gdb) call debug.trace (me, "You")
    warning: Value does not fit in 16 bits.
    warning: Value does not fit in 16 bits.
    Tracing message: You

It could have been worse if Trace actually tried to dereference the Unit
argument...

gdb/ChangeLog (from Tristan Gingold):

	* ada-lang.c (value_pointer): New function.
	(make_array_descriptor): Call value_pointer to convert addresses to
	pointers.

Tested on avr and x86_64-linux. Checked in.

---
 gdb/ada-lang.c |   25 +++++++++++++++++++++++--
 1 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index c3cd971..d586b81 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -3863,6 +3863,25 @@ ada_convert_actual (struct value *actual, struct type *formal_type0,
   return actual;
 }
 
+/* Convert VALUE (which must be an address) to a CORE_ADDR that is a pointer of
+   type TYPE.  This is usually an inefficient no-op except on some targets
+   (such as AVR) where the representation of a pointer and an address
+   differs.  */
+
+static CORE_ADDR
+value_pointer (struct value *value, struct type *type)
+{
+  struct gdbarch *gdbarch = get_type_arch (type);
+  unsigned len = TYPE_LENGTH (type);
+  gdb_byte *buf = alloca (len);
+  CORE_ADDR addr;
+
+  addr = value_address (value);
+  gdbarch_address_to_pointer (gdbarch, type, buf, addr);
+  addr = extract_unsigned_integer (buf, len, gdbarch_byte_order (gdbarch));
+  return addr;
+}
+
 
 /* Push a descriptor of type TYPE for array value ARR on the stack at
    *SP, updating *SP to reflect the new descriptor.  Return either
@@ -3898,13 +3917,15 @@ make_array_descriptor (struct type *type, struct value *arr,
 
   modify_general_field (value_type (descriptor),
 			value_contents_writeable (descriptor),
-                        value_address (ensure_lval (arr, gdbarch, sp)),
+                        value_pointer (ensure_lval (arr, gdbarch, sp),
+                                       TYPE_FIELD_TYPE (desc_type, 0)),
                         fat_pntr_data_bitpos (desc_type),
                         fat_pntr_data_bitsize (desc_type));
 
   modify_general_field (value_type (descriptor),
 			value_contents_writeable (descriptor),
-                        value_address (bounds),
+                        value_pointer (bounds,
+                                       TYPE_FIELD_TYPE (desc_type, 1)),
                         fat_pntr_bounds_bitpos (desc_type),
                         fat_pntr_bounds_bitsize (desc_type));
 
-- 
1.6.3.3

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

only message in thread, other threads:[~2010-04-20 22:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-20 22:42 FYI: inferior call of subprogram with pointer as argument Joel Brobecker

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).