runtime: show stacktrace when panic

This commit is contained in:
Li Jie
2025-01-02 21:45:11 +08:00
parent 5131881bf2
commit 65f855b251
4 changed files with 56 additions and 1 deletions

View File

@@ -20,6 +20,7 @@ import (
"unsafe"
"github.com/goplus/llgo/c"
"github.com/goplus/llgo/c/debug"
"github.com/goplus/llgo/c/pthread"
"github.com/goplus/llgo/c/signal"
"github.com/goplus/llgo/c/syscall"
@@ -61,6 +62,13 @@ func Rethrow(link *Defer) {
if ptr := excepKey.Get(); ptr != nil {
if link == nil {
TracePanic(*(*any)(ptr))
debug.StackTrace(0, func(fr *debug.Frame) bool {
var info debug.Info
debug.Addrinfo(unsafe.Pointer(fr.PC), &info)
c.Fprintf(c.Stderr, c.Str("[0x%08X %s+0x%x, SP = 0x%x]\n"), fr.PC, fr.Name, fr.Offset, fr.SP)
return true
})
c.Free(ptr)
c.Exit(2)
} else {