Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debug: do not include inlined sources in frame counts #2199

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions internal/wasmdebug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ func NewErrorBuilder() ErrorBuilder {
}

type stackTrace struct {
frames []string
// frameCount is the number of stack frame currently pushed into lines.
frameCount int
// lines contains the stack trace and possibly the inlined source code information.
lines []string
}

// GoRuntimeErrorTracePrefix is the prefix coming before the Go runtime stack trace included in the face of runtime.Error.
Expand All @@ -125,7 +128,7 @@ func (s *stackTrace) FromRecovered(recovered interface{}) error {
return exitErr
}

stack := strings.Join(s.frames, "\n\t")
stack := strings.Join(s.lines, "\n\t")

// If the error was internal, don't mention it was recovered.
if wasmErr, ok := recovered.(*wasmruntime.Error); ok {
Expand All @@ -152,12 +155,16 @@ const MaxFrames = 30

// AddFrame implements ErrorBuilder.AddFrame
func (s *stackTrace) AddFrame(funcName string, paramTypes, resultTypes []api.ValueType, sources []string) {
if s.frameCount == MaxFrames {
return
}
s.frameCount++
sig := signature(funcName, paramTypes, resultTypes)
s.frames = append(s.frames, sig)
s.lines = append(s.lines, sig)
for _, source := range sources {
s.frames = append(s.frames, "\t"+source)
s.lines = append(s.lines, "\t"+source)
}
if len(s.frames) == MaxFrames {
s.frames = append(s.frames, "... maybe followed by omitted frames")
if s.frameCount == MaxFrames {
s.lines = append(s.lines, "... maybe followed by omitted frames")
}
}
10 changes: 10 additions & 0 deletions internal/wasmdebug/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,13 @@ func (e testRuntimeErr) RuntimeError() {}
func (e testRuntimeErr) Error() string {
return string(e)
}

func Test_AddFrame_MaxFrame(t *testing.T) {
builder := NewErrorBuilder().(*stackTrace)
for i := 0; i < MaxFrames+10; i++ {
builder.AddFrame("x.y", nil, nil, []string{"a.go:1:2", "b.go:3:4"})
}
require.Equal(t, MaxFrames, builder.frameCount)
require.Equal(t, MaxFrames*3 /* frame + two inlined sources */ +1, len(builder.lines))
require.Equal(t, "... maybe followed by omitted frames", builder.lines[len(builder.lines)-1])
}
Loading