1
0
mirror of https://github.com/golang/go synced 2024-11-25 02:07:58 -07:00

http: use runtime/debug.Stack() to dump stack trace on panic.

Test output now looks like this:

2011/06/15 21:10:41 http: panic serving 127.0.0.1:59729: intentional death for testing
$GOROOT/src/pkg/http/server.go:495 (0x3f9f8)
        _func_004: buf.Write(debug.Stack())
$GOROOT/src/pkg/runtime/proc.c:1041 (0x12367)
        panic: reflect·call(d->fn, d->args, d->siz);
$GOROOT/src/pkg/http/serve_test.go:775 (0x5831b)
        _func_029: panic("intentional death for testing")
$GOROOT/src/pkg/http/server.go:575 (0x26366)
        HandlerFunc.ServeHTTP: f(w, r)
$GOROOT/src/pkg/http/server.go:541 (0x261a9)
        *conn.serve: c.handler.ServeHTTP(w, w.req)
$GOROOT/src/pkg/runtime/proc.c:178 (0x10a83)
        goexit: runtime·goexit(void)

with $GOROOT expanded, of course.

R=bradfitz, rsc
CC=golang-dev
https://golang.org/cl/4607051
This commit is contained in:
Rob Pike 2011-06-16 00:12:50 +10:00
parent 39208939c6
commit d6653fed98

View File

@ -20,7 +20,7 @@ import (
"net" "net"
"os" "os"
"path" "path"
"runtime" "runtime/debug"
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
@ -490,23 +490,9 @@ func (c *conn) serve() {
} }
c.rwc.Close() c.rwc.Close()
// TODO(rsc,bradfitz): this is boilerplate. move it to runtime.Stack()
var buf bytes.Buffer var buf bytes.Buffer
fmt.Fprintf(&buf, "http: panic serving %v: %v\n", c.remoteAddr, err) fmt.Fprintf(&buf, "http: panic serving %v: %v\n", c.remoteAddr, err)
for i := 1; i < 20; i++ { buf.Write(debug.Stack())
pc, file, line, ok := runtime.Caller(i)
if !ok {
break
}
var name string
f := runtime.FuncForPC(pc)
if f != nil {
name = f.Name()
} else {
name = fmt.Sprintf("%#x", pc)
}
fmt.Fprintf(&buf, " %s %s:%d\n", name, file, line)
}
log.Print(buf.String()) log.Print(buf.String())
}() }()