write stack traces and panics to stderr

R=rsc
DELTA=31  (5 added, 3 deleted, 23 changed)
OCL=35700
CL=35700
This commit is contained in:
Rob Pike 2009-10-13 22:48:03 -07:00
parent bf983a0df2
commit f6d67c9e95
5 changed files with 28 additions and 24 deletions

View File

@ -26,7 +26,7 @@ dump(byte *p, int32 n)
void void
prints(int8 *s) prints(int8 *s)
{ {
write(1, s, findnull((byte*)s)); write(fd, s, findnull((byte*)s));
} }
// Very simple printf. Only for debugging prints. // Very simple printf. Only for debugging prints.
@ -45,7 +45,7 @@ printf(int8 *s, ...)
if(*p != '%') if(*p != '%')
continue; continue;
if(p > lp) if(p > lp)
write(1, lp, p-lp); write(fd, lp, p-lp);
p++; p++;
narg = nil; narg = nil;
switch(*p) { switch(*p) {
@ -98,7 +98,7 @@ printf(int8 *s, ...)
lp = p+1; lp = p+1;
} }
if(p > lp) if(p > lp)
write(1, lp, p-lp); write(fd, lp, p-lp);
// unlock(&debuglock); // unlock(&debuglock);
} }
@ -115,10 +115,10 @@ void
sys·printbool(bool v) sys·printbool(bool v)
{ {
if(v) { if(v) {
write(1, (byte*)"true", 4); write(fd, (byte*)"true", 4);
return; return;
} }
write(1, (byte*)"false", 5); write(fd, (byte*)"false", 5);
} }
void void
@ -129,15 +129,15 @@ sys·printfloat(float64 v)
float64 h; float64 h;
if(isNaN(v)) { if(isNaN(v)) {
write(1, "NaN", 3); write(fd, "NaN", 3);
return; return;
} }
if(isInf(v, 0)) { if(isInf(v, 0)) {
write(1, "+Inf", 4); write(fd, "+Inf", 4);
return; return;
} }
if(isInf(v, -1)) { if(isInf(v, -1)) {
write(1, "+Inf", 4); write(fd, "+Inf", 4);
return; return;
} }
@ -196,7 +196,7 @@ sys·printfloat(float64 v)
buf[n+4] = (e/100) + '0'; buf[n+4] = (e/100) + '0';
buf[n+5] = (e/10)%10 + '0'; buf[n+5] = (e/10)%10 + '0';
buf[n+6] = (e%10) + '0'; buf[n+6] = (e%10) + '0';
write(1, buf, n+7); write(fd, buf, n+7);
} }
void void
@ -211,14 +211,14 @@ sys·printuint(uint64 v)
break; break;
v = v/10; v = v/10;
} }
write(1, buf+i, nelem(buf)-i); write(fd, buf+i, nelem(buf)-i);
} }
void void
sys·printint(int64 v) sys·printint(int64 v)
{ {
if(v < 0) { if(v < 0) {
write(1, "-", 1); write(fd, "-", 1);
v = -v; v = -v;
} }
sys·printuint(v); sys·printuint(v);
@ -238,7 +238,7 @@ sys·printhex(uint64 v)
buf[--i] = '0'; buf[--i] = '0';
buf[--i] = 'x'; buf[--i] = 'x';
buf[--i] = '0'; buf[--i] = '0';
write(1, buf+i, nelem(buf)-i); write(fd, buf+i, nelem(buf)-i);
} }
void void
@ -253,21 +253,21 @@ sys·printstring(String v)
extern int32 maxstring; extern int32 maxstring;
if(v.len > maxstring) { if(v.len > maxstring) {
write(1, "[invalid string]", 16); write(fd, "[invalid string]", 16);
return; return;
} }
if(v.len > 0) if(v.len > 0)
write(1, v.str, v.len); write(fd, v.str, v.len);
} }
void void
sys·printsp(void) sys·printsp(void)
{ {
write(1, " ", 1); write(fd, " ", 1);
} }
void void
sys·printnl(void) sys·printnl(void)
{ {
write(1, "\n", 1); write(fd, "\n", 1);
} }

View File

@ -6,6 +6,7 @@
int32 panicking = 0; int32 panicking = 0;
int32 maxround = sizeof(uintptr); int32 maxround = sizeof(uintptr);
int32 fd = 1;
int32 int32
gotraceback(void) gotraceback(void)
@ -23,6 +24,7 @@ sys·panicl(int32 lno)
{ {
uint8 *sp; uint8 *sp;
fd = 2;
if(panicking) { if(panicking) {
printf("double panic\n"); printf("double panic\n");
exit(3); exit(3);
@ -66,6 +68,7 @@ sys·throwinit(void)
void void
throw(int8 *s) throw(int8 *s)
{ {
fd = 2;
printf("throw: %s\n", s); printf("throw: %s\n", s);
sys·panicl(-1); sys·panicl(-1);
*(int32*)0 = 0; // not reached *(int32*)0 = 0; // not reached

View File

@ -312,6 +312,7 @@ int32 goidgen;
extern int32 gomaxprocs; extern int32 gomaxprocs;
extern int32 panicking; extern int32 panicking;
extern int32 maxround; extern int32 maxround;
extern int32 fd; // usually 1; set to 2 when panicking
int8* goos; int8* goos;
/* /*
@ -412,7 +413,8 @@ void lock(Lock*);
void unlock(Lock*); void unlock(Lock*);
/* /*
* sleep and wakeup on one-time events. * sleep and wakeup on one-time events, like
* Notification (but shorter to type).
* before any calls to notesleep or notewakeup, * before any calls to notesleep or notewakeup,
* must call noteclear to initialize the Note. * must call noteclear to initialize the Note.
* then, any number of threads can call notesleep * then, any number of threads can call notesleep

View File

@ -1,3 +1,5 @@
// $G $D/$F.go && $L $F.$A && ./$A.out
// Copyright 2009 The Go Authors. All rights reserved. // Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.

View File

@ -36,7 +36,6 @@ PATH=/bin:/usr/bin:/usr/local/bin:${GOBIN:-$HOME/bin}:`pwd`
RUNFILE=/tmp/gorun-$$-$USER RUNFILE=/tmp/gorun-$$-$USER
TMP1FILE=/tmp/gotest1-$$-$USER TMP1FILE=/tmp/gotest1-$$-$USER
TMP2FILE=/tmp/gotest2-$$-$USER TMP2FILE=/tmp/gotest2-$$-$USER
TMP3FILE=/tmp/gotest3-$$-$USER
# don't run the machine out of memory: limit individual processes to 4GB. # don't run the machine out of memory: limit individual processes to 4GB.
# on thresher, 3GB suffices to run the tests; with 2GB, peano fails. # on thresher, 3GB suffices to run the tests; with 2GB, peano fails.
@ -53,26 +52,24 @@ do
export F=$(basename $i .go) export F=$(basename $i .go)
export D=$dir export D=$dir
sed '/^\/\//!q' $i | sed 's@//@@; $d' |sed 's|./\$A.out|$E &|' >$RUNFILE sed '/^\/\//!q' $i | sed 's@//@@; $d' |sed 's|./\$A.out|$E &|' >$RUNFILE
if ! /usr/bin/time -p sh -c "sh $RUNFILE >$TMP1FILE 2>$TMP2FILE" 2>$TMP3FILE if ! /usr/bin/time -p sh -c "sh $RUNFILE >$TMP1FILE 2>&1" 2>$TMP2FILE
then then
echo echo
echo "===========" $i echo "===========" $i
cat $TMP1FILE cat $TMP1FILE
cat $TMP2FILE
echo >&2 fail: $i echo >&2 fail: $i
elif test -s $TMP1FILE || test -s $TMP2FILE elif test -s $TMP1FILE
then then
echo echo
echo "===========" $i echo "===========" $i
cat $TMP1FILE cat $TMP1FILE
cat $TMP2FILE
elif [ $dir = "bugs" ] elif [ $dir = "bugs" ]
then then
echo $i succeeded with no output. echo $i succeeded with no output.
else else
echo $i >>pass.out echo $i >>pass.out
fi fi
echo $(awk 'NR==1{print $2}' $TMP3FILE) $D/$F >>times.out echo $(awk 'NR==1{print $2}' $TMP2FILE) $D/$F >>times.out
done done
done | # clean up some stack noise done | # clean up some stack noise
egrep -v '^(r[0-9a-z]+|[cfg]s) +0x' | egrep -v '^(r[0-9a-z]+|[cfg]s) +0x' |
@ -90,7 +87,7 @@ case $failed in
1) 1)
echo FAIL echo FAIL
esac esac
rm -f $RUNFILE $TMP1FILE $TMP2FILE $TMP3FILE *.$A $A.out rm -f $RUNFILE $TMP1FILE $TMP2FILE *.$A $A.out
diffmsg="" diffmsg=""
if ! diff run.out golden.out if ! diff run.out golden.out
then then