1
0
mirror of https://github.com/golang/go synced 2024-11-23 04:40:09 -07:00

cmd/compile: revise block/func end sentinels in debug analysis

The SSA code for debug variable location analysis (for DWARF) has two
special 'sentinel' values that it uses to handshake with the
debugInfo.GetPC callback when capturing the PC values of debug
variable ranges after prog generatoin: "BlockStart" and "BlockEnd".

"BlockStart" has the expected semantics: it means "the PC value of the
first instruction of block B", but "BlockEnd" does not mean "PC value
of the last instruction of block B", but rather it is implemented as
"the PC value of the last instruction of the function". This causes
confusion when reading the code, and seems to to result in implementation
flaws in the past, leading to incorrect ranges in some cases.

To help with this, add a new sentinel "FuncEnd" (which has the "last
inst in the function" semantics) and change the implementation of
"BlockEnd" to actually mean what its name implies (last inst in
block).

Updates #45720.

Change-Id: Ic3497fb60413e898d2bfe27805c3db56483d12a2
Reviewed-on: https://go-review.googlesource.com/c/go/+/314930
Trust: Than McIntosh <thanm@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Reviewed-by: David Chase <drchase@google.com>
This commit is contained in:
Than McIntosh 2021-04-28 18:26:54 -04:00
parent 83ac59b1a5
commit afa58ddf5a
2 changed files with 15 additions and 1 deletions

View File

@ -152,6 +152,12 @@ var BlockEnd = &Value{
Aux: StringToAux("BlockEnd"),
}
var FuncEnd = &Value{
ID: -30000,
Op: OpInvalid,
Aux: StringToAux("FuncEnd"),
}
// RegisterSet is a bitmap of registers, indexed by Register.num.
type RegisterSet uint64
@ -948,7 +954,7 @@ func (state *debugState) buildLocationLists(blockLocs []*BlockDebug) {
// Flush any leftover entries live at the end of the last block.
for varID := range state.lists {
state.writePendingEntry(VarID(varID), state.f.Blocks[len(state.f.Blocks)-1].ID, BlockEnd.ID)
state.writePendingEntry(VarID(varID), state.f.Blocks[len(state.f.Blocks)-1].ID, FuncEnd.ID)
list := state.lists[varID]
if state.loggingEnabled {
if len(list) == 0 {

View File

@ -6964,6 +6964,10 @@ func genssa(f *ssa.Func, pp *objw.Progs) {
debugInfo := ssa.BuildFuncDebug(base.Ctxt, f, base.Debug.LocationLists > 1, StackOffset)
e.curfn.DebugInfo = debugInfo
bstart := s.bstart
idToIdx := make([]int, f.NumBlocks())
for i, b := range f.Blocks {
idToIdx[b.ID] = i
}
// Note that at this moment, Prog.Pc is a sequence number; it's
// not a real PC until after assembly, so this mapping has to
// be done later.
@ -6976,6 +6980,10 @@ func genssa(f *ssa.Func, pp *objw.Progs) {
}
return bstart[b].Pc
case ssa.BlockEnd.ID:
blk := f.Blocks[idToIdx[b]]
nv := len(blk.Values)
return valueToProgAfter[blk.Values[nv-1].ID].Pc
case ssa.FuncEnd.ID:
return e.curfn.LSym.Size
default:
return valueToProgAfter[v].Pc