📄 gdb.exp
字号:
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 0set hp_cc_compiler 0set 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-06proc 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] ]
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -