diff options
author | mark <mark@138bc75d-0d04-0410-961f-82ee72b054a4> | 2014-08-19 10:30:07 +0000 |
---|---|---|
committer | mark <mark@138bc75d-0d04-0410-961f-82ee72b054a4> | 2014-08-19 10:30:07 +0000 |
commit | 5ea32736d1697cc8bd91fa105afc1e614942fb5f (patch) | |
tree | 3fd8d69776cc4f02da123057b50399697da12933 /gcc/testsuite/lib/gcc-gdb-test.exp | |
parent | 7d1503ccb361fda611d30c5e4ba70dfd29ecf7d2 (diff) | |
download | gcc-5ea32736d1697cc8bd91fa105afc1e614942fb5f.tar.gz |
Add guality [p]type test.
Add a new type:var variant to the guality.exp testsuite to check that
gdb gets the correct type for a variable or function. To use it in a
guality test add something like:
/* { dg-final { gdb-test 50 "type:main" "int (int, char **)" } } */
Which will put a breakpoint at line 50 and check that the type of "main"
equals "int (int, char **)" according to gdb. The test harness will make
sure to squash all extra whitespace/newlines that gdb might use to make
comparisons of large structs easy.
gcc/testsuite/ChangeLog
* lib/gcc-gdb-test.exp (gdb-test): Handle type:var for gdb ptype
matching. Catch '<unknown type in ' to recognize older gdb versions.
* gcc.dg/guality/const-volatile.c: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@214139 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/testsuite/lib/gcc-gdb-test.exp')
-rw-r--r-- | gcc/testsuite/lib/gcc-gdb-test.exp | 47 |
1 files changed, 43 insertions, 4 deletions
diff --git a/gcc/testsuite/lib/gcc-gdb-test.exp b/gcc/testsuite/lib/gcc-gdb-test.exp index d182d88fa56..c7297936c39 100644 --- a/gcc/testsuite/lib/gcc-gdb-test.exp +++ b/gcc/testsuite/lib/gcc-gdb-test.exp @@ -19,7 +19,12 @@ # # Argument 0 is the line number on which to put a breakpoint # Argument 1 is the name of the variable to be checked -# Argument 2 is the expected value of the variable +# possibly prefixed with type: to get the type of the variable +# instead of the value of the variable (the default). +# Argument 2 is the expected value (or type) of the variable +# When asking for the value, the expected value is produced +# calling print on it in gdb. When asking for the type it is +# the literal string with extra whitespace removed. # Argument 3 handles expected failures and the like proc gdb-test { args } { if { ![isnative] || [is_remote target] } { return } @@ -39,6 +44,16 @@ proc gdb-test { args } { upvar 2 name testcase upvar 2 prog prog + # The command to run on the variable + set arg1 [lindex $args 1] + if { [string equal -length 5 "type:" $arg1] == 1 } { + set command "ptype" + set var [string range $arg1 5 end] + } else { + set command "print" + set var $arg1 + } + set gdb_name $::env(GUALITY_GDB_NAME) set testname "$testcase line [lindex $args 0] [lindex $args 1] == [lindex $args 2]" set output_file "[file rootname [file tail $prog]].exe" @@ -47,8 +62,14 @@ proc gdb-test { args } { set fd [open $cmd_file "w"] puts $fd "break [lindex $args 0]" puts $fd "run" - puts $fd "print [lindex $args 1]" - puts $fd "print [lindex $args 2]" + puts $fd "$command $var" + if { $command == "print" } { + # For values, let gdb interpret them by printing them. + puts $fd "print [lindex $args 2]" + } else { + # Since types can span multiple lines, we need an end marker. + puts $fd "echo TYPE_END\\n" + } puts $fd "quit" close $fd @@ -62,12 +83,13 @@ proc gdb-test { args } { remote_expect target [timeout_value] { # Too old GDB - -re "Unhandled dwarf expression|Error in sourced command file" { + -re "Unhandled dwarf expression|Error in sourced command file|<unknown type in " { unsupported "$testname" remote_close target file delete $cmd_file return } + # print var; print expected -re {[\n\r]\$1 = ([^\n\r]*)[\n\r]+\$2 = ([^\n\r]*)[\n\r]} { set first $expect_out(1,string) set second $expect_out(2,string) @@ -83,6 +105,23 @@ proc gdb-test { args } { file delete $cmd_file return } + # ptype var; + -re {[\n\r]type = (.*)[\n\r][\n\r]TYPE_END[\n\r]} { + set type $expect_out(1,string) + # Squash all extra whitespace/newlines that gdb might use for + # "pretty printing" into one so result is just one line. + regsub -all {[\n\r\t ]+} $type " " type + set expected [lindex $args 2] + if { $type == $expected } { + pass "$testname" + } else { + send_log -- "$type != $expected\n" + fail "$testname" + } + remote_close target + file delete $cmd_file + return + } timeout { unsupported "$testname" remote_close target |