aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/panic.go
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2018-06-28 16:45:28 -0700
committerIan Lance Taylor <iant@golang.org>2018-06-29 21:29:17 +0000
commitf43aa1df701d7190eeaf301d3a41e1714c516c45 (patch)
tree452f2ee9d5e13b5de4c3a2de36d8dff850cf9488 /src/runtime/panic.go
parent955cc07dde70415489fb2096eb575654181e21fe (diff)
downloadgo-f43aa1df701d7190eeaf301d3a41e1714c516c45.tar.gz
go-f43aa1df701d7190eeaf301d3a41e1714c516c45.zip
runtime: throw if the runtime panics with out of bounds index
If the runtime code panics due to a bad index or slice expression, then throw instead of panicing. This will skip calls to recover and dump the entire runtime stack trace. The runtime should never panic due to an out of bounds index, and this will help with debugging if it does. For #24991 Updates #25201 Change-Id: I85a9feded8f0de914ee1558425931853223c0514 Reviewed-on: https://go-review.googlesource.com/121515 Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'src/runtime/panic.go')
-rw-r--r--src/runtime/panic.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/runtime/panic.go b/src/runtime/panic.go
index ce367cfa70..7bb7f9b90c 100644
--- a/src/runtime/panic.go
+++ b/src/runtime/panic.go
@@ -23,7 +23,23 @@ func panicCheckMalloc(err error) {
var indexError = error(errorString("index out of range"))
+// The panicindex, panicslice, and panicdivide functions are called by
+// code generated by the compiler for out of bounds index expressions,
+// out of bounds slice expressions, and division by zero. The
+// panicdivide (again), panicoverflow, panicfloat, and panicmem
+// functions are called by the signal handler when a signal occurs
+// indicating the respective problem.
+//
+// Since panicindex and panicslice are never called directly, and
+// since the runtime package should never have an out of bounds slice
+// or array reference, if we see those functions called from the
+// runtime package we turn the panic into a throw. That will dump the
+// entire runtime stack for easier debugging.
+
func panicindex() {
+ if hasprefix(funcname(findfunc(getcallerpc())), "runtime.") {
+ throw(string(indexError.(errorString)))
+ }
panicCheckMalloc(indexError)
panic(indexError)
}
@@ -31,6 +47,9 @@ func panicindex() {
var sliceError = error(errorString("slice bounds out of range"))
func panicslice() {
+ if hasprefix(funcname(findfunc(getcallerpc())), "runtime.") {
+ throw(string(sliceError.(errorString)))
+ }
panicCheckMalloc(sliceError)
panic(sliceError)
}