# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-# Please email any bugs, comments, and/or additions to this file to:
-# bug-gdb@prep.ai.mit.edu
-
# This file was written by Fred Fish. (fnf@cygnus.com)
# Generic gdb subroutines that should work for any target. If these
if [target_info exists gdb,do_reload_on_run] {
# Specifying no file, defaults to the executable
# currently being debugged.
- if { [gdb_load ""] < 0 } {
+ if { [gdb_load ""] != 0 } {
return;
}
send_gdb "continue\n";
send_gdb "y\n"
}
-re "The program is not being run.*$gdb_prompt $" {
- if { [gdb_load ""] < 0 } {
+ if { [gdb_load ""] != 0 } {
return;
}
send_gdb "jump *$start\n";
}
if [target_info exists gdb,do_reload_on_run] {
- if { [gdb_load ""] < 0 } {
+ if { [gdb_load ""] != 0 } {
return;
}
}
}
}
-proc gdb_breakpoint { function } {
+# Set a breakpoint at FUNCTION. If there is an additional argument it is
+# a list of options; the only currently supported option is allow-pending.
+
+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
+ }
+
send_gdb "break $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 "Make breakpoint pending.*y or n. $" {
- send_gdb "n\n"
+ -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 }
# 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.
+# single quoted C++ function specifier. If there's an additional argument,
+# pass it to gdb_breakpoint.
-proc runto { function } {
+proc runto { function args } {
global gdb_prompt
global decimal
delete_breakpoints
- if ![gdb_breakpoint $function] {
+ if ![gdb_breakpoint $function [lindex $args 0]] {
return 0;
}
fail "$errmsg"
set result -1
}
- -re ".*$gdb_prompt $" {
+ -re "\r\n$gdb_prompt $" {
if ![string match "" $message] then {
fail "$message"
}
}
set result 0
- gdb_expect $tmt $code
+ 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
}
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
#
-# load a file into the debugger.
-# return a -1 if anything goes wrong.
+# 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 loadpath
- global loadfile
global GDB
- global gdb_prompt
- upvar timeout timeout
+
+ # 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];
+ set arg [remote_download host $arg]
if { $arg == "" } {
- error "download failed"
- return -1;
+ perror "download failed"
+ return -1
}
}
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"
- return 0
- }
- -re "has no symbol-table.*$gdb_prompt $" {
- perror "$arg wasn't compiled with \"-g\""
- return -1
+ set gdb_file_cmd_debug_info "debug"
+ return 0
}
-re "A program is being debugged already.*Kill it.*y or n. $" {
send_gdb "y\n"
- verbose "\t\tKilling previous program being debugged"
+ verbose "\t\tKilling previous program being debugged"
exp_continue
}
-re "Load new symbol table from \".*\".*y or n. $" {
gdb_expect 120 {
-re "Reading symbols from.*done.*$gdb_prompt $" {
verbose "\t\tLoaded $arg with new symbol table into $GDB"
- return 0
+ set gdb_file_cmd_debug_info "debug"
+ return 0
}
timeout {
perror "(timeout) Couldn't load $arg, other program already loaded."
- return -1
+ return -1
}
}
}
-re "No such file or directory.*$gdb_prompt $" {
- perror "($arg) No such file or directory\n"
- return -1
+ perror "($arg) No such file or directory"
+ return -1
}
-re "$gdb_prompt $" {
perror "couldn't load $arg into $GDB."
- return -1
+ return -1
}
timeout {
perror "couldn't load $arg into $GDB (timed out)."
- return -1
+ 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
+ return -1
}
}
}
return 0
}
+# Return a 1 if I don't even want to try to test FORTRAN.
+
+proc skip_fortran_tests {} {
+ return 0
+}
+
# Skip all the tests in the file if you are not on an hppa running
# hpux target.
set gcc_compiled 0
set hp_cc_compiler 0
set hp_aCC_compiler 0
-set signed_keyword_not_used 0
# Figure out what compiler I am using.
#
# 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
- global signed_keyword_not_used
# Choose which file to preprocess.
set ifile "${srcdir}/lib/compiler.c"
set cppout [ gdb_compile "${ifile}" "" preprocess [list "$args" quiet] ]
log_file -a "$outdir/$tool.log"
- # Source the output.
+ # Eval the output.
+ set unknown 0
foreach cppline [ split "$cppout" "\n" ] {
- if { ! [ regexp "^#" "$cppline" ] } {
- if { ! [ regexp "^\[\n\r\t \]*$" "$cppline" ] } {
- verbose "get_compiler_info: $cppline" 2
- eval "$cppline"
- }
+ 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
return 0;
}
-proc test_compiler_info { compiler } {
+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]
}
global gdb_wrapper_flags;
global gdb_wrapper_initialized;
+ # 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"
+ } 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${objdir}/${subdir}"
+ } elseif { [istarget "mips-sgi-irix*"] } {
+ lappend options "additional_flags=-rpath ${objdir}/${subdir}"
+ }
+ }
+ } 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]";
}
}
+# 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*"]) } {
+ 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 {[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} {
#
# gdb_load -- load a file into the debugger.
-# return a -1 if anything goes wrong.
+# Many files in config/*.exp override this procedure.
#
proc gdb_load { arg } {
return [gdb_file_cmd $arg]
}
}
-### gdb_get_line_number TEXT [FILE]
-###
-### Search the source file FILE, and return the line number of a line
-### containing TEXT. Use this function instead of hard-coding line
-### numbers into your test script.
-###
-### Specifically, this function uses GDB's "search" command to search
-### FILE for the first line containing TEXT, and returns its line
-### number. Thus, FILE must be a source file, compiled into the
-### executable you are running. If omitted, FILE defaults to the
-### value of the global variable `srcfile'; most test scripts set
-### `srcfile' appropriately at the top anyway.
-###
-### 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.)
-
-proc gdb_get_line_number {text {file /omitted/}} {
- global gdb_prompt;
- global srcfile;
+# 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 {! [string compare $file /omitted/]} {
- set file $srcfile
+ if { "$file" == "" } then {
+ set file "$srcfile"
+ }
+ if { ! [regexp "^/" "$file"] } then {
+ set file "$srcdir/$subdir/$file"
}
- set result -1;
- gdb_test "list ${file}:1,1" ".*" ""
- send_gdb "search ${text}\n"
- gdb_expect {
- -re "\[\r\n\]+(\[0-9\]+)\[ \t\].*${text}.*$gdb_prompt $" {
- set result $expect_out(1,string)
- }
- -re ".*$gdb_prompt $" {
- fail "find line number containing \"${text}\""
- }
- timeout {
- fail "find line number containing \"${text}\" (timeout)"
- }
+ if { [ catch { set fd [open "$file"] } message ] } then {
+ perror "$message"
+ return -1
}
- return $result;
+
+ 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: