📄 charset.exp
字号:
} 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 [all_charset_names] { 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 [gdb_get_line_number "all strings initialized"]" \ ".*Breakpoint.* at .*" \ "set breakpoint after all strings have been initialized"gdb_run_cmdgdb_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 "set host-charset ASCII" ""foreach target_charset [all_charset_names] { send_gdb "set target-charset $target_charset\n" gdb_expect { -re "$gdb_prompt $" { pass "set target-charset $target_charset" } timeout { fail "set target-charset $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 '\\0'\n" gdb_expect { -re "\\\$${decimal} = 0 '\\\\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. 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\]\[0-9\]\[0-9\]" send_gdb "print $var_name\n" # ${escapes}${uppercase}${lowercase}${digits}${octal}${octal} gdb_expect { -re ".* = \"(\\\\a|x)(\\\\b|x)(\\\\f|x)(\\\\n|x)(\\\\r|x)(\\\\t|x)(\\\\v|x)${uppercase}${lowercase}${digits}(\\\\\[0-9\]\[0-9\]\[0-9\]|x)(\\\\\[0-9\]\[0-9\]\[0-9\]|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 'A'" \ " = \[0-9-\]+ 'A'" \ "parse character literal in ${target_charset}" # Check that the character literal was encoded correctly. gdb_test "print '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 \"abcdefABCDEF012345\"" \ " = \"abcdefABCDEF012345\"" \ "parse string literal in ${target_charset}" # Check that the string literal was encoded correctly. gdb_test "print \"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-\]+ '\\\\${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 '\\${escape}' == $var_name\[$i\]" \ " = 1" \ "check value of '\\${escape}' in ${target_charset}" # Try parsing a backslash escape in a string literal. gdb_test "print \"\\${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 '\\q'" " = \[0-9-\]+ 'q'" \ "print escape that doesn't exist in $target_charset" gdb_test "print '\\q' == $var_name\[49\]" " = 1" \ "check value of escape that doesn't exist in $target_charset"}gdb_exit
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -