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