]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/printcmds.exp
* gdb.base/call-ar-st.exp (set_lang_c): Delete, unused.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / printcmds.exp
1 # This testcase is part of GDB, the GNU debugger.
2
3 # Copyright 1992, 1994, 1995, 1996, 1997, 1999, 2000, 2002, 2003, 2004, 2007,
4 # 2008, 2009, 2010 Free Software Foundation, Inc.
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 3 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, see <http://www.gnu.org/licenses/>.
18
19 # Please email any bugs, comments, and/or additions to this file to:
20 # bug-gdb@gnu.org
21
22 # This file was written by Fred Fish. (fnf@cygnus.com)
23
24 if $tracelevel then {
25 strace $tracelevel
26 }
27
28 set testfile "printcmds"
29 set srcfile ${testfile}.c
30 set binfile ${objdir}/${subdir}/${testfile}
31 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
32 untested printcmds.exp
33 return -1
34 }
35
36 get_compiler_info ${binfile}
37
38 proc test_integer_literals_accepted {} {
39 global gdb_prompt
40
41 # Test various decimal values.
42
43 gdb_test "p 123" " = 123"
44 gdb_test "p -123" " = -123"
45 gdb_test "p/d 123" " = 123"
46
47 # Test various octal values.
48
49 gdb_test "p 0123" " = 83"
50 gdb_test "p 00123" " = 83"
51 gdb_test "p -0123" " = -83"
52 gdb_test "p/o 0123" " = 0123"
53
54 # Test various hexadecimal values.
55
56 gdb_test "p 0x123" " = 291"
57 gdb_test "p -0x123" " = -291"
58 gdb_test "p 0x0123" " = 291"
59 gdb_test "p -0x0123" " = -291"
60 gdb_test "p 0xABCDEF" " = 11259375"
61 gdb_test "p 0xabcdef" " = 11259375"
62 gdb_test "p 0xAbCdEf" " = 11259375"
63 gdb_test "p/x 0x123" " = 0x123"
64
65 # Test various binary values.
66
67 gdb_test "p 0b0" " = 0"
68 gdb_test "p 0b1111" " = 15"
69 gdb_test "p 0B1111" " = 15"
70 gdb_test "p -0b1111" " = -15"
71 }
72
73 proc test_character_literals_accepted {} {
74 global gdb_prompt
75
76 gdb_test "p 'a'" " = 97 'a'"
77 gdb_test "p/c 'a'" " = 97 'a'"
78 gdb_test "p/x 'a'" " = 0x61"
79 gdb_test "p/d 'a'" " = 97"
80 gdb_test "p/t 'a'" " = 1100001"
81 gdb_test "p '\\141'" " = 97 'a'"
82 gdb_test "p/x '\\377'" " = 0xff"
83 # Note "p '\''" => "= 39 '\''"
84 gdb_test "p '\\''" " = 39 '\\\\''"
85 # Note "p '\\'" => "= 92 '\\'"
86 gdb_test "p '\\\\'" " = 92 '\\\\\\\\'"
87 }
88
89 proc test_integer_literals_rejected {} {
90 global gdb_prompt
91
92 test_print_reject "p 0x"
93 test_print_reject "p 0b"
94 gdb_test "p ''" "(Empty character constant\\.|A character constant must contain at least one character\\.)"
95 gdb_test "p '''" "(Empty character constant\\.|A character constant must contain at least one character\\.)"
96 test_print_reject "p '\\'"
97
98 # Note that this turns into "p '\\\'" at gdb's input.
99 test_print_reject "p '\\\\\\'"
100
101 # Test various decimal values.
102
103 test_print_reject "p DEADBEEF"
104
105 # Gdb currently fails this test for all configurations. The C
106 # lexer thinks that 123DEADBEEF is a floating point number, but
107 # then fails to notice that atof() only eats the 123 part.
108 # FIXME: This should be put into PRMS.
109 # Fixed, 4/25/97, by Bob Manson.
110
111 test_print_reject "p 123DEADBEEF"
112 test_print_reject "p 123foobar.bazfoo3"
113 test_print_reject "p 123EEEEEEEEEEEEEEEEE33333k333"
114 gdb_test "p 123.4+56.7" "180.(099\[0-9]*|100\[0-9\]*)" "check for floating addition"
115
116 # Test various octal values.
117
118 test_print_reject "p 09"
119 test_print_reject "p 079"
120
121 # Test various hexadecimal values.
122
123 test_print_reject "p 0xG"
124 test_print_reject "p 0xAG"
125
126 # Test various binary values.
127
128 test_print_reject "p 0b2"
129 test_print_reject "p 0b12"
130 }
131
132 proc test_print_all_chars {} {
133 global gdb_prompt
134
135 gdb_test "p ctable1\[0\]" " = 0 '\\\\000'"
136 gdb_test "p ctable1\[1\]" " = 1 '\\\\001'"
137 gdb_test "p ctable1\[2\]" " = 2 '\\\\002'"
138 gdb_test "p ctable1\[3\]" " = 3 '\\\\003'"
139 gdb_test "p ctable1\[4\]" " = 4 '\\\\004'"
140 gdb_test "p ctable1\[5\]" " = 5 '\\\\005'"
141 gdb_test "p ctable1\[6\]" " = 6 '\\\\006'"
142 gdb_test "p ctable1\[7\]" " = 7 '\\\\a'"
143 gdb_test "p ctable1\[8\]" " = 8 '\\\\b'"
144 gdb_test "p ctable1\[9\]" " = 9 '\\\\t'"
145 gdb_test "p ctable1\[10\]" " = 10 '\\\\n'"
146 gdb_test "p ctable1\[11\]" " = 11 '\\\\v'"
147 gdb_test "p ctable1\[12\]" " = 12 '\\\\f'"
148 gdb_test "p ctable1\[13\]" " = 13 '\\\\r'"
149 gdb_test "p ctable1\[14\]" " = 14 '\\\\016'"
150 gdb_test "p ctable1\[15\]" " = 15 '\\\\017'"
151 gdb_test "p ctable1\[16\]" " = 16 '\\\\020'"
152 gdb_test "p ctable1\[17\]" " = 17 '\\\\021'"
153 gdb_test "p ctable1\[18\]" " = 18 '\\\\022'"
154 gdb_test "p ctable1\[19\]" " = 19 '\\\\023'"
155 gdb_test "p ctable1\[20\]" " = 20 '\\\\024'"
156 gdb_test "p ctable1\[21\]" " = 21 '\\\\025'"
157 gdb_test "p ctable1\[22\]" " = 22 '\\\\026'"
158 gdb_test "p ctable1\[23\]" " = 23 '\\\\027'"
159 gdb_test "p ctable1\[24\]" " = 24 '\\\\030'"
160 gdb_test "p ctable1\[25\]" " = 25 '\\\\031'"
161 gdb_test "p ctable1\[26\]" " = 26 '\\\\032'"
162 gdb_test "p ctable1\[27\]" " = 27 '\\\\033'"
163 gdb_test "p ctable1\[28\]" " = 28 '\\\\034'"
164 gdb_test "p ctable1\[29\]" " = 29 '\\\\035'"
165 gdb_test "p ctable1\[30\]" " = 30 '\\\\036'"
166 gdb_test "p ctable1\[31\]" " = 31 '\\\\037'"
167 gdb_test "p ctable1\[32\]" " = 32 ' '"
168 gdb_test "p ctable1\[33\]" " = 33 '!'"
169 gdb_test "p ctable1\[34\]" " = 34 '\"'"
170 gdb_test "p ctable1\[35\]" " = 35 '#'"
171 gdb_test "p ctable1\[36\]" " = 36 '\\\$'"
172 gdb_test "p ctable1\[37\]" " = 37 '%'"
173 gdb_test "p ctable1\[38\]" " = 38 '&'"
174 gdb_test "p ctable1\[39\]" " = 39 '\\\\''"
175 gdb_test "p ctable1\[40\]" " = 40 '\\('"
176 gdb_test "p ctable1\[41\]" " = 41 '\\)'"
177 gdb_test "p ctable1\[42\]" " = 42 '\\*'"
178 gdb_test "p ctable1\[43\]" " = 43 '\\+'"
179 gdb_test "p ctable1\[44\]" " = 44 ','"
180 gdb_test "p ctable1\[45\]" " = 45 '-'"
181 gdb_test "p ctable1\[46\]" " = 46 '.'"
182 gdb_test "p ctable1\[47\]" " = 47 '/'"
183 gdb_test "p ctable1\[48\]" " = 48 '0'"
184 gdb_test "p ctable1\[49\]" " = 49 '1'"
185 gdb_test "p ctable1\[50\]" " = 50 '2'"
186 gdb_test "p ctable1\[51\]" " = 51 '3'"
187 gdb_test "p ctable1\[52\]" " = 52 '4'"
188 gdb_test "p ctable1\[53\]" " = 53 '5'"
189 gdb_test "p ctable1\[54\]" " = 54 '6'"
190 gdb_test "p ctable1\[55\]" " = 55 '7'"
191 gdb_test "p ctable1\[56\]" " = 56 '8'"
192 gdb_test "p ctable1\[57\]" " = 57 '9'"
193 gdb_test "p ctable1\[58\]" " = 58 ':'"
194 gdb_test "p ctable1\[59\]" " = 59 ';'"
195 gdb_test "p ctable1\[60\]" " = 60 '<'"
196 gdb_test "p ctable1\[61\]" " = 61 '='"
197 gdb_test "p ctable1\[62\]" " = 62 '>'"
198 gdb_test "p ctable1\[63\]" " = 63 '\\?'"
199 gdb_test "p ctable1\[64\]" " = 64 '@'"
200 gdb_test "p ctable1\[65\]" " = 65 'A'"
201 gdb_test "p ctable1\[66\]" " = 66 'B'"
202 gdb_test "p ctable1\[67\]" " = 67 'C'"
203 gdb_test "p ctable1\[68\]" " = 68 'D'"
204 gdb_test "p ctable1\[69\]" " = 69 'E'"
205 gdb_test "p ctable1\[70\]" " = 70 'F'"
206 gdb_test "p ctable1\[71\]" " = 71 'G'"
207 gdb_test "p ctable1\[72\]" " = 72 'H'"
208 gdb_test "p ctable1\[73\]" " = 73 'I'"
209 gdb_test "p ctable1\[74\]" " = 74 'J'"
210 gdb_test "p ctable1\[75\]" " = 75 'K'"
211 gdb_test "p ctable1\[76\]" " = 76 'L'"
212 gdb_test "p ctable1\[77\]" " = 77 'M'"
213 gdb_test "p ctable1\[78\]" " = 78 'N'"
214 gdb_test "p ctable1\[79\]" " = 79 'O'"
215 gdb_test "p ctable1\[80\]" " = 80 'P'"
216 gdb_test "p ctable1\[81\]" " = 81 'Q'"
217 gdb_test "p ctable1\[82\]" " = 82 'R'"
218 gdb_test "p ctable1\[83\]" " = 83 'S'"
219 gdb_test "p ctable1\[84\]" " = 84 'T'"
220 gdb_test "p ctable1\[85\]" " = 85 'U'"
221 gdb_test "p ctable1\[86\]" " = 86 'V'"
222 gdb_test "p ctable1\[87\]" " = 87 'W'"
223 gdb_test "p ctable1\[88\]" " = 88 'X'"
224 gdb_test "p ctable1\[89\]" " = 89 'Y'"
225 gdb_test "p ctable1\[90\]" " = 90 'Z'"
226 gdb_test "p ctable1\[91\]" " = 91 '\\\['"
227 gdb_test "p ctable1\[92\]" " = 92 '\\\\\\\\'"
228 gdb_test "p ctable1\[93\]" " = 93 '\\\]'"
229 gdb_test "p ctable1\[94\]" " = 94 '\\^'"
230 gdb_test "p ctable1\[95\]" " = 95 '_'"
231 gdb_test "p ctable1\[96\]" " = 96 '`'"
232 gdb_test "p ctable1\[97\]" " = 97 'a'"
233 gdb_test "p ctable1\[98\]" " = 98 'b'"
234 gdb_test "p ctable1\[99\]" " = 99 'c'"
235 gdb_test "p ctable1\[100\]" " = 100 'd'"
236 gdb_test "p ctable1\[101\]" " = 101 'e'"
237 gdb_test "p ctable1\[102\]" " = 102 'f'"
238 gdb_test "p ctable1\[103\]" " = 103 'g'"
239 gdb_test "p ctable1\[104\]" " = 104 'h'"
240 gdb_test "p ctable1\[105\]" " = 105 'i'"
241 gdb_test "p ctable1\[106\]" " = 106 'j'"
242 gdb_test "p ctable1\[107\]" " = 107 'k'"
243 gdb_test "p ctable1\[108\]" " = 108 'l'"
244 gdb_test "p ctable1\[109\]" " = 109 'm'"
245 gdb_test "p ctable1\[110\]" " = 110 'n'"
246 gdb_test "p ctable1\[111\]" " = 111 'o'"
247 gdb_test "p ctable1\[112\]" " = 112 'p'"
248 gdb_test "p ctable1\[113\]" " = 113 'q'"
249 gdb_test "p ctable1\[114\]" " = 114 'r'"
250 gdb_test "p ctable1\[115\]" " = 115 's'"
251 gdb_test "p ctable1\[116\]" " = 116 't'"
252 gdb_test "p ctable1\[117\]" " = 117 'u'"
253 gdb_test "p ctable1\[118\]" " = 118 'v'"
254 gdb_test "p ctable1\[119\]" " = 119 'w'"
255 gdb_test "p ctable1\[120\]" " = 120 'x'"
256 gdb_test "p ctable1\[121\]" " = 121 'y'"
257 gdb_test "p ctable1\[122\]" " = 122 'z'"
258 gdb_test "p ctable1\[123\]" " = 123 '\[{\]+'"
259 gdb_test "p ctable1\[124\]" " = 124 '\[|\]+'"
260 gdb_test "p ctable1\[125\]" " = 125 '\[}\]+'"
261 gdb_test "p ctable1\[126\]" " = 126 '\[~\]'"
262 gdb_test "p ctable1\[127\]" " = 127 '\\\\177'"
263 gdb_test "p ctable1\[128\]" " = 128 '\\\\200'"
264 gdb_test "p ctable1\[129\]" " = 129 '\\\\201'"
265 gdb_test "p ctable1\[130\]" " = 130 '\\\\202'"
266 gdb_test "p ctable1\[131\]" " = 131 '\\\\203'"
267 gdb_test "p ctable1\[132\]" " = 132 '\\\\204'"
268 gdb_test "p ctable1\[133\]" " = 133 '\\\\205'"
269 gdb_test "p ctable1\[134\]" " = 134 '\\\\206'"
270 gdb_test "p ctable1\[135\]" " = 135 '\\\\207'"
271 gdb_test "p ctable1\[136\]" " = 136 '\\\\210'"
272 gdb_test "p ctable1\[137\]" " = 137 '\\\\211'"
273 gdb_test "p ctable1\[138\]" " = 138 '\\\\212'"
274 gdb_test "p ctable1\[139\]" " = 139 '\\\\213'"
275 gdb_test "p ctable1\[140\]" " = 140 '\\\\214'"
276 gdb_test "p ctable1\[141\]" " = 141 '\\\\215'"
277 gdb_test "p ctable1\[142\]" " = 142 '\\\\216'"
278 gdb_test "p ctable1\[143\]" " = 143 '\\\\217'"
279 gdb_test "p ctable1\[144\]" " = 144 '\\\\220'"
280 gdb_test "p ctable1\[145\]" " = 145 '\\\\221'"
281 gdb_test "p ctable1\[146\]" " = 146 '\\\\222'"
282 gdb_test "p ctable1\[147\]" " = 147 '\\\\223'"
283 gdb_test "p ctable1\[148\]" " = 148 '\\\\224'"
284 gdb_test "p ctable1\[149\]" " = 149 '\\\\225'"
285 gdb_test "p ctable1\[150\]" " = 150 '\\\\226'"
286 gdb_test "p ctable1\[151\]" " = 151 '\\\\227'"
287 gdb_test "p ctable1\[152\]" " = 152 '\\\\230'"
288 gdb_test "p ctable1\[153\]" " = 153 '\\\\231'"
289 gdb_test "p ctable1\[154\]" " = 154 '\\\\232'"
290 gdb_test "p ctable1\[155\]" " = 155 '\\\\233'"
291 gdb_test "p ctable1\[156\]" " = 156 '\\\\234'"
292 gdb_test "p ctable1\[157\]" " = 157 '\\\\235'"
293 gdb_test "p ctable1\[158\]" " = 158 '\\\\236'"
294 gdb_test "p ctable1\[159\]" " = 159 '\\\\237'"
295 gdb_test "p ctable1\[160\]" " = 160 '\\\\240'"
296 gdb_test "p ctable1\[161\]" " = 161 '\\\\241'"
297 gdb_test "p ctable1\[162\]" " = 162 '\\\\242'"
298 gdb_test "p ctable1\[163\]" " = 163 '\\\\243'"
299 gdb_test "p ctable1\[164\]" " = 164 '\\\\244'"
300 gdb_test "p ctable1\[165\]" " = 165 '\\\\245'"
301 gdb_test "p ctable1\[166\]" " = 166 '\\\\246'"
302 gdb_test "p ctable1\[167\]" " = 167 '\\\\247'"
303 gdb_test "p ctable1\[168\]" " = 168 '\\\\250'"
304 gdb_test "p ctable1\[169\]" " = 169 '\\\\251'"
305 gdb_test "p ctable1\[170\]" " = 170 '\\\\252'"
306 gdb_test "p ctable1\[171\]" " = 171 '\\\\253'"
307 gdb_test "p ctable1\[172\]" " = 172 '\\\\254'"
308 gdb_test "p ctable1\[173\]" " = 173 '\\\\255'"
309 gdb_test "p ctable1\[174\]" " = 174 '\\\\256'"
310 gdb_test "p ctable1\[175\]" " = 175 '\\\\257'"
311 gdb_test "p ctable1\[176\]" " = 176 '\\\\260'"
312 gdb_test "p ctable1\[177\]" " = 177 '\\\\261'"
313 gdb_test "p ctable1\[178\]" " = 178 '\\\\262'"
314 gdb_test "p ctable1\[179\]" " = 179 '\\\\263'"
315 gdb_test "p ctable1\[180\]" " = 180 '\\\\264'"
316 gdb_test "p ctable1\[181\]" " = 181 '\\\\265'"
317 gdb_test "p ctable1\[182\]" " = 182 '\\\\266'"
318 gdb_test "p ctable1\[183\]" " = 183 '\\\\267'"
319 gdb_test "p ctable1\[184\]" " = 184 '\\\\270'"
320 gdb_test "p ctable1\[185\]" " = 185 '\\\\271'"
321 gdb_test "p ctable1\[186\]" " = 186 '\\\\272'"
322 gdb_test "p ctable1\[187\]" " = 187 '\\\\273'"
323 gdb_test "p ctable1\[188\]" " = 188 '\\\\274'"
324 gdb_test "p ctable1\[189\]" " = 189 '\\\\275'"
325 gdb_test "p ctable1\[190\]" " = 190 '\\\\276'"
326 gdb_test "p ctable1\[191\]" " = 191 '\\\\277'"
327 gdb_test "p ctable1\[192\]" " = 192 '\\\\300'"
328 gdb_test "p ctable1\[193\]" " = 193 '\\\\301'"
329 gdb_test "p ctable1\[194\]" " = 194 '\\\\302'"
330 gdb_test "p ctable1\[195\]" " = 195 '\\\\303'"
331 gdb_test "p ctable1\[196\]" " = 196 '\\\\304'"
332 gdb_test "p ctable1\[197\]" " = 197 '\\\\305'"
333 gdb_test "p ctable1\[198\]" " = 198 '\\\\306'"
334 gdb_test "p ctable1\[199\]" " = 199 '\\\\307'"
335 gdb_test "p ctable1\[200\]" " = 200 '\\\\310'"
336 gdb_test "p ctable1\[201\]" " = 201 '\\\\311'"
337 gdb_test "p ctable1\[202\]" " = 202 '\\\\312'"
338 gdb_test "p ctable1\[203\]" " = 203 '\\\\313'"
339 gdb_test "p ctable1\[204\]" " = 204 '\\\\314'"
340 gdb_test "p ctable1\[205\]" " = 205 '\\\\315'"
341 gdb_test "p ctable1\[206\]" " = 206 '\\\\316'"
342 gdb_test "p ctable1\[207\]" " = 207 '\\\\317'"
343 gdb_test "p ctable1\[208\]" " = 208 '\\\\320'"
344 gdb_test "p ctable1\[209\]" " = 209 '\\\\321'"
345 gdb_test "p ctable1\[210\]" " = 210 '\\\\322'"
346 gdb_test "p ctable1\[211\]" " = 211 '\\\\323'"
347 gdb_test "p ctable1\[212\]" " = 212 '\\\\324'"
348 gdb_test "p ctable1\[213\]" " = 213 '\\\\325'"
349 gdb_test "p ctable1\[214\]" " = 214 '\\\\326'"
350 gdb_test "p ctable1\[215\]" " = 215 '\\\\327'"
351 gdb_test "p ctable1\[216\]" " = 216 '\\\\330'"
352 gdb_test "p ctable1\[217\]" " = 217 '\\\\331'"
353 gdb_test "p ctable1\[218\]" " = 218 '\\\\332'"
354 gdb_test "p ctable1\[219\]" " = 219 '\\\\333'"
355 gdb_test "p ctable1\[220\]" " = 220 '\\\\334'"
356 gdb_test "p ctable1\[221\]" " = 221 '\\\\335'"
357 gdb_test "p ctable1\[222\]" " = 222 '\\\\336'"
358 gdb_test "p ctable1\[223\]" " = 223 '\\\\337'"
359 gdb_test "p ctable1\[224\]" " = 224 '\\\\340'"
360 gdb_test "p ctable1\[225\]" " = 225 '\\\\341'"
361 gdb_test "p ctable1\[226\]" " = 226 '\\\\342'"
362 gdb_test "p ctable1\[227\]" " = 227 '\\\\343'"
363 gdb_test "p ctable1\[228\]" " = 228 '\\\\344'"
364 gdb_test "p ctable1\[229\]" " = 229 '\\\\345'"
365 gdb_test "p ctable1\[230\]" " = 230 '\\\\346'"
366 gdb_test "p ctable1\[231\]" " = 231 '\\\\347'"
367 gdb_test "p ctable1\[232\]" " = 232 '\\\\350'"
368 gdb_test "p ctable1\[233\]" " = 233 '\\\\351'"
369 gdb_test "p ctable1\[234\]" " = 234 '\\\\352'"
370 gdb_test "p ctable1\[235\]" " = 235 '\\\\353'"
371 gdb_test "p ctable1\[236\]" " = 236 '\\\\354'"
372 gdb_test "p ctable1\[237\]" " = 237 '\\\\355'"
373 gdb_test "p ctable1\[238\]" " = 238 '\\\\356'"
374 gdb_test "p ctable1\[239\]" " = 239 '\\\\357'"
375 gdb_test "p ctable1\[240\]" " = 240 '\\\\360'"
376 gdb_test "p ctable1\[241\]" " = 241 '\\\\361'"
377 gdb_test "p ctable1\[242\]" " = 242 '\\\\362'"
378 gdb_test "p ctable1\[243\]" " = 243 '\\\\363'"
379 gdb_test "p ctable1\[244\]" " = 244 '\\\\364'"
380 gdb_test "p ctable1\[245\]" " = 245 '\\\\365'"
381 gdb_test "p ctable1\[246\]" " = 246 '\\\\366'"
382 gdb_test "p ctable1\[247\]" " = 247 '\\\\367'"
383 gdb_test "p ctable1\[248\]" " = 248 '\\\\370'"
384 gdb_test "p ctable1\[249\]" " = 249 '\\\\371'"
385 gdb_test "p ctable1\[250\]" " = 250 '\\\\372'"
386 gdb_test "p ctable1\[251\]" " = 251 '\\\\373'"
387 gdb_test "p ctable1\[252\]" " = 252 '\\\\374'"
388 gdb_test "p ctable1\[253\]" " = 253 '\\\\375'"
389 gdb_test "p ctable1\[254\]" " = 254 '\\\\376'"
390 gdb_test "p ctable1\[255\]" " = 255 '\\\\377'"
391 }
392
393 # Test interaction of the number of print elements to print and the
394 # repeat count, set to the default of 10.
395
396 proc test_print_repeats_10 {} {
397 global gdb_prompt
398
399 for { set x 1; } { $x <= 16 } { incr x; } {
400 gdb_test_no_output "set print elements $x"
401 for { set e 1; } { $e <= 16 } {incr e; } {
402 set v [expr $e - 1];
403 set command "p &ctable2\[${v}*16\]"
404 if { $x < $e } {
405 set aval $x;
406 } else {
407 set aval $e;
408 }
409 set xval [expr $x - $e];
410 if { $xval < 0 } {
411 set xval 0;
412 }
413 if { $aval > 10 } {
414 set a "'a' <repeats $aval times>";
415 if { $xval > 0 } {
416 set a "${a}, \\\"";
417 }
418 } else {
419 set a "\\\"[string range "aaaaaaaaaaaaaaaa" 1 $aval]";
420 if { $xval > 10 } {
421 set a "$a\\\", ";
422 }
423 }
424 set xstr "";
425 if { $xval > 10 } {
426 set xstr "'X' <repeats $xval times>";
427 } else {
428 if { $xval > 0 } {
429 set xstr "[string range "XXXXXXXXXXXXXXXX" 1 $xval]\\\"";
430 } else {
431 if { $aval <= 10 } {
432 set xstr "\\\"";
433 }
434 }
435 }
436 if { $aval < 16 } {
437 set xstr "${xstr}\[.\]\[.\]\[.\]"
438 }
439 set string " = \[(\]unsigned char \[*\]\[)\] ${a}${xstr}";
440 gdb_test "$command" "$string" "$command with print elements set to $x";
441 }
442 }
443 }
444
445 proc test_print_strings {} {
446 global gdb_prompt
447
448 # We accept "(unsigned char *) " before the string. char vs. unsigned char
449 # is already tested elsewhere.
450
451 # Test that setting print elements unlimited doesn't completely suppress
452 # printing; this was a bug in older gdb's.
453 gdb_test_no_output "set print elements 0"
454 gdb_test "p teststring" \
455 " = (.unsigned char .. )?\"teststring contents\"" "p teststring with elements set to 0"
456 gdb_test_no_output "set print elements 1"
457 gdb_test "p teststring" \
458 " = (.unsigned char .. )?\"t\"\\.\\.\\." "p teststring with elements set to 1"
459 gdb_test_no_output "set print elements 5"
460 gdb_test "p teststring" \
461 " = (.unsigned char .. )?\"tests\"\\.\\.\\." "p teststring with elements set to 5"
462 gdb_test_no_output "set print elements 19"
463 gdb_test "p teststring" \
464 " = (.unsigned char .. )?\"teststring contents\"" "p teststring with elements set to 19"
465 gdb_test_no_output "set print elements 20"
466 gdb_test "p teststring" \
467 " = (.unsigned char .. )?\"teststring contents\"" "p teststring with elements set to 20"
468
469 gdb_test_no_output "set print elements 8"
470
471 gdb_test "p &ctable1\[0\]" \
472 " = \\(unsigned char \\*\\) \"\""
473 gdb_test "p &ctable1\[1\]" \
474 " = \\(unsigned char \\*\\) \"\\\\001\\\\002\\\\003\\\\004\\\\005\\\\006\\\\a\\\\b\"..."
475 gdb_test "p &ctable1\[1*8\]" \
476 " = \\(unsigned char \\*\\) \"\\\\b\\\\t\\\\n\\\\v\\\\f\\\\r\\\\016\\\\017\"..."
477 gdb_test "p &ctable1\[2*8\]" \
478 " = \\(unsigned char \\*\\) \"\\\\020\\\\021\\\\022\\\\023\\\\024\\\\025\\\\026\\\\027\"..."
479 gdb_test "p &ctable1\[3*8\]" \
480 " = \\(unsigned char \\*\\) \"\\\\030\\\\031\\\\032\\\\033\\\\034\\\\035\\\\036\\\\037\"..."
481 gdb_test "p &ctable1\[4*8\]" \
482 " = \\(unsigned char \\*\\) \" !\\\\\"#\\\$%&'\"..."
483 gdb_test "p &ctable1\[5*8\]" \
484 " = \\(unsigned char \\*\\) \"\\(\\)\\*\\+,-./\"..."
485 gdb_test "p &ctable1\[6*8\]" \
486 " = \\(unsigned char \\*\\) \"01234567\"..."
487 gdb_test "p &ctable1\[7*8\]" \
488 " = \\(unsigned char \\*\\) \"89:;<=>\\?\"..."
489 gdb_test "p &ctable1\[8*8\]" \
490 " = \\(unsigned char \\*\\) \"@ABCDEFG\"..."
491 gdb_test "p &ctable1\[9*8\]" \
492 " = \\(unsigned char \\*\\) \"HIJKLMNO\"..."
493 gdb_test "p &ctable1\[10*8\]" \
494 " = \\(unsigned char \\*\\) \"PQRSTUVW\"..."
495 gdb_test "p &ctable1\[11*8\]" \
496 " = \\(unsigned char \\*\\) \"XYZ\\\[\\\\\\\\\\\]\\^_\"..."
497 gdb_test "p &ctable1\[12*8\]" \
498 " = \\(unsigned char \\*\\) \"`abcdefg\"..."
499 gdb_test "p &ctable1\[13*8\]" \
500 " = \\(unsigned char \\*\\) \"hijklmno\"..."
501 gdb_test "p &ctable1\[14*8\]" \
502 " = \\(unsigned char \\*\\) \"pqrstuvw\"..."
503 gdb_test "p &ctable1\[15*8\]" \
504 " = \\(unsigned char \\*\\) \"xyz\[{|}\]+\\~\\\\177\"..."
505 gdb_test "p &ctable1\[16*8\]" \
506 " = \\(unsigned char \\*\\) \"\\\\200\\\\201\\\\202\\\\203\\\\204\\\\205\\\\206\\\\207\"..."
507 gdb_test "p &ctable1\[17*8\]" \
508 " = \\(unsigned char \\*\\) \"\\\\210\\\\211\\\\212\\\\213\\\\214\\\\215\\\\216\\\\217\"..."
509 gdb_test "p &ctable1\[18*8\]" \
510 " = \\(unsigned char \\*\\) \"\\\\220\\\\221\\\\222\\\\223\\\\224\\\\225\\\\226\\\\227\"..."
511 gdb_test "p &ctable1\[19*8\]" \
512 " = \\(unsigned char \\*\\) \"\\\\230\\\\231\\\\232\\\\233\\\\234\\\\235\\\\236\\\\237\"..."
513 gdb_test "p &ctable1\[20*8\]" \
514 " = \\(unsigned char \\*\\) \"\\\\240\\\\241\\\\242\\\\243\\\\244\\\\245\\\\246\\\\247\"..."
515 gdb_test "p &ctable1\[21*8\]" \
516 " = \\(unsigned char \\*\\) \"\\\\250\\\\251\\\\252\\\\253\\\\254\\\\255\\\\256\\\\257\"..."
517 gdb_test "p &ctable1\[22*8\]" \
518 " = \\(unsigned char \\*\\) \"\\\\260\\\\261\\\\262\\\\263\\\\264\\\\265\\\\266\\\\267\"..."
519 gdb_test "p &ctable1\[23*8\]" \
520 " = \\(unsigned char \\*\\) \"\\\\270\\\\271\\\\272\\\\273\\\\274\\\\275\\\\276\\\\277\"..."
521 gdb_test "p &ctable1\[24*8\]" \
522 " = \\(unsigned char \\*\\) \"\\\\300\\\\301\\\\302\\\\303\\\\304\\\\305\\\\306\\\\307\"..."
523 gdb_test "p &ctable1\[25*8\]" \
524 " = \\(unsigned char \\*\\) \"\\\\310\\\\311\\\\312\\\\313\\\\314\\\\315\\\\316\\\\317\"..."
525 gdb_test "p &ctable1\[26*8\]" \
526 " = \\(unsigned char \\*\\) \"\\\\320\\\\321\\\\322\\\\323\\\\324\\\\325\\\\326\\\\327\"..."
527 gdb_test "p &ctable1\[27*8\]" \
528 " = \\(unsigned char \\*\\) \"\\\\330\\\\331\\\\332\\\\333\\\\334\\\\335\\\\336\\\\337\"..."
529 gdb_test "p &ctable1\[28*8\]" \
530 " = \\(unsigned char \\*\\) \"\\\\340\\\\341\\\\342\\\\343\\\\344\\\\345\\\\346\\\\347\"..."
531 gdb_test "p &ctable1\[29*8\]" \
532 " = \\(unsigned char \\*\\) \"\\\\350\\\\351\\\\352\\\\353\\\\354\\\\355\\\\356\\\\357\"..."
533 gdb_test "p &ctable1\[30*8\]" \
534 " = \\(unsigned char \\*\\) \"\\\\360\\\\361\\\\362\\\\363\\\\364\\\\365\\\\366\\\\367\"..."
535 gdb_test "p &ctable1\[31*8\]" \
536 " = \\(unsigned char \\*\\) \"\\\\370\\\\371\\\\372\\\\373\\\\374\\\\375\\\\376\\\\377\"..."
537 }
538
539 proc test_print_int_arrays {} {
540 global gdb_prompt
541
542 gdb_test_no_output "set print elements 24"
543
544 gdb_test_escape_braces "p int1dim" \
545 " = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}"
546 gdb_test_escape_braces "p int2dim" \
547 " = {{0, 1, 2, 3}, {4, 5, 6, 7}, {8, 9, 10, 11}}"
548 gdb_test_escape_braces "p int3dim" \
549 " = {{{0, 1}, {2, 3}, {4, 5}}, {{6, 7}, {8, 9}, {10, 11}}}"
550 gdb_test_escape_braces "p int4dim" \
551 " = {{{{0, 1}, {2, 3}, {4, 5}}, {{6, 7}, {8, 9}, {10, 11}}}}"
552 }
553
554 proc test_print_typedef_arrays {} {
555 global gdb_prompt
556
557 gdb_test_no_output "set print elements 24"
558
559 gdb_test_escape_braces "p a1" \
560 " = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20}"
561 gdb_test "p a1\[0\]" " = 2"
562 gdb_test "p a1\[9\]" " = 20"
563
564 gdb_test "p a2" \
565 " = \"abcd\""
566 gdb_test "p a2\[0\]" " = 97 'a'"
567 gdb_test "p a2\[3\]" " = 100 'd'"
568
569 # Regression test of null-stop; PR 11049.
570 gdb_test_no_output "set print null-stop on"
571 gdb_test "p a2" " = \"abcd\"" "print a2 with null-stop on"
572 gdb_test_no_output "set print null-stop off"
573 }
574
575 proc test_artificial_arrays {} {
576 # Send \026@ instead of just @ in case the kill character is @.
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" \
579 "({{0, 1}, {2, 3}, {4, 5}}|\[Cc\]annot.*)" \
580 {p int1dim[0]@2@3}
581 gdb_test_escape_braces {p/x (short [])0x12345678} \
582 " = ({0x1234, 0x5678}|{0x5678, 0x1234})"
583 }
584
585 proc test_print_char_arrays {} {
586 global gdb_prompt
587 global hex
588
589 gdb_test_no_output "set print elements 24"
590 gdb_test_no_output "set print address on"
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
607 gdb_test_no_output "set print address off"
608 }
609
610 proc test_print_string_constants {} {
611 global gdb_prompt
612
613 gdb_test_no_output "set print elements 50"
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
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
625 gdb_test "p \"a string\"" " = \"a string\""
626 gdb_test "p \"embedded \\000 null\"" " = \"embedded \\\\000 null\""
627 gdb_test "p \"abcd\"\[2\]" " = 99 'c'"
628 gdb_test "p sizeof (\"abcdef\")" " = 7"
629 gdb_test "ptype \"foo\"" " = char \\\[4\\\]"
630 gdb_test "p *\"foo\"" " = 102 'f'"
631 gdb_test "ptype *\"foo\"" " = char"
632 gdb_test "p &*\"foo\"" " = \"foo\""
633 gdb_test "ptype &*\"foo\"" "type = char \\*"
634 gdb_test "p (char *)\"foo\"" " = \"foo\""
635 }
636
637 proc test_print_array_constants {} {
638
639 if [target_info exists gdb,cannot_call_functions] {
640 setup_xfail "*-*-*" 2416
641 fail "This target can not call functions"
642 return
643 }
644
645 # We need to up this because this can be really slow on some boards.
646 # (Test may involve inferior malloc() calls).
647 set timeout 60;
648
649 gdb_test "print {'a','b','c'}" " = \"abc\""
650 gdb_test_escape_braces "print {0,1,2}" " = {0, 1, 2}"
651 gdb_test_escape_braces "print {(long)0,(long)1,(long)2}" " = {0, 1, 2}"
652 gdb_test_escape_braces "print {{0,1,2},{3,4,5}}" " = {{0, 1, 2}, {3, 4, 5}}"
653 gdb_test "print {4,5,6}\[2\]" " = 6"
654 gdb_test "print *&{4,5,6}\[1\]" "Attempt to take address of value not located in memory."
655 }
656
657 proc test_print_enums {} {
658 # Regression test for PR11827.
659 gdb_test "print some_volatile_enum" "enumvolval1"
660 }
661
662 proc test_printf {} {
663 gdb_test "printf \"x=%d,y=%d,z=%d\\n\", 5, 6, 7" "x=5,y=6,z=7"
664 gdb_test "printf \"string=%.4sxx\\n\", teststring" "string=testxx"
665 gdb_test "printf \"string=%sxx\\n\", teststring" \
666 "string=teststring contentsxx"
667
668 gdb_test "printf \"%f is fun\\n\", 1.0" "1\.0+ is fun"
669
670 # Test mixing args of different sizes.
671 gdb_test "printf \"x=%d,y=%f,z=%d\\n\", 5, 6.0, 7" "x=5,y=6\.0+,z=7"
672 gdb_test "printf \"%x %f, %c %x, %x, %f\\n\", 0xbad, -99.541, 'z',\
673 0xfeedface, 0xdeadbeef, 5.0" "bad -99.54\[0-9\]+, z feedface, deadbeef, 5.0+"
674
675 # Regression test for C lexer bug.
676 gdb_test "printf \"%c\\n\", \"x\"\[1,0\]" "x"
677
678 # Regression test for "%% at end of format string.
679 # See http://sourceware.org/bugzilla/show_bug.cgi?id=11345
680 gdb_test "printf \"%%%d%%\\n\", 5" "%5%"
681 }
682
683 #Test printing DFP values with printf
684 proc test_printf_with_dfp {} {
685
686 # Test various dfp values, covering 32-bit, 64-bit and 128-bit ones
687
688 # _Decimal32 constants, which can support up to 7 digits
689 gdb_test "printf \"%Hf\\n\",1.2df" "1.2"
690 gdb_test "printf \"%Hf\\n\",-1.2df" "-1.2"
691 gdb_test "printf \"%Hf\\n\",1.234567df" "1.234567"
692 gdb_test "printf \"%Hf\\n\",-1.234567df" "-1.234567"
693 gdb_test "printf \"%Hf\\n\",1234567.df" "1234567"
694 gdb_test "printf \"%Hf\\n\",-1234567.df" "-1234567"
695
696 gdb_test "printf \"%Hf\\n\",1.2E1df" "12"
697 gdb_test "printf \"%Hf\\n\",1.2E10df" "1.2E\\+10"
698 gdb_test "printf \"%Hf\\n\",1.2E-10df" "1.2E-10"
699
700 # The largest exponent for 32-bit dfp value is 96.
701 gdb_test "printf \"%Hf\\n\",1.2E96df" "1.200000E\\+96"
702
703 # _Decimal64 constants, which can support up to 16 digits
704 gdb_test "printf \"%Df\\n\",1.2dd" "1.2"
705 gdb_test "printf \"%Df\\n\",-1.2dd" "-1.2"
706 gdb_test "printf \"%Df\\n\",1.234567890123456dd" "1.234567890123456"
707 gdb_test "printf \"%Df\\n\",-1.234567890123456dd" "-1.234567890123456"
708 gdb_test "printf \"%Df\\n\",1234567890123456.dd" "1234567890123456"
709 gdb_test "printf \"%Df\\n\",-1234567890123456.dd" "-1234567890123456"
710
711 gdb_test "printf \"%Df\\n\",1.2E1dd" "12"
712 gdb_test "printf \"%Df\\n\",1.2E10dd" "1.2E\\+10"
713 gdb_test "printf \"%Df\\n\",1.2E-10dd" "1.2E-10"
714
715 # The largest exponent for 64-bit dfp value is 384.
716 gdb_test "printf \"%Df\\n\",1.2E384dd" "1.200000000000000E\\+384"
717
718 # _Decimal128 constants, which can support up to 34 digits
719 gdb_test "printf \"%DDf\\n\",1.2dl" "1.2"
720 gdb_test "printf \"%DDf\\n\",-1.2dl" "-1.2"
721 gdb_test "printf \"%DDf\\n\",1.234567890123456789012345678901234dl" "1.234567890123456789012345678901234"
722 gdb_test "printf \"%DDf\\n\",-1.234567890123456789012345678901234dl" "-1.234567890123456789012345678901234"
723 gdb_test "printf \"%DDf\\n\",1234567890123456789012345678901234.dl" "1234567890123456789012345678901234"
724 gdb_test "printf \"%DDf\\n\",-1234567890123456789012345678901234.dl" "-1234567890123456789012345678901234"
725
726 gdb_test "printf \"%DDf\\n\",1.2E1dl" "12"
727 gdb_test "printf \"%DDf\\n\",1.2E10dl" "1.2E\\+10"
728 gdb_test "printf \"%DDf\\n\",1.2E-10dl" "1.2E-10"
729
730 # The largest exponent for 128-bit dfp value is 6144.
731 gdb_test "printf \"%DDf\\n\",1.2E6144dl" "1.200000000000000000000000000000000E\\+6144"
732 }
733
734 # Escape a left curly brace to prevent it from being interpreted as
735 # the beginning of a bound
736 proc gdb_test_escape_braces { args } {
737
738 set pattern [lindex $args 1]
739 regsub -all {\{[0-9]} $pattern {\\&} esc_pattern
740 gdb_test [lindex $args 0] $esc_pattern [lindex $args 2]
741 }
742
743 # Start with a fresh gdb.
744
745 gdb_exit
746 gdb_start
747 gdb_reinitialize_dir $srcdir/$subdir
748
749 gdb_test "print \$pc" "No registers\\."
750
751 # Some simple operations on strings should work even without a target
752 # (and therefore without calling malloc).
753 gdb_test "print \"abc\"" " = \"abc\""
754 gdb_test "print sizeof (\"abc\")" " = 4"
755 gdb_test "ptype \"abc\"" " = char \\\[4\\\]"
756 gdb_test "print \$cvar = \"abc\"" " = \"abc\""
757 gdb_test "print sizeof (\$cvar)" " = 4"
758
759 gdb_file_cmd ${binfile}
760
761 gdb_test "print \$pc" "No registers\\." "print \$pc (with file)"
762
763 gdb_test_no_output "set print sevenbit-strings"
764 gdb_test_no_output "set print address off"
765 gdb_test_no_output "set width 0"
766
767 if { [test_compiler_info "armcc-*"] } {
768 # ARM RealView compresses large arrays in the data segment.
769 # Before the program starts, we can not read them. There is
770 # nothing in the file to indicate that data is compressed.
771 setup_xfail "arm*-*-eabi"
772 }
773 gdb_test "p ctable1\[120\]" "120 'x'" "p ctable1\[120\] #1"
774
775 gdb_load ${binfile}
776
777 if ![runto_main] then {
778 fail "Can't run to main"
779 return 0
780 }
781
782 test_integer_literals_accepted
783 test_integer_literals_rejected
784 test_character_literals_accepted
785 test_print_all_chars
786 test_print_repeats_10
787 test_print_strings
788 test_print_int_arrays
789 test_print_typedef_arrays
790 test_artificial_arrays
791 test_print_char_arrays
792 # We used to do the runto main here.
793 test_print_string_constants
794 test_print_array_constants
795 test_print_enums
796 test_printf
797 test_printf_with_dfp