Commit | Line | Data |
---|---|---|
0dcd613f AC |
1 | # This testcase is part of GDB, the GNU debugger. |
2 | ||
0fb0cc75 | 3 | # Copyright 2001, 2004, 2007, 2008, 2009 Free Software Foundation, Inc. |
dea97812 KB |
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 |
dea97812 | 8 | # (at your option) any later version. |
e22f8b7c | 9 | # |
dea97812 KB |
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 | # |
dea97812 | 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/>. |
dea97812 KB |
17 | |
18 | # Please email any bugs, comments, and/or additions to this file to: | |
0dcd613f | 19 | # bug-gdb@gnu.org |
dea97812 KB |
20 | |
21 | # Test GDB's character set support. | |
22 | ||
23 | if $tracelevel then { | |
24 | strace $tracelevel | |
25 | } | |
26 | ||
27 | set prms_id 0 | |
28 | set bug_id 0 | |
29 | ||
30 | set testfile "charset" | |
31 | set srcfile ${testfile}.c | |
32 | set binfile ${objdir}/${subdir}/${testfile} | |
33 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { | |
f21565d2 JB |
34 | untested "couldn't compile ${srcdir}/${subdir}/${srcfile}" |
35 | return -1 | |
dea97812 KB |
36 | } |
37 | ||
38 | # Start with a fresh gdb. | |
39 | gdb_exit | |
40 | gdb_start | |
41 | gdb_reinitialize_dir $srcdir/$subdir | |
42 | gdb_load ${binfile} | |
43 | ||
44 | # Parse the output from a `show charset' command. Return the host | |
45 | # and target charset as a two-element list. | |
46 | proc parse_show_charset_output {testname} { | |
47 | global gdb_prompt | |
48 | ||
49 | gdb_expect { | |
6c7a06a3 | 50 | -re "The host character set is \"(.*)\"\\.\[\r\n\]+The target character set is \"(.*)\"\\.\[\r\n\]+The target wide character set is \"(.*)\"\\.\[\r\n\]+$gdb_prompt $" { |
dea97812 KB |
51 | set host_charset $expect_out(1,string) |
52 | set target_charset $expect_out(2,string) | |
e33d66ec EZ |
53 | set retlist [list $host_charset $target_charset] |
54 | pass $testname | |
55 | } | |
56 | -re "The host character set is \"(.*)\"\\.\[\r\n\]+$gdb_prompt $" { | |
57 | set host_charset $expect_out(1,string) | |
58 | set retlist [list $host_charset] | |
59 | pass $testname | |
60 | } | |
61 | -re "The target character set is \"(.*)\"\\.\[\r\n\]+$gdb_prompt $" { | |
62 | set target_charset $expect_out(1,string) | |
63 | set retlist [list $target_charset] | |
dea97812 KB |
64 | pass $testname |
65 | } | |
66 | -re ".*$gdb_prompt $" { | |
67 | fail $testname | |
68 | } | |
69 | timeout { | |
70 | fail "$testname (timeout)" | |
71 | } | |
72 | } | |
73 | ||
e33d66ec | 74 | return $retlist |
dea97812 KB |
75 | } |
76 | ||
77 | ||
6c7a06a3 | 78 | # Try the various `show charset' commands. |
dea97812 KB |
79 | |
80 | send_gdb "show charset\n" | |
81 | set show_charset [parse_show_charset_output "show charset"] | |
82 | ||
83 | send_gdb "show target-charset\n" | |
6c7a06a3 TT |
84 | set show_target_charset \ |
85 | [lindex [parse_show_charset_output "show target-charset"] 0] | |
dea97812 | 86 | |
6c7a06a3 | 87 | if {[lsearch -exact $show_charset $show_target_charset] >= 0} { |
dea97812 KB |
88 | pass "check `show target-charset' against `show charset'" |
89 | } else { | |
90 | fail "check `show target-charset' against `show charset'" | |
91 | } | |
92 | ||
93 | send_gdb "show host-charset\n" | |
6c7a06a3 TT |
94 | set show_host_charset \ |
95 | [lindex [parse_show_charset_output "show host-charset"] 0] | |
dea97812 | 96 | |
6c7a06a3 | 97 | if {[lsearch -exact $show_charset $show_host_charset] >= 0} { |
dea97812 KB |
98 | pass "check `show host-charset' against `show charset'" |
99 | } else { | |
100 | fail "check `show host-charset' against `show charset'" | |
101 | } | |
102 | ||
e33d66ec EZ |
103 | # Try a malformed `set charset'. |
104 | gdb_test "set charset" \ | |
105 | "Requires an argument. Valid arguments are.*" \ | |
106 | "try malformed `set charset'" | |
107 | ||
108 | # Try using `set host-charset' on an invalid character set. | |
109 | gdb_test "set host-charset my_grandma_bonnie" \ | |
110 | "Undefined item: \"my_grandma_bonnie\"." \ | |
111 | "try `set host-charset' with invalid charset" | |
dea97812 | 112 | |
e33d66ec EZ |
113 | # Try using `set target-charset' on an invalid character set. |
114 | gdb_test "set target-charset my_grandma_bonnie" \ | |
115 | "Undefined item: \"my_grandma_bonnie\"." \ | |
116 | "try `set target-charset' with invalid charset" | |
dea97812 KB |
117 | |
118 | # A Tcl array mapping the names of all the character sets we've seen | |
119 | # to "1" if the character set can be used as a host character set, or | |
120 | # "0" otherwise. We can use `array names charsets' just to get a list | |
121 | # of all character sets. | |
122 | array set charsets {} | |
123 | ||
124 | proc all_charset_names {} { | |
125 | global charsets | |
126 | return [array names charsets] | |
127 | } | |
128 | ||
dea97812 KB |
129 | proc valid_host_charset {charset} { |
130 | global charsets | |
6c7a06a3 | 131 | return [expr {[info exists charsets($charset)] && $charsets($charset)}] |
dea97812 KB |
132 | } |
133 | ||
a8df5de4 TT |
134 | proc valid_target_charset {charset} { |
135 | global charsets | |
136 | return [info exists charsets($charset)] | |
137 | } | |
138 | ||
e33d66ec | 139 | send_gdb "set host-charset\n" |
dea97812 | 140 | gdb_expect { |
e33d66ec EZ |
141 | -re "Requires an argument. Valid arguments are (\[^ \t\n\r,.\]*)" { |
142 | #set host_charset_list $expect_out(1,string) | |
143 | set charsets($expect_out(1,string)) 1 | |
144 | exp_continue | |
145 | #pass "capture valid host charsets" | |
dea97812 | 146 | } |
e33d66ec EZ |
147 | |
148 | -re ", (\[^ \t\n\r,.\]*)" { | |
149 | #set host_charset_list $expect_out(1,string) | |
150 | set charsets($expect_out(1,string)) 1 | |
151 | exp_continue | |
152 | #pass "capture valid host charsets" | |
dea97812 | 153 | } |
e33d66ec EZ |
154 | |
155 | -re "\\.\r\n$gdb_prompt $" { | |
156 | #set host_charset_list $expect_out(1,string) | |
e33d66ec | 157 | pass "capture valid host charsets" |
dea97812 | 158 | } |
e33d66ec EZ |
159 | |
160 | -re ".*$gdb_prompt $" { | |
161 | fail "capture valid host charsets" | |
dea97812 KB |
162 | } |
163 | timeout { | |
e33d66ec | 164 | fail "(timeout) capture valid host charsets" |
dea97812 KB |
165 | } |
166 | } | |
167 | ||
6c7a06a3 TT |
168 | # If gdb was built with a phony iconv, it will only have two character |
169 | # sets: "auto" and the default. In this situation, this set of tests | |
170 | # is pointless. | |
171 | if {[llength [array names charsets]] < 3} { | |
172 | untested charset.exp | |
173 | return -1 | |
174 | } | |
dea97812 | 175 | |
e33d66ec EZ |
176 | send_gdb "set target-charset\n" |
177 | gdb_expect { | |
178 | -re "Requires an argument. Valid arguments are (\[^ \t\n\r,.\]*)" { | |
179 | set target_charset $expect_out(1,string) | |
180 | if {! [info exists charsets($target_charset)]} { | |
181 | set charsets($target_charset) 0 | |
182 | } | |
183 | exp_continue | |
dea97812 | 184 | } |
dea97812 | 185 | |
e33d66ec EZ |
186 | -re ", (\[^ \t\n\r,.\]*)" { |
187 | set target_charset $expect_out(1,string) | |
188 | if {! [info exists charsets($target_charset)]} { | |
189 | set charsets($target_charset) 0 | |
190 | } | |
191 | exp_continue | |
192 | } | |
dea97812 | 193 | |
e33d66ec EZ |
194 | -re "\\.\r\n$gdb_prompt $" { |
195 | pass "capture valid target charsets" | |
dea97812 | 196 | |
e33d66ec | 197 | } |
dea97812 | 198 | |
e33d66ec EZ |
199 | -re ".*$gdb_prompt $" { |
200 | fail "capture valid target charsets" | |
201 | } | |
dea97812 | 202 | |
e33d66ec EZ |
203 | timeout { |
204 | fail "(timeout) capture valid target charsets" | |
205 | } | |
206 | } | |
dea97812 | 207 | |
6c7a06a3 TT |
208 | # We don't want to test all the charset names here, since that would |
209 | # be too many combinations. We we pick a subset. | |
210 | set charset_subset {ASCII ISO-8859-1 EBCDIC-US IBM1047} | |
211 | foreach host_charset $charset_subset { | |
dea97812 KB |
212 | if {[valid_host_charset $host_charset]} { |
213 | ||
214 | set testname "try `set host-charset $host_charset'" | |
215 | send_gdb "set host-charset $host_charset\n" | |
216 | gdb_expect { | |
217 | -re "GDB doesn't know of any character set named.*\[\r\n]+${gdb_prompt} $" { | |
218 | # How did it get into `charsets' then? | |
219 | fail "$testname (didn't recognize name)" | |
220 | } | |
221 | -re "GDB can't use `.*' as its host character set\\.\[\r\n]+${gdb_prompt} $" { | |
222 | # Well, then why does its `charsets' entry say it can? | |
223 | fail $testname | |
224 | } | |
225 | -re "${gdb_prompt} $" { | |
226 | pass $testname | |
227 | } | |
228 | timeout { | |
229 | fail "$testname (timeout)" | |
230 | } | |
231 | } | |
232 | ||
233 | # Check that the command actually had its intended effect: | |
234 | # $host_charset should now be the host character set. | |
235 | send_gdb "show charset\n" | |
236 | set result [parse_show_charset_output "parse `show charset' after `set host-charset $host_charset'"] | |
237 | if {! [string compare [lindex $result 0] $host_charset]} { | |
238 | pass "check effect of `set host-charset $host_charset'" | |
239 | } else { | |
240 | fail "check effect of `set host-charset $host_charset'" | |
241 | } | |
242 | ||
243 | # Now try setting every possible target character set, | |
244 | # given that host charset. | |
6c7a06a3 | 245 | foreach target_charset $charset_subset { |
a8df5de4 TT |
246 | if {![valid_target_charset $target_charset]} { |
247 | continue | |
248 | } | |
dea97812 KB |
249 | set testname "try `set target-charset $target_charset'" |
250 | send_gdb "set target-charset $target_charset\n" | |
251 | gdb_expect { | |
252 | -re "GDB doesn't know of any character set named.*\[\r\n]+${gdb_prompt} $" { | |
253 | fail "$testname (didn't recognize name)" | |
254 | } | |
255 | -re "GDB can't convert from the .* character set to .*\\.\[\r\n\]+${gdb_prompt} $" { | |
256 | # This is a serious problem. GDB should be able to convert | |
257 | # between any arbitrary pair of character sets. | |
258 | fail "$testname (can't convert)" | |
259 | } | |
260 | -re "${gdb_prompt} $" { | |
261 | pass $testname | |
262 | } | |
263 | timeout { | |
264 | fail "$testname (timeout)" | |
265 | } | |
266 | } | |
267 | ||
268 | # Check that the command actually had its intended effect: | |
269 | # $target_charset should now be the target charset. | |
270 | send_gdb "show charset\n" | |
271 | set result [parse_show_charset_output "parse `show charset' after `set target-charset $target_charset'"] | |
272 | if {! [string compare $result [list $host_charset $target_charset]]} { | |
273 | pass "check effect of `set target-charset $target_charset'" | |
274 | } else { | |
275 | fail "check effect of `set target-charset $target_charset'" | |
276 | } | |
277 | ||
278 | # Test handling of characters in the host charset which | |
279 | # can't be translated into the target charset. \xA2 is | |
280 | # `cent' in ISO-8859-1, which has no equivalent in ASCII. | |
281 | # | |
282 | # On some systems, the pseudo-tty through which we | |
283 | # communicate with GDB insists on stripping the high bit | |
284 | # from input characters, meaning that `cent' turns into | |
285 | # `"'. Since ISO-8859-1 and ASCII are identical in the | |
286 | # lower 128 characters, it's tough to see how we can test | |
287 | # this behavior on such systems, so we just xfail it. | |
288 | # | |
289 | # Note: the \x16 (Control-V) is an escape to allow \xA2 to | |
290 | # get past readline. | |
291 | if {! [string compare $host_charset iso-8859-1] && ! [string compare $target_charset ascii]} { | |
292 | ||
293 | set testname "untranslatable character in character literal" | |
294 | send_gdb "print '\x16\xA2'\n" | |
295 | gdb_expect { | |
296 | -re "There is no character corresponding to .* in the target character set .*\\.\[\r\n\]+$gdb_prompt $" { | |
297 | pass $testname | |
298 | } | |
299 | -re " = 34 '\"'\[\r\n\]+$gdb_prompt $" { | |
300 | xfail "$testname (DejaGNU's pseudo-tty strips eighth bit)" | |
301 | } | |
302 | -re "$gdb_prompt $" { | |
303 | fail $testname | |
304 | } | |
305 | timeout { | |
306 | fail "$testname (timeout)" | |
307 | } | |
308 | } | |
309 | ||
310 | set testname "untranslatable character in string literal" | |
311 | # If the PTTY zeros bit seven, then this turns into | |
312 | # print """ | |
313 | # which gets us a syntax error. We don't care. | |
314 | send_gdb "print \"\x16\xA2\"\n" | |
315 | gdb_expect { | |
316 | -re "There is no character corresponding to .* in the target character set .*\\.\[\r\n\]+$gdb_prompt $" { | |
317 | pass $testname | |
318 | } | |
319 | -re "Unterminated string in expression.\[\r\n\]+$gdb_prompt $" { | |
320 | xfail "$testname (DejaGNU's pseudo-tty strips eighth bit)" | |
321 | } | |
322 | -re "$gdb_prompt $" { | |
323 | fail $testname | |
324 | } | |
325 | timeout { | |
326 | fail "$testname (timeout)" | |
327 | } | |
328 | } | |
329 | ||
330 | set testname "untranslatable characters in backslash escape" | |
331 | send_gdb "print '\\\x16\xA2'\n" | |
332 | gdb_expect { | |
333 | -re "The escape sequence .* is equivalent to plain .*, which has no equivalent\[\r\n\]+in the .* character set\\.\[\r\n\]+$gdb_prompt $" { | |
334 | pass $testname | |
335 | } | |
336 | -re " = 34 '\"'\[\r\n\]+$gdb_prompt $" { | |
337 | xfail "$testname (DejaGNU's pseudo-tty strips eighth bit)" | |
338 | } | |
339 | -re "$gdb_prompt $" { | |
340 | fail $testname | |
341 | } | |
342 | timeout { | |
343 | fail "$testname (timeout)" | |
344 | } | |
345 | } | |
346 | } | |
347 | } | |
348 | } | |
349 | } | |
350 | ||
351 | ||
352 | # Set the host character set to plain ASCII, and try actually printing | |
353 | # some strings in various target character sets. We need to run the | |
354 | # test program to the point at which the strings have been | |
355 | # initialized. | |
381bc39b | 356 | gdb_test "break ${srcfile}:[gdb_get_line_number "all strings initialized"]" \ |
dea97812 KB |
357 | ".*Breakpoint.* at .*" \ |
358 | "set breakpoint after all strings have been initialized" | |
359 | gdb_run_cmd | |
360 | gdb_expect { | |
361 | -re "Breakpoint.*all strings initialized.*$gdb_prompt $" { | |
362 | pass "run until all strings have been initialized" | |
363 | } | |
364 | -re "$gdb_prompt $" { | |
365 | fail "run until all strings have been initialized" | |
366 | } | |
367 | timeout { | |
368 | fail "run until all strings have been initialized (timeout)" | |
369 | } | |
370 | } | |
371 | ||
372 | ||
6c7a06a3 TT |
373 | # We only try the wide character tests on machines where the wchar_t |
374 | # typedef in the test case has the right size. | |
375 | set wchar_size [get_sizeof wchar_t 99] | |
376 | set wchar_ok 0 | |
377 | if {$wchar_size == 2} { | |
378 | lappend charset_subset UCS-2 | |
379 | set wchar_ok 1 | |
380 | } elseif {$wchar_size == 4} { | |
381 | lappend charset_subset UCS-4 | |
382 | set wchar_ok 1 | |
383 | } | |
384 | ||
e33d66ec | 385 | gdb_test "set host-charset ASCII" "" |
6c7a06a3 | 386 | foreach target_charset $charset_subset { |
a8df5de4 TT |
387 | if {![valid_target_charset $target_charset]} { |
388 | continue | |
389 | } | |
390 | ||
6c7a06a3 TT |
391 | if {$target_charset == "UCS-4" || $target_charset == "UCS-2"} { |
392 | set param target-wide-charset | |
393 | set L L | |
394 | } else { | |
395 | set param target-charset | |
396 | set L "" | |
397 | } | |
398 | send_gdb "set $param $target_charset\n" | |
dea97812 KB |
399 | gdb_expect { |
400 | -re "$gdb_prompt $" { | |
6c7a06a3 | 401 | pass "set $param $target_charset" |
dea97812 KB |
402 | } |
403 | timeout { | |
6c7a06a3 | 404 | fail "set $param $target_charset (timeout)" |
dea97812 KB |
405 | } |
406 | } | |
407 | ||
408 | # Try printing the null character. There seems to be a bug in | |
409 | # gdb_test that requires us to use gdb_expect here. | |
6c7a06a3 | 410 | send_gdb "print $L'\\0'\n" |
dea97812 | 411 | gdb_expect { |
30b66ecc | 412 | -re "\\\$${decimal} = 0 $L'\\\\000'\[\r\n\]+$gdb_prompt $" { |
dea97812 KB |
413 | pass "print the null character in ${target_charset}" |
414 | } | |
415 | -re "$gdb_prompt $" { | |
416 | fail "print the null character in ${target_charset}" | |
417 | } | |
418 | timeout { | |
419 | fail "print the null character in ${target_charset} (timeout)" | |
420 | } | |
421 | } | |
422 | ||
423 | # Compute the name of the variable in the test program that holds | |
424 | # a string in $target_charset. The variable's name is the | |
425 | # character set's name, in lower-case, with all non-identifier | |
426 | # characters replaced with '_', with "_string" stuck on the end. | |
6c7a06a3 TT |
427 | if {$target_charset == "UCS-2"} { |
428 | # We still use the ucs_4_string variable -- but the size is | |
429 | # correct for UCS-2. | |
430 | set var_name ucs_4_string | |
431 | } else { | |
432 | set var_name [string tolower "${target_charset}_string"] | |
433 | regsub -all -- "\[^a-z0-9_\]" $var_name "_" var_name | |
434 | } | |
dea97812 KB |
435 | |
436 | # Compute a regexp matching the results we expect. This is static, | |
437 | # but it's easier than writing it out. | |
0dcd613f | 438 | regsub -all "." "abfnrtv" "(\\\\&|x)" escapes |
dea97812 KB |
439 | set uppercase "ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
440 | set lowercase "abcdefghijklmnopqrstuvwxyz" | |
441 | set digits "0123456789" | |
6c7a06a3 | 442 | set octal_escape "\\\\\[0-9\]+" |
dea97812 KB |
443 | |
444 | send_gdb "print $var_name\n" | |
445 | # ${escapes}${uppercase}${lowercase}${digits}${octal}${octal} | |
446 | gdb_expect { | |
6c7a06a3 | 447 | -re ".* = $L\"(\\\\a|x)(\\\\b|x)(\\\\f|x)(\\\\n|x)(\\\\r|x)(\\\\t|x)(\\\\v|x)${uppercase}${lowercase}${digits}(${octal_escape}|x)+\"\[\r\n\]+$gdb_prompt $" { |
dea97812 KB |
448 | pass "print string in $target_charset" |
449 | } | |
450 | -re "$gdb_prompt $" { | |
451 | fail "print string in $target_charset" | |
452 | } | |
453 | timeout { | |
454 | fail "print string in $target_charset (timeout)" | |
455 | } | |
456 | } | |
457 | ||
458 | # Try entering a character literal, and see if it comes back unchanged. | |
6c7a06a3 TT |
459 | gdb_test "print $L'A'" \ |
460 | " = \[0-9-\]+ $L'A'" \ | |
dea97812 KB |
461 | "parse character literal in ${target_charset}" |
462 | ||
463 | # Check that the character literal was encoded correctly. | |
6c7a06a3 | 464 | gdb_test "print $L'A' == $var_name\[7\]" \ |
dea97812 KB |
465 | " = 1" \ |
466 | "check value of parsed character literal in ${target_charset}" | |
467 | ||
468 | # Try entering a string literal, and see if it comes back unchanged. | |
6c7a06a3 TT |
469 | gdb_test "print $L\"abcdefABCDEF012345\"" \ |
470 | " = $L\"abcdefABCDEF012345\"" \ | |
dea97812 KB |
471 | "parse string literal in ${target_charset}" |
472 | ||
473 | # Check that the string literal was encoded correctly. | |
6c7a06a3 | 474 | gdb_test "print $L\"q\"\[0\] == $var_name\[49\]" \ |
dea97812 KB |
475 | " = 1" \ |
476 | "check value of parsed string literal in ${target_charset}" | |
477 | ||
478 | # Test handling of characters in the target charset which | |
479 | # can't be translated into the host charset. | |
480 | if {! [string compare $target_charset iso-8859-1]} { | |
0dcd613f | 481 | gdb_test "print iso_8859_1_string\[69\]" \ |
dea97812 KB |
482 | " = \[0-9-\]+ '\\\\242'" \ |
483 | "print character with no equivalent in host character set" | |
484 | gdb_test "print iso_8859_1_string + 70" \ | |
485 | " = ${hex} \"\\\\242.*\"" \ | |
486 | "print string with no equivalent in host character set" | |
487 | } | |
488 | ||
489 | # Make sure that we don't apply the ISO-8859-1 `print_literally' | |
490 | # function to ASCII. | |
491 | if {! [string compare $target_charset ascii]} { | |
0dcd613f | 492 | gdb_test "print iso_8859_1_string\[69\]" \ |
dea97812 KB |
493 | " = \[0-9-\]+ '\\\\242'" \ |
494 | "print ASCII unprintable character" | |
495 | gdb_test "print iso_8859_1_string + 70" \ | |
496 | " = ${hex} \"\\\\242.*\"" \ | |
497 | "print ASCII unprintable string" | |
498 | } | |
499 | ||
500 | # Try printing characters with backslash escape equivalents. | |
0dcd613f | 501 | set escapees {a b f n r t v} |
dea97812 KB |
502 | for {set i 0} {$i < [llength $escapees]} {incr i} { |
503 | set escape [lindex $escapees $i] | |
504 | send_gdb "print $var_name\[$i\]\n" | |
505 | set have_escape 1 | |
506 | gdb_expect { | |
6c7a06a3 | 507 | -re "= \[0-9-\]+ $L'\\\\${escape}'\[\r\n\]+$gdb_prompt $" { |
dea97812 KB |
508 | pass "try printing '\\${escape}' in ${target_charset}" |
509 | } | |
510 | -re "= \[0-9-\]+ 'x'\[\r\n\]+$gdb_prompt $" { | |
511 | xfail "try printing '\\${escape}' in ${target_charset} (no such escape)" | |
512 | set have_escape 0 | |
513 | } | |
514 | -re "$gdb_prompt $" { | |
515 | fail "try printing '\\${escape}' in ${target_charset}" | |
516 | } | |
517 | timeout { | |
518 | fail "try printing '\\${escape}' in ${target_charset} (timeout)" | |
519 | } | |
520 | } | |
521 | ||
522 | if {$have_escape} { | |
523 | ||
524 | # Try parsing a backslash escape in a character literal. | |
6c7a06a3 | 525 | gdb_test "print $L'\\${escape}' == $var_name\[$i\]" \ |
dea97812 KB |
526 | " = 1" \ |
527 | "check value of '\\${escape}' in ${target_charset}" | |
528 | ||
529 | # Try parsing a backslash escape in a string literal. | |
6c7a06a3 | 530 | gdb_test "print $L\"\\${escape}\"\[0\] == $var_name\[$i\]" \ |
dea97812 KB |
531 | " = 1" \ |
532 | "check value of \"\\${escape}\" in ${target_charset}" | |
533 | } | |
534 | } | |
535 | ||
536 | # Try printing a character escape that doesn't exist. We should | |
537 | # get the unescaped character, in the target character set. | |
6c7a06a3 | 538 | gdb_test "print $L'\\q'" " = \[0-9-\]+ $L'q'" \ |
dea97812 | 539 | "print escape that doesn't exist in $target_charset" |
6c7a06a3 | 540 | gdb_test "print $L'\\q' == $var_name\[49\]" " = 1" \ |
dea97812 KB |
541 | "check value of escape that doesn't exist in $target_charset" |
542 | } | |
543 | ||
6c7a06a3 TT |
544 | # Reset the target charset. |
545 | gdb_test "set target-charset UTF-8" "" | |
546 | ||
547 | # \242 is not a valid UTF-8 character. | |
548 | gdb_test "print \"\\242\"" " = \"\\\\242\"" \ | |
549 | "non-representable target character" | |
550 | ||
551 | gdb_test "print '\\x'" "\\\\x escape without a following hex digit." | |
552 | gdb_test "print '\\u'" "\\\\u escape without a following hex digit." | |
553 | gdb_test "print '\\9'" " = \[0-9\]+ '9'" | |
554 | ||
30b66ecc TT |
555 | # An octal escape can only be 3 digits. |
556 | gdb_test "print \"\\1011\"" " = \"A1\"" | |
557 | ||
6c7a06a3 TT |
558 | # Tests for wide- or unicode- strings. L is the prefix letter to use, |
559 | # either "L" (for wide strings), "u" (for UCS-2), or "U" (for UCS-4). | |
560 | # NAME is used in the test names and should be related to the prefix | |
561 | # letter in some easy-to-undestand way. | |
562 | proc test_wide_or_unicode {L name} { | |
563 | gdb_test "print $L\"ab\" $L\"c\"" " = $L\"abc\"" \ | |
564 | "basic $name string concatenation" | |
565 | gdb_test "print $L\"ab\" \"c\"" " = $L\"abc\"" \ | |
566 | "narrow and $name string concatenation" | |
567 | gdb_test "print \"ab\" $L\"c\"" " = $L\"abc\"" \ | |
568 | "$name and narrow string concatenation" | |
30b66ecc | 569 | gdb_test "print $L\"\\xe\" $L\"c\"" " = $L\"\\\\016c\"" \ |
6c7a06a3 TT |
570 | "$name string concatenation with escape" |
571 | gdb_test "print $L\"\" \"abcdef\" \"g\"" \ | |
572 | "$L\"abcdefg\"" \ | |
573 | "concatenate three strings with empty $name string" | |
574 | ||
575 | gdb_test "print $L'a'" "= \[0-9\]+ $L'a'" \ | |
576 | "basic $name character" | |
577 | } | |
578 | ||
579 | if {$wchar_ok} { | |
580 | test_wide_or_unicode L wide | |
581 | } | |
582 | ||
583 | set ucs2_ok [expr {[get_sizeof char16_t 99] == 2}] | |
584 | if {$ucs2_ok} { | |
585 | test_wide_or_unicode u UCS-2 | |
586 | } | |
587 | ||
588 | set ucs4_ok [expr {[get_sizeof char32_t 99] == 4}] | |
589 | if {$ucs4_ok} { | |
590 | test_wide_or_unicode U UCS-4 | |
591 | } | |
592 | ||
593 | # Test an invalid string combination. | |
594 | proc test_combination {L1 name1 L2 name2} { | |
595 | gdb_test "print $L1\"abc\" $L2\"def\"" \ | |
596 | "Undefined string concatenation." \ | |
597 | "undefined concatenation of $name1 and $name2" | |
598 | } | |
599 | ||
600 | if {$wchar_ok && $ucs2_ok} { | |
601 | test_combination L wide u UCS-2 | |
602 | } | |
603 | if {$wchar_ok && $ucs4_ok} { | |
604 | test_combination L wide U UCS-4 | |
85e306ed TT |
605 | # Regression test for a typedef to a typedef. |
606 | gdb_test "print myvar" "= \[0-9\]+ L'A'" \ | |
607 | "typedef to wchar_t" | |
6c7a06a3 TT |
608 | } |
609 | if {$ucs2_ok && $ucs4_ok} { | |
610 | test_combination u UCS-2 U UCS-4 | |
611 | } | |
612 | ||
334cc82d TT |
613 | # Regression test for a cleanup bug in the charset code. |
614 | gdb_test "print 'a' == 'a' || 'b' == 'b'" \ | |
615 | ".* = 1" \ | |
616 | "EVAL_SKIP cleanup handling regression test" | |
617 | ||
dea97812 | 618 | gdb_exit |