aboutsummaryrefslogtreecommitdiff
path: root/src/debug
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josharian@gmail.com>2021-09-28 13:13:49 -0700
committerJosh Bleecher Snyder <josharian@gmail.com>2021-09-29 16:45:42 +0000
commit2fad7dbb893737a01c7ab4f382720a2b0440b736 (patch)
tree073c99498db0f92bab83943b6e7c0e44b0adb0e1 /src/debug
parentc2de759581aef5d14fd07b843caf76db3c8a115b (diff)
downloadgo-2fad7dbb893737a01c7ab4f382720a2b0440b736.tar.gz
go-2fad7dbb893737a01c7ab4f382720a2b0440b736.zip
debug/gosym: add hook to disable recovers
debug/gosym assumes throughout that bogus input means a malformed file. That's generally true, but not when you're changing the package. In that case, the panic usually indicates a newly introduced bug, and seeing the panic is really useful. Add a manually-enabled way to make panics panic. Change-Id: I07af6c7b982c4cf61180db29f07aa63576ba7837 Reviewed-on: https://go-review.googlesource.com/c/go/+/352949 Trust: Josh Bleecher Snyder <josharian@gmail.com> Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
Diffstat (limited to 'src/debug')
-rw-r--r--src/debug/gosym/pclntab.go36
1 files changed, 23 insertions, 13 deletions
diff --git a/src/debug/gosym/pclntab.go b/src/debug/gosym/pclntab.go
index 555add67e3..5d65b7826a 100644
--- a/src/debug/gosym/pclntab.go
+++ b/src/debug/gosym/pclntab.go
@@ -193,10 +193,12 @@ func (t *LineTable) parsePclnTab() {
// Error paths through this code will default the version to 1.1.
t.version = ver11
- defer func() {
- // If we panic parsing, assume it's a Go 1.1 pclntab.
- recover()
- }()
+ if !disableRecover {
+ defer func() {
+ // If we panic parsing, assume it's a Go 1.1 pclntab.
+ recover()
+ }()
+ }
// Check header: 4-byte magic, two zeros, pc quantum, pointer size.
if len(t.Data) < 16 || t.Data[4] != 0 || t.Data[5] != 0 ||
@@ -265,9 +267,11 @@ func (t *LineTable) parsePclnTab() {
// go12Funcs returns a slice of Funcs derived from the Go 1.2 pcln table.
func (t *LineTable) go12Funcs() []Func {
// Assume it is malformed and return nil on error.
- defer func() {
- recover()
- }()
+ if !disableRecover {
+ defer func() {
+ recover()
+ }()
+ }
n := len(t.functab) / int(t.ptrsize) / 2
funcs := make([]Func, n)
@@ -441,7 +445,7 @@ func (t *LineTable) findFileLine(entry uint64, filetab, linetab uint32, filenum,
// go12PCToLine maps program counter to line number for the Go 1.2 pcln table.
func (t *LineTable) go12PCToLine(pc uint64) (line int) {
defer func() {
- if recover() != nil {
+ if !disableRecover && recover() != nil {
line = -1
}
}()
@@ -458,7 +462,7 @@ func (t *LineTable) go12PCToLine(pc uint64) (line int) {
// go12PCToFile maps program counter to file name for the Go 1.2 pcln table.
func (t *LineTable) go12PCToFile(pc uint64) (file string) {
defer func() {
- if recover() != nil {
+ if !disableRecover && recover() != nil {
file = ""
}
}()
@@ -490,7 +494,7 @@ func (t *LineTable) go12PCToFile(pc uint64) (file string) {
// go12LineToPC maps a (file, line) pair to a program counter for the Go 1.2/1.16 pcln table.
func (t *LineTable) go12LineToPC(file string, line int) (pc uint64) {
defer func() {
- if recover() != nil {
+ if !disableRecover && recover() != nil {
pc = 0
}
}()
@@ -552,12 +556,18 @@ func (t *LineTable) initFileMap() {
// Every key maps to obj. That's not a very interesting map, but it provides
// a way for callers to obtain the list of files in the program.
func (t *LineTable) go12MapFiles(m map[string]*Obj, obj *Obj) {
- defer func() {
- recover()
- }()
+ if !disableRecover {
+ defer func() {
+ recover()
+ }()
+ }
t.initFileMap()
for file := range t.fileMap {
m[file] = obj
}
}
+
+// disableRecover causes this package not to swallow panics.
+// This is useful when making changes.
+const disableRecover = false