Commit 7faf7023 authored by Ian Lance Taylor's avatar Ian Lance Taylor

runtime: avoid endless loop if printing the panic value panics

Change-Id: I56de359a5ccdc0a10925cd372fa86534353c6ca0
Reviewed-on: https://go-review.googlesource.com/30358
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent efaa3601
...@@ -444,6 +444,13 @@ func TestPanicDeadlockSyscall(t *testing.T) { ...@@ -444,6 +444,13 @@ func TestPanicDeadlockSyscall(t *testing.T) {
testPanicDeadlock(t, "SyscallInPanic", "1\n2\npanic: 3\n\n") testPanicDeadlock(t, "SyscallInPanic", "1\n2\npanic: 3\n\n")
} }
func TestPanicLoop(t *testing.T) {
output := runTestProg(t, "testprog", "PanicLoop")
if want := "panic while printing panic value"; !strings.Contains(output, want) {
t.Errorf("output does not contain %q:\n%s", want, output)
}
}
func TestMemPprof(t *testing.T) { func TestMemPprof(t *testing.T) {
testenv.MustHaveGoRun(t) testenv.MustHaveGoRun(t)
......
...@@ -376,6 +376,11 @@ func Goexit() { ...@@ -376,6 +376,11 @@ func Goexit() {
// Used when crashing with panicking. // Used when crashing with panicking.
// This must match types handled by printany. // This must match types handled by printany.
func preprintpanics(p *_panic) { func preprintpanics(p *_panic) {
defer func() {
if recover() != nil {
throw("panic while printing panic value")
}
}()
for p != nil { for p != nil {
switch v := p.arg.(type) { switch v := p.arg.(type) {
case error: case error:
......
...@@ -32,6 +32,7 @@ func init() { ...@@ -32,6 +32,7 @@ func init() {
register("PanicTraceback", PanicTraceback) register("PanicTraceback", PanicTraceback)
register("GoschedInPanic", GoschedInPanic) register("GoschedInPanic", GoschedInPanic)
register("SyscallInPanic", SyscallInPanic) register("SyscallInPanic", SyscallInPanic)
register("PanicLoop", PanicLoop)
} }
func SimpleDeadlock() { func SimpleDeadlock() {
...@@ -214,3 +215,13 @@ func pt2() { ...@@ -214,3 +215,13 @@ func pt2() {
}() }()
panic("hello") panic("hello")
} }
type panicError struct{}
func (*panicError) Error() string {
panic("double error")
}
func PanicLoop() {
panic(&panicError{})
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment