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