diff options
author | Ian Lance Taylor <iant@google.com> | 2016-02-03 21:58:02 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2016-02-03 21:58:02 +0000 |
commit | f98dd1a338867a408f7c72d73fbad7fe7fc93e3a (patch) | |
tree | 2f8da9862a9c1fe0df138917f997b03439c02773 /libgo/go/runtime/debug | |
parent | b081ed4efc144da0c45a6484aebfd10e0eb9fda3 (diff) | |
download | gcc-f98dd1a338867a408f7c72d73fbad7fe7fc93e3a.zip gcc-f98dd1a338867a408f7c72d73fbad7fe7fc93e3a.tar.gz gcc-f98dd1a338867a408f7c72d73fbad7fe7fc93e3a.tar.bz2 |
libgo: Update to go1.6rc1.
Reviewed-on: https://go-review.googlesource.com/19200
From-SVN: r233110
Diffstat (limited to 'libgo/go/runtime/debug')
-rw-r--r-- | libgo/go/runtime/debug/garbage.go | 11 | ||||
-rw-r--r-- | libgo/go/runtime/debug/garbage_test.go | 5 | ||||
-rw-r--r-- | libgo/go/runtime/debug/heapdump_test.go | 3 | ||||
-rw-r--r-- | libgo/go/runtime/debug/stack.go | 86 | ||||
-rw-r--r-- | libgo/go/runtime/debug/stack_test.go | 33 |
5 files changed, 42 insertions, 96 deletions
diff --git a/libgo/go/runtime/debug/garbage.go b/libgo/go/runtime/debug/garbage.go index c3363f9..0f8a44c 100644 --- a/libgo/go/runtime/debug/garbage.go +++ b/libgo/go/runtime/debug/garbage.go @@ -151,3 +151,14 @@ func SetPanicOnFault(enabled bool) bool // it to the given file descriptor. // The heap dump format is defined at https://golang.org/s/go13heapdump. func WriteHeapDump(fd uintptr) + +// SetTraceback sets the amount of detail printed by the runtime in +// the traceback it prints before exiting due to an unrecovered panic +// or an internal runtime error. +// The level argument takes the same values as the GOTRACEBACK +// environment variable. For example, SetTraceback("all") ensure +// that the program prints all goroutines when it crashes. +// See the package runtime documentation for details. +// If SetTraceback is called with a level lower than that of the +// environment variable, the call is ignored. +func SetTraceback(level string) diff --git a/libgo/go/runtime/debug/garbage_test.go b/libgo/go/runtime/debug/garbage_test.go index 13e1845..21bf6eb 100644 --- a/libgo/go/runtime/debug/garbage_test.go +++ b/libgo/go/runtime/debug/garbage_test.go @@ -2,10 +2,11 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package debug +package debug_test import ( "runtime" + . "runtime/debug" "testing" "time" ) @@ -75,7 +76,7 @@ func TestReadGCStats(t *testing.T) { var big = make([]byte, 1<<20) func TestFreeOSMemory(t *testing.T) { - if runtime.GOARCH == "arm64" || runtime.GOARCH == "ppc64" || runtime.GOARCH == "ppc64le" || + if runtime.GOARCH == "arm64" || runtime.GOARCH == "ppc64" || runtime.GOARCH == "ppc64le" || runtime.GOARCH == "mips64" || runtime.GOARCH == "mips64le" || runtime.GOOS == "nacl" { t.Skip("issue 9993; scavenger temporarily disabled on systems with physical pages larger than logical pages") } diff --git a/libgo/go/runtime/debug/heapdump_test.go b/libgo/go/runtime/debug/heapdump_test.go index cb2f2f0..5761c01 100644 --- a/libgo/go/runtime/debug/heapdump_test.go +++ b/libgo/go/runtime/debug/heapdump_test.go @@ -2,12 +2,13 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package debug +package debug_test import ( "io/ioutil" "os" "runtime" + . "runtime/debug" "testing" ) diff --git a/libgo/go/runtime/debug/stack.go b/libgo/go/runtime/debug/stack.go index ab12bff..5d810af 100644 --- a/libgo/go/runtime/debug/stack.go +++ b/libgo/go/runtime/debug/stack.go @@ -7,92 +7,24 @@ package debug import ( - "bytes" - "fmt" - "io/ioutil" "os" "runtime" ) -var ( - dunno = []byte("???") - centerDot = []byte("·") - dot = []byte(".") - slash = []byte("/") -) - -// PrintStack prints to standard error the stack trace returned by Stack. +// PrintStack prints to standard error the stack trace returned by runtime.Stack. func PrintStack() { - os.Stderr.Write(stack()) + os.Stderr.Write(Stack()) } // Stack returns a formatted stack trace of the goroutine that calls it. -// For each routine, it includes the source line information and PC value, -// then attempts to discover, for Go functions, the calling function or -// method and the text of the line containing the invocation. -// -// Deprecated: Use package runtime's Stack instead. +// It calls runtime.Stack with a large enough buffer to capture the entire trace. func Stack() []byte { - return stack() -} - -// stack implements Stack, skipping 2 frames -func stack() []byte { - buf := new(bytes.Buffer) // the returned data - // As we loop, we open files and read them. These variables record the currently - // loaded file. - var lines [][]byte - var lastFile string - for i := 2; ; i++ { // Caller we care about is the user, 2 frames up - pc, file, line, ok := runtime.Caller(i) - if !ok { - break + buf := make([]byte, 1024) + for { + n := runtime.Stack(buf, false) + if n < len(buf) { + return buf[:n] } - // Print this much at least. If we can't find the source, it won't show. - fmt.Fprintf(buf, "%s:%d (0x%x)\n", file, line, pc) - if file != lastFile { - data, err := ioutil.ReadFile(file) - if err != nil { - continue - } - lines = bytes.Split(data, []byte{'\n'}) - lastFile = file - } - line-- // in stack trace, lines are 1-indexed but our array is 0-indexed - fmt.Fprintf(buf, "\t%s: %s\n", function(pc), source(lines, line)) - } - return buf.Bytes() -} - -// source returns a space-trimmed slice of the n'th line. -func source(lines [][]byte, n int) []byte { - if n < 0 || n >= len(lines) { - return dunno - } - return bytes.Trim(lines[n], " \t") -} - -// function returns, if possible, the name of the function containing the PC. -func function(pc uintptr) []byte { - fn := runtime.FuncForPC(pc) - if fn == nil { - return dunno - } - name := []byte(fn.Name()) - // The name includes the path name to the package, which is unnecessary - // since the file name is already included. Plus, it has center dots. - // That is, we see - // runtime/debug.*T·ptrmethod - // and want - // *T.ptrmethod - // Since the package path might contains dots (e.g. code.google.com/...), - // we first remove the path prefix if there is one. - if lastslash := bytes.LastIndex(name, slash); lastslash >= 0 { - name = name[lastslash+1:] - } - if period := bytes.Index(name, dot); period >= 0 { - name = name[period+1:] + buf = make([]byte, 2*len(buf)) } - name = bytes.Replace(name, centerDot, dot, -1) - return name } diff --git a/libgo/go/runtime/debug/stack_test.go b/libgo/go/runtime/debug/stack_test.go index 263d715..0f769ee 100644 --- a/libgo/go/runtime/debug/stack_test.go +++ b/libgo/go/runtime/debug/stack_test.go @@ -2,9 +2,10 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package debug +package debug_test import ( + . "runtime/debug" "strings" "testing" ) @@ -22,16 +23,19 @@ func (t T) method() []byte { The traceback should look something like this, modulo line numbers and hex constants. Don't worry much about the base levels, but check the ones in our own package. - /Users/r/go/src/pkg/runtime/debug/stack_test.go:15 (0x13878) - (*T).ptrmethod: return Stack() - /Users/r/go/src/pkg/runtime/debug/stack_test.go:18 (0x138dd) - T.method: return t.ptrmethod() - /Users/r/go/src/pkg/runtime/debug/stack_test.go:23 (0x13920) - TestStack: b := T(0).method() - /Users/r/go/src/pkg/testing/testing.go:132 (0x14a7a) - tRunner: test.F(t) - /Users/r/go/src/pkg/runtime/proc.c:145 (0xc970) - ???: runtime·unlock(&runtime·sched); + goroutine 10 [running]: + runtime/debug.Stack(0x0, 0x0, 0x0) + /Users/r/go/src/runtime/debug/stack.go:28 +0x80 + runtime/debug.(*T).ptrmethod(0xc82005ee70, 0x0, 0x0, 0x0) + /Users/r/go/src/runtime/debug/stack_test.go:15 +0x29 + runtime/debug.T.method(0x0, 0x0, 0x0, 0x0) + /Users/r/go/src/runtime/debug/stack_test.go:18 +0x32 + runtime/debug.TestStack(0xc8201ce000) + /Users/r/go/src/runtime/debug/stack_test.go:37 +0x38 + testing.tRunner(0xc8201ce000, 0x664b58) + /Users/r/go/src/testing/testing.go:456 +0x98 + created by testing.RunTests + /Users/r/go/src/testing/testing.go:561 +0x86d */ func TestStack(t *testing.T) { b := T(0).method() @@ -41,13 +45,10 @@ func TestStack(t *testing.T) { } n := 0 frame := func(line, code string) { + check(t, lines[n], code) + n++ check(t, lines[n], line) n++ - // The source might not be available while running the test. - if strings.HasPrefix(lines[n], "\t") { - check(t, lines[n], code) - n++ - } } frame("stack_test.go", "\tmethod.N15_runtime_debug.T: return Stack()") frame("stack_test.go", "\tmethod.N15_runtime_debug.T: return t.ptrmethod()") |