mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime/debug: fix incorrect Stack output if package path contains a dot
Although debug.Stack is deprecated, it should still return the correct result.
Output before this CL (using a trivial library in $GOPATH/test.com/a):
/home/vince/src/test.com/a/lib.go:9 (0x42311e)
com/a.ShowStack: os.Stdout.Write(debug.Stack())
Output with this CL applied:
/home/vince/src/test.com/a/lib.go:9 (0x42311e)
ShowStack: os.Stdout.Write(debug.Stack())
LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews
https://golang.org/cl/57330043
This commit is contained in:
parent
86a3a54284
commit
d7c14655a9
1 changed files with 6 additions and 0 deletions
|
|
@ -18,6 +18,7 @@ var (
|
||||||
dunno = []byte("???")
|
dunno = []byte("???")
|
||||||
centerDot = []byte("·")
|
centerDot = []byte("·")
|
||||||
dot = []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 Stack.
|
||||||
|
|
@ -84,6 +85,11 @@ func function(pc uintptr) []byte {
|
||||||
// runtime/debug.*T·ptrmethod
|
// runtime/debug.*T·ptrmethod
|
||||||
// and want
|
// and want
|
||||||
// *T.ptrmethod
|
// *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 {
|
if period := bytes.Index(name, dot); period >= 0 {
|
||||||
name = name[period+1:]
|
name = name[period+1:]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue