binutils-gdb/gdb/testsuite/gdb.hp/thr-lib.exp

237 lines
6.8 KiB
Plaintext
Raw Normal View History

# thr-lib.exp -- Expect script to test thread-local storage in lib
# Copyright (C) 1992 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 2 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, 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
# use this to debug:
#
#log_user 1
# Thread stuff is _slow_; prepare for long waits.
#
# Further, this test has some "null" lines designed
# to consume output from gdb that was too late to be
# matched (sequence is "gdb_test" sends; timeout and
# on to next send; result finally comes in; mismatch).
#
# The null command is 'gdb_test "p \$pc" ".*" ""'
# NOTE: this command undoes any up/down stuff!
#
proc pre_timeout {} {
global timeout
set timeout [expr "$timeout + 100"]
}
proc post_timeout {} {
global timeout
global oldtimeout
set timeout $oldtimeout
gdb_test "p \$pc" ".*" ""
}
if $tracelevel then {
strace $tracelevel
}
1999-04-26 20:34:20 +02:00
if { [skip_hp_tests] } then { continue }
if { ![istarget "hppa*-*-hpux10.30"] && ![istarget "hppa*-*-hpux11.*"] } {
verbose "HPUX thread test ignored for non-hppa or pre-HP/UX-10.30 targets."
return 0
}
set testfile thr-lib
set srcfile ${srcdir}/${subdir}/${testfile}.c
set libsrc ${srcdir}/${subdir}/${testfile}lib.c
set mainobj ${objdir}/${testfile}.o
set libobj ${objdir}/${testfile}lib.o
set libsl ${objdir}/${subdir}/${testfile}lib.sl
set binfile ${objdir}/${subdir}/${testfile}
# To build the executable we need to do this:
#
# cc -c -Aa -g -D_HPUX_SOURCE -D_REENTRANT +DA1.0 ./gdb.hp/thr-lib.c
# cc -c -Aa -g -D_HPUX_SOURCE -D_REENTRANT +DA1.0 +z ./gdb.hp/thr-liblib.c
# ld -o thread_local_in_lib.lib.sl -b ./gdb.hp/thr-liblib.o
# ld -a archive /opt/langtools/lib/crt0.o /opt/langtools/lib/end.o \
# > thr-lib.o ./gdb.hp/thr-liblib.sl \
# > -o thr-lib -lpthread -lc
#
remote_exec build "$CC ${srcfile} -c -Aa -g -D_HPUX_SOURCE -D_REENTRANT +DA1.0"
remote_exec build "$CC ${libsrc} -c -Aa -g -D_HPUX_SOURCE -D_REENTRANT +DA1.0 +z"
remote_exec build "ld -o ${libsl} -b ${libobj}"
remote_exec build "ld -a archive /opt/langtools/lib/crt0.o /opt/langtools/lib/end.o ${mainobj} ${libsl} -lpthread -lc -o ${binfile}"
gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
set oldtimeout $timeout
#set timeout [expr "$timeout + 200"]
set oldverbose $verbose
gdb_load ${binfile}
# Here we go: test various things.
#
gdb_test "b adder" ".*Cannot break on adder without a running program.*" "shared loc, needs to run"
gdb_test "b main" ".*" ""
gdb_test "run" ".*Breakpoint 1, main.*" ""
# Set a bp to inspect the results
#
gdb_test "b 67" ".*Breakpoint 2.*" ""
# get to a point where we can set the collection breakpoint.
#
gdb_test "tb adder" ".*Breakpoint 3.*line 47.*" "set bp in shared lib"
gdb_test "c" ".*Switched to.*adder.*" "run to shared lib rtn"
# Check locations of things
#
gdb_test "i ad sum" ".*Symbol \"sum\" is a thread-local variable.*offset.*from the thread base register mpsfu_high.*" "find sum"
gdb_test "i add x" ".*Symbol \"x\" is a thread-local variable.*" "find x"
# Set a breakpoint later on in "adder" and
# collect the thread local's value.
#
gdb_test "b 61" ".*Breakpoint 4.*61.*" "Set collection bp"
# extra check for grins, expect to hit "adder" in thread 2 first
# but could be wrong...
#
gdb_test "info thread" ".*\\\* 2.*thread.*thread.*" "two threads"
# Can't use "gdb_test", as it uses "$gdb_prompt $" in
# testing the result. Our new prompt is ">", with
# no trailing space, so we can't do this just by
# changing "prompt".
#
# Anyway, I couldn't get expect to see the ">" prompt,
# during the command addition, so I just punted.
# _You_ are welcome to try, if you want!
#
send_gdb "commands 4\n"
gdb_expect {
-re "(.*Type commands.*\"end\"\.\r\n\>)" {
pass "start commands"
}
-re ".*$gdb_prompt $" {
fail "start commands"
}
}
# Assume we're in commands-input mode. (Self-debug stuff turned off)
#
send_gdb "silent\n"
#send_gdb "p id\n"
#send_gdb "p j\n"
#send_gdb "p x\[j\]\n"
send_gdb "set debugger_saw\[id\]\[j\] = x\[j\]\n"
send_gdb "continue\n"
send_gdb "end\n"
gdb_expect {
-re ".*set.*cont.*$gdb_prompt $" {
pass "add commands"
}
-re ".*$gdb_prompt $" {
fail "add commands"
}
}
# Check out of paranoia.
#
send_gdb "info break 4\n"
gdb_expect {
-re ".*breakpoint.*set debugger_saw.*continue.*$gdb_prompt $" {
pass "Commands added"
}
-re ".*$gdb_prompt $" {
fail "Commands not added."
}
}
# We now expect to run through the whole application
# Since this'll run for while, set a generous timeout.
#
set timeout [expr "$timeout + 30"]
send_gdb "c\n"
gdb_expect {
-re ".*Program exited normally.*$gdb_prompt $" {
fail "program runaway"
}
-re ".*Breakpoint 2.*67.*$gdb_prompt $" {
pass "get to end"
}
-re ".*$gdb_prompt $" {
fail "No progress?"
}
timeout { fail "timeout" }
}
set timeout $oldtimeout
gdb_test "p debugger_saw" ".*5, 1, 9.*4, 6, 10.*3, 7, 12.*2, 8, 11.*" "check results"
# Often only one misses; let's get detailed!
#
gdb_test "p debugger_saw\[0\]\[0\]" ".*= 5.*" "1"
gdb_test "p debugger_saw\[0\]\[1\]" ".*= 1.*" "2"
gdb_test "p debugger_saw\[0\]\[2\]" ".*= 9.*" "3"
gdb_test "p debugger_saw\[1\]\[0\]" ".*= 4.*" "4"
gdb_test "p debugger_saw\[1\]\[1\]" ".*= 6.*" "5"
gdb_test "p debugger_saw\[1\]\[2\]" ".*= 10.*" "6"
gdb_test "p debugger_saw\[2\]\[0\]" ".*= 3.*" "7"
gdb_test "p debugger_saw\[2\]\[1\]" ".*= 7.*" "8"
gdb_test "p debugger_saw\[2\]\[2\]" ".*= 12.*" "9"
gdb_test "p debugger_saw\[3\]\[0\]" ".*= 2.*" "10"
gdb_test "p debugger_saw\[3\]\[1\]" ".*= 8.*" "11"
gdb_test "p debugger_saw\[3\]\[2\]" ".*= 11.*" "12"
send_gdb "i th\n"
gdb_expect {
-re ".* 1.*system thread.* 2.*system thread.*$gdb_prompt $" {
fail "Too many threads left"
}
-re ".*\\\* 1.*system thread.*main.*$gdb_prompt $" {
pass "Expect only base thread"
}
-re ".*No stack.*$gdb_prompt $" {
fail "runaway"
}
-re ".*$gdb_prompt $" {
fail "Hunh?"
}
timeout { fail "timeout" }
}
gdb_test "c" ".*exited normally.*" "run to completion"
# Done!
#
gdb_exit
set timeout $oldtimeout
set verbose $oldverbose
# execute_anywhere "rm -f ${binfile}"
#
return 0