Skip to content

Commit 82c371a

Browse files
aarzilligopherbot
authored andcommitted
cmd/compile: drop internal range-over-func vars from DWARF output
Drops internal range-over-func variables from the DWARF output (excluding #yield which is used by Delve). Fixes #68238 Change-Id: Ic035e37ca3560347276cdc3b469fd564da33f4f5 Reviewed-on: https://go-review.googlesource.com/c/go/+/594257 Reviewed-by: Than McIntosh <[email protected]> Reviewed-by: Cherry Mui <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: David Chase <[email protected]> Reviewed-by: Hyang-Ah Hana Kim <[email protected]> Auto-Submit: Hyang-Ah Hana Kim <[email protected]>
1 parent 773767d commit 82c371a

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

src/cmd/compile/internal/dwarfgen/dwarf.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ func Info(fnsym *obj.LSym, infosym *obj.LSym, curfn obj.Func) (scopes []dwarf.Sc
9191
default:
9292
continue
9393
}
94+
if !ssa.IsVarWantedForDebug(n) {
95+
continue
96+
}
9497
apdecls = append(apdecls, n)
9598
if n.Type().Kind() == types.TSSA {
9699
// Can happen for TypeInt128 types. This only happens for
@@ -194,6 +197,9 @@ func createDwarfVars(fnsym *obj.LSym, complexOK bool, fn *ir.Func, apDecls []*ir
194197
// DWARF-gen. See issue 48573 for more details.
195198
debugInfo := fn.DebugInfo.(*ssa.FuncDebug)
196199
for _, n := range debugInfo.RegOutputParams {
200+
if !ssa.IsVarWantedForDebug(n) {
201+
continue
202+
}
197203
if n.Class != ir.PPARAMOUT || !n.IsOutputParamInRegisters() {
198204
panic("invalid ir.Name on debugInfo.RegOutputParams list")
199205
}

src/cmd/compile/internal/rangefunc/rewrite.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,7 @@ func (r *rewriter) setStateAt(index int, stateVal abi.RF_State) *syntax.AssignSt
11371137
func (r *rewriter) bodyFunc(body []syntax.Stmt, lhs []syntax.Expr, def bool, ftyp *types2.Signature, start, end syntax.Pos) *syntax.FuncLit {
11381138
// Starting X(bodyFunc); build up bodyFunc first.
11391139
var params, results []*types2.Var
1140-
results = append(results, types2.NewVar(start, nil, "", r.bool.Type()))
1140+
results = append(results, types2.NewVar(start, nil, "#r", r.bool.Type()))
11411141
bodyFunc := &syntax.FuncLit{
11421142
// Note: Type is ignored but needs to be non-nil to avoid panic in syntax.Inspect.
11431143
Type: &syntax.FuncType{},

src/cmd/compile/internal/ssa/debug.go

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ func BuildFuncDebug(ctxt *obj.Link, f *Func, loggingLevel int, stackOffset func(
600600
state.vars = state.vars[:0]
601601
for i, slot := range f.Names {
602602
state.slots = append(state.slots, *slot)
603-
if ir.IsSynthetic(slot.N) {
603+
if ir.IsSynthetic(slot.N) || !IsVarWantedForDebug(slot.N) {
604604
continue
605605
}
606606

@@ -620,7 +620,7 @@ func BuildFuncDebug(ctxt *obj.Link, f *Func, loggingLevel int, stackOffset func(
620620
for _, v := range b.Values {
621621
if v.Op == OpVarDef {
622622
n := v.Aux.(*ir.Name)
623-
if ir.IsSynthetic(n) {
623+
if ir.IsSynthetic(n) || !IsVarWantedForDebug(n) {
624624
continue
625625
}
626626

@@ -665,7 +665,7 @@ func BuildFuncDebug(ctxt *obj.Link, f *Func, loggingLevel int, stackOffset func(
665665
state.initializeCache(f, len(state.varParts), len(state.slots))
666666

667667
for i, slot := range f.Names {
668-
if ir.IsSynthetic(slot.N) {
668+
if ir.IsSynthetic(slot.N) || !IsVarWantedForDebug(slot.N) {
669669
continue
670670
}
671671
for _, value := range f.NamedValues[*slot] {
@@ -1087,7 +1087,7 @@ func (state *debugState) processValue(v *Value, vSlots []SlotID, vReg *Register)
10871087
switch {
10881088
case v.Op == OpVarDef:
10891089
n := v.Aux.(*ir.Name)
1090-
if ir.IsSynthetic(n) {
1090+
if ir.IsSynthetic(n) || !IsVarWantedForDebug(n) {
10911091
break
10921092
}
10931093

@@ -1835,6 +1835,9 @@ func BuildFuncDebugNoOptimized(ctxt *obj.Link, f *Func, loggingEnabled bool, sta
18351835
// will be sorted out elsewhere
18361836
continue
18371837
}
1838+
if !IsVarWantedForDebug(inp.Name) {
1839+
continue
1840+
}
18381841
addVarSlot(inp.Name, inp.Type)
18391842
params = append(params, inp)
18401843
}
@@ -1855,6 +1858,9 @@ func BuildFuncDebugNoOptimized(ctxt *obj.Link, f *Func, loggingEnabled bool, sta
18551858
// will be sorted out elsewhere
18561859
continue
18571860
}
1861+
if !IsVarWantedForDebug(inp.Name) {
1862+
continue
1863+
}
18581864

18591865
sl := rval.Slots[pidx]
18601866
n := rval.Vars[pidx]
@@ -1948,3 +1954,19 @@ func BuildFuncDebugNoOptimized(ctxt *obj.Link, f *Func, loggingEnabled bool, sta
19481954
pidx++
19491955
}
19501956
}
1957+
1958+
// IsVarWantedForDebug returns true if the debug info for the node should
1959+
// be generated.
1960+
// For example, internal variables for range-over-func loops have little
1961+
// value to users, so we don't generate debug info for them.
1962+
func IsVarWantedForDebug(n ir.Node) bool {
1963+
name := n.Sym().Name
1964+
if len(name) > 0 && name[0] == '&' {
1965+
name = name[1:]
1966+
}
1967+
if len(name) > 0 && name[0] == '#' {
1968+
// #yield is used by delve.
1969+
return strings.HasPrefix(name, "#yield")
1970+
}
1971+
return true
1972+
}

0 commit comments

Comments
 (0)