This is the mail archive of the gdb-patches@sources.redhat.com 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]

Re: [RFA] string_to_core_addr fix


On Thursday 10 October 2002 03:40 pm, Kevin Buettner wrote:
> On Oct 10,  3:07pm, Martin M. Hunt wrote:
> > This is necessary for 64-bit targets where sometimes 32-bit
> > values must be sign-extended to 64-bits.
> >
> > 2002-10-10  Martin M. Hunt  <hunt@redhat.com>
> >
> > 	* utils.c (string_to_core_addr): After turning string into
> > 	a number, convert to a CORE_ADDR using POINTER_TO_ADDRESS
> > 	which will do necessary sign-extension, etc.
> >
> > Index: utils.c
> > ===================================================================
> > RCS file: /cvs/src/src/gdb/utils.c,v
> > retrieving revision 1.80
> > diff -u -p -r1.80 utils.c
> > --- utils.c	20 Sep 2002 00:24:01 -0000	1.80
> > +++ utils.c	10 Oct 2002 22:06:50 -0000
> > @@ -2649,7 +2649,7 @@ string_to_core_addr (const char *my_stri
> >  	    internal_error (__FILE__, __LINE__, "invalid decimal");
> >  	}
> >      }
> > -  return addr;
> > +  return POINTER_TO_ADDRESS (builtin_type_void_data_ptr, &addr);
> >  }
> >
> >  char *
>
> While I agree that something like this is needed, I'm not convinced that
> using POINTER_TO_ADDRESS on a CORE_ADDR is right.  By default,
> unsigned_pointer_to_address() is used.  It looks like this:
>
>     /* Given a pointer of type TYPE in target form in BUF, return the
>        address it represents.  */
>     CORE_ADDR
>     unsigned_pointer_to_address (struct type *type, void *buf)
>     {
>       return extract_address (buf, TYPE_LENGTH (type));
>     }
>
> The problem is that ``addr'' is an address in host format (i.e, a
> CORE_ADDR), not a target address.  I suspect you'll get incorrect results
> if the host and target are of different endianness or if sizeof (CORE_ADDR)
> != TYPE_LENGTH (type).
>
> I think you could get the right results by writing addr to a buffer
> (maybe using store_typed_address) and then using extract_typed_address(),
> but there may be a more straightforward way to do it.

For years we used parse_and_eval_address() in Insight until earlier this year 
when those calls were replaced with string_to_core_addr(), breaking all mips 
targets.  parse_and_eval_address() internally calls INTEGER_TO_ADDRESS() so I 
probably should use that. In fact I decided to just do what 
parse_and_eval_address() did but apparently submitted the wrong version.

Revised patch attached.

Martin

Index: utils.c
===================================================================
RCS file: /cvs/src/src/gdb/utils.c,v
retrieving revision 1.80
diff -u -p -r1.80 utils.c
--- utils.c	20 Sep 2002 00:24:01 -0000	1.80
+++ utils.c	11 Oct 2002 04:29:51 -0000
@@ -2649,6 +2649,8 @@ string_to_core_addr (const char *my_stri
 	    internal_error (__FILE__, __LINE__, "invalid decimal");
 	}
     }
+  if (INTEGER_TO_ADDRESS_P ())
+    addr = INTEGER_TO_ADDRESS (builtin_type_void_data_ptr, &addr); 
   return addr;
 }
 

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