c/debug: StackTrace

This commit is contained in:
visualfc
2024-11-29 11:27:56 +08:00
parent 67f9580c5d
commit 7b6b8b0eeb
3 changed files with 70 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
package main
import (
"unsafe"
"github.com/goplus/llgo/c/debug"
)
type T struct {
n int
}
func (t *T) Demo() {
println(t.n)
debug.StackTrace(0, func(fr *debug.Frame) bool {
var info debug.Info
debug.Addrinfo(unsafe.Pointer(fr.PC), &info)
println("[", fr.PC, "]", fr.Name, "+", fr.Offset, ", SP =", fr.SP)
return true
})
}
func main() {
t := &T{100}
t.Demo()
}