From: Than McIntosh Date: Wed, 28 Apr 2021 22:26:54 +0000 (-0400) Subject: cmd/compile: revise block/func end sentinels in debug analysis X-Git-Tag: go1.17beta1~317 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=afa58ddf5a17a3618a24baf161b06cf0e066cb88;p=gostls13.git 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 Run-TryBot: Than McIntosh TryBot-Result: Go Bot Reviewed-by: Cherry Zhang Reviewed-by: David Chase --- diff --git a/src/cmd/compile/internal/ssa/debug.go b/src/cmd/compile/internal/ssa/debug.go index d725fc526e..46743f54eb 100644 --- a/src/cmd/compile/internal/ssa/debug.go +++ b/src/cmd/compile/internal/ssa/debug.go @@ -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 { diff --git a/src/cmd/compile/internal/ssagen/ssa.go b/src/cmd/compile/internal/ssagen/ssa.go index c49350005e..fb35d8044e 100644 --- a/src/cmd/compile/internal/ssagen/ssa.go +++ b/src/cmd/compile/internal/ssagen/ssa.go @@ -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