Skip to content

Commit

Permalink
core/godebuginstance: fix sorting results by arrivalindex. Improve st…
Browse files Browse the repository at this point in the history
…ringifyitem to accept strlen arg.
  • Loading branch information
jmigpin committed Feb 22, 2024
1 parent a683c68 commit 462c002
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
15 changes: 10 additions & 5 deletions core/godebug/stringifyitem.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,32 @@ import (
)

func StringifyItem(item debug.Item) string {
return StringifyItem2(item, 20)
}
func StringifyItem2(item debug.Item, valueStrLen int) string {
is := NewItemStringifier()
is.valueStrLen = valueStrLen
is.stringify(item)
return is.b.String()
}
func StringifyItemFull(item debug.Item) string {
is := NewItemStringifier()
is.fullStr = true
is.valueStrLen = -1 // full str
is.stringify(item)
return is.b.String()
}

//----------

type ItemStringifier struct {
b *strings.Builder
fullStr bool
b *strings.Builder
valueStrLen int // <0 = full str
}

func NewItemStringifier() *ItemStringifier {
is := &ItemStringifier{}
is.b = &strings.Builder{}
is.valueStrLen = 20
return is
}

Expand All @@ -44,10 +49,10 @@ func (is *ItemStringifier) stringify(item debug.Item) {

switch t := item.(type) {
case *debug.ItemValue:
if is.fullStr {
if is.valueStrLen < 0 {
is.p(t.Str)
} else {
is.p(debug.SprintCutCheckQuote(20, t.Str))
is.p(debug.SprintCutCheckQuote(is.valueStrLen, t.Str))
}

case *debug.ItemList: // ex: func args list
Expand Down
6 changes: 5 additions & 1 deletion core/godebuginstance.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func (gdi *GoDebugInstance) trace() error {
msg := msgs[i]
afd := gdi.di.afds[msg.offsetMsg.FileIndex]
loc := fmt.Sprintf("%v:o=%d", afd.Filename, msg.offsetMsg.Offset)
s := godebug.StringifyItemFull(msg.offsetMsg.Item)
s := godebug.StringifyItem2(msg.offsetMsg.Item, 8)
u := fmt.Sprintf("%v: %v", s, loc)
sb.WriteString("\t" + u + "\n")
}
Expand Down Expand Up @@ -1017,6 +1017,10 @@ func (di *GDDataIndex) trace() []*GDOffsetMsg {
}
}

sort.Slice(res, func(a, b int) bool {
return res[a].arrivalIndex < res[b].arrivalIndex
})

return res
}

Expand Down

0 comments on commit 462c002

Please sign in to comment.