This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[rfc] Allow cast from int -> pointer
- To: GDB Patches <gdb-patches at sourceware dot cygnus dot com>
- Subject: [rfc] Allow cast from int -> pointer
- From: Andrew Cagney <ac131313 at cygnus dot com>
- Date: Tue, 11 Jul 2000 20:08:48 +1000
Does the attatched look ok? This is slightly modified from the original
that MichaelS sent to me - I've tried to avoid overflow problems.
Briefly the problem is with doing things like:
(gdb) print 0x1234
when ints, longs and pointers are strange sizes.
Andrew
Tue Jul 11 19:45:42 2000 Andrew Cagney <cagney@b1.cygnus.com>
* valops.c (value_cast): Allow cast from INT, ENUM or RANGE to
POINTER.
Index: valops.c
===================================================================
RCS file: /cvs/src/src/gdb/valops.c,v
retrieving revision 1.19
diff -p -r1.19 valops.c
*** valops.c 2000/07/09 05:15:50 1.19
--- valops.c 2000/07/11 10:04:23
*************** value_cast (type, arg2)
*** 290,295 ****
--- 290,309 ----
return value_from_longest (type, convert_to_boolean ?
(LONGEST) (longest ? 1 : 0) : longest);
}
+ else if (code1 == TYPE_CODE_PTR && (code2 == TYPE_CODE_INT ||
+ code2 == TYPE_CODE_ENUM ||
+ code2 == TYPE_CODE_RANGE))
+ {
+ int ptr_bit = HOST_CHAR_BIT * TYPE_LENGTH (type);
+ LONGEST longest = value_as_long (arg2);
+ if (ptr_bit < sizeof (LONGEST) * HOST_CHAR_BIT)
+ {
+ if (longest >= ((LONGEST) 1 << ptr_bit)
+ || longest <= -((LONGEST) 1 << ptr_bit))
+ warning ("value truncated");
+ }
+ return value_from_longest (type, longest);
+ }
else if (TYPE_LENGTH (type) == TYPE_LENGTH (type2))
{
if (code1 == TYPE_CODE_PTR && code2 == TYPE_CODE_PTR)