@@ -55,51 +55,25 @@ func scopeVariables(dwarfVars []*dwarf.Var, varScopes []ScopeID, dwarfScopes []d
55
55
}
56
56
}
57
57
58
- // A scopedPCs represents a non-empty half-open interval of PCs that
59
- // share a common source position.
60
- type scopedPCs struct {
61
- start , end int64
62
- pos src.XPos
63
- scope ScopeID
64
- }
65
-
66
58
// scopePCs assigns PC ranges to their scopes.
67
59
func scopePCs (fnsym * obj.LSym , marks []Mark , dwarfScopes []dwarf.Scope ) {
68
60
// If there aren't any child scopes (in particular, when scope
69
61
// tracking is disabled), we can skip a whole lot of work.
70
62
if len (marks ) == 0 {
71
63
return
72
64
}
73
-
74
- // Break function text into scopedPCs.
75
- var pcs []scopedPCs
76
65
p0 := fnsym .Func .Text
66
+ scope := findScope (marks , p0 .Pos )
77
67
for p := fnsym .Func .Text ; p != nil ; p = p .Link {
78
68
if p .Pos == p0 .Pos {
79
69
continue
80
70
}
81
- if p0 .Pc < p .Pc {
82
- pcs = append (pcs , scopedPCs {start : p0 .Pc , end : p .Pc , pos : p0 .Pos })
83
- }
71
+ dwarfScopes [scope ].AppendRange (dwarf.Range {Start : p0 .Pc , End : p .Pc })
84
72
p0 = p
73
+ scope = findScope (marks , p0 .Pos )
85
74
}
86
75
if p0 .Pc < fnsym .Size {
87
- pcs = append (pcs , scopedPCs {start : p0 .Pc , end : fnsym .Size , pos : p0 .Pos })
88
- }
89
-
90
- // Assign scopes to each chunk of instructions.
91
- for i := range pcs {
92
- pcs [i ].scope = findScope (marks , pcs [i ].pos )
93
- }
94
-
95
- // Create sorted PC ranges for each DWARF scope.
96
- for _ , pc := range pcs {
97
- r := & dwarfScopes [pc .scope ].Ranges
98
- if i := len (* r ); i > 0 && (* r )[i - 1 ].End == pc .start {
99
- (* r )[i - 1 ].End = pc .end
100
- } else {
101
- * r = append (* r , dwarf.Range {Start : pc .start , End : pc .end })
102
- }
76
+ dwarfScopes [scope ].AppendRange (dwarf.Range {Start : p0 .Pc , End : fnsym .Size })
103
77
}
104
78
}
105
79
0 commit comments