aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.base/exprs.exp
blob: ebce24fefa1a73e9cea923ebacd72795c8e75d79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#   Copyright 1988-2014 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
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# This file was written by Rob Savoye. (rob@cygnus.com)

#
# test running programs
#

standard_testfile .c

if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
     untested exprs.exp
     return -1
}

if [get_compiler_info] {
    return -1
}

clean_restart ${binfile}

#
# set it up at a breakpoint so we can play with the variable values
#

if ![runto_main] then {
    perror "couldn't run to breakpoint"
    continue
}

proc test_expr { args } {
    if { [llength $args] % 2 } {
	warning "an even # of arguments should be passed to test_expr"
    }
    set last_ent [expr [llength $args] - 1]
    set testname [lindex $args $last_ent]
    if [gdb_test [lindex $args 0] ".*" "$testname (setup)"] {
	gdb_suppress_tests
    }
    for {set x 1} {$x < $last_ent} {set x [expr $x + 2]} {
	if [gdb_test [lindex $args $x] [lindex $args [expr $x + 1]] "$testname ([lindex $args $x])"] {
	    gdb_suppress_tests
	}
    }
    gdb_stop_suppressing_tests
}
#
# test expressions with "char" types
#
test_expr "set variable v_char=127" "print v_char == 0" "\\$\[0-9\]* = $false"  "print v_char == 127" "\\$\[0-9\]* = $true"  "print char =="
test_expr "set variable v_char=127" "print v_char != 0" "\\$\[0-9\]* = $true"  "print v_char != 127" "\\$\[0-9\]* = $false"  "print char !="
test_expr "set variable v_char=127" "print v_char < 0" "\\$\[0-9\]* = $false"  "print v_char < 127" "\\$\[0-9\]* = $false"  "print char <"
test_expr "set variable v_char=127" "print v_char > 0" "\\$\[0-9\]* = $true"  "print v_char > 127" "\\$\[0-9\]* = $false"  "print char >"
#
# test expressions with "signed char" types
#
test_expr "set variable v_signed_char=127" "print v_signed_char == 0" "\\$\[0-9\]* = $false"  "print v_signed_char == 127" "\\$\[0-9\]* = $true"  "print signed char =="
test_expr "set variable v_signed_char=127" "print v_signed_char != 0" "\\$\[0-9\]* = $true"  "print v_signed_char != 127" "\\$\[0-9\]* = $false"  "print signed char !="
test_expr "set variable v_signed_char=127" "print v_signed_char < 0" "\\$\[0-9\]* = $false"  "print v_signed_char < 127" "\\$\[0-9\]* = $false"  "print signed char <"
test_expr "set variable v_signed_char=127" "print v_signed_char > 0" "\\$\[0-9\]* = $true"  "print v_signed_char > 127" "\\$\[0-9\]* = $false"  "print signed char >"
# make char a minus
test_expr "set variable v_signed_char=-1" "print v_signed_char == 0" "\\$\[0-9\]* = $false"  "print v_signed_char == -1" "\\$\[0-9\]* = $true"  "print signed char == (minus)"
test_expr "set variable v_signed_char=-1" "print v_signed_char != 0" "\\$\[0-9\]* = $true"  "print v_signed_char != -1" "\\$\[0-9\]* = $false"  "print signed char != (minus)"
test_expr "set variable v_signed_char=-1" "print v_signed_char < 0" "\\$\[0-9\]* = $true"  "print v_signed_char < 127" "\\$\[0-9\]* = $true"  "print signed char < (minus)"
test_expr "set variable v_signed_char=-1" "print v_signed_char > 0" "\\$\[0-9\]* = $false"  "print v_signed_char > 127" "\\$\[0-9\]* = $false"  "print signed char > (minus)"
#
# test expressions with "unsigned char" types
#
test_expr "set variable v_unsigned_char=127" "print v_unsigned_char == 0" "\\$\[0-9\]* = $false"  "print v_unsigned_char == 127" "\\$\[0-9\]* = $true"  "print unsigned char =="
test_expr "set variable v_unsigned_char=127" "print v_unsigned_char != 0" "\\$\[0-9\]* = $true"  "print v_unsigned_char != 127" "\\$\[0-9\]* = $false"  "print unsigned char !="
test_expr "set variable v_unsigned_char=127" "print v_unsigned_char < 0" "\\$\[0-9\]* = $false"  "print v_unsigned_char < 127" "\\$\[0-9\]* = $false"  "print unsigned char <"
test_expr "set variable v_unsigned_char=127" "print v_unsigned_char > 0" "\\$\[0-9\]* = $true"  "print v_unsigned_char > 127" "\\$\[0-9\]* = $false"  "print unsigned char >"
# make char a minus
test_expr "set variable v_unsigned_char=~0" "print v_unsigned_char == 0" "\\$\[0-9\]* = $false"  "print v_unsigned_char == ~0" "\\$\[0-9\]* = $false"  "print v_unsigned_char == (unsigned char)~0" "\\$\[0-9\]* = $true" "print unsigned char == (~0)"
test_expr "set variable v_unsigned_char=~0" "print v_unsigned_char != 0" "\\$\[0-9\]* = $true"  "print v_unsigned_char != (unsigned char)~0" "\\$\[0-9\]* = $false"  "print v_unsigned_char != ~0" "\\$\[0-9\]* = $true" "print unsigned char != (~0)"
test_expr "set variable v_unsigned_char=~0" "print v_unsigned_char < 0" "\\$\[0-9\]* = $false"  "print v_unsigned_char < 127" "\\$\[0-9\]* = $false"  "print unsigned char < (~0)"
test_expr "set variable v_unsigned_char=~0" "print v_unsigned_char > 0" "\\$\[0-9\]* = $true"  "print v_unsigned_char > 127" "\\$\[0-9\]* = $true"  "print unsigned char > (~0)"
#
# test expressions with "short" types
#
test_expr "set variable v_short=0x7FFF" "print v_short == 0" "\\$\[0-9\]* = $false"  "print v_short == 0x7FFF" "\\$\[0-9\]* = $true"  "print signed short =="
test_expr "set variable v_short=0x7FFF" "print v_short != 0" "\\$\[0-9\]* = $true"  "print v_short != 0x7FFF" "\\$\[0-9\]* = $false"  "print signed short !="
test_expr "set variable v_short=0x7FFF" "print v_short < 0" "\\$\[0-9\]* = $false"  "print v_short < 0x7FFF" "\\$\[0-9\]* = $false"  "print signed short <"
test_expr "set variable v_short=0x7FFF" "print v_short > 0" "\\$\[0-9\]* = $true"  "print v_short > 0x7FFF" "\\$\[0-9\]* = $false"  "print signed short >"
# make short a minus
test_expr "set variable v_short=-1" "print v_short == 0" "\\$\[0-9\]* = $false"  "print v_short == -1" "\\$\[0-9\]* = $true"  "print signed short == (minus)"
test_expr "set variable v_short=-1" "print v_short != 0" "\\$\[0-9\]* = $true"  "print v_short != -1" "\\$\[0-9\]* = $false"  "print signed short != (minus)"
test_expr "set variable v_short=-1" "print v_short < 0" "\\$\[0-9\]* = $true"  "print v_short < 0x7FFF" "\\$\[0-9\]* = $true"  "print signed short < (minus)"
test_expr "set variable v_short=-1" "print v_short > 0" "\\$\[0-9\]* = $false"  "print v_short > 0x7FFF" "\\$\[0-9\]* = $false"  "print signed short > (minus)"
#
# test expressions with "signed short" types
#
test_expr "set variable v_signed_short=0x7FFF" "print v_signed_short == 0" "\\$\[0-9\]* = $false"  "print v_signed_short == 0x7FFF" "\\$\[0-9\]* = $true"  "print signed signed short =="
test_expr "set variable v_signed_short=0x7FFF" "print v_signed_short != 0" "\\$\[0-9\]* = $true"  "print v_signed_short != 0x7FFF" "\\$\[0-9\]* = $false"  "print signed signed short !="
test_expr "set variable v_signed_short=0x7FFF" "print v_signed_short < 0" "\\$\[0-9\]* = $false"  "print v_signed_short < 0x7FFF" "\\$\[0-9\]* = $false"  "print signed signed short <"
test_expr "set variable v_signed_short=0x7FFF" "print v_signed_short > 0" "\\$\[0-9\]* = $true"  "print v_signed_short > 0x7FFF" "\\$\[0-9\]* = $false"  "print signed signed short >"
# make short a minus
test_expr "set variable v_signed_short=-1" "print v_signed_short == 0" "\\$\[0-9\]* = $false"  "print v_signed_short == -1" "\\$\[0-9\]* = $true"  "print signed signed short == (minus)"
test_expr "set variable v_signed_short=-1" "print v_signed_short != 0" "\\$\[0-9\]* = $true"  "print v_signed_short != -1" "\\$\[0-9\]* = $false"  "print signed signed short != (minus)"
test_expr "set variable v_signed_short=-1" "print v_signed_short < 0" "\\$\[0-9\]* = $true"  "print v_signed_short < 0x7FFF" "\\$\[0-9\]* = $true"  "print signed signed short < (minus)"
test_expr "set variable v_signed_short=-1" "print v_signed_short > 0" "\\$\[0-9\]* = $false"  "print v_signed_short > 0x7FFF" "\\$\[0-9\]* = $false"  "print signed signed short > (minus)"
#
# test expressions with "unsigned short" types
#
test_expr "set variable v_unsigned_short=0x7FFF" "print v_unsigned_short == 0" "\\$\[0-9\]* = $false"  "print v_unsigned_short == 0x7FFF" "\\$\[0-9\]* = $true"  "print unsigned short =="
test_expr "set variable v_unsigned_short=0x7FFF" "print v_unsigned_short != 0" "\\$\[0-9\]* = $true"  "print v_unsigned_short != 0x7FFF" "\\$\[0-9\]* = $false"  "print unsigned short !="
test_expr "set variable v_unsigned_short=0x7FFF" "print v_unsigned_short < 0" "\\$\[0-9\]* = $false"  "print v_unsigned_short < 0x7FFF" "\\$\[0-9\]* = $false"  "print unsigned short <"
test_expr "set variable v_unsigned_short=0x7FFF" "print v_unsigned_short > 0" "\\$\[0-9\]* = $true"  "print v_unsigned_short > 0x7FFF" "\\$\[0-9\]* = $false"  "print unsigned short >"
# make short a minus
test_expr "set variable v_unsigned_short=~0" "print v_unsigned_short == 0" "\\$\[0-9\]* = $false"  "print sizeof (v_unsigned_short) < sizeof (~0) && v_unsigned_short == ~0" "\\$\[0-9\]* = $false"  "print v_unsigned_short == (unsigned short)~0" "\\$\[0-9\]* = $true"  "print unsigned short == (~0)"
test_expr "set variable v_unsigned_short=~0" "print v_unsigned_short != 0" "\\$\[0-9\]* = $true"  "print v_unsigned_short != (unsigned short)~0" "\\$\[0-9\]* = $false"  "print unsigned short != (~0)"
test_expr "set variable v_unsigned_short=~0" "print v_unsigned_short < 0" "\\$\[0-9\]* = $false"  "print v_unsigned_short < 0x7FFF" "\\$\[0-9\]* = $false"  "print unsigned short < (~0)"
test_expr "set variable v_unsigned_short=~0" "print v_unsigned_short > 0" "\\$\[0-9\]* = $true"  "print v_unsigned_short > 0x7FFF" "\\$\[0-9\]* = $true"  "print unsigned short > (~0)"
#
# test expressions with "int" types
#
test_expr "set variable v_int=0x7FFF" "print v_int == 0" "\\$\[0-9\]* = $false"  "print v_int == 0x7FFF" "\\$\[0-9\]* = $true"  "print signed int =="
test_expr "set variable v_int=0x7FFF" "print v_int != 0" "\\$\[0-9\]* = $true"  "print v_int != 0x7FFF" "\\$\[0-9\]* = $false"  "print signed int !="
test_expr "set variable v_int=0x7FFF" "print v_int < 0" "\\$\[0-9\]* = $false"  "print v_int < 0x7FFF" "\\$\[0-9\]* = $false"  "print signed int <"
test_expr "set variable v_int=0x7FFF" "print v_int > 0" "\\$\[0-9\]* = $true"  "print v_int > 0x7FFF" "\\$\[0-9\]* = $false"  "print signed int >"
# make int a minus
test_expr "set variable v_int=-1" "print v_int == 0" "\\$\[0-9\]* = $false"  "print v_int == -1" "\\$\[0-9\]* = $true"  "print signed int == (minus)"
test_expr "set variable v_int=-1" "print v_int != 0" "\\$\[0-9\]* = $true"  "print v_int != -1" "\\$\[0-9\]* = $false"  "print signed int != (minus)"
test_expr "set variable v_int=-1" "print v_int < 0" "\\$\[0-9\]* = $true"  "print v_int < 0x7FFF" "\\$\[0-9\]* = $true"  "print signed int < (minus)"
test_expr "set variable v_int=-1" "print v_int > 0" "\\$\[0-9\]* = $false"  "print v_int > 0x7FFF" "\\$\[0-9\]* = $false"  "print signed int > (minus)"
#
# test expressions with "signed int" types
#
test_expr "set variable v_signed_int=0x7FFF" "print v_signed_int == 0" "\\$\[0-9\]* = $false"  "print v_signed_int == 0x7FFF" "\\$\[0-9\]* = $true"  "print signed signed int =="
test_expr "set variable v_signed_int=0x7FFF" "print v_signed_int != 0" "\\$\[0-9\]* = $true"  "print v_signed_int != 0x7FFF" "\\$\[0-9\]* = $false"  "print signed signed int !="
test_expr "set variable v_signed_int=0x7FFF" "print v_signed_int < 0" "\\$\[0-9\]* = $false"  "print v_signed_int < 0x7FFF" "\\$\[0-9\]* = $false"  "print signed signed int <"
test_expr "set variable v_signed_int=0x7FFF" "print v_signed_int > 0" "\\$\[0-9\]* = $true"  "print v_signed_int > 0x7FFF" "\\$\[0-9\]* = $false"  "print signed signed int >"
# make int a minus
test_expr "set variable v_signed_int=-1" "print v_signed_int == 0" "\\$\[0-9\]* = $false"  "print v_signed_int == -1" "\\$\[0-9\]* = $true"  "print signed signed int == (minus)"
test_expr "set variable v_signed_int=-1" "print v_signed_int != 0" "\\$\[0-9\]* = $true"  "print v_signed_int != -1" "\\$\[0-9\]* = $false"  "print signed signed int != (minus)"
test_expr "set variable v_signed_int=-1" "print v_signed_int < 0" "\\$\[0-9\]* = $true"  "print v_signed_int < 0x7FFF" "\\$\[0-9\]* = $true"  "print signed signed int < (minus)"
test_expr "set variable v_signed_int=-1" "print v_signed_int > 0" "\\$\[0-9\]* = $false"  "print v_signed_int > 0x7FFF" "\\$\[0-9\]* = $false"  "print signed signed int > (minus)"
#
# test expressions with "unsigned int" types
#
test_expr "set variable v_unsigned_int=0x7FFF" "print v_unsigned_int == 0" "\\$\[0-9\]* = $false"  "print v_unsigned_int == 0x7FFF" "\\$\[0-9\]* = $true"  "print unsigned int =="
test_expr "set variable v_unsigned_int=0x7FFF" "print v_unsigned_int != 0" "\\$\[0-9\]* = $true"  "print v_unsigned_int != 0x7FFF" "\\$\[0-9\]* = $false"  "print unsigned int !="
test_expr "set variable v_unsigned_int=0x7FFF" "print v_unsigned_int < 0" "\\$\[0-9\]* = $false"  "print v_unsigned_int < 0x7FFF" "\\$\[0-9\]* = $false"  "print unsigned int <"
test_expr "set variable v_unsigned_int=0x7FFF" "print v_unsigned_int > 0" "\\$\[0-9\]* = $true"  "print v_unsigned_int > 0x7FFF" "\\$\[0-9\]* = $false"  "print unsigned int >"
# make int a minus
test_expr "set variable v_unsigned_int=~0" "print v_unsigned_int == 0" "\\$\[0-9\]* = $false"  "print v_unsigned_int == ~0" "\\$\[0-9\]* = $true"  "print v_unsigned_int == (unsigned int)~0" "\\$\[0-9\]* = $true"  "print unsigned int == (~0)"
test_expr "set variable v_unsigned_int=~0" "print v_unsigned_int != 0" "\\$\[0-9\]* = $true"  "print v_unsigned_int != (unsigned int)~0" "\\$\[0-9\]* = $false"  "print unsigned int != (~0)"
test_expr "set variable v_unsigned_int=~0" "print v_unsigned_int < 0" "\\$\[0-9\]* = $false"  "print v_unsigned_int < 0x7FFF" "\\$\[0-9\]* = $false"  "print unsigned int < (~0)"
test_expr "set variable v_unsigned_int=~0" "print v_unsigned_int > 0" "\\$\[0-9\]* = $true"  "print v_unsigned_int > 0x7FFF" "\\$\[0-9\]* = $true"  "print unsigned int > (~0)"
#
# test expressions with "long" types
#
test_expr "set variable v_long=0x7FFF" "print v_long == 0" "\\$\[0-9\]* = $false"  "print v_long == 0x7FFF" "\\$\[0-9\]* = $true"  "print signed long =="
test_expr "set variable v_long=0x7FFF" "print v_long != 0" "\\$\[0-9\]* = $true"  "print v_long != 0x7FFF" "\\$\[0-9\]* = $false"  "print signed long !="
test_expr "set variable v_long=0x7FFF" "print v_long < 0" "\\$\[0-9\]* = $false"  "print v_long < 0x7FFF" "\\$\[0-9\]* = $false"  "print signed long <"
test_expr "set variable v_long=0x7FFF" "print v_long > 0" "\\$\[0-9\]* = $true"  "print v_long > 0x7FFF" "\\$\[0-9\]* = $false"  "print signed long >"
# make long a minus
test_expr "set variable v_long=-1" "print v_long == 0" "\\$\[0-9\]* = $false"  "print v_long == -1" "\\$\[0-9\]* = $true"  "print signed long == (minus)"
test_expr "set variable v_long=-1" "print v_long != 0" "\\$\[0-9\]* = $true"  "print v_long != -1" "\\$\[0-9\]* = $false"  "print signed long != (minus)"
test_expr "set variable v_long=-1" "print v_long < 0" "\\$\[0-9\]* = $true"  "print v_long < 0x7FFF" "\\$\[0-9\]* = $true"  "print signed long < (minus)"
test_expr "set variable v_long=-1" "print v_long > 0" "\\$\[0-9\]* = $false"  "print v_long > 0x7FFF" "\\$\[0-9\]* = $false"  "print signed long > (minus)"
#
# test expressions with "signed long" types
#
test_expr "set variable v_signed_long=0x7FFF" "print v_signed_long == 0" "\\$\[0-9\]* = $false"  "print v_signed_long == 0x7FFF" "\\$\[0-9\]* = $true"  "print signed signed long =="
test_expr "set variable v_signed_long=0x7FFF" "print v_signed_long != 0" "\\$\[0-9\]* = $true"  "print v_signed_long != 0x7FFF" "\\$\[0-9\]* = $false"  "print signed signed long !="
test_expr "set variable v_signed_long=0x7FFF" "print v_signed_long < 0" "\\$\[0-9\]* = $false"  "print v_signed_long < 0x7FFF" "\\$\[0-9\]* = $false"  "print signed signed long <"
test_expr "set variable v_signed_long=0x7FFF" "print v_signed_long > 0" "\\$\[0-9\]* = $true"  "print v_signed_long > 0x7FFF" "\\$\[0-9\]* = $false"  "print signed signed long >"
# make long a minus
test_expr "set variable v_signed_long=-1" "print v_signed_long == 0" "\\$\[0-9\]* = $false"  "print v_signed_long == -1" "\\$\[0-9\]* = $true"  "print signed signed long == (minus)"
test_expr "set variable v_signed_long=-1" "print v_signed_long != 0" "\\$\[0-9\]* = $true"  "print v_signed_long != -1" "\\$\[0-9\]* = $false"  "print signed signed long != (minus)"
test_expr "set variable v_signed_long=-1" "print v_signed_long < 0" "\\$\[0-9\]* = $true"  "print v_signed_long < 0x7FFF" "\\$\[0-9\]* = $true"  "print signed signed long < (minus)"
test_expr "set variable v_signed_long=-1" "print v_signed_long > 0" "\\$\[0-9\]* = $false"  "print v_signed_long > 0x7FFF" "\\$\[0-9\]* = $false"  "print signed signed long > (minus)"
#
# test expressions with "unsigned long" types
#
test_expr "set variable v_unsigned_long=0x7FFF" "print v_unsigned_long == 0" "\\$\[0-9\]* = $false"  "print v_unsigned_long == 0x7FFF" "\\$\[0-9\]* = $true"  "print unsigned long =="
test_expr "set variable v_unsigned_long=0x7FFF" "print v_unsigned_long != 0" "\\$\[0-9\]* = $true"  "print v_unsigned_long != 0x7FFF" "\\$\[0-9\]* = $false"  "print unsigned long !="
test_expr "set variable v_unsigned_long=0x7FFF" "print v_unsigned_long < 0" "\\$\[0-9\]* = $false"  "print v_unsigned_long < 0x7FFF" "\\$\[0-9\]* = $false"  "print unsigned long <"
test_expr "set variable v_unsigned_long=0x7FFF" "print v_unsigned_long > 0" "\\$\[0-9\]* = $true"  "print v_unsigned_long > 0x7FFF" "\\$\[0-9\]* = $false"  "print unsigned long >"
# make long a minus
test_expr "set variable v_unsigned_long=~0" "print v_unsigned_long == 0" "\\$\[0-9\]* = $false"  "print v_unsigned_long == ~0" "\\$\[0-9\]* = $true"  "print v_unsigned_long == (unsigned long)~0" "\\$\[0-9\]* = $true"  "print unsigned long == (~0)"
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 so this test can not work.
#
gdb_test_multiple "print sizeof (long long) > sizeof (long)" \
    "sizeof long long > sizeof long" {
    -re "\\$\[0-9\]* = $true.*$gdb_prompt" {
	set ok 1
	pass "sizeof (long long) > sizeof (long) (true)"
    }
    -re "\\$\[0-9\]* = $false.*$gdb_prompt" {
	set ok 0
	pass "sizeof (long long) > sizeof (long) (false)"
    }
}
if [expr ! $ok] { setup_xfail "*-*-*" }
gdb_test "print (void*) ((long long) (unsigned long) -1 + 1)" \
	"warning: value truncated.*" "truncate (void*) 0x00000000ffffffff + 1"
if [expr ! $ok] { setup_xfail "*-*-*" }
gdb_test "print (void*) (~((long long)(unsigned long) -1) - 1)" \
	"warning: value truncated.*" "truncate (void*) 0xffffffff00000000 - 1"

# String concatentation.
test_expr "print \"x\" \"y\"" "\\$\[0-9\]* = \"xy\""
test_expr "print \"x\" \"y\" \"z\"" "\\$\[0-9\]* = \"xyz\""

# Enum formatting tests.
test_expr "print red" "\\$\[0-9\]* = red"
gdb_test "set output-radix 8" ".*"
test_expr "print red" "\\$\[0-9\]* = red"
test_expr "print/d red" "\\$\[0-9\]* = 0"
gdb_test "set output-radix 10" ".*"

# Pre-/post in-/decrement tests.
gdb_test "set variable v_int = 1" ""
gdb_test "print v_int++" "\\$\[0-9\]* = 1"
gdb_test "print ++v_int" "\\$\[0-9\]* = 3"
gdb_test "print v_int--" "\\$\[0-9\]* = 3"
gdb_test "print --v_int" "\\$\[0-9\]* = 1"
gdb_test "print v_int++ = 5" "Left operand of assignment is not an lvalue."
gdb_test "print v_int-- = 5" "Left operand of assignment is not an lvalue."

# initialized array
gdb_test {print v_int_array_init} { = \{10, 20\}}
gdb_test {print *v_int_array_init@1} { = \{10\}}
gdb_test {print *v_int_array_init@2} { = \{10, 20\}}
gdb_test {print v_int_array_init[0]@1} { = \{10\}}
gdb_test {print v_int_array_init[0]@2} { = \{10, 20\}}
gdb_test {print v_int_array_init[1]@1} { = \{20\}}

# gdb's {} extension
gdb_test_no_output "set variable v_short_array\[0\] = 42"
gdb_test "print {short} v_short_array" "$decimal = 42"

# Regression tests for cast to void.
gdb_test "print (void) v_int_pointer" " = void"
gdb_test "print & (void) v_char" "value not located in memory."

# Regression test for "&&".
gdb_test "print null_t_struct && null_t_struct->v_int_member == 0" \
    " = 0"