1 # Copyright
(C
) 2009-2017 Free Software Foundation
, Inc.
3 # This
program is free software
; you can redistribute it and
/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation
; either version
3 of the License
, or
6 #
(at your option
) any later version.
8 # This
program is distributed in the hope that it will be useful
,
9 # but WITHOUT
ANY WARRANTY
; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License
for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with GCC
; see the file COPYING3.
If not see
15 #
<http
://www.gnu.org
/licenses
/>.
17 # Utility
for testing
variable values using gdb
, invoked via dg
-final.
18 #
Call pass
if variable has the desired value
, otherwise fail.
20 #
Argument 0 is the line number
on which to put a breakpoint
21 #
Argument 1 is the
name of the
variable to be checked
22 # possibly prefixed with type
: to
get the type of the
variable
23 # instead of the value of the
variable (the default
).
24 #
Argument 2 is the expected value
(or type
) of the
variable
25 # When asking
for the value
, the expected value is produced
26 # calling print
on it in gdb. When asking
for the type it is
27 # the literal string with extra whitespace removed.
28 #
Argument 3 handles expected failures and the like
29 proc gdb
-test
{ args } {
30 if { ![isnative
] ||
[is_remote target
] } { return }
32 if { [llength $
args] >= 4 } {
33 switch [dg
-process
-target
[lindex $
args 3]] {
36 "F" { setup_xfail "*-*-*" }
41 # This assumes that we are three frames down from dg
-test
, and that
42 # it still stores the filename of the testcase in a local
variable "name".
43 # A cleaner solution would require a new DejaGnu release.
47 # The command to run
on the
variable
48 set arg1
[lindex $
args 1]
49 if { [string equal
-length
5 "type:" $arg1] == 1 } {
51 set var
[string range $arg1
5 end
]
57 set gdb_name $
::env
(GUALITY_GDB_NAME
)
58 set testname
"$testcase line [lindex $args 0] [lindex $args 1] == [lindex $args 2]"
59 set output_file
"[file rootname [file tail $prog]].exe"
60 set cmd_file
"[file rootname [file tail $prog]].gdb"
62 set fd
[open $cmd_file
"w"]
63 puts $fd
"break [lindex $args 0]"
65 puts $fd
"$command $var"
66 if { $command
== "print" } {
67 #
For values, let gdb interpret them by printing them.
68 puts $fd
"print [lindex $args 2]"
70 # Since types can span multiple lines
, we need an end marker.
71 puts $fd
"echo TYPE_END\\n"
76 send_log
"Spawning: $gdb_name -nx -nw -quiet -batch -x $cmd_file ./$output_file\n"
77 set res
[remote_spawn target
"$gdb_name -nx -nw -quiet -batch -x $cmd_file ./$output_file"]
78 if { $res
< 0 || $res
== "" } {
79 unsupported
"$testname"
84 remote_expect target
[timeout_value
] {
86 -re
"Unhandled dwarf expression|Error in sourced command file|<unknown type in " {
87 unsupported
"$testname"
92 # print var
; print expected
93 -re
{[\n\r]\$
1 = ([^
\n\r]*)[\n\r]+\$
2 = ([^
\n\r]*)[\n\r]} {
94 set first $expect_out
(1,string
)
95 set second $expect_out
(2,string
)
96 if { $first
== $second
} {
99 # We need the
-- to disambiguate $first from an option
,
100 # as it may be negative.
101 send_log
-- "$first != $second\n"
105 file
delete $cmd_file
109 -re
{[\n\r]type
= (.
*)[\n\r][\n\r]TYPE_END
[\n\r]} {
110 set type $expect_out
(1,string
)
111 # Squash all extra whitespace
/newlines that gdb might use
for
112 #
"pretty printing" into one so result is just one line.
113 regsub
-all
{[\n\r\t ]+} $type
" " type
114 # Old gdb might output
"long int" instead of just "long"
115 # and
"short int" instead of just "short". Canonicalize.
116 regsub
-all
{\mlong
int\M
} $type
"long" type
117 regsub
-all
{\mshort
int\M
} $type
"short" type
118 set expected
[lindex $
args 2]
119 if { $type
== $expected
} {
122 send_log
-- "$type != $expected\n"
126 file
delete $cmd_file
130 unsupported
"$testname"
132 file
delete $cmd_file
137 unsupported
"$testname"
139 file
delete $cmd_file