aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.hp/thr-lib.exp
blob: e40b469c2dee4e660d69798a11299777025d5bdf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# 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
}

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