mirror of
https://github.com/golang/go
synced 2024-11-05 18:36:08 +00:00
cmd/compile: preserve argument order in debug_info
When regabi is used sorting by stack offset will not preserve the order of function arguments. Trust that variables are already ordered correctly when creating debug_info entries. Fixes #45720 Change-Id: I1dbdd185975273f70244a23302d34f082347603d Reviewed-on: https://go-review.googlesource.com/c/go/+/315280 Reviewed-by: Than McIntosh <thanm@google.com> Trust: Jeremy Faller <jeremy@golang.org>
This commit is contained in:
parent
472f519fe2
commit
169155d61e
1 changed files with 25 additions and 3 deletions
|
@ -36,7 +36,7 @@ func assembleScopes(fnsym *obj.LSym, fn *ir.Func, dwarfVars []*dwarf.Var, varSco
|
|||
dwarfScopes[i+1].Parent = int32(parent)
|
||||
}
|
||||
|
||||
scopeVariables(dwarfVars, varScopes, dwarfScopes)
|
||||
scopeVariables(dwarfVars, varScopes, dwarfScopes, fnsym.ABI() != obj.ABI0)
|
||||
if fnsym.Func().Text != nil {
|
||||
scopePCs(fnsym, fn.Marks, dwarfScopes)
|
||||
}
|
||||
|
@ -44,8 +44,12 @@ func assembleScopes(fnsym *obj.LSym, fn *ir.Func, dwarfVars []*dwarf.Var, varSco
|
|||
}
|
||||
|
||||
// scopeVariables assigns DWARF variable records to their scopes.
|
||||
func scopeVariables(dwarfVars []*dwarf.Var, varScopes []ir.ScopeID, dwarfScopes []dwarf.Scope) {
|
||||
sort.Stable(varsByScopeAndOffset{dwarfVars, varScopes})
|
||||
func scopeVariables(dwarfVars []*dwarf.Var, varScopes []ir.ScopeID, dwarfScopes []dwarf.Scope, regabi bool) {
|
||||
if regabi {
|
||||
sort.Stable(varsByScope{dwarfVars, varScopes})
|
||||
} else {
|
||||
sort.Stable(varsByScopeAndOffset{dwarfVars, varScopes})
|
||||
}
|
||||
|
||||
i0 := 0
|
||||
for i := range dwarfVars {
|
||||
|
@ -112,3 +116,21 @@ func (v varsByScopeAndOffset) Swap(i, j int) {
|
|||
v.vars[i], v.vars[j] = v.vars[j], v.vars[i]
|
||||
v.scopes[i], v.scopes[j] = v.scopes[j], v.scopes[i]
|
||||
}
|
||||
|
||||
type varsByScope struct {
|
||||
vars []*dwarf.Var
|
||||
scopes []ir.ScopeID
|
||||
}
|
||||
|
||||
func (v varsByScope) Len() int {
|
||||
return len(v.vars)
|
||||
}
|
||||
|
||||
func (v varsByScope) Less(i, j int) bool {
|
||||
return v.scopes[i] < v.scopes[j]
|
||||
}
|
||||
|
||||
func (v varsByScope) Swap(i, j int) {
|
||||
v.vars[i], v.vars[j] = v.vars[j], v.vars[i]
|
||||
v.scopes[i], v.scopes[j] = v.scopes[j], v.scopes[i]
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue