stack: move parsing constants
There was in stack.go, but used in context.go, so move them there.
No functional change.
diff --git a/stack/context.go b/stack/context.go
index fbc5933..49b5ac2 100644
--- a/stack/context.go
+++ b/stack/context.go
@@ -12,6 +12,7 @@
"os"
"os/user"
"path/filepath"
+ "regexp"
"runtime"
"sort"
"strconv"
@@ -83,6 +84,42 @@
// Private stuff.
+const lockedToThread = "locked to thread"
+
+// These are effectively constants.
+var (
+ // TODO(maruel): Handle corrupted stack cases:
+ // - missed stack barrier
+ // - found next stack barrier at 0x123; expected
+ // - runtime: unexpected return pc for FUNC_NAME called from 0x123
+
+ reRoutineHeader = regexp.MustCompile("^goroutine (\\d+) \\[([^\\]]+)\\]\\:\r?\n$")
+ reMinutes = regexp.MustCompile("^(\\d+) minutes$")
+ reUnavail = regexp.MustCompile("^(?:\t| +)goroutine running on other thread; stack unavailable")
+ // See gentraceback() in src/runtime/traceback.go for more information.
+ // - Sometimes the source file comes up as "<autogenerated>". It is the
+ // compiler than generated these, not the runtime.
+ // - The tab may be replaced with spaces when a user copy-paste it, handle
+ // this transparently.
+ // - "runtime.gopanic" is explicitly replaced with "panic" by gentraceback().
+ // - The +0x123 byte offset is printed when frame.pc > _func.entry. _func is
+ // generated by the linker.
+ // - The +0x123 byte offset is not included with generated code, e.g. unnamed
+ // functions "func·006()" which is generally go func() { ... }()
+ // statements. Since the _func is generated at runtime, it's probably why
+ // _func.entry is not set.
+ // - C calls may have fp=0x123 sp=0x123 appended. I think it normally happens
+ // when a signal is not correctly handled. It is printed with m.throwing>0.
+ // These are discarded.
+ // - For cgo, the source file may be "??".
+ reFile = regexp.MustCompile("^(?:\t| +)(\\?\\?|\\<autogenerated\\>|.+\\.(?:c|go|s))\\:(\\d+)(?:| \\+0x[0-9a-f]+)(?:| fp=0x[0-9a-f]+ sp=0x[0-9a-f]+)\r?\n$")
+ // Sadly, it doesn't note the goroutine number so we could cascade them per
+ // parenthood.
+ reCreated = regexp.MustCompile("^created by (.+)\r?\n$")
+ reFunc = regexp.MustCompile("^(.+)\\((.*)\\)\r?\n$")
+ reElided = regexp.MustCompile("^\\.\\.\\.additional frames elided\\.\\.\\.\r?\n$")
+)
+
func parseDump(r io.Reader, out io.Writer) ([]*Goroutine, error) {
scanner := bufio.NewScanner(r)
scanner.Split(scanLines)
diff --git a/stack/stack.go b/stack/stack.go
index 0e27466..cc684ba 100644
--- a/stack/stack.go
+++ b/stack/stack.go
@@ -14,49 +14,12 @@
"net/url"
"os"
"path/filepath"
- "regexp"
"sort"
"strings"
"unicode"
"unicode/utf8"
)
-const lockedToThread = "locked to thread"
-
-// These are effectively constants.
-var (
- // TODO(maruel): Handle corrupted stack cases:
- // - missed stack barrier
- // - found next stack barrier at 0x123; expected
- // - runtime: unexpected return pc for FUNC_NAME called from 0x123
-
- reRoutineHeader = regexp.MustCompile("^goroutine (\\d+) \\[([^\\]]+)\\]\\:\r?\n$")
- reMinutes = regexp.MustCompile("^(\\d+) minutes$")
- reUnavail = regexp.MustCompile("^(?:\t| +)goroutine running on other thread; stack unavailable")
- // See gentraceback() in src/runtime/traceback.go for more information.
- // - Sometimes the source file comes up as "<autogenerated>". It is the
- // compiler than generated these, not the runtime.
- // - The tab may be replaced with spaces when a user copy-paste it, handle
- // this transparently.
- // - "runtime.gopanic" is explicitly replaced with "panic" by gentraceback().
- // - The +0x123 byte offset is printed when frame.pc > _func.entry. _func is
- // generated by the linker.
- // - The +0x123 byte offset is not included with generated code, e.g. unnamed
- // functions "func·006()" which is generally go func() { ... }()
- // statements. Since the _func is generated at runtime, it's probably why
- // _func.entry is not set.
- // - C calls may have fp=0x123 sp=0x123 appended. I think it normally happens
- // when a signal is not correctly handled. It is printed with m.throwing>0.
- // These are discarded.
- // - For cgo, the source file may be "??".
- reFile = regexp.MustCompile("^(?:\t| +)(\\?\\?|\\<autogenerated\\>|.+\\.(?:c|go|s))\\:(\\d+)(?:| \\+0x[0-9a-f]+)(?:| fp=0x[0-9a-f]+ sp=0x[0-9a-f]+)\r?\n$")
- // Sadly, it doesn't note the goroutine number so we could cascade them per
- // parenthood.
- reCreated = regexp.MustCompile("^created by (.+)\r?\n$")
- reFunc = regexp.MustCompile("^(.+)\\((.*)\\)\r?\n$")
- reElided = regexp.MustCompile("^\\.\\.\\.additional frames elided\\.\\.\\.\r?\n$")
-)
-
// Func is a function call.
//
// Go stack traces print a mangled function call, this wrapper unmangle the