2
|
1 |
#!/bin/sh
|
|
2 |
|
|
3 |
#
|
|
4 |
# Copyright 2002-2005 Sun Microsystems, Inc. All Rights Reserved.
|
|
5 |
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
6 |
#
|
|
7 |
# This code is free software; you can redistribute it and/or modify it
|
|
8 |
# under the terms of the GNU General Public License version 2 only, as
|
|
9 |
# published by the Free Software Foundation.
|
|
10 |
#
|
|
11 |
# This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
# version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
# accompanied this code).
|
|
16 |
#
|
|
17 |
# You should have received a copy of the GNU General Public License version
|
|
18 |
# 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
#
|
|
21 |
# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
# CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
# have any questions.
|
|
24 |
#
|
|
25 |
|
|
26 |
#
|
|
27 |
#
|
|
28 |
# jtreg runs this in a scratch dir.
|
|
29 |
# It (and runregress -no) sets these env vars:
|
|
30 |
# TESTSRC: The dir that contains this file
|
|
31 |
# TESTCLASSES: Where .class files are compiled to
|
|
32 |
# TESTJAVA: The jdk to run
|
|
33 |
#
|
|
34 |
# This is a 'library' script that is included by
|
|
35 |
# shell script test cases that want to run a .java file as the debuggee
|
|
36 |
# and use jdb as the debugger. This file contains
|
|
37 |
# several functions that support such a test.
|
|
38 |
|
|
39 |
# The caller script can also set these shell vars before
|
|
40 |
# including this file:
|
|
41 |
# pkg=<package name> To use a package, define it here and put
|
|
42 |
# package $pkg
|
|
43 |
# in your java file
|
|
44 |
# classname=<classnam> Omit this to use the default class name, 'shtest'.
|
|
45 |
|
|
46 |
# compileOptions=<string> compile options for at least the first compile,
|
|
47 |
# eg, compileOptions=-g
|
|
48 |
# compileOptions2=<string> Options for the 2nd, ..., compile. compileOptions1
|
|
49 |
# is used if this is not set. To use no compile
|
|
50 |
# options for the 2nd ... compiles, do
|
|
51 |
# compileOptions2=none
|
|
52 |
#
|
|
53 |
# mode=-Xcomp or mode=-Xint to run in these modes. These should not
|
|
54 |
# really be used since the tests are normally
|
|
55 |
# run in both modes.
|
|
56 |
# javacCmd=path-to-javac to use a non-standard javac for compiling
|
|
57 |
# compileOptions=<string> Options to pass to javac
|
|
58 |
#
|
|
59 |
# See RedefineException.sh as an example of a caller script.
|
|
60 |
#
|
|
61 |
# To do RedefineClasses operations, embed @1 tags in the .java
|
|
62 |
# file to tell this script how to modify it to produce the 2nd
|
|
63 |
# version of the .class file to be used in the redefine operation.
|
|
64 |
# Here are examples of each editting tag and what change
|
|
65 |
# it causes in the new file. Note that blanks are not preserved
|
|
66 |
# in these editing operations.
|
|
67 |
#
|
|
68 |
# @1 uncomment
|
|
69 |
# orig: // @1 uncomment gus = 89;
|
|
70 |
# new: gus = 89;
|
|
71 |
#
|
|
72 |
# @1 commentout
|
|
73 |
# orig: gus = 89 // @1 commentout
|
|
74 |
# new: // gus = 89 // @1 commentout
|
|
75 |
#
|
|
76 |
# @1 delete
|
|
77 |
# orig: gus = 89 // @1 delete
|
|
78 |
# new: entire line deleted
|
|
79 |
#
|
|
80 |
# @1 newline
|
|
81 |
# orig: gus = 89; // @1 newline gus++;
|
|
82 |
# new: gus = 89; //
|
|
83 |
# gus++;
|
|
84 |
#
|
|
85 |
# @1 replace
|
|
86 |
# orig: gus = 89; // @1 replace gus = 90;
|
|
87 |
# new: gus = 90;
|
|
88 |
#
|
|
89 |
# The only other tag supported is @1 breakpoint. The setbkpts function
|
|
90 |
# sets bkpts at all lines that contain this string.
|
|
91 |
#
|
|
92 |
# Currently, all these tags are start with @1. It is envisioned that this script
|
|
93 |
# could be ehanced to allow multiple cycles of redefines by allowing
|
|
94 |
# @2, @3, ... tags. IE, processing the @i tags in the ith version of
|
|
95 |
# the file will produce the i+1th version of the file.
|
|
96 |
#
|
|
97 |
# There are problem with jtreg leaving behind orphan java and jdb processes
|
|
98 |
# when this script is run. Sometimes, on some platforms, it just doesn't
|
|
99 |
# get them all killed properly.
|
|
100 |
# The solution is to put a magic word in the cmd lines of background java
|
|
101 |
# and jdb processes this script launches. We can then do the right kind
|
|
102 |
# of ps cmds to find all these processes and kill them. We do this by
|
|
103 |
# trapping the completion of this script.
|
|
104 |
#
|
|
105 |
# An associated problem is that our trap handler (cleanup) doesn't
|
|
106 |
# always get called when jtreg terminates a test. This can leave tests
|
|
107 |
# hanging but following tests should run ok because each test uses
|
|
108 |
# unique names for the port and temp files (based on the PID returned
|
|
109 |
# by $$).
|
|
110 |
#
|
|
111 |
# mks 6.2a on win 98 presents two problems:
|
|
112 |
# $! returns the PID as a negative number whereas ps returns
|
|
113 |
# it in the form 0xFFF.... This means our trick of
|
|
114 |
# of using $! to get the PIDs of the jdb and debuggee processes
|
|
115 |
# doesn't work. This will cause some error cases to fail
|
|
116 |
# with a jtreg timeout instead of failing more gracefully.
|
|
117 |
#
|
|
118 |
# There is no form of the ps command that will show the whole
|
|
119 |
# cmd line. Thus, the magic keyword trick doesn't work. We
|
|
120 |
# resort to just killing java.exe and jdb.exes
|
|
121 |
#
|
|
122 |
# pid usage:
|
|
123 |
# debuggeepid: used in jdb process to detect if debuggee has died.
|
|
124 |
# - waitForDebuggeeMsg: fail if debuggee is gone
|
|
125 |
#
|
|
126 |
# jdbpid: dofail: used to detect if in main process or jdb process
|
|
127 |
# waitforfinish: quit if the jdb process is gone
|
|
128 |
|
|
129 |
#killcmd=/bin/kill
|
|
130 |
killcmd=kill
|
|
131 |
|
|
132 |
# This can be increased if timing seems to be an issue.
|
|
133 |
sleep_seconds=1
|
|
134 |
|
|
135 |
echo "ShellScaffold.sh: Version" >& 2
|
|
136 |
topPid=$$
|
|
137 |
|
|
138 |
# Be careful to echo to >& in these general functions.
|
|
139 |
# If they are called from the functions that are sending
|
|
140 |
# cmds to jdb, then stdout is redirected to jdb.
|
|
141 |
cleanup()
|
|
142 |
{
|
|
143 |
if [ -r "$failFile" ] ; then
|
|
144 |
cat $failFile >& 2
|
|
145 |
fi
|
|
146 |
|
|
147 |
# Kill all processes that have our special
|
|
148 |
# keyword in their cmd line.
|
|
149 |
killOrphans cleanup $jdbKeyword
|
|
150 |
killOrphans cleanup $debuggeeKeyword
|
|
151 |
}
|
|
152 |
|
|
153 |
# Kill all processes with $2 in their cmd lines
|
|
154 |
# Print a msg about this using $1 as the prefix
|
|
155 |
killOrphans()
|
|
156 |
{
|
|
157 |
str=$2
|
|
158 |
|
|
159 |
if [ -z "$isCygwin" ] ; then
|
|
160 |
toBeKilled=`$psCmd | $grep -v grep | $grep -i $str | awk '{print $1}' | tr '\n\r' ' '`
|
|
161 |
else
|
|
162 |
# The cygwin ps command doesn't show the options passed to a cmd.
|
|
163 |
# We will use jps to get the win PID of the command, and
|
|
164 |
# then use ps to find the cygwin pid to be killed.
|
|
165 |
# The form of a ps output line is
|
|
166 |
# ^ ddddd dddd dddd dddd.*
|
|
167 |
# where the 4th digits are the win pid and the first
|
|
168 |
# are the cygwin pid.
|
|
169 |
if [ -r "$jdk/bin/$jstack" ] ; then
|
|
170 |
winPid=`$jdk/bin/jps -v | $grep -i $str | sed -e 's@ .*@@'`
|
|
171 |
if [ ! -z "$winPid" ] ; then
|
|
172 |
# Here is a way to kill using a win cmd and the win PID.
|
|
173 |
#echo "$1: taskkill /F $winPid" >& 2
|
|
174 |
#taskkill /F /PID $winPid
|
|
175 |
|
|
176 |
toBeKilled=`$psCmd | $grep -v grep | \
|
|
177 |
$grep '^ +[0-9]+ +[0-9]+ +[0-9]+ +'"$winPid" |\
|
|
178 |
awk '{print $1}' | tr '\n\r' ' '`
|
|
179 |
fi
|
|
180 |
else
|
|
181 |
# Well, too bad - we can't find what to kill.
|
|
182 |
toBeKilled=
|
|
183 |
fi
|
|
184 |
fi
|
|
185 |
|
|
186 |
if [ ! -z "$toBeKilled" ] ; then
|
|
187 |
echo "$1: kill -9 $toBeKilled" >& 2
|
|
188 |
kill -9 $toBeKilled
|
|
189 |
fi
|
|
190 |
}
|
|
191 |
|
|
192 |
findPid()
|
|
193 |
{
|
|
194 |
# Return 0 if $1 is the pid of a running process.
|
|
195 |
if [ -z "$isWin98" ] ; then
|
|
196 |
# Never use plain 'ps', which requires a "controlling terminal"
|
|
197 |
# and will fail with a "ps: no controlling terminal" error.
|
|
198 |
# Running under 'rsh' will cause this ps error.
|
|
199 |
# cygwin ps puts an I in column 1 for some reason.
|
|
200 |
$psCmd -e | $grep '^I* *'"$1 " > $devnull 2>&1
|
|
201 |
return $?
|
|
202 |
fi
|
|
203 |
|
|
204 |
# mks 6.2a on win98 has $! getting a negative
|
|
205 |
# number and in ps, it shows up as 0x...
|
|
206 |
# Thus, we can't search in ps output for
|
|
207 |
# PIDs gotten via $!
|
|
208 |
# We don't know if it is running or not - assume it is.
|
|
209 |
# We don't really care about win98 anymore.
|
|
210 |
return 0
|
|
211 |
}
|
|
212 |
|
|
213 |
setup()
|
|
214 |
{
|
|
215 |
failed=
|
|
216 |
# This is used to tag each java and jdb cmd we issue so
|
|
217 |
# we can kill them at the end of the run.
|
|
218 |
|
|
219 |
orphanKeyword=HANGINGJAVA-$$
|
|
220 |
debuggeeKeyword=${orphanKeyword}_DEB
|
|
221 |
jdbKeyword=${orphanKeyword}_JDB
|
|
222 |
baseArgs=-D${debuggeeKeyword}
|
|
223 |
if [ -z "$TESTCLASSES" ] ; then
|
|
224 |
echo "--Warning: TESTCLASSES is not defined; using TESTCLASSES=."
|
|
225 |
echo " You should run: "
|
|
226 |
echo " runregress $0 -no"
|
|
227 |
echo " or"
|
|
228 |
echo " (setenv TESTCLASSES .; $0 $*)"
|
|
229 |
TESTCLASSES=.
|
|
230 |
fi
|
|
231 |
if [ ! -z "$TESTJAVA" ] ; then
|
|
232 |
jdk="$TESTJAVA"
|
|
233 |
else
|
|
234 |
echo "--Error: TESTJAVA must be defined as the pathname of a jdk to test."
|
|
235 |
exit 1
|
|
236 |
fi
|
|
237 |
|
|
238 |
ulimitCmd=
|
|
239 |
osname=`uname -s`
|
|
240 |
isWin98=
|
|
241 |
isCygwin=
|
|
242 |
case "$osname" in
|
|
243 |
Windows* | CYGWIN*)
|
|
244 |
if [ "$osname" = Windows_98 -o "$osname" = Windows_ME ]; then
|
|
245 |
isWin98=1
|
|
246 |
debuggeeKeyword='we_cant_kill_debuggees_on_win98'
|
|
247 |
jdbKeyword='jdb\.exe'
|
|
248 |
fi
|
|
249 |
|
|
250 |
case "$osname" in
|
|
251 |
CYGWIN*)
|
|
252 |
isCygwin=1
|
|
253 |
;;
|
|
254 |
esac
|
|
255 |
|
|
256 |
if [ -r $jdk/bin/dt_shmem.dll -o -r $jdk/jre/bin/dt_shmem.dll ] ; then
|
|
257 |
transport=dt_shmem
|
|
258 |
address=kkkk.$$
|
|
259 |
else
|
|
260 |
transport=dt_socket
|
|
261 |
address=
|
|
262 |
fi
|
|
263 |
devnull=NUL
|
|
264 |
baseArgs="$baseArgs -XX:-ShowMessageBoxOnError"
|
|
265 |
# jtreg puts \\s in TESTCLASSES and some uses, eg. echo
|
|
266 |
# treat them as control chars on mks (eg \t is tab)
|
|
267 |
# Oops; windows mks really seems to want this cat line
|
|
268 |
# to start in column 1
|
|
269 |
if [ -w "$SystemRoot" ] ; then
|
|
270 |
tmpFile=$SystemRoot/tmp.$$
|
|
271 |
elif [ -w "$SYSTEMROOT" ] ; then
|
|
272 |
tmpFile=$SYSTEMROOT/tmp.$$
|
|
273 |
else
|
|
274 |
tmpFile=tmp.$$
|
|
275 |
fi
|
|
276 |
cat <<EOF >$tmpFile
|
|
277 |
$TESTCLASSES
|
|
278 |
EOF
|
|
279 |
TESTCLASSES=`cat $tmpFile | sed -e 's@\\\\@/@g'`
|
|
280 |
rm -f $tmpFile
|
|
281 |
# on mks
|
|
282 |
grep=egrep
|
|
283 |
psCmd=ps
|
|
284 |
jstack=jstack.exe
|
|
285 |
;;
|
|
286 |
SunOS | Linux)
|
|
287 |
transport=dt_socket
|
|
288 |
address=
|
|
289 |
devnull=/dev/null
|
|
290 |
grep=egrep
|
|
291 |
jstack=jstack
|
|
292 |
# On linux, core files take a long time, and can leave
|
|
293 |
# zombie processes
|
|
294 |
if [ "$osname" = SunOS ] ; then
|
|
295 |
psCmd="/usr/ucb/ps -axwww"
|
|
296 |
else
|
|
297 |
ulimit -c 0
|
|
298 |
# See bug 6238593.
|
|
299 |
psCmd="ps axwww"
|
|
300 |
fi
|
|
301 |
;;
|
|
302 |
*)
|
|
303 |
echo "--Error: Unknown result from 'uname -s': $osname"
|
|
304 |
exit 1
|
|
305 |
;;
|
|
306 |
esac
|
|
307 |
|
|
308 |
|
|
309 |
tmpFileDir=$TESTCLASSES/aa$$
|
|
310 |
TESTCLASSES=$tmpFileDir
|
|
311 |
|
|
312 |
mkdir -p $tmpFileDir
|
|
313 |
|
|
314 |
# This must not contain 'jdb' or it shows up
|
|
315 |
# in grep of ps output for some platforms
|
|
316 |
jdbOutFile=$tmpFileDir/jxdbOutput.txt
|
|
317 |
rm -f $jdbOutFile
|
|
318 |
touch $jdbOutFile
|
|
319 |
|
|
320 |
debuggeeOutFile=$tmpFileDir/debuggeeOutput.txt
|
|
321 |
failFile=$tmpFileDir/testFailed
|
|
322 |
debuggeepidFile=$tmpFileDir/debuggeepid
|
|
323 |
rm -f $failFile $debuggeepidFile
|
|
324 |
|
|
325 |
if [ -z "$pkg" ] ; then
|
|
326 |
pkgSlash=
|
|
327 |
pkgDot=
|
|
328 |
redefineSubdir=.
|
|
329 |
else
|
|
330 |
pkgSlash=$pkg/
|
|
331 |
pkgDot=$pkg.
|
|
332 |
redefineSubdir=$pkgSlash
|
|
333 |
fi
|
|
334 |
if [ -z "$classname" ] ; then
|
|
335 |
classname=shtest
|
|
336 |
fi
|
|
337 |
|
|
338 |
if [ -z "$java" ] ; then
|
|
339 |
java=java
|
|
340 |
fi
|
|
341 |
|
|
342 |
if [ -z "$jdb" ] ; then
|
|
343 |
jdb=$jdk/bin/jdb
|
|
344 |
fi
|
|
345 |
|
|
346 |
####################################################3
|
|
347 |
####################################################3
|
|
348 |
####################################################3
|
|
349 |
####################################################3
|
|
350 |
# sol: this gets all processes killed but
|
|
351 |
# no jstack
|
|
352 |
# linux same as above
|
|
353 |
# win mks: No dice; processes still running
|
|
354 |
trap "cleanup" 0 1 2 3 4 6 9 10 15
|
|
355 |
|
|
356 |
jdbOptions="$jdbOptions -J-D${jdbKeyword}"
|
|
357 |
}
|
|
358 |
|
|
359 |
docompile()
|
|
360 |
{
|
|
361 |
if [ "$compile" = 0 ] ; then
|
|
362 |
return
|
|
363 |
fi
|
|
364 |
saveDir=`pwd`
|
|
365 |
cd $tmpFileDir
|
|
366 |
rm -f *.java
|
|
367 |
createJavaFile $classname
|
|
368 |
|
|
369 |
# Compile two versions of the file, the original and with the
|
|
370 |
# indicated lines modified.
|
|
371 |
cp $classname.java.1 $classname.java
|
|
372 |
echo "--Compiling first version of `pwd`/$classname.java with options: $compileOptions"
|
|
373 |
# Result is in $pkgSlash$classname.class
|
|
374 |
|
|
375 |
if [ -z "$javacCmd" ] ; then
|
|
376 |
javacCmd=$jdk/bin/javac
|
|
377 |
fi
|
|
378 |
|
|
379 |
echo "compiling " `ls *.java`
|
|
380 |
$javacCmd $compileOptions -d . *.java
|
|
381 |
if [ $? != 0 ] ; then
|
|
382 |
dofail "First compile failed"
|
|
383 |
fi
|
|
384 |
if [ -r vers1 ] ; then
|
|
385 |
rm -rf vers1
|
|
386 |
fi
|
|
387 |
mkdir -p vers1
|
|
388 |
mv *.class vers1
|
|
389 |
if [ ! -z "$compileOptions2" ] ; then
|
|
390 |
if [ "$compileOptions2" = none ] ; then
|
|
391 |
compileOptions=
|
|
392 |
else
|
|
393 |
compileOptions=$compileOptions2
|
|
394 |
fi
|
|
395 |
fi
|
|
396 |
|
|
397 |
while [ 1 = 1 ] ; do
|
|
398 |
# Not really a loop; just a way to avoid goto
|
|
399 |
# by using breaks
|
|
400 |
sed -e '/@1 *delete/ d' \
|
|
401 |
-e 's! *// *@1 *uncomment! !' \
|
|
402 |
-e 's!\(.*@1 *commentout\)!//\1!' \
|
|
403 |
-e 's/@1 *newline/\
|
|
404 |
/' \
|
|
405 |
-e 's/.*@1 *replace//' \
|
|
406 |
$classname.java.1 >$classname.java
|
|
407 |
|
|
408 |
cmp -s $classname.java.1 $classname.java
|
|
409 |
if [ $? = 0 ] ; then
|
|
410 |
break
|
|
411 |
fi
|
|
412 |
echo
|
|
413 |
echo "--Compiling second version of `pwd`/$classname.java with $compileOptions"
|
|
414 |
$javacCmd $compileOptions -d . $classname.java
|
|
415 |
if [ $? != 0 ] ; then
|
|
416 |
dofail "Second compile failed"
|
|
417 |
fi
|
|
418 |
if [ -r vers2 ] ; then
|
|
419 |
rm -rf vers2
|
|
420 |
fi
|
|
421 |
mkdir -p vers2
|
|
422 |
mv *.class vers2
|
|
423 |
mv $classname.java $classname.java.2
|
|
424 |
cp $classname.java.1 $classname.java
|
|
425 |
|
|
426 |
###### Do the same for @2, and @3 allowing 3 redefines to occur.
|
|
427 |
###### If I had more time to write sed cmds, I would do
|
|
428 |
###### this in a loop. But, I don't think we will ever need
|
|
429 |
###### more than 3 redefines.
|
|
430 |
sed -e '/@2 *delete/ d' \
|
|
431 |
-e 's! *// *@2 *uncomment! !' \
|
|
432 |
-e 's!\(.*@2 *commentout\)!//\1!' \
|
|
433 |
-e 's/@2 *newline/\
|
|
434 |
/' \
|
|
435 |
-e 's/.*@2 *replace//' \
|
|
436 |
$classname.java.2 >$classname.java
|
|
437 |
cmp -s $classname.java.2 $classname.java
|
|
438 |
if [ $? = 0 ] ; then
|
|
439 |
break
|
|
440 |
fi
|
|
441 |
echo
|
|
442 |
echo "--Compiling third version of `pwd`/$classname.java with $compileOptions"
|
|
443 |
$javacCmd $compileOptions -d . $classname.java
|
|
444 |
if [ $? != 0 ] ; then
|
|
445 |
dofail "Third compile failed"
|
|
446 |
fi
|
|
447 |
if [ -r vers3 ] ; then
|
|
448 |
rm -rf vers3
|
|
449 |
fi
|
|
450 |
mkdir -p vers3
|
|
451 |
mv *.class vers3
|
|
452 |
mv $classname.java $classname.java.3
|
|
453 |
cp $classname.java.1 $classname.java
|
|
454 |
|
|
455 |
########
|
|
456 |
sed -e '/@3 *delete/ d' \
|
|
457 |
-e 's! *// *@3 *uncomment! !' \
|
|
458 |
-e 's!\(.*@3 *commentout\)!//\1!' \
|
|
459 |
-e 's/@3 *newline/\
|
|
460 |
/' \
|
|
461 |
-e 's/.*@3 *replace//' \
|
|
462 |
$classname.java.3 >$classname.java
|
|
463 |
cmp -s $classname.java.3 $classname.java
|
|
464 |
if [ $? = 0 ] ; then
|
|
465 |
break
|
|
466 |
fi
|
|
467 |
echo
|
|
468 |
echo "--Compiling fourth version of `pwd`/$classname.java with $compileOptions"
|
|
469 |
$javacCmd $compileOptions -d . $classname.java
|
|
470 |
if [ $? != 0 ] ; then
|
|
471 |
dofail "fourth compile failed"
|
|
472 |
fi
|
|
473 |
if [ -r vers4 ] ; then
|
|
474 |
rm -rf vers4
|
|
475 |
fi
|
|
476 |
mkdir -p vers4
|
|
477 |
mv *.class vers4
|
|
478 |
mv $classname.java $classname.java.4
|
|
479 |
cp $classname.java.1 $classname.java
|
|
480 |
break
|
|
481 |
fgrep @4 $classname.java
|
|
482 |
if [ $? = 0 ] ; then
|
|
483 |
echo "--Error: @4 and above are not yet allowed"
|
|
484 |
exit 1
|
|
485 |
fi
|
|
486 |
done
|
|
487 |
|
|
488 |
cp vers1/* $redefineSubdir
|
|
489 |
cd $saveDir
|
|
490 |
}
|
|
491 |
|
|
492 |
# Send a cmd to jdb and wait for the jdb prompt to appear.
|
|
493 |
# We don't want to allow > as a prompt because if the debuggee
|
|
494 |
# runs for awhile after a command, jdb will show this prompt
|
|
495 |
# but is not really ready to accept another command for the
|
|
496 |
# debuggee - ie, a cont in this state will be ignored.
|
|
497 |
# If it ever becomes necessary to send a jdb command before
|
|
498 |
# a main[10] form of prompt appears, then this
|
|
499 |
# code will have to be modified.
|
|
500 |
cmd()
|
|
501 |
{
|
|
502 |
if [ $1 = quit -o -r "$failFile" ] ; then
|
|
503 |
# if jdb got a cont cmd that caused the debuggee
|
|
504 |
# to run to completion, jdb can be gone before
|
|
505 |
# we get here.
|
|
506 |
echo quit >& 2
|
|
507 |
echo quit
|
|
508 |
# See 6562090. Maybe there is a way that the exit
|
|
509 |
# can cause jdb to not get the quit.
|
|
510 |
sleep 5
|
|
511 |
exit 1
|
|
512 |
fi
|
|
513 |
|
|
514 |
# $jdbOutFile always exists here and is non empty
|
|
515 |
# because after starting jdb, we waited
|
|
516 |
# for the prompt.
|
|
517 |
fileSize=`wc -c $jdbOutFile | awk '{ print $1 }'`
|
|
518 |
echo $* >&2
|
|
519 |
|
|
520 |
# jjh: We have a few intermittent failures here.
|
|
521 |
# It is as if every so often, jdb doesn't
|
|
522 |
# get the first cmd that is sent to it here.
|
|
523 |
# (actually, I have seen it get the first cmd ok,
|
|
524 |
# but then not get some subsequent cmd).
|
|
525 |
# It seems like jdb really doesn't get the cmd; jdb's response
|
|
526 |
# does not appear in the jxdboutput file. It contains:
|
|
527 |
# main[1]
|
|
528 |
# The application has been disconnected
|
|
529 |
|
|
530 |
# Is it possible
|
|
531 |
# that jdb got the cmd ok, but its response didn't make
|
|
532 |
# it to the jxdboutput file? If so, why did 'The application
|
|
533 |
# has been disconnected' make it?
|
|
534 |
|
|
535 |
# This causes the following loop to timeout and the test to fail.
|
|
536 |
# The above echo works because the cmd (stop at ...)
|
|
537 |
# is in the System.err shown in the .jtr file.
|
|
538 |
# Also, the cmd is shown in the 'jdb never responded ...'
|
|
539 |
# msg output below after the timeout.
|
|
540 |
# And, we know jdb is started because the main[1] output is in the .jtr
|
|
541 |
# file. And, we wouldn't have gotten here if mydojdbcmds hadn't
|
|
542 |
# seen the ].
|
|
543 |
echo $*
|
|
544 |
|
|
545 |
# wait for jdb output to appear
|
|
546 |
count=0
|
|
547 |
msg1=`echo At start: cmd/size/waiting : $* / $fileSize / \`date\``
|
|
548 |
while [ 1 = 1 ] ; do
|
|
549 |
newFileSize=`wc -c $jdbOutFile | awk '{ print $1 } '`
|
|
550 |
if [ "$fileSize" != "$newFileSize" ] ; then
|
|
551 |
break
|
|
552 |
fi
|
|
553 |
sleep ${sleep_seconds}
|
|
554 |
count=`expr $count + 1`
|
|
555 |
if [ $count = 30 -o $count = 60 ] ; then
|
|
556 |
# record some debug info.
|
|
557 |
echo "--DEBUG: jdb $$ didn't responded to command in $count secs: $*" >& 2
|
|
558 |
echo "--DEBUG:" $msg1 >& 2
|
|
559 |
echo "--DEBUG: "done size/waiting : / $newFileSize / `date` >& 2
|
|
560 |
$psCmd | sed -e '/com.sun.javatest/d' -e '/nsk/d' >& 2
|
|
561 |
if [ $count = 60 ] ; then
|
|
562 |
dofail "jdb never responded to command: $*"
|
|
563 |
fi
|
|
564 |
fi
|
|
565 |
done
|
|
566 |
|
|
567 |
waitForJdbMsg '^.*\[[0-9]*\] $' 1 allowExit
|
|
568 |
}
|
|
569 |
|
|
570 |
setBkpts()
|
|
571 |
{
|
|
572 |
# Can set multiple bkpts, but only in one class.
|
|
573 |
# $1 is the bkpt name, eg, @1
|
|
574 |
allLines=`$grep -n "$1 *breakpoint" $tmpFileDir/$classname.java.1 | sed -e 's@^\([0-9]*\).*@\1@g'`
|
|
575 |
for ii in $allLines ; do
|
|
576 |
cmd stop at $pkgDot$classname:$ii
|
|
577 |
done
|
|
578 |
}
|
|
579 |
|
|
580 |
runToBkpt()
|
|
581 |
{
|
|
582 |
cmd run
|
|
583 |
# Wait for jdb to hit the bkpt
|
|
584 |
waitForJdbMsg "Breakpoint hit" 5
|
|
585 |
}
|
|
586 |
|
|
587 |
contToBkpt()
|
|
588 |
{
|
|
589 |
cmd cont
|
|
590 |
# Wait for jdb to hit the bkpt
|
|
591 |
waitForJdbMsg "Breakpoint hit" 5
|
|
592 |
}
|
|
593 |
|
|
594 |
|
|
595 |
# Wait until string $1 appears in the output file, within the last $2 lines
|
|
596 |
# If $3 is allowExit, then don't fail if jdb exits before
|
|
597 |
# the desired string appears.
|
|
598 |
waitForJdbMsg()
|
|
599 |
{
|
|
600 |
# This can be called from the jdb thread which doesn't
|
|
601 |
# have access to $debuggeepid, so we have to read it from the file.
|
|
602 |
nlines=$2
|
|
603 |
allowExit="$3"
|
|
604 |
myCount=0
|
|
605 |
timeLimit=40 # wait a max of 40 secs for a response from a jdb command
|
|
606 |
while [ 1 = 1 ] ; do
|
|
607 |
if [ -r $jdbOutFile ] ; then
|
|
608 |
# Something here causes jdb to complain about Unrecognized cmd on x86.
|
|
609 |
tail -$nlines $jdbOutFile | $grep -s "$1" > $devnull 2>&1
|
|
610 |
if [ $? = 0 ] ; then
|
|
611 |
# Found desired string
|
|
612 |
break
|
|
613 |
fi
|
|
614 |
fi
|
|
615 |
tail -2 $jdbOutFile | $grep -s "The application exited" > $devnull 2>&1
|
|
616 |
if [ $? = 0 ] ; then
|
|
617 |
# Found 'The application exited'
|
|
618 |
if [ ! -z "$allowExit" ] ; then
|
|
619 |
break
|
|
620 |
fi
|
|
621 |
# Otherwise, it is an error if we don't find $1
|
|
622 |
if [ -r $jdbOutFile ] ; then
|
|
623 |
tail -$nlines $jdbOutFile | $grep -s "$1" > $devnull 2>&1
|
|
624 |
if [ $? = 0 ] ; then
|
|
625 |
break
|
|
626 |
fi
|
|
627 |
fi
|
|
628 |
dofail "Waited for jdb msg $1, but it never appeared"
|
|
629 |
fi
|
|
630 |
|
|
631 |
sleep ${sleep_seconds}
|
|
632 |
findPid $topPid
|
|
633 |
if [ $? != 0 ] ; then
|
|
634 |
# Top process is dead. We better die too
|
|
635 |
dojstack
|
|
636 |
exit 1
|
|
637 |
fi
|
|
638 |
|
|
639 |
myCount=`expr $myCount + ${sleep_seconds}`
|
|
640 |
if [ $myCount -gt $timeLimit ] ; then
|
|
641 |
dojstack
|
|
642 |
echo "--Fail: waitForJdbMsg timed out after $timeLimit seconds; exitting" >> $failFile
|
|
643 |
exit 1
|
|
644 |
fi
|
|
645 |
done
|
|
646 |
|
|
647 |
}
|
|
648 |
|
|
649 |
# $1 is the string to print. If $2 exists,
|
|
650 |
# it is the name of a file to print, ie, the name
|
|
651 |
# of the file that contains the $1 string.
|
|
652 |
dofail()
|
|
653 |
{
|
|
654 |
if [ ! -z "$jdbpid" ] ; then
|
|
655 |
# we are in the main process instead of the jdb process
|
|
656 |
echo " " >> $failFile
|
|
657 |
echo "--Fail: main: $*" >> $failFile
|
|
658 |
else
|
|
659 |
# Kill the debuggee ; it could be hung so
|
|
660 |
# we want to get rid of it as soon as possible.
|
|
661 |
killOrphans "killing debuggee" $debuggeeKeyword
|
|
662 |
|
|
663 |
echo " " >>$failFile
|
|
664 |
echo "--Fail: $*" >> $failFile
|
|
665 |
echo quit
|
|
666 |
fi
|
|
667 |
if [ ! -z "$2" ] ; then
|
|
668 |
echo "---- contents of $2 follows -------" >> $failFile
|
|
669 |
cat "$2" >> $failFile
|
|
670 |
echo "---------------" >>$failFile
|
|
671 |
fi
|
|
672 |
exit 1
|
|
673 |
}
|
|
674 |
|
|
675 |
|
|
676 |
redefineClass()
|
|
677 |
{
|
|
678 |
if [ -z "$1" ] ; then
|
|
679 |
vers=2
|
|
680 |
else
|
|
681 |
vers=`echo $1 | sed -e 's/@//'`
|
|
682 |
vers=`expr $vers + 1`
|
|
683 |
fi
|
|
684 |
|
|
685 |
cmd redefine $pkgDot$classname $tmpFileDir/vers$vers/$classname.class
|
|
686 |
|
|
687 |
cp $tmpFileDir/$classname.java.$vers \
|
|
688 |
$tmpFileDir/$classname.java
|
|
689 |
}
|
|
690 |
|
|
691 |
mydojdbCmds()
|
|
692 |
{
|
|
693 |
# Wait for jdb to start before we start sending cmds
|
|
694 |
waitForJdbMsg ']' 1
|
|
695 |
dojdbCmds
|
|
696 |
cmd quit
|
|
697 |
}
|
|
698 |
|
|
699 |
startJdb()
|
|
700 |
{
|
|
701 |
if [ ! -r "$jdb" -a ! -r "$jdb.exe" ] ; then
|
|
702 |
dofail "$jdb does not exist"
|
|
703 |
fi
|
|
704 |
echo
|
|
705 |
echo "--Starting jdb, address=$address"
|
|
706 |
if [ -z "$address" ] ; then
|
|
707 |
# Let jdb choose the port and write it to stdout
|
|
708 |
mydojdbCmds | $jdb $jdbOptions -listenany | tee $jdbOutFile &
|
|
709 |
|
|
710 |
while [ 1 ] ; do
|
|
711 |
lastLine=`$grep 'Listening at address' $jdbOutFile`
|
|
712 |
if [ ! -z "$lastLine" ] ; then
|
|
713 |
break
|
|
714 |
fi
|
|
715 |
sleep 1
|
|
716 |
done
|
|
717 |
# jjh: we got the address ok, and seemed to start the debuggee
|
|
718 |
address=`echo $lastLine | sed -e 's@.*: *@@'`
|
|
719 |
else
|
|
720 |
mydojdbCmds | $jdb $jdbOptions -listen $address | tee $jdbOutFile &
|
|
721 |
fi
|
|
722 |
#echo address = $address
|
|
723 |
|
|
724 |
|
|
725 |
# this gets the pid of tee, at least it does on solaris
|
|
726 |
jdbpid=$!
|
|
727 |
|
|
728 |
# This fails on linux because there is an entry for each thread in jdb
|
|
729 |
# so we get a list of numbers in jdbpid
|
|
730 |
# jdbpid=`$psCmd | $grep -v grep | $grep ${orphanKeyword}_JDB | awk '{print $1}' | tr '\n\r' ' '`
|
|
731 |
}
|
|
732 |
|
|
733 |
startDebuggee()
|
|
734 |
{
|
|
735 |
args=
|
|
736 |
# Note that @debuggeeVMOptions is unique to a test run instead of
|
|
737 |
# a test in a run. It is not modified during a test run.
|
|
738 |
if [ -r $TESTCLASSES/../@debuggeeVMOptions ] ; then
|
|
739 |
args=`cat $TESTCLASSES/../@debuggeeVMOptions`
|
|
740 |
fi
|
|
741 |
|
|
742 |
if [ ! -z "$args" ] ; then
|
|
743 |
echo "--Starting debuggee with args from @debuggeeVMOptions: $args"
|
|
744 |
else
|
|
745 |
echo "--Starting debuggee"
|
|
746 |
fi
|
|
747 |
|
|
748 |
debuggeepid=
|
|
749 |
waitForJdbMsg Listening 4
|
|
750 |
|
|
751 |
beOption="-agentlib:jdwp=transport=$transport,address=$address,server=n,suspend=y"
|
|
752 |
# beOption="-Xdebug -Xrunjdwp:transport=$transport,address=$address,server=n,suspend=y"
|
|
753 |
|
|
754 |
thecmd="$jdk/bin/$java $mode -classpath $tmpFileDir $baseArgs $args \
|
|
755 |
-Djtreg.classDir=$TESTCLASSES \
|
|
756 |
-showversion \
|
|
757 |
$beOption \
|
|
758 |
$pkgDot$classname"
|
|
759 |
echo "Cmd: $thecmd"
|
|
760 |
|
|
761 |
sh -c "$thecmd | tee $debuggeeOutFile" &
|
|
762 |
|
|
763 |
# Note that the java cmd and the tee cmd will be children of
|
|
764 |
# the sh process. We can use that to find them to kill them.
|
|
765 |
debuggeepid=$!
|
|
766 |
|
|
767 |
# Save this in a place where the jdb process can find it.
|
|
768 |
# Note that it is possible for the java cmd to abort during startup
|
|
769 |
# due to a bad classpath or whatever.
|
|
770 |
echo $debuggeepid > $debuggeepidFile
|
|
771 |
}
|
|
772 |
|
|
773 |
dojstack()
|
|
774 |
{
|
|
775 |
if [ -r "$jdk/bin/$jstack" ] ; then
|
|
776 |
# If jstack exists, so will jps
|
|
777 |
# Show stack traces of jdb and debuggee as a possible debugging aid.
|
|
778 |
jdbCmd=`$jdk/bin/jps -v | $grep $jdbKeyword`
|
|
779 |
realJdbPid=`echo "$jdbCmd" | sed -e 's@ TTY.*@@'`
|
|
780 |
if [ ! -z "$realJdbPid" ] ; then
|
|
781 |
echo "-- jdb process info ----------------------" >&2
|
|
782 |
echo " $jdbCmd" >&2
|
|
783 |
echo "-- jdb threads: jstack $realJdbPid" >&2
|
|
784 |
$jdk/bin/$jstack $realJdbPid >&2
|
|
785 |
echo "------------------------------------------" >&2
|
|
786 |
echo >&2
|
|
787 |
fi
|
|
788 |
debuggeeCmd=`$jdk/bin/jps -v | $grep $debuggeeKeyword`
|
|
789 |
realDebuggeePid=`echo "$debuggeeCmd" | sed -e 's@ .*@@'`
|
|
790 |
if [ ! -z "$realDebuggeePid" ] ; then
|
|
791 |
if [ -r "$jdk/lib/sa-jdi.jar" ] ; then
|
|
792 |
# disableVersionCheck can be removed after 6475822
|
|
793 |
# is fixed.
|
|
794 |
moption="-m -J-Dsun.jvm.hotspot.runtime.VM.disableVersionCheck"
|
|
795 |
else
|
|
796 |
moption=
|
|
797 |
fi
|
|
798 |
|
|
799 |
echo "-- debuggee process info ----------------------" >&2
|
|
800 |
echo " $debuggeeCmd" >&2
|
|
801 |
echo "-- debuggee threads: jstack $moption $realDebuggeePid" >&2
|
|
802 |
$jdk/bin/$jstack $moption $realDebuggeePid >&2
|
|
803 |
echo "=============================================" >&2
|
|
804 |
echo >&2
|
|
805 |
fi
|
|
806 |
fi
|
|
807 |
}
|
|
808 |
|
|
809 |
waitForFinish()
|
|
810 |
{
|
|
811 |
# This is the main process
|
|
812 |
# Wait for the jdb process to finish, or some error to occur
|
|
813 |
|
|
814 |
while [ 1 = 1 ] ; do
|
|
815 |
findPid $jdbpid
|
|
816 |
if [ $? != 0 ] ; then
|
|
817 |
break
|
|
818 |
fi
|
|
819 |
if [ ! -z "$isWin98" ] ; then
|
|
820 |
$psCmd | $grep -i 'JDB\.EXE' >$devnull 2>&1
|
|
821 |
if [ $? != 0 ] ; then
|
|
822 |
break;
|
|
823 |
fi
|
|
824 |
fi
|
|
825 |
$grep -s 'Input stream closed' $jdbOutFile > $devnull 2>&1
|
|
826 |
if [ $? = 0 ] ; then
|
|
827 |
#something went wrong
|
|
828 |
dofail "jdb input stream closed prematurely"
|
|
829 |
fi
|
|
830 |
|
|
831 |
# If a failure has occured, quit
|
|
832 |
if [ -r "$failFile" ] ; then
|
|
833 |
break
|
|
834 |
fi
|
|
835 |
|
|
836 |
sleep ${sleep_seconds}
|
|
837 |
done
|
|
838 |
|
|
839 |
if [ -r "$failFile" ] ; then
|
|
840 |
exit 1
|
|
841 |
fi
|
|
842 |
}
|
|
843 |
|
|
844 |
# $1 is the filename, $2 is the string to look for,
|
|
845 |
# $3 is the number of lines to search (from the end)
|
|
846 |
grepForString()
|
|
847 |
{
|
|
848 |
# See bug 6220903. Sometimes the jdb '> ' prompt chars
|
|
849 |
# get inserted into the string we are searching for
|
|
850 |
# so ignore those chars.
|
|
851 |
if [ -z "$3" ] ; then
|
|
852 |
case "$2" in
|
|
853 |
*\>*)
|
|
854 |
# Target string contains a > so we better
|
|
855 |
# not ignore it
|
|
856 |
$grep -s "$2" $1 > $devnull 2>&1
|
|
857 |
stat=$?
|
|
858 |
;;
|
|
859 |
*)
|
|
860 |
# Target string does not contain a >.
|
|
861 |
# Ignore > and '> ' in the file.
|
|
862 |
cat $1 | sed -e 's@> @@g' -e 's@>@@g' | $grep -s "$2" > $devnull 2>&1
|
|
863 |
stat=$?
|
|
864 |
esac
|
|
865 |
else
|
|
866 |
case "$2" in
|
|
867 |
*\>*)
|
|
868 |
# Target string contains a > so we better
|
|
869 |
# not ignore it
|
|
870 |
tail -$3 $1 | $grep -s "$2" > $devnull 2>&1
|
|
871 |
stat=$?
|
|
872 |
;;
|
|
873 |
*)
|
|
874 |
# Target string does not contain a >.
|
|
875 |
# Ignore > and '> ' in the file.
|
|
876 |
tail -$3 $1 | sed -e 's@> @@g' -e 's@>@@g' | $grep -s "$2" > $devnull 2>&1
|
|
877 |
stat=$?
|
|
878 |
;;
|
|
879 |
esac
|
|
880 |
fi
|
|
881 |
return $stat
|
|
882 |
}
|
|
883 |
|
|
884 |
# $1 is the filename, $2 is the string to look for,
|
|
885 |
# $3 is the number of lines to search (from the end)
|
|
886 |
failIfPresent()
|
|
887 |
{
|
|
888 |
if [ -r "$1" ] ; then
|
|
889 |
grepForString "$1" "$2" "$3"
|
|
890 |
if [ $? = 0 ] ; then
|
|
891 |
dofail "Error output found: \"$2\" in $1" $1
|
|
892 |
fi
|
|
893 |
fi
|
|
894 |
}
|
|
895 |
|
|
896 |
# $1 is the filename, $2 is the string to look for
|
|
897 |
# $3 is the number of lines to search (from the end)
|
|
898 |
failIfNotPresent()
|
|
899 |
{
|
|
900 |
if [ ! -r "$1" ] ; then
|
|
901 |
dofail "Required output \"$2\" not found in $1"
|
|
902 |
fi
|
|
903 |
grepForString "$1" "$2" "$3"
|
|
904 |
if [ $? != 0 ] ; then
|
|
905 |
dofail "Required output \"$2\" not found in $1" $1
|
|
906 |
fi
|
|
907 |
|
|
908 |
}
|
|
909 |
|
|
910 |
# fail if $1 is not in the jdb output
|
|
911 |
# $2 is the number of lines to search (from the end)
|
|
912 |
jdbFailIfNotPresent()
|
|
913 |
{
|
|
914 |
failIfNotPresent $jdbOutFile "$1" $2
|
|
915 |
}
|
|
916 |
|
|
917 |
# fail if $1 is not in the debuggee output
|
|
918 |
# $2 is the number of lines to search (from the end)
|
|
919 |
debuggeeFailIfNotPresent()
|
|
920 |
{
|
|
921 |
failIfNotPresent $debuggeeOutFile "$1" $2
|
|
922 |
}
|
|
923 |
|
|
924 |
# fail if $1 is in the jdb output
|
|
925 |
# $2 is the number of lines to search (from the end)
|
|
926 |
jdbFailIfPresent()
|
|
927 |
{
|
|
928 |
failIfPresent $jdbOutFile "$1" $2
|
|
929 |
}
|
|
930 |
|
|
931 |
# fail if $1 is in the debuggee output
|
|
932 |
# $2 is the number of lines to search (from the end)
|
|
933 |
debuggeeFailIfPresent()
|
|
934 |
{
|
|
935 |
failIfPresent $debuggeeOutFile "$1" $2
|
|
936 |
}
|
|
937 |
|
|
938 |
# This should really be named 'done' instead of pass.
|
|
939 |
pass()
|
|
940 |
{
|
|
941 |
if [ ! -r "$failFile" ] ; then
|
|
942 |
echo
|
|
943 |
echo "--Done: test passed"
|
|
944 |
exit 0
|
|
945 |
fi
|
|
946 |
}
|
|
947 |
|
|
948 |
runit()
|
|
949 |
{
|
|
950 |
setup
|
|
951 |
runitAfterSetup
|
|
952 |
}
|
|
953 |
|
|
954 |
runitAfterSetup()
|
|
955 |
{
|
|
956 |
docompile
|
|
957 |
startJdb
|
|
958 |
startDebuggee
|
|
959 |
waitForFinish
|
|
960 |
|
|
961 |
# in hs_err file from 1.3.1
|
|
962 |
debuggeeFailIfPresent "Virtual Machine Error"
|
|
963 |
|
|
964 |
# in hs_err file from 1.4.2, 1.5: An unexpected error
|
|
965 |
debuggeeFailIfPresent "An unexpected error"
|
|
966 |
|
|
967 |
# in hs_err file from 1.4.2, 1.5: Internal error
|
|
968 |
debuggeeFailIfPresent "Internal error"
|
|
969 |
|
|
970 |
|
|
971 |
# Don't know how this arises
|
|
972 |
debuggeeFailIfPresent "An unexpected exception"
|
|
973 |
|
|
974 |
# Don't know how this arises
|
|
975 |
debuggeeFailIfPresent "Internal exception"
|
|
976 |
}
|
|
977 |
|
|
978 |
|