Skip to content

Commit 8efd67e

Browse files
committed
panicweb: tweaks
- Print the hostname when -allowremote is used - Add an handler for / to help navigation
1 parent 98493fa commit 8efd67e

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

cmd/panicweb/main.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"net"
2121
"net/http"
2222
_ "net/http/pprof"
23+
"os"
2324
"runtime"
2425
"strings"
2526
"sync"
@@ -30,6 +31,15 @@ import (
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
}

stack/context_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2205,7 +2205,7 @@ func identifyPanicwebSignature(t *testing.T, b *Bucket, pwebDir string) panicweb
22052205
rest := []Call{
22062206
newCallLocal("main.sysHang", Args{}, pathJoin(pwebDir, mainOS), 12),
22072207
newCallLocal(
2208-
"main.main.func2",
2208+
"main.main.func3",
22092209
Args{Values: []Arg{{Value: 0xc000140720, Name: "#135", IsPtr: true}}},
22102210
pathJoin(pwebDir, "main.go"),
22112211
65),

0 commit comments

Comments
 (0)