diff options
author | Keith Randall <khr@google.com> | 2019-01-14 13:47:14 -0800 |
---|---|---|
committer | Keith Randall <khr@golang.org> | 2019-01-14 23:37:39 +0000 |
commit | 462e90259af39af9e23c9d919e002913042c2faa (patch) | |
tree | 61290a47ac5b2387921c1a0cd05e7f39c4d68c7b /src/runtime/symtab.go | |
parent | e1d20ce25acfd8a1c5933453f34db5f589585eaa (diff) | |
download | go-462e90259af39af9e23c9d919e002913042c2faa.tar.gz go-462e90259af39af9e23c9d919e002913042c2faa.zip |
runtime: keep FuncForPC from crashing for PCs between functions
Reuse the strict mechanism from FileLine for FuncForPC, so we don't
crash when asking the pcln table about bad pcs.
Fixes #29735
Change-Id: Iaffb32498b8586ecf4eae03823e8aecef841aa68
Reviewed-on: https://go-review.googlesource.com/c/157799
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/runtime/symtab.go')
-rw-r--r-- | src/runtime/symtab.go | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/runtime/symtab.go b/src/runtime/symtab.go index e7ce3de497..17e342ef69 100644 --- a/src/runtime/symtab.go +++ b/src/runtime/symtab.go @@ -474,7 +474,11 @@ func FuncForPC(pc uintptr) *Func { return nil } if inldata := funcdata(f, _FUNCDATA_InlTree); inldata != nil { - if ix := pcdatavalue(f, _PCDATA_InlTreeIndex, pc, nil); ix >= 0 { + // Note: strict=false so bad PCs (those between functions) don't crash the runtime. + // We just report the preceeding function in that situation. See issue 29735. + // TODO: Perhaps we should report no function at all in that case. + // The runtime currently doesn't have function end info, alas. + if ix := pcdatavalue1(f, _PCDATA_InlTreeIndex, pc, nil, false); ix >= 0 { inltree := (*[1 << 20]inlinedCall)(inldata) name := funcnameFromNameoff(f, inltree[ix].func_) file, line := funcline(f, pc) @@ -756,12 +760,22 @@ func funcspdelta(f funcInfo, targetpc uintptr, cache *pcvalueCache) int32 { return x } +func pcdatastart(f funcInfo, table int32) int32 { + return *(*int32)(add(unsafe.Pointer(&f.nfuncdata), unsafe.Sizeof(f.nfuncdata)+uintptr(table)*4)) +} + func pcdatavalue(f funcInfo, table int32, targetpc uintptr, cache *pcvalueCache) int32 { if table < 0 || table >= f.npcdata { return -1 } - off := *(*int32)(add(unsafe.Pointer(&f.nfuncdata), unsafe.Sizeof(f.nfuncdata)+uintptr(table)*4)) - return pcvalue(f, off, targetpc, cache, true) + return pcvalue(f, pcdatastart(f, table), targetpc, cache, true) +} + +func pcdatavalue1(f funcInfo, table int32, targetpc uintptr, cache *pcvalueCache, strict bool) int32 { + if table < 0 || table >= f.npcdata { + return -1 + } + return pcvalue(f, pcdatastart(f, table), targetpc, cache, strict) } func funcdata(f funcInfo, i uint8) unsafe.Pointer { |