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