URL
https://opencores.org/ocsvn/openrisc/openrisc/trunk
Subversion Repositories openrisc
Compare Revisions
- This comparison shows the changes necessary to convert path
/openrisc/trunk/gnu-old/gdb-6.8/gdb/testsuite/lib
- from Rev 157 to Rev 816
- ↔ Reverse comparison
Rev 157 → Rev 816
/ada.exp
0,0 → 1,431
# Copyright 2004, 2007, 2008 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/>. |
|
load_lib libgloss.exp |
|
# FIXME:brobecker/2004-03-31: |
# The following function should eventually be part of dejagnu. Even after |
# this function becomes available in dejagnu, we will keep for a while |
# a copy of this function here in order to avoid increasing the dejagnu |
# version requirement. |
|
proc gdb_find_gnatmake {} { |
global tool_root_dir |
|
set root "$tool_root_dir/gcc" |
set GM "" |
|
if ![is_remote host] { |
set file [lookfor_file $root gnatmake] |
if { $file != "" } { |
set GM "$file -I$root/ada/rts --GCC=$root/xgcc --GNATBIND=$root/gnatbind --GNATLINK=$root/gnatlink -cargs -B$root -largs --GCC=$root/xgcc -margs"; |
} |
} |
|
if {$GM == ""} { |
set GM [transform gnatmake] |
} |
|
return $GM |
} |
|
# FIXME:brobecker/2004-03-31: |
# The following function is a copy of the function of the same name provided |
# by dejagnu, except that it has been modified to add support for building |
# Ada programs. This copy is temporarily placed here until the changes |
# are merged into the dejagnu official release. Once the changes are merged, |
# we will likely keep this local copy for a while to avoid increasing the |
# dejagnu version requirement. |
|
proc gdb_default_target_compile {source destfile type options} { |
global target_triplet |
global tool_root_dir |
global CFLAGS_FOR_TARGET |
global compiler_flags |
|
if { $destfile == "" && $type != "preprocess" && $type != "none" } { |
error "Must supply an output filename for the compile to default_target_compile" |
} |
|
set add_flags "" |
set libs "" |
set compiler_type "c" |
set compiler "" |
set ldflags "" |
set dest [target_info name] |
|
if [info exists CFLAGS_FOR_TARGET] { |
append add_flags " $CFLAGS_FOR_TARGET" |
} |
|
if [info exists target_info(host,name)] { |
set host [host_info name]; |
} else { |
set host "unix"; |
} |
|
foreach i $options { |
if { $i == "ada" } { |
set compiler_type "ada" |
if [board_info $dest exists adaflags] { |
append add_flags " [target_info adaflags]" |
} |
# append add_flags " [gnatmake_include_flags]"; |
if [board_info $dest exists gnatmake] { |
set compiler [target_info gnatmake]; |
} else { |
set compiler [find_gnatmake]; |
} |
} |
|
if { $i == "c++" } { |
set compiler_type "c++" |
if [board_info $dest exists cxxflags] { |
append add_flags " [target_info cxxflags]" |
} |
append add_flags " [g++_include_flags]"; |
if [board_info $dest exists c++compiler] { |
set compiler [target_info c++compiler]; |
} else { |
set compiler [find_g++]; |
} |
} |
|
if { $i == "f77" } { |
set compiler_type "f77" |
if [board_info $dest exists f77flags] { |
append add_flags " [target_info f77flags]" |
} |
# append add_flags " [f77_include_flags]" |
if [board_info $dest exists f77compiler] { |
set compiler [target_info f77compiler] |
} else { |
set compiler [find_g77] |
} |
} |
|
if [regexp "^dest=" $i] { |
regsub "^dest=" $i "" tmp |
if [board_info $tmp exists name] { |
set dest [board_info $tmp name]; |
} else { |
set dest $tmp; |
} |
} |
if [regexp "^compiler=" $i] { |
regsub "^compiler=" $i "" tmp |
set compiler $tmp |
} |
if [regexp "^additional_flags=" $i] { |
regsub "^additional_flags=" $i "" tmp |
append add_flags " $tmp" |
} |
if [regexp "^ldflags=" $i] { |
regsub "^ldflags=" $i "" tmp |
append ldflags " $tmp" |
} |
if [regexp "^libs=" $i] { |
regsub "^libs=" $i "" tmp |
append libs " $tmp" |
} |
if [regexp "^incdir=" $i] { |
regsub "^incdir=" $i "-I" tmp |
append add_flags " $tmp" |
} |
if [regexp "^libdir=" $i] { |
regsub "^libdir=" $i "-L" tmp |
append add_flags " $tmp" |
} |
if [regexp "^ldscript=" $i] { |
regsub "^ldscript=" $i "" ldscript |
} |
if [regexp "^redirect=" $i] { |
regsub "^redirect=" $i "" redirect |
} |
if [regexp "^optimize=" $i] { |
regsub "^optimize=" $i "" optimize |
} |
if [regexp "^timeout=" $i] { |
regsub "^timeout=" $i "" timeout |
} |
} |
|
if [board_info $host exists cflags_for_target] { |
append add_flags " [board_info $host cflags_for_target]"; |
} |
|
global CC_FOR_TARGET |
global CXX_FOR_TARGET |
global F77_FOR_TARGET |
global GNATMAKE_FOR_TARGET |
|
if [info exists CC_FOR_TARGET] { |
if { $compiler == "" } { |
set compiler $CC_FOR_TARGET |
} |
} |
|
if [info exists CXX_FOR_TARGET] { |
if { $compiler_type == "c++" } { |
set compiler $CXX_FOR_TARGET |
} |
} |
|
if [info exists F77_FOR_TARGET] { |
if { $compiler_type == "f77" } { |
set compiler $F77_FOR_TARGET |
} |
} |
|
if [info exists GNATMAKE_FOR_TARGET] { |
if { $compiler_type == "ada" } { |
set compiler $GNATMAKE_FOR_TARGET |
} |
} |
|
if { $compiler == "" } { |
set compiler [board_info $dest compiler]; |
if { $compiler == "" } { |
return "default_target_compile: No compiler to compile with"; |
} |
} |
|
if ![is_remote host] { |
if { [which $compiler] == 0 } { |
return "default_target_compile: Can't find $compiler." |
} |
} |
|
if {$type == "object"} { |
append add_flags " -c" |
} |
|
if { $type == "preprocess" } { |
append add_flags " -E" |
} |
|
if { $type == "assembly" } { |
append add_flags " -S" |
} |
|
if [board_info $dest exists cflags] { |
append add_flags " [board_info $dest cflags]" |
} |
|
if { $type == "executable" } { |
# This must be added here. |
# if [board_info $dest exists ldscript] { |
# append add_flags " [board_info $dest ldscript]" |
# } |
|
if [board_info $dest exists ldflags] { |
append add_flags " [board_info $dest ldflags]" |
} |
if { $compiler_type == "c++" } { |
append add_flags " [g++_link_flags]"; |
} |
if [isnative] { |
# This is a lose. |
catch "glob -nocomplain $tool_root_dir/libstdc++/libstdc++.so* $tool_root_dir/libstdc++/libstdc++.sl" tmp |
if { ${tmp} != "" } { |
if [regexp ".*solaris2.*" $target_triplet] { |
# Solaris 2 |
append add_flags " -R$tool_root_dir/libstdc++" |
} elseif [regexp ".*(osf|irix5|linux).*" $target_triplet] { |
# OSF/1 or Irix5 |
append add_flags " -Wl,-rpath,$tool_root_dir/libstdc++" |
} elseif [regexp ".*hppa.*" $target_triplet] { |
# HP/UX |
append add_flags " -Wl,-a,shared_archive" |
} |
} |
} |
} |
|
if ![info exists ldscript] { |
set ldscript [board_info $dest ldscript] |
} |
|
foreach i $options { |
if { $i == "debug" } { |
if [board_info $dest exists debug_flags] { |
append add_flags " [board_info $dest debug_flags]"; |
} else { |
append add_flags " -g" |
} |
} |
} |
|
if [info exists optimize] { |
append add_flags " $optimize"; |
} |
|
if { $type == "executable" } { |
append add_flags " $ldflags" |
foreach x $libs { |
if [file exists $x] { |
append source " $x" |
} else { |
append add_flags " $x"; |
} |
} |
|
if [board_info $dest exists libs] { |
append add_flags " [board_info $dest libs]" |
} |
|
# This probably isn't such a good idea, but it avoids nasty |
# hackiness in the testsuites. |
# The math library must be linked in before the C library. The C |
# library is linked in by the linker script, so this must be before |
# the linker script. |
if [board_info $dest exists mathlib] { |
append add_flags " [board_info $dest mathlib]" |
} else { |
append add_flags " -lm" |
} |
|
# This must be added here. |
append add_flags " $ldscript"; |
|
if [board_info $dest exists remote_link] { |
# Relink option. |
append add_flags " -Wl,-r" |
} |
if [board_info $dest exists output_format] { |
append add_flags " -Wl,-oformat,[board_info $dest output_format]"; |
} |
} |
|
if [board_info $dest exists multilib_flags] { |
append add_flags " [board_info $dest multilib_flags]"; |
} |
|
verbose "doing compile" |
|
set sources "" |
if [is_remote host] { |
foreach x $source { |
set file [remote_download host $x]; |
if { $file == "" } { |
warning "Unable to download $x to host." |
return "Unable to download $x to host." |
} else { |
append sources " $file"; |
} |
} |
} else { |
set sources $source |
} |
|
if [is_remote host] { |
append add_flags " -o a.out" |
remote_file host delete a.out; |
} else { |
if { $destfile != "" } { |
append add_flags " -o $destfile"; |
} |
} |
|
# This is obscure: we put SOURCES at the end when building an |
# object, because otherwise, in some situations, libtool will |
# become confused about the name of the actual source file. |
if {$type == "object"} { |
set opts "$add_flags $sources" |
} else { |
set opts "$sources $add_flags" |
} |
|
if [is_remote host] { |
if [host_info exists use_at] { |
set fid [open "atfile" "w"]; |
puts $fid "$opts"; |
close $fid; |
set opts "@[remote_download host atfile]" |
remote_file build delete atfile |
} |
} |
|
verbose "Invoking the compiler as $compiler $opts" 2 |
|
if [info exists redirect] { |
verbose "Redirecting output to $redirect" 2 |
set status [remote_exec host "$compiler $opts" "" "" $redirect]; |
} else { |
if [info exists timeout] { |
verbose "Setting timeout to $timeout" 2 |
set status [remote_exec host "$compiler $opts" "" "" "" $timeout]; |
} else { |
set status [remote_exec host "$compiler $opts"]; |
} |
} |
|
set compiler_flags $opts |
if [is_remote host] { |
remote_upload host a.out $destfile; |
remote_file host delete a.out; |
} |
set comp_output [prune_warnings [lindex $status 1]]; |
regsub "^\[\r\n\]+" $comp_output "" comp_output; |
if { [lindex $status 0] != 0 } { |
verbose -log "compiler exited with status [lindex $status 0]"; |
} |
if { [lindex $status 1] != "" } { |
verbose -log "output is:\n[lindex $status 1]" 2; |
} |
if { [lindex $status 0] != 0 && "${comp_output}" == "" } { |
set comp_output "exit status is [lindex $status 0]"; |
} |
return ${comp_output}; |
} |
|
# See if the version of dejaGNU being used to run the testsuite is |
# recent enough to contain support for building Ada programs or not. |
# If not, then use the functions above in place of the ones provided |
# by dejaGNU. This is only temporary (brobecker/2004-03-31). |
|
if {[info procs find_gnatmake] == ""} { |
proc find_gnatmake { } { return [gdb_find_gnatmake] } |
proc default_target_compile { source destfile type options } { |
return [gdb_default_target_compile $source $destfile $type $options] |
} |
} |
|
# Compile some Ada code. |
|
proc gdb_compile_ada {source dest type options} { |
|
set srcdir [file dirname $source] |
set gprdir [file dirname $srcdir] |
set objdir [file dirname $dest] |
|
append options " ada" |
append options " additional_flags=-P$gprdir/gnat_ada" |
append options " additional_flags=-XSRC=[file tail $srcdir]" |
append options " additional_flags=-XOBJ=$objdir" |
|
set result [target_compile [file tail $source] $dest $type $options] |
|
# The Ada build always produces some output, even when the build |
# succeeds. Thus, we can not use the output the same way we do in |
# gdb_compile to determine whether the build has succeeded or not. |
# We therefore simply check whether the dest file has been created |
# or not. Unless not present, the build has succeeded. |
if ![file exists $dest] { |
unsupported "Ada compilation failed: $result" |
return "Ada compilation failed." |
} |
} |
|
/trace-support.exp
0,0 → 1,306
# Copyright (C) 1998, 2007, 2008 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@prep.ai.mit.edu |
|
|
# |
# Support procedures for trace testing |
# |
|
|
# |
# Procedure: gdb_target_supports_trace |
# Returns true if GDB is connected to a target that supports tracing. |
# Allows tests to abort early if not running on a trace-aware target. |
# |
|
proc gdb_target_supports_trace { } { |
global gdb_prompt |
|
send_gdb "tstatus\n" |
gdb_expect { |
-re "\[Tt\]race can only be run on.*$gdb_prompt $" { |
return 0 |
} |
-re "\[Tt\]race can not be run on.*$gdb_prompt $" { |
return 0 |
} |
-re "\[Tt\]arget does not support.*$gdb_prompt $" { |
return 0 |
} |
-re ".*\[Ee\]rror.*$gdb_prompt $" { |
return 0 |
} |
-re ".*\[Ww\]arning.*$gdb_prompt $" { |
return 0 |
} |
-re ".*$gdb_prompt $" { |
return 1 |
} |
timeout { |
return 0 |
} |
} |
} |
|
|
# |
# Procedure: gdb_delete_tracepoints |
# Many of the tests depend on setting tracepoints at various places and |
# running until that tracepoint is reached. At times, we want to start |
# with a clean slate with respect to tracepoints, so this utility proc |
# lets us do this without duplicating this code everywhere. |
# |
|
proc gdb_delete_tracepoints {} { |
global gdb_prompt |
|
send_gdb "delete tracepoints\n" |
gdb_expect 30 { |
-re "Delete all tracepoints.*y or n.*$" { |
send_gdb "y\n"; |
exp_continue |
} |
-re ".*$gdb_prompt $" { # This happens if there were no tracepoints } |
timeout { |
perror "Delete all tracepoints in delete_tracepoints (timeout)" |
return |
} |
} |
send_gdb "info tracepoints\n" |
gdb_expect 30 { |
-re "No tracepoints.*$gdb_prompt $" {} |
-re "$gdb_prompt $" { perror "tracepoints not deleted" ; return } |
timeout { perror "info tracepoints (timeout)" ; return } |
} |
} |
|
# |
# Procedure: gdb_trace_setactions |
# Define actions for a tracepoint. |
# Arguments: |
# testname -- identifying string for pass/fail output |
# tracepoint -- to which tracepoint do these actions apply? (optional) |
# args -- list of actions to be defined. |
# Returns: |
# zero -- success |
# non-zero -- failure |
|
proc gdb_trace_setactions { testname tracepoint args } { |
global gdb_prompt; |
|
set state 0; |
set passfail "pass"; |
send_gdb "actions $tracepoint\n"; |
set expected_result ""; |
gdb_expect 5 { |
-re "No tracepoint number .*$gdb_prompt $" { |
fail $testname |
return 1; |
} |
-re "Enter actions for tracepoint $tracepoint.*>" { |
if { [llength $args] > 0 } { |
set lastcommand "[lindex $args $state]"; |
send_gdb "[lindex $args $state]\n"; |
incr state; |
set expected_result [lindex $args $state]; |
incr state; |
} else { |
send_gdb "end\n"; |
} |
exp_continue; |
} |
-re "\(.*\)\[\r\n\]+\[ \t]*> $" { |
if { $expected_result != "" } { |
regsub "^\[^\r\n\]+\[\r\n\]+" "$expect_out(1,string)" "" out; |
if ![regexp $expected_result $out] { |
set passfail "fail"; |
} |
set expected_result ""; |
} |
if { $state < [llength $args] } { |
send_gdb "[lindex $args $state]\n"; |
incr state; |
set expected_result [lindex $args $state]; |
incr state; |
} else { |
send_gdb "end\n"; |
set expected_result ""; |
} |
exp_continue; |
} |
-re "\(.*\)$gdb_prompt $" { |
if { $expected_result != "" } { |
if ![regexp $expected_result $expect_out(1,string)] { |
set passfail "fail"; |
} |
set expected_result ""; |
} |
if { [llength $args] < $state } { |
set passfail "fail"; |
} |
} |
default { |
set passfail "fail"; |
} |
} |
if { $testname != "" } { |
$passfail $testname; |
} |
if { $passfail == "pass" } then { |
return 0; |
} else { |
return 1; |
} |
} |
|
# |
# Procedure: gdb_tfind_test |
# Find a specified trace frame. |
# Arguments: |
# testname -- identifying string for pass/fail output |
# tfind_arg -- frame (line, PC, etc.) identifier |
# exp_res -- Expected result of frame test |
# args -- Test expression |
# Returns: |
# zero -- success |
# non-zero -- failure |
# |
|
proc gdb_tfind_test { testname tfind_arg exp_res args } { |
global gdb_prompt; |
|
if { "$args" != "" } { |
set expr "$exp_res"; |
set exp_res "$args"; |
} else { |
set expr "(int) \$trace_frame"; |
} |
set passfail "fail"; |
|
gdb_test "tfind $tfind_arg" "" "" |
send_gdb "printf \"x \%d x\\n\", $expr\n"; |
gdb_expect 10 { |
-re "x (-*\[0-9\]+) x" { |
if { $expect_out(1,string) == $exp_res } { |
set passfail "pass"; |
} |
exp_continue; |
} |
-re "$gdb_prompt $" { } |
} |
$passfail "$testname"; |
if { $passfail == "pass" } then { |
return 0; |
} else { |
return 1; |
} |
} |
|
# |
# Procedure: gdb_readexpr |
# Arguments: |
# gdb_expr -- the expression whose value is desired |
# Returns: |
# the value of gdb_expr, as evaluated by gdb. |
# [FIXME: returns -1 on error, which is sometimes a legit value] |
# |
|
proc gdb_readexpr { gdb_expr } { |
global gdb_prompt; |
|
set result -1; |
send_gdb "print $gdb_expr\n" |
gdb_expect 5 { |
-re "\[$\].*= (\[0-9\]+).*$gdb_prompt $" { |
set result $expect_out(1,string); |
} |
-re "$gdb_prompt $" { } |
default { } |
} |
return $result; |
} |
|
# |
# Procedure: gdb_gettpnum |
# Arguments: |
# tracepoint (optional): if supplied, set a tracepoint here. |
# Returns: |
# the tracepoint ID of the most recently set tracepoint. |
# |
|
proc gdb_gettpnum { tracepoint } { |
global gdb_prompt; |
|
if { $tracepoint != "" } { |
gdb_test "trace $tracepoint" "" "" |
} |
return [gdb_readexpr "\$tpnum"]; |
} |
|
|
# |
# Procedure: gdb_find_function_baseline |
# Arguments: |
# func_name -- name of source function |
# Returns: |
# Sourcefile line of function definition (open curly brace), |
# or -1 on failure. Caller must check return value. |
# Note: |
# Works only for open curly brace at beginning of source line! |
# |
|
proc gdb_find_function_baseline { func_name } { |
global gdb_prompt; |
|
set baseline -1; |
|
send_gdb "list $func_name\n" |
# gdb_expect { |
# -re "\[\r\n\]\[\{\].*$gdb_prompt $" { |
# set baseline 1 |
# } |
# } |
} |
|
# |
# Procedure: gdb_find_function_baseline |
# Arguments: |
# filename: name of source file of desired function. |
# Returns: |
# Sourcefile line of function definition (open curly brace), |
# or -1 on failure. Caller must check return value. |
# Note: |
# Works only for open curly brace at beginning of source line! |
# |
|
proc gdb_find_recursion_test_baseline { filename } { |
global gdb_prompt; |
|
set baseline -1; |
|
gdb_test "list $filename:1" "" "" |
send_gdb "search gdb_recursion_test line 0\n" |
gdb_expect { |
-re "(\[0-9\]+)\[\t \]+\{.*line 0.*$gdb_prompt $" { |
set baseline $expect_out(1,string); |
} |
-re "$gdb_prompt $" { } |
default { } |
} |
return $baseline; |
} |
/cp-support.exp
0,0 → 1,468
# This test code is part of GDB, the GNU debugger. |
|
# Copyright 2003, 2004, 2007, 2008 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/>. |
|
# Auxiliary function to check for known problems. |
# |
# EXPECTED_STRING is the string expected by the test. |
# |
# ACTUAL_STRING is the actual string output by gdb. |
# |
# ERRATA_TABLE is a list of lines of the form: |
# |
# { expected-string broken-string {eval-block} } |
# |
# If there is a line for the given EXPECTED_STRING, and if the |
# ACTUAL_STRING output by gdb is the same as the BROKEN_STRING in the |
# table, then I eval the eval-block. |
|
proc cp_check_errata { expected_string actual_string errata_table } { |
foreach erratum $errata_table { |
if { "$expected_string" == [lindex $erratum 0] |
&& "$actual_string" == [lindex $erratum 1] } then { |
eval [lindex $erratum 2] |
} |
} |
} |
|
# Test ptype of a class. |
# |
# Different C++ compilers produce different output. To accommodate all |
# the variations listed below, I read the output of "ptype" and process |
# each line, matching it to the class description given in the |
# parameters. |
# |
# IN_COMMAND and IN_TESTNAME are the command and testname for |
# gdb_test_multiple. If IN_TESTNAME is the empty string, then it |
# defaults to IN_COMMAND. |
# |
# IN_KEY is "class" or "struct". For now, I ignore it, and allow either |
# "class" or "struct" in the output, as long as the access specifiers all |
# work out okay. |
# |
# IN_TAG is the class tag or structure tag. |
# |
# IN_CLASS_TABLE is a list of class information. Each entry contains a |
# keyword and some values. The keywords and their values are: |
# |
# { base "base-declaration" } |
# |
# the class has a base with the given declaration. |
# |
# { vbase "name" } |
# |
# the class has a virtual base pointer with the given name. this |
# is for gcc 2.95.3, which emits ptype entries for the virtual base |
# pointers. the vbase list includes both indirect and direct |
# virtual base classes (indeed, a virtual base is usually |
# indirect), so this information cannot be derived from the base |
# declarations. |
# |
# { field "access" "declaration" } |
# |
# the class has a data field with the given access type and the |
# given declaration. |
# |
# { method "access" "declaration" } |
# |
# the class has a member function with the given access type |
# and the given declaration. |
# |
# If you test the same class declaration more than once, you can specify |
# IN_CLASS_TABLE as "ibid". "ibid" means: look for a previous class |
# table that had the same IN_KEY and IN_TAG, and re-use that table. |
# |
# IN_TAIL is the expected text after the close brace, specifically the "*" |
# in "struct { ... } *". This is an optional parameter. The default |
# value is "", for no tail. |
# |
# IN_ERRATA_TABLE is a list of errata entries. See cp_check_errata for the |
# format of the errata table. Note: the errata entries are not subject to |
# demangler syntax adjustment, so you have to make a bigger table |
# with lines for each output variation. |
# |
# gdb can vary the output of ptype in several ways: |
# |
# . CLASS/STRUCT |
# |
# The output can start with either "class" or "struct", depending on |
# what the symbol table reader in gdb decides. This is usually |
# unrelated to the original source code. |
# |
# dwarf-2 debug info distinguishes class/struct, but gdb ignores it |
# stabs+ debug info does not distinguish class/struct |
# hp debug info distinguishes class/struct, and gdb honors it |
# |
# I tried to accommodate this with regular expressions such as |
# "((class|struct) A \{ public:|struct A \{)", but that turns into a |
# hairy mess because of optional private virtual base pointers and |
# optional public synthetic operators. This is the big reason I gave |
# up on regular expressions and started parsing the output. |
# |
# . REDUNDANT ACCESS SPECIFIER |
# |
# In "class { private: ... }" or "struct { public: ... }", gdb might |
# or might not emit a redundant initial access specifier, depending |
# on the gcc version. |
# |
# . VIRTUAL BASE POINTERS |
# |
# If a class has virtual bases, either direct or indirect, the class |
# will have virtual base pointers. With gcc 2.95.3, gdb prints lines |
# for these virtual base pointers. This does not happen with gcc |
# 3.3.4, gcc 3.4.1, or hp acc A.03.45. |
# |
# I accept these lines. These lines are optional; but if I see one of |
# these lines, then I expect to see all of them. |
# |
# Note: drow considers printing these lines to be a bug in gdb. |
# |
# . SYNTHETIC METHODS |
# |
# A C++ compiler may synthesize some methods: an assignment |
# operator, a copy constructor, a constructor, and a destructor. The |
# compiler might include debug information for these methods. |
# |
# dwarf-2 gdb does not show these methods |
# stabs+ gdb shows these methods |
# hp gdb does not show these methods |
# |
# I accept these methods. These lines are optional, and any or |
# all of them might appear, mixed in anywhere in the regular methods. |
# |
# With gcc v2, the synthetic copy-ctor and ctor have an additional |
# "int" parameter at the beginning, the "in-charge" flag. |
# |
# . DEMANGLER SYNTAX VARIATIONS |
# |
# Different demanglers produce "int foo(void)" versus "int foo()", |
# "const A&" versus "const A &", and so on. |
# |
# TESTED WITH |
# |
# gcc 2.95.3 -gdwarf-2 |
# gcc 2.95.3 -gstabs+ |
# gcc 3.3.4 -gdwarf-2 |
# gcc 3.3.4 -gstabs+ |
# gcc 3.4.1 -gdwarf-2 |
# gcc 3.4.1 -gstabs+ |
# gcc HEAD 20040731 -gdwarf-2 |
# gcc HEAD 20040731 -gstabs+ |
# |
# TODO |
# |
# Tagless structs. |
# |
# "A*" versus "A *" and "A&" versus "A &" in user methods. |
# |
# Test with hp ACC. |
# |
# -- chastain 2004-08-07 |
|
proc cp_test_ptype_class { in_command in_testname in_key in_tag in_class_table { in_tail "" } { in_errata_table { } } } { |
global gdb_prompt |
set wsopt "\[\r\n\t \]*" |
|
# The test name defaults to the command. |
|
if { "$in_testname" == "" } then { set in_testname "$in_command" } |
|
# Save class tables in a history array for reuse. |
|
global cp_class_table_history |
if { $in_class_table == "ibid" } then { |
if { ! [info exists cp_class_table_history("$in_key,$in_tag") ] } then { |
fail "$in_testname // bad ibid" |
return |
} |
set in_class_table $cp_class_table_history("$in_key,$in_tag") |
} else { |
set cp_class_table_history("$in_key,$in_tag") $in_class_table |
} |
|
# Split the class table into separate tables. |
|
set list_bases { } |
set list_vbases { } |
set list_fields { } |
set list_methods { } |
|
foreach class_line $in_class_table { |
switch [lindex $class_line 0] { |
"base" { lappend list_bases [lindex $class_line 1] } |
"vbase" { lappend list_vbases [lindex $class_line 1] } |
"field" { lappend list_fields [lrange $class_line 1 2] } |
"method" { lappend list_methods [lrange $class_line 1 2] } |
default { fail "$in_testname // bad line in class table: $class_line"; return; } |
} |
} |
|
# Construct a list of synthetic operators. |
# These are: { count ccess-type regular-expression }. |
|
set list_synth { } |
lappend list_synth [list 0 "public" "$in_tag & operator=\\($in_tag const ?&\\);"] |
lappend list_synth [list 0 "public" "$in_tag\\((int,|) ?$in_tag const ?&\\);"] |
lappend list_synth [list 0 "public" "$in_tag\\((int|void|)\\);"] |
|
# Actually do the ptype. |
|
set parse_okay 0 |
gdb_test_multiple "$in_command" "$in_testname // parse failed" { |
-re "type = (struct|class)${wsopt}(\[A-Za-z0-9_\]*)${wsopt}((:\[^\{\]*)?)${wsopt}\{(.*)\}${wsopt}(\[^\r\n\]*)\[\r\n\]+$gdb_prompt $" { |
set parse_okay 1 |
set actual_key $expect_out(1,string) |
set actual_tag $expect_out(2,string) |
set actual_base_string $expect_out(3,string) |
set actual_body $expect_out(5,string) |
set actual_tail $expect_out(6,string) |
} |
} |
if { ! $parse_okay } then { return } |
|
# Check the actual key. It would be nice to require that it match |
# the input key, but gdb does not support that. For now, accept any |
# $actual_key as long as the access property of each field/method |
# matches. |
|
switch "$actual_key" { |
"class" { set access "private" } |
"struct" { set access "public" } |
default { |
cp_check_errata "class" "$actual_key" $in_errata_table |
cp_check_errata "struct" "$actual_key" $in_errata_table |
fail "$in_testname // wrong key: $actual_key" |
return |
} |
} |
|
# Check the actual tag. |
|
if { "$actual_tag" != "$in_tag" } then { |
cp_check_errata "$in_tag" "$actual_tag" $in_errata_table |
fail "$in_testname // wrong tag: $actual_tag" |
return |
} |
|
# Check the actual bases. |
# First parse them into a list. |
|
set list_actual_bases { } |
if { "$actual_base_string" != "" } then { |
regsub "^:${wsopt}" $actual_base_string "" actual_base_string |
set list_actual_bases [split $actual_base_string ","] |
} |
|
# Check the base count. |
|
if { [llength $list_actual_bases] < [llength $list_bases] } then { |
fail "$in_testname // too few bases" |
return |
} |
if { [llength $list_actual_bases] > [llength $list_bases] } then { |
fail "$in_testname // too many bases" |
return |
} |
|
# Check each base. |
|
foreach actual_base $list_actual_bases { |
set actual_base [string trim $actual_base] |
set base [lindex $list_bases 0] |
if { "$actual_base" != "$base" } then { |
cp_check_errata "$base" "$actual_base" $in_errata_table |
fail "$in_testname // wrong base: $actual_base" |
return |
} |
set list_bases [lreplace $list_bases 0 0] |
} |
|
# Parse each line in the body. |
|
set last_was_access 0 |
set vbase_match 0 |
|
foreach actual_line [split $actual_body "\r\n"] { |
|
# Chomp the line. |
|
set actual_line [string trim $actual_line] |
if { "$actual_line" == "" } then { continue } |
|
# Access specifiers. |
|
if { [regexp "^(public|protected|private)${wsopt}:\$" "$actual_line" s0 s1] } then { |
set access "$s1" |
if { $last_was_access } then { |
fail "$in_testname // redundant access specifier" |
return |
} |
set last_was_access 1 |
continue |
} else { |
set last_was_access 0 |
} |
|
# Optional virtual base pointer. |
|
if { [ llength $list_vbases ] > 0 } then { |
set vbase [lindex $list_vbases 0] |
if { [ regexp "$vbase \\*(_vb.|_vb\\\$|__vb_)\[0-9\]*$vbase;" $actual_line ] } then { |
if { "$access" != "private" } then { |
cp_check_errata "private" "$access" $in_errata_table |
fail "$in_testname // wrong access specifier for virtual base: $access" |
return |
} |
set list_vbases [lreplace $list_vbases 0 0] |
set vbase_match 1 |
continue |
} |
} |
|
# Data field. |
|
if { [llength $list_fields] > 0 } then { |
set field_access [lindex [lindex $list_fields 0] 0] |
set field_decl [lindex [lindex $list_fields 0] 1] |
if { "$actual_line" == "$field_decl" } then { |
if { "$access" != "$field_access" } then { |
cp_check_errata "$field_access" "$access" $in_errata_table |
fail "$in_testname // wrong access specifier for field: $access" |
return |
} |
set list_fields [lreplace $list_fields 0 0] |
continue |
} |
|
# Data fields must appear before synths and methods. |
cp_check_errata "$field_decl" "$actual_line" $in_errata_table |
fail "$in_testname // unrecognized line type 1: $actual_line" |
return |
} |
|
# Method function. |
|
if { [llength $list_methods] > 0 } then { |
set method_access [lindex [lindex $list_methods 0] 0] |
set method_decl [lindex [lindex $list_methods 0] 1] |
if { "$actual_line" == "$method_decl" } then { |
if { "$access" != "$method_access" } then { |
cp_check_errata "$method_access" "$access" $in_errata_table |
fail "$in_testname // wrong access specifier for method: $access" |
return |
} |
set list_methods [lreplace $list_methods 0 0] |
continue |
} |
|
# gcc 2.95.3 shows "foo()" as "foo(void)". |
regsub -all "\\(\\)" $method_decl "(void)" method_decl |
if { "$actual_line" == "$method_decl" } then { |
if { "$access" != "$method_access" } then { |
cp_check_errata "$method_access" "$access" $in_errata_table |
fail "$in_testname // wrong access specifier for method: $access" |
return |
} |
set list_methods [lreplace $list_methods 0 0] |
continue |
} |
} |
|
# Synthetic operators. These are optional and can be mixed in |
# with the methods in any order, but duplicates are wrong. |
# |
# This test must come after the user methods, so that a user |
# method which matches a synth-method pattern is treated |
# properly as a user method. |
|
set synth_match 0 |
for { set isynth 0 } { $isynth < [llength $list_synth] } { incr isynth } { |
set synth [lindex $list_synth $isynth] |
set synth_count [lindex $synth 0] |
set synth_access [lindex $synth 1] |
set synth_re [lindex $synth 2] |
|
if { [ regexp "$synth_re" "$actual_line" ] } then { |
|
if { "$access" != "$synth_access" } then { |
cp_check_errata "$synth_access" "$access" $in_errata_table |
fail "$in_testname // wrong access specifier for synthetic operator: $access" |
return |
} |
|
if { $synth_count > 0 } then { |
cp_check_errata "$actual_line" "$actual_line" $in_errata_table |
fail "$in_testname // duplicate synthetic operator: $actual_line" |
} |
|
# Update the count in list_synth. |
|
incr synth_count |
set synth [list $synth_count $synth_access "$synth_re"] |
set list_synth [lreplace $list_synth $isynth $isynth $synth] |
|
# Match found. |
|
set synth_match 1 |
break |
} |
} |
if { $synth_match } then { continue } |
|
# Unrecognized line. |
|
if { [llength $list_methods] > 0 } then { |
set method_decl [lindex [lindex $list_methods 0] 1] |
cp_check_errata "$method_decl" "$actual_line" $in_errata_table |
} |
|
fail "$in_testname // unrecognized line type 2: $actual_line" |
return |
} |
|
# Check for missing elements. |
|
if { $vbase_match } then { |
if { [llength $list_vbases] > 0 } then { |
fail "$in_testname // missing virtual base pointers" |
return |
} |
} |
|
if { [llength $list_fields] > 0 } then { |
fail "$in_testname // missing fields" |
return |
} |
|
if { [llength $list_methods] > 0 } then { |
fail "$in_testname // missing methods" |
return |
} |
|
# Check the tail. |
|
set actual_tail [string trim $actual_tail] |
if { "$actual_tail" != "$in_tail" } then { |
cp_check_errata "$in_tail" "$actual_tail" $in_errata_table |
fail "$in_testname // wrong tail: $actual_tail" |
return |
} |
|
# It all worked! |
|
pass "$in_testname" |
return |
} |
/gdb.exp
0,0 → 1,2645
# Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, |
# 2003, 2004, 2005, 2007, 2008 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/>. |
|
# This file was written by Fred Fish. (fnf@cygnus.com) |
|
# Generic gdb subroutines that should work for any target. If these |
# need to be modified for any target, it can be done with a variable |
# or by passing arguments. |
|
if {$tool == ""} { |
# Tests would fail, logs on get_compiler_info() would be missing. |
send_error "`site.exp' not found, run `make site.exp'!\n" |
exit 2 |
} |
|
load_lib libgloss.exp |
|
global GDB |
|
if [info exists TOOL_EXECUTABLE] { |
set GDB $TOOL_EXECUTABLE; |
} |
if ![info exists GDB] { |
if ![is_remote host] { |
set GDB [findfile $base_dir/../../gdb/gdb "$base_dir/../../gdb/gdb" [transform gdb]] |
} else { |
set GDB [transform gdb]; |
} |
} |
verbose "using GDB = $GDB" 2 |
|
global GDBFLAGS |
if ![info exists GDBFLAGS] { |
set GDBFLAGS "-nx" |
} |
verbose "using GDBFLAGS = $GDBFLAGS" 2 |
|
# The variable gdb_prompt is a regexp which matches the gdb prompt. |
# Set it if it is not already set. |
global gdb_prompt |
if ![info exists gdb_prompt] then { |
set gdb_prompt "\[(\]gdb\[)\]" |
} |
|
# The variable fullname_syntax_POSIX is a regexp which matches a POSIX |
# absolute path ie. /foo/ |
set fullname_syntax_POSIX "/.*/" |
# The variable fullname_syntax_UNC is a regexp which matches a Windows |
# UNC path ie. \\D\foo\ |
set fullname_syntax_UNC {\\\\[^\\]+\\.+\\} |
# The variable fullname_syntax_DOS_CASE is a regexp which matches a |
# particular DOS case that GDB most likely will output |
# ie. \foo\, but don't match \\.*\ |
set fullname_syntax_DOS_CASE {\\[^\\].*\\} |
# The variable fullname_syntax_DOS is a regexp which matches a DOS path |
# ie. a:\foo\ && a:foo\ |
set fullname_syntax_DOS {[a-zA-Z]:.*\\} |
# The variable fullname_syntax is a regexp which matches what GDB considers |
# an absolute path. It is currently debatable if the Windows style paths |
# d:foo and \abc should be considered valid as an absolute path. |
# Also, the purpse of this regexp is not to recognize a well formed |
# absolute path, but to say with certainty that a path is absolute. |
set fullname_syntax "($fullname_syntax_POSIX|$fullname_syntax_UNC|$fullname_syntax_DOS_CASE|$fullname_syntax_DOS)" |
|
# Needed for some tests under Cygwin. |
global EXEEXT |
global env |
|
if ![info exists env(EXEEXT)] { |
set EXEEXT "" |
} else { |
set EXEEXT $env(EXEEXT) |
} |
|
set octal "\[0-7\]+" |
|
### Only procedures should come after this point. |
|
# |
# gdb_version -- extract and print the version number of GDB |
# |
proc default_gdb_version {} { |
global GDB |
global GDBFLAGS |
global gdb_prompt |
set fileid [open "gdb_cmd" w]; |
puts $fileid "q"; |
close $fileid; |
set cmdfile [remote_download host "gdb_cmd"]; |
set output [remote_exec host "$GDB -nw --command $cmdfile"] |
remote_file build delete "gdb_cmd"; |
remote_file host delete "$cmdfile"; |
set tmp [lindex $output 1]; |
set version "" |
regexp " \[0-9\]\[^ \t\n\r\]+" "$tmp" version |
if ![is_remote host] { |
clone_output "[which $GDB] version $version $GDBFLAGS\n" |
} else { |
clone_output "$GDB on remote host version $version $GDBFLAGS\n" |
} |
} |
|
proc gdb_version { } { |
return [default_gdb_version]; |
} |
|
# |
# gdb_unload -- unload a file if one is loaded |
# |
|
proc gdb_unload {} { |
global verbose |
global GDB |
global gdb_prompt |
send_gdb "file\n" |
gdb_expect 60 { |
-re "No executable file now\[^\r\n\]*\[\r\n\]" { exp_continue } |
-re "No symbol file now\[^\r\n\]*\[\r\n\]" { exp_continue } |
-re "A program is being debugged already..*Kill it.*y or n. $"\ |
{ send_gdb "y\n" |
verbose "\t\tKilling previous program being debugged" |
exp_continue |
} |
-re "Discard symbol table from .*y or n.*$" { |
send_gdb "y\n" |
exp_continue |
} |
-re "$gdb_prompt $" {} |
timeout { |
perror "couldn't unload file in $GDB (timed out)." |
return -1 |
} |
} |
} |
|
# Many of the tests depend on setting breakpoints at various places and |
# running until that breakpoint is reached. At times, we want to start |
# with a clean-slate with respect to breakpoints, so this utility proc |
# lets us do this without duplicating this code everywhere. |
# |
|
proc delete_breakpoints {} { |
global gdb_prompt |
|
# we need a larger timeout value here or this thing just confuses |
# itself. May need a better implementation if possible. - guo |
# |
send_gdb "delete breakpoints\n" |
gdb_expect 100 { |
-re "Delete all breakpoints.*y or n.*$" { |
send_gdb "y\n"; |
exp_continue |
} |
-re "$gdb_prompt $" { # This happens if there were no breakpoints |
} |
timeout { perror "Delete all breakpoints in delete_breakpoints (timeout)" ; return } |
} |
send_gdb "info breakpoints\n" |
gdb_expect 100 { |
-re "No breakpoints or watchpoints..*$gdb_prompt $" {} |
-re "$gdb_prompt $" { perror "breakpoints not deleted" ; return } |
-re "Delete all breakpoints.*or n.*$" { |
send_gdb "y\n"; |
exp_continue |
} |
timeout { perror "info breakpoints (timeout)" ; return } |
} |
} |
|
|
# |
# Generic run command. |
# |
# The second pattern below matches up to the first newline *only*. |
# Using ``.*$'' could swallow up output that we attempt to match |
# elsewhere. |
# |
proc gdb_run_cmd {args} { |
global gdb_prompt |
|
if [target_info exists gdb_init_command] { |
send_gdb "[target_info gdb_init_command]\n"; |
gdb_expect 30 { |
-re "$gdb_prompt $" { } |
default { |
perror "gdb_init_command for target failed"; |
return; |
} |
} |
} |
|
if [target_info exists use_gdb_stub] { |
if [target_info exists gdb,do_reload_on_run] { |
if { [gdb_reload] != 0 } { |
return; |
} |
send_gdb "continue\n"; |
gdb_expect 60 { |
-re "Continu\[^\r\n\]*\[\r\n\]" {} |
default {} |
} |
return; |
} |
|
if [target_info exists gdb,start_symbol] { |
set start [target_info gdb,start_symbol]; |
} else { |
set start "start"; |
} |
send_gdb "jump *$start\n" |
set start_attempt 1; |
while { $start_attempt } { |
# Cap (re)start attempts at three to ensure that this loop |
# always eventually fails. Don't worry about trying to be |
# clever and not send a command when it has failed. |
if [expr $start_attempt > 3] { |
perror "Jump to start() failed (retry count exceeded)"; |
return; |
} |
set start_attempt [expr $start_attempt + 1]; |
gdb_expect 30 { |
-re "Continuing at \[^\r\n\]*\[\r\n\]" { |
set start_attempt 0; |
} |
-re "No symbol \"_start\" in current.*$gdb_prompt $" { |
perror "Can't find start symbol to run in gdb_run"; |
return; |
} |
-re "No symbol \"start\" in current.*$gdb_prompt $" { |
send_gdb "jump *_start\n"; |
} |
-re "No symbol.*context.*$gdb_prompt $" { |
set start_attempt 0; |
} |
-re "Line.* Jump anyway.*y or n. $" { |
send_gdb "y\n" |
} |
-re "The program is not being run.*$gdb_prompt $" { |
if { [gdb_reload] != 0 } { |
return; |
} |
send_gdb "jump *$start\n"; |
} |
timeout { |
perror "Jump to start() failed (timeout)"; |
return |
} |
} |
} |
if [target_info exists gdb_stub] { |
gdb_expect 60 { |
-re "$gdb_prompt $" { |
send_gdb "continue\n" |
} |
} |
} |
return |
} |
|
if [target_info exists gdb,do_reload_on_run] { |
if { [gdb_reload] != 0 } { |
return; |
} |
} |
send_gdb "run $args\n" |
# This doesn't work quite right yet. |
# Use -notransfer here so that test cases (like chng-sym.exp) |
# may test for additional start-up messages. |
gdb_expect 60 { |
-re "The program .* has been started already.*y or n. $" { |
send_gdb "y\n" |
exp_continue |
} |
-notransfer -re "Starting program: \[^\r\n\]*" {} |
} |
} |
|
# Generic start command. Return 0 if we could start the program, -1 |
# if we could not. |
|
proc gdb_start_cmd {args} { |
global gdb_prompt |
|
if [target_info exists gdb_init_command] { |
send_gdb "[target_info gdb_init_command]\n"; |
gdb_expect 30 { |
-re "$gdb_prompt $" { } |
default { |
perror "gdb_init_command for target failed"; |
return; |
} |
} |
} |
|
if [target_info exists use_gdb_stub] { |
return -1 |
} |
|
send_gdb "start $args\n" |
gdb_expect 60 { |
-re "The program .* has been started already.*y or n. $" { |
send_gdb "y\n" |
exp_continue |
} |
# Use -notransfer here so that test cases (like chng-sym.exp) |
# may test for additional start-up messages. |
-notransfer -re "Starting program: \[^\r\n\]*" { |
return 0 |
} |
} |
return -1 |
} |
|
# Set a breakpoint at FUNCTION. If there is an additional argument it is |
# a list of options; the supported options are allow-pending and temporary. |
|
proc gdb_breakpoint { function args } { |
global gdb_prompt |
global decimal |
|
set pending_response n |
if {[lsearch -exact [lindex $args 0] allow-pending] != -1} { |
set pending_response y |
} |
|
set break_command "break" |
if {[lsearch -exact [lindex $args 0] temporary] != -1} { |
set break_command "tbreak" |
} |
|
send_gdb "$break_command $function\n" |
# The first two regexps are what we get with -g, the third is without -g. |
gdb_expect 30 { |
-re "Breakpoint \[0-9\]* at .*: file .*, line $decimal.\r\n$gdb_prompt $" {} |
-re "Breakpoint \[0-9\]*: file .*, line $decimal.\r\n$gdb_prompt $" {} |
-re "Breakpoint \[0-9\]* at .*$gdb_prompt $" {} |
-re "Breakpoint \[0-9\]* \\(.*\\) pending.*$gdb_prompt $" { |
if {$pending_response == "n"} { |
fail "setting breakpoint at $function" |
return 0 |
} |
} |
-re "Make breakpoint pending.*y or \\\[n\\\]. $" { |
send_gdb "$pending_response\n" |
exp_continue |
} |
-re "$gdb_prompt $" { fail "setting breakpoint at $function" ; return 0 } |
timeout { fail "setting breakpoint at $function (timeout)" ; return 0 } |
} |
return 1; |
} |
|
# Set breakpoint at function and run gdb until it breaks there. |
# Since this is the only breakpoint that will be set, if it stops |
# at a breakpoint, we will assume it is the one we want. We can't |
# just compare to "function" because it might be a fully qualified, |
# single quoted C++ function specifier. If there's an additional argument, |
# pass it to gdb_breakpoint. |
|
proc runto { function args } { |
global gdb_prompt |
global decimal |
|
delete_breakpoints |
|
if ![gdb_breakpoint $function [lindex $args 0]] { |
return 0; |
} |
|
gdb_run_cmd |
|
# the "at foo.c:36" output we get with -g. |
# the "in func" output we get without -g. |
gdb_expect 30 { |
-re "Break.* at .*:$decimal.*$gdb_prompt $" { |
return 1 |
} |
-re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in .*$gdb_prompt $" { |
return 1 |
} |
-re "$gdb_prompt $" { |
fail "running to $function in runto" |
return 0 |
} |
timeout { |
fail "running to $function in runto (timeout)" |
return 0 |
} |
} |
return 1 |
} |
|
# |
# runto_main -- ask gdb to run until we hit a breakpoint at main. |
# The case where the target uses stubs has to be handled |
# specially--if it uses stubs, assuming we hit |
# breakpoint() and just step out of the function. |
# |
proc runto_main { } { |
global gdb_prompt |
global decimal |
|
if ![target_info exists gdb_stub] { |
return [runto main] |
} |
|
delete_breakpoints |
|
gdb_step_for_stub; |
|
return 1 |
} |
|
|
### Continue, and expect to hit a breakpoint. |
### Report a pass or fail, depending on whether it seems to have |
### worked. Use NAME as part of the test name; each call to |
### continue_to_breakpoint should use a NAME which is unique within |
### that test file. |
proc gdb_continue_to_breakpoint {name} { |
global gdb_prompt |
set full_name "continue to breakpoint: $name" |
|
send_gdb "continue\n" |
gdb_expect { |
-re "Breakpoint .* at .*\r\n$gdb_prompt $" { |
pass $full_name |
} |
-re ".*$gdb_prompt $" { |
fail $full_name |
} |
timeout { |
fail "$full_name (timeout)" |
} |
} |
} |
|
|
# gdb_internal_error_resync: |
# |
# Answer the questions GDB asks after it reports an internal error |
# until we get back to a GDB prompt. Decline to quit the debugging |
# session, and decline to create a core file. Return non-zero if the |
# resync succeeds. |
# |
# This procedure just answers whatever questions come up until it sees |
# a GDB prompt; it doesn't require you to have matched the input up to |
# any specific point. However, it only answers questions it sees in |
# the output itself, so if you've matched a question, you had better |
# answer it yourself before calling this. |
# |
# You can use this function thus: |
# |
# gdb_expect { |
# ... |
# -re ".*A problem internal to GDB has been detected" { |
# gdb_internal_error_resync |
# } |
# ... |
# } |
# |
proc gdb_internal_error_resync {} { |
global gdb_prompt |
|
set count 0 |
while {$count < 10} { |
gdb_expect { |
-re "Quit this debugging session\\? \\(y or n\\) $" { |
send_gdb "n\n" |
incr count |
} |
-re "Create a core file of GDB\\? \\(y or n\\) $" { |
send_gdb "n\n" |
incr count |
} |
-re "$gdb_prompt $" { |
# We're resynchronized. |
return 1 |
} |
timeout { |
perror "Could not resync from internal error (timeout)" |
return 0 |
} |
} |
} |
perror "Could not resync from internal error (resync count exceeded)" |
return 0 |
} |
|
|
# gdb_test_multiple COMMAND MESSAGE EXPECT_ARGUMENTS |
# Send a command to gdb; test the result. |
# |
# COMMAND is the command to execute, send to GDB with send_gdb. If |
# this is the null string no command is sent. |
# MESSAGE is a message to be printed with the built-in failure patterns |
# if one of them matches. If MESSAGE is empty COMMAND will be used. |
# EXPECT_ARGUMENTS will be fed to expect in addition to the standard |
# patterns. Pattern elements will be evaluated in the caller's |
# context; action elements will be executed in the caller's context. |
# Unlike patterns for gdb_test, these patterns should generally include |
# the final newline and prompt. |
# |
# Returns: |
# 1 if the test failed, according to a built-in failure pattern |
# 0 if only user-supplied patterns matched |
# -1 if there was an internal error. |
# |
# You can use this function thus: |
# |
# gdb_test_multiple "print foo" "test foo" { |
# -re "expected output 1" { |
# pass "print foo" |
# } |
# -re "expected output 2" { |
# fail "print foo" |
# } |
# } |
# |
# The standard patterns, such as "Program exited..." and "A problem |
# ...", all being implicitly appended to that list. |
# |
proc gdb_test_multiple { command message user_code } { |
global verbose |
global gdb_prompt |
global GDB |
upvar timeout timeout |
upvar expect_out expect_out |
|
if { $message == "" } { |
set message $command |
} |
|
# TCL/EXPECT WART ALERT |
# Expect does something very strange when it receives a single braced |
# argument. It splits it along word separators and performs substitutions. |
# This means that { "[ab]" } is evaluated as "[ab]", but { "\[ab\]" } is |
# evaluated as "\[ab\]". But that's not how TCL normally works; inside a |
# double-quoted list item, "\[ab\]" is just a long way of representing |
# "[ab]", because the backslashes will be removed by lindex. |
|
# Unfortunately, there appears to be no easy way to duplicate the splitting |
# that expect will do from within TCL. And many places make use of the |
# "\[0-9\]" construct, so we need to support that; and some places make use |
# of the "[func]" construct, so we need to support that too. In order to |
# get this right we have to substitute quoted list elements differently |
# from braced list elements. |
|
# We do this roughly the same way that Expect does it. We have to use two |
# lists, because if we leave unquoted newlines in the argument to uplevel |
# they'll be treated as command separators, and if we escape newlines |
# we mangle newlines inside of command blocks. This assumes that the |
# input doesn't contain a pattern which contains actual embedded newlines |
# at this point! |
|
regsub -all {\n} ${user_code} { } subst_code |
set subst_code [uplevel list $subst_code] |
|
set processed_code "" |
set patterns "" |
set expecting_action 0 |
foreach item $user_code subst_item $subst_code { |
if { $item == "-n" || $item == "-notransfer" || $item == "-nocase" } { |
lappend processed_code $item |
continue |
} |
if {$item == "-indices" || $item == "-re" || $item == "-ex"} { |
lappend processed_code $item |
continue |
} |
if { $expecting_action } { |
lappend processed_code "uplevel [list $item]" |
set expecting_action 0 |
# Cosmetic, no effect on the list. |
append processed_code "\n" |
continue |
} |
set expecting_action 1 |
lappend processed_code $subst_item |
if {$patterns != ""} { |
append patterns "; " |
} |
append patterns "\"$subst_item\"" |
} |
|
# Also purely cosmetic. |
regsub -all {\r} $patterns {\\r} patterns |
regsub -all {\n} $patterns {\\n} patterns |
|
if $verbose>2 then { |
send_user "Sending \"$command\" to gdb\n" |
send_user "Looking to match \"$patterns\"\n" |
send_user "Message is \"$message\"\n" |
} |
|
set result -1 |
set string "${command}\n"; |
if { $command != "" } { |
while { "$string" != "" } { |
set foo [string first "\n" "$string"]; |
set len [string length "$string"]; |
if { $foo < [expr $len - 1] } { |
set str [string range "$string" 0 $foo]; |
if { [send_gdb "$str"] != "" } { |
global suppress_flag; |
|
if { ! $suppress_flag } { |
perror "Couldn't send $command to GDB."; |
} |
fail "$message"; |
return $result; |
} |
# since we're checking if each line of the multi-line |
# command are 'accepted' by GDB here, |
# we need to set -notransfer expect option so that |
# command output is not lost for pattern matching |
# - guo |
gdb_expect 2 { |
-notransfer -re "\[\r\n\]" { verbose "partial: match" 3 } |
timeout { verbose "partial: timeout" 3 } |
} |
set string [string range "$string" [expr $foo + 1] end]; |
} else { |
break; |
} |
} |
if { "$string" != "" } { |
if { [send_gdb "$string"] != "" } { |
global suppress_flag; |
|
if { ! $suppress_flag } { |
perror "Couldn't send $command to GDB."; |
} |
fail "$message"; |
return $result; |
} |
} |
} |
|
if [target_info exists gdb,timeout] { |
set tmt [target_info gdb,timeout]; |
} else { |
if [info exists timeout] { |
set tmt $timeout; |
} else { |
global timeout; |
if [info exists timeout] { |
set tmt $timeout; |
} else { |
set tmt 60; |
} |
} |
} |
|
set code { |
-re ".*A problem internal to GDB has been detected" { |
fail "$message (GDB internal error)" |
gdb_internal_error_resync |
} |
-re "\\*\\*\\* DOSEXIT code.*" { |
if { $message != "" } { |
fail "$message"; |
} |
gdb_suppress_entire_file "GDB died"; |
set result -1; |
} |
} |
append code $processed_code |
append code { |
-re "Ending remote debugging.*$gdb_prompt $" { |
if ![isnative] then { |
warning "Can`t communicate to remote target." |
} |
gdb_exit |
gdb_start |
set result -1 |
} |
-re "Undefined\[a-z\]* command:.*$gdb_prompt $" { |
perror "Undefined command \"$command\"." |
fail "$message" |
set result 1 |
} |
-re "Ambiguous command.*$gdb_prompt $" { |
perror "\"$command\" is not a unique command name." |
fail "$message" |
set result 1 |
} |
-re "Program exited with code \[0-9\]+.*$gdb_prompt $" { |
if ![string match "" $message] then { |
set errmsg "$message (the program exited)" |
} else { |
set errmsg "$command (the program exited)" |
} |
fail "$errmsg" |
set result -1 |
} |
-re "EXIT code \[0-9\r\n\]+Program exited normally.*$gdb_prompt $" { |
if ![string match "" $message] then { |
set errmsg "$message (the program exited)" |
} else { |
set errmsg "$command (the program exited)" |
} |
fail "$errmsg" |
set result -1 |
} |
-re "The program is not being run.*$gdb_prompt $" { |
if ![string match "" $message] then { |
set errmsg "$message (the program is no longer running)" |
} else { |
set errmsg "$command (the program is no longer running)" |
} |
fail "$errmsg" |
set result -1 |
} |
-re "\r\n$gdb_prompt $" { |
if ![string match "" $message] then { |
fail "$message" |
} |
set result 1 |
} |
"<return>" { |
send_gdb "\n" |
perror "Window too small." |
fail "$message" |
set result -1 |
} |
-re "\\(y or n\\) " { |
send_gdb "n\n" |
perror "Got interactive prompt." |
fail "$message" |
set result -1 |
} |
eof { |
perror "Process no longer exists" |
if { $message != "" } { |
fail "$message" |
} |
return -1 |
} |
full_buffer { |
perror "internal buffer is full." |
fail "$message" |
set result -1 |
} |
timeout { |
if ![string match "" $message] then { |
fail "$message (timeout)" |
} |
set result 1 |
} |
} |
|
set result 0 |
set code [catch {gdb_expect $tmt $code} string] |
if {$code == 1} { |
global errorInfo errorCode; |
return -code error -errorinfo $errorInfo -errorcode $errorCode $string |
} elseif {$code == 2} { |
return -code return $string |
} elseif {$code == 3} { |
return |
} elseif {$code > 4} { |
return -code $code $string |
} |
return $result |
} |
|
# gdb_test COMMAND PATTERN MESSAGE QUESTION RESPONSE |
# Send a command to gdb; test the result. |
# |
# COMMAND is the command to execute, send to GDB with send_gdb. If |
# this is the null string no command is sent. |
# PATTERN is the pattern to match for a PASS, and must NOT include |
# the \r\n sequence immediately before the gdb prompt. |
# MESSAGE is an optional message to be printed. If this is |
# omitted, then the pass/fail messages use the command string as the |
# message. (If this is the empty string, then sometimes we don't |
# call pass or fail at all; I don't understand this at all.) |
# QUESTION is a question GDB may ask in response to COMMAND, like |
# "are you sure?" |
# RESPONSE is the response to send if QUESTION appears. |
# |
# Returns: |
# 1 if the test failed, |
# 0 if the test passes, |
# -1 if there was an internal error. |
# |
proc gdb_test { args } { |
global verbose |
global gdb_prompt |
global GDB |
upvar timeout timeout |
|
if [llength $args]>2 then { |
set message [lindex $args 2] |
} else { |
set message [lindex $args 0] |
} |
set command [lindex $args 0] |
set pattern [lindex $args 1] |
|
if [llength $args]==5 { |
set question_string [lindex $args 3]; |
set response_string [lindex $args 4]; |
} else { |
set question_string "^FOOBAR$" |
} |
|
return [gdb_test_multiple $command $message { |
-re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" { |
if ![string match "" $message] then { |
pass "$message" |
} |
} |
-re "(${question_string})$" { |
send_gdb "$response_string\n"; |
exp_continue; |
} |
}] |
} |
|
# Test that a command gives an error. For pass or fail, return |
# a 1 to indicate that more tests can proceed. However a timeout |
# is a serious error, generates a special fail message, and causes |
# a 0 to be returned to indicate that more tests are likely to fail |
# as well. |
|
proc test_print_reject { args } { |
global gdb_prompt |
global verbose |
|
if [llength $args]==2 then { |
set expectthis [lindex $args 1] |
} else { |
set expectthis "should never match this bogus string" |
} |
set sendthis [lindex $args 0] |
if $verbose>2 then { |
send_user "Sending \"$sendthis\" to gdb\n" |
send_user "Looking to match \"$expectthis\"\n" |
} |
send_gdb "$sendthis\n" |
#FIXME: Should add timeout as parameter. |
gdb_expect { |
-re "A .* in expression.*\\.*$gdb_prompt $" { |
pass "reject $sendthis" |
return 1 |
} |
-re "Invalid syntax in expression.*$gdb_prompt $" { |
pass "reject $sendthis" |
return 1 |
} |
-re "Junk after end of expression.*$gdb_prompt $" { |
pass "reject $sendthis" |
return 1 |
} |
-re "Invalid number.*$gdb_prompt $" { |
pass "reject $sendthis" |
return 1 |
} |
-re "Invalid character constant.*$gdb_prompt $" { |
pass "reject $sendthis" |
return 1 |
} |
-re "No symbol table is loaded.*$gdb_prompt $" { |
pass "reject $sendthis" |
return 1 |
} |
-re "No symbol .* in current context.*$gdb_prompt $" { |
pass "reject $sendthis" |
return 1 |
} |
-re "Unmatched single quote.*$gdb_prompt $" { |
pass "reject $sendthis" |
return 1 |
} |
-re "A character constant must contain at least one character.*$gdb_prompt $" { |
pass "reject $sendthis" |
return 1 |
} |
-re "$expectthis.*$gdb_prompt $" { |
pass "reject $sendthis" |
return 1 |
} |
-re ".*$gdb_prompt $" { |
fail "reject $sendthis" |
return 1 |
} |
default { |
fail "reject $sendthis (eof or timeout)" |
return 0 |
} |
} |
} |
|
# Given an input string, adds backslashes as needed to create a |
# regexp that will match the string. |
|
proc string_to_regexp {str} { |
set result $str |
regsub -all {[]*+.|()^$\[\\]} $str {\\&} result |
return $result |
} |
|
# Same as gdb_test, but the second parameter is not a regexp, |
# but a string that must match exactly. |
|
proc gdb_test_exact { args } { |
upvar timeout timeout |
|
set command [lindex $args 0] |
|
# This applies a special meaning to a null string pattern. Without |
# this, "$pattern\r\n$gdb_prompt $" will match anything, including error |
# messages from commands that should have no output except a new |
# prompt. With this, only results of a null string will match a null |
# string pattern. |
|
set pattern [lindex $args 1] |
if [string match $pattern ""] { |
set pattern [string_to_regexp [lindex $args 0]] |
} else { |
set pattern [string_to_regexp [lindex $args 1]] |
} |
|
# It is most natural to write the pattern argument with only |
# embedded \n's, especially if you are trying to avoid Tcl quoting |
# problems. But gdb_expect really wants to see \r\n in patterns. So |
# transform the pattern here. First transform \r\n back to \n, in |
# case some users of gdb_test_exact already do the right thing. |
regsub -all "\r\n" $pattern "\n" pattern |
regsub -all "\n" $pattern "\r\n" pattern |
if [llength $args]==3 then { |
set message [lindex $args 2] |
} else { |
set message $command |
} |
|
return [gdb_test $command $pattern $message] |
} |
|
proc gdb_reinitialize_dir { subdir } { |
global gdb_prompt |
|
if [is_remote host] { |
return ""; |
} |
send_gdb "dir\n" |
gdb_expect 60 { |
-re "Reinitialize source path to empty.*y or n. " { |
send_gdb "y\n" |
gdb_expect 60 { |
-re "Source directories searched.*$gdb_prompt $" { |
send_gdb "dir $subdir\n" |
gdb_expect 60 { |
-re "Source directories searched.*$gdb_prompt $" { |
verbose "Dir set to $subdir" |
} |
-re "$gdb_prompt $" { |
perror "Dir \"$subdir\" failed." |
} |
} |
} |
-re "$gdb_prompt $" { |
perror "Dir \"$subdir\" failed." |
} |
} |
} |
-re "$gdb_prompt $" { |
perror "Dir \"$subdir\" failed." |
} |
} |
} |
|
# |
# gdb_exit -- exit the GDB, killing the target program if necessary |
# |
proc default_gdb_exit {} { |
global GDB |
global GDBFLAGS |
global verbose |
global gdb_spawn_id; |
|
gdb_stop_suppressing_tests; |
|
if ![info exists gdb_spawn_id] { |
return; |
} |
|
verbose "Quitting $GDB $GDBFLAGS" |
|
if { [is_remote host] && [board_info host exists fileid] } { |
send_gdb "quit\n"; |
gdb_expect 10 { |
-re "y or n" { |
send_gdb "y\n"; |
exp_continue; |
} |
-re "DOSEXIT code" { } |
default { } |
} |
} |
|
if ![is_remote host] { |
remote_close host; |
} |
unset gdb_spawn_id |
} |
|
# Load a file into the debugger. |
# The return value is 0 for success, -1 for failure. |
# |
# This procedure also set the global variable GDB_FILE_CMD_DEBUG_INFO |
# to one of these values: |
# |
# debug file was loaded successfully and has debug information |
# nodebug file was loaded successfully and has no debug information |
# fail file was not loaded |
# |
# I tried returning this information as part of the return value, |
# but ran into a mess because of the many re-implementations of |
# gdb_load in config/*.exp. |
# |
# TODO: gdb.base/sepdebug.exp and gdb.stabs/weird.exp might be able to use |
# this if they can get more information set. |
|
proc gdb_file_cmd { arg } { |
global gdb_prompt |
global verbose |
global GDB |
global last_loaded_file |
|
set last_loaded_file $arg |
|
# Set whether debug info was found. |
# Default to "fail". |
global gdb_file_cmd_debug_info |
set gdb_file_cmd_debug_info "fail" |
|
if [is_remote host] { |
set arg [remote_download host $arg] |
if { $arg == "" } { |
perror "download failed" |
return -1 |
} |
} |
|
# The file command used to kill the remote target. For the benefit |
# of the testsuite, preserve this behavior. |
send_gdb "kill\n" |
gdb_expect 120 { |
-re "Kill the program being debugged. .y or n. $" { |
send_gdb "y\n" |
verbose "\t\tKilling previous program being debugged" |
exp_continue |
} |
-re "$gdb_prompt $" { |
# OK. |
} |
} |
|
send_gdb "file $arg\n" |
gdb_expect 120 { |
-re "Reading symbols from.*no debugging symbols found.*done.*$gdb_prompt $" { |
verbose "\t\tLoaded $arg into the $GDB with no debugging symbols" |
set gdb_file_cmd_debug_info "nodebug" |
return 0 |
} |
-re "Reading symbols from.*done.*$gdb_prompt $" { |
verbose "\t\tLoaded $arg into the $GDB" |
set gdb_file_cmd_debug_info "debug" |
return 0 |
} |
-re "Load new symbol table from \".*\".*y or n. $" { |
send_gdb "y\n" |
gdb_expect 120 { |
-re "Reading symbols from.*done.*$gdb_prompt $" { |
verbose "\t\tLoaded $arg with new symbol table into $GDB" |
set gdb_file_cmd_debug_info "debug" |
return 0 |
} |
timeout { |
perror "(timeout) Couldn't load $arg, other program already loaded." |
return -1 |
} |
} |
} |
-re "No such file or directory.*$gdb_prompt $" { |
perror "($arg) No such file or directory" |
return -1 |
} |
-re "$gdb_prompt $" { |
perror "couldn't load $arg into $GDB." |
return -1 |
} |
timeout { |
perror "couldn't load $arg into $GDB (timed out)." |
return -1 |
} |
eof { |
# This is an attempt to detect a core dump, but seems not to |
# work. Perhaps we need to match .* followed by eof, in which |
# gdb_expect does not seem to have a way to do that. |
perror "couldn't load $arg into $GDB (end of file)." |
return -1 |
} |
} |
} |
|
# |
# start gdb -- start gdb running, default procedure |
# |
# When running over NFS, particularly if running many simultaneous |
# tests on different hosts all using the same server, things can |
# get really slow. Give gdb at least 3 minutes to start up. |
# |
proc default_gdb_start { } { |
global verbose |
global GDB |
global GDBFLAGS |
global gdb_prompt |
global timeout |
global gdb_spawn_id; |
|
gdb_stop_suppressing_tests; |
|
verbose "Spawning $GDB -nw $GDBFLAGS" |
|
if [info exists gdb_spawn_id] { |
return 0; |
} |
|
if ![is_remote host] { |
if { [which $GDB] == 0 } then { |
perror "$GDB does not exist." |
exit 1 |
} |
} |
set res [remote_spawn host "$GDB -nw $GDBFLAGS [host_info gdb_opts]"]; |
if { $res < 0 || $res == "" } { |
perror "Spawning $GDB failed." |
return 1; |
} |
gdb_expect 360 { |
-re "\[\r\n\]$gdb_prompt $" { |
verbose "GDB initialized." |
} |
-re "$gdb_prompt $" { |
perror "GDB never initialized." |
return -1 |
} |
timeout { |
perror "(timeout) GDB never initialized after 10 seconds." |
remote_close host; |
return -1 |
} |
} |
set gdb_spawn_id -1; |
# force the height to "unlimited", so no pagers get used |
|
send_gdb "set height 0\n" |
gdb_expect 10 { |
-re "$gdb_prompt $" { |
verbose "Setting height to 0." 2 |
} |
timeout { |
warning "Couldn't set the height to 0" |
} |
} |
# force the width to "unlimited", so no wraparound occurs |
send_gdb "set width 0\n" |
gdb_expect 10 { |
-re "$gdb_prompt $" { |
verbose "Setting width to 0." 2 |
} |
timeout { |
warning "Couldn't set the width to 0." |
} |
} |
return 0; |
} |
|
# Return a 1 for configurations for which we don't even want to try to |
# test C++. |
|
proc skip_cplus_tests {} { |
if { [istarget "h8300-*-*"] } { |
return 1 |
} |
|
# The C++ IO streams are too large for HC11/HC12 and are thus not |
# available. The gdb C++ tests use them and don't compile. |
if { [istarget "m6811-*-*"] } { |
return 1 |
} |
if { [istarget "m6812-*-*"] } { |
return 1 |
} |
return 0 |
} |
|
# Return a 1 if I don't even want to try to test FORTRAN. |
|
proc skip_fortran_tests {} { |
return 0 |
} |
|
# Return a 1 if we should skip shared library tests. |
|
proc skip_shlib_tests {} { |
# Run the shared library tests on native systems. |
if {[isnative]} { |
return 0 |
} |
|
# An abbreviated list of remote targets where we should be able to |
# run shared library tests. |
if {([istarget *-*-linux*] |
|| [istarget *-*-*bsd*] |
|| [istarget *-*-solaris2*] |
|| [istarget arm*-*-symbianelf*] |
|| [istarget *-*-mingw*] |
|| [istarget *-*-cygwin*] |
|| [istarget *-*-pe*])} { |
return 0 |
} |
|
return 1 |
} |
|
# Run a test on the target to see if it supports vmx hardware. Return 0 if so, |
# 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite. |
|
proc skip_altivec_tests {} { |
global skip_vmx_tests_saved |
global srcdir subdir gdb_prompt |
|
# Use the cached value, if it exists. |
set me "skip_altivec_tests" |
if [info exists skip_vmx_tests_saved] { |
verbose "$me: returning saved $skip_vmx_tests_saved" 2 |
return $skip_vmx_tests_saved |
} |
|
# Some simulators are known to not support VMX instructions. |
if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } { |
verbose "$me: target known to not support VMX, returning 1" 2 |
return [set skip_vmx_tests_saved 1] |
} |
|
# Make sure we have a compiler that understands altivec. |
set compile_flags {debug nowarnings} |
if [get_compiler_info not-used] { |
warning "Could not get compiler info" |
return 1 |
} |
if [test_compiler_info gcc*] { |
set compile_flags "$compile_flags additional_flags=-maltivec" |
} elseif [test_compiler_info xlc*] { |
set compile_flags "$compile_flags additional_flags=-qaltivec" |
} else { |
verbose "Could not compile with altivec support, returning 1" 2 |
return 1 |
} |
|
# Set up, compile, and execute a test program containing VMX instructions. |
# Include the current process ID in the file names to prevent conflicts |
# with invocations for multiple testsuites. |
set src vmx[pid].c |
set exe vmx[pid].x |
|
set f [open $src "w"] |
puts $f "int main() {" |
puts $f "#ifdef __MACH__" |
puts $f " asm volatile (\"vor v0,v0,v0\");" |
puts $f "#else" |
puts $f " asm volatile (\"vor 0,0,0\");" |
puts $f "#endif" |
puts $f " return 0; }" |
close $f |
|
verbose "$me: compiling testfile $src" 2 |
set lines [gdb_compile $src $exe executable $compile_flags] |
file delete $src |
|
if ![string match "" $lines] then { |
verbose "$me: testfile compilation failed, returning 1" 2 |
return [set skip_vmx_tests_saved 1] |
} |
|
# No error message, compilation succeeded so now run it via gdb. |
|
gdb_exit |
gdb_start |
gdb_reinitialize_dir $srcdir/$subdir |
gdb_load "$exe" |
gdb_run_cmd |
gdb_expect { |
-re ".*Illegal instruction.*${gdb_prompt} $" { |
verbose -log "\n$me altivec hardware not detected" |
set skip_vmx_tests_saved 1 |
} |
-re ".*Program exited normally.*${gdb_prompt} $" { |
verbose -log "\n$me: altivec hardware detected" |
set skip_vmx_tests_saved 0 |
} |
default { |
warning "\n$me: default case taken" |
set skip_vmx_tests_saved 1 |
} |
} |
gdb_exit |
remote_file build delete $exe |
|
verbose "$me: returning $skip_vmx_tests_saved" 2 |
return $skip_vmx_tests_saved |
} |
|
# Skip all the tests in the file if you are not on an hppa running |
# hpux target. |
|
proc skip_hp_tests {} { |
eval set skip_hp [ expr ![isnative] || ![istarget "hppa*-*-hpux*"] ] |
verbose "Skip hp tests is $skip_hp" |
return $skip_hp |
} |
|
set compiler_info "unknown" |
set gcc_compiled 0 |
set hp_cc_compiler 0 |
set hp_aCC_compiler 0 |
|
# Figure out what compiler I am using. |
# |
# BINFILE is a "compiler information" output file. This implementation |
# does not use BINFILE. |
# |
# ARGS can be empty or "C++". If empty, "C" is assumed. |
# |
# There are several ways to do this, with various problems. |
# |
# [ gdb_compile -E $ifile -o $binfile.ci ] |
# source $binfile.ci |
# |
# Single Unix Spec v3 says that "-E -o ..." together are not |
# specified. And in fact, the native compiler on hp-ux 11 (among |
# others) does not work with "-E -o ...". Most targets used to do |
# this, and it mostly worked, because it works with gcc. |
# |
# [ catch "exec $compiler -E $ifile > $binfile.ci" exec_output ] |
# source $binfile.ci |
# |
# This avoids the problem with -E and -o together. This almost works |
# if the build machine is the same as the host machine, which is |
# usually true of the targets which are not gcc. But this code does |
# not figure which compiler to call, and it always ends up using the C |
# compiler. Not good for setting hp_aCC_compiler. Targets |
# hppa*-*-hpux* and mips*-*-irix* used to do this. |
# |
# [ gdb_compile -E $ifile > $binfile.ci ] |
# source $binfile.ci |
# |
# dejagnu target_compile says that it supports output redirection, |
# but the code is completely different from the normal path and I |
# don't want to sweep the mines from that path. So I didn't even try |
# this. |
# |
# set cppout [ gdb_compile $ifile "" preprocess $args quiet ] |
# eval $cppout |
# |
# I actually do this for all targets now. gdb_compile runs the right |
# compiler, and TCL captures the output, and I eval the output. |
# |
# Unfortunately, expect logs the output of the command as it goes by, |
# and dejagnu helpfully prints a second copy of it right afterwards. |
# So I turn off expect logging for a moment. |
# |
# [ gdb_compile $ifile $ciexe_file executable $args ] |
# [ remote_exec $ciexe_file ] |
# [ source $ci_file.out ] |
# |
# I could give up on -E and just do this. |
# I didn't get desperate enough to try this. |
# |
# -- chastain 2004-01-06 |
|
proc get_compiler_info {binfile args} { |
# For compiler.c and compiler.cc |
global srcdir |
|
# I am going to play with the log to keep noise out. |
global outdir |
global tool |
|
# These come from compiler.c or compiler.cc |
global compiler_info |
|
# Legacy global data symbols. |
global gcc_compiled |
global hp_cc_compiler |
global hp_aCC_compiler |
|
# Choose which file to preprocess. |
set ifile "${srcdir}/lib/compiler.c" |
if { [llength $args] > 0 && [lindex $args 0] == "c++" } { |
set ifile "${srcdir}/lib/compiler.cc" |
} |
|
# Run $ifile through the right preprocessor. |
# Toggle gdb.log to keep the compiler output out of the log. |
log_file |
set cppout [ gdb_compile "${ifile}" "" preprocess [list "$args" quiet] ] |
log_file -a "$outdir/$tool.log" |
|
# Eval the output. |
set unknown 0 |
foreach cppline [ split "$cppout" "\n" ] { |
if { [ regexp "^#" "$cppline" ] } { |
# line marker |
} elseif { [ regexp "^\[\n\r\t \]*$" "$cppline" ] } { |
# blank line |
} elseif { [ regexp "^\[\n\r\t \]*set\[\n\r\t \]" "$cppline" ] } { |
# eval this line |
verbose "get_compiler_info: $cppline" 2 |
eval "$cppline" |
} else { |
# unknown line |
verbose -log "get_compiler_info: $cppline" |
set unknown 1 |
} |
} |
|
# Reset to unknown compiler if any diagnostics happened. |
if { $unknown } { |
set compiler_info "unknown" |
} |
|
# Set the legacy symbols. |
set gcc_compiled 0 |
set hp_cc_compiler 0 |
set hp_aCC_compiler 0 |
if { [regexp "^gcc-1-" "$compiler_info" ] } { set gcc_compiled 1 } |
if { [regexp "^gcc-2-" "$compiler_info" ] } { set gcc_compiled 2 } |
if { [regexp "^gcc-3-" "$compiler_info" ] } { set gcc_compiled 3 } |
if { [regexp "^gcc-4-" "$compiler_info" ] } { set gcc_compiled 4 } |
if { [regexp "^gcc-5-" "$compiler_info" ] } { set gcc_compiled 5 } |
if { [regexp "^hpcc-" "$compiler_info" ] } { set hp_cc_compiler 1 } |
if { [regexp "^hpacc-" "$compiler_info" ] } { set hp_aCC_compiler 1 } |
|
# Log what happened. |
verbose -log "get_compiler_info: $compiler_info" |
|
# Most compilers will evaluate comparisons and other boolean |
# operations to 0 or 1. |
uplevel \#0 { set true 1 } |
uplevel \#0 { set false 0 } |
|
# Use of aCC results in boolean results being displayed as |
# "true" or "false" |
if { $hp_aCC_compiler } { |
uplevel \#0 { set true true } |
uplevel \#0 { set false false } |
} |
|
return 0; |
} |
|
proc test_compiler_info { {compiler ""} } { |
global compiler_info |
|
# if no arg, return the compiler_info string |
|
if [string match "" $compiler] { |
if [info exists compiler_info] { |
return $compiler_info |
} else { |
perror "No compiler info found." |
} |
} |
|
return [string match $compiler $compiler_info] |
} |
|
set gdb_wrapper_initialized 0 |
|
proc gdb_wrapper_init { args } { |
global gdb_wrapper_initialized; |
global gdb_wrapper_file; |
global gdb_wrapper_flags; |
|
if { $gdb_wrapper_initialized == 1 } { return; } |
|
if {[target_info exists needs_status_wrapper] && \ |
[target_info needs_status_wrapper] != "0"} { |
set result [build_wrapper "testglue.o"]; |
if { $result != "" } { |
set gdb_wrapper_file [lindex $result 0]; |
set gdb_wrapper_flags [lindex $result 1]; |
} else { |
warning "Status wrapper failed to build." |
} |
} |
set gdb_wrapper_initialized 1 |
} |
|
proc gdb_compile {source dest type options} { |
global GDB_TESTCASE_OPTIONS; |
global gdb_wrapper_file; |
global gdb_wrapper_flags; |
global gdb_wrapper_initialized; |
|
set outdir [file dirname $dest] |
|
# Add platform-specific options if a shared library was specified using |
# "shlib=librarypath" in OPTIONS. |
set new_options "" |
set shlib_found 0 |
foreach opt $options { |
if [regexp {^shlib=(.*)} $opt dummy_var shlib_name] { |
if [test_compiler_info "xlc-*"] { |
# IBM xlc compiler doesn't accept shared library named other |
# than .so: use "-Wl," to bypass this |
lappend source "-Wl,$shlib_name" |
} elseif { ([istarget "*-*-mingw*"] |
|| [istarget *-*-cygwin*] |
|| [istarget *-*-pe*])} { |
lappend source "${shlib_name}.a" |
} else { |
lappend source $shlib_name |
} |
if {$shlib_found == 0} { |
set shlib_found 1 |
if { ([test_compiler_info "gcc-*"] |
&& ([istarget "powerpc*-*-aix*"] |
|| [istarget "rs6000*-*-aix*"] )) } { |
lappend options "additional_flags=-L${outdir}" |
} elseif { [istarget "mips-sgi-irix*"] } { |
lappend options "additional_flags=-rpath ${outdir}" |
} |
} |
} elseif { $opt == "shlib_load" } { |
if { ([istarget "*-*-mingw*"] |
|| [istarget *-*-cygwin*] |
|| [istarget *-*-pe*] |
|| [istarget arm*-*-symbianelf*] |
|| [istarget hppa*-*-hpux*])} { |
# Do not need anything. |
} elseif { [istarget *-*-openbsd*] } { |
lappend new_options "additional_flags=-Wl,-rpath,${outdir}" |
} else { |
lappend new_options "libs=-ldl" |
lappend new_options "additional_flags=-Wl,-rpath,\\\$ORIGIN" |
} |
} else { |
lappend new_options $opt |
} |
} |
set options $new_options |
|
if [target_info exists gdb_stub] { |
set options2 { "additional_flags=-Dusestubs" } |
lappend options "libs=[target_info gdb_stub]"; |
set options [concat $options2 $options] |
} |
if [target_info exists is_vxworks] { |
set options2 { "additional_flags=-Dvxworks" } |
lappend options "libs=[target_info gdb_stub]"; |
set options [concat $options2 $options] |
} |
if [info exists GDB_TESTCASE_OPTIONS] { |
lappend options "additional_flags=$GDB_TESTCASE_OPTIONS"; |
} |
verbose "options are $options" |
verbose "source is $source $dest $type $options" |
|
if { $gdb_wrapper_initialized == 0 } { gdb_wrapper_init } |
|
if {[target_info exists needs_status_wrapper] && \ |
[target_info needs_status_wrapper] != "0" && \ |
[info exists gdb_wrapper_file]} { |
lappend options "libs=${gdb_wrapper_file}" |
lappend options "ldflags=${gdb_wrapper_flags}" |
} |
|
# Replace the "nowarnings" option with the appropriate additional_flags |
# to disable compiler warnings. |
set nowarnings [lsearch -exact $options nowarnings] |
if {$nowarnings != -1} { |
if [target_info exists gdb,nowarnings_flag] { |
set flag "additional_flags=[target_info gdb,nowarnings_flag]" |
} else { |
set flag "additional_flags=-w" |
} |
set options [lreplace $options $nowarnings $nowarnings $flag] |
} |
|
set result [target_compile $source $dest $type $options]; |
|
# Prune uninteresting compiler (and linker) output. |
regsub "Creating library file: \[^\r\n\]*\[\r\n\]+" $result "" result |
|
regsub "\[\r\n\]*$" "$result" "" result; |
regsub "^\[\r\n\]*" "$result" "" result; |
|
if { $result != "" && [lsearch $options quiet] == -1} { |
clone_output "gdb compile failed, $result" |
} |
return $result; |
} |
|
|
# This is just like gdb_compile, above, except that it tries compiling |
# against several different thread libraries, to see which one this |
# system has. |
proc gdb_compile_pthreads {source dest type options} { |
set built_binfile 0 |
set why_msg "unrecognized error" |
foreach lib {-lpthreads -lpthread -lthread} { |
# This kind of wipes out whatever libs the caller may have |
# set. Or maybe theirs will override ours. How infelicitous. |
set options_with_lib [concat $options [list libs=$lib quiet]] |
set ccout [gdb_compile $source $dest $type $options_with_lib] |
switch -regexp -- $ccout { |
".*no posix threads support.*" { |
set why_msg "missing threads include file" |
break |
} |
".*cannot open -lpthread.*" { |
set why_msg "missing runtime threads library" |
} |
".*Can't find library for -lpthread.*" { |
set why_msg "missing runtime threads library" |
} |
{^$} { |
pass "successfully compiled posix threads test case" |
set built_binfile 1 |
break |
} |
} |
} |
if {!$built_binfile} { |
unsupported "Couldn't compile $source: ${why_msg}" |
return -1 |
} |
} |
|
# Build a shared library from SOURCES. You must use get_compiler_info |
# first. |
|
proc gdb_compile_shlib {sources dest options} { |
set obj_options $options |
|
switch -glob [test_compiler_info] { |
"xlc-*" { |
lappend obj_options "additional_flags=-qpic" |
} |
"gcc-*" { |
if { !([istarget "powerpc*-*-aix*"] |
|| [istarget "rs6000*-*-aix*"] |
|| [istarget "*-*-cygwin*"] |
|| [istarget "*-*-mingw*"] |
|| [istarget "*-*-pe*"]) } { |
lappend obj_options "additional_flags=-fpic" |
} |
} |
default { |
switch -glob [istarget] { |
"hppa*-hp-hpux*" { |
lappend obj_options "additional_flags=+z" |
} |
"mips-sgi-irix*" { |
# Disable SGI compiler's implicit -Dsgi |
lappend obj_options "additional_flags=-Usgi" |
} |
default { |
# don't know what the compiler is... |
} |
} |
} |
} |
|
set outdir [file dirname $dest] |
set objects "" |
foreach source $sources { |
set sourcebase [file tail $source] |
if {[gdb_compile $source "${outdir}/${sourcebase}.o" object $obj_options] != ""} { |
return -1 |
} |
lappend objects ${outdir}/${sourcebase}.o |
} |
|
if [istarget "hppa*-*-hpux*"] { |
remote_exec build "ld -b ${objects} -o ${dest}" |
} else { |
set link_options $options |
if [test_compiler_info "xlc-*"] { |
lappend link_options "additional_flags=-qmkshrobj" |
} else { |
lappend link_options "additional_flags=-shared" |
|
if { ([istarget "*-*-mingw*"] |
|| [istarget *-*-cygwin*] |
|| [istarget *-*-pe*])} { |
lappend link_options "additional_flags=-Wl,--out-implib,${dest}.a" |
} |
} |
if {[gdb_compile "${objects}" "${dest}" executable $link_options] != ""} { |
return -1 |
} |
} |
} |
|
# This is just like gdb_compile_pthreads, above, except that we always add the |
# objc library for compiling Objective-C programs |
proc gdb_compile_objc {source dest type options} { |
set built_binfile 0 |
set why_msg "unrecognized error" |
foreach lib {-lobjc -lpthreads -lpthread -lthread solaris} { |
# This kind of wipes out whatever libs the caller may have |
# set. Or maybe theirs will override ours. How infelicitous. |
if { $lib == "solaris" } { |
set lib "-lpthread -lposix4" |
} |
if { $lib != "-lobjc" } { |
set lib "-lobjc $lib" |
} |
set options_with_lib [concat $options [list libs=$lib quiet]] |
set ccout [gdb_compile $source $dest $type $options_with_lib] |
switch -regexp -- $ccout { |
".*no posix threads support.*" { |
set why_msg "missing threads include file" |
break |
} |
".*cannot open -lpthread.*" { |
set why_msg "missing runtime threads library" |
} |
".*Can't find library for -lpthread.*" { |
set why_msg "missing runtime threads library" |
} |
{^$} { |
pass "successfully compiled objc with posix threads test case" |
set built_binfile 1 |
break |
} |
} |
} |
if {!$built_binfile} { |
unsupported "Couldn't compile $source: ${why_msg}" |
return -1 |
} |
} |
|
proc send_gdb { string } { |
global suppress_flag; |
if { $suppress_flag } { |
return "suppressed"; |
} |
return [remote_send host "$string"]; |
} |
|
# |
# |
|
proc gdb_expect { args } { |
if { [llength $args] == 2 && [lindex $args 0] != "-re" } { |
set gtimeout [lindex $args 0]; |
set expcode [list [lindex $args 1]]; |
} else { |
upvar timeout timeout; |
|
set expcode $args; |
if [target_info exists gdb,timeout] { |
if [info exists timeout] { |
if { $timeout < [target_info gdb,timeout] } { |
set gtimeout [target_info gdb,timeout]; |
} else { |
set gtimeout $timeout; |
} |
} else { |
set gtimeout [target_info gdb,timeout]; |
} |
} |
|
if ![info exists gtimeout] { |
global timeout; |
if [info exists timeout] { |
set gtimeout $timeout; |
} else { |
# Eeeeew. |
set gtimeout 60; |
} |
} |
} |
global suppress_flag; |
global remote_suppress_flag; |
if [info exists remote_suppress_flag] { |
set old_val $remote_suppress_flag; |
} |
if [info exists suppress_flag] { |
if { $suppress_flag } { |
set remote_suppress_flag 1; |
} |
} |
set code [catch \ |
{uplevel remote_expect host $gtimeout $expcode} string]; |
if [info exists old_val] { |
set remote_suppress_flag $old_val; |
} else { |
if [info exists remote_suppress_flag] { |
unset remote_suppress_flag; |
} |
} |
|
if {$code == 1} { |
global errorInfo errorCode; |
|
return -code error -errorinfo $errorInfo -errorcode $errorCode $string |
} elseif {$code == 2} { |
return -code return $string |
} elseif {$code == 3} { |
return |
} elseif {$code > 4} { |
return -code $code $string |
} |
} |
|
# gdb_expect_list MESSAGE SENTINEL LIST -- expect a sequence of outputs |
# |
# Check for long sequence of output by parts. |
# MESSAGE: is the test message to be printed with the test success/fail. |
# SENTINEL: Is the terminal pattern indicating that output has finished. |
# LIST: is the sequence of outputs to match. |
# If the sentinel is recognized early, it is considered an error. |
# |
# Returns: |
# 1 if the test failed, |
# 0 if the test passes, |
# -1 if there was an internal error. |
# |
proc gdb_expect_list {test sentinel list} { |
global gdb_prompt |
global suppress_flag |
set index 0 |
set ok 1 |
if { $suppress_flag } { |
set ok 0 |
unresolved "${test}" |
} |
while { ${index} < [llength ${list}] } { |
set pattern [lindex ${list} ${index}] |
set index [expr ${index} + 1] |
if { ${index} == [llength ${list}] } { |
if { ${ok} } { |
gdb_expect { |
-re "${pattern}${sentinel}" { |
# pass "${test}, pattern ${index} + sentinel" |
} |
-re "${sentinel}" { |
fail "${test} (pattern ${index} + sentinel)" |
set ok 0 |
} |
-re ".*A problem internal to GDB has been detected" { |
fail "${test} (GDB internal error)" |
set ok 0 |
gdb_internal_error_resync |
} |
timeout { |
fail "${test} (pattern ${index} + sentinel) (timeout)" |
set ok 0 |
} |
} |
} else { |
# unresolved "${test}, pattern ${index} + sentinel" |
} |
} else { |
if { ${ok} } { |
gdb_expect { |
-re "${pattern}" { |
# pass "${test}, pattern ${index}" |
} |
-re "${sentinel}" { |
fail "${test} (pattern ${index})" |
set ok 0 |
} |
-re ".*A problem internal to GDB has been detected" { |
fail "${test} (GDB internal error)" |
set ok 0 |
gdb_internal_error_resync |
} |
timeout { |
fail "${test} (pattern ${index}) (timeout)" |
set ok 0 |
} |
} |
} else { |
# unresolved "${test}, pattern ${index}" |
} |
} |
} |
if { ${ok} } { |
pass "${test}" |
return 0 |
} else { |
return 1 |
} |
} |
|
# |
# |
proc gdb_suppress_entire_file { reason } { |
global suppress_flag; |
|
warning "$reason\n"; |
set suppress_flag -1; |
} |
|
# |
# Set suppress_flag, which will cause all subsequent calls to send_gdb and |
# gdb_expect to fail immediately (until the next call to |
# gdb_stop_suppressing_tests). |
# |
proc gdb_suppress_tests { args } { |
global suppress_flag; |
|
return; # fnf - disable pending review of results where |
# testsuite ran better without this |
incr suppress_flag; |
|
if { $suppress_flag == 1 } { |
if { [llength $args] > 0 } { |
warning "[lindex $args 0]\n"; |
} else { |
warning "Because of previous failure, all subsequent tests in this group will automatically fail.\n"; |
} |
} |
} |
|
# |
# Clear suppress_flag. |
# |
proc gdb_stop_suppressing_tests { } { |
global suppress_flag; |
|
if [info exists suppress_flag] { |
if { $suppress_flag > 0 } { |
set suppress_flag 0; |
clone_output "Tests restarted.\n"; |
} |
} else { |
set suppress_flag 0; |
} |
} |
|
proc gdb_clear_suppressed { } { |
global suppress_flag; |
|
set suppress_flag 0; |
} |
|
proc gdb_start { } { |
default_gdb_start |
} |
|
proc gdb_exit { } { |
catch default_gdb_exit |
} |
|
# |
# gdb_load_cmd -- load a file into the debugger. |
# ARGS - additional args to load command. |
# return a -1 if anything goes wrong. |
# |
proc gdb_load_cmd { args } { |
global gdb_prompt |
|
if [target_info exists gdb_load_timeout] { |
set loadtimeout [target_info gdb_load_timeout] |
} else { |
set loadtimeout 1600 |
} |
send_gdb "load $args\n" |
verbose "Timeout is now $loadtimeout seconds" 2 |
gdb_expect $loadtimeout { |
-re "Loading section\[^\r\]*\r\n" { |
exp_continue |
} |
-re "Start address\[\r\]*\r\n" { |
exp_continue |
} |
-re "Transfer rate\[\r\]*\r\n" { |
exp_continue |
} |
-re "Memory access error\[^\r\]*\r\n" { |
perror "Failed to load program" |
return -1 |
} |
-re "$gdb_prompt $" { |
return 0 |
} |
-re "(.*)\r\n$gdb_prompt " { |
perror "Unexpected reponse from 'load' -- $expect_out(1,string)" |
return -1 |
} |
timeout { |
perror "Timed out trying to load $arg." |
return -1 |
} |
} |
return -1 |
} |
|
# gdb_download |
# |
# Copy a file to the remote target and return its target filename. |
# Schedule the file to be deleted at the end of this test. |
|
proc gdb_download { filename } { |
global cleanfiles |
|
set destname [remote_download target $filename] |
lappend cleanfiles $destname |
return $destname |
} |
|
# gdb_load_shlibs LIB... |
# |
# Copy the listed libraries to the target. |
|
proc gdb_load_shlibs { args } { |
if {![is_remote target]} { |
return |
} |
|
foreach file $args { |
gdb_download $file |
} |
|
# Even if the target supplies full paths for shared libraries, |
# they may not be paths for this system. |
gdb_test "set solib-search-path [file dirname [lindex $args 0]]" "" "" |
} |
|
# |
# gdb_load -- load a file into the debugger. |
# Many files in config/*.exp override this procedure. |
# |
proc gdb_load { arg } { |
return [gdb_file_cmd $arg] |
} |
|
# gdb_reload -- load a file into the target. Called before "running", |
# either the first time or after already starting the program once, |
# for remote targets. Most files that override gdb_load should now |
# override this instead. |
|
proc gdb_reload { } { |
# For the benefit of existing configurations, default to gdb_load. |
# Specifying no file defaults to the executable currently being |
# debugged. |
return [gdb_load ""] |
} |
|
proc gdb_continue { function } { |
global decimal |
|
return [gdb_test "continue" ".*Breakpoint $decimal, $function .*" "continue to $function"]; |
} |
|
proc default_gdb_init { args } { |
global gdb_wrapper_initialized |
global cleanfiles |
|
set cleanfiles {} |
|
gdb_clear_suppressed; |
|
# Make sure that the wrapper is rebuilt |
# with the appropriate multilib option. |
set gdb_wrapper_initialized 0 |
|
# Unlike most tests, we have a small number of tests that generate |
# a very large amount of output. We therefore increase the expect |
# buffer size to be able to contain the entire test output. |
match_max -d 30000 |
|
# We want to add the name of the TCL testcase to the PASS/FAIL messages. |
if { [llength $args] > 0 } { |
global pf_prefix |
|
set file [lindex $args 0]; |
|
set pf_prefix "[file tail [file dirname $file]]/[file tail $file]:"; |
} |
global gdb_prompt; |
if [target_info exists gdb_prompt] { |
set gdb_prompt [target_info gdb_prompt]; |
} else { |
set gdb_prompt "\\(gdb\\)" |
} |
} |
|
proc gdb_init { args } { |
return [eval default_gdb_init $args]; |
} |
|
proc gdb_finish { } { |
global cleanfiles |
|
# Exit first, so that the files are no longer in use. |
gdb_exit |
|
if { [llength $cleanfiles] > 0 } { |
eval remote_file target delete $cleanfiles |
set cleanfiles {} |
} |
} |
|
global debug_format |
set debug_format "unknown" |
|
# Run the gdb command "info source" and extract the debugging format |
# information from the output and save it in debug_format. |
|
proc get_debug_format { } { |
global gdb_prompt |
global verbose |
global expect_out |
global debug_format |
|
set debug_format "unknown" |
send_gdb "info source\n" |
gdb_expect 10 { |
-re "Compiled with (.*) debugging format.\r\n.*$gdb_prompt $" { |
set debug_format $expect_out(1,string) |
verbose "debug format is $debug_format" |
return 1; |
} |
-re "No current source file.\r\n$gdb_prompt $" { |
perror "get_debug_format used when no current source file" |
return 0; |
} |
-re "$gdb_prompt $" { |
warning "couldn't check debug format (no valid response)." |
return 1; |
} |
timeout { |
warning "couldn't check debug format (timed out)." |
return 1; |
} |
} |
} |
|
# Return true if FORMAT matches the debug format the current test was |
# compiled with. FORMAT is a shell-style globbing pattern; it can use |
# `*', `[...]', and so on. |
# |
# This function depends on variables set by `get_debug_format', above. |
|
proc test_debug_format {format} { |
global debug_format |
|
return [expr [string match $format $debug_format] != 0] |
} |
|
# Like setup_xfail, but takes the name of a debug format (DWARF 1, |
# COFF, stabs, etc). If that format matches the format that the |
# current test was compiled with, then the next test is expected to |
# fail for any target. Returns 1 if the next test or set of tests is |
# expected to fail, 0 otherwise (or if it is unknown). Must have |
# previously called get_debug_format. |
proc setup_xfail_format { format } { |
set ret [test_debug_format $format]; |
|
if {$ret} then { |
setup_xfail "*-*-*" |
} |
return $ret; |
} |
|
proc gdb_step_for_stub { } { |
global gdb_prompt; |
|
if ![target_info exists gdb,use_breakpoint_for_stub] { |
if [target_info exists gdb_stub_step_command] { |
set command [target_info gdb_stub_step_command]; |
} else { |
set command "step"; |
} |
send_gdb "${command}\n"; |
set tries 0; |
gdb_expect 60 { |
-re "(main.* at |.*in .*start).*$gdb_prompt" { |
return; |
} |
-re ".*$gdb_prompt" { |
incr tries; |
if { $tries == 5 } { |
fail "stepping out of breakpoint function"; |
return; |
} |
send_gdb "${command}\n"; |
exp_continue; |
} |
default { |
fail "stepping out of breakpoint function"; |
return; |
} |
} |
} |
send_gdb "where\n"; |
gdb_expect { |
-re "main\[^\r\n\]*at \(\[^:]+\):\(\[0-9\]+\)" { |
set file $expect_out(1,string); |
set linenum [expr $expect_out(2,string) + 1]; |
set breakplace "${file}:${linenum}"; |
} |
default {} |
} |
send_gdb "break ${breakplace}\n"; |
gdb_expect 60 { |
-re "Breakpoint (\[0-9\]+) at.*$gdb_prompt" { |
set breakpoint $expect_out(1,string); |
} |
-re "Breakpoint (\[0-9\]+): file.*$gdb_prompt" { |
set breakpoint $expect_out(1,string); |
} |
default {} |
} |
send_gdb "continue\n"; |
gdb_expect 60 { |
-re "Breakpoint ${breakpoint},.*$gdb_prompt" { |
gdb_test "delete $breakpoint" ".*" ""; |
return; |
} |
default {} |
} |
} |
|
# gdb_get_line_number TEXT [FILE] |
# |
# Search the source file FILE, and return the line number of the |
# first line containing TEXT. If no match is found, return -1. |
# |
# TEXT is a string literal, not a regular expression. |
# |
# The default value of FILE is "$srcdir/$subdir/$srcfile". If FILE is |
# specified, and does not start with "/", then it is assumed to be in |
# "$srcdir/$subdir". This is awkward, and can be fixed in the future, |
# by changing the callers and the interface at the same time. |
# In particular: gdb.base/break.exp, gdb.base/condbreak.exp, |
# gdb.base/ena-dis-br.exp. |
# |
# Use this function to keep your test scripts independent of the |
# exact line numbering of the source file. Don't write: |
# |
# send_gdb "break 20" |
# |
# This means that if anyone ever edits your test's source file, |
# your test could break. Instead, put a comment like this on the |
# source file line you want to break at: |
# |
# /* breakpoint spot: frotz.exp: test name */ |
# |
# and then write, in your test script (which we assume is named |
# frotz.exp): |
# |
# send_gdb "break [gdb_get_line_number "frotz.exp: test name"]\n" |
# |
# (Yes, Tcl knows how to handle the nested quotes and brackets. |
# Try this: |
# $ tclsh |
# % puts "foo [lindex "bar baz" 1]" |
# foo baz |
# % |
# Tcl is quite clever, for a little stringy language.) |
# |
# === |
# |
# The previous implementation of this procedure used the gdb search command. |
# This version is different: |
# |
# . It works with MI, and it also works when gdb is not running. |
# |
# . It operates on the build machine, not the host machine. |
# |
# . For now, this implementation fakes a current directory of |
# $srcdir/$subdir to be compatible with the old implementation. |
# This will go away eventually and some callers will need to |
# be changed. |
# |
# . The TEXT argument is literal text and matches literally, |
# not a regular expression as it was before. |
# |
# . State changes in gdb, such as changing the current file |
# and setting $_, no longer happen. |
# |
# After a bit of time we can forget about the differences from the |
# old implementation. |
# |
# --chastain 2004-08-05 |
|
proc gdb_get_line_number { text { file "" } } { |
global srcdir |
global subdir |
global srcfile |
|
if { "$file" == "" } then { |
set file "$srcfile" |
} |
if { ! [regexp "^/" "$file"] } then { |
set file "$srcdir/$subdir/$file" |
} |
|
if { [ catch { set fd [open "$file"] } message ] } then { |
perror "$message" |
return -1 |
} |
|
set found -1 |
for { set line 1 } { 1 } { incr line } { |
if { [ catch { set nchar [gets "$fd" body] } message ] } then { |
perror "$message" |
return -1 |
} |
if { $nchar < 0 } then { |
break |
} |
if { [string first "$text" "$body"] >= 0 } then { |
set found $line |
break |
} |
} |
|
if { [ catch { close "$fd" } message ] } then { |
perror "$message" |
return -1 |
} |
|
return $found |
} |
|
# gdb_continue_to_end: |
# The case where the target uses stubs has to be handled specially. If a |
# stub is used, we set a breakpoint at exit because we cannot rely on |
# exit() behavior of a remote target. |
# |
# mssg is the error message that gets printed. |
|
proc gdb_continue_to_end {mssg} { |
if [target_info exists use_gdb_stub] { |
if {![gdb_breakpoint "exit"]} { |
return 0 |
} |
gdb_test "continue" "Continuing..*Breakpoint .*exit.*" \ |
"continue until exit at $mssg" |
} else { |
# Continue until we exit. Should not stop again. |
# Don't bother to check the output of the program, that may be |
# extremely tough for some remote systems. |
gdb_test "continue"\ |
"Continuing.\[\r\n0-9\]+(... EXIT code 0\[\r\n\]+|Program exited normally\\.).*"\ |
"continue until exit at $mssg" |
} |
} |
|
proc rerun_to_main {} { |
global gdb_prompt |
|
if [target_info exists use_gdb_stub] { |
gdb_run_cmd |
gdb_expect { |
-re ".*Breakpoint .*main .*$gdb_prompt $"\ |
{pass "rerun to main" ; return 0} |
-re "$gdb_prompt $"\ |
{fail "rerun to main" ; return 0} |
timeout {fail "(timeout) rerun to main" ; return 0} |
} |
} else { |
send_gdb "run\n" |
gdb_expect { |
-re "The program .* has been started already.*y or n. $" { |
send_gdb "y\n" |
exp_continue |
} |
-re "Starting program.*$gdb_prompt $"\ |
{pass "rerun to main" ; return 0} |
-re "$gdb_prompt $"\ |
{fail "rerun to main" ; return 0} |
timeout {fail "(timeout) rerun to main" ; return 0} |
} |
} |
} |
|
# Print a message and return true if a test should be skipped |
# due to lack of floating point suport. |
|
proc gdb_skip_float_test { msg } { |
if [target_info exists gdb,skip_float_tests] { |
verbose "Skipping test '$msg': no float tests."; |
return 1; |
} |
return 0; |
} |
|
# Print a message and return true if a test should be skipped |
# due to lack of stdio support. |
|
proc gdb_skip_stdio_test { msg } { |
if [target_info exists gdb,noinferiorio] { |
verbose "Skipping test '$msg': no inferior i/o."; |
return 1; |
} |
return 0; |
} |
|
proc gdb_skip_bogus_test { msg } { |
return 0; |
} |
|
# Return true if a test should be skipped due to lack of XML support |
# in the host GDB. |
|
proc gdb_skip_xml_test { } { |
global gdb_prompt |
global srcdir |
global xml_missing_cached |
|
if {[info exists xml_missing_cached]} { |
return $xml_missing_cached |
} |
|
gdb_start |
set xml_missing_cached 0 |
gdb_test_multiple "set tdesc filename ${srcdir}/gdb.xml/trivial.xml" "" { |
-re ".*XML support was disabled at compile time.*$gdb_prompt $" { |
set xml_missing_cached 1 |
} |
-re ".*$gdb_prompt $" { } |
} |
gdb_exit |
return $xml_missing_cached |
} |
|
# Note: the procedure gdb_gnu_strip_debug will produce an executable called |
# ${binfile}.dbglnk, which is just like the executable ($binfile) but without |
# the debuginfo. Instead $binfile has a .gnu_debuglink section which contains |
# the name of a debuginfo only file. This file will be stored in the |
# gdb.base/.debug subdirectory. |
|
# Functions for separate debug info testing |
|
# starting with an executable: |
# foo --> original executable |
|
# at the end of the process we have: |
# foo.stripped --> foo w/o debug info |
# .debug/foo.debug --> foo's debug info |
# foo --> like foo, but with a new .gnu_debuglink section pointing to foo.debug. |
|
# Return the name of the file in which we should stor EXEC's separated |
# debug info. EXEC contains the full path. |
proc separate_debug_filename { exec } { |
|
# In a .debug subdirectory off the same directory where the testcase |
# executable is going to be. Something like: |
# <your-path>/gdb/testsuite/gdb.base/.debug/blah.debug. |
# This is the default location where gdb expects to findi |
# the debug info file. |
|
set exec_dir [file dirname $exec] |
set exec_file [file tail $exec] |
set debug_dir [file join $exec_dir ".debug"] |
set debug_file [file join $debug_dir "${exec_file}.debug"] |
|
return $debug_file |
} |
|
# Return the build-id hex string (usually 160 bits as 40 hex characters) |
# converted to the form: .build-id/ab/cdef1234...89.debug |
# Return "" if no build-id found. |
proc build_id_debug_filename_get { exec } { |
set tmp "${exec}-tmp" |
set objcopy_program [transform objcopy] |
|
set result [catch "exec $objcopy_program -j .note.gnu.build-id -O binary $exec $tmp" output] |
verbose "result is $result" |
verbose "output is $output" |
if {$result == 1} { |
return "" |
} |
set fi [open $tmp] |
fconfigure $fi -translation binary |
# Skip the NOTE header. |
read $fi 16 |
set data [read $fi] |
close $fi |
file delete $tmp |
if ![string compare $data ""] then { |
return "" |
} |
# Convert it to hex. |
binary scan $data H* data |
set data [regsub {^..} $data {\0/}] |
return ".build-id/${data}.debug"; |
} |
|
# Create stripped files for DEST, replacing it. If ARGS is passed, it is a |
# list of optional flags. The only currently supported flag is no-main, |
# which removes the symbol entry for main from the separate debug file. |
|
proc gdb_gnu_strip_debug { dest args } { |
|
set debug_file [separate_debug_filename $dest] |
set strip_to_file_program [transform strip] |
set objcopy_program [transform objcopy] |
|
# Make sure the directory that will hold the separated debug |
# info actually exists. |
set debug_dir [file dirname $debug_file] |
if {! [file isdirectory $debug_dir]} { |
file mkdir $debug_dir |
} |
|
set debug_link [file tail $debug_file] |
set stripped_file "${dest}.stripped" |
|
# Get rid of the debug info, and store result in stripped_file |
# something like gdb/testsuite/gdb.base/blah.stripped. |
set result [catch "exec $strip_to_file_program --strip-debug ${dest} -o ${stripped_file}" output] |
verbose "result is $result" |
verbose "output is $output" |
if {$result == 1} { |
return 1 |
} |
|
# Get rid of everything but the debug info, and store result in debug_file |
# This will be in the .debug subdirectory, see above. |
set result [catch "exec $strip_to_file_program --only-keep-debug ${dest} -o ${debug_file}" output] |
verbose "result is $result" |
verbose "output is $output" |
if {$result == 1} { |
return 1 |
} |
|
# If no-main is passed, strip the symbol for main from the separate |
# file. This is to simulate the behavior of elfutils's eu-strip, which |
# leaves the symtab in the original file only. There's no way to get |
# objcopy or strip to remove the symbol table without also removing the |
# debugging sections, so this is as close as we can get. |
if { [llength $args] == 1 && [lindex $args 0] == "no-main" } { |
set result [catch "exec $objcopy_program -N main ${debug_file} ${debug_file}-tmp" output] |
verbose "result is $result" |
verbose "output is $output" |
if {$result == 1} { |
return 1 |
} |
file delete "${debug_file}" |
file rename "${debug_file}-tmp" "${debug_file}" |
} |
|
# Link the two previous output files together, adding the .gnu_debuglink |
# section to the stripped_file, containing a pointer to the debug_file, |
# save the new file in dest. |
# This will be the regular executable filename, in the usual location. |
set result [catch "exec $objcopy_program --add-gnu-debuglink=${debug_file} ${stripped_file} ${dest}" output] |
verbose "result is $result" |
verbose "output is $output" |
if {$result == 1} { |
return 1 |
} |
|
return 0 |
} |
|
# Test the output of GDB_COMMAND matches the pattern obtained |
# by concatenating all elements of EXPECTED_LINES. This makes |
# it possible to split otherwise very long string into pieces. |
# If third argument is not empty, it's used as the name of the |
# test to be printed on pass/fail. |
proc help_test_raw { gdb_command expected_lines args } { |
set message $gdb_command |
if [llength $args]>0 then { |
set message [lindex $args 0] |
} |
set expected_output [join $expected_lines ""] |
gdb_test "${gdb_command}" "${expected_output}" $message |
} |
|
# Test the output of "help COMMNAD_CLASS". EXPECTED_INITIAL_LINES |
# are regular expressions that should match the beginning of output, |
# before the list of commands in that class. The presence of |
# command list and standard epilogue will be tested automatically. |
proc test_class_help { command_class expected_initial_lines args } { |
set l_stock_body { |
"List of commands\:.*\[\r\n\]+" |
"Type \"help\" followed by command name for full documentation\.\[\r\n\]+" |
"Type \"apropos word\" to search for commands related to \"word\"\.[\r\n\]+" |
"Command name abbreviations are allowed if unambiguous\." |
} |
set l_entire_body [concat $expected_initial_lines $l_stock_body] |
|
eval [list help_test_raw "help ${command_class}" $l_entire_body] $args |
} |
|
# COMMAND_LIST should have either one element -- command to test, or |
# two elements -- abbreviated command to test, and full command the first |
# element is abbreviation of. |
# The command must be a prefix command. EXPECTED_INITIAL_LINES |
# are regular expressions that should match the beginning of output, |
# before the list of subcommands. The presence of |
# subcommand list and standard epilogue will be tested automatically. |
proc test_prefix_command_help { command_list expected_initial_lines args } { |
set command [lindex $command_list 0] |
if {[llength $command_list]>1} { |
set full_command [lindex $command_list 1] |
} else { |
set full_command $command |
} |
# Use 'list' and not just {} because we want variables to |
# be expanded in this list. |
set l_stock_body [list\ |
"List of $full_command subcommands\:.*\[\r\n\]+"\ |
"Type \"help $full_command\" followed by $full_command subcommand name for full documentation\.\[\r\n\]+"\ |
"Type \"apropos word\" to search for commands related to \"word\"\.\[\r\n\]+"\ |
"Command name abbreviations are allowed if unambiguous\."] |
set l_entire_body [concat $expected_initial_lines $l_stock_body] |
if {[llength $args]>0} { |
help_test_raw "help ${command}" $l_entire_body [lindex $args 0] |
} else { |
help_test_raw "help ${command}" $l_entire_body |
} |
} |
/gdbserver-support.exp
0,0 → 1,308
# Copyright 2000, 2002, 2003, 2004, 2005, 2006, 2007, 2008 |
# 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/>. |
|
# This file is based on config/gdbserver.exp, which was written by |
# Michael Snyder (msnyder@redhat.com). |
|
# |
# To be addressed or set in your baseboard config file: |
# |
# set_board_info gdb_protocol "remote" |
# Unles you have a gdbserver that uses a different protocol... |
# |
# set_board_info gdb_server_prog |
# This will be the path to the gdbserver program you want to test. |
# Defaults to "gdbserver". |
# |
# set_board_info sockethost |
# The name of the host computer whose socket is being used. |
# Defaults to "localhost". Note: old gdbserver requires |
# that you define this, but libremote/gdbserver does not. |
# |
# set_board_info gdb,socketport |
# Port id to use for socket connection. If not set explicitly, |
# it will start at "2345" and increment for each use. |
# |
|
# |
# gdb_target_cmd |
# Send gdb the "target" command |
# |
proc gdb_target_cmd { targetname serialport } { |
global gdb_prompt |
|
set serialport_re [string_to_regexp $serialport] |
for {set i 1} {$i <= 3} {incr i} { |
send_gdb "target $targetname $serialport\n" |
gdb_expect 60 { |
-re "A program is being debugged already.*ill it.*y or n. $" { |
send_gdb "y\n" |
exp_continue |
} |
-re "unknown host.*$gdb_prompt" { |
verbose "Couldn't look up $serialport" |
} |
-re "Couldn't establish connection to remote.*$gdb_prompt $" { |
verbose "Connection failed" |
} |
-re "Remote MIPS debugging.*$gdb_prompt" { |
verbose "Set target to $targetname" |
return 0 |
} |
-re "Remote debugging using .*$serialport_re.*$gdb_prompt $" { |
verbose "Set target to $targetname" |
return 0 |
} |
-re "Remote target $targetname connected to.*$gdb_prompt $" { |
verbose "Set target to $targetname" |
return 0 |
} |
-re "Connected to.*$gdb_prompt $" { |
verbose "Set target to $targetname" |
return 0 |
} |
-re "Ending remote.*$gdb_prompt $" { } |
-re "Connection refused.*$gdb_prompt $" { |
verbose "Connection refused by remote target. Pausing, and trying again." |
sleep 30 |
continue |
} |
-re "Timeout reading from remote system.*$gdb_prompt $" { |
verbose "Got timeout error from gdb." |
} |
-notransfer -re "Remote debugging using .*\r\n> $" { |
# We got an unexpected prompt while creating the target. |
# Leave it there for the test to diagnose. |
return 1 |
} |
timeout { |
send_gdb "" |
break |
} |
} |
} |
return 1 |
} |
|
|
global portnum |
set portnum "2345" |
|
# Locate the gdbserver binary. Returns "" if gdbserver could not be found. |
|
proc find_gdbserver { } { |
global GDB |
|
if [target_info exists gdb_server_prog] { |
return [target_info gdb_server_prog] |
} |
|
set gdbserver "${GDB}server" |
if { [file isdirectory $gdbserver] } { |
append gdbserver "/gdbserver" |
} |
|
if { [file executable $gdbserver] } { |
return $gdbserver |
} |
|
return "" |
} |
|
# Return non-zero if we should skip gdbserver-specific tests. |
|
proc skip_gdbserver_tests { } { |
if { [find_gdbserver] == "" } { |
return 1 |
} |
|
return 0 |
} |
|
# Download the currently loaded program to the target if necessary. |
# Return the target system filename. |
|
proc gdbserver_download { } { |
global gdbserver_host_exec |
global gdbserver_host_mtime |
global gdbserver_server_exec |
global last_loaded_file |
|
set host_exec $last_loaded_file |
|
# If we already downloaded a file to the target, see if we can reuse it. |
set reuse 0 |
if { [info exists gdbserver_server_exec] } { |
set reuse 1 |
|
# If the file has changed, we can not. |
if { $host_exec != $gdbserver_host_exec } { |
set reuse 0 |
} |
|
# If the mtime has changed, we can not. |
if { [file mtime $host_exec] != $gdbserver_host_mtime } { |
set reuse 0 |
} |
} |
|
if { $reuse == 0 } { |
set gdbserver_host_exec $host_exec |
set gdbserver_host_mtime [file mtime $host_exec] |
if [is_remote target] { |
set gdbserver_server_exec [gdb_download $host_exec] |
} else { |
set gdbserver_server_exec $host_exec |
} |
} |
|
return $gdbserver_server_exec |
} |
|
# Start a gdbserver process with initial OPTIONS and trailing ARGUMENTS. |
# The port will be filled in between them automatically. |
# |
# Returns the target protocol and socket to connect to. |
|
proc gdbserver_start { options arguments } { |
global portnum |
|
# Port id -- either specified in baseboard file, or managed here. |
if [target_info exists gdb,socketport] { |
set portnum [target_info gdb,socketport] |
} else { |
# Bump the port number to avoid conflicts with hung ports. |
incr portnum |
} |
|
# Extract the local and remote host ids from the target board struct. |
if [target_info exists sockethost] { |
set debughost [target_info sockethost] |
} else { |
set debughost "localhost:" |
} |
|
# Extract the protocol |
if [target_info exists gdb_protocol] { |
set protocol [target_info gdb_protocol] |
} else { |
set protocol "remote" |
} |
|
set gdbserver [find_gdbserver] |
|
# Export the host:port pair. |
set gdbport $debughost$portnum |
|
# Fire off the debug agent. |
set gdbserver_command "$gdbserver" |
if { $options != "" } { |
append gdbserver_command " $options" |
} |
append gdbserver_command " :$portnum" |
if { $arguments != "" } { |
append gdbserver_command " $arguments" |
} |
|
set server_spawn_id [remote_spawn target $gdbserver_command] |
|
# Wait for the server to open its TCP socket, so that GDB can connect. |
expect { |
-i $server_spawn_id |
-notransfer |
-re "Listening on" { } |
} |
|
# We can't just call close, because if gdbserver is local then that means |
# that it will get a SIGHUP. Doing it this way could also allow us to |
# get at the inferior's input or output if necessary, and means that we |
# don't need to redirect output. |
expect_background { |
-i $server_spawn_id |
full_buffer { } |
eof { |
# The spawn ID is already closed now (but not yet waited for). |
wait -i $expect_out(spawn_id) |
} |
} |
|
return [list $protocol $gdbport] |
} |
|
# Start a gdbserver process running SERVER_EXEC, and connect GDB |
# to it. CHILD_ARGS are passed to the inferior. |
# |
# Returns the target protocol and socket to connect to. |
|
proc gdbserver_spawn { child_args } { |
set target_exec [gdbserver_download] |
|
# Fire off the debug agent. This flavour of gdbserver takes as |
# arguments the port information, the name of the executable file to |
# be debugged, and any arguments. |
set arguments "$target_exec" |
if { $child_args != "" } { |
append arguments " $child_args" |
} |
return [gdbserver_start "" $arguments] |
} |
|
# Start a gdbserver process running HOST_EXEC and pass CHILD_ARGS |
# to it. Return 0 on success, or non-zero on failure. |
|
proc gdbserver_run { child_args } { |
global gdbserver_protocol |
global gdbserver_gdbport |
|
# Kill anything running before we try to start gdbserver, in case |
# we are sharing a serial connection. |
global gdb_prompt |
send_gdb "kill\n" |
gdb_expect 120 { |
-re "Kill the program being debugged. .y or n. $" { |
send_gdb "y\n" |
verbose "\t\tKilling previous program being debugged" |
exp_continue |
} |
-re "$gdb_prompt $" { |
# OK. |
} |
} |
|
set res [gdbserver_spawn $child_args] |
set gdbserver_protocol [lindex $res 0] |
set gdbserver_gdbport [lindex $res 1] |
|
return [gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport] |
} |
|
# Reconnect to the previous gdbserver session. |
|
proc gdbserver_reconnect { } { |
global gdbserver_protocol |
global gdbserver_gdbport |
|
return [gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport] |
} |
|
# Start and connect to a gdbserver in extended mode. |
proc gdbserver_start_extended { } { |
set res [gdbserver_start "--multi" ""] |
set gdbserver_protocol "extended-[lindex $res 0]" |
set gdbserver_gdbport [lindex $res 1] |
|
return [gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport] |
} |
/emc-support.exp
0,0 → 1,223
proc gdb_emc_readvar { varname } { |
global gdb_prompt; |
|
set result -1; |
send_gdb "print $varname\n" |
gdb_expect 5 { |
-re "\[$\].*= (\[0-9\]+).*$gdb_prompt $" { |
set result $expect_out(1,string); |
} |
-re "$gdb_prompt $" { } |
default { } |
} |
return $result; |
} |
|
proc gdb_emc_gettpnum { testname } { |
global gdb_prompt; |
|
if { $testname != "" } { |
gdb_test "trace $testname" "" "" |
} |
return [gdb_emc_readvar "\$tpnum"]; |
} |
|
proc gdb_emc_setactions { testname actionname args } { |
global gdb_prompt; |
|
set state 0; |
set status "pass"; |
send_gdb "actions $actionname\n"; |
set expected_result ""; |
gdb_expect 5 { |
-re "No tracepoint number .*$gdb_prompt $" { |
fail $testname |
return 1; |
} |
-re "Enter actions for tracepoint $actionname.*>" { |
if { [llength $args] > 0 } { |
set lastcommand "[lindex $args $state]"; |
send_gdb "[lindex $args $state]\n"; |
incr state; |
set expected_result [lindex $args $state]; |
incr state; |
} else { |
send_gdb "end\n"; |
} |
exp_continue; |
} |
-re "\(.*\[\r\n\]+)\[ \t]*> $" { |
if { $expected_result != "" } { |
# Remove echoed command and its associated newline. |
regsub "^\[^\r\n\]+\[\r\n\]+" "$expect_out(1,string)" "" out; |
# Strip off any newlines at the end of the string. |
regsub "\[\r\n\]+$" "$out" "" out; |
verbose "expected '$expected_result', got '$out', expect_out is '$expect_out(1,string)'"; |
if ![regexp $expected_result $out] { |
set status "fail"; |
} |
set expected_result ""; |
} |
if { $state < [llength $args] } { |
send_gdb "[lindex $args $state]\n"; |
incr state; |
set expected_result [lindex $args $state]; |
incr state; |
} else { |
send_gdb "end\n"; |
set expected_result ""; |
} |
exp_continue; |
} |
-re "\(.*\)$gdb_prompt $" { |
if { $expected_result != "" } { |
if ![regexp $expected_result $expect_out(1,string)] { |
set status "fail"; |
} |
set expected_result ""; |
} |
if { [llength $args] < $state } { |
set status "fail"; |
} |
} |
default { |
set status "fail"; |
} |
} |
if { $testname != "" } { |
$status $testname; |
} |
if { $status == "pass" } then { |
return 0; |
} else { |
return 1; |
} |
} |
|
# |
# test collect command |
# |
|
proc gdb_emc_tracetest_collect { arg1 msgstring } { |
global decimal |
global gdb_prompt; |
|
set teststate 0 |
gdb_expect 30 { |
-re "Enter actions for tracepoint $decimal.*> $" { |
send_gdb "collect $arg1\n" |
incr teststate; |
exp_continue |
} |
-re "> $" { |
if { $teststate == 1 } { |
send_gdb "end\n" |
incr teststate; |
exp_continue |
} else { |
fail "$msgstring" |
} |
} |
-re ".*$gdb_prompt $" { |
if { $teststate == 2 } { |
pass "$msgstring"; |
} else { |
fail "$msgstring"; |
} |
} |
default { |
fail "$msgstring (default)"; |
} |
} |
regsub -all "(\[($@*+)\])" "collect $arg1" "\[\\1\]" arg1_regexp; |
gdb_test "info tracepoints" ".*$arg1_regexp.*" "$msgstring info tracepoint" |
} |
|
proc gdb_delete_tracepoints { } { |
global gdb_prompt; |
|
send_gdb "delete tracepoints\n" |
gdb_expect 30 { |
-re "Delete all tracepoints.*y or n.*$" { |
send_gdb "y\n" |
exp_continue; |
} |
-re "$gdb_prompt $" { } |
timeout { fail "delete all tracepoints (timeout)" } |
} |
} |
|
|
# Send each command in the list CMDLIST to gdb. If we see the string |
# "error" or "warning" from gdb, we assume an error has occured and |
# return a non-zero result. All of the commands in CMDLIST are always |
# sent, even if an error occurs. |
# If TESTNAME is non-null, we call pass or fail with the string in TESTNAME |
# depending on whether or not an error/warning has occurred. |
# |
proc gdb_do_cmdlist { cmdlist testname } { |
global gdb_prompt; |
|
set status 0; |
|
foreach x $cmdlist { |
send_gdb "$x\n"; |
gdb_expect 60 { |
-re "\[Ee\]rror|\[Ww\]arning" { |
set status 1; |
exp_continue; |
} |
-re "$gdb_prompt $" { } |
-re "\[\r\n\]\[ \t\]*> *$" { } |
} |
} |
if { $testname != "" } { |
if { $status == 0 } { |
pass "$testname"; |
} else { |
fail "$testname"; |
} |
} |
return $status; |
} |
|
# |
# Given the file FILENAME, we read it as a list of commands and generate |
# a list suitable for use by gdb_do_cmdlist. Lines beginning with # are |
# ignored; blank lines are interpreted as empty lines to be sent to gdb. |
# |
proc gdb_process_cmdfile { filename } { |
set id [open $filename "r"]; |
if { $id < 0 } { |
return ""; |
} |
set result {}; |
while { [gets $id line] >= 0 } { |
if [regexp "^#" $line] { |
continue; |
} |
set result [concat $result [list "$line"]]; |
} |
close $id; |
return $result; |
} |
|
# gdb_find_c_test_baseline |
# returns -1 on failure (CALLER MUST CHECK RETURN!) |
proc gdb_find_c_test_baseline { } { |
global gdb_prompt; |
|
set gdb_c_test_baseline -1; |
|
send_gdb "list gdb_c_test\n" |
gdb_expect { |
-re "void.*p5,.*void.*p6.*\[\r\n\](\[0-9\]+)\[\t \]+\{.*$gdb_prompt $" { |
set gdb_c_test_baseline $expect_out(1,string) |
} |
-re "$gdb_prompt $" { } |
default { } |
} |
return $gdb_c_test_baseline; |
} |
|
|
/mi-support.exp
0,0 → 1,1349
# Copyright 1999, 2000, 2002, 2003, 2004, 2005, 2007, 2008 |
# 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@prep.ai.mit.edu |
|
# This file was based on a file written by Fred Fish. (fnf@cygnus.com) |
|
# Test setup routines that work with the MI interpreter. |
|
# The variable mi_gdb_prompt is a regexp which matches the gdb mi prompt. |
# Set it if it is not already set. |
global mi_gdb_prompt |
if ![info exists mi_gdb_prompt] then { |
set mi_gdb_prompt "\[(\]gdb\[)\] \r\n" |
} |
|
global mi_inferior_spawn_id |
global mi_inferior_tty_name |
|
set MIFLAGS "-i=mi" |
|
# |
# mi_gdb_exit -- exit the GDB, killing the target program if necessary |
# |
proc mi_gdb_exit {} { |
catch mi_uncatched_gdb_exit |
} |
|
proc mi_uncatched_gdb_exit {} { |
global GDB |
global GDBFLAGS |
global verbose |
global gdb_spawn_id; |
global gdb_prompt |
global mi_gdb_prompt |
global MIFLAGS |
|
gdb_stop_suppressing_tests; |
|
if { [info procs sid_exit] != "" } { |
sid_exit |
} |
|
if ![info exists gdb_spawn_id] { |
return; |
} |
|
verbose "Quitting $GDB $GDBFLAGS $MIFLAGS" |
|
if { [is_remote host] && [board_info host exists fileid] } { |
send_gdb "999-gdb-exit\n"; |
gdb_expect 10 { |
-re "y or n" { |
send_gdb "y\n"; |
exp_continue; |
} |
-re "Undefined command.*$gdb_prompt $" { |
send_gdb "quit\n" |
exp_continue; |
} |
-re "DOSEXIT code" { } |
default { } |
} |
} |
|
if ![is_remote host] { |
remote_close host; |
} |
unset gdb_spawn_id |
} |
|
# |
# mi_gdb_start [INFERIOR_PTY] -- start gdb running, default procedure |
# |
# INFERIOR_PTY should be set to separate-inferior-tty to have the inferior work |
# with it's own PTY. If set to same-inferior-tty, the inferior shares GDB's PTY. |
# The default value is same-inferior-tty. |
# |
# When running over NFS, particularly if running many simultaneous |
# tests on different hosts all using the same server, things can |
# get really slow. Give gdb at least 3 minutes to start up. |
# |
proc mi_gdb_start { args } { |
global verbose |
global GDB |
global GDBFLAGS |
global gdb_prompt |
global mi_gdb_prompt |
global timeout |
global gdb_spawn_id; |
global MIFLAGS |
|
gdb_stop_suppressing_tests; |
set inferior_pty no-tty |
|
if { [llength $args] == 1} { |
set inferior_pty [lindex $args 0] |
} |
|
set separate_inferior_pty [string match $inferior_pty separate-inferior-tty] |
|
# Start SID. |
if { [info procs sid_start] != "" } { |
verbose "Spawning SID" |
sid_start |
} |
|
verbose "Spawning $GDB -nw $GDBFLAGS $MIFLAGS" |
|
if [info exists gdb_spawn_id] { |
return 0; |
} |
|
if ![is_remote host] { |
if { [which $GDB] == 0 } then { |
perror "$GDB does not exist." |
exit 1 |
} |
} |
|
# Create the new PTY for the inferior process. |
if { $separate_inferior_pty } { |
spawn -pty |
global mi_inferior_spawn_id |
global mi_inferior_tty_name |
set mi_inferior_spawn_id $spawn_id |
set mi_inferior_tty_name $spawn_out(slave,name) |
} |
|
set res [remote_spawn host "$GDB -nw $GDBFLAGS $MIFLAGS [host_info gdb_opts]"]; |
if { $res < 0 || $res == "" } { |
perror "Spawning $GDB failed." |
return 1; |
} |
gdb_expect { |
-re "~\"GNU.*\r\n~\".*$mi_gdb_prompt$" { |
# We have a new format mi startup prompt. If we are |
# running mi1, then this is an error as we should be |
# using the old-style prompt. |
if { $MIFLAGS == "-i=mi1" } { |
perror "(mi startup) Got unexpected new mi prompt." |
remote_close host; |
return -1; |
} |
verbose "GDB initialized." |
} |
-re "\[^~\].*$mi_gdb_prompt$" { |
# We have an old format mi startup prompt. If we are |
# not running mi1, then this is an error as we should be |
# using the new-style prompt. |
if { $MIFLAGS != "-i=mi1" } { |
perror "(mi startup) Got unexpected old mi prompt." |
remote_close host; |
return -1; |
} |
verbose "GDB initialized." |
} |
-re ".*$gdb_prompt $" { |
untested "Skip mi tests (got non-mi prompt)." |
remote_close host; |
return -1; |
} |
-re ".*unrecognized option.*for a complete list of options." { |
untested "Skip mi tests (not compiled with mi support)." |
remote_close host; |
return -1; |
} |
-re ".*Interpreter `mi' unrecognized." { |
untested "Skip mi tests (not compiled with mi support)." |
remote_close host; |
return -1; |
} |
timeout { |
perror "(timeout) GDB never initialized after 10 seconds." |
remote_close host; |
return -1 |
} |
} |
set gdb_spawn_id -1; |
|
# FIXME: mi output does not go through pagers, so these can be removed. |
# force the height to "unlimited", so no pagers get used |
send_gdb "100-gdb-set height 0\n" |
gdb_expect 10 { |
-re ".*100-gdb-set height 0\r\n100\\\^done\r\n$mi_gdb_prompt$" { |
verbose "Setting height to 0." 2 |
} |
timeout { |
warning "Couldn't set the height to 0" |
} |
} |
# force the width to "unlimited", so no wraparound occurs |
send_gdb "101-gdb-set width 0\n" |
gdb_expect 10 { |
-re ".*101-gdb-set width 0\r\n101\\\^done\r\n$mi_gdb_prompt$" { |
verbose "Setting width to 0." 2 |
} |
timeout { |
warning "Couldn't set the width to 0." |
} |
} |
# If allowing the inferior to have its own PTY then assign the inferior |
# its own terminal device here. |
if { $separate_inferior_pty } { |
send_gdb "102-inferior-tty-set $mi_inferior_tty_name\n" |
gdb_expect 10 { |
-re ".*102\\\^done\r\n$mi_gdb_prompt$" { |
verbose "redirect inferior output to new terminal device." |
} |
timeout { |
warning "Couldn't redirect inferior output." 2 |
} |
} |
} |
|
return 0; |
} |
|
# Many of the tests depend on setting breakpoints at various places and |
# running until that breakpoint is reached. At times, we want to start |
# with a clean-slate with respect to breakpoints, so this utility proc |
# lets us do this without duplicating this code everywhere. |
# |
|
proc mi_delete_breakpoints {} { |
global mi_gdb_prompt |
|
# FIXME: The mi operation won't accept a prompt back and will use the 'all' arg |
send_gdb "102-break-delete\n" |
gdb_expect 30 { |
-re "Delete all breakpoints.*y or n.*$" { |
send_gdb "y\n"; |
exp_continue |
} |
-re "102-break-delete\r\n102\\\^done\r\n$mi_gdb_prompt$" { |
# This happens if there were no breakpoints |
} |
timeout { perror "Delete all breakpoints in mi_delete_breakpoints (timeout)" ; return } |
} |
|
# The correct output is not "No breakpoints or watchpoints." but an |
# empty BreakpointTable. Also, a query is not acceptable with mi. |
send_gdb "103-break-list\n" |
gdb_expect 30 { |
-re "103-break-list\r\n103\\\^done,BreakpointTable=\{\}\r\n$mi_gdb_prompt$" {} |
-re "103-break-list\r\n103\\\^done,BreakpointTable=\{nr_rows=\".\",nr_cols=\".\",hdr=\\\[\{width=\".*\",alignment=\".*\",col_name=\"number\",colhdr=\"Num\"\}.*colhdr=\"Type\".*colhdr=\"Disp\".*colhdr=\"Enb\".*colhdr=\"Address\".*colhdr=\"What\".*\\\],body=\\\[\\\]\}" {} |
-re "103-break-list\r\n103\\\^doneNo breakpoints or watchpoints.\r\n\r\n$mi_gdb_prompt$" {warning "Unexpected console text received"} |
-re "$mi_gdb_prompt$" { perror "Breakpoints not deleted" ; return } |
-re "Delete all breakpoints.*or n.*$" { |
warning "Unexpected prompt for breakpoints deletion"; |
send_gdb "y\n"; |
exp_continue |
} |
timeout { perror "-break-list (timeout)" ; return } |
} |
} |
|
proc mi_gdb_reinitialize_dir { subdir } { |
global mi_gdb_prompt |
global MIFLAGS |
|
global suppress_flag |
if { $suppress_flag } { |
return |
} |
|
if [is_remote host] { |
return ""; |
} |
|
if { $MIFLAGS == "-i=mi1" } { |
send_gdb "104-environment-directory\n" |
gdb_expect 60 { |
-re ".*Reinitialize source path to empty.*y or n. " { |
warning "Got confirmation prompt for dir reinitialization." |
send_gdb "y\n" |
gdb_expect 60 { |
-re "$mi_gdb_prompt$" {} |
timeout {error "Dir reinitialization failed (timeout)"} |
} |
} |
-re "$mi_gdb_prompt$" {} |
timeout {error "Dir reinitialization failed (timeout)"} |
} |
} else { |
send_gdb "104-environment-directory -r\n" |
gdb_expect 60 { |
-re "104\\\^done,source-path=.*\r\n$mi_gdb_prompt$" {} |
-re "$mi_gdb_prompt$" {} |
timeout {error "Dir reinitialization failed (timeout)"} |
} |
} |
|
send_gdb "105-environment-directory $subdir\n" |
gdb_expect 60 { |
-re "Source directories searched.*$mi_gdb_prompt$" { |
verbose "Dir set to $subdir" |
} |
-re "105\\\^done.*\r\n$mi_gdb_prompt$" { |
# FIXME: We return just the prompt for now. |
verbose "Dir set to $subdir" |
# perror "Dir \"$subdir\" failed." |
} |
} |
} |
|
# Send GDB the "target" command. |
# FIXME: Some of these patterns are not appropriate for MI. Based on |
# config/monitor.exp:gdb_target_command. |
proc mi_gdb_target_cmd { targetname serialport } { |
global mi_gdb_prompt |
|
set serialport_re [string_to_regexp $serialport] |
for {set i 1} {$i <= 3} {incr i} { |
send_gdb "47-target-select $targetname $serialport\n" |
gdb_expect 60 { |
-re "47\\^connected.*$mi_gdb_prompt$" { |
verbose "Set target to $targetname"; |
return 0; |
} |
-re "unknown host.*$mi_gdb_prompt" { |
verbose "Couldn't look up $serialport" |
} |
-re "Couldn't establish connection to remote.*$mi_gdb_prompt$" { |
verbose "Connection failed"; |
} |
-re "Remote MIPS debugging.*$mi_gdb_prompt$" { |
verbose "Set target to $targetname"; |
return 0; |
} |
-re "Remote debugging using .*$serialport_re.*$mi_gdb_prompt$" { |
verbose "Set target to $targetname"; |
return 0; |
} |
-re "Remote target $targetname connected to.*$mi_gdb_prompt$" { |
verbose "Set target to $targetname"; |
return 0; |
} |
-re "Connected to.*$mi_gdb_prompt$" { |
verbose "Set target to $targetname"; |
return 0; |
} |
-re "Ending remote.*$mi_gdb_prompt$" { } |
-re "Connection refused.*$mi_gdb_prompt$" { |
verbose "Connection refused by remote target. Pausing, and trying again." |
sleep 5 |
continue |
} |
-re "Timeout reading from remote system.*$mi_gdb_prompt$" { |
verbose "Got timeout error from gdb."; |
} |
timeout { |
send_gdb ""; |
break |
} |
} |
} |
return 1 |
} |
|
# |
# load a file into the debugger (file command only). |
# return a -1 if anything goes wrong. |
# |
proc mi_gdb_file_cmd { arg } { |
global verbose |
global loadpath |
global loadfile |
global GDB |
global mi_gdb_prompt |
global last_loaded_file |
upvar timeout timeout |
|
set last_loaded_file $arg |
|
if [is_remote host] { |
set arg [remote_download host $arg]; |
if { $arg == "" } { |
error "download failed" |
return -1; |
} |
} |
|
# FIXME: Several of these patterns are only acceptable for console |
# output. Queries are an error for mi. |
send_gdb "105-file-exec-and-symbols $arg\n" |
gdb_expect 120 { |
-re "Reading symbols from.*done.*$mi_gdb_prompt$" { |
verbose "\t\tLoaded $arg into the $GDB" |
return 0 |
} |
-re "has no symbol-table.*$mi_gdb_prompt$" { |
perror "$arg wasn't compiled with \"-g\"" |
return -1 |
} |
-re "Load new symbol table from \".*\".*y or n. $" { |
send_gdb "y\n" |
gdb_expect 120 { |
-re "Reading symbols from.*done.*$mi_gdb_prompt$" { |
verbose "\t\tLoaded $arg with new symbol table into $GDB" |
# All OK |
} |
timeout { |
perror "(timeout) Couldn't load $arg, other program already loaded." |
return -1 |
} |
} |
} |
-re "No such file or directory.*$mi_gdb_prompt$" { |
perror "($arg) No such file or directory\n" |
return -1 |
} |
-re "105-file-exec-and-symbols .*\r\n105\\\^done\r\n$mi_gdb_prompt$" { |
# We (MI) are just giving the prompt back for now, instead of giving |
# some acknowledgement. |
return 0 |
} |
timeout { |
perror "couldn't load $arg into $GDB (timed out)." |
return -1 |
} |
eof { |
# This is an attempt to detect a core dump, but seems not to |
# work. Perhaps we need to match .* followed by eof, in which |
# gdb_expect does not seem to have a way to do that. |
perror "couldn't load $arg into $GDB (end of file)." |
return -1 |
} |
} |
} |
|
# |
# connect to the target and download a file, if necessary. |
# return a -1 if anything goes wrong. |
# |
proc mi_gdb_target_load { } { |
global verbose |
global loadpath |
global loadfile |
global GDB |
global mi_gdb_prompt |
upvar timeout timeout |
|
if { [info procs gdbserver_gdb_load] != "" } { |
mi_gdb_test "kill" ".*" "" |
set res [gdbserver_gdb_load] |
set protocol [lindex $res 0] |
set gdbport [lindex $res 1] |
|
if { [mi_gdb_target_cmd $protocol $gdbport] != 0 } { |
return -1 |
} |
} elseif { [info procs send_target_sid] != "" } { |
# For SID, things get complex |
send_gdb "kill\n" |
gdb_expect 10 { |
-re ".*$mi_gdb_prompt$" |
} |
send_target_sid |
gdb_expect 60 { |
-re "\\^done.*$mi_gdb_prompt$" { |
} |
timeout { |
perror "Unable to connect to SID target" |
return -1 |
} |
} |
send_gdb "48-target-download\n" |
gdb_expect 10 { |
-re "48\\^done.*$mi_gdb_prompt$" { |
} |
timeout { |
perror "Unable to download to SID target" |
return -1 |
} |
} |
} elseif { [target_info protocol] == "sim" } { |
# For the simulator, just connect to it directly. |
send_gdb "47-target-select sim\n" |
gdb_expect 10 { |
-re "47\\^connected.*$mi_gdb_prompt$" { |
} |
timeout { |
perror "Unable to select sim target" |
return -1 |
} |
} |
send_gdb "48-target-download\n" |
gdb_expect 10 { |
-re "48\\^done.*$mi_gdb_prompt$" { |
} |
timeout { |
perror "Unable to download to sim target" |
return -1 |
} |
} |
} elseif { [target_info gdb_protocol] == "remote" } { |
# remote targets |
if { [mi_gdb_target_cmd "remote" [target_info netport]] != 0 } { |
perror "Unable to connect to remote target" |
return -1 |
} |
send_gdb "48-target-download\n" |
gdb_expect 10 { |
-re "48\\^done.*$mi_gdb_prompt$" { |
} |
timeout { |
perror "Unable to download to remote target" |
return -1 |
} |
} |
} |
return 0 |
} |
|
# |
# load a file into the debugger. |
# return a -1 if anything goes wrong. |
# |
proc mi_gdb_load { arg } { |
if { $arg != "" } { |
return [mi_gdb_file_cmd $arg] |
} |
return 0 |
} |
|
# mi_gdb_test COMMAND PATTERN MESSAGE [IPATTERN] -- send a command to gdb; |
# test the result. |
# |
# COMMAND is the command to execute, send to GDB with send_gdb. If |
# this is the null string no command is sent. |
# PATTERN is the pattern to match for a PASS, and must NOT include |
# the \r\n sequence immediately before the gdb prompt. |
# MESSAGE is the message to be printed. (If this is the empty string, |
# then sometimes we don't call pass or fail at all; I don't |
# understand this at all.) |
# IPATTERN is the pattern to match for the inferior's output. This parameter |
# is optional. If present, it will produce a PASS if the match is |
# successful, and a FAIL if unsuccessful. |
# |
# Returns: |
# 1 if the test failed, |
# 0 if the test passes, |
# -1 if there was an internal error. |
# |
proc mi_gdb_test { args } { |
global verbose |
global mi_gdb_prompt |
global GDB expect_out |
upvar timeout timeout |
|
set command [lindex $args 0] |
set pattern [lindex $args 1] |
set message [lindex $args 2] |
|
if [llength $args]==4 { |
set ipattern [lindex $args 3] |
} |
|
if [llength $args]==5 { |
set question_string [lindex $args 3]; |
set response_string [lindex $args 4]; |
} else { |
set question_string "^FOOBAR$" |
} |
|
if $verbose>2 then { |
send_user "Sending \"$command\" to gdb\n" |
send_user "Looking to match \"$pattern\"\n" |
send_user "Message is \"$message\"\n" |
} |
|
set result -1 |
set string "${command}\n"; |
set string_regex [string_to_regexp $command] |
|
if { $command != "" } { |
while { "$string" != "" } { |
set foo [string first "\n" "$string"]; |
set len [string length "$string"]; |
if { $foo < [expr $len - 1] } { |
set str [string range "$string" 0 $foo]; |
if { [send_gdb "$str"] != "" } { |
global suppress_flag; |
|
if { ! $suppress_flag } { |
perror "Couldn't send $command to GDB."; |
} |
fail "$message"; |
return $result; |
} |
gdb_expect 2 { |
-re "\[\r\n\]" { } |
timeout { } |
} |
set string [string range "$string" [expr $foo + 1] end]; |
} else { |
break; |
} |
} |
if { "$string" != "" } { |
if { [send_gdb "$string"] != "" } { |
global suppress_flag; |
|
if { ! $suppress_flag } { |
perror "Couldn't send $command to GDB."; |
} |
fail "$message"; |
return $result; |
} |
} |
} |
|
if [info exists timeout] { |
set tmt $timeout; |
} else { |
global timeout; |
if [info exists timeout] { |
set tmt $timeout; |
} else { |
set tmt 60; |
} |
} |
gdb_expect $tmt { |
-re "\\*\\*\\* DOSEXIT code.*" { |
if { $message != "" } { |
fail "$message"; |
} |
gdb_suppress_entire_file "GDB died"; |
return -1; |
} |
-re "Ending remote debugging.*$mi_gdb_prompt\[ \]*$" { |
if ![isnative] then { |
warning "Can`t communicate to remote target." |
} |
gdb_exit |
gdb_start |
set result -1 |
} |
-re "^($string_regex\[\r\n\]+)?($pattern\[\r\n\]+$mi_gdb_prompt\[ \]*)" { |
# At this point, $expect_out(1,string) is the MI input command. |
# and $expect_out(2,string) is the MI output command. |
# If $expect_out(1,string) is "", then there was no MI input command here. |
|
# NOTE, there is no trailing anchor because with GDB/MI, |
# asynchronous responses can happen at any point, causing more |
# data to be available. Normally an anchor is used to make |
# sure the end of the output is matched, however, $mi_gdb_prompt |
# is just as good of an anchor since mi_gdb_test is meant to |
# match a single mi output command. If a second GDB/MI output |
# response is sent, it will be in the buffer for the next |
# time mi_gdb_test is called. |
if ![string match "" $message] then { |
pass "$message" |
} |
set result 0 |
} |
-re "(${question_string})$" { |
send_gdb "$response_string\n"; |
exp_continue; |
} |
-re "Undefined.* command:.*$mi_gdb_prompt\[ \]*$" { |
perror "Undefined command \"$command\"." |
fail "$message" |
set result 1 |
} |
-re "Ambiguous command.*$mi_gdb_prompt\[ \]*$" { |
perror "\"$command\" is not a unique command name." |
fail "$message" |
set result 1 |
} |
-re "Program exited with code \[0-9\]+.*$mi_gdb_prompt\[ \]*$" { |
if ![string match "" $message] then { |
set errmsg "$message (the program exited)" |
} else { |
set errmsg "$command (the program exited)" |
} |
fail "$errmsg" |
return -1 |
} |
-re "The program is not being run.*$mi_gdb_prompt\[ \]*$" { |
if ![string match "" $message] then { |
set errmsg "$message (the program is no longer running)" |
} else { |
set errmsg "$command (the program is no longer running)" |
} |
fail "$errmsg" |
return -1 |
} |
-re ".*$mi_gdb_prompt\[ \]*$" { |
if ![string match "" $message] then { |
fail "$message" |
} |
set result 1 |
} |
"<return>" { |
send_gdb "\n" |
perror "Window too small." |
fail "$message" |
} |
-re "\\(y or n\\) " { |
send_gdb "n\n" |
perror "Got interactive prompt." |
fail "$message" |
} |
eof { |
perror "Process no longer exists" |
if { $message != "" } { |
fail "$message" |
} |
return -1 |
} |
full_buffer { |
perror "internal buffer is full." |
fail "$message" |
} |
timeout { |
if ![string match "" $message] then { |
fail "$message (timeout)" |
} |
set result 1 |
} |
} |
|
# If the GDB output matched, compare the inferior output. |
if { $result == 0 } { |
if [ info exists ipattern ] { |
if { ![target_info exists gdb,noinferiorio] } { |
global mi_inferior_spawn_id |
expect { |
-i $mi_inferior_spawn_id -re "$ipattern" { |
pass "$message inferior output" |
} |
timeout { |
fail "$message inferior output (timeout)" |
set result 1 |
} |
} |
} else { |
unsupported "$message inferior output" |
} |
} |
} |
|
return $result |
} |
|
# |
# MI run command. (A modified version of gdb_run_cmd) |
# |
|
# In patterns, the newline sequence ``\r\n'' is matched explicitly as |
# ``.*$'' could swallow up output that we attempt to match elsewhere. |
|
proc mi_run_cmd {args} { |
global suppress_flag |
if { $suppress_flag } { |
return -1 |
} |
global mi_gdb_prompt |
|
if [target_info exists gdb_init_command] { |
send_gdb "[target_info gdb_init_command]\n"; |
gdb_expect 30 { |
-re "$mi_gdb_prompt$" { } |
default { |
perror "gdb_init_command for target failed"; |
return; |
} |
} |
} |
|
if { [mi_gdb_target_load] < 0 } { |
return |
} |
|
if [target_info exists use_gdb_stub] { |
if [target_info exists gdb,do_reload_on_run] { |
send_gdb "000-exec-continue\n"; |
gdb_expect 60 { |
-re "000\\^running\[\r\n\]+$mi_gdb_prompt$" {} |
default {} |
} |
return; |
} |
|
if [target_info exists gdb,start_symbol] { |
set start [target_info gdb,start_symbol]; |
} else { |
set start "start"; |
} |
|
# HACK: Should either use 000-jump or fix the target code |
# to better handle RUN. |
send_gdb "jump *$start\n" |
warning "Using CLI jump command, expect run-to-main FAIL" |
return |
} |
|
send_gdb "000-exec-run $args\n" |
gdb_expect { |
-re "000\\^running\r\n${mi_gdb_prompt}" { |
} |
timeout { |
perror "Unable to start target" |
return |
} |
} |
# NOTE: Shortly after this there will be a ``000*stopped,...(gdb)'' |
} |
|
# |
# Just like run-to-main but works with the MI interface |
# |
|
proc mi_run_to_main { } { |
global suppress_flag |
if { $suppress_flag } { |
return -1 |
} |
|
global srcdir |
global subdir |
global binfile |
global srcfile |
|
mi_delete_breakpoints |
mi_gdb_reinitialize_dir $srcdir/$subdir |
mi_gdb_load ${binfile} |
|
mi_runto main |
} |
|
|
# Just like gdb's "runto" proc, it will run the target to a given |
# function. The big difference here between mi_runto and mi_execute_to |
# is that mi_execute_to must have the inferior running already. This |
# proc will (like gdb's runto) (re)start the inferior, too. |
# |
# FUNC is the linespec of the place to stop (it inserts a breakpoint here). |
# It returns: |
# -1 if test suppressed, failed, timedout |
# 0 if test passed |
|
proc mi_runto_helper {func run_or_continue} { |
global suppress_flag |
if { $suppress_flag } { |
return -1 |
} |
|
global mi_gdb_prompt expect_out |
global hex decimal fullname_syntax |
|
set test "mi runto $func" |
mi_gdb_test "200-break-insert -t $func" \ |
"200\\^done,bkpt=\{number=\"\[0-9\]+\",type=\"breakpoint\",disp=\"del\",enabled=\"y\",addr=\"$hex\",func=\"$func\(\\\(.*\\\)\)?\",file=\".*\",line=\"\[0-9\]*\",times=\"0\"\}" \ |
"breakpoint at $func" |
|
if {![regexp {number="[0-9]+"} $expect_out(buffer) str] |
|| ![scan $str {number="%d"} bkptno]} { |
set bkptno {[0-9]+} |
} |
|
if {$run_or_continue == "run"} { |
mi_run_cmd |
} else { |
send_gdb "000-exec-continue\n" |
gdb_expect { |
-re "000\\^running\r\n${mi_gdb_prompt}" { |
} |
timeout { |
fail "$test" |
return -1 |
} |
} |
} |
|
gdb_expect { |
-re ".*000\\*stopped,thread-id=\"$decimal\",frame=\{addr=\"$hex\",func=\"$func\",args=\(\\\[.*\\\]\|\{.*\}\),file=\".*\",fullname=\"${fullname_syntax}.*\",line=\"\[0-9\]*\"\}\r\n$mi_gdb_prompt$" { |
pass "$test" |
return 0 |
} |
-re ".*$mi_gdb_prompt$" { |
fail "$test (2)" |
} |
timeout { |
fail "$test (timeout)" |
return -1 |
} |
} |
} |
|
proc mi_runto {func} { |
mi_runto_helper $func "run" |
} |
|
# Next to the next statement |
# For return values, see mi_execute_to_helper |
|
proc mi_next { test } { |
return [mi_next_to {.*} {.*} {.*} {.*} $test] |
} |
|
|
# Step to the next statement |
# For return values, see mi_execute_to_helper |
|
proc mi_step { test } { |
return [mi_step_to {.*} {.*} {.*} {.*} $test] |
} |
|
# cmd should not include the number or newline (i.e. "exec-step 3", not |
# "220-exec-step 3\n" |
|
# Can not match -re ".*\r\n${mi_gdb_prompt}", because of false positives |
# after the first prompt is printed. |
|
proc mi_execute_to_helper { cmd reason func args file line extra test } { |
global suppress_flag |
if { $suppress_flag } { |
return -1 |
} |
global mi_gdb_prompt |
global hex |
global decimal |
global fullname_syntax |
send_gdb "220-$cmd\n" |
gdb_expect { |
-re "220\\^running\r\n${mi_gdb_prompt}.*220\\*stopped,reason=\"$reason\",thread-id=\"$decimal\",frame=\{addr=\"$hex\",func=\"$func\",args=$args,file=\".*$file\",fullname=\"${fullname_syntax}$file\",line=\"$line\"\}$extra\r\n$mi_gdb_prompt$" { |
pass "$test" |
return 0 |
} |
-re "220\\^running\r\n${mi_gdb_prompt}.*220\\*stopped,reason=\"$reason\",thread-id=\"$decimal\",frame=\{addr=\"$hex\",func=\".*\",args=\[\\\[\{\].*\[\\\]\}\],file=\".*\",fullname=\"${fullname_syntax}.*\",line=\"\[0-9\]*\"\}.*\r\n$mi_gdb_prompt$" { |
fail "$test (stopped at wrong place)" |
return -1 |
} |
-re "220\\^running\r\n${mi_gdb_prompt}.*\r\n${mi_gdb_prompt}$" { |
fail "$test (unknown output after running)" |
return -1 |
} |
timeout { |
fail "$test (timeout)" |
return -1 |
} |
} |
} |
|
proc mi_execute_to { cmd reason func args file line extra test } { |
mi_execute_to_helper "$cmd" "$reason" "$func" "\\\[$args\\\]" \ |
"$file" "$line" "$extra" "$test" |
} |
|
proc mi_next_to { func args file line test } { |
mi_execute_to "exec-next" "end-stepping-range" "$func" "$args" \ |
"$file" "$line" "" "$test" |
} |
|
proc mi_step_to { func args file line test } { |
mi_execute_to "exec-step" "end-stepping-range" "$func" "$args" \ |
"$file" "$line" "" "$test" |
} |
|
proc mi_finish_to { func args file line result ret test } { |
mi_execute_to "exec-finish" "function-finished" "$func" "$args" \ |
"$file" "$line" \ |
",gdb-result-var=\"$result\",return-value=\"$ret\"" \ |
"$test" |
} |
|
proc mi_continue_to {func} { |
mi_runto_helper $func "continue" |
} |
|
proc mi0_execute_to { cmd reason func args file line extra test } { |
mi_execute_to_helper "$cmd" "$reason" "$func" "\{$args\}" \ |
"$file" "$line" "$extra" "$test" |
} |
|
proc mi0_next_to { func args file line test } { |
mi0_execute_to "exec-next" "end-stepping-range" "$func" "$args" \ |
"$file" "$line" "" "$test" |
} |
|
proc mi0_step_to { func args file line test } { |
mi0_execute_to "exec-step" "end-stepping-range" "$func" "$args" \ |
"$file" "$line" "" "$test" |
} |
|
proc mi0_finish_to { func args file line result ret test } { |
mi0_execute_to "exec-finish" "function-finished" "$func" "$args" \ |
"$file" "$line" \ |
",gdb-result-var=\"$result\",return-value=\"$ret\"" \ |
"$test" |
} |
|
proc mi0_continue_to { bkptno func args file line test } { |
mi0_execute_to "exec-continue" "breakpoint-hit\",bkptno=\"$bkptno" \ |
"$func" "$args" "$file" "$line" "" "$test" |
} |
|
# Creates varobj named NAME for EXPRESSION. |
# Name cannot be "-". |
proc mi_create_varobj { name expression testname } { |
mi_gdb_test "-var-create $name * $expression" \ |
"\\^done,name=\"$name\",numchild=\"\[0-9\]+\",value=\".*\",type=.*" \ |
$testname |
} |
|
# Deletes the specified NAME. |
proc mi_delete_varobj { name testname } { |
mi_gdb_test "-var-delete $name" \ |
"\\^done,ndeleted=.*" \ |
$testname |
} |
|
# Updates varobj named NAME and checks that all varobjs in EXPECTED |
# are reported as updated, and no other varobj is updated. |
# Assumes that no varobj is out of scope and that no varobj changes |
# types. |
proc mi_varobj_update { name expected testname } { |
set er "\\^done,changelist=\\\[" |
set first 1 |
foreach item $expected { |
set v "{name=\"$item\",in_scope=\"true\",type_changed=\"false\"}" |
if {$first == 1} { |
set er "$er$v" |
set first 0 |
} else { |
set er "$er,$v" |
} |
} |
set er "$er\\\]" |
|
verbose -log "Expecting: $er" 2 |
mi_gdb_test "-var-update $name" $er $testname |
} |
|
proc mi_check_varobj_value { name value testname } { |
|
mi_gdb_test "-var-evaluate-expression $name" \ |
"\\^done,value=\"$value\"" \ |
$testname |
} |
|
# Check the results of the: |
# |
# -var-list-children VARNAME |
# |
# command. The CHILDREN parement should be a list of lists. |
# Each inner list can have either 3 or 4 elements, describing |
# fields that gdb is expected to report for child variable object, |
# in the following order |
# |
# - Name |
# - Expression |
# - Number of children |
# - Type |
# |
# If inner list has 3 elements, the gdb is expected to output no |
# type for a child. |
# |
proc mi_list_varobj_children { varname children testname } { |
|
set numchildren [llength $children] |
set children_exp {} |
set whatever "\"\[^\"\]+\"" |
|
foreach item $children { |
|
set name [lindex $item 0] |
set exp [lindex $item 1] |
set numchild [lindex $item 2] |
if {[llength $item] == 4} { |
set type [lindex $item 3] |
|
lappend children_exp\ |
"child={name=\"$name\",exp=\"$exp\",numchild=\"$numchild\",type=\"$type\"}" |
} else { |
lappend children_exp\ |
"child={name=\"$name\",exp=\"$exp\",numchild=\"$numchild\"}" |
} |
} |
set children_exp_j [join $children_exp ","] |
set expected "\\^done,numchild=\"$numchildren\",children=\\\[$children_exp_j\\\]" |
|
verbose -log "Expecting: $expected" |
|
mi_gdb_test "-var-list-children $varname" $expected $testname |
} |
|
# A list of two-element lists. First element of each list is |
# a Tcl statement, and the second element is the line |
# number of source C file where the statement originates. |
set mi_autotest_data "" |
# The name of the source file for autotesting. |
set mi_autotest_source "" |
|
proc count_newlines { string } { |
return [regexp -all "\n" $string] |
} |
|
# Prepares for running inline tests in FILENAME. |
# See comments for mi_run_inline_test for detailed |
# explanation of the idea and syntax. |
proc mi_prepare_inline_tests { filename } { |
|
global srcdir |
global subdir |
global mi_autotest_source |
global mi_autotest_data |
|
set mi_autotest_data {} |
|
set mi_autotest_source $filename |
|
if { ! [regexp "^/" "$filename"] } then { |
set filename "$srcdir/$subdir/$filename" |
} |
|
set chan [open $filename] |
set content [read $chan] |
set line_number 1 |
while {1} { |
set start [string first "/*:" $content] |
if {$start != -1} { |
set end [string first ":*/" $content] |
if {$end == -1} { |
error "Unterminated special comment in $filename" |
} |
|
set prefix [string range $content 0 $start] |
set prefix_newlines [count_newlines $prefix] |
|
set line_number [expr $line_number+$prefix_newlines] |
set comment_line $line_number |
|
set comment [string range $content [expr $start+3] [expr $end-1]] |
|
set comment_newlines [count_newlines $comment] |
set line_number [expr $line_number+$comment_newlines] |
|
set comment [string trim $comment] |
set content [string range $content [expr $end+3] \ |
[string length $content]] |
lappend mi_autotest_data [list $comment $comment_line] |
} else { |
break |
} |
} |
close $chan |
} |
|
# Helper to mi_run_inline_test below. |
# Return the list of all (statement,line_number) lists |
# that comprise TESTCASE. The begin and end markers |
# are not included. |
proc mi_get_inline_test {testcase} { |
|
global mi_gdb_prompt |
global mi_autotest_data |
global mi_autotest_source |
|
set result {} |
|
set seen_begin 0 |
set seen_end 0 |
foreach l $mi_autotest_data { |
|
set comment [lindex $l 0] |
|
if {$comment == "BEGIN: $testcase"} { |
set seen_begin 1 |
} elseif {$comment == "END: $testcase"} { |
set seen_end 1 |
break |
} elseif {$seen_begin==1} { |
lappend result $l |
} |
} |
|
if {$seen_begin == 0} { |
error "Autotest $testcase not found" |
} |
|
if {$seen_begin == 1 && $seen_end == 0} { |
error "Missing end marker for test $testcase" |
} |
|
return $result |
} |
|
# Sets temporary breakpoint at LOCATION. |
proc mi_tbreak {location} { |
|
global mi_gdb_prompt |
|
mi_gdb_test "-break-insert -t $location" \ |
{\^done,bkpt=.*} \ |
"run to $location (set breakpoint)" |
} |
|
# Send COMMAND that must be a command that resumes |
# the inferiour (run/continue/next/etc) and consumes |
# the "^running" output from it. |
proc mi_send_resuming_command {command test} { |
|
global mi_gdb_prompt |
|
send_gdb "220-$command\n" |
gdb_expect { |
-re "220\\^running\r\n${mi_gdb_prompt}" { |
} |
timeout { |
fail $test |
} |
} |
} |
|
# Helper to mi_run_inline_test below. |
# Sets a temporary breakpoint at LOCATION and runs |
# the program using COMMAND. When the program is stopped |
# returns the line at which it. Returns -1 if line cannot |
# be determined. |
# Does not check that the line is the same as requested. |
# The caller can check itself if required. |
proc mi_continue_to_line {location test} { |
|
mi_tbreak $location |
mi_send_resuming_command "exec-continue" "run to $location (exec-continue)" |
return [mi_wait_for_stop $test] |
} |
|
# Wait until gdb prints the current line. |
proc mi_wait_for_stop {test} { |
|
global mi_gdb_prompt |
|
gdb_expect { |
-re ".*line=\"(.*)\".*\r\n$mi_gdb_prompt$" { |
return $expect_out(1,string) |
} |
-re ".*$mi_gdb_prompt$" { |
fail "wait for stop ($test)" |
} |
timeout { |
fail "wait for stop ($test)" |
} |
} |
} |
|
# Run a MI test embedded in comments in a C file. |
# The C file should contain special comments in the following |
# three forms: |
# |
# /*: BEGIN: testname :*/ |
# /*: <Tcl statements> :*/ |
# /*: END: testname :*/ |
# |
# This procedure find the begin and end marker for the requested |
# test. Then, a temporary breakpoint is set at the begin |
# marker and the program is run (from start). |
# |
# After that, for each special comment between the begin and end |
# marker, the Tcl statements are executed. It is assumed that |
# for each comment, the immediately preceding line is executable |
# C statement. Then, gdb will be single-stepped until that |
# preceding C statement is executed, and after that the |
# Tcl statements in the comment will be executed. |
# |
# For example: |
# |
# /*: BEGIN: assignment-test :*/ |
# v = 10; |
# /*: <Tcl code to check that 'v' is indeed 10 :*/ |
# /*: END: assignment-test :*/ |
# |
# The mi_prepare_inline_tests function should be called before |
# calling this function. A given C file can contain several |
# inline tests. The names of the tests must be unique within one |
# C file. |
# |
proc mi_run_inline_test { testcase } { |
|
global mi_gdb_prompt |
global hex |
global decimal |
global fullname_syntax |
global mi_autotest_source |
|
set commands [mi_get_inline_test $testcase] |
|
set first 1 |
set line_now 1 |
|
foreach c $commands { |
set statements [lindex $c 0] |
set line [lindex $c 1] |
set line [expr $line-1] |
|
# We want gdb to be stopped at the expression immediately |
# before the comment. If this is the first comment, the |
# program is either not started yet or is in some random place, |
# so we run it. For further comments, we might be already |
# standing at the right line. If not continue till the |
# right line. |
|
if {$first==1} { |
# Start the program afresh. |
mi_tbreak "$mi_autotest_source:$line" |
mi_run_cmd |
set line_now [mi_wait_for_stop "$testcase: step to $line"] |
set first 0 |
} elseif {$line_now!=$line} { |
set line_now [mi_continue_to_line "$mi_autotest_source:$line" "continue to $line"] |
} |
|
if {$line_now!=$line} { |
fail "$testcase: go to line $line" |
} |
|
# We're not at the statement right above the comment. |
# Execute that statement so that the comment can test |
# the state after the statement is executed. |
|
# Single-step past the line. |
mi_send_resuming_command "exec-next" "$testcase: step over $line" |
set line_now [mi_wait_for_stop "$testcase: step over $line"] |
|
# We probably want to use 'uplevel' so that statements |
# have direct access to global variables that the |
# main 'exp' file has set up. But it's not yet clear, |
# will need more experience to be sure. |
eval $statements |
} |
} |
/compiler.c
0,0 → 1,76
/* This test file is part of GDB, the GNU debugger. |
|
Copyright 1995, 1997, 1999, 2003, 2004, 2007, 2008 |
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/>. |
|
*/ |
|
/* Sometimes the behavior of a test depends upon the compiler used to |
compile the test program. A test script can call get_compiler_info |
to figure out the compiler version and test_compiler_info to test it. |
|
get_compiler_info runs the preprocessor on this file and then eval's |
the result. This sets various symbols for use by test_compiler_info. |
|
TODO: make compiler_info a local variable for get_compiler_info and |
test_compiler_info. |
|
TODO: all clients should use test_compiler_info and should not |
use gcc_compiled, hp_cc_compiler, or hp_aCC_compiler. |
|
*/ |
|
/* Note the semicolon at the end of this line. Older versions of |
hp c++ have a bug in string preprocessing: if the last token on a |
line is a string, then the preprocessor concatenates the next line |
onto the current line and eats the newline! That messes up TCL of |
course. That happens with HP aC++ A.03.13, but it no longer happens |
with HP aC++ A.03.45. */ |
|
set compiler_info "unknown" ; |
|
#if defined (__GNUC__) |
#if defined (__GNUC_PATCHLEVEL__) |
/* Only GCC versions >= 3.0 define the __GNUC_PATCHLEVEL__ macro. */ |
set compiler_info [join {gcc __GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__} -] |
#else |
set compiler_info [join {gcc __GNUC__ __GNUC_MINOR__ "unknown"} -] |
#endif |
#endif |
|
#if defined (__HP_CXD_SPP) |
/* older hp ansi c, such as A.11.01.25171.gp, defines this */ |
set compiler_info [join {hpcc __HP_CXD_SPP} -] |
#endif |
|
#if defined (__HP_cc) |
/* newer hp ansi c, such as B.11.11.28706.gp, defines this */ |
set compiler_info [join {hpcc __HP_cc} -] |
#endif |
|
#if defined (__HP_aCC) |
set compiler_info [join {hpacc __HP_aCC} -] |
#endif |
|
#if defined (__xlc__) |
/* IBM'x xlc compiler. NOTE: __xlc__ expands to a double quoted string of four |
numbers seperated by '.'s: currently "7.0.0.0" */ |
set need_a_set [regsub -all {\.} [join {xlc __xlc__} -] - compiler_info] |
#endif |
|
#if defined (__ARMCC_VERSION) |
set compiler_info [join {armcc __ARMCC_VERSION} -] |
#endif |
compiler.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: java.exp
===================================================================
--- java.exp (nonexistent)
+++ java.exp (revision 816)
@@ -0,0 +1,122 @@
+# This test code is part of GDB, the GNU debugger.
+
+# Copyright 1998, 1999, 2000, 2003, 2004, 2006, 2007, 2008
+# 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 .
+
+load_lib "libgloss.exp"
+
+# GCJ_UNDER_TEST is the compiler under test.
+
+global tmpdir
+
+if ![info exists tmpdir] {
+ set tmpdir "/tmp"
+}
+
+set java_initialized 0
+
+#
+# Build the status wrapper library as needed.
+#
+proc java_init { args } {
+ global wrapper_file;
+ global wrap_compile_flags;
+ global java_initialized
+ global GCJ_UNDER_TEST
+ global TOOL_EXECUTABLE
+ global env
+
+ if { $java_initialized == 1 } { return; }
+
+ if ![info exists GCJ_UNDER_TEST] {
+ if [info exists TOOL_EXECUTABLE] {
+ set GCJ_UNDER_TEST $TOOL_EXECUTABLE;
+ } else {
+ if [info exists env(GCJ)] {
+ set GCJ_UNDER_TEST $env(GCJ)
+ } else {
+ global tool_root_dir
+ global target_alias
+
+ if ![is_remote host] {
+ set file [lookfor_file $tool_root_dir gcj];
+ if { $file == "" } {
+ set file [lookfor_file $tool_root_dir gcc/gcj];
+ }
+ if { $file != "" } {
+ set CC "$file -B[file dirname $file]/ --specs=$tool_root_dir/$target_alias/libjava/libgcj-test.spec";
+ } else {
+ set CC [transform gcj];
+ }
+ } else {
+ set CC [transform gcj]
+ }
+ set GCJ_UNDER_TEST $CC
+ }
+ }
+ }
+
+ set wrapper_file "";
+ set wrap_compile_flags "";
+ if [target_info exists needs_status_wrapper] {
+ set result [build_wrapper "testglue.o"];
+ if { $result != "" } {
+ set wrapper_file [lindex $result 0];
+ set wrap_compile_flags [lindex $result 1];
+ } else {
+ warning "Status wrapper failed to build."
+ }
+ }
+
+ set java_initialized 1
+}
+
+#
+# Run the test specified by srcfile and resultfile. compile_args and
+# exec_args are options telling this proc how to work.
+#
+proc compile_java_from_source { srcfile binfile compile_args } {
+ global GCJ_UNDER_TEST
+ global runtests
+ global java_initialized
+
+ if { $java_initialized != 1 } { java_init }
+
+ set errname [file rootname [file tail $srcfile]]
+ if {! [runtest_file_p $runtests $errname]} {
+ return
+ }
+
+ set args "compiler=$GCJ_UNDER_TEST"
+ lappend args "additional_flags=--main=[file rootname [file tail $srcfile]]"
+ if { $compile_args != "" } {
+ lappend args "additional_flags=$compile_args"
+ }
+
+ if { $compile_args != "" } {
+ set errname "$errname $compile_args"
+ }
+
+ set x [target_compile $srcfile ${binfile} executable $args]
+ if { $x != "" } {
+ verbose "target_compile failed: $x" 2
+ return "$errname compilation from source";
+ }
+}
+
+# Local Variables:
+# tcl-indent-level:4
+# End:
Index: compiler.cc
===================================================================
--- compiler.cc (nonexistent)
+++ compiler.cc (revision 816)
@@ -0,0 +1,63 @@
+/* This test file is part of GDB, the GNU debugger.
+
+ Copyright 1995, 1999, 2003, 2004, 2007, 2008 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 .
+
+ */
+
+/* This file is exactly like compiler.c. I could just use compiler.c if
+ I could be sure that every C++ compiler accepted extensions of ".c". */
+
+/* Note the semicolon at the end of this line. Older versions of
+ hp c++ have a bug in string preprocessing: if the last token on a
+ line is a string, then the preprocessor concatenates the next line
+ onto the current line and eats the newline! That messes up TCL of
+ course. That happens with HP aC++ A.03.13, but it no longer happens
+ with HP aC++ A.03.45. */
+
+set compiler_info "unknown" ;
+
+#if defined (__GNUC__)
+#if defined (__GNUC_PATCHLEVEL__)
+/* Only GCC versions >= 3.0 define the __GNUC_PATCHLEVEL__ macro. */
+set compiler_info [join {gcc __GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__} -]
+#else
+set compiler_info [join {gcc __GNUC__ __GNUC_MINOR__ "unknown"} -]
+#endif
+#endif
+
+#if defined (__HP_CXD_SPP)
+/* older hp ansi c, such as A.11.01.25171.gp, defines this */
+set compiler_info [join {hpcc __HP_CXD_SPP} -]
+#endif
+
+#if defined (__HP_cc)
+/* newer hp ansi c, such as B.11.11.28706.gp, defines this */
+set compiler_info [join {hpcc __HP_cc} -]
+#endif
+
+#if defined (__HP_aCC)
+set compiler_info [join {hpacc __HP_aCC} -]
+#endif
+
+#if defined (__xlc__)
+/* IBM'x xlc compiler. NOTE: __xlc__ expands to a double quoted string of four
+ numbers seperated by '.'s: currently "7.0.0.0" */
+set need_a_set [regsub -all {\.} [join {xlc __xlc__} -] - compiler_info]
+#endif
+
+#if defined (__ARMCC_VERSION)
+set compiler_info [join {armcc __ARMCC_VERSION} -]
+#endif
Index: pascal.exp
===================================================================
--- pascal.exp (nonexistent)
+++ pascal.exp (revision 816)
@@ -0,0 +1,152 @@
+# Copyright 2007, 2008 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 .
+
+load_lib libgloss.exp
+
+set pascal_init_done 0
+
+# This procedure looks for a suitable pascal compiler
+# For now only GNU pascal compiler and Free Pascal compiler
+# are searched.
+# First, environment variable GPC is checked
+# if present, GPC compiler is assumed to be the value of
+# that environment variable.
+# Second, environment variable FPC is checked
+# if present, Free Pascal compiler is assumed to be the value of
+# that environment variable.
+# Third, gpc executable is searched using `which gpc`
+# Lastly, fpc executable is searched using `which fpc`
+# Using environment variable allows to force
+# which compiler is used in testsuite
+
+proc pascal_init {} {
+ global pascal_init_done
+ global pascal_compiler_is_gpc
+ global pascal_compiler_is_fpc
+ global gpc_compiler
+ global fpc_compiler
+ global env
+
+ if { $pascal_init_done == 1 } {
+ return
+ }
+
+ set pascal_compiler_is_gpc 0
+ set pascal_compiler_is_fpc 0
+ set gpc_compiler [transform gpc]
+ set fpc_compiler [transform fpc]
+
+ if ![is_remote host] {
+ if { [info exists env(GPC)] } {
+ set pascal_compiler_is_gpc 1
+ set gpc_compiler $env(GPC)
+ verbose -log "Assuming GNU Pascal ($gpc_compiler)"
+ } elseif { [info exists env(FPC)] } {
+ set pascal_compiler_is_fpc 1
+ set fpc_compiler $env(FPC)
+ verbose -log "Assuming Free Pascal ($fpc_compiler)"
+ } elseif { [which $gpc_compiler] != 0 } {
+ set pascal_compiler_is_gpc 1
+ verbose -log "GNU Pascal compiler found"
+ } elseif { [which $fpc_compiler] != 0 } {
+ set pascal_compiler_is_fpc 1
+ verbose -log "Free Pascal compiler found"
+ }
+ }
+ set pascal_init_done 1
+}
+
+proc gpc_compile {source dest type options} {
+ global gpc_compiler
+ set add_flags ""
+ if {$type == "object"} {
+ append add_flags " -c"
+ }
+
+ if { $type == "preprocess" } {
+ append add_flags " -E"
+ }
+
+ if { $type == "assembly" } {
+ append add_flags " -S"
+ }
+
+ foreach i $options {
+ if { $i == "debug" } {
+ if [board_info $dest exists debug_flags] {
+ append add_flags " [board_info $dest debug_flags]";
+ } else {
+ append add_flags " -g"
+ }
+ }
+ }
+
+ set result [remote_exec host $gpc_compiler "-o $dest --automake $add_flags $source"]
+ return $result
+}
+
+proc fpc_compile {source dest type options} {
+ global fpc_compiler
+ set add_flags ""
+ if {$type == "object"} {
+ append add_flags " -Cn"
+ }
+
+ if { $type == "preprocess" } {
+ return "Free Pascal can not preprocess"
+ }
+
+ if { $type == "assembly" } {
+ append add_flags " -al"
+ }
+
+ foreach i $options {
+ if { $i == "debug" } {
+ if [board_info $dest exists debug_flags] {
+ append add_flags " [board_info $dest debug_flags]";
+ } else {
+ append add_flags " -g"
+ }
+ }
+ }
+
+ set result [remote_exec host $fpc_compiler "-o$dest $add_flags $source"]
+ return $result
+}
+
+proc gdb_compile_pascal {source dest type options} {
+ global pascal_init_done
+ global pascal_compiler_is_gpc
+ global pascal_compiler_is_fpc
+
+ if { $pascal_init_done == 0 } {
+ pascal_init
+ }
+
+ if { $pascal_compiler_is_fpc == 1 } {
+ set result [fpc_compile $source $dest $type $options]
+ } elseif { $pascal_compiler_is_gpc == 1 } {
+ set result [gpc_compile $source $dest $type $options]
+ } else {
+ unsupported "No pascal compiler found"
+ return "No pascal compiler. Compilation failed."
+ }
+
+ if ![file exists $dest] {
+ unsupported "Pascal compilation failed: $result"
+ return "Pascal compilation failed."
+ }
+}
+