]>
Commit | Line | Data |
---|---|---|
0dcd613f AC |
1 | # This testcase is part of GDB, the GNU debugger. |
2 | ||
3 | # Copyright 1992, 1994, 1995, 1996, 1997, 1999, 2000, 2002, 2003, 2004 | |
4 | # Free Software Foundation, Inc. | |
c906108c SS |
5 | |
6 | # This program is free software; you can redistribute it and/or modify | |
7 | # it under the terms of the GNU General Public License as published by | |
8 | # the Free Software Foundation; either version 2 of the License, or | |
9 | # (at your option) any later version. | |
10 | # | |
11 | # This program is distributed in the hope that it will be useful, | |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | # GNU General Public License for more details. | |
15 | # | |
16 | # You should have received a copy of the GNU General Public License | |
17 | # along with this program; if not, write to the Free Software | |
18 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
19 | ||
20 | # Please email any bugs, comments, and/or additions to this file to: | |
0dcd613f | 21 | # bug-gdb@gnu.org |
c906108c SS |
22 | |
23 | # This file was written by Fred Fish. (fnf@cygnus.com) | |
24 | ||
25 | if $tracelevel then { | |
26 | strace $tracelevel | |
27 | } | |
28 | ||
29 | set prms_id 0 | |
30 | set bug_id 0 | |
31 | ||
32 | set testfile "printcmds" | |
33 | set srcfile ${testfile}.c | |
34 | set binfile ${objdir}/${subdir}/${testfile} | |
35 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { | |
b60f0898 JB |
36 | untested printcmds.exp |
37 | return -1 | |
c906108c SS |
38 | } |
39 | ||
40 | # Set the current language to C. This counts as a test. If it | |
41 | # fails, then we skip the other tests. | |
42 | ||
43 | proc set_lang_c {} { | |
44 | global gdb_prompt | |
45 | ||
46 | if [gdb_test "set language c" "" "set language c"] { | |
47 | return 0 | |
48 | } | |
49 | ||
50 | if [gdb_test "show language" ".* source language is \"c\".*"] { | |
51 | return 0 | |
52 | } | |
53 | return 1; | |
54 | } | |
55 | ||
56 | proc test_integer_literals_accepted {} { | |
57 | global gdb_prompt | |
58 | ||
59 | # Test various decimal values. | |
60 | ||
61 | gdb_test "p 123" " = 123" | |
62 | gdb_test "p -123" " = -123" | |
63 | gdb_test "p/d 123" " = 123" | |
64 | ||
65 | # Test various octal values. | |
66 | ||
67 | gdb_test "p 0123" " = 83" | |
68 | gdb_test "p 00123" " = 83" | |
69 | gdb_test "p -0123" " = -83" | |
70 | gdb_test "p/o 0123" " = 0123" | |
71 | ||
72 | # Test various hexadecimal values. | |
73 | ||
74 | gdb_test "p 0x123" " = 291" | |
75 | gdb_test "p -0x123" " = -291" | |
76 | gdb_test "p 0x0123" " = 291" | |
77 | gdb_test "p -0x0123" " = -291" | |
78 | gdb_test "p 0xABCDEF" " = 11259375" | |
79 | gdb_test "p 0xabcdef" " = 11259375" | |
80 | gdb_test "p 0xAbCdEf" " = 11259375" | |
81 | gdb_test "p/x 0x123" " = 0x123" | |
82 | } | |
83 | ||
84 | proc test_character_literals_accepted {} { | |
85 | global gdb_prompt | |
86 | ||
87 | gdb_test "p 'a'" " = 97 'a'" | |
88 | gdb_test "p/c 'a'" " = 97 'a'" | |
89 | gdb_test "p/x 'a'" " = 0x61" | |
90 | gdb_test "p/d 'a'" " = 97" | |
91 | gdb_test "p/t 'a'" " = 1100001" | |
92 | gdb_test "p '\\141'" " = 97 'a'" | |
93 | gdb_test "p/x '\\377'" " = 0xff" | |
94 | # Note "p '\''" => "= 39 '\''" | |
95 | gdb_test "p '\\''" " = 39 '\\\\''" | |
96 | # Note "p '\\'" => "= 92 '\\'" | |
97 | gdb_test "p '\\\\'" " = 92 '\\\\\\\\'" | |
98 | } | |
99 | ||
100 | proc test_integer_literals_rejected {} { | |
101 | global gdb_prompt | |
102 | ||
103 | test_print_reject "p 0x" | |
c4b7bc2b JB |
104 | gdb_test "p ''" "(Empty character constant\\.|A character constant must contain at least one character\\.)" |
105 | gdb_test "p '''" "(Empty character constant\\.|A character constant must contain at least one character\\.)" | |
c906108c SS |
106 | test_print_reject "p '\\'" |
107 | ||
108 | # Note that this turns into "p '\\\'" at gdb's input. | |
109 | test_print_reject "p '\\\\\\'" | |
110 | ||
111 | # Test various decimal values. | |
112 | ||
113 | test_print_reject "p DEADBEEF" | |
114 | ||
115 | # Gdb currently fails this test for all configurations. The C | |
116 | # lexer thinks that 123DEADBEEF is a floating point number, but | |
117 | # then fails to notice that atof() only eats the 123 part. | |
118 | # FIXME: This should be put into PRMS. | |
119 | # Fixed, 4/25/97, by Bob Manson. | |
120 | ||
121 | test_print_reject "p 123DEADBEEF" | |
122 | test_print_reject "p 123foobar.bazfoo3" | |
123 | test_print_reject "p 123EEEEEEEEEEEEEEEEE33333k333" | |
124 | gdb_test "p 123.4+56.7" "180.(099\[0-9]*|100\[0-9\]*)" "check for floating addition" | |
125 | ||
126 | # Test various octal values. | |
127 | ||
128 | test_print_reject "p 09" | |
129 | test_print_reject "p 079" | |
130 | ||
131 | # Test various hexadecimal values. | |
132 | ||
133 | test_print_reject "p 0xG" | |
134 | test_print_reject "p 0xAG" | |
135 | } | |
136 | ||
137 | proc test_print_all_chars {} { | |
138 | global gdb_prompt | |
139 | ||
99ebe9ac | 140 | gdb_test "p ctable1\[0\]" " = 0 '\\\\0'" |
c906108c SS |
141 | gdb_test "p ctable1\[1\]" " = 1 '\\\\001'" |
142 | gdb_test "p ctable1\[2\]" " = 2 '\\\\002'" | |
143 | gdb_test "p ctable1\[3\]" " = 3 '\\\\003'" | |
144 | gdb_test "p ctable1\[4\]" " = 4 '\\\\004'" | |
145 | gdb_test "p ctable1\[5\]" " = 5 '\\\\005'" | |
146 | gdb_test "p ctable1\[6\]" " = 6 '\\\\006'" | |
147 | gdb_test "p ctable1\[7\]" " = 7 '\\\\a'" | |
148 | gdb_test "p ctable1\[8\]" " = 8 '\\\\b'" | |
149 | gdb_test "p ctable1\[9\]" " = 9 '\\\\t'" | |
150 | gdb_test "p ctable1\[10\]" " = 10 '\\\\n'" | |
99ebe9ac | 151 | gdb_test "p ctable1\[11\]" " = 11 '\\\\v'" |
c906108c SS |
152 | gdb_test "p ctable1\[12\]" " = 12 '\\\\f'" |
153 | gdb_test "p ctable1\[13\]" " = 13 '\\\\r'" | |
154 | gdb_test "p ctable1\[14\]" " = 14 '\\\\016'" | |
155 | gdb_test "p ctable1\[15\]" " = 15 '\\\\017'" | |
156 | gdb_test "p ctable1\[16\]" " = 16 '\\\\020'" | |
157 | gdb_test "p ctable1\[17\]" " = 17 '\\\\021'" | |
158 | gdb_test "p ctable1\[18\]" " = 18 '\\\\022'" | |
159 | gdb_test "p ctable1\[19\]" " = 19 '\\\\023'" | |
160 | gdb_test "p ctable1\[20\]" " = 20 '\\\\024'" | |
161 | gdb_test "p ctable1\[21\]" " = 21 '\\\\025'" | |
162 | gdb_test "p ctable1\[22\]" " = 22 '\\\\026'" | |
163 | gdb_test "p ctable1\[23\]" " = 23 '\\\\027'" | |
164 | gdb_test "p ctable1\[24\]" " = 24 '\\\\030'" | |
165 | gdb_test "p ctable1\[25\]" " = 25 '\\\\031'" | |
166 | gdb_test "p ctable1\[26\]" " = 26 '\\\\032'" | |
0dcd613f | 167 | gdb_test "p ctable1\[27\]" " = 27 '\\\\033'" |
c906108c SS |
168 | gdb_test "p ctable1\[28\]" " = 28 '\\\\034'" |
169 | gdb_test "p ctable1\[29\]" " = 29 '\\\\035'" | |
170 | gdb_test "p ctable1\[30\]" " = 30 '\\\\036'" | |
171 | gdb_test "p ctable1\[31\]" " = 31 '\\\\037'" | |
172 | gdb_test "p ctable1\[32\]" " = 32 ' '" | |
173 | gdb_test "p ctable1\[33\]" " = 33 '!'" | |
174 | gdb_test "p ctable1\[34\]" " = 34 '\"'" | |
175 | gdb_test "p ctable1\[35\]" " = 35 '#'" | |
176 | gdb_test "p ctable1\[36\]" " = 36 '\\\$'" | |
177 | gdb_test "p ctable1\[37\]" " = 37 '%'" | |
178 | gdb_test "p ctable1\[38\]" " = 38 '&'" | |
179 | gdb_test "p ctable1\[39\]" " = 39 '\\\\''" | |
180 | gdb_test "p ctable1\[40\]" " = 40 '\\('" | |
181 | gdb_test "p ctable1\[41\]" " = 41 '\\)'" | |
182 | gdb_test "p ctable1\[42\]" " = 42 '\\*'" | |
183 | gdb_test "p ctable1\[43\]" " = 43 '\\+'" | |
184 | gdb_test "p ctable1\[44\]" " = 44 ','" | |
185 | gdb_test "p ctable1\[45\]" " = 45 '-'" | |
186 | gdb_test "p ctable1\[46\]" " = 46 '.'" | |
187 | gdb_test "p ctable1\[47\]" " = 47 '/'" | |
188 | gdb_test "p ctable1\[48\]" " = 48 '0'" | |
189 | gdb_test "p ctable1\[49\]" " = 49 '1'" | |
190 | gdb_test "p ctable1\[50\]" " = 50 '2'" | |
191 | gdb_test "p ctable1\[51\]" " = 51 '3'" | |
192 | gdb_test "p ctable1\[52\]" " = 52 '4'" | |
193 | gdb_test "p ctable1\[53\]" " = 53 '5'" | |
194 | gdb_test "p ctable1\[54\]" " = 54 '6'" | |
195 | gdb_test "p ctable1\[55\]" " = 55 '7'" | |
196 | gdb_test "p ctable1\[56\]" " = 56 '8'" | |
197 | gdb_test "p ctable1\[57\]" " = 57 '9'" | |
198 | gdb_test "p ctable1\[58\]" " = 58 ':'" | |
199 | gdb_test "p ctable1\[59\]" " = 59 ';'" | |
200 | gdb_test "p ctable1\[60\]" " = 60 '<'" | |
201 | gdb_test "p ctable1\[61\]" " = 61 '='" | |
202 | gdb_test "p ctable1\[62\]" " = 62 '>'" | |
203 | gdb_test "p ctable1\[63\]" " = 63 '\\?'" | |
204 | gdb_test "p ctable1\[64\]" " = 64 '@'" | |
205 | gdb_test "p ctable1\[65\]" " = 65 'A'" | |
206 | gdb_test "p ctable1\[66\]" " = 66 'B'" | |
207 | gdb_test "p ctable1\[67\]" " = 67 'C'" | |
208 | gdb_test "p ctable1\[68\]" " = 68 'D'" | |
209 | gdb_test "p ctable1\[69\]" " = 69 'E'" | |
210 | gdb_test "p ctable1\[70\]" " = 70 'F'" | |
211 | gdb_test "p ctable1\[71\]" " = 71 'G'" | |
212 | gdb_test "p ctable1\[72\]" " = 72 'H'" | |
213 | gdb_test "p ctable1\[73\]" " = 73 'I'" | |
214 | gdb_test "p ctable1\[74\]" " = 74 'J'" | |
215 | gdb_test "p ctable1\[75\]" " = 75 'K'" | |
216 | gdb_test "p ctable1\[76\]" " = 76 'L'" | |
217 | gdb_test "p ctable1\[77\]" " = 77 'M'" | |
218 | gdb_test "p ctable1\[78\]" " = 78 'N'" | |
219 | gdb_test "p ctable1\[79\]" " = 79 'O'" | |
220 | gdb_test "p ctable1\[80\]" " = 80 'P'" | |
221 | gdb_test "p ctable1\[81\]" " = 81 'Q'" | |
222 | gdb_test "p ctable1\[82\]" " = 82 'R'" | |
223 | gdb_test "p ctable1\[83\]" " = 83 'S'" | |
224 | gdb_test "p ctable1\[84\]" " = 84 'T'" | |
225 | gdb_test "p ctable1\[85\]" " = 85 'U'" | |
226 | gdb_test "p ctable1\[86\]" " = 86 'V'" | |
227 | gdb_test "p ctable1\[87\]" " = 87 'W'" | |
228 | gdb_test "p ctable1\[88\]" " = 88 'X'" | |
229 | gdb_test "p ctable1\[89\]" " = 89 'Y'" | |
230 | gdb_test "p ctable1\[90\]" " = 90 'Z'" | |
231 | gdb_test "p ctable1\[91\]" " = 91 '\\\['" | |
232 | gdb_test "p ctable1\[92\]" " = 92 '\\\\\\\\'" | |
233 | gdb_test "p ctable1\[93\]" " = 93 '\\\]'" | |
234 | gdb_test "p ctable1\[94\]" " = 94 '\\^'" | |
235 | gdb_test "p ctable1\[95\]" " = 95 '_'" | |
236 | gdb_test "p ctable1\[96\]" " = 96 '`'" | |
237 | gdb_test "p ctable1\[97\]" " = 97 'a'" | |
238 | gdb_test "p ctable1\[98\]" " = 98 'b'" | |
239 | gdb_test "p ctable1\[99\]" " = 99 'c'" | |
240 | gdb_test "p ctable1\[100\]" " = 100 'd'" | |
241 | gdb_test "p ctable1\[101\]" " = 101 'e'" | |
242 | gdb_test "p ctable1\[102\]" " = 102 'f'" | |
243 | gdb_test "p ctable1\[103\]" " = 103 'g'" | |
244 | gdb_test "p ctable1\[104\]" " = 104 'h'" | |
245 | gdb_test "p ctable1\[105\]" " = 105 'i'" | |
246 | gdb_test "p ctable1\[106\]" " = 106 'j'" | |
247 | gdb_test "p ctable1\[107\]" " = 107 'k'" | |
248 | gdb_test "p ctable1\[108\]" " = 108 'l'" | |
249 | gdb_test "p ctable1\[109\]" " = 109 'm'" | |
250 | gdb_test "p ctable1\[110\]" " = 110 'n'" | |
251 | gdb_test "p ctable1\[111\]" " = 111 'o'" | |
252 | gdb_test "p ctable1\[112\]" " = 112 'p'" | |
253 | gdb_test "p ctable1\[113\]" " = 113 'q'" | |
254 | gdb_test "p ctable1\[114\]" " = 114 'r'" | |
255 | gdb_test "p ctable1\[115\]" " = 115 's'" | |
256 | gdb_test "p ctable1\[116\]" " = 116 't'" | |
257 | gdb_test "p ctable1\[117\]" " = 117 'u'" | |
258 | gdb_test "p ctable1\[118\]" " = 118 'v'" | |
259 | gdb_test "p ctable1\[119\]" " = 119 'w'" | |
260 | gdb_test "p ctable1\[120\]" " = 120 'x'" | |
261 | gdb_test "p ctable1\[121\]" " = 121 'y'" | |
262 | gdb_test "p ctable1\[122\]" " = 122 'z'" | |
263 | gdb_test "p ctable1\[123\]" " = 123 '\[{\]+'" | |
264 | gdb_test "p ctable1\[124\]" " = 124 '\[|\]+'" | |
265 | gdb_test "p ctable1\[125\]" " = 125 '\[}\]+'" | |
266 | gdb_test "p ctable1\[126\]" " = 126 '\[~\]'" | |
267 | gdb_test "p ctable1\[127\]" " = 127 '\\\\177'" | |
268 | gdb_test "p ctable1\[128\]" " = 128 '\\\\200'" | |
269 | gdb_test "p ctable1\[129\]" " = 129 '\\\\201'" | |
270 | gdb_test "p ctable1\[130\]" " = 130 '\\\\202'" | |
271 | gdb_test "p ctable1\[131\]" " = 131 '\\\\203'" | |
272 | gdb_test "p ctable1\[132\]" " = 132 '\\\\204'" | |
273 | gdb_test "p ctable1\[133\]" " = 133 '\\\\205'" | |
274 | gdb_test "p ctable1\[134\]" " = 134 '\\\\206'" | |
275 | gdb_test "p ctable1\[135\]" " = 135 '\\\\207'" | |
276 | gdb_test "p ctable1\[136\]" " = 136 '\\\\210'" | |
277 | gdb_test "p ctable1\[137\]" " = 137 '\\\\211'" | |
278 | gdb_test "p ctable1\[138\]" " = 138 '\\\\212'" | |
279 | gdb_test "p ctable1\[139\]" " = 139 '\\\\213'" | |
280 | gdb_test "p ctable1\[140\]" " = 140 '\\\\214'" | |
281 | gdb_test "p ctable1\[141\]" " = 141 '\\\\215'" | |
282 | gdb_test "p ctable1\[142\]" " = 142 '\\\\216'" | |
283 | gdb_test "p ctable1\[143\]" " = 143 '\\\\217'" | |
284 | gdb_test "p ctable1\[144\]" " = 144 '\\\\220'" | |
285 | gdb_test "p ctable1\[145\]" " = 145 '\\\\221'" | |
286 | gdb_test "p ctable1\[146\]" " = 146 '\\\\222'" | |
287 | gdb_test "p ctable1\[147\]" " = 147 '\\\\223'" | |
288 | gdb_test "p ctable1\[148\]" " = 148 '\\\\224'" | |
289 | gdb_test "p ctable1\[149\]" " = 149 '\\\\225'" | |
290 | gdb_test "p ctable1\[150\]" " = 150 '\\\\226'" | |
291 | gdb_test "p ctable1\[151\]" " = 151 '\\\\227'" | |
292 | gdb_test "p ctable1\[152\]" " = 152 '\\\\230'" | |
293 | gdb_test "p ctable1\[153\]" " = 153 '\\\\231'" | |
294 | gdb_test "p ctable1\[154\]" " = 154 '\\\\232'" | |
295 | gdb_test "p ctable1\[155\]" " = 155 '\\\\233'" | |
296 | gdb_test "p ctable1\[156\]" " = 156 '\\\\234'" | |
297 | gdb_test "p ctable1\[157\]" " = 157 '\\\\235'" | |
298 | gdb_test "p ctable1\[158\]" " = 158 '\\\\236'" | |
299 | gdb_test "p ctable1\[159\]" " = 159 '\\\\237'" | |
300 | gdb_test "p ctable1\[160\]" " = 160 '\\\\240'" | |
301 | gdb_test "p ctable1\[161\]" " = 161 '\\\\241'" | |
302 | gdb_test "p ctable1\[162\]" " = 162 '\\\\242'" | |
303 | gdb_test "p ctable1\[163\]" " = 163 '\\\\243'" | |
304 | gdb_test "p ctable1\[164\]" " = 164 '\\\\244'" | |
305 | gdb_test "p ctable1\[165\]" " = 165 '\\\\245'" | |
306 | gdb_test "p ctable1\[166\]" " = 166 '\\\\246'" | |
307 | gdb_test "p ctable1\[167\]" " = 167 '\\\\247'" | |
308 | gdb_test "p ctable1\[168\]" " = 168 '\\\\250'" | |
309 | gdb_test "p ctable1\[169\]" " = 169 '\\\\251'" | |
310 | gdb_test "p ctable1\[170\]" " = 170 '\\\\252'" | |
311 | gdb_test "p ctable1\[171\]" " = 171 '\\\\253'" | |
312 | gdb_test "p ctable1\[172\]" " = 172 '\\\\254'" | |
313 | gdb_test "p ctable1\[173\]" " = 173 '\\\\255'" | |
314 | gdb_test "p ctable1\[174\]" " = 174 '\\\\256'" | |
315 | gdb_test "p ctable1\[175\]" " = 175 '\\\\257'" | |
316 | gdb_test "p ctable1\[176\]" " = 176 '\\\\260'" | |
317 | gdb_test "p ctable1\[177\]" " = 177 '\\\\261'" | |
318 | gdb_test "p ctable1\[178\]" " = 178 '\\\\262'" | |
319 | gdb_test "p ctable1\[179\]" " = 179 '\\\\263'" | |
320 | gdb_test "p ctable1\[180\]" " = 180 '\\\\264'" | |
321 | gdb_test "p ctable1\[181\]" " = 181 '\\\\265'" | |
322 | gdb_test "p ctable1\[182\]" " = 182 '\\\\266'" | |
323 | gdb_test "p ctable1\[183\]" " = 183 '\\\\267'" | |
324 | gdb_test "p ctable1\[184\]" " = 184 '\\\\270'" | |
325 | gdb_test "p ctable1\[185\]" " = 185 '\\\\271'" | |
326 | gdb_test "p ctable1\[186\]" " = 186 '\\\\272'" | |
327 | gdb_test "p ctable1\[187\]" " = 187 '\\\\273'" | |
328 | gdb_test "p ctable1\[188\]" " = 188 '\\\\274'" | |
329 | gdb_test "p ctable1\[189\]" " = 189 '\\\\275'" | |
330 | gdb_test "p ctable1\[190\]" " = 190 '\\\\276'" | |
331 | gdb_test "p ctable1\[191\]" " = 191 '\\\\277'" | |
332 | gdb_test "p ctable1\[192\]" " = 192 '\\\\300'" | |
333 | gdb_test "p ctable1\[193\]" " = 193 '\\\\301'" | |
334 | gdb_test "p ctable1\[194\]" " = 194 '\\\\302'" | |
335 | gdb_test "p ctable1\[195\]" " = 195 '\\\\303'" | |
336 | gdb_test "p ctable1\[196\]" " = 196 '\\\\304'" | |
337 | gdb_test "p ctable1\[197\]" " = 197 '\\\\305'" | |
338 | gdb_test "p ctable1\[198\]" " = 198 '\\\\306'" | |
339 | gdb_test "p ctable1\[199\]" " = 199 '\\\\307'" | |
340 | gdb_test "p ctable1\[200\]" " = 200 '\\\\310'" | |
341 | gdb_test "p ctable1\[201\]" " = 201 '\\\\311'" | |
342 | gdb_test "p ctable1\[202\]" " = 202 '\\\\312'" | |
343 | gdb_test "p ctable1\[203\]" " = 203 '\\\\313'" | |
344 | gdb_test "p ctable1\[204\]" " = 204 '\\\\314'" | |
345 | gdb_test "p ctable1\[205\]" " = 205 '\\\\315'" | |
346 | gdb_test "p ctable1\[206\]" " = 206 '\\\\316'" | |
347 | gdb_test "p ctable1\[207\]" " = 207 '\\\\317'" | |
348 | gdb_test "p ctable1\[208\]" " = 208 '\\\\320'" | |
349 | gdb_test "p ctable1\[209\]" " = 209 '\\\\321'" | |
350 | gdb_test "p ctable1\[210\]" " = 210 '\\\\322'" | |
351 | gdb_test "p ctable1\[211\]" " = 211 '\\\\323'" | |
352 | gdb_test "p ctable1\[212\]" " = 212 '\\\\324'" | |
353 | gdb_test "p ctable1\[213\]" " = 213 '\\\\325'" | |
354 | gdb_test "p ctable1\[214\]" " = 214 '\\\\326'" | |
355 | gdb_test "p ctable1\[215\]" " = 215 '\\\\327'" | |
356 | gdb_test "p ctable1\[216\]" " = 216 '\\\\330'" | |
357 | gdb_test "p ctable1\[217\]" " = 217 '\\\\331'" | |
358 | gdb_test "p ctable1\[218\]" " = 218 '\\\\332'" | |
359 | gdb_test "p ctable1\[219\]" " = 219 '\\\\333'" | |
360 | gdb_test "p ctable1\[220\]" " = 220 '\\\\334'" | |
361 | gdb_test "p ctable1\[221\]" " = 221 '\\\\335'" | |
362 | gdb_test "p ctable1\[222\]" " = 222 '\\\\336'" | |
363 | gdb_test "p ctable1\[223\]" " = 223 '\\\\337'" | |
364 | gdb_test "p ctable1\[224\]" " = 224 '\\\\340'" | |
365 | gdb_test "p ctable1\[225\]" " = 225 '\\\\341'" | |
366 | gdb_test "p ctable1\[226\]" " = 226 '\\\\342'" | |
367 | gdb_test "p ctable1\[227\]" " = 227 '\\\\343'" | |
368 | gdb_test "p ctable1\[228\]" " = 228 '\\\\344'" | |
369 | gdb_test "p ctable1\[229\]" " = 229 '\\\\345'" | |
370 | gdb_test "p ctable1\[230\]" " = 230 '\\\\346'" | |
371 | gdb_test "p ctable1\[231\]" " = 231 '\\\\347'" | |
372 | gdb_test "p ctable1\[232\]" " = 232 '\\\\350'" | |
373 | gdb_test "p ctable1\[233\]" " = 233 '\\\\351'" | |
374 | gdb_test "p ctable1\[234\]" " = 234 '\\\\352'" | |
375 | gdb_test "p ctable1\[235\]" " = 235 '\\\\353'" | |
376 | gdb_test "p ctable1\[236\]" " = 236 '\\\\354'" | |
377 | gdb_test "p ctable1\[237\]" " = 237 '\\\\355'" | |
378 | gdb_test "p ctable1\[238\]" " = 238 '\\\\356'" | |
379 | gdb_test "p ctable1\[239\]" " = 239 '\\\\357'" | |
380 | gdb_test "p ctable1\[240\]" " = 240 '\\\\360'" | |
381 | gdb_test "p ctable1\[241\]" " = 241 '\\\\361'" | |
382 | gdb_test "p ctable1\[242\]" " = 242 '\\\\362'" | |
383 | gdb_test "p ctable1\[243\]" " = 243 '\\\\363'" | |
384 | gdb_test "p ctable1\[244\]" " = 244 '\\\\364'" | |
385 | gdb_test "p ctable1\[245\]" " = 245 '\\\\365'" | |
386 | gdb_test "p ctable1\[246\]" " = 246 '\\\\366'" | |
387 | gdb_test "p ctable1\[247\]" " = 247 '\\\\367'" | |
388 | gdb_test "p ctable1\[248\]" " = 248 '\\\\370'" | |
389 | gdb_test "p ctable1\[249\]" " = 249 '\\\\371'" | |
390 | gdb_test "p ctable1\[250\]" " = 250 '\\\\372'" | |
391 | gdb_test "p ctable1\[251\]" " = 251 '\\\\373'" | |
392 | gdb_test "p ctable1\[252\]" " = 252 '\\\\374'" | |
393 | gdb_test "p ctable1\[253\]" " = 253 '\\\\375'" | |
394 | gdb_test "p ctable1\[254\]" " = 254 '\\\\376'" | |
395 | gdb_test "p ctable1\[255\]" " = 255 '\\\\377'" | |
396 | } | |
397 | ||
398 | # Test interaction of the number of print elements to print and the | |
399 | # repeat count, set to the default of 10. | |
400 | ||
401 | proc test_print_repeats_10 {} { | |
402 | global gdb_prompt | |
403 | ||
404 | for { set x 1; } { $x <= 16 } { incr x; } { | |
a0b3c4fd | 405 | gdb_test "set print elements $x" "" |
c906108c SS |
406 | for { set e 1; } { $e <= 16 } {incr e; } { |
407 | set v [expr $e - 1]; | |
408 | set command "p &ctable2\[${v}*16\]" | |
409 | if { $x < $e } { | |
410 | set aval $x; | |
411 | } else { | |
412 | set aval $e; | |
413 | } | |
414 | set xval [expr $x - $e]; | |
415 | if { $xval < 0 } { | |
416 | set xval 0; | |
417 | } | |
418 | if { $aval > 10 } { | |
419 | set a "'a' <repeats $aval times>"; | |
420 | if { $xval > 0 } { | |
421 | set a "${a}, \\\""; | |
422 | } | |
423 | } else { | |
424 | set a "\\\"[string range "aaaaaaaaaaaaaaaa" 1 $aval]"; | |
425 | if { $xval > 10 } { | |
426 | set a "$a\\\", "; | |
427 | } | |
428 | } | |
429 | set xstr ""; | |
430 | if { $xval > 10 } { | |
431 | set xstr "'X' <repeats $xval times>"; | |
432 | } else { | |
433 | if { $xval > 0 } { | |
434 | set xstr "[string range "XXXXXXXXXXXXXXXX" 1 $xval]\\\""; | |
435 | } else { | |
436 | if { $aval <= 10 } { | |
437 | set xstr "\\\""; | |
438 | } | |
439 | } | |
440 | } | |
441 | if { $aval < 16 } { | |
442 | set xstr "${xstr}\[.\]\[.\]\[.\]" | |
443 | } | |
444 | set string " = \[(\]unsigned char \[*\]\[)\] ${a}${xstr}"; | |
445 | gdb_test "$command" "$string" "$command with print elements set to $x"; | |
446 | } | |
447 | } | |
448 | } | |
449 | ||
450 | proc test_print_strings {} { | |
451 | global gdb_prompt | |
452 | ||
453 | # We accept "(unsigned char *) " before the string. char vs. unsigned char | |
454 | # is already tested elsewhere. | |
455 | ||
456 | # Test that setting print elements unlimited doesn't completely suppress | |
457 | # printing; this was a bug in older gdb's. | |
a0b3c4fd | 458 | gdb_test "set print elements 0" "" |
c906108c SS |
459 | gdb_test "p teststring" \ |
460 | " = (.unsigned char .. )?\"teststring contents\"" "p teststring with elements set to 0" | |
a0b3c4fd | 461 | gdb_test "set print elements 1" "" |
c906108c SS |
462 | gdb_test "p teststring" \ |
463 | " = (.unsigned char .. )?\"t\"\\.\\.\\." "p teststring with elements set to 1" | |
a0b3c4fd | 464 | gdb_test "set print elements 5" "" |
c906108c SS |
465 | gdb_test "p teststring" \ |
466 | " = (.unsigned char .. )?\"tests\"\\.\\.\\." "p teststring with elements set to 5" | |
a0b3c4fd | 467 | gdb_test "set print elements 19" "" |
c906108c SS |
468 | gdb_test "p teststring" \ |
469 | " = (.unsigned char .. )?\"teststring contents\"" "p teststring with elements set to 19" | |
a0b3c4fd | 470 | gdb_test "set print elements 20" "" |
c906108c SS |
471 | gdb_test "p teststring" \ |
472 | " = (.unsigned char .. )?\"teststring contents\"" "p teststring with elements set to 20" | |
473 | ||
a0b3c4fd | 474 | gdb_test "set print elements 8" "" |
c906108c SS |
475 | |
476 | gdb_test "p &ctable1\[0\]" \ | |
477 | " = \\(unsigned char \\*\\) \"\"" | |
478 | gdb_test "p &ctable1\[1\]" \ | |
479 | " = \\(unsigned char \\*\\) \"\\\\001\\\\002\\\\003\\\\004\\\\005\\\\006\\\\a\\\\b\"..." | |
480 | gdb_test "p &ctable1\[1*8\]" \ | |
99ebe9ac | 481 | " = \\(unsigned char \\*\\) \"\\\\b\\\\t\\\\n\\\\v\\\\f\\\\r\\\\016\\\\017\"..." |
c906108c SS |
482 | gdb_test "p &ctable1\[2*8\]" \ |
483 | " = \\(unsigned char \\*\\) \"\\\\020\\\\021\\\\022\\\\023\\\\024\\\\025\\\\026\\\\027\"..." | |
484 | gdb_test "p &ctable1\[3*8\]" \ | |
0dcd613f | 485 | " = \\(unsigned char \\*\\) \"\\\\030\\\\031\\\\032\\\\033\\\\034\\\\035\\\\036\\\\037\"..." |
c906108c SS |
486 | gdb_test "p &ctable1\[4*8\]" \ |
487 | " = \\(unsigned char \\*\\) \" !\\\\\"#\\\$%&'\"..." | |
488 | gdb_test "p &ctable1\[5*8\]" \ | |
489 | " = \\(unsigned char \\*\\) \"\\(\\)\\*\\+,-./\"..." | |
490 | gdb_test "p &ctable1\[6*8\]" \ | |
491 | " = \\(unsigned char \\*\\) \"01234567\"..." | |
492 | gdb_test "p &ctable1\[7*8\]" \ | |
493 | " = \\(unsigned char \\*\\) \"89:;<=>\\?\"..." | |
494 | gdb_test "p &ctable1\[8*8\]" \ | |
495 | " = \\(unsigned char \\*\\) \"@ABCDEFG\"..." | |
496 | gdb_test "p &ctable1\[9*8\]" \ | |
497 | " = \\(unsigned char \\*\\) \"HIJKLMNO\"..." | |
498 | gdb_test "p &ctable1\[10*8\]" \ | |
499 | " = \\(unsigned char \\*\\) \"PQRSTUVW\"..." | |
500 | gdb_test "p &ctable1\[11*8\]" \ | |
501 | " = \\(unsigned char \\*\\) \"XYZ\\\[\\\\\\\\\\\]\\^_\"..." | |
502 | gdb_test "p &ctable1\[12*8\]" \ | |
503 | " = \\(unsigned char \\*\\) \"`abcdefg\"..." | |
504 | gdb_test "p &ctable1\[13*8\]" \ | |
505 | " = \\(unsigned char \\*\\) \"hijklmno\"..." | |
506 | gdb_test "p &ctable1\[14*8\]" \ | |
507 | " = \\(unsigned char \\*\\) \"pqrstuvw\"..." | |
508 | gdb_test "p &ctable1\[15*8\]" \ | |
509 | " = \\(unsigned char \\*\\) \"xyz\[{|}\]+\\~\\\\177\"..." | |
510 | gdb_test "p &ctable1\[16*8\]" \ | |
511 | " = \\(unsigned char \\*\\) \"\\\\200\\\\201\\\\202\\\\203\\\\204\\\\205\\\\206\\\\207\"..." | |
512 | gdb_test "p &ctable1\[17*8\]" \ | |
513 | " = \\(unsigned char \\*\\) \"\\\\210\\\\211\\\\212\\\\213\\\\214\\\\215\\\\216\\\\217\"..." | |
514 | gdb_test "p &ctable1\[18*8\]" \ | |
515 | " = \\(unsigned char \\*\\) \"\\\\220\\\\221\\\\222\\\\223\\\\224\\\\225\\\\226\\\\227\"..." | |
516 | gdb_test "p &ctable1\[19*8\]" \ | |
517 | " = \\(unsigned char \\*\\) \"\\\\230\\\\231\\\\232\\\\233\\\\234\\\\235\\\\236\\\\237\"..." | |
518 | gdb_test "p &ctable1\[20*8\]" \ | |
519 | " = \\(unsigned char \\*\\) \"\\\\240\\\\241\\\\242\\\\243\\\\244\\\\245\\\\246\\\\247\"..." | |
520 | gdb_test "p &ctable1\[21*8\]" \ | |
521 | " = \\(unsigned char \\*\\) \"\\\\250\\\\251\\\\252\\\\253\\\\254\\\\255\\\\256\\\\257\"..." | |
522 | gdb_test "p &ctable1\[22*8\]" \ | |
523 | " = \\(unsigned char \\*\\) \"\\\\260\\\\261\\\\262\\\\263\\\\264\\\\265\\\\266\\\\267\"..." | |
524 | gdb_test "p &ctable1\[23*8\]" \ | |
525 | " = \\(unsigned char \\*\\) \"\\\\270\\\\271\\\\272\\\\273\\\\274\\\\275\\\\276\\\\277\"..." | |
526 | gdb_test "p &ctable1\[24*8\]" \ | |
527 | " = \\(unsigned char \\*\\) \"\\\\300\\\\301\\\\302\\\\303\\\\304\\\\305\\\\306\\\\307\"..." | |
528 | gdb_test "p &ctable1\[25*8\]" \ | |
529 | " = \\(unsigned char \\*\\) \"\\\\310\\\\311\\\\312\\\\313\\\\314\\\\315\\\\316\\\\317\"..." | |
530 | gdb_test "p &ctable1\[26*8\]" \ | |
531 | " = \\(unsigned char \\*\\) \"\\\\320\\\\321\\\\322\\\\323\\\\324\\\\325\\\\326\\\\327\"..." | |
532 | gdb_test "p &ctable1\[27*8\]" \ | |
533 | " = \\(unsigned char \\*\\) \"\\\\330\\\\331\\\\332\\\\333\\\\334\\\\335\\\\336\\\\337\"..." | |
534 | gdb_test "p &ctable1\[28*8\]" \ | |
535 | " = \\(unsigned char \\*\\) \"\\\\340\\\\341\\\\342\\\\343\\\\344\\\\345\\\\346\\\\347\"..." | |
536 | gdb_test "p &ctable1\[29*8\]" \ | |
537 | " = \\(unsigned char \\*\\) \"\\\\350\\\\351\\\\352\\\\353\\\\354\\\\355\\\\356\\\\357\"..." | |
538 | gdb_test "p &ctable1\[30*8\]" \ | |
539 | " = \\(unsigned char \\*\\) \"\\\\360\\\\361\\\\362\\\\363\\\\364\\\\365\\\\366\\\\367\"..." | |
540 | gdb_test "p &ctable1\[31*8\]" \ | |
541 | " = \\(unsigned char \\*\\) \"\\\\370\\\\371\\\\372\\\\373\\\\374\\\\375\\\\376\\\\377\"..." | |
542 | } | |
543 | ||
544 | proc test_print_int_arrays {} { | |
545 | global gdb_prompt | |
546 | ||
a0b3c4fd | 547 | gdb_test "set print elements 24" "" |
c906108c | 548 | |
39124dea | 549 | gdb_test_escape_braces "p int1dim" \ |
c906108c | 550 | " = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}" |
39124dea | 551 | gdb_test_escape_braces "p int2dim" \ |
c906108c | 552 | " = {{0, 1, 2, 3}, {4, 5, 6, 7}, {8, 9, 10, 11}}" |
39124dea | 553 | gdb_test_escape_braces "p int3dim" \ |
c906108c | 554 | " = {{{0, 1}, {2, 3}, {4, 5}}, {{6, 7}, {8, 9}, {10, 11}}}" |
39124dea | 555 | gdb_test_escape_braces "p int4dim" \ |
c906108c SS |
556 | " = {{{{0, 1}, {2, 3}, {4, 5}}, {{6, 7}, {8, 9}, {10, 11}}}}" |
557 | } | |
558 | ||
751a959b EZ |
559 | proc test_print_typedef_arrays {} { |
560 | global gdb_prompt | |
561 | ||
562 | gdb_test "set print elements 24" "" | |
563 | ||
39124dea | 564 | gdb_test_escape_braces "p a1" \ |
751a959b EZ |
565 | " = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20}" |
566 | gdb_test "p a1\[0\]" " = 2" | |
567 | gdb_test "p a1\[9\]" " = 20" | |
568 | ||
569 | gdb_test "p a2" \ | |
570 | " = \"abcd\"" | |
571 | gdb_test "p a2\[0\]" " = 97 'a'" | |
572 | gdb_test "p a2\[3\]" " = 100 'd'" | |
573 | } | |
574 | ||
c906108c SS |
575 | proc test_artificial_arrays {} { |
576 | # Send \026@ instead of just @ in case the kill character is @. | |
39124dea FN |
577 | gdb_test_escape_braces "p int1dim\[0\]\026@2" " = {0, 1}" {p int1dim[0]@2} |
578 | gdb_test_escape_braces "p int1dim\[0\]\026@2\026@3" \ | |
c906108c SS |
579 | "({{0, 1}, {2, 3}, {4, 5}}|\[Cc\]annot.*)" \ |
580 | {p int1dim[0]@2@3} | |
39124dea | 581 | gdb_test_escape_braces {p/x (short [])0x12345678} \ |
c906108c SS |
582 | " = ({0x1234, 0x5678}|{0x5678, 0x1234})" |
583 | } | |
584 | ||
585 | proc test_print_char_arrays {} { | |
586 | global gdb_prompt | |
587 | global hex | |
588 | ||
a0b3c4fd JM |
589 | gdb_test "set print elements 24" "" |
590 | gdb_test "set print address on" "" | |
c906108c SS |
591 | |
592 | gdb_test "p arrays" \ | |
593 | " = {array1 = \"abc\", array2 = \"d\", array3 = \"e\", array4 = \"fg\", array5 = \"hij\"}" | |
594 | ||
595 | gdb_test "p parrays" " = \\(struct some_arrays \\*\\) $hex" | |
596 | gdb_test "p parrays->array1" " = \"abc\"" | |
597 | gdb_test "p &parrays->array1" " = \\(unsigned char \\(\\*\\)\\\[4\\\]\\) $hex" | |
598 | gdb_test "p parrays->array2" " = \"d\"" | |
599 | gdb_test "p &parrays->array2" " = \\(unsigned char \\(\\*\\)\\\[1\\\]\\) $hex" | |
600 | gdb_test "p parrays->array3" " = \"e\"" | |
601 | gdb_test "p &parrays->array3" " = \\(unsigned char \\(\\*\\)\\\[1\\\]\\) $hex" | |
602 | gdb_test "p parrays->array4" " = \"fg\"" | |
603 | gdb_test "p &parrays->array4" " = \\(unsigned char \\(\\*\\)\\\[2\\\]\\) $hex" | |
604 | gdb_test "p parrays->array5" " = \"hij\"" | |
605 | gdb_test "p &parrays->array5" " = \\(unsigned char \\(\\*\\)\\\[4\\\]\\) $hex" | |
606 | ||
a0b3c4fd | 607 | gdb_test "set print address off" "" |
c906108c SS |
608 | } |
609 | ||
610 | proc test_print_string_constants {} { | |
611 | global gdb_prompt | |
612 | ||
a0b3c4fd | 613 | gdb_test "set print elements 50" "" |
c906108c SS |
614 | |
615 | if [target_info exists gdb,cannot_call_functions] { | |
616 | setup_xfail "*-*-*" 2416 | |
617 | fail "This target can not call functions" | |
618 | return | |
619 | } | |
620 | ||
9846de1b JM |
621 | # We need to up this because this can be really slow on some boards. |
622 | # (Test may involve inferior malloc() calls). | |
623 | set timeout 60; | |
624 | ||
c906108c | 625 | gdb_test "p \"a string\"" " = \"a string\"" |
0deec7d6 | 626 | gdb_test "p \"embedded \\000 null\"" " = \"embedded \\\\000 null\"" |
c906108c | 627 | gdb_test "p \"abcd\"\[2\]" " = 99 'c'" |
c906108c | 628 | gdb_test "p sizeof (\"abcdef\")" " = 7" |
c906108c | 629 | gdb_test "ptype \"foo\"" " = char \\\[4\\\]" |
c906108c | 630 | gdb_test "p *\"foo\"" " = 102 'f'" |
c906108c | 631 | gdb_test "ptype *\"foo\"" " = char" |
c906108c | 632 | gdb_test "p &*\"foo\"" " = \"foo\"" |
b0023472 | 633 | setup_kfail "gdb/538" *-*-* |
c906108c | 634 | gdb_test "ptype &*\"foo\"" "type = char \\*" |
c906108c SS |
635 | gdb_test "p (char *)\"foo\"" " = \"foo\"" |
636 | } | |
637 | ||
638 | proc test_print_array_constants {} { | |
639 | ||
640 | if [target_info exists gdb,cannot_call_functions] { | |
641 | setup_xfail "*-*-*" 2416 | |
642 | fail "This target can not call functions" | |
643 | return | |
644 | } | |
645 | ||
9846de1b JM |
646 | # We need to up this because this can be really slow on some boards. |
647 | # (Test may involve inferior malloc() calls). | |
648 | set timeout 60; | |
649 | ||
c906108c | 650 | gdb_test "print {'a','b','c'}" " = \"abc\"" |
39124dea | 651 | gdb_test_escape_braces "print {0,1,2}" " = {0, 1, 2}" |
39124dea | 652 | gdb_test_escape_braces "print {(long)0,(long)1,(long)2}" " = {0, 1, 2}" |
39124dea | 653 | gdb_test_escape_braces "print {{0,1,2},{3,4,5}}" " = {{0, 1, 2}, {3, 4, 5}}" |
c906108c | 654 | gdb_test "print {4,5,6}\[2\]" " = 6" |
c906108c SS |
655 | gdb_test "print *&{4,5,6}\[1\]" " = 5" |
656 | } | |
657 | ||
658 | proc test_printf {} { | |
659 | gdb_test "printf \"x=%d,y=%d,z=%d\\n\", 5, 6, 7" "x=5,y=6,z=7" | |
660 | gdb_test "printf \"string=%.4sxx\\n\", teststring" "string=testxx" | |
661 | gdb_test "printf \"string=%sxx\\n\", teststring" \ | |
662 | "string=teststring contentsxx" | |
663 | ||
664 | gdb_test "printf \"%f is fun\\n\", 1.0" "1\.0+ is fun" | |
665 | ||
666 | # Test mixing args of different sizes. | |
667 | gdb_test "printf \"x=%d,y=%f,z=%d\\n\", 5, 6.0, 7" "x=5,y=6\.0+,z=7" | |
668 | gdb_test "printf \"%x %f, %c %x, %x, %f\\n\", 0xbad, -99.541, 'z',\ | |
669 | 0xfeedface, 0xdeadbeef, 5.0" "bad -99.54\[0-9\]+, z feedface, deadbeef, 5.0+" | |
670 | } | |
671 | ||
39124dea FN |
672 | # Escape a left curly brace to prevent it from being interpreted as |
673 | # the beginning of a bound | |
674 | proc gdb_test_escape_braces { args } { | |
675 | ||
676 | set pattern [lindex $args 1] | |
677 | regsub -all {\{[0-9]} $pattern {\\&} esc_pattern | |
678 | gdb_test [lindex $args 0] $esc_pattern [lindex $args 2] | |
679 | } | |
680 | ||
c906108c SS |
681 | # Start with a fresh gdb. |
682 | ||
683 | gdb_exit | |
684 | gdb_start | |
685 | gdb_reinitialize_dir $srcdir/$subdir | |
686 | ||
687 | gdb_test "print \$pc" "No registers\\." | |
688 | # FIXME: should also test "print $pc" when there is an execfile but no | |
689 | # remote debugging target, process or corefile. | |
690 | ||
691 | gdb_load ${binfile} | |
692 | ||
693 | gdb_test "set print sevenbit-strings" "" | |
a0b3c4fd | 694 | gdb_test "set print address off" "" |
c906108c SS |
695 | gdb_test "set width 0" "" |
696 | ||
697 | if [set_lang_c] then { | |
698 | gdb_test "p ctable1\[120\]" "120 'x'" "p ctable1\[120\] #1" | |
699 | ||
700 | if [runto_main] then { | |
701 | test_integer_literals_accepted | |
702 | test_integer_literals_rejected | |
703 | test_character_literals_accepted | |
704 | test_print_all_chars | |
705 | test_print_repeats_10 | |
706 | test_print_strings | |
707 | test_print_int_arrays | |
751a959b | 708 | test_print_typedef_arrays |
c906108c SS |
709 | test_artificial_arrays |
710 | test_print_char_arrays | |
711 | # We used to do the runto main here. | |
712 | test_print_string_constants | |
713 | test_print_array_constants | |
714 | test_printf | |
715 | } | |
716 | } else { | |
717 | fail "C print command tests suppressed" | |
718 | } |