diff options
| author | Shenghou Ma <minux@golang.org> | 2016-02-21 13:56:08 -0500 |
|---|---|---|
| committer | Minux Ma <minux@golang.org> | 2016-02-21 20:18:51 +0000 |
| commit | e960302410fafaf595c1ad92c28c61da3a254d63 (patch) | |
| tree | 33379b0279e0f9afbff63bd9b7255de63ff2dd79 /src/runtime/panic.go | |
| parent | bc8458ab02878ae64af860f1cade78b6fa97e994 (diff) | |
| download | go-e960302410fafaf595c1ad92c28c61da3a254d63.tar.xz | |
runtime: when crash with panic, call user Error/String methods before freezing the world
Fixes #14432.
Change-Id: I0a92ef86de95de39217df9a664d8034ef685a906
Reviewed-on: https://go-review.googlesource.com/19792
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Minux Ma <minux@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/runtime/panic.go')
| -rw-r--r-- | src/runtime/panic.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/runtime/panic.go b/src/runtime/panic.go index ba07330e35..349e997395 100644 --- a/src/runtime/panic.go +++ b/src/runtime/panic.go @@ -333,6 +333,21 @@ func Goexit() { goexit1() } +// Call all Error and String methods before freezing the world. +// Used when crashing with panicking. +// This must match types handled by printany. +func preprintpanics(p *_panic) { + for p != nil { + switch v := p.arg.(type) { + case error: + p.arg = v.Error() + case stringer: + p.arg = v.String() + } + p = p.link + } +} + // Print all currently active panics. Used when crashing. func printpanics(p *_panic) { if p.link != nil { @@ -459,6 +474,10 @@ func gopanic(e interface{}) { } // ran out of deferred calls - old-school panic now + // Because it is unsafe to call arbitrary user code after freezing + // the world, we call preprintpanics to invoke all necessary Error + // and String methods to prepare the panic strings before startpanic. + preprintpanics(gp._panic) startpanic() printpanics(gp._panic) dopanic(0) // should not return |
