mirror of
https://github.com/golang/go
synced 2024-11-17 04:04:46 -07:00
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>
This commit is contained in:
parent
c2de759581
commit
2fad7dbb89
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user