@@ -600,7 +600,7 @@ func BuildFuncDebug(ctxt *obj.Link, f *Func, loggingLevel int, stackOffset func(
600
600
state .vars = state .vars [:0 ]
601
601
for i , slot := range f .Names {
602
602
state .slots = append (state .slots , * slot )
603
- if ir .IsSynthetic (slot .N ) {
603
+ if ir .IsSynthetic (slot .N ) || ! IsVarWantedForDebug ( slot . N ) {
604
604
continue
605
605
}
606
606
@@ -620,7 +620,7 @@ func BuildFuncDebug(ctxt *obj.Link, f *Func, loggingLevel int, stackOffset func(
620
620
for _ , v := range b .Values {
621
621
if v .Op == OpVarDef {
622
622
n := v .Aux .(* ir.Name )
623
- if ir .IsSynthetic (n ) {
623
+ if ir .IsSynthetic (n ) || ! IsVarWantedForDebug ( n ) {
624
624
continue
625
625
}
626
626
@@ -665,7 +665,7 @@ func BuildFuncDebug(ctxt *obj.Link, f *Func, loggingLevel int, stackOffset func(
665
665
state .initializeCache (f , len (state .varParts ), len (state .slots ))
666
666
667
667
for i , slot := range f .Names {
668
- if ir .IsSynthetic (slot .N ) {
668
+ if ir .IsSynthetic (slot .N ) || ! IsVarWantedForDebug ( slot . N ) {
669
669
continue
670
670
}
671
671
for _ , value := range f .NamedValues [* slot ] {
@@ -1087,7 +1087,7 @@ func (state *debugState) processValue(v *Value, vSlots []SlotID, vReg *Register)
1087
1087
switch {
1088
1088
case v .Op == OpVarDef :
1089
1089
n := v .Aux .(* ir.Name )
1090
- if ir .IsSynthetic (n ) {
1090
+ if ir .IsSynthetic (n ) || ! IsVarWantedForDebug ( n ) {
1091
1091
break
1092
1092
}
1093
1093
@@ -1835,6 +1835,9 @@ func BuildFuncDebugNoOptimized(ctxt *obj.Link, f *Func, loggingEnabled bool, sta
1835
1835
// will be sorted out elsewhere
1836
1836
continue
1837
1837
}
1838
+ if ! IsVarWantedForDebug (inp .Name ) {
1839
+ continue
1840
+ }
1838
1841
addVarSlot (inp .Name , inp .Type )
1839
1842
params = append (params , inp )
1840
1843
}
@@ -1855,6 +1858,9 @@ func BuildFuncDebugNoOptimized(ctxt *obj.Link, f *Func, loggingEnabled bool, sta
1855
1858
// will be sorted out elsewhere
1856
1859
continue
1857
1860
}
1861
+ if ! IsVarWantedForDebug (inp .Name ) {
1862
+ continue
1863
+ }
1858
1864
1859
1865
sl := rval .Slots [pidx ]
1860
1866
n := rval .Vars [pidx ]
@@ -1948,3 +1954,19 @@ func BuildFuncDebugNoOptimized(ctxt *obj.Link, f *Func, loggingEnabled bool, sta
1948
1954
pidx ++
1949
1955
}
1950
1956
}
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