Skip to content

Commit 0b45582

Browse files
committed
Merge back CLI tools from v2.1.0.
Confirms that it makes v1 work with go1.16. With this: go get github.com/maruel/panicparse/cmd/pp does the right thing! It leverages an updated version of cmd/ and internal/, and then uses stack@v2 instead of stack/ here. Found a way to hack my way through: - Copied .github/workflows/test.yaml from v2.1.0. - Deleted all of vendor/. It was breaking the CI tests. - Updated stack/context_test.go to make it work with go1.16. - Updated stack/context_test.go to make it work with all of vendor/ removed. - Use v2.1.0 version of the executables in cmd/ and //main.go. - Use v2.1.0 version of the internal/. - Copied stack@v2.1.0 back into vendor/github.com/maruel/panicparse/v2/stack. Since older Go versions still look into it, they are able to load v2 even if go modules are disabled.
1 parent 025ad72 commit 0b45582

47 files changed

Lines changed: 8613 additions & 270 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cmd/panic/main.go

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,19 @@ import (
3737

3838
"github.com/maruel/panicparse/cmd/panic/internal"
3939
correct "github.com/maruel/panicparse/cmd/panic/internal/incorrect"
40-
"github.com/maruel/panicparse/cmd/panic/internal/ùtf8"
40+
ùtf8 "github.com/maruel/panicparse/cmd/panic/internal/utf8"
4141
)
4242

4343
func main() {
4444
if len(os.Args) == 2 {
45-
n := os.Args[1]
46-
if f, ok := types[n]; ok {
47-
fmt.Printf("GOTRACEBACK=%s\n", os.Getenv("GOTRACEBACK"))
48-
if n == "simple" {
49-
// Since the map lookup creates another call stack entry, add a one-off
50-
// "simple" panic style to test the very minimal case.
51-
// types["simple"].f is never called.
52-
panic("simple")
53-
}
54-
f.f()
55-
os.Exit(3)
56-
}
57-
// Undocumented command to do a raw dump of the supported commands. This is
58-
// used by unit tests in ../../stack.
59-
if n == "dump_commands" {
45+
switch n := os.Args[1]; n {
46+
case "-h", "-help", "--help", "help":
47+
usage()
48+
os.Exit(0)
49+
50+
case "dump_commands":
51+
// Undocumented command to do a raw dump of the supported commands. This
52+
// is used by unit tests in ../../stack.
6053
items := make([]string, 0, len(types))
6154
for n := range types {
6255
items = append(items, n)
@@ -66,11 +59,25 @@ func main() {
6659
fmt.Printf("%s\n", n)
6760
}
6861
os.Exit(0)
62+
63+
default:
64+
if f, ok := types[n]; ok {
65+
fmt.Printf("GOTRACEBACK=%s\n", os.Getenv("GOTRACEBACK"))
66+
if n == "simple" {
67+
// Since the map lookup creates another call stack entry, add a
68+
// one-off "simple" panic style to test the very minimal case.
69+
// types["simple"].f is never called.
70+
panic("simple")
71+
}
72+
f.f()
73+
os.Exit(3)
74+
}
75+
fmt.Fprintf(stdErr, "unknown panic style %q\n", n)
76+
os.Exit(1)
6977
}
70-
fmt.Fprintf(stdErr, "unknown panic style %q\n", n)
71-
os.Exit(1)
7278
}
7379
usage()
80+
os.Exit(1)
7481
}
7582

7683
// Mocked in test.
@@ -111,7 +118,7 @@ func panicRaceDisabled(name string) {
111118

112119
func rerunWithFastCrash() {
113120
if os.Getenv("GORACE") != "log_path=stderr halt_on_error=1" {
114-
os.Setenv("GORACE", "log_path=stderr halt_on_error=1")
121+
_ = os.Setenv("GORACE", "log_path=stderr halt_on_error=1")
115122
c := exec.Command(os.Args[0], os.Args[1:]...)
116123
c.Stderr = os.Stderr
117124
if err, ok := c.Run().(*exec.ExitError); ok {
@@ -413,7 +420,7 @@ Set GOTRACEBACK before running this tool to see how it affects the panic output.
413420
414421
Select the way to panic:
415422
`
416-
io.WriteString(stdErr, t)
423+
_, _ = io.WriteString(stdErr, t)
417424
names := make([]string, 0, len(types))
418425
m := 0
419426
for n := range types {
@@ -426,7 +433,6 @@ Select the way to panic:
426433
for _, n := range names {
427434
fmt.Fprintf(stdErr, "- %-*s %s\n", m, n, types[n].desc)
428435
}
429-
os.Exit(2)
430436
}
431437

432438
//

cmd/panicweb/internal/internal.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func GetAsync(url string) {
2727
if err != nil {
2828
log.Fatalf("failed to read: %v", err)
2929
}
30-
resp.Body.Close()
30+
_ = resp.Body.Close()
3131
log.Fatal("the goal is to not complete this request")
3232
}()
3333
}
@@ -39,7 +39,7 @@ func URL1Handler(w http.ResponseWriter, req *http.Request) {
3939
w.Header().Set("Content-Length", "100000")
4040
w.WriteHeader(200)
4141
b := [4096]byte{}
42-
w.Write(b[:])
42+
_, _ = w.Write(b[:])
4343
<-Unblock
4444
}
4545

@@ -50,6 +50,6 @@ func URL2Handler(w http.ResponseWriter, req *http.Request) {
5050
w.Header().Set("Content-Length", "100000")
5151
w.WriteHeader(200)
5252
b := [4096]byte{}
53-
w.Write(b[:])
53+
_, _ = w.Write(b[:])
5454
<-Unblock
5555
}

cmd/panicweb/main.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,26 @@ import (
2020
"net"
2121
"net/http"
2222
_ "net/http/pprof"
23+
"os"
2324
"runtime"
2425
"strings"
2526
"sync"
2627
"time"
2728

2829
"github.com/maruel/panicparse/cmd/panicweb/internal"
29-
"github.com/maruel/panicparse/stack/webstack"
30+
"github.com/maruel/panicparse/v2/stack/webstack"
3031
"github.com/mattn/go-colorable"
3132
)
3233

34+
var rootPage = []byte(`<!DOCTYPE html>
35+
<ul>
36+
<li><a href="/panicparse">/panicparse</a></li>
37+
<li><a href="/debug/pprof/goroutine?debug=2">/debug/pprof/goroutine?debug=2</a></li>
38+
<li><a href="/url1">/url1</a></li>
39+
<li><a href="/url2">/url2</a></li>
40+
</ul>
41+
`)
42+
3343
func main() {
3444
allowremote := flag.Bool("allowremote", false, "allows access from non-localhost; implies -wait")
3545
sleep := flag.Bool("wait", false, "sleep instead of crashing")
@@ -91,10 +101,22 @@ func main() {
91101
} else {
92102
http.HandleFunc("/panicparse", webstack.SnapshotHandler)
93103
}
104+
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
105+
w.Header().Set("Content-Type", "text/html; charset=utf-8")
106+
_, _ = w.Write(rootPage)
107+
})
94108
go http.Serve(ln, http.DefaultServeMux)
95109

96110
// Start many clients.
97-
url := "http://" + ln.Addr().String() + "/"
111+
a := ln.Addr()
112+
url := fmt.Sprintf("http://%s/", a)
113+
if *allowremote {
114+
if h, err := os.Hostname(); err == nil {
115+
if t, ok := a.(*net.TCPAddr); ok {
116+
url = fmt.Sprintf("http://%s:%d/", h, t.Port)
117+
}
118+
}
119+
}
98120
for i := 0; i < 10; i++ {
99121
internal.GetAsync(url + "url1")
100122
}

cmd/panicweb/main_unix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ package main
99
import "golang.org/x/sys/unix"
1010

1111
func sysHang() {
12-
unix.Nanosleep(&unix.Timespec{Sec: 366 * 24 * 60 * 60}, &unix.Timespec{})
12+
_ = unix.Nanosleep(&unix.Timespec{Sec: 366 * 24 * 60 * 60}, &unix.Timespec{})
1313
}

cmd/pp/main.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,10 @@
22
// Use of this source code is governed under the Apache License, Version 2.0
33
// that can be found in the LICENSE file.
44

5-
// panicparse: analyzes stack dump of Go processes and simplifies it.
5+
// pp: analyzes stack dump of Go processes and simplifies it.
66
//
77
// It is mostly useful on servers will large number of identical goroutines,
88
// making the crash dump harder to read than strictly necessary.
9-
//
10-
// Colors:
11-
// - Magenta: first goroutine to be listed.
12-
// - Yellow: main package.
13-
// - Green: standard library.
14-
// - Red: other packages.
15-
//
16-
// Bright colors are used for exported symbols.
179
package main
1810

1911
import (
@@ -24,7 +16,7 @@ import (
2416
)
2517

2618
func main() {
27-
if err := internal.Main("/cmd/pp"); err != nil {
19+
if err := internal.Main(); err != nil {
2820
fmt.Fprintf(os.Stderr, "Failed: %s\n", err)
2921
os.Exit(1)
3022
}

go.mod

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ module github.com/maruel/panicparse
33
go 1.11
44

55
require (
6-
github.com/google/go-cmp v0.4.0
7-
github.com/mattn/go-colorable v0.1.6
6+
github.com/google/go-cmp v0.5.1
7+
github.com/maruel/panicparse/v2 v2.1.0
8+
github.com/mattn/go-colorable v0.1.7
89
github.com/mattn/go-isatty v0.0.12
9-
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b
10-
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae
10+
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d
11+
golang.org/x/sys v0.0.0-20200724161237-0e2f3a69832c
1112
)

go.sum

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
2-
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
3-
github.com/mattn/go-colorable v0.1.6 h1:6Su7aK7lXmJ/U79bYtBjLNaha4Fs1Rg9plHpcH+vvnE=
4-
github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
1+
github.com/google/go-cmp v0.5.1 h1:JFrFEBb2xKufg6XkJsJr+WbKb4FQlURi5RUcBveYu9k=
2+
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
3+
github.com/maruel/panicparse/v2 v2.1.0 h1:Ml+NucJWyfNVA7YVXavI3EAwqGcPEY1epYjs4CSMwy0=
4+
github.com/maruel/panicparse/v2 v2.1.0/go.mod h1:AeTWdCE4lcq8OKsLb6cHSj1RWHVSnV9HBCk7sKLF4Jg=
5+
github.com/mattn/go-colorable v0.1.7 h1:bQGKb3vps/j0E9GfJQ03JyhRuxsvdAanXlT9BTw3mdw=
6+
github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
57
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
68
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
7-
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4=
8-
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
9+
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQE9x6ikvDFZS2mDVS3drnohI=
10+
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
911
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
1012
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8=
1113
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
14+
golang.org/x/sys v0.0.0-20200724161237-0e2f3a69832c h1:UIcGWL6/wpCfyGuJnRFJRurA+yj8RrW7Q6x2YMCXt6c=
15+
golang.org/x/sys v0.0.0-20200724161237-0e2f3a69832c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
1216
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
1317
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

internal/internaltest/go1.13.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright 2020 Marc-Antoine Ruel. All rights reserved.
2+
// Use of this source code is governed under the Apache License, Version 2.0
3+
// that can be found in the LICENSE file.
4+
5+
// +build go1.13
6+
7+
package internaltest
8+
9+
const wrap = "%w"

internal/internaltest/gopre1.13.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright 2020 Marc-Antoine Ruel. All rights reserved.
2+
// Use of this source code is governed under the Apache License, Version 2.0
3+
// that can be found in the LICENSE file.
4+
5+
// +build go1.1
6+
// +build !go1.13
7+
8+
package internaltest
9+
10+
const wrap = "%v"

0 commit comments

Comments
 (0)