2004-01-15 Michael Chastain <mec.gnu@mindspring.com>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / setvar.exp
CommitLineData
091c48f6
MC
1# Copyright 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2001
2# Free Software Foundation, Inc.
c906108c
SS
3
4# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 2 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program; if not, write to the Free Software
16# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18# Please email any bugs, comments, and/or additions to this file to:
19# bug-gdb@prep.ai.mit.edu
20
21# Copyright (C) 1988, 1990, 1991, 1992, 1994, 1995
22# Free Software Foundation, Inc.
23
24# This program is free software; you can redistribute it and/or modify
25# it under the terms of the GNU General Public License as published by
26# the Free Software Foundation; either version 2 of the License, or
27# (at your option) any later version.
28#
29# This program is distributed in the hope that it will be useful,
30# but WITHOUT ANY WARRANTY; without even the implied warranty of
31# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32# GNU General Public License for more details.
33#
34# You should have received a copy of the GNU General Public License
35# along with this program; if not, write to the Free Software
36# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
37
38# Please email any bugs, comments, and/or additions to this file to:
39# bug-gdb@prep.ai.mit.edu
40
41# This file was written by Rob Savoye. (rob@cygnus.com)
42
43if $tracelevel then {
44 strace $tracelevel
45 }
46
47#
48# test running programs
49#
50set prms_id 0
51set bug_id 0
52
53set testfile "setvar"
54set srcfile ${testfile}.c
55set binfile ${objdir}/${subdir}/${testfile}
56if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
57 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
58}
59
60# Create and source the file that provides information about the compiler
61# used to compile the test case.
62if [get_compiler_info ${binfile}] {
63 return -1;
64}
65
66gdb_exit
67gdb_start
68gdb_reinitialize_dir $srcdir/$subdir
69gdb_load $binfile
70
71#
72# set it up at a breakpoint so we canplay with the variable values
73#
74send_gdb "set print sevenbit-strings\n" ; gdb_expect -re "$gdb_prompt $"
75
76if ![runto_main] then {
77 perror "couldn't run to breakpoint"
78 continue
79}
80
81# Determine expected output for unsigned long variables,
82# the output varies with sizeof (unsigned long).
83
84set ulong_minus_1 4294967295
85set ulong_minus_456 4294966840
86send_gdb "print sizeof (unsigned long)\n"
87gdb_expect {
88 -re ".\[0-9\]* = 4.*$gdb_prompt $" {}
89 -re ".\[0-9\]* = 8.*$gdb_prompt $" {
90 set ulong_minus_1 18446744073709551615
91 set ulong_minus_456 18446744073709551160
92 }
93 -re ".*$gdb_prompt $" {
94 fail "getting sizeof unsigned long"
95 }
96 default { fail "(timeout) getting sizeof unsigned long" }
97}
98
99proc test_set { args } {
100 global gdb_prompt
101
102 set length [expr [llength $args] - 1];
103 set message "[lindex $args $length]";
104 set final [expr $length - 2];
105 set count 1;
106
107 # Set up the variables.
108 for {set x 0;} {$x < $length} {incr x;} {
109 if { "[lindex $args $x]" != "" } {
110 set arg [lindex $args $x];
111 if { ($x == $final) || ([string first ".*" [lindex $args [expr $x + 1]]] >= 0) } {
112 set match [lindex $args [expr $x + 1]];
113 if { $count == 1 } {
114 set mess "$message"
115 } else {
116 set mess "$message (#$count)";
117 }
118 incr count;
119 incr x;
120 } else {
121 set mess "";
122 set match ""
123 }
124 verbose "doing $arg $match"
125 if [gdb_test "$arg" "$match" "$mess"] {
126 fail "$message -- $match";
127 return 1;
128 }
129 }
130 }
131 return 0;
132}
133
134#
135# test "set variable" for type "char"
136#
137# Because bare char types can be either signed or unsigned, we just test the
138# range of values that are common to both (0-127).
139#
140
99ebe9ac 141test_set "set variable v_char=0" "print v_char" ".\[0-9\]* = 0 \'.0\'" "set variable char=0"
c906108c
SS
142test_set "set variable v_char=1" "print v_char" ".\[0-9\]* = 1 \'.001\'" "set variable char=1"
143test_set "set variable v_char=27" "print v_char" ".\[0-9\]* = 27 \'.e\'" "set variable char=27 (Esc)"
144test_set "set variable v_char=32" "print v_char" ".\[0-9\]* = 32 \' \'" "set variable char=32 (SPC)"
145test_set "set variable v_char=65" "print v_char" ".\[0-9\]* = 65 \'A\'" "set variable char=65 ('A')"
146test_set "set variable v_char=97" "print v_char" ".\[0-9\]* = 97 \'a\'" "set variable char=97 ('a')"
147test_set "set variable v_char=126" "print v_char" ".\[0-9\]* = 126 \'~\'" "set variable char=126 ('~')"
148test_set "set variable v_char=127" "print v_char" ".\[0-9\]* = 127 \'.177\'" "set variable char=127 (8-bit)"
149#
150# test "set variable" for type "signed char"
151#
99ebe9ac 152test_set "set variable v_char=0" "print v_signed_char" ".\[0-9\]* = 0 \'.0\'" "set variable signed char=0"
c906108c
SS
153test_set "set variable v_signed_char=1" "print v_signed_char" ".\[0-9\]* = 1 \'.001\'" "set variable signed char=1"
154test_set "set variable v_signed_char=27" "print v_signed_char" ".\[0-9\]* = 27 \'.e\'" "set variable signed char=27 (Esc)"
155test_set "set variable v_signed_char=32" "print v_signed_char" ".\[0-9\]* = 32 \' \'" "set variable signed char=32 (SPC)"
156test_set "set variable v_signed_char=65" "print v_signed_char" ".\[0-9\]* = 65 \'A\'" "set variable signed char=65 ('A')"
157test_set "set variable v_signed_char=97" "print v_signed_char" ".\[0-9\]* = 97 \'a\'" "set variable signed char=97 ('a')"
158test_set "set variable v_signed_char=126" "print v_signed_char" ".\[0-9\]* = 126 \'~\'" "set variable signed char=126 ('~')"
159test_set "set variable v_signed_char=127" "print v_signed_char" ".\[0-9\]* = 127 \'.177\'" "set variable signed char=127 (8-bit)"
160gdb_test "set variable v_signed_char=-1" ""
161if {!$gcc_compiled} then { setup_xfail "mips-sgi-irix4*" }
162gdb_test "print v_signed_char" ".\[0-9\]* = -1 \'.377\'" \
163 "set variable signed char=-1 (-1)"
164gdb_test "set variable v_signed_char=0xFF" ""
165if {!$gcc_compiled} then { setup_xfail "mips-sgi-irix4*" }
166gdb_test "print v_signed_char" ".\[0-9\]* = -1 \'.377\'" \
167 "set variable signed char=0xFF (0xFF)"
168#
169# test "set variable" for type "unsigned char"
170#
99ebe9ac 171test_set "set variable v_unsigned_char=0" "print v_unsigned_char" ".\[0-9\]* = 0 \'.0\'" "set variable unsigned char=0"
c906108c
SS
172test_set "set variable v_unsigned_char=1" "print v_unsigned_char" ".\[0-9\]* = 1 \'.001\'" "set variable unsigned char=1"
173test_set "set variable v_unsigned_char=27" "print v_unsigned_char" ".\[0-9\]* = 27 \'.e\'" "set variable unsigned char=27 (Esc)"
174test_set "set variable v_unsigned_char=32" "print v_unsigned_char" ".\[0-9\]* = 32 \' \'" "set variable unsigned char=32 (SPC)"
175test_set "set variable v_unsigned_char=65" "print v_unsigned_char" ".\[0-9\]* = 65 \'A\'" "set variable unsigned char=65 ('A')"
176test_set "set variable v_unsigned_char=97" "print v_unsigned_char" ".\[0-9\]* = 97 \'a\'" "set variable unsigned char=97 ('a')"
177test_set "set variable v_unsigned_char=126" "print v_unsigned_char" ".\[0-9\]* = 126 \'~\'" "set variable unsigned char=126 ('~')"
178test_set "set variable v_unsigned_char=~0" "print v_unsigned_char" ".\[0-9\]* = 255 \'.377\'" "set variable unsigned char=255 (8-bit)"
179#
180# test "set variable" for type "short"
181#
182test_set "set variable v_short=0" "print v_short" ".\[0-9\]* = 0" "set variable short=0"
183test_set "set variable v_short=1" "print v_short" ".\[0-9\]* = 1" "set variable short=1"
184test_set "set variable v_short=-1" "print v_short" ".\[0-9\]* = -1" "set variable short=-1 (minus)"
185#
186# test "set variable" for type "signed short"
187#
188test_set "set variable v_signed_short=0" "print v_signed_short" ".\[0-9\]* = 0" "set variable signed short=0"
189test_set "set variable v_signed_short=1" "print v_signed_short" ".\[0-9\]* = 1" "set variable signed short=1"
190test_set "set variable v_signed_short=-1" "print v_signed_short" ".\[0-9\]* = -1" "set variable signed short=-1 (minus)"
191#
192# test "set variable" for type "unsigned short"
193#
194test_set "set variable v_unsigned_short=0" "print v_unsigned_short" ".\[0-9\]* = 0" "set variable unsigned short=0"
195test_set "set variable v_unsigned_short=1" "print v_unsigned_short" ".\[0-9\]* = 1" "set variable unsigned short=1"
196test_set "set variable v_unsigned_short=~0" "print v_unsigned_short" ".\[0-9\]* = 65535" "set variable unsigned short=~0 (minus)"
197#
198# test "set variable" for type "int"
199#
200test_set "set variable v_int=0" "print v_int" ".\[0-9\]* = 0" "set variable int=0"
201test_set "set variable v_int=1" "print v_int" ".\[0-9\]* = 1" "set variable int=1"
202test_set "set variable v_int=-1" "print v_int" ".\[0-9\]* = -1" "set variable int=-1 (minus)"
203#
204# test "set variable" for type "signed int"
205#
206test_set "set variable v_signed_int=0" "print v_signed_int" ".\[0-9\]* = 0" "set variable signed int=0"
207test_set "set variable v_signed_int=1" "print v_signed_int" ".\[0-9\]* = 1" "set variable signed int=1"
208test_set "set variable v_signed_int=-1" "print v_signed_int" ".\[0-9\]* = -1" "set variable signed int=-1 (minus)"
209#
210# test "set variable" for type "unsigned int"
211#
212test_set "set variable v_unsigned_int=0" "print v_unsigned_int" ".\[0-9\]* = 0" "set variable unsigned int=0"
213test_set "set variable v_unsigned_int=1" "print v_unsigned_int" ".\[0-9\]* = 1" "set variable unsigned int=1"
214test_set "set variable v_unsigned_int=~0" "print v_unsigned_int" ".\[0-9\]* = (4294967295|65535)" "set variable unsigned int=~0 (minus)"
215#test_set ".\[0-9\]* = 65535" "set variable unsigned int=~0 (minus)"
216#
217# test "set variable" for type "long"
218#
219test_set "set variable v_long=0" "print v_long" ".\[0-9\]* = 0" "set variable long=0"
220test_set "set variable v_long=1" "print v_long" ".\[0-9\]* = 1" "set variable long=1"
221test_set "set variable v_long=-1" "print v_long" ".\[0-9\]* = -1" "set variable long=-1 (minus)"
222#
223# test "set variable" for type "signed long"
224#
225test_set "set variable v_signed_long=0" "print v_signed_long" ".\[0-9\]* = 0" "set variable signed long=0"
226test_set "set variable v_signed_long=1" "print v_signed_long" ".\[0-9\]* = 1" "set variable signed long=1"
227test_set "set variable v_signed_long=-1" "print v_signed_long" ".\[0-9\]* = -1" "set variable signed long=-1 (minus)"
228#
229# test "set variable" for type "unsigned long"
230#
231test_set "set variable v_unsigned_long=0" "print v_unsigned_long" ".\[0-9\]* = 0" "set variable unsigned long=0"
232test_set "set variable v_unsigned_long=1" "print v_unsigned_long" ".\[0-9\]* = 1" "set variable unsigned long=1"
233test_set "set variable v_unsigned_long=~0" "print v_unsigned_long" ".\[0-9\]* = $ulong_minus_1" "set variable unsigned long=~0 (minus)"
234#
235# test "set variable" for type "float"
236#
237test_set "set variable v_float=0.0" "print v_float" ".\[0-9\]* = 0" "set variable float=0"
238test_set "set variable v_float=1.0" "print v_float" ".\[0-9\]* = 1" "set variable float=1"
239test_set "set variable v_float=-1.0" "print v_float" ".\[0-9\]* = -1" "set variable float=-1 (minus)"
240#
241# test "set variable" for type "double"
242#
243test_set "set variable v_double=0.0" "print v_double" ".\[0-9\]* = 0" "set variable double=0"
244test_set "set variable v_double=1.0" "print v_double" ".\[0-9\]* = 1" "set variable double=1"
245test_set "set variable v_double=-1.0" "print v_double" ".*.\[0-9\]* = -1" "set variable double=-1 (minus)"
246#
247# test "set variable" for "char array[2]"
248#
249test_set "set variable v_char_array\[0\]='h'" "set variable v_char_array\[1\]='i'" "print v_char_array" ".*.\[0-9\]* =.*\"hi\"" "set variable char array=\"hi\" (string)"
250#
251# test "set variable" for "signed char array[2]"
252#
253test_set "set variable v_signed_char_array\[0\]='h'" "set variable v_signed_char_array\[1\]='i'" "print v_signed_char_array" ".*.\[0-9\]* =.*\"hi\"" "set variable signed char array=\"hi\" (string)"
254#
255# test "set variable" for "unsigned char array[2]"
256#
257test_set "set variable v_unsigned_char_array\[0\]='h'" "set variable v_unsigned_char_array\[1\]='i'" "print v_unsigned_char_array" ".*.\[0-9\]* =.*\"hi\"" "set variable unsigned char array=\"hi\" (string)"
258#
259# test "set variable" for "short array[2]"
260#
49c890fc 261test_set "set variable v_short_array\[0\]=123" "set variable v_short_array\[1\]=-456" "print v_short_array" ".*.\[0-9\]* =.*\\{123,.*-456\\}" "set variable short array"
c906108c
SS
262#
263# test "set variable" for "signed short array[2]"
264#
49c890fc 265test_set "set variable v_signed_short_array\[0\]=123" "set variable v_signed_short_array\[1\]=-456" "print v_signed_short_array" ".*.\[0-9\]* =.*\\{123,.*-456\\}" "set variable signed short array"
c906108c
SS
266#
267# test "set variable" for "unsigned short array[2]"
268#
49c890fc 269test_set "set variable v_unsigned_short_array\[0\]=123" "set variable v_unsigned_short_array\[1\]=-456" "print v_unsigned_short_array" ".*.\[0-9\]* =.*\\{123,.*65080\\}" "set variable unsigned short array"
c906108c
SS
270#
271# test "set variable" for "int array[2]"
272#
49c890fc 273test_set "set variable v_int_array\[0\]=123" "set variable v_int_array\[1\]=-456" "print v_int_array" ".*.\[0-9\]* =.*\\{123,.*-456\\}" "set variable int array"
c906108c
SS
274#
275# test "set variable" for "signed int array[2]"
276#
49c890fc 277test_set "set variable v_signed_int_array\[0\]=123" "set variable v_signed_int_array\[1\]=-456" "print v_signed_int_array" ".*.\[0-9\]* =.*\\{123,.*-456\\}" "set variable signed int array"
c906108c
SS
278#
279# test "set variable" for "unsigned int array[2]"
280#
49c890fc 281test_set "set variable v_unsigned_int_array\[0\]=123" "set variable v_unsigned_int_array\[1\]=-456" "print v_unsigned_int_array" ".*.\[0-9\]* =.*\\{123,.*(4294966840|65080)\\}" "set variable unsigned int array"
c906108c
SS
282#
283# test "set variable" for "long array[2]"
284#
49c890fc 285test_set "set variable v_long_array\[0\]=123" "set variable v_long_array\[1\]=-456" "print v_long_array" ".*.\[0-9\]* =.*\\{123,.*-456\\}" "set variable long array"
c906108c
SS
286#
287# test "set variable" for "signed long array[2]"
288#
49c890fc 289test_set "set variable v_signed_long_array\[0\]=123" "set variable v_signed_long_array\[1\]=-456" "print v_signed_long_array" ".*.\[0-9\]* =.*\\{123,.*-456\\}" "set variable signed long array"
c906108c
SS
290#
291# test "set variable" for "unsigned long array[2]"
292#
49c890fc 293test_set "set variable v_unsigned_long_array\[0\]=123" "set variable v_unsigned_long_array\[1\]=-456" "print v_unsigned_long_array" ".*.\[0-9\]* =.*\\{123,.*$ulong_minus_456\\}" "set variable unsigned long array"
c906108c
SS
294#
295# test "set variable" for "float array[2]"
296#
49c890fc 297test_set "set variable v_float_array\[0\]=123.0" "set variable v_float_array\[1\]=-456.0" "print v_float_array" ".*.\[0-9\]* =.*\\{123,.*-456\\}" "set variable float array"
c906108c
SS
298#
299# test "set variable" for "double array[2]"
300#
49c890fc 301test_set "set variable v_double_array\[0\]=123.0" "set variable v_double_array\[1\]=-456.0" "print v_double_array" ".*.\[0-9\]* =.*\\{123,.*-456\\}" "set variable double array"
c906108c
SS
302#
303# test "set variable" for type "char *"
304#
305test_set "set v_char_pointer=v_char_array" "set variable *(v_char_pointer)='h'" "set variable *(v_char_pointer+1)='i'" "print v_char_array" ".*.\[0-9\]* =.*\"hi\"" "print *(v_char_pointer+1)" ".*.\[0-9\]* = 105 \'i\'" "set variable char pointer=\"hi\" (string)"
306#
307# test "set variable" for type "signed char *"
308#
309test_set "set v_signed_char_pointer=v_signed_char_array" "set variable *(v_signed_char_pointer)='h'" "set variable *(v_signed_char_pointer+1)='i'" "print v_signed_char_array" ".*.\[0-9\]* =.*\"hi\"" "print *(v_signed_char_pointer+1)" ".*.\[0-9\]* = 105 \'i\'" "set variable signed char pointer=\"hi\" (string)"
310#
311# test "set variable" for type "unsigned char *"
312#
313test_set "set v_unsigned_char_pointer=v_unsigned_char_array" "set variable *(v_unsigned_char_pointer)='h'" "set variable *(v_unsigned_char_pointer+1)='i'" "print v_unsigned_char_array" ".*.\[0-9\]* =.*\"hi\"" "print *(v_unsigned_char_pointer+1)" ".*.\[0-9\]* = 105 \'i\'" "set variable unsigned char pointer=\"hi\" (string)"
314#
315# test "set variable" for type "short *"
316#
49c890fc 317test_set "set v_short_pointer=v_short_array" "set variable *(v_short_pointer)=123" "set variable *(v_short_pointer+1)=-456" "print v_short_array" ".*.\[0-9\]* =.*\\{123,.*-456\\}" "print *(v_short_pointer+1)" ".*.\[0-9\]* = -456" "set variable short pointer"
c906108c
SS
318#
319# test "set variable" for type "signed short *"
320#
321gdb_test "set v_signed_short_pointer=v_signed_short_array" ""
322gdb_test "set variable *(v_signed_short_pointer)=123" ""
323gdb_test "set variable *(v_signed_short_pointer+1)=-456" ""
cb135b83 324gdb_test "print v_signed_short_array" ".\[0-9\]* =.*\\{123,.*-456\\}" \
c906108c
SS
325 "set variable signed short pointer"
326gdb_test "print *(v_signed_short_pointer+1)" ".\[0-9\]*.*=.*-456"
327#
328# test "set variable" for type "unsigned short *"
329#
330gdb_test "set v_unsigned_short_pointer=v_unsigned_short_array" ""
331gdb_test "set variable *(v_unsigned_short_pointer)=123" ""
332gdb_test "set variable *(v_unsigned_short_pointer+1)=-456" ""
085dd6e6 333# DTS 10060CLLbs - bad type info from cc
a0b3c4fd 334if {$hp_cc_compiler} {setup_xfail hppa*-*-*11* 10060CLLbs}
cb135b83 335gdb_test "print v_unsigned_short_array" ".\[0-9\]* =.*\\{123,.*65080\\}" \
c906108c 336 "set variable unsigned short pointer"
085dd6e6 337# DTS 10060CLLbs - bad type info from cc
a0b3c4fd 338if {$hp_cc_compiler} {setup_xfail hppa*-*-*11* 10060CLLbs}
c906108c
SS
339gdb_test "print *(v_unsigned_short_pointer+1)" ".\[0-9\]* = 65080"
340#
341# test "set variable" for type "int *"
342#
49c890fc 343test_set "set v_int_pointer=v_int_array" "set variable *(v_int_pointer)=123" "set variable *(v_int_pointer+1)=-456" "print v_int_array" ".*.\[0-9\]* =.*\\{123,.*-456\\}" "print *(v_int_pointer+1)" ".*.\[0-9\]* = -456" "set variable int pointer"
c906108c
SS
344#
345# test "set variable" for type "signed int *"
346#
49c890fc 347test_set "set v_signed_int_pointer=v_signed_int_array" "set variable *(v_signed_int_pointer)=123" "set variable *(v_signed_int_pointer+1)=-456" "print v_signed_int_array" ".*.\[0-9\]* =.*\\{123,.*-456\\}" "print *(v_signed_int_pointer+1)" ".*.\[0-9\]* = -456" "set variable signed int pointer"
c906108c
SS
348#
349# test "set variable" for type "unsigned int *"
350#
49c890fc 351test_set "set v_unsigned_int_pointer=v_unsigned_int_array" "set variable *(v_unsigned_int_pointer)=123" "set variable *(v_unsigned_int_pointer+1)=-456" "print v_unsigned_int_array" ".*.\[0-9\]* =.*\\{123,.*(4294966840|65080)\\}" "set variable unsigned int pointer"
c906108c
SS
352test_set "" "print *(v_unsigned_int_pointer+1)" ".*.\[0-9\]* = (4294966840|65080)" "print variable unsigned int pointer+1"
353#
354# test "set variable" for type "long *"
355#
49c890fc 356test_set "set v_long_pointer=v_long_array" "set variable *(v_long_pointer)=123" "set variable *(v_long_pointer+1)=-456" "print v_long_array" ".*.\[0-9\]* =.*\\{123,.*-456\\}" "print *(v_long_pointer+1)" ".*.\[0-9\]* = -456" "set variable long pointer"
c906108c
SS
357#
358# test "set variable" for type "signed long *"
359#
49c890fc 360test_set "set v_signed_long_pointer=v_signed_long_array" "set variable *(v_signed_long_pointer)=123" "set variable *(v_signed_long_pointer+1)=-456" "print v_signed_long_array" ".*.\[0-9\]* =.*\\{123,.*-456\\}" "print *(v_signed_long_pointer+1)" ".*.\[0-9\]* = -456" "set variable signed long pointer"
c906108c
SS
361#
362# test "set variable" for type "unsigned long *"
363#
49c890fc 364test_set "set v_unsigned_long_pointer=v_unsigned_long_array" "set variable *(v_unsigned_long_pointer)=123" "set variable *(v_unsigned_long_pointer+1)=-456" "print v_unsigned_long_array" ".*.\[0-9\]* =.*\\{123,.*$ulong_minus_456\\}" "print *(v_unsigned_long_pointer+1)" ".*.\[0-9\]* = $ulong_minus_456" "set variable unsigned long pointer"
c906108c
SS
365#
366# test "set variable" for type "float *"
367#
49c890fc 368test_set "set v_float_pointer=v_float_array" "set variable *(v_float_pointer)=123.0" "set variable *(v_float_pointer+1)=-456.0" "print v_float_array" ".*.\[0-9\]* =.*\\{123,.*-456\\}" "print *(v_float_pointer+1)" ".*.\[0-9\]* = -456" "set variable float pointer"
c906108c
SS
369#
370# test "set variable" for type "double *"
371#
49c890fc 372test_set "set v_double_pointer=v_double_array" "set variable *(v_double_pointer)=123.0" "set variable *(v_double_pointer+1)=-456.0" "print v_double_array" ".*.\[0-9\]* =.*\\{123,.*-456\\}" "print *(v_double_pointer+1)" ".*.\[0-9\]* = -456" "set variable double pointer"
c906108c
SS
373#
374# test "set variable" for struct members
375#
376test_set "set variable v_struct1.v_char_member='h'" "print v_struct1.v_char_member" ".*.\[0-9\]* = 104 \'h\'" "set variable structure char member"
377test_set "set variable v_struct1.v_short_member=1" "print v_struct1.v_short_member" ".*.\[0-9\]* = 1" "set variable structure short member"
378test_set "set variable v_struct1.v_int_member=2" "print v_struct1.v_int_member" ".*.\[0-9\]* = 2" "set variable structure int member"
379test_set "set variable v_struct1.v_long_member=3" "print v_struct1.v_long_member" ".*.\[0-9\]* = 3" "set variable structure long member"
380test_set "set variable v_struct1.v_float_member=4.0" "print v_struct1.v_float_member" ".*.\[0-9\]* = 4" "set variable structure float member"
381test_set "set variable v_struct1.v_double_member=5.0" "print v_struct1.v_double_member" ".*.\[0-9\]* = 5" "set variable structure double member"
382
383gdb_test "print v_struct1" \
384 ".*.\[0-9\]* = \{.*v_char_member = 104 \'h\',.*v_short_member = 1,\
385.*v_int_member = 2,.*\
386v_long_member = 3,.*v_float_member = 4,.*v_double_member = 5.*\}" \
387 "set print structure #1"
388
c4093a6a
JM
389# Some believe that the following should be an error. GCC extensions for
390# structure constants require the type of the structure to be specified, as in
c906108c 391# v_struct1 = (struct t_struct) {32, 33, 34, 35, 36, 37}
c4093a6a
JM
392# The argument is that GDB should do the same if it wants to provide this
393# feature, i.e., require the cast.
394# We decided that we don't want the debugger to be as picky as a
395# compiler and make us type complex casts.
396
9846de1b
JM
397# We need to up this because this can be really slow on some boards.
398# (malloc() is called as part of the test).
399set timeout 60;
c906108c 400
c4093a6a
JM
401# Change the values
402test_set "set variable v_struct1 = {32, 33, 34, 35, 36, 37}" \
403 "print v_struct1" \
49c890fc 404 ".*.\[0-9\]* = \\{.*v_char_member = 32 \' \',.*v_short_member = 33,\
c4093a6a 405.*v_int_member = 34,.*\
49c890fc 406v_long_member = 35,.*v_float_member = 36,.*v_double_member = 37.*\\}" \
c4093a6a
JM
407 "set print structure #2"
408
409# Change them back
410test_set "set variable v_struct1 = {'h', 1, 2, 3, 4.0, 5.0}" \
411 "print v_struct1" \
49c890fc 412 ".*.\[0-9\]* = \\{.*v_char_member = 104 \'h\',.*v_short_member = 1,\
c906108c 413.*v_int_member = 2,.*\
49c890fc 414v_long_member = 3,.*v_float_member = 4,.*v_double_member = 5.*\\}" \
c4093a6a 415 "set print structure #3"
c906108c
SS
416
417# Test printing of enumeration bitfields.
418# GNU C supports them, some other compilers don't.
419
420if {$gcc_compiled} then {
421 gdb_test "print sef.field=sm1" ".*.\[0-9\]* = sm1"
422 gdb_test "print sef.field" ".*.\[0-9\]* = sm1" "print sef.field (sm1)"
423 gdb_test "print sef.field=s1" ".*.\[0-9\]* = s1"
424 gdb_test "print sef.field" ".*.\[0-9\]* = s1" "print sef.field (s1)"
425 gdb_test "print uef.field=u2" ".*.\[0-9\]* = u2"
426 gdb_test "print uef.field" ".*.\[0-9\]* = u2" "print uef.field (u2)"
427 gdb_test "print uef.field=u1" ".*.\[0-9\]* = u1"
428 gdb_test "print uef.field" ".*.\[0-9\]* = u1" "print uef.field (u1)"
429
430 # Test for truncation when assigning invalid values to bitfields.
431 gdb_test "print sef.field=7" \
432 ".*warning: Value does not fit in 2 bits.*\[0-9\]* = sm1"
433 gdb_test "print uef.field=6" \
434 ".*warning: Value does not fit in 2 bits.*\[0-9\]* = u2"
435}
This page took 0.415344 seconds and 4 git commands to generate.