diff --git a/src/debug/gosym/pclntab.go b/src/debug/gosym/pclntab.go index 555add67e30..5d65b7826ad 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