2009-03-19 Tom Tromey <tromey@redhat.com> Julian Brown <julian@codesourcery.com> PR i18n/7220, PR i18n/7821, PR exp/8815, PR exp/9103, PR i18n/9401, PR exp/9613: * NEWS: Update * value.h (value_typed_string): Declare. (val_print_string): Update. * valprint.h (print_char_chars): Update. * valprint.c (print_char_chars): Add type argument. Update. (val_print_string): Likewise. * valops.c (value_typed_string): New function. * utils.c (host_char_to_target): New function. (parse_escape): Use host_char_to_target, host_hex_value. Update. Remove '^' case. (no_control_char_error): Remove. * typeprint.c (print_type_scalar): Update. * scm-valprint.c (scm_scmval_print): Update. * scm-lang.h (scm_printchar, scm_printstr): Update. * scm-lang.c (scm_printchar): Add type argument. (scm_printstr): Likewise. * printcmd.c (print_formatted): Update. (print_scalar_formatted): Update. (printf_command) <wide_string_arg, wide_char_arg>: New constants. Handle '%lc' and '%ls'. * parser-defs.h (struct typed_stoken): New type. (struct stoken_vector): Likewise. (write_exp_string_vector): Declare. * parse.c (write_exp_string_vector): New function. * p-valprint.c (pascal_val_print): Update. * p-lang.h (is_pascal_string_type, pascal_printchar, pascal_printstr): Update. * p-lang.c (is_pascal_string_type): Remove 'char_size' argument. Add 'char_type' argument. (pascal_emit_char): Add type argument. (pascal_printchar): Likewise. (pascal_printstr): Likewise. * objc-lang.c (objc_emit_char): Add type argument. (objc_printchar): Likewise. (objc_printstr): Likewise. * macroexp.c (get_character_constant): Handle unicode characters. Use c_parse_escape. (get_string_literal): Handle unicode strings. Use c_parse_escape. * m2-valprint.c (print_unpacked_pointer): Update. (m2_print_array_contents): Update. (m2_val_print): Update. * m2-lang.c (m2_emit_char): Add type argument. (m2_printchar): Likewise. (m2_printstr): Likewise. * language.h (struct language_defn) <la_printchar>: Add type argument. <la_printstr, la_emitchar>: Likewise. (LA_PRINT_CHAR): Likewise. (LA_PRINT_STRING): Likewise. (LA_EMIT_CHAR): Likewise. * language.c (unk_lang_emit_char): Add type argument. (unk_lang_printchar): Likewise. (unk_lang_printstr): Likewise. * jv-valprint.c (java_val_print): Update. * jv-lang.c (java_emit_char): Add type argument. * f-valprint.c (f_val_print): Update. * f-lang.c (f_emit_char): Add type argument. (f_printchar): Likewise. (f_printstr): Likewise. * expprint.c (print_subexp_standard): Update. * charset.h (target_wide_charset): Declare. (c_target_char_has_backslash_escape, c_parse_backslash, host_char_print_literally, host_char_to_target, target_char_to_host, target_char_to_control_char): Remove. (enum transliterations): New type. (convert_between_encodings): Declare. (HOST_ESCAPE_CHAR): New define. (host_letter_to_control_character, host_hex_value): Declare. (enum wchar_iterate_result): New enum. (struct wchar_iterator): Declare. (make_wchar_iterator, make_cleanup_wchar_iterator, wchar_iterator, wchar_push_back): Declare. * charset-list.h: New file. * c-valprint.c (textual_name): New function. (textual_element_type): Handle wide character types. (c_val_print): Pass original type to textual_element_type. Handle wide character types. (c_value_print): Use textual_element_type. Pass original type of value to val_print. * c-lang.h (enum c_string_type): New type. (c_printchar, c_printstr): Update. * c-lang.c (classify_type): New function. (print_wchar): Likewise. (c_emit_char): Add type argument. Handle wide characters. (c_printchar): Likewise. (c_printstr): Add type argument. Handle wide and multibyte character sets. (convert_ucn): New function. (emit_numeric_character): Likewise. (convert_octal): Likewise. (convert_hex): Likewise. (ADVANCE): New macro. (convert_escape): New function. (parse_one_string): Likewise. (evaluate_subexp_c): Likewise. (exp_descriptor_c): New global. (c_language_defn): Use exp_descriptor_c. (cplus_language_defn): Likewise. (asm_language_defn): Likewise. (minimal_language_defn): Likewise. (charset_for_string_type): New function. * c-exp.y (%union): Add 'svec' and 'tsval'. (CHAR): New token. (exp): Add CHAR production. (string_exp): Rewrite. (exp) <string_exp>: Rewrite. (tempbuf): Now global. (tempbuf_init): New global. (parse_string_or_char): New function. (yylex) <tempbuf>: Now global. <tokptr, tempbufindex, tempbufsize, token_string, class_prefix>: Remove. Handle 'u', 'U', and 'L' prefixes. Call parse_string_or_char. (c_parse_escape): New function. * auxv.c (fprint_target_auxv): Update. * ada-valprint.c (ada_emit_char): Add type argument. (ada_printchar): Likewise. (ada_print_scalar): Update. (printstr): Add type argument. Update calls to ada_emit_char. (ada_printstr): Add type argument. (ada_val_print_array): Update. (ada_val_print_1): Likewise. * ada-lang.c (emit_char): Add type argument. * ada-lang.h (ada_emit_char, ada_printchar, ada_printstr): Add type arguments. * gdb_locale.h: Include langinfo.h. * charset.c (_initialize_charset): Set default host charset from the locale. Don't register charsets. Add target-wide-charset commands. Call find_charset_names. (struct charset, struct translation): Remove. (GDB_DEFAULT_HOST_CHARSET): Remove. (GDB_DEFAULT_TARGET_WIDE_CHARSET): New define. (target_wide_charset_name): New global. (show_host_charset_name): Handle "auto". (show_target_wide_charset_name): New function. (host_charset_enum, target_charset_enum): Remove. (charset_enum): New global. (all_charsets, register_charset, lookup_charset, all_translations, register_translation, lookup_translation): Remove. (simple_charset, ascii_print_literally, ascii_to_control): Remove. (iso_8859_print_literally, iso_8859_to_control, iso_8859_family_charset): Remove. (ebcdic_print_literally, ebcdic_to_control, ebcdic_family_charset): Remove. (struct cached_iconv, check_iconv_cache, cached_iconv_convert, register_iconv_charsets): Remove. (target_wide_charset_be_name, target_wide_charset_le_name): New globals. (identity_either_char_to_other): Remove. (set_be_le_names, validate): New functions. (backslashable, backslashed, represented): Remove. (default_c_target_char_has_backslash_escape): Remove. (default_c_parse_backslash, iconv_convert): Remove. (ascii_to_iso_8859_1_table, ascii_to_ebcdic_us_table, ascii_to_ibm1047_table, iso_8859_1_to_ascii_table, iso_8859_1_to_ebcdic_us_table, iso_8859_1_to_ibm1047_table, ebcdic_us_to_ascii_table, ebcdic_us_to_iso_8859_1_table, ebcdic_us_to_ibm1047_table, ibm1047_to_ascii_table, ibm1047_to_iso_8859_1_table, ibm1047_to_ebcdic_us_table): Remove. (table_convert_char, table_translation, simple_table_translation): Remove. (current_host_charset, current_target_charset, c_target_char_has_backslash_escape_func, c_target_char_has_backslash_escape_baton): Remove. (c_parse_backslash_func, c_parse_backslash_baton): Remove. (host_char_to_target_func, host_char_to_target_baton): Remove. (target_char_to_host_func, target_char_to_host_baton): Remove. (cached_iconv_host_to_target, cached_iconv_target_to_host): Remove. (lookup_charset_or_error, check_valid_host_charset): Remove. (set_host_and_target_charsets): Remove. (set_host_charset, set_target_charset): Remove. (set_host_charset_sfunc, set_target_charset_sfunc): Rewrite. (set_target_wide_charset_sfunc): New function. (show_charset): Print target wide character set. (host_charset, target_charset): Rewrite. (target_wide_charset): New function. (c_target_char_has_backslash_escape): Remove. (c_parse_backslash): Remove. (host_letter_to_control_character): New function. (host_char_print_literally): Remove. (host_hex_value): New function. (target_char_to_control_char): Remove. (cleanup_iconv): New function. (convert_between_encodings): New function. (target_char_to_host): Remove. (struct wchar_iterator): Define. (make_wchar_iterator, make_cleanup_wchar_iterator, wchar_iterator, wchar_push_back): New functions. (do_cleanup_iterator): New function. (char_ptr): New typedef. (charsets): New global. (add_one, find_charset_names): New functions. (default_charset_names): New global. (auto_host_charset_name): Likewise. * aclocal.m4, config.in, configure: Rebuild. * configure.ac: Call AM_LANGINFO_CODESET. (GDB_DEFAULT_HOST_CHARSET): Default to UTF-8. (AM_ICONV): Invoke earlier. * acinclude.m4: Include codeset.m4. Subst LIBICONV_INCLUDE and LIBICONV_LIBDIR. Check for libiconv in build tree. * Makefile.in (LIBICONV_LIBDIR, LIBICONV_INCLUDE): New macros. (INTERNAL_CFLAGS_BASE): Add LIBICONV_INCLUDE. (INTERNAL_LDFLAGS): Add LIBICONV_LIBDIR. * gdb_obstack.h (obstack_grow_wstr): New define. * gdb_wchar.h: New file. * defs.h: Include it. gdb/testsuite: * gdb.base/store.exp: Update for change to escape output. * gdb.base/callfuncs.exp (fetch_all_registers): Update for change to escape output. * gdb.base/pointers.exp: Update for change to escape output. * gdb.base/long_long.exp (gdb_test_long_long): Update for change to escape output. * gdb.base/constvars.exp (do_constvar_tests): Update for change to escape output. * gdb.base/call-rt-st.exp (print_struct_call): Update for change to escape output. * gdb.cp/ref-types.exp (gdb_start_again): Update for change to escape output. * gdb.base/setvar.exp: Update for change to escape output. * lib/gdb.exp (default_gdb_start): Set LC_CTYPE to C. * gdb.base/printcmds.exp (test_print_all_chars): Update for change to escape output. (test_print_string_constants): Likewise. * gdb.base/charset.exp (valid_host_charset): Check size of wchar_t. Handle UCS-2 and UCS-4. Add tests for wide and unicode cases. Handle "auto"-related output. * gdb.base/charset.c (char16_t, char32_t): New typedefs. (uvar, Uvar): New globals. gdb/doc: * gdb.texinfo (Character Sets): Remove obsolete text. Document set target-wide-charset. (Requirements): Mention iconv.
595 lines
21 KiB
Text
595 lines
21 KiB
Text
# This testcase is part of GDB, the GNU debugger.
|
|
|
|
# Copyright 2001, 2004, 2007, 2008, 2009 Free Software Foundation, Inc.
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
# Please email any bugs, comments, and/or additions to this file to:
|
|
# bug-gdb@gnu.org
|
|
|
|
# Test GDB's character set support.
|
|
|
|
if $tracelevel then {
|
|
strace $tracelevel
|
|
}
|
|
|
|
set prms_id 0
|
|
set bug_id 0
|
|
|
|
set testfile "charset"
|
|
set srcfile ${testfile}.c
|
|
set binfile ${objdir}/${subdir}/${testfile}
|
|
if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
|
|
untested "couldn't compile ${srcdir}/${subdir}/${srcfile}"
|
|
return -1
|
|
}
|
|
|
|
# Start with a fresh gdb.
|
|
gdb_exit
|
|
gdb_start
|
|
gdb_reinitialize_dir $srcdir/$subdir
|
|
gdb_load ${binfile}
|
|
|
|
# Parse the output from a `show charset' command. Return the host
|
|
# and target charset as a two-element list.
|
|
proc parse_show_charset_output {testname} {
|
|
global gdb_prompt
|
|
|
|
gdb_expect {
|
|
-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 $" {
|
|
set host_charset $expect_out(1,string)
|
|
set target_charset $expect_out(2,string)
|
|
set retlist [list $host_charset $target_charset]
|
|
pass $testname
|
|
}
|
|
-re "The host character set is \"(.*)\"\\.\[\r\n\]+$gdb_prompt $" {
|
|
set host_charset $expect_out(1,string)
|
|
set retlist [list $host_charset]
|
|
pass $testname
|
|
}
|
|
-re "The target character set is \"(.*)\"\\.\[\r\n\]+$gdb_prompt $" {
|
|
set target_charset $expect_out(1,string)
|
|
set retlist [list $target_charset]
|
|
pass $testname
|
|
}
|
|
-re ".*$gdb_prompt $" {
|
|
fail $testname
|
|
}
|
|
timeout {
|
|
fail "$testname (timeout)"
|
|
}
|
|
}
|
|
|
|
return $retlist
|
|
}
|
|
|
|
|
|
# Try the various `show charset' commands.
|
|
|
|
send_gdb "show charset\n"
|
|
set show_charset [parse_show_charset_output "show charset"]
|
|
|
|
send_gdb "show target-charset\n"
|
|
set show_target_charset \
|
|
[lindex [parse_show_charset_output "show target-charset"] 0]
|
|
|
|
if {[lsearch -exact $show_charset $show_target_charset] >= 0} {
|
|
pass "check `show target-charset' against `show charset'"
|
|
} else {
|
|
fail "check `show target-charset' against `show charset'"
|
|
}
|
|
|
|
send_gdb "show host-charset\n"
|
|
set show_host_charset \
|
|
[lindex [parse_show_charset_output "show host-charset"] 0]
|
|
|
|
if {[lsearch -exact $show_charset $show_host_charset] >= 0} {
|
|
pass "check `show host-charset' against `show charset'"
|
|
} else {
|
|
fail "check `show host-charset' against `show charset'"
|
|
}
|
|
|
|
# Try a malformed `set charset'.
|
|
gdb_test "set charset" \
|
|
"Requires an argument. Valid arguments are.*" \
|
|
"try malformed `set charset'"
|
|
|
|
# Try using `set host-charset' on an invalid character set.
|
|
gdb_test "set host-charset my_grandma_bonnie" \
|
|
"Undefined item: \"my_grandma_bonnie\"." \
|
|
"try `set host-charset' with invalid charset"
|
|
|
|
# Try using `set target-charset' on an invalid character set.
|
|
gdb_test "set target-charset my_grandma_bonnie" \
|
|
"Undefined item: \"my_grandma_bonnie\"." \
|
|
"try `set target-charset' with invalid charset"
|
|
|
|
# A Tcl array mapping the names of all the character sets we've seen
|
|
# to "1" if the character set can be used as a host character set, or
|
|
# "0" otherwise. We can use `array names charsets' just to get a list
|
|
# of all character sets.
|
|
array set charsets {}
|
|
|
|
proc all_charset_names {} {
|
|
global charsets
|
|
return [array names charsets]
|
|
}
|
|
|
|
proc valid_host_charset {charset} {
|
|
global charsets
|
|
return [expr {[info exists charsets($charset)] && $charsets($charset)}]
|
|
}
|
|
|
|
send_gdb "set host-charset\n"
|
|
gdb_expect {
|
|
-re "Requires an argument. Valid arguments are (\[^ \t\n\r,.\]*)" {
|
|
#set host_charset_list $expect_out(1,string)
|
|
set charsets($expect_out(1,string)) 1
|
|
exp_continue
|
|
#pass "capture valid host charsets"
|
|
}
|
|
|
|
-re ", (\[^ \t\n\r,.\]*)" {
|
|
#set host_charset_list $expect_out(1,string)
|
|
set charsets($expect_out(1,string)) 1
|
|
exp_continue
|
|
#pass "capture valid host charsets"
|
|
}
|
|
|
|
-re "\\.\r\n$gdb_prompt $" {
|
|
#set host_charset_list $expect_out(1,string)
|
|
pass "capture valid host charsets"
|
|
}
|
|
|
|
-re ".*$gdb_prompt $" {
|
|
fail "capture valid host charsets"
|
|
}
|
|
timeout {
|
|
fail "(timeout) capture valid host charsets"
|
|
}
|
|
}
|
|
|
|
# If gdb was built with a phony iconv, it will only have two character
|
|
# sets: "auto" and the default. In this situation, this set of tests
|
|
# is pointless.
|
|
if {[llength [array names charsets]] < 3} {
|
|
untested charset.exp
|
|
return -1
|
|
}
|
|
|
|
send_gdb "set target-charset\n"
|
|
gdb_expect {
|
|
-re "Requires an argument. Valid arguments are (\[^ \t\n\r,.\]*)" {
|
|
set target_charset $expect_out(1,string)
|
|
if {! [info exists charsets($target_charset)]} {
|
|
set charsets($target_charset) 0
|
|
}
|
|
exp_continue
|
|
}
|
|
|
|
-re ", (\[^ \t\n\r,.\]*)" {
|
|
set target_charset $expect_out(1,string)
|
|
if {! [info exists charsets($target_charset)]} {
|
|
set charsets($target_charset) 0
|
|
}
|
|
exp_continue
|
|
}
|
|
|
|
-re "\\.\r\n$gdb_prompt $" {
|
|
pass "capture valid target charsets"
|
|
|
|
}
|
|
|
|
-re ".*$gdb_prompt $" {
|
|
fail "capture valid target charsets"
|
|
}
|
|
|
|
timeout {
|
|
fail "(timeout) capture valid target charsets"
|
|
}
|
|
}
|
|
|
|
# We don't want to test all the charset names here, since that would
|
|
# be too many combinations. We we pick a subset.
|
|
set charset_subset {ASCII ISO-8859-1 EBCDIC-US IBM1047}
|
|
foreach host_charset $charset_subset {
|
|
if {[valid_host_charset $host_charset]} {
|
|
|
|
set testname "try `set host-charset $host_charset'"
|
|
send_gdb "set host-charset $host_charset\n"
|
|
gdb_expect {
|
|
-re "GDB doesn't know of any character set named.*\[\r\n]+${gdb_prompt} $" {
|
|
# How did it get into `charsets' then?
|
|
fail "$testname (didn't recognize name)"
|
|
}
|
|
-re "GDB can't use `.*' as its host character set\\.\[\r\n]+${gdb_prompt} $" {
|
|
# Well, then why does its `charsets' entry say it can?
|
|
fail $testname
|
|
}
|
|
-re "${gdb_prompt} $" {
|
|
pass $testname
|
|
}
|
|
timeout {
|
|
fail "$testname (timeout)"
|
|
}
|
|
}
|
|
|
|
# Check that the command actually had its intended effect:
|
|
# $host_charset should now be the host character set.
|
|
send_gdb "show charset\n"
|
|
set result [parse_show_charset_output "parse `show charset' after `set host-charset $host_charset'"]
|
|
if {! [string compare [lindex $result 0] $host_charset]} {
|
|
pass "check effect of `set host-charset $host_charset'"
|
|
} else {
|
|
fail "check effect of `set host-charset $host_charset'"
|
|
}
|
|
|
|
# Now try setting every possible target character set,
|
|
# given that host charset.
|
|
foreach target_charset $charset_subset {
|
|
set testname "try `set target-charset $target_charset'"
|
|
send_gdb "set target-charset $target_charset\n"
|
|
gdb_expect {
|
|
-re "GDB doesn't know of any character set named.*\[\r\n]+${gdb_prompt} $" {
|
|
fail "$testname (didn't recognize name)"
|
|
}
|
|
-re "GDB can't convert from the .* character set to .*\\.\[\r\n\]+${gdb_prompt} $" {
|
|
# This is a serious problem. GDB should be able to convert
|
|
# between any arbitrary pair of character sets.
|
|
fail "$testname (can't convert)"
|
|
}
|
|
-re "${gdb_prompt} $" {
|
|
pass $testname
|
|
}
|
|
timeout {
|
|
fail "$testname (timeout)"
|
|
}
|
|
}
|
|
|
|
# Check that the command actually had its intended effect:
|
|
# $target_charset should now be the target charset.
|
|
send_gdb "show charset\n"
|
|
set result [parse_show_charset_output "parse `show charset' after `set target-charset $target_charset'"]
|
|
if {! [string compare $result [list $host_charset $target_charset]]} {
|
|
pass "check effect of `set target-charset $target_charset'"
|
|
} else {
|
|
fail "check effect of `set target-charset $target_charset'"
|
|
}
|
|
|
|
# Test handling of characters in the host charset which
|
|
# can't be translated into the target charset. \xA2 is
|
|
# `cent' in ISO-8859-1, which has no equivalent in ASCII.
|
|
#
|
|
# On some systems, the pseudo-tty through which we
|
|
# communicate with GDB insists on stripping the high bit
|
|
# from input characters, meaning that `cent' turns into
|
|
# `"'. Since ISO-8859-1 and ASCII are identical in the
|
|
# lower 128 characters, it's tough to see how we can test
|
|
# this behavior on such systems, so we just xfail it.
|
|
#
|
|
# Note: the \x16 (Control-V) is an escape to allow \xA2 to
|
|
# get past readline.
|
|
if {! [string compare $host_charset iso-8859-1] && ! [string compare $target_charset ascii]} {
|
|
|
|
set testname "untranslatable character in character literal"
|
|
send_gdb "print '\x16\xA2'\n"
|
|
gdb_expect {
|
|
-re "There is no character corresponding to .* in the target character set .*\\.\[\r\n\]+$gdb_prompt $" {
|
|
pass $testname
|
|
}
|
|
-re " = 34 '\"'\[\r\n\]+$gdb_prompt $" {
|
|
xfail "$testname (DejaGNU's pseudo-tty strips eighth bit)"
|
|
}
|
|
-re "$gdb_prompt $" {
|
|
fail $testname
|
|
}
|
|
timeout {
|
|
fail "$testname (timeout)"
|
|
}
|
|
}
|
|
|
|
set testname "untranslatable character in string literal"
|
|
# If the PTTY zeros bit seven, then this turns into
|
|
# print """
|
|
# which gets us a syntax error. We don't care.
|
|
send_gdb "print \"\x16\xA2\"\n"
|
|
gdb_expect {
|
|
-re "There is no character corresponding to .* in the target character set .*\\.\[\r\n\]+$gdb_prompt $" {
|
|
pass $testname
|
|
}
|
|
-re "Unterminated string in expression.\[\r\n\]+$gdb_prompt $" {
|
|
xfail "$testname (DejaGNU's pseudo-tty strips eighth bit)"
|
|
}
|
|
-re "$gdb_prompt $" {
|
|
fail $testname
|
|
}
|
|
timeout {
|
|
fail "$testname (timeout)"
|
|
}
|
|
}
|
|
|
|
set testname "untranslatable characters in backslash escape"
|
|
send_gdb "print '\\\x16\xA2'\n"
|
|
gdb_expect {
|
|
-re "The escape sequence .* is equivalent to plain .*, which has no equivalent\[\r\n\]+in the .* character set\\.\[\r\n\]+$gdb_prompt $" {
|
|
pass $testname
|
|
}
|
|
-re " = 34 '\"'\[\r\n\]+$gdb_prompt $" {
|
|
xfail "$testname (DejaGNU's pseudo-tty strips eighth bit)"
|
|
}
|
|
-re "$gdb_prompt $" {
|
|
fail $testname
|
|
}
|
|
timeout {
|
|
fail "$testname (timeout)"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
# Set the host character set to plain ASCII, and try actually printing
|
|
# some strings in various target character sets. We need to run the
|
|
# test program to the point at which the strings have been
|
|
# initialized.
|
|
gdb_test "break ${srcfile}:[gdb_get_line_number "all strings initialized"]" \
|
|
".*Breakpoint.* at .*" \
|
|
"set breakpoint after all strings have been initialized"
|
|
gdb_run_cmd
|
|
gdb_expect {
|
|
-re "Breakpoint.*all strings initialized.*$gdb_prompt $" {
|
|
pass "run until all strings have been initialized"
|
|
}
|
|
-re "$gdb_prompt $" {
|
|
fail "run until all strings have been initialized"
|
|
}
|
|
timeout {
|
|
fail "run until all strings have been initialized (timeout)"
|
|
}
|
|
}
|
|
|
|
|
|
# We only try the wide character tests on machines where the wchar_t
|
|
# typedef in the test case has the right size.
|
|
set wchar_size [get_sizeof wchar_t 99]
|
|
set wchar_ok 0
|
|
if {$wchar_size == 2} {
|
|
lappend charset_subset UCS-2
|
|
set wchar_ok 1
|
|
} elseif {$wchar_size == 4} {
|
|
lappend charset_subset UCS-4
|
|
set wchar_ok 1
|
|
}
|
|
|
|
gdb_test "set host-charset ASCII" ""
|
|
foreach target_charset $charset_subset {
|
|
if {$target_charset == "UCS-4" || $target_charset == "UCS-2"} {
|
|
set param target-wide-charset
|
|
set L L
|
|
} else {
|
|
set param target-charset
|
|
set L ""
|
|
}
|
|
send_gdb "set $param $target_charset\n"
|
|
gdb_expect {
|
|
-re "$gdb_prompt $" {
|
|
pass "set $param $target_charset"
|
|
}
|
|
timeout {
|
|
fail "set $param $target_charset (timeout)"
|
|
}
|
|
}
|
|
|
|
# Try printing the null character. There seems to be a bug in
|
|
# gdb_test that requires us to use gdb_expect here.
|
|
send_gdb "print $L'\\0'\n"
|
|
gdb_expect {
|
|
-re "\\\$${decimal} = 0 $L'\\\\0'\[\r\n\]+$gdb_prompt $" {
|
|
pass "print the null character in ${target_charset}"
|
|
}
|
|
-re "$gdb_prompt $" {
|
|
fail "print the null character in ${target_charset}"
|
|
}
|
|
timeout {
|
|
fail "print the null character in ${target_charset} (timeout)"
|
|
}
|
|
}
|
|
|
|
# Compute the name of the variable in the test program that holds
|
|
# a string in $target_charset. The variable's name is the
|
|
# character set's name, in lower-case, with all non-identifier
|
|
# characters replaced with '_', with "_string" stuck on the end.
|
|
if {$target_charset == "UCS-2"} {
|
|
# We still use the ucs_4_string variable -- but the size is
|
|
# correct for UCS-2.
|
|
set var_name ucs_4_string
|
|
} else {
|
|
set var_name [string tolower "${target_charset}_string"]
|
|
regsub -all -- "\[^a-z0-9_\]" $var_name "_" var_name
|
|
}
|
|
|
|
# Compute a regexp matching the results we expect. This is static,
|
|
# but it's easier than writing it out.
|
|
regsub -all "." "abfnrtv" "(\\\\&|x)" escapes
|
|
set uppercase "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
set lowercase "abcdefghijklmnopqrstuvwxyz"
|
|
set digits "0123456789"
|
|
set octal_escape "\\\\\[0-9\]+"
|
|
|
|
send_gdb "print $var_name\n"
|
|
# ${escapes}${uppercase}${lowercase}${digits}${octal}${octal}
|
|
gdb_expect {
|
|
-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 $" {
|
|
pass "print string in $target_charset"
|
|
}
|
|
-re "$gdb_prompt $" {
|
|
fail "print string in $target_charset"
|
|
}
|
|
timeout {
|
|
fail "print string in $target_charset (timeout)"
|
|
}
|
|
}
|
|
|
|
# Try entering a character literal, and see if it comes back unchanged.
|
|
gdb_test "print $L'A'" \
|
|
" = \[0-9-\]+ $L'A'" \
|
|
"parse character literal in ${target_charset}"
|
|
|
|
# Check that the character literal was encoded correctly.
|
|
gdb_test "print $L'A' == $var_name\[7\]" \
|
|
" = 1" \
|
|
"check value of parsed character literal in ${target_charset}"
|
|
|
|
# Try entering a string literal, and see if it comes back unchanged.
|
|
gdb_test "print $L\"abcdefABCDEF012345\"" \
|
|
" = $L\"abcdefABCDEF012345\"" \
|
|
"parse string literal in ${target_charset}"
|
|
|
|
# Check that the string literal was encoded correctly.
|
|
gdb_test "print $L\"q\"\[0\] == $var_name\[49\]" \
|
|
" = 1" \
|
|
"check value of parsed string literal in ${target_charset}"
|
|
|
|
# Test handling of characters in the target charset which
|
|
# can't be translated into the host charset.
|
|
if {! [string compare $target_charset iso-8859-1]} {
|
|
gdb_test "print iso_8859_1_string\[69\]" \
|
|
" = \[0-9-\]+ '\\\\242'" \
|
|
"print character with no equivalent in host character set"
|
|
gdb_test "print iso_8859_1_string + 70" \
|
|
" = ${hex} \"\\\\242.*\"" \
|
|
"print string with no equivalent in host character set"
|
|
}
|
|
|
|
# Make sure that we don't apply the ISO-8859-1 `print_literally'
|
|
# function to ASCII.
|
|
if {! [string compare $target_charset ascii]} {
|
|
gdb_test "print iso_8859_1_string\[69\]" \
|
|
" = \[0-9-\]+ '\\\\242'" \
|
|
"print ASCII unprintable character"
|
|
gdb_test "print iso_8859_1_string + 70" \
|
|
" = ${hex} \"\\\\242.*\"" \
|
|
"print ASCII unprintable string"
|
|
}
|
|
|
|
# Try printing characters with backslash escape equivalents.
|
|
set escapees {a b f n r t v}
|
|
for {set i 0} {$i < [llength $escapees]} {incr i} {
|
|
set escape [lindex $escapees $i]
|
|
send_gdb "print $var_name\[$i\]\n"
|
|
set have_escape 1
|
|
gdb_expect {
|
|
-re "= \[0-9-\]+ $L'\\\\${escape}'\[\r\n\]+$gdb_prompt $" {
|
|
pass "try printing '\\${escape}' in ${target_charset}"
|
|
}
|
|
-re "= \[0-9-\]+ 'x'\[\r\n\]+$gdb_prompt $" {
|
|
xfail "try printing '\\${escape}' in ${target_charset} (no such escape)"
|
|
set have_escape 0
|
|
}
|
|
-re "$gdb_prompt $" {
|
|
fail "try printing '\\${escape}' in ${target_charset}"
|
|
}
|
|
timeout {
|
|
fail "try printing '\\${escape}' in ${target_charset} (timeout)"
|
|
}
|
|
}
|
|
|
|
if {$have_escape} {
|
|
|
|
# Try parsing a backslash escape in a character literal.
|
|
gdb_test "print $L'\\${escape}' == $var_name\[$i\]" \
|
|
" = 1" \
|
|
"check value of '\\${escape}' in ${target_charset}"
|
|
|
|
# Try parsing a backslash escape in a string literal.
|
|
gdb_test "print $L\"\\${escape}\"\[0\] == $var_name\[$i\]" \
|
|
" = 1" \
|
|
"check value of \"\\${escape}\" in ${target_charset}"
|
|
}
|
|
}
|
|
|
|
# Try printing a character escape that doesn't exist. We should
|
|
# get the unescaped character, in the target character set.
|
|
gdb_test "print $L'\\q'" " = \[0-9-\]+ $L'q'" \
|
|
"print escape that doesn't exist in $target_charset"
|
|
gdb_test "print $L'\\q' == $var_name\[49\]" " = 1" \
|
|
"check value of escape that doesn't exist in $target_charset"
|
|
}
|
|
|
|
# Reset the target charset.
|
|
gdb_test "set target-charset UTF-8" ""
|
|
|
|
# \242 is not a valid UTF-8 character.
|
|
gdb_test "print \"\\242\"" " = \"\\\\242\"" \
|
|
"non-representable target character"
|
|
|
|
gdb_test "print '\\x'" "\\\\x escape without a following hex digit."
|
|
gdb_test "print '\\u'" "\\\\u escape without a following hex digit."
|
|
gdb_test "print '\\9'" " = \[0-9\]+ '9'"
|
|
|
|
# Tests for wide- or unicode- strings. L is the prefix letter to use,
|
|
# either "L" (for wide strings), "u" (for UCS-2), or "U" (for UCS-4).
|
|
# NAME is used in the test names and should be related to the prefix
|
|
# letter in some easy-to-undestand way.
|
|
proc test_wide_or_unicode {L name} {
|
|
gdb_test "print $L\"ab\" $L\"c\"" " = $L\"abc\"" \
|
|
"basic $name string concatenation"
|
|
gdb_test "print $L\"ab\" \"c\"" " = $L\"abc\"" \
|
|
"narrow and $name string concatenation"
|
|
gdb_test "print \"ab\" $L\"c\"" " = $L\"abc\"" \
|
|
"$name and narrow string concatenation"
|
|
gdb_test "print $L\"\\xe\" $L\"c\"" " = $L\"\\\\16c\"" \
|
|
"$name string concatenation with escape"
|
|
gdb_test "print $L\"\" \"abcdef\" \"g\"" \
|
|
"$L\"abcdefg\"" \
|
|
"concatenate three strings with empty $name string"
|
|
|
|
gdb_test "print $L'a'" "= \[0-9\]+ $L'a'" \
|
|
"basic $name character"
|
|
}
|
|
|
|
if {$wchar_ok} {
|
|
test_wide_or_unicode L wide
|
|
}
|
|
|
|
set ucs2_ok [expr {[get_sizeof char16_t 99] == 2}]
|
|
if {$ucs2_ok} {
|
|
test_wide_or_unicode u UCS-2
|
|
}
|
|
|
|
set ucs4_ok [expr {[get_sizeof char32_t 99] == 4}]
|
|
if {$ucs4_ok} {
|
|
test_wide_or_unicode U UCS-4
|
|
}
|
|
|
|
# Test an invalid string combination.
|
|
proc test_combination {L1 name1 L2 name2} {
|
|
gdb_test "print $L1\"abc\" $L2\"def\"" \
|
|
"Undefined string concatenation." \
|
|
"undefined concatenation of $name1 and $name2"
|
|
}
|
|
|
|
if {$wchar_ok && $ucs2_ok} {
|
|
test_combination L wide u UCS-2
|
|
}
|
|
if {$wchar_ok && $ucs4_ok} {
|
|
test_combination L wide U UCS-4
|
|
}
|
|
if {$ucs2_ok && $ucs4_ok} {
|
|
test_combination u UCS-2 U UCS-4
|
|
}
|
|
|
|
gdb_exit
|