Skip to content
Open
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
7 changes: 4 additions & 3 deletions gostackparse.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func Parse(r io.Reader) ([]*Goroutine, []error) {
case stateStackFunc, stateCreatedByFunc:
f = parseFunc(line, state)
if f == nil {
if bytes.Equal(line, framesElided) {
if bytes.HasSuffix(line, framesElidedSuffix) {
g.FramesElided = true
state = stateCreatedBy
continue
Expand Down Expand Up @@ -150,11 +150,11 @@ var (
goroutinePrefix = []byte("goroutine ")
createdByPrefix = []byte("created by ")
originatingFromPrefix = []byte("[originating from goroutine ")
framesElided = []byte("...additional frames elided...")
framesElidedSuffix = []byte("frames elided...")
)

var goroutineHeader = regexp.MustCompile(
`^(\d+) \[([^,]+)(?:, (\d+) minutes)?(, locked to thread)?\]:$`,
`^(\d+) [^[]*\[([^,]+)(?:, (\d+) minutes)?(, locked to thread)?\]:$`,
)

// parseGoroutineHeader parses a goroutine header line and returns a new
Expand All @@ -163,6 +163,7 @@ var goroutineHeader = regexp.MustCompile(
//
// Example Input:
// 1 [chan receive, 6883 minutes]:
// 1 gp=0xffffffffff m=0 mp=0xffffff [chan receive, 6883 minutes]:
//
// Example Output:
// &Goroutine{ID: 1, State "chan receive", Waitduration: 6883*time.Minute}
Expand Down
56 changes: 56 additions & 0 deletions test-fixtures/stackoverflow.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//go:build ignore
// +build ignore

package main

import (
"io"
"os"
"os/exec"
"runtime/debug"
"sync"
)

func main() {
crashOutput := os.Getenv("CRASH_OUTPUT")
if crashOutput != "" {
f, err := os.OpenFile(crashOutput, os.O_APPEND|os.O_WRONLY, 0600)
if err != nil {
panic(err)
}
debug.SetCrashOutput(f, debug.CrashOptions{})
f.Close()
debug.SetMaxStack(2 << 13)
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
overflow()
}()
wg.Wait()
} else {
exe, err := os.Executable()
if err != nil {
panic(err)
}
f, err := os.CreateTemp("", "*.crash")
if err != nil {
panic(err)
}
defer f.Close()
cmd := exec.Command(exe)
cmd.Env = append(os.Environ(), "CRASH_OUTPUT="+f.Name())
_, err = cmd.Output()
if err == nil {
panic("expected a crash")
}
_, err = io.Copy(os.Stdout, f)
if err != nil {
panic(err)
}
}
}

func overflow() {
overflow()
}
Loading