default:
continue
}
+ if !ssa.IsVarWantedForDebug(n) {
+ continue
+ }
apdecls = append(apdecls, n)
if n.Type().Kind() == types.TSSA {
// Can happen for TypeInt128 types. This only happens for
// DWARF-gen. See issue 48573 for more details.
debugInfo := fn.DebugInfo.(*ssa.FuncDebug)
for _, n := range debugInfo.RegOutputParams {
+ if !ssa.IsVarWantedForDebug(n) {
+ continue
+ }
if n.Class != ir.PPARAMOUT || !n.IsOutputParamInRegisters() {
panic("invalid ir.Name on debugInfo.RegOutputParams list")
}
func (r *rewriter) bodyFunc(body []syntax.Stmt, lhs []syntax.Expr, def bool, ftyp *types2.Signature, start, end syntax.Pos) *syntax.FuncLit {
// Starting X(bodyFunc); build up bodyFunc first.
var params, results []*types2.Var
- results = append(results, types2.NewVar(start, nil, "", r.bool.Type()))
+ results = append(results, types2.NewVar(start, nil, "#r", r.bool.Type()))
bodyFunc := &syntax.FuncLit{
// Note: Type is ignored but needs to be non-nil to avoid panic in syntax.Inspect.
Type: &syntax.FuncType{},
state.vars = state.vars[:0]
for i, slot := range f.Names {
state.slots = append(state.slots, *slot)
- if ir.IsSynthetic(slot.N) {
+ if ir.IsSynthetic(slot.N) || !IsVarWantedForDebug(slot.N) {
continue
}
for _, v := range b.Values {
if v.Op == OpVarDef {
n := v.Aux.(*ir.Name)
- if ir.IsSynthetic(n) {
+ if ir.IsSynthetic(n) || !IsVarWantedForDebug(n) {
continue
}
state.initializeCache(f, len(state.varParts), len(state.slots))
for i, slot := range f.Names {
- if ir.IsSynthetic(slot.N) {
+ if ir.IsSynthetic(slot.N) || !IsVarWantedForDebug(slot.N) {
continue
}
for _, value := range f.NamedValues[*slot] {
switch {
case v.Op == OpVarDef:
n := v.Aux.(*ir.Name)
- if ir.IsSynthetic(n) {
+ if ir.IsSynthetic(n) || !IsVarWantedForDebug(n) {
break
}
// will be sorted out elsewhere
continue
}
+ if !IsVarWantedForDebug(inp.Name) {
+ continue
+ }
addVarSlot(inp.Name, inp.Type)
params = append(params, inp)
}
// will be sorted out elsewhere
continue
}
+ if !IsVarWantedForDebug(inp.Name) {
+ continue
+ }
sl := rval.Slots[pidx]
n := rval.Vars[pidx]
pidx++
}
}
+
+// IsVarWantedForDebug returns true if the debug info for the node should
+// be generated.
+// For example, internal variables for range-over-func loops have little
+// value to users, so we don't generate debug info for them.
+func IsVarWantedForDebug(n ir.Node) bool {
+ name := n.Sym().Name
+ if len(name) > 0 && name[0] == '&' {
+ name = name[1:]
+ }
+ if len(name) > 0 && name[0] == '#' {
+ // #yield is used by delve.
+ return strings.HasPrefix(name, "#yield")
+ }
+ return true
+}