Dimitri Rakitine
unread,Nov 13, 2009, 11:49:11 PM11/13/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to golang-nuts
From the documentation I thought that runtime.Caller(frame) will
return false when it is not possible to obtain information - instead
it causes program to crash past call stack top :
package main
import (
"fmt";
"runtime";
"strings"
)
func main() {
foo()
}
func foo() {
bar()
}
func bar() {
for i := 0; ; i++ {
_, file, line, ok := runtime.Caller(i);
if ok {
path := strings.Split(file, "/", 0);
fmt.Printf("%s : %d\n", path[len(path)-1], line);
} else {
break;
}
}
}
results in
stacktrace.go : 19
stacktrace.go : 14
stacktrace.go : 10
asm.s : 81
proc.c : 135
Bus error
Also, Caller() doc says 'The argument is the number of stack frames to
ascend, with 1 identifying the the caller of Caller', while in fact,
it looks like 0 is the caller of Caller.
So, how do I obtain current thread stacktrace ?
TIA,
Dimitri