This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[rfa/testsuite] Was: [rfc] Allow cast from int -> pointer
- To: GDB Patches <gdb-patches at sourceware dot cygnus dot com>
- Subject: [rfa/testsuite] Was: [rfc] Allow cast from int -> pointer
- From: Andrew Cagney <ac131313 at cygnus dot com>
- Date: Wed, 12 Jul 2000 18:29:05 +1000
- References: <396AF230.4864717E@cygnus.com>
Andrew Cagney wrote:
>
> 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.
FYI,
I've checked this in.
Now, is the attatched test case ok? It uses if/else - see comments for
details - better ways of doing this welcome.
Andrew
Wed Jul 12 18:14:29 2000 Andrew Cagney <cagney@b1.cygnus.com>
* gdb.base/exprs.exp: Test casts to a pointer including over and
underflow.
Index: testsuite/gdb.base/exprs.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/exprs.exp,v
retrieving revision 1.1.1.2
diff -p -r1.1.1.2 exprs.exp
*** exprs.exp 1999/06/28 16:03:12 1.1.1.2
--- exprs.exp 2000/07/12 08:16:15
***************
*** 1,4 ****
! # Copyright (C) 1988, 1990, 1991, 1992, 1994, 1997 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
--- 1,5 ----
! # Copyright (C) 1988, 1990, 1991, 1992, 1994, 1997, 2000 Free
! # Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
*************** test_expr "set variable v_unsigned_long=
*** 215,217 ****
--- 216,252 ----
test_expr "set variable v_unsigned_long=~0" "print v_unsigned_long != 0" "\\$\[0-9\]* = $true" "print v_unsigned_long != (unsigned long)~0" "\\$\[0-9\]* = $false" "print unsigned long != (~0)"
test_expr "set variable v_unsigned_long=~0" "print v_unsigned_long < 0" "\\$\[0-9\]* = $false" "print v_unsigned_long < 0x7FFF" "\\$\[0-9\]* = $false" "print unsigned long < (~0)"
test_expr "set variable v_unsigned_long=~0" "print v_unsigned_long > 0" "\\$\[0-9\]* = $true" "print v_unsigned_long > 0x7FFF" "\\$\[0-9\]* = $true" "print unsigned long > (~0)"
+ #
+ # Test expressions with casts to a pointer.
+ # NB: Some architectures convert a ``NULL'' pointer into
+ # something else. Don't simply test for 0.
+ #
+ test_expr "set variable v_signed_char = 0" "print (void*)v_signed_char" "\\$\[0-9\]* = .void \\*. $hex" "print (void*)v_signed_char"
+ test_expr "set variable v_signed_short = 0" "print (void*)v_signed_short" "\\$\[0-9\]* = .void \\*. $hex" "print (void*)v_signed_short"
+ test_expr "set variable v_signed_int = 0" "print (void*)v_signed_int" "\\$\[0-9\]* = .void \\*. $hex" "print (void*)v_signed_int"
+ test_expr "set variable v_signed_long = 0" "print (void*)v_signed_long" "\\$\[0-9\]* = .void \\*. $hex" "print (void*)v_signed_long"
+ test_expr "set variable v_unsigned_char = 0" "print (void*)v_unsigned_char" "\\$\[0-9\]* = .void \\*. $hex" "print (void*)v_unsigned_char"
+ test_expr "set variable v_unsigned_short = 0" "print (void*)v_unsigned_short" "\\$\[0-9\]* = .void \\*. $hex" "print (void*)v_unsigned_short"
+ test_expr "set variable v_unsigned_int = 0" "print (void*)v_unsigned_int" "\\$\[0-9\]* = .void \\*. $hex" "print (void*)v_unsigned_int"
+ test_expr "set variable v_unsigned_long = 0" "print (void*)v_unsigned_long" "\\$\[0-9\]* = .void \\*. $hex" "print (void*)v_unsigned_long"
+ #
+ # Test expressions with pointers out of range
+ # NB: For some architectures, all of sizeof(long),
+ # sizeof(long long) and sizeof(void*) are
+ # the same size and that size is determined
+ # at runtime.
+ #
+ gdb_test "\
+ if sizeof (long long) > sizeof (long)\n\
+ print (void*) ((long long) (unsigned long) -1 + 1)\n\
+ else\n\
+ echo Fake warning: value truncated\\n\n\
+ end" \
+ "warning: value truncated.*" "(void*) 0xffffffff + 1"
+ gdb_test "\
+ if sizeof (long long) > sizeof (long)\n\
+ print (void*) (~((long long)(unsigned long) -1) - 1)\n\
+ else\n\
+ echo Fake warning: value truncated\\n\n\
+ end" \
+ "warning: value truncated.*" "(void*) 0xffffffff00000000 - 1"