Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / printcmds.exp
CommitLineData
0dcd613f
AC
1# This testcase is part of GDB, the GNU debugger.
2
88b9d363 3# Copyright 1992-2022 Free Software Foundation, Inc.
c906108c
SS
4
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
e22f8b7c 7# the Free Software Foundation; either version 3 of the License, or
c906108c 8# (at your option) any later version.
e22f8b7c 9#
c906108c
SS
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
e22f8b7c 14#
c906108c 15# You should have received a copy of the GNU General Public License
e22f8b7c 16# along with this program. If not, see <http://www.gnu.org/licenses/>.
c906108c
SS
17
18# Please email any bugs, comments, and/or additions to this file to:
0dcd613f 19# bug-gdb@gnu.org
c906108c
SS
20
21# This file was written by Fred Fish. (fnf@cygnus.com)
22
822bd149
TT
23standard_testfile .c
24
c906108c 25if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
84c93cd5 26 untested "failed to compile"
b60f0898 27 return -1
c906108c
SS
28}
29
4c93b1db 30get_compiler_info
293e2f9e 31
c906108c
SS
32proc test_integer_literals_accepted {} {
33 global gdb_prompt
34
35 # Test various decimal values.
36
37 gdb_test "p 123" " = 123"
38 gdb_test "p -123" " = -123"
39 gdb_test "p/d 123" " = 123"
40
41 # Test various octal values.
42
43 gdb_test "p 0123" " = 83"
44 gdb_test "p 00123" " = 83"
45 gdb_test "p -0123" " = -83"
46 gdb_test "p/o 0123" " = 0123"
47
48 # Test various hexadecimal values.
49
50 gdb_test "p 0x123" " = 291"
51 gdb_test "p -0x123" " = -291"
52 gdb_test "p 0x0123" " = 291"
53 gdb_test "p -0x0123" " = -291"
54 gdb_test "p 0xABCDEF" " = 11259375"
55 gdb_test "p 0xabcdef" " = 11259375"
56 gdb_test "p 0xAbCdEf" " = 11259375"
57 gdb_test "p/x 0x123" " = 0x123"
b5cfddf5
JK
58
59 # Test various binary values.
60
61 gdb_test "p 0b0" " = 0"
62 gdb_test "p 0b1111" " = 15"
63 gdb_test "p 0B1111" " = 15"
64 gdb_test "p -0b1111" " = -15"
c906108c
SS
65}
66
67proc test_character_literals_accepted {} {
68 global gdb_prompt
69
70 gdb_test "p 'a'" " = 97 'a'"
71 gdb_test "p/c 'a'" " = 97 'a'"
72 gdb_test "p/x 'a'" " = 0x61"
73 gdb_test "p/d 'a'" " = 97"
74 gdb_test "p/t 'a'" " = 1100001"
75 gdb_test "p '\\141'" " = 97 'a'"
76 gdb_test "p/x '\\377'" " = 0xff"
77 # Note "p '\''" => "= 39 '\''"
78 gdb_test "p '\\''" " = 39 '\\\\''"
79 # Note "p '\\'" => "= 92 '\\'"
80 gdb_test "p '\\\\'" " = 92 '\\\\\\\\'"
81}
82
83proc test_integer_literals_rejected {} {
84 global gdb_prompt
85
b5cfddf5
JK
86 test_print_reject "p 0x"
87 test_print_reject "p 0b"
c4b7bc2b
JB
88 gdb_test "p ''" "(Empty character constant\\.|A character constant must contain at least one character\\.)"
89 gdb_test "p '''" "(Empty character constant\\.|A character constant must contain at least one character\\.)"
c906108c
SS
90 test_print_reject "p '\\'"
91
92 # Note that this turns into "p '\\\'" at gdb's input.
93 test_print_reject "p '\\\\\\'"
94
95 # Test various decimal values.
96
97 test_print_reject "p DEADBEEF"
98
c906108c
SS
99 # Test various octal values.
100
101 test_print_reject "p 09"
102 test_print_reject "p 079"
103
104 # Test various hexadecimal values.
105
106 test_print_reject "p 0xG"
107 test_print_reject "p 0xAG"
b5cfddf5
JK
108
109 # Test various binary values.
110
111 test_print_reject "p 0b2"
112 test_print_reject "p 0b12"
c906108c
SS
113}
114
d30f5e1f 115proc test_float_accepted {} {
809df446
JK
116 global gdb_prompt
117
d30f5e1f
DE
118 # This test is useful to catch successful parsing of the first fp value.
119 gdb_test "p 123.4+56.7" " = 180.(099\[0-9]*|100\[0-9\]*)" "check for floating addition"
120
121 # Test all the suffixes (including no suffix).
122 gdb_test "p 1." " = 1"
123 gdb_test "p 1.5" " = 1.5"
124 gdb_test "p 1.f" " = 1"
125 gdb_test "p 1.5f" " = 1.5"
126 gdb_test "p 1.l" " = 1"
127 gdb_test "p 1.5l" " = 1.5"
809df446
JK
128
129 # Test hexadecimal floating point.
2b4e6a3f
TT
130 foreach {num result} {
131 0x1.1 1.0625
132 0x1.8480000000000p+6 97.125
133 0x1.8480000000000p6 97.125
134 0x00.1p0 0.0625
135 0x00.1p1 0.125
136 0x00.1p-1 0.03125
137 } {
138 gdb_test "p $num" " = [string_to_regexp $result]"
809df446 139 }
d30f5e1f
DE
140}
141
142proc test_float_rejected {} {
143 # Gdb use to fail this test for all configurations. The C
144 # lexer thought that 123DEADBEEF was a floating point number, but
145 # then failed to notice that atof() only eats the 123 part.
146 # Fixed, 4/25/97, by Bob Manson.
147 test_print_reject "p 123DEADBEEF"
148
149 test_print_reject "p 123foobar.bazfoo3"
150 test_print_reject "p 123EEEEEEEEEEEEEEEEE33333k333"
d30f5e1f
DE
151
152 # Test bad suffixes.
153 test_print_reject "p 1.1x"
154 test_print_reject "p 1.1ff"
155 test_print_reject "p 1.1ll"
156}
157
d6382fff
TT
158# Regression test for PR gdb/21675
159proc test_radices {} {
160 gdb_test "print/o 16777211" " = 077777773"
161 gdb_test "print/d 1.5" " = 1"
162 gdb_test "print/u 1.5" " = 1"
163
164 gdb_test "print/u (char) -1" " = 255"
165 gdb_test "print/d (unsigned char) -1" " = -1"
166}
167
c906108c
SS
168proc test_print_all_chars {} {
169 global gdb_prompt
170
389b98f7
YQ
171 # Set the target-charset to ASCII, because the output varies from
172 # different charset.
173 with_target_charset "ASCII" {
174
175 gdb_test "p ctable1\[0\]" " = 0 '\\\\000'"
176 gdb_test "p ctable1\[1\]" " = 1 '\\\\001'"
177 gdb_test "p ctable1\[2\]" " = 2 '\\\\002'"
178 gdb_test "p ctable1\[3\]" " = 3 '\\\\003'"
179 gdb_test "p ctable1\[4\]" " = 4 '\\\\004'"
180 gdb_test "p ctable1\[5\]" " = 5 '\\\\005'"
181 gdb_test "p ctable1\[6\]" " = 6 '\\\\006'"
182 gdb_test "p ctable1\[7\]" " = 7 '\\\\a'"
183 gdb_test "p ctable1\[8\]" " = 8 '\\\\b'"
184 gdb_test "p ctable1\[9\]" " = 9 '\\\\t'"
185 gdb_test "p ctable1\[10\]" " = 10 '\\\\n'"
186 gdb_test "p ctable1\[11\]" " = 11 '\\\\v'"
187 gdb_test "p ctable1\[12\]" " = 12 '\\\\f'"
188 gdb_test "p ctable1\[13\]" " = 13 '\\\\r'"
189 gdb_test "p ctable1\[14\]" " = 14 '\\\\016'"
190 gdb_test "p ctable1\[15\]" " = 15 '\\\\017'"
191 gdb_test "p ctable1\[16\]" " = 16 '\\\\020'"
192 gdb_test "p ctable1\[17\]" " = 17 '\\\\021'"
193 gdb_test "p ctable1\[18\]" " = 18 '\\\\022'"
194 gdb_test "p ctable1\[19\]" " = 19 '\\\\023'"
195 gdb_test "p ctable1\[20\]" " = 20 '\\\\024'"
196 gdb_test "p ctable1\[21\]" " = 21 '\\\\025'"
197 gdb_test "p ctable1\[22\]" " = 22 '\\\\026'"
198 gdb_test "p ctable1\[23\]" " = 23 '\\\\027'"
199 gdb_test "p ctable1\[24\]" " = 24 '\\\\030'"
200 gdb_test "p ctable1\[25\]" " = 25 '\\\\031'"
201 gdb_test "p ctable1\[26\]" " = 26 '\\\\032'"
202 gdb_test "p ctable1\[27\]" " = 27 '\\\\033'"
203 gdb_test "p ctable1\[28\]" " = 28 '\\\\034'"
204 gdb_test "p ctable1\[29\]" " = 29 '\\\\035'"
205 gdb_test "p ctable1\[30\]" " = 30 '\\\\036'"
206 gdb_test "p ctable1\[31\]" " = 31 '\\\\037'"
207 gdb_test "p ctable1\[32\]" " = 32 ' '"
208 gdb_test "p ctable1\[33\]" " = 33 '!'"
209 gdb_test "p ctable1\[34\]" " = 34 '\"'"
210 gdb_test "p ctable1\[35\]" " = 35 '#'"
211 gdb_test "p ctable1\[36\]" " = 36 '\\\$'"
212 gdb_test "p ctable1\[37\]" " = 37 '%'"
213 gdb_test "p ctable1\[38\]" " = 38 '&'"
214 gdb_test "p ctable1\[39\]" " = 39 '\\\\''"
215 gdb_test "p ctable1\[40\]" " = 40 '\\('"
216 gdb_test "p ctable1\[41\]" " = 41 '\\)'"
217 gdb_test "p ctable1\[42\]" " = 42 '\\*'"
218 gdb_test "p ctable1\[43\]" " = 43 '\\+'"
219 gdb_test "p ctable1\[44\]" " = 44 ','"
220 gdb_test "p ctable1\[45\]" " = 45 '-'"
221 gdb_test "p ctable1\[46\]" " = 46 '.'"
222 gdb_test "p ctable1\[47\]" " = 47 '/'"
223 gdb_test "p ctable1\[48\]" " = 48 '0'"
224 gdb_test "p ctable1\[49\]" " = 49 '1'"
225 gdb_test "p ctable1\[50\]" " = 50 '2'"
226 gdb_test "p ctable1\[51\]" " = 51 '3'"
227 gdb_test "p ctable1\[52\]" " = 52 '4'"
228 gdb_test "p ctable1\[53\]" " = 53 '5'"
229 gdb_test "p ctable1\[54\]" " = 54 '6'"
230 gdb_test "p ctable1\[55\]" " = 55 '7'"
231 gdb_test "p ctable1\[56\]" " = 56 '8'"
232 gdb_test "p ctable1\[57\]" " = 57 '9'"
233 gdb_test "p ctable1\[58\]" " = 58 ':'"
234 gdb_test "p ctable1\[59\]" " = 59 ';'"
235 gdb_test "p ctable1\[60\]" " = 60 '<'"
236 gdb_test "p ctable1\[61\]" " = 61 '='"
237 gdb_test "p ctable1\[62\]" " = 62 '>'"
238 gdb_test "p ctable1\[63\]" " = 63 '\\?'"
239 gdb_test "p ctable1\[64\]" " = 64 '@'"
240 gdb_test "p ctable1\[65\]" " = 65 'A'"
241 gdb_test "p ctable1\[66\]" " = 66 'B'"
242 gdb_test "p ctable1\[67\]" " = 67 'C'"
243 gdb_test "p ctable1\[68\]" " = 68 'D'"
244 gdb_test "p ctable1\[69\]" " = 69 'E'"
245 gdb_test "p ctable1\[70\]" " = 70 'F'"
246 gdb_test "p ctable1\[71\]" " = 71 'G'"
247 gdb_test "p ctable1\[72\]" " = 72 'H'"
248 gdb_test "p ctable1\[73\]" " = 73 'I'"
249 gdb_test "p ctable1\[74\]" " = 74 'J'"
250 gdb_test "p ctable1\[75\]" " = 75 'K'"
251 gdb_test "p ctable1\[76\]" " = 76 'L'"
252 gdb_test "p ctable1\[77\]" " = 77 'M'"
253 gdb_test "p ctable1\[78\]" " = 78 'N'"
254 gdb_test "p ctable1\[79\]" " = 79 'O'"
255 gdb_test "p ctable1\[80\]" " = 80 'P'"
256 gdb_test "p ctable1\[81\]" " = 81 'Q'"
257 gdb_test "p ctable1\[82\]" " = 82 'R'"
258 gdb_test "p ctable1\[83\]" " = 83 'S'"
259 gdb_test "p ctable1\[84\]" " = 84 'T'"
260 gdb_test "p ctable1\[85\]" " = 85 'U'"
261 gdb_test "p ctable1\[86\]" " = 86 'V'"
262 gdb_test "p ctable1\[87\]" " = 87 'W'"
263 gdb_test "p ctable1\[88\]" " = 88 'X'"
264 gdb_test "p ctable1\[89\]" " = 89 'Y'"
265 gdb_test "p ctable1\[90\]" " = 90 'Z'"
266 gdb_test "p ctable1\[91\]" " = 91 '\\\['"
267 gdb_test "p ctable1\[92\]" " = 92 '\\\\\\\\'"
268 gdb_test "p ctable1\[93\]" " = 93 '\\\]'"
269 gdb_test "p ctable1\[94\]" " = 94 '\\^'"
270 gdb_test "p ctable1\[95\]" " = 95 '_'"
271 gdb_test "p ctable1\[96\]" " = 96 '`'"
272 gdb_test "p ctable1\[97\]" " = 97 'a'"
273 gdb_test "p ctable1\[98\]" " = 98 'b'"
274 gdb_test "p ctable1\[99\]" " = 99 'c'"
275 gdb_test "p ctable1\[100\]" " = 100 'd'"
276 gdb_test "p ctable1\[101\]" " = 101 'e'"
277 gdb_test "p ctable1\[102\]" " = 102 'f'"
278 gdb_test "p ctable1\[103\]" " = 103 'g'"
279 gdb_test "p ctable1\[104\]" " = 104 'h'"
280 gdb_test "p ctable1\[105\]" " = 105 'i'"
281 gdb_test "p ctable1\[106\]" " = 106 'j'"
282 gdb_test "p ctable1\[107\]" " = 107 'k'"
283 gdb_test "p ctable1\[108\]" " = 108 'l'"
284 gdb_test "p ctable1\[109\]" " = 109 'm'"
285 gdb_test "p ctable1\[110\]" " = 110 'n'"
286 gdb_test "p ctable1\[111\]" " = 111 'o'"
287 gdb_test "p ctable1\[112\]" " = 112 'p'"
288 gdb_test "p ctable1\[113\]" " = 113 'q'"
289 gdb_test "p ctable1\[114\]" " = 114 'r'"
290 gdb_test "p ctable1\[115\]" " = 115 's'"
291 gdb_test "p ctable1\[116\]" " = 116 't'"
292 gdb_test "p ctable1\[117\]" " = 117 'u'"
293 gdb_test "p ctable1\[118\]" " = 118 'v'"
294 gdb_test "p ctable1\[119\]" " = 119 'w'"
295 gdb_test "p ctable1\[120\]" " = 120 'x'"
296 gdb_test "p ctable1\[121\]" " = 121 'y'"
297 gdb_test "p ctable1\[122\]" " = 122 'z'"
298 gdb_test "p ctable1\[123\]" " = 123 '\[{\]+'"
299 gdb_test "p ctable1\[124\]" " = 124 '\[|\]+'"
300 gdb_test "p ctable1\[125\]" " = 125 '\[}\]+'"
301 gdb_test "p ctable1\[126\]" " = 126 '\[~\]'"
302 gdb_test "p ctable1\[127\]" " = 127 '\\\\177'"
303 gdb_test "p ctable1\[128\]" " = 128 '\\\\200'"
304 gdb_test "p ctable1\[129\]" " = 129 '\\\\201'"
305 gdb_test "p ctable1\[130\]" " = 130 '\\\\202'"
306 gdb_test "p ctable1\[131\]" " = 131 '\\\\203'"
307 gdb_test "p ctable1\[132\]" " = 132 '\\\\204'"
308 gdb_test "p ctable1\[133\]" " = 133 '\\\\205'"
309 gdb_test "p ctable1\[134\]" " = 134 '\\\\206'"
310 gdb_test "p ctable1\[135\]" " = 135 '\\\\207'"
311 gdb_test "p ctable1\[136\]" " = 136 '\\\\210'"
312 gdb_test "p ctable1\[137\]" " = 137 '\\\\211'"
313 gdb_test "p ctable1\[138\]" " = 138 '\\\\212'"
314 gdb_test "p ctable1\[139\]" " = 139 '\\\\213'"
315 gdb_test "p ctable1\[140\]" " = 140 '\\\\214'"
316 gdb_test "p ctable1\[141\]" " = 141 '\\\\215'"
317 gdb_test "p ctable1\[142\]" " = 142 '\\\\216'"
318 gdb_test "p ctable1\[143\]" " = 143 '\\\\217'"
319 gdb_test "p ctable1\[144\]" " = 144 '\\\\220'"
320 gdb_test "p ctable1\[145\]" " = 145 '\\\\221'"
321 gdb_test "p ctable1\[146\]" " = 146 '\\\\222'"
322 gdb_test "p ctable1\[147\]" " = 147 '\\\\223'"
323 gdb_test "p ctable1\[148\]" " = 148 '\\\\224'"
324 gdb_test "p ctable1\[149\]" " = 149 '\\\\225'"
325 gdb_test "p ctable1\[150\]" " = 150 '\\\\226'"
326 gdb_test "p ctable1\[151\]" " = 151 '\\\\227'"
327 gdb_test "p ctable1\[152\]" " = 152 '\\\\230'"
328 gdb_test "p ctable1\[153\]" " = 153 '\\\\231'"
329 gdb_test "p ctable1\[154\]" " = 154 '\\\\232'"
330 gdb_test "p ctable1\[155\]" " = 155 '\\\\233'"
331 gdb_test "p ctable1\[156\]" " = 156 '\\\\234'"
332 gdb_test "p ctable1\[157\]" " = 157 '\\\\235'"
333 gdb_test "p ctable1\[158\]" " = 158 '\\\\236'"
334 gdb_test "p ctable1\[159\]" " = 159 '\\\\237'"
335 gdb_test "p ctable1\[160\]" " = 160 '\\\\240'"
336 gdb_test "p ctable1\[161\]" " = 161 '\\\\241'"
337 gdb_test "p ctable1\[162\]" " = 162 '\\\\242'"
338 gdb_test "p ctable1\[163\]" " = 163 '\\\\243'"
339 gdb_test "p ctable1\[164\]" " = 164 '\\\\244'"
340 gdb_test "p ctable1\[165\]" " = 165 '\\\\245'"
341 gdb_test "p ctable1\[166\]" " = 166 '\\\\246'"
342 gdb_test "p ctable1\[167\]" " = 167 '\\\\247'"
343 gdb_test "p ctable1\[168\]" " = 168 '\\\\250'"
344 gdb_test "p ctable1\[169\]" " = 169 '\\\\251'"
345 gdb_test "p ctable1\[170\]" " = 170 '\\\\252'"
346 gdb_test "p ctable1\[171\]" " = 171 '\\\\253'"
347 gdb_test "p ctable1\[172\]" " = 172 '\\\\254'"
348 gdb_test "p ctable1\[173\]" " = 173 '\\\\255'"
349 gdb_test "p ctable1\[174\]" " = 174 '\\\\256'"
350 gdb_test "p ctable1\[175\]" " = 175 '\\\\257'"
351 gdb_test "p ctable1\[176\]" " = 176 '\\\\260'"
352 gdb_test "p ctable1\[177\]" " = 177 '\\\\261'"
353 gdb_test "p ctable1\[178\]" " = 178 '\\\\262'"
354 gdb_test "p ctable1\[179\]" " = 179 '\\\\263'"
355 gdb_test "p ctable1\[180\]" " = 180 '\\\\264'"
356 gdb_test "p ctable1\[181\]" " = 181 '\\\\265'"
357 gdb_test "p ctable1\[182\]" " = 182 '\\\\266'"
358 gdb_test "p ctable1\[183\]" " = 183 '\\\\267'"
359 gdb_test "p ctable1\[184\]" " = 184 '\\\\270'"
360 gdb_test "p ctable1\[185\]" " = 185 '\\\\271'"
361 gdb_test "p ctable1\[186\]" " = 186 '\\\\272'"
362 gdb_test "p ctable1\[187\]" " = 187 '\\\\273'"
363 gdb_test "p ctable1\[188\]" " = 188 '\\\\274'"
364 gdb_test "p ctable1\[189\]" " = 189 '\\\\275'"
365 gdb_test "p ctable1\[190\]" " = 190 '\\\\276'"
366 gdb_test "p ctable1\[191\]" " = 191 '\\\\277'"
367 gdb_test "p ctable1\[192\]" " = 192 '\\\\300'"
368 gdb_test "p ctable1\[193\]" " = 193 '\\\\301'"
369 gdb_test "p ctable1\[194\]" " = 194 '\\\\302'"
370 gdb_test "p ctable1\[195\]" " = 195 '\\\\303'"
371 gdb_test "p ctable1\[196\]" " = 196 '\\\\304'"
372 gdb_test "p ctable1\[197\]" " = 197 '\\\\305'"
373 gdb_test "p ctable1\[198\]" " = 198 '\\\\306'"
374 gdb_test "p ctable1\[199\]" " = 199 '\\\\307'"
375 gdb_test "p ctable1\[200\]" " = 200 '\\\\310'"
376 gdb_test "p ctable1\[201\]" " = 201 '\\\\311'"
377 gdb_test "p ctable1\[202\]" " = 202 '\\\\312'"
378 gdb_test "p ctable1\[203\]" " = 203 '\\\\313'"
379 gdb_test "p ctable1\[204\]" " = 204 '\\\\314'"
380 gdb_test "p ctable1\[205\]" " = 205 '\\\\315'"
381 gdb_test "p ctable1\[206\]" " = 206 '\\\\316'"
382 gdb_test "p ctable1\[207\]" " = 207 '\\\\317'"
383 gdb_test "p ctable1\[208\]" " = 208 '\\\\320'"
384 gdb_test "p ctable1\[209\]" " = 209 '\\\\321'"
385 gdb_test "p ctable1\[210\]" " = 210 '\\\\322'"
386 gdb_test "p ctable1\[211\]" " = 211 '\\\\323'"
387 gdb_test "p ctable1\[212\]" " = 212 '\\\\324'"
388 gdb_test "p ctable1\[213\]" " = 213 '\\\\325'"
389 gdb_test "p ctable1\[214\]" " = 214 '\\\\326'"
390 gdb_test "p ctable1\[215\]" " = 215 '\\\\327'"
391 gdb_test "p ctable1\[216\]" " = 216 '\\\\330'"
392 gdb_test "p ctable1\[217\]" " = 217 '\\\\331'"
393 gdb_test "p ctable1\[218\]" " = 218 '\\\\332'"
394 gdb_test "p ctable1\[219\]" " = 219 '\\\\333'"
395 gdb_test "p ctable1\[220\]" " = 220 '\\\\334'"
396 gdb_test "p ctable1\[221\]" " = 221 '\\\\335'"
397 gdb_test "p ctable1\[222\]" " = 222 '\\\\336'"
398 gdb_test "p ctable1\[223\]" " = 223 '\\\\337'"
399 gdb_test "p ctable1\[224\]" " = 224 '\\\\340'"
400 gdb_test "p ctable1\[225\]" " = 225 '\\\\341'"
401 gdb_test "p ctable1\[226\]" " = 226 '\\\\342'"
402 gdb_test "p ctable1\[227\]" " = 227 '\\\\343'"
403 gdb_test "p ctable1\[228\]" " = 228 '\\\\344'"
404 gdb_test "p ctable1\[229\]" " = 229 '\\\\345'"
405 gdb_test "p ctable1\[230\]" " = 230 '\\\\346'"
406 gdb_test "p ctable1\[231\]" " = 231 '\\\\347'"
407 gdb_test "p ctable1\[232\]" " = 232 '\\\\350'"
408 gdb_test "p ctable1\[233\]" " = 233 '\\\\351'"
409 gdb_test "p ctable1\[234\]" " = 234 '\\\\352'"
410 gdb_test "p ctable1\[235\]" " = 235 '\\\\353'"
411 gdb_test "p ctable1\[236\]" " = 236 '\\\\354'"
412 gdb_test "p ctable1\[237\]" " = 237 '\\\\355'"
413 gdb_test "p ctable1\[238\]" " = 238 '\\\\356'"
414 gdb_test "p ctable1\[239\]" " = 239 '\\\\357'"
415 gdb_test "p ctable1\[240\]" " = 240 '\\\\360'"
416 gdb_test "p ctable1\[241\]" " = 241 '\\\\361'"
417 gdb_test "p ctable1\[242\]" " = 242 '\\\\362'"
418 gdb_test "p ctable1\[243\]" " = 243 '\\\\363'"
419 gdb_test "p ctable1\[244\]" " = 244 '\\\\364'"
420 gdb_test "p ctable1\[245\]" " = 245 '\\\\365'"
421 gdb_test "p ctable1\[246\]" " = 246 '\\\\366'"
422 gdb_test "p ctable1\[247\]" " = 247 '\\\\367'"
423 gdb_test "p ctable1\[248\]" " = 248 '\\\\370'"
424 gdb_test "p ctable1\[249\]" " = 249 '\\\\371'"
425 gdb_test "p ctable1\[250\]" " = 250 '\\\\372'"
426 gdb_test "p ctable1\[251\]" " = 251 '\\\\373'"
427 gdb_test "p ctable1\[252\]" " = 252 '\\\\374'"
428 gdb_test "p ctable1\[253\]" " = 253 '\\\\375'"
429 gdb_test "p ctable1\[254\]" " = 254 '\\\\376'"
430 gdb_test "p ctable1\[255\]" " = 255 '\\\\377'"
431 }
c906108c
SS
432}
433
434# Test interaction of the number of print elements to print and the
435# repeat count, set to the default of 10.
436
437proc test_print_repeats_10 {} {
9cb709b6 438 global gdb_prompt decimal
c906108c 439
13e4e967 440 for { set x 1 } { $x <= 16 } { incr x } {
1f6f6e21 441 gdb_test_no_output "set print elements $x" "elements $x repeats"
13e4e967 442 for { set e 1 } { $e <= 16 } {incr e } {
4ec70201 443 set v [expr $e - 1]
c906108c
SS
444 set command "p &ctable2\[${v}*16\]"
445 if { $x < $e } {
4ec70201 446 set aval $x
c906108c 447 } else {
4ec70201 448 set aval $e
c906108c 449 }
4ec70201 450 set xval [expr $x - $e]
c906108c 451 if { $xval < 0 } {
4ec70201 452 set xval 0
c906108c
SS
453 }
454 if { $aval > 10 } {
4ec70201 455 set a "'a' <repeats $aval times>"
c906108c 456 if { $xval > 0 } {
4ec70201 457 set a "${a}, \\\""
c906108c
SS
458 }
459 } else {
4ec70201 460 set a "\\\"[string range "aaaaaaaaaaaaaaaa" 1 $aval]"
c906108c 461 if { $xval > 10 } {
4ec70201 462 set a "$a\\\", "
c906108c
SS
463 }
464 }
4ec70201 465 set xstr ""
c906108c 466 if { $xval > 10 } {
4ec70201 467 set xstr "'X' <repeats $xval times>"
c906108c
SS
468 } else {
469 if { $xval > 0 } {
4ec70201 470 set xstr "[string range "XXXXXXXXXXXXXXXX" 1 $xval]\\\""
c906108c
SS
471 } else {
472 if { $aval <= 10 } {
4ec70201 473 set xstr "\\\""
c906108c
SS
474 }
475 }
476 }
477 if { $aval < 16 } {
478 set xstr "${xstr}\[.\]\[.\]\[.\]"
479 }
4ec70201
PA
480 set string " = \[(\]unsigned char \[*\]\[)\] <ctable2(\\+$decimal)?> ${a}${xstr}"
481 gdb_test "$command" "$string" "$command with print elements set to $x"
c906108c
SS
482 }
483 }
484}
485
490f124f
PA
486# This tests whether GDB uses the correct element content offsets
487# (relative to the complete `some_struct' value) when counting value
488# repetitions.
489
490proc test_print_repeats_embedded_array {} {
491 global gdb_prompt
492
493 gdb_test_escape_braces "p/x some_struct" \
494 "= {a = 0x12345678, b = 0x87654321, array = {0xaa <repeats 20 times>}}" \
495 "correct element repeats in array embedded at offset > 0"
496}
497
c906108c 498proc test_print_strings {} {
9cb709b6 499 global gdb_prompt decimal
c906108c
SS
500
501 # We accept "(unsigned char *) " before the string. char vs. unsigned char
502 # is already tested elsewhere.
503
504 # Test that setting print elements unlimited doesn't completely suppress
505 # printing; this was a bug in older gdb's.
27d3a1a2 506 gdb_test_no_output "set print elements 0"
c906108c
SS
507 gdb_test "p teststring" \
508 " = (.unsigned char .. )?\"teststring contents\"" "p teststring with elements set to 0"
27d3a1a2 509 gdb_test_no_output "set print elements 1"
c906108c
SS
510 gdb_test "p teststring" \
511 " = (.unsigned char .. )?\"t\"\\.\\.\\." "p teststring with elements set to 1"
27d3a1a2 512 gdb_test_no_output "set print elements 5"
c906108c
SS
513 gdb_test "p teststring" \
514 " = (.unsigned char .. )?\"tests\"\\.\\.\\." "p teststring with elements set to 5"
27d3a1a2 515 gdb_test_no_output "set print elements 19"
c906108c
SS
516 gdb_test "p teststring" \
517 " = (.unsigned char .. )?\"teststring contents\"" "p teststring with elements set to 19"
27d3a1a2 518 gdb_test_no_output "set print elements 20"
c906108c
SS
519 gdb_test "p teststring" \
520 " = (.unsigned char .. )?\"teststring contents\"" "p teststring with elements set to 20"
521
a1f6a07c 522 gdb_test "print teststring2" \
09546b56 523 " = \\(charptr\\) \"more contents\""
a1f6a07c 524
27d3a1a2 525 gdb_test_no_output "set print elements 8"
c906108c 526
389b98f7
YQ
527 # Set the target-charset to ASCII, because the output varies from
528 # different charset.
529 with_target_charset "ASCII" {
530 gdb_test "p &ctable1\[0\]" \
531 " = \\(unsigned char \\*\\) <ctable1> \"\""
532 gdb_test "p &ctable1\[1\]" \
533 " = \\(unsigned char \\*\\) <ctable1\\+$decimal> \"\\\\001\\\\002\\\\003\\\\004\\\\005\\\\006\\\\a\\\\b\"..."
534 gdb_test "p &ctable1\[1*8\]" \
535 " = \\(unsigned char \\*\\) <ctable1\\+$decimal> \"\\\\b\\\\t\\\\n\\\\v\\\\f\\\\r\\\\016\\\\017\"..."
536 gdb_test "p &ctable1\[2*8\]" \
537 " = \\(unsigned char \\*\\) <ctable1\\+$decimal> \"\\\\020\\\\021\\\\022\\\\023\\\\024\\\\025\\\\026\\\\027\"..."
538 gdb_test "p &ctable1\[3*8\]" \
539 " = \\(unsigned char \\*\\) <ctable1\\+$decimal> \"\\\\030\\\\031\\\\032\\\\033\\\\034\\\\035\\\\036\\\\037\"..."
540 gdb_test "p &ctable1\[4*8\]" \
541 " = \\(unsigned char \\*\\) <ctable1\\+$decimal> \" !\\\\\"#\\\$%&'\"..."
542 gdb_test "p &ctable1\[5*8\]" \
543 " = \\(unsigned char \\*\\) <ctable1\\+$decimal> \"\\(\\)\\*\\+,-./\"..."
544 gdb_test "p &ctable1\[6*8\]" \
545 " = \\(unsigned char \\*\\) <ctable1\\+$decimal> \"01234567\"..."
546 gdb_test "p &ctable1\[7*8\]" \
547 " = \\(unsigned char \\*\\) <ctable1\\+$decimal> \"89:;<=>\\?\"..."
548 gdb_test "p &ctable1\[8*8\]" \
549 " = \\(unsigned char \\*\\) <ctable1\\+$decimal> \"@ABCDEFG\"..."
550 gdb_test "p &ctable1\[9*8\]" \
551 " = \\(unsigned char \\*\\) <ctable1\\+$decimal> \"HIJKLMNO\"..."
552 gdb_test "p &ctable1\[10*8\]" \
553 " = \\(unsigned char \\*\\) <ctable1\\+$decimal> \"PQRSTUVW\"..."
554 gdb_test "p &ctable1\[11*8\]" \
555 " = \\(unsigned char \\*\\) <ctable1\\+$decimal> \"XYZ\\\[\\\\\\\\\\\]\\^_\"..."
556 gdb_test "p &ctable1\[12*8\]" \
557 " = \\(unsigned char \\*\\) <ctable1\\+$decimal> \"`abcdefg\"..."
558 gdb_test "p &ctable1\[13*8\]" \
559 " = \\(unsigned char \\*\\) <ctable1\\+$decimal> \"hijklmno\"..."
560 gdb_test "p &ctable1\[14*8\]" \
561 " = \\(unsigned char \\*\\) <ctable1\\+$decimal> \"pqrstuvw\"..."
562 gdb_test "p &ctable1\[15*8\]" \
563 " = \\(unsigned char \\*\\) <ctable1\\+$decimal> \"xyz\[{|}\]+\\~\\\\177\"..."
564 gdb_test "p &ctable1\[16*8\]" \
565 " = \\(unsigned char \\*\\) <ctable1\\+$decimal> \"\\\\200\\\\201\\\\202\\\\203\\\\204\\\\205\\\\206\\\\207\"..."
566 gdb_test "p &ctable1\[17*8\]" \
567 " = \\(unsigned char \\*\\) <ctable1\\+$decimal> \"\\\\210\\\\211\\\\212\\\\213\\\\214\\\\215\\\\216\\\\217\"..."
568 gdb_test "p &ctable1\[18*8\]" \
569 " = \\(unsigned char \\*\\) <ctable1\\+$decimal> \"\\\\220\\\\221\\\\222\\\\223\\\\224\\\\225\\\\226\\\\227\"..."
570 gdb_test "p &ctable1\[19*8\]" \
571 " = \\(unsigned char \\*\\) <ctable1\\+$decimal> \"\\\\230\\\\231\\\\232\\\\233\\\\234\\\\235\\\\236\\\\237\"..."
572 gdb_test "p &ctable1\[20*8\]" \
573 " = \\(unsigned char \\*\\) <ctable1\\+$decimal> \"\\\\240\\\\241\\\\242\\\\243\\\\244\\\\245\\\\246\\\\247\"..."
574 gdb_test "p &ctable1\[21*8\]" \
575 " = \\(unsigned char \\*\\) <ctable1\\+$decimal> \"\\\\250\\\\251\\\\252\\\\253\\\\254\\\\255\\\\256\\\\257\"..."
576 gdb_test "p &ctable1\[22*8\]" \
577 " = \\(unsigned char \\*\\) <ctable1\\+$decimal> \"\\\\260\\\\261\\\\262\\\\263\\\\264\\\\265\\\\266\\\\267\"..."
578 gdb_test "p &ctable1\[23*8\]" \
579 " = \\(unsigned char \\*\\) <ctable1\\+$decimal> \"\\\\270\\\\271\\\\272\\\\273\\\\274\\\\275\\\\276\\\\277\"..."
580 gdb_test "p &ctable1\[24*8\]" \
581 " = \\(unsigned char \\*\\) <ctable1\\+$decimal> \"\\\\300\\\\301\\\\302\\\\303\\\\304\\\\305\\\\306\\\\307\"..."
582 gdb_test "p &ctable1\[25*8\]" \
583 " = \\(unsigned char \\*\\) <ctable1\\+$decimal> \"\\\\310\\\\311\\\\312\\\\313\\\\314\\\\315\\\\316\\\\317\"..."
584 gdb_test "p &ctable1\[26*8\]" \
585 " = \\(unsigned char \\*\\) <ctable1\\+$decimal> \"\\\\320\\\\321\\\\322\\\\323\\\\324\\\\325\\\\326\\\\327\"..."
586 gdb_test "p &ctable1\[27*8\]" \
587 " = \\(unsigned char \\*\\) <ctable1\\+$decimal> \"\\\\330\\\\331\\\\332\\\\333\\\\334\\\\335\\\\336\\\\337\"..."
588 gdb_test "p &ctable1\[28*8\]" \
589 " = \\(unsigned char \\*\\) <ctable1\\+$decimal> \"\\\\340\\\\341\\\\342\\\\343\\\\344\\\\345\\\\346\\\\347\"..."
590 gdb_test "p &ctable1\[29*8\]" \
591 " = \\(unsigned char \\*\\) <ctable1\\+$decimal> \"\\\\350\\\\351\\\\352\\\\353\\\\354\\\\355\\\\356\\\\357\"..."
592 gdb_test "p &ctable1\[30*8\]" \
593 " = \\(unsigned char \\*\\) <ctable1\\+$decimal> \"\\\\360\\\\361\\\\362\\\\363\\\\364\\\\365\\\\366\\\\367\"..."
594 gdb_test "p &ctable1\[31*8\]" \
595 " = \\(unsigned char \\*\\) <ctable1\\+$decimal> \"\\\\370\\\\371\\\\372\\\\373\\\\374\\\\375\\\\376\\\\377\"..."
596 }
c906108c
SS
597}
598
599proc test_print_int_arrays {} {
600 global gdb_prompt
601
1f6f6e21 602 gdb_test_no_output "set print elements 24" "elements 24 int arrays"
c906108c 603
39124dea 604 gdb_test_escape_braces "p int1dim" \
c906108c 605 " = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}"
39124dea 606 gdb_test_escape_braces "p int2dim" \
c906108c 607 " = {{0, 1, 2, 3}, {4, 5, 6, 7}, {8, 9, 10, 11}}"
39124dea 608 gdb_test_escape_braces "p int3dim" \
c906108c 609 " = {{{0, 1}, {2, 3}, {4, 5}}, {{6, 7}, {8, 9}, {10, 11}}}"
39124dea 610 gdb_test_escape_braces "p int4dim" \
c906108c 611 " = {{{{0, 1}, {2, 3}, {4, 5}}, {{6, 7}, {8, 9}, {10, 11}}}}"
6fbe845e
AB
612
613 # Some checks for various output formats.
614 gdb_test_escape_braces "p/x int4dim" \
615 " = {{{{0x0, 0x1}, {0x2, 0x3}, {0x4, 0x5}}, {{0x6, 0x7}, {0x8, 0x9}, {0xa, 0xb}}}}"
616 gdb_test_escape_braces "p/z int4dim" \
617 " = {{{{0x0+0, 0x0+1}, {0x0+2, 0x0+3}, {0x0+4, 0x0+5}}, {{0x0+6, 0x0+7}, {0x0+8, 0x0+9}, {0x0+a, 0x0+b}}}}"
618 gdb_test_escape_braces "p/o int4dim" \
619 " = {{{{0, 01}, {02, 03}, {04, 05}}, {{06, 07}, {010, 011}, {012, 013}}}}"
620 gdb_test_escape_braces "p/t int4dim" \
621 " = {{{{0, 1}, {10, 11}, {100, 101}}, {{110, 111}, {1000, 1001}, {1010, 1011}}}}"
c906108c
SS
622}
623
751a959b
EZ
624proc test_print_typedef_arrays {} {
625 global gdb_prompt
626
1f6f6e21 627 gdb_test_no_output "set print elements 24" "elements 24 typedef_arrays"
751a959b 628
39124dea 629 gdb_test_escape_braces "p a1" \
751a959b
EZ
630 " = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20}"
631 gdb_test "p a1\[0\]" " = 2"
632 gdb_test "p a1\[9\]" " = 20"
633
634 gdb_test "p a2" \
635 " = \"abcd\""
636 gdb_test "p a2\[0\]" " = 97 'a'"
637 gdb_test "p a2\[3\]" " = 100 'd'"
421d5d99
TT
638
639 # Regression test of null-stop; PR 11049.
27d3a1a2 640 gdb_test_no_output "set print null-stop on"
421d5d99 641 gdb_test "p a2" " = \"abcd\"" "print a2 with null-stop on"
27d3a1a2 642 gdb_test_no_output "set print null-stop off"
751a959b
EZ
643}
644
c906108c
SS
645proc test_artificial_arrays {} {
646 # Send \026@ instead of just @ in case the kill character is @.
ae1d2761
PM
647 # \026 (ctrl-v) is to escape the next character (@), but it is
648 # not only unnecessary to do so on MingW hosts, but also harmful
649 # for the test because that character isn't recognized as an
650 # escape character.
651 set ctrlv "\026"
652 if [ishost *-*-mingw*] {
653 set ctrlv ""
654 }
655 gdb_test_escape_braces "p int1dim\[0\]${ctrlv}@2" " = {0, 1}" {p int1dim[0]@2}
656 gdb_test_escape_braces "p int1dim\[0\]${ctrlv}@2${ctrlv}@3" \
c906108c
SS
657 "({{0, 1}, {2, 3}, {4, 5}}|\[Cc\]annot.*)" \
658 {p int1dim[0]@2@3}
edd45eb0 659 gdb_test_escape_braces "p int1dim\[0\]${ctrlv}@FE_TWO" " = {0, 1}" \
cc63428a 660 {p int1dim[0]@TWO}
edd45eb0 661 gdb_test_escape_braces "p int1dim\[0\]${ctrlv}@FE_TWO${ctrlv}@three" \
cc63428a
AV
662 "({{0, 1}, {2, 3}, {4, 5}}|\[Cc\]annot.*)" \
663 {p int1dim[0]@TWO@three}
39124dea 664 gdb_test_escape_braces {p/x (short [])0x12345678} \
c906108c
SS
665 " = ({0x1234, 0x5678}|{0x5678, 0x1234})"
666}
667
668proc test_print_char_arrays {} {
669 global gdb_prompt
9cb709b6 670 global hex decimal
c906108c 671
1f6f6e21 672 gdb_test_no_output "set print elements 24" "elements 24 char_arrays"
27d3a1a2 673 gdb_test_no_output "set print address on"
c906108c
SS
674
675 gdb_test "p arrays" \
ea37ba09 676 " = {array1 = \"abc\", array2 = \"d\", array3 = \"e\", array4 = \"fg\", array5 = \"hij\"}"
c906108c 677
9cb709b6 678 gdb_test "p parrays" " = \\(struct some_arrays \\*\\) $hex <arrays>"
ea37ba09 679 gdb_test "p parrays->array1" " = \"abc\""
9cb709b6 680 gdb_test "p &parrays->array1" " = \\(unsigned char \\(\\*\\)\\\[4\\\]\\) $hex <arrays>"
ea37ba09 681 gdb_test "p parrays->array2" " = \"d\""
9cb709b6 682 gdb_test "p &parrays->array2" " = \\(unsigned char \\(\\*\\)\\\[1\\\]\\) $hex <arrays\\+$decimal>"
ea37ba09 683 gdb_test "p parrays->array3" " = \"e\""
9cb709b6 684 gdb_test "p &parrays->array3" " = \\(unsigned char \\(\\*\\)\\\[1\\\]\\) $hex <arrays\\+$decimal>"
ea37ba09 685 gdb_test "p parrays->array4" " = \"fg\""
9cb709b6 686 gdb_test "p &parrays->array4" " = \\(unsigned char \\(\\*\\)\\\[2\\\]\\) $hex <arrays\\+$decimal>"
ea37ba09 687 gdb_test "p parrays->array5" " = \"hij\""
9cb709b6 688 gdb_test "p &parrays->array5" " = \\(unsigned char \\(\\*\\)\\\[4\\\]\\) $hex <arrays\\+$decimal>"
c906108c 689
1f6f6e21 690 gdb_test_no_output "set print address off" "address off char arrays"
c906108c
SS
691}
692
693proc test_print_string_constants {} {
694 global gdb_prompt
695
27d3a1a2 696 gdb_test_no_output "set print elements 50"
c906108c
SS
697
698 if [target_info exists gdb,cannot_call_functions] {
bc6c7af4 699 unsupported "this target can not call functions"
c906108c
SS
700 return
701 }
702
9846de1b
JM
703 # We need to up this because this can be really slow on some boards.
704 # (Test may involve inferior malloc() calls).
4ec70201 705 set timeout 60
9846de1b 706
c906108c 707 gdb_test "p \"a string\"" " = \"a string\""
30b66ecc 708 gdb_test "p \"embedded \\000 null\"" " = \"embedded \\\\000 null\""
c906108c 709 gdb_test "p \"abcd\"\[2\]" " = 99 'c'"
c906108c 710 gdb_test "p sizeof (\"abcdef\")" " = 7"
c906108c 711 gdb_test "ptype \"foo\"" " = char \\\[4\\\]"
c906108c 712 gdb_test "p *\"foo\"" " = 102 'f'"
c906108c 713 gdb_test "ptype *\"foo\"" " = char"
c906108c 714 gdb_test "p &*\"foo\"" " = \"foo\""
c906108c 715 gdb_test "ptype &*\"foo\"" "type = char \\*"
c906108c
SS
716 gdb_test "p (char *)\"foo\"" " = \"foo\""
717}
718
719proc test_print_array_constants {} {
720
721 if [target_info exists gdb,cannot_call_functions] {
bc6c7af4 722 unsupported "this target can not call functions"
c906108c
SS
723 return
724 }
725
9846de1b
JM
726 # We need to up this because this can be really slow on some boards.
727 # (Test may involve inferior malloc() calls).
4ec70201 728 set timeout 60
9846de1b 729
c906108c 730 gdb_test "print {'a','b','c'}" " = \"abc\""
39124dea 731 gdb_test_escape_braces "print {0,1,2}" " = {0, 1, 2}"
39124dea 732 gdb_test_escape_braces "print {(long)0,(long)1,(long)2}" " = {0, 1, 2}"
39124dea 733 gdb_test_escape_braces "print {{0,1,2},{3,4,5}}" " = {{0, 1, 2}, {3, 4, 5}}"
c906108c 734 gdb_test "print {4,5,6}\[2\]" " = 6"
63092375 735 gdb_test "print *&{4,5,6}\[1\]" "Attempt to take address of value not located in memory."
c906108c
SS
736}
737
23bd0f7c
PA
738proc test_print_enums {} {
739 # Regression test for PR11827.
740 gdb_test "print some_volatile_enum" "enumvolval1"
cafec441 741
edd45eb0
SM
742 # Print a flag enum.
743 gdb_test "print three" [string_to_regexp " = (FE_ONE | FE_TWO)"]
744
745 # Print a flag enum with value 0, where an enumerator has value 0.
746 gdb_test "print (enum flag_enum) 0x0" [string_to_regexp " = FE_NONE"]
747
748 # Print a flag enum with value 0, where no enumerator has value 0.
373d7ac0 749 gdb_test "print flag_enum_without_zero" [string_to_regexp " = 0"]
edd45eb0
SM
750
751 # Print a flag enum with unknown bits set.
b29a2df0 752 gdb_test "print (enum flag_enum) 0xf1" [string_to_regexp " = (FE_ONE | unknown: 0xf0)"]
edd45eb0
SM
753
754 # Test printing an enum not considered a "flag enum" (because one of its
755 # enumerators has multiple bits set).
756 gdb_test "print three_not_flag" [string_to_regexp " = 3"]
23bd0f7c
PA
757}
758
c906108c
SS
759proc test_printf {} {
760 gdb_test "printf \"x=%d,y=%d,z=%d\\n\", 5, 6, 7" "x=5,y=6,z=7"
761 gdb_test "printf \"string=%.4sxx\\n\", teststring" "string=testxx"
762 gdb_test "printf \"string=%sxx\\n\", teststring" \
763 "string=teststring contentsxx"
764
765 gdb_test "printf \"%f is fun\\n\", 1.0" "1\.0+ is fun"
766
767 # Test mixing args of different sizes.
768 gdb_test "printf \"x=%d,y=%f,z=%d\\n\", 5, 6.0, 7" "x=5,y=6\.0+,z=7"
769 gdb_test "printf \"%x %f, %c %x, %x, %f\\n\", 0xbad, -99.541, 'z',\
7700xfeedface, 0xdeadbeef, 5.0" "bad -99.54\[0-9\]+, z feedface, deadbeef, 5.0+"
379a77b5
TT
771
772 # Regression test for C lexer bug.
773 gdb_test "printf \"%c\\n\", \"x\"\[1,0\]" "x"
a0e0ef55
TT
774
775 # Regression test for "%% at end of format string.
776 # See http://sourceware.org/bugzilla/show_bug.cgi?id=11345
777 gdb_test "printf \"%%%d%%\\n\", 5" "%5%"
5ea5559b
AB
778
779 # Some tests for missing format specifier after '%'.
780 gdb_test "printf \"%\", 0" "Incomplete format specifier at end of format string"
781 gdb_test "printf \"%.234\", 0" "Incomplete format specifier at end of format string"
782 gdb_test "printf \"%-\", 0" "Incomplete format specifier at end of format string"
783 gdb_test "printf \"%-23\", 0" "Incomplete format specifier at end of format string"
5c30d39a
AB
784
785 # Test for invalid printf flags on pointer types.
786 gdb_test "printf \"%#p\", 0" "Inappropriate modifiers to format specifier 'p' in printf"
787 gdb_test "printf \"% p\", 0" "Inappropriate modifiers to format specifier 'p' in printf"
788 gdb_test "printf \"%0p\", 0" "Inappropriate modifiers to format specifier 'p' in printf"
789 gdb_test "printf \"%+p\", 0" "Inappropriate modifiers to format specifier 'p' in printf"
50b34a18
TT
790
791
792 gdb_test "define hibob\nprintf \"hi bob \"\nshell echo zzz\nprintf \"y\\n\"\nend" \
793 "" \
794 "create hibob command"
795 gdb_test "hibob" "hi bob zzz.*y" "run hibob command"
b8c2339b
TT
796
797 # PR cli/19918.
798 gdb_test "printf \"%-16dq\\n\", 0" "0 q"
799 gdb_test "printf \"%-16pq\\n\", 0" "\\(nil\\) q"
3ae9ce5d
TT
800
801 # PR cli/14977.
802 gdb_test "printf \"%s\\n\", 0" "\\(null\\)"
c906108c
SS
803}
804
1a619819
LM
805#Test printing DFP values with printf
806proc test_printf_with_dfp {} {
807
808 # Test various dfp values, covering 32-bit, 64-bit and 128-bit ones
809
810 # _Decimal32 constants, which can support up to 7 digits
0aea4bf3
LM
811 gdb_test "printf \"%Hf\\n\",1.2df" "1.2"
812 gdb_test "printf \"%Hf\\n\",-1.2df" "-1.2"
813 gdb_test "printf \"%Hf\\n\",1.234567df" "1.234567"
814 gdb_test "printf \"%Hf\\n\",-1.234567df" "-1.234567"
815 gdb_test "printf \"%Hf\\n\",1234567.df" "1234567"
816 gdb_test "printf \"%Hf\\n\",-1234567.df" "-1234567"
1a619819 817
0aea4bf3
LM
818 gdb_test "printf \"%Hf\\n\",1.2E1df" "12"
819 gdb_test "printf \"%Hf\\n\",1.2E10df" "1.2E\\+10"
820 gdb_test "printf \"%Hf\\n\",1.2E-10df" "1.2E-10"
1a619819
LM
821
822 # The largest exponent for 32-bit dfp value is 96.
0aea4bf3 823 gdb_test "printf \"%Hf\\n\",1.2E96df" "1.200000E\\+96"
1a619819
LM
824
825 # _Decimal64 constants, which can support up to 16 digits
0aea4bf3
LM
826 gdb_test "printf \"%Df\\n\",1.2dd" "1.2"
827 gdb_test "printf \"%Df\\n\",-1.2dd" "-1.2"
828 gdb_test "printf \"%Df\\n\",1.234567890123456dd" "1.234567890123456"
829 gdb_test "printf \"%Df\\n\",-1.234567890123456dd" "-1.234567890123456"
830 gdb_test "printf \"%Df\\n\",1234567890123456.dd" "1234567890123456"
831 gdb_test "printf \"%Df\\n\",-1234567890123456.dd" "-1234567890123456"
1a619819 832
0aea4bf3
LM
833 gdb_test "printf \"%Df\\n\",1.2E1dd" "12"
834 gdb_test "printf \"%Df\\n\",1.2E10dd" "1.2E\\+10"
835 gdb_test "printf \"%Df\\n\",1.2E-10dd" "1.2E-10"
1a619819
LM
836
837 # The largest exponent for 64-bit dfp value is 384.
0aea4bf3 838 gdb_test "printf \"%Df\\n\",1.2E384dd" "1.200000000000000E\\+384"
1a619819
LM
839
840 # _Decimal128 constants, which can support up to 34 digits
0aea4bf3
LM
841 gdb_test "printf \"%DDf\\n\",1.2dl" "1.2"
842 gdb_test "printf \"%DDf\\n\",-1.2dl" "-1.2"
843 gdb_test "printf \"%DDf\\n\",1.234567890123456789012345678901234dl" "1.234567890123456789012345678901234"
844 gdb_test "printf \"%DDf\\n\",-1.234567890123456789012345678901234dl" "-1.234567890123456789012345678901234"
845 gdb_test "printf \"%DDf\\n\",1234567890123456789012345678901234.dl" "1234567890123456789012345678901234"
846 gdb_test "printf \"%DDf\\n\",-1234567890123456789012345678901234.dl" "-1234567890123456789012345678901234"
1a619819 847
0aea4bf3
LM
848 gdb_test "printf \"%DDf\\n\",1.2E1dl" "12"
849 gdb_test "printf \"%DDf\\n\",1.2E10dl" "1.2E\\+10"
850 gdb_test "printf \"%DDf\\n\",1.2E-10dl" "1.2E-10"
1a619819
LM
851
852 # The largest exponent for 128-bit dfp value is 6144.
0aea4bf3 853 gdb_test "printf \"%DDf\\n\",1.2E6144dl" "1.200000000000000000000000000000000E\\+6144"
c2792f5a
DE
854
855 # GDB used to get this wrong.
856 gdb_test "printf \"%Hf %Hf\\n\",1.2df,1.3df" "1.2 1.3"
1a619819
LM
857}
858
9cb709b6
TT
859proc test_print_symbol {} {
860 gdb_test_no_output "set print symbol on"
861
862 gdb_test "print &three" " = .* <three>"
863 gdb_test "print parrays" " = .* <arrays>"
864
865 # In case somebody adds tests after this.
866 gdb_test_no_output "set print symbol off"
867}
868
39124dea
FN
869# Escape a left curly brace to prevent it from being interpreted as
870# the beginning of a bound
871proc gdb_test_escape_braces { args } {
872
873 set pattern [lindex $args 1]
874 regsub -all {\{[0-9]} $pattern {\\&} esc_pattern
875 gdb_test [lindex $args 0] $esc_pattern [lindex $args 2]
876}
877
0d63ecda
KS
878proc test_repeat_bytes {} {
879 set start(E) {}
880 set start(S) {a}
881 set start(L) {abaabbaaabbb}
882 set start(R) {'a' <repeats 20 times>}
883 set end(E) {}
884 set end(S) {c}
885 set end(L) {cdccddcccddd}
886 set end(R) {'c' <repeats 20 times>}
887 set invalid(S) {\\240}
888 set invalid(L) {\\240\\240\\240\\240}
889 set invalid(R) {'\\240' <repeats 20 times>}
890
891 set fmt(SSS) "\"%s%s%s\""
892 set fmt(SSR) "\"%s%s\", %s"
893 set fmt(SRS) "\"%s\", %s, \"%s\""
894 set fmt(RSS) "%s, \"%s%s\""
895 set fmt(RSR) "%s, \"%s\", %s"
896 set fmt(SRR) "\"%s\", %s, %s"
897 set fmt(RRS) "%s, %s, \"%s\""
898 set fmt(RRR) "%s, %s, %s"
899
900 set fmt(RS) "%s, \"%s\""
901 set fmt(RR) "%s, %s"
902 set fmt(SR) "\"%s\", %s"
903 set fmt(SS) "\"%s%s\""
904
389b98f7
YQ
905 # Set the target-charset to ASCII, because the output varies from
906 # different charset.
907 with_target_charset "ASCII" {
908 # Test the various permutations of invalid characters
909 foreach i [array names invalid] {
910 set I $i
0d63ecda 911
389b98f7
YQ
912 if {$i == "L"} {
913 set i "S"
914 }
0d63ecda 915
389b98f7
YQ
916 foreach s [array names start] {
917 set S $s
0d63ecda 918
389b98f7
YQ
919 if {$s == "L"} {
920 set s "S"
921 }
0d63ecda
KS
922
923
389b98f7
YQ
924 foreach e [array names end] {
925 set E $e
0d63ecda 926
389b98f7
YQ
927 if {$e == "L"} {
928 set e "S"
929 }
0d63ecda 930
389b98f7
YQ
931 # Skip E*E.
932 if {$s == "E" && $e == "E"} { continue }
933
934 # Special cases...
935 if {$s == "E"} {
936 set result [format $fmt($i$e) $invalid($I) $end($E)]
937 } elseif {$e == "E"} {
938 set result [format $fmt($s$i) $start($S) $invalid($I)]
939 } else {
940 set result [format $fmt($s$i$e) \
941 $start($S) $invalid($I) $end($E)]
942 }
0d63ecda 943
389b98f7
YQ
944 send_log "expecting: = $result\n"
945 gdb_test "print invalid_$S$I$E" "= $result"
0d63ecda 946 }
0d63ecda
KS
947 }
948 }
949 }
950}
951
1f6f6e21
PW
952# Test printf of convenience variables.
953# These tests can be done with or without a running inferior.
954# PREFIX ensures uniqueness of test names.
1f6f6e21 955
0826779b 956proc test_printf_convenience_var {prefix} {
1f6f6e21
PW
957
958 with_test_prefix "conv var: $prefix" {
959 gdb_test_no_output "set var \$cstr = \"abcde\"" "set \$cstr"
960 gdb_test "printf \"cstr val = %s\\n\", \$cstr" "cstr val = abcde" \
961 "printf \$cstr"
962 gdb_test_no_output "set var \$abcde = \"ABCDE\"" "set \$abcde"
963 gdb_test "eval \"print \$%s\\n\", \$cstr" "= \"ABCDE\"" \
964 "indirect print abcde"
965 # Without a target, the below produces no output
966 # but with a target, it gives a warning.
967 # So, use gdb_test expecting ".*" instead of gdb_test_no_output.
11af934b 968 gdb_test "set language ada" ".*"
1f6f6e21
PW
969 gdb_test_no_output "set var \$astr := \"fghij\"" "set \$astr"
970 gdb_test "printf \"astr val = %s\\n\", \$astr" "astr val = fghij" \
971 "printf \$astr"
972 gdb_test_no_output "set language auto" "set language auto"
973 gdb_test "printf \"astr val = %s\\n\", \$astr" "astr val = fghij" \
974 "printf \$astr, auto language"
0826779b
PW
975 # Wide strings can only be created when wchar_t type is known.
976 # Switch to c++ for the wide strings tests, as wchar_t is predefined
977 # when current language is c++.
978 # See above "set language ada" about why we use gdb_test.
11af934b 979 gdb_test "set language c++" ".*"
0826779b
PW
980 gdb_test_no_output "set var \$wstr = L\"facile\"" \
981 "set \$wstr"
982 gdb_test "printf \"wstr val = %ls\\n\", \$wstr" \
983 "wstr val = facile" "printf \$wstr"
984 gdb_test_no_output "set language auto" "set language auto, wstring"
1f6f6e21
PW
985 }
986}
987
988
c906108c
SS
989# Start with a fresh gdb.
990
991gdb_exit
992gdb_start
993gdb_reinitialize_dir $srcdir/$subdir
994
995gdb_test "print \$pc" "No registers\\."
63092375
DJ
996
997# Some simple operations on strings should work even without a target
998# (and therefore without calling malloc).
999gdb_test "print \"abc\"" " = \"abc\""
1000gdb_test "print sizeof (\"abc\")" " = 4"
1001gdb_test "ptype \"abc\"" " = char \\\[4\\\]"
1002gdb_test "print \$cvar = \"abc\"" " = \"abc\""
1003gdb_test "print sizeof (\$cvar)" " = 4"
c906108c 1004
1f6f6e21 1005# Similarly, printf of a string convenience var should work without a target.
0826779b 1006test_printf_convenience_var "no target"
1f6f6e21 1007
3d87245c
HD
1008# Test void results.
1009gdb_test "p (void)10" " = void"
1010gdb_test "p/x (void)10" " = void"
1011gdb_test "p \$abcd" " = void"
1012
eb17d413
PA
1013# GDB used to complete the explicit location options even when
1014# printing expressions.
1015gdb_test_no_output "complete p -function"
1016gdb_test_no_output "complete p -line"
1017gdb_test_no_output "complete p -source"
1018
f572f0a9 1019gdb_file_cmd ${binfile}
c906108c 1020
63092375
DJ
1021gdb_test "print \$pc" "No registers\\." "print \$pc (with file)"
1022
27d3a1a2
MS
1023gdb_test_no_output "set print sevenbit-strings"
1024gdb_test_no_output "set print address off"
1025gdb_test_no_output "set width 0"
c906108c 1026
f1208f9e
DE
1027if { [test_compiler_info "armcc-*"] } {
1028 # ARM RealView compresses large arrays in the data segment.
1029 # Before the program starts, we can not read them. There is
1030 # nothing in the file to indicate that data is compressed.
1031 setup_xfail "arm*-*-eabi"
1032}
1033gdb_test "p ctable1\[120\]" "120 'x'" "p ctable1\[120\] #1"
1034
1035gdb_load ${binfile}
1036
1037if ![runto_main] then {
bc6c7af4 1038 fail "can't run to main"
f1208f9e 1039 return 0
c906108c 1040}
f1208f9e 1041
1f6f6e21 1042# With a running target, printf convenience vars should of course work.
0826779b 1043test_printf_convenience_var "with target"
1f6f6e21
PW
1044
1045# It should also work when inferior function calls are forbidden.
1046gdb_test_no_output "set may-call-functions off"
0826779b 1047test_printf_convenience_var "with target, may-call-functions off"
1f6f6e21
PW
1048gdb_test_no_output "set may-call-functions on"
1049
7b973adc
SDJ
1050# Test printf of a variable that holds the address to a substring in
1051# the inferior. This test will not work without a target.
1052gdb_test_no_output "set var \$test_substr = \(char \*\) \(&teststring\[0\] + 4\)" \
1053 "set \$test_substr var"
1054gdb_test "printf \"test_substr val = %s\\n\", \$test_substr" \
1055 "test_substr val = string contents" \
1056 "print \$test_substr"
1057
f1208f9e
DE
1058test_integer_literals_accepted
1059test_integer_literals_rejected
d30f5e1f
DE
1060test_float_accepted
1061test_float_rejected
f1208f9e
DE
1062test_character_literals_accepted
1063test_print_all_chars
1064test_print_repeats_10
490f124f 1065test_print_repeats_embedded_array
f1208f9e
DE
1066test_print_strings
1067test_print_int_arrays
1068test_print_typedef_arrays
1069test_artificial_arrays
1070test_print_char_arrays
1071# We used to do the runto main here.
1072test_print_string_constants
1073test_print_array_constants
1074test_print_enums
1075test_printf
1076test_printf_with_dfp
9cb709b6 1077test_print_symbol
0d63ecda 1078test_repeat_bytes
d6382fff 1079test_radices
This page took 3.296298 seconds and 4 git commands to generate.