]> Cypherpunks repositories - gostls13.git/commitdiff
http: use runtime/debug.Stack() to dump stack trace on panic.
authorRob Pike <r@golang.org>
Wed, 15 Jun 2011 14:12:50 +0000 (00:12 +1000)
committerRob Pike <r@golang.org>
Wed, 15 Jun 2011 14:12:50 +0000 (00:12 +1000)
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

src/pkg/http/server.go

index d4638f127c7238fffb455bc64b081237352cbf31..c697ef0d3e2864b3f9ae65ff8ded1a31018d41fc 100644 (file)
@@ -20,7 +20,7 @@ import (
        "net"
        "os"
        "path"
-       "runtime"
+       "runtime/debug"
        "strconv"
        "strings"
        "sync"
@@ -490,23 +490,9 @@ func (c *conn) serve() {
                }
                c.rwc.Close()
 
-               // TODO(rsc,bradfitz): this is boilerplate. move it to runtime.Stack()
                var buf bytes.Buffer
                fmt.Fprintf(&buf, "http: panic serving %v: %v\n", c.remoteAddr, err)
-               for i := 1; i < 20; i++ {
-                       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)
-               }
+               buf.Write(debug.Stack())
                log.Print(buf.String())
        }()