# This testcase is part of GDB, the GNU debugger.
-# Copyright 2001, 2004, 2007, 2008, 2009 Free Software Foundation, Inc.
+# Copyright 2001-2016 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
# Test GDB's character set support.
-if $tracelevel then {
- strace $tracelevel
-}
-set prms_id 0
-set bug_id 0
+standard_testfile .c charset-malloc.c
-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}"
+if { [prepare_for_testing ${testfile}.exp ${testfile} [list $srcfile $srcfile2]] } {
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} {
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)
+ -re "Requires an argument. Valid arguments are (.*)\\.\r\n$gdb_prompt $" {
+ set host_charset_list $expect_out(1,string)
+ regsub -all {, } $host_charset_list {,} host_charset_list
+ foreach host_charset [split $host_charset_list ","] {
+ set charsets($host_charset) 1
+ }
pass "capture valid host charsets"
}
-re ".*$gdb_prompt $" {
fail "capture valid host charsets"
}
+
timeout {
fail "(timeout) capture valid host charsets"
}
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
+ -re "Requires an argument. Valid arguments are (.*)\\.\r\n$gdb_prompt $" {
+ set target_charset_list $expect_out(1,string)
+ regsub -all {, } $target_charset_list {,} target_charset_list
+ foreach target_charset [split $target_charset_list ","] {
+ 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 $" {
".*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)"
- }
-}
-
+gdb_test "" "Breakpoint.*all strings initialized.*" "run until all strings have been initialized"
# 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
+ lappend charset_subset UTF-16
set wchar_ok 1
} elseif {$wchar_size == 4} {
- lappend charset_subset UCS-4
+ lappend charset_subset UTF-32
set wchar_ok 1
}
-gdb_test "set host-charset ASCII" ""
+gdb_test_no_output "set host-charset ASCII"
foreach target_charset $charset_subset {
if {![valid_target_charset $target_charset]} {
continue
}
- if {$target_charset == "UCS-4" || $target_charset == "UCS-2"} {
+ if {$target_charset == "UTF-32" || $target_charset == "UTF-16"} {
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)"
- }
- }
+ gdb_test_no_output "set $param $target_charset"
# 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 $" {
+ -re "\\\$${decimal} = 0 $L'\\\\000'\[\r\n\]+$gdb_prompt $" {
pass "print the null character in ${target_charset}"
}
-re "$gdb_prompt $" {
# 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
+ if {$target_charset == "UTF-16"} {
+ # We still use the utf_32_string variable -- but the size is
+ # correct for UTF-16.
+ set var_name utf_32_string
} else {
set var_name [string tolower "${target_charset}_string"]
regsub -all -- "\[^a-z0-9_\]" $var_name "_" var_name
}
# Reset the target charset.
-gdb_test "set target-charset UTF-8" ""
+gdb_test_no_output "set target-charset UTF-8"
# \242 is not a valid UTF-8 character.
gdb_test "print \"\\242\"" " = \"\\\\242\"" \
gdb_test "print '\\u'" "\\\\u escape without a following hex digit."
gdb_test "print '\\9'" " = \[0-9\]+ '9'"
+# An octal escape can only be 3 digits.
+gdb_test "print \"\\1011\"" " = \"A1\""
+
# 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).
+# either "L" (for wide strings), "u" (for UTF-16), or "U" (for UTF-32).
# 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} {
"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\"" \
+ gdb_test "print $L\"\\xe\" $L\"c\"" " = $L\"\\\\016c\"" \
"$name string concatenation with escape"
gdb_test "print $L\"\" \"abcdef\" \"g\"" \
"$L\"abcdefg\"" \
}
set ucs2_ok [expr {[get_sizeof char16_t 99] == 2}]
+
+if ![valid_host_charset "UTF-16"] {
+ verbose -log "Disabling UTF-16 tests."
+ set ucs2_ok 0
+}
+
if {$ucs2_ok} {
- test_wide_or_unicode u UCS-2
+ test_wide_or_unicode u UTF-16
}
set ucs4_ok [expr {[get_sizeof char32_t 99] == 4}]
if {$ucs4_ok} {
- test_wide_or_unicode U UCS-4
+ test_wide_or_unicode U UTF-32
}
# Test an invalid string combination.
}
if {$wchar_ok && $ucs2_ok} {
- test_combination L wide u UCS-2
+ test_combination L wide u UTF-16
}
if {$wchar_ok && $ucs4_ok} {
- test_combination L wide U UCS-4
+ test_combination L wide U UTF-32
# Regression test for a typedef to a typedef.
gdb_test "print myvar" "= \[0-9\]+ L'A'" \
"typedef to wchar_t"
}
if {$ucs2_ok && $ucs4_ok} {
- test_combination u UCS-2 U UCS-4
+ test_combination u UTF-16 U UTF-32
+}
+
+if {$ucs2_ok} {
+ set go 1
+ gdb_test_multiple "python print ('hello, world!')" \
+ "verify python support for charset tests" {
+ -re "not supported.*$gdb_prompt $" {
+ unsupported "python support is disabled"
+ set go 0
+ }
+ -re "$gdb_prompt $" {}
+ }
+
+ if {$go} {
+ gdb_test "print u\"abcdef\"" " = u\"abcdef\"" \
+ "set up for python printing of utf-16 string"
+
+ gdb_test "python print (gdb.history(0).string())" "abcdef" \
+ "extract utf-16 string using python"
+ }
}
# Regression test for a cleanup bug in the charset code.
".* = 1" \
"EVAL_SKIP cleanup handling regression test"
+
+proc string_display { var_name set_prefix x_size x_type} {
+ gdb_test_no_output "set ${var_name} = ${set_prefix}\"Test String\\0with zeroes\"" "Assign ${var_name} with prefix ${set_prefix}"
+ gdb_test "x /2${x_size}s ${var_name}" ".*\t${x_type}\"Test String\"\[\r\n\]+.*\t${x_type}\"with zeroes\"" "Display String ${var_name} with x/${x_size}s"
+}
+
+if {$ucs2_ok} {
+ string_display String16 u h u
+ if {$wchar_size == 2} {
+ string_display String16 L h u
+ }
+}
+
+string_display String32 U w U
+if {$wchar_size == 4} {
+ string_display String32 L w U
+}
+
+
+foreach name {short int long} {
+ # We're really just checking to make sure this doesn't give an
+ # error.
+ gdb_test "print ${name}_array = \"hi\"" \
+ " = {.*}" \
+ "assign string to $name array"
+}
+
+
gdb_exit