-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/goplus/llgo/c" | ||
"github.com/goplus/llgo/c/debug" | ||
) | ||
|
||
type T struct { | ||
n int | ||
} | ||
|
||
func (t *T) Demo() { | ||
println(t.n) | ||
addr := debug.Address() | ||
c.Printf(c.Str("addr:0x%x\n"), addr) | ||
var info debug.Info | ||
r := debug.Addrinfo(addr, &info) | ||
if r == 0 { | ||
panic("not found info") | ||
} | ||
c.Printf(c.Str("func file:%s name:%s base:0x%x addr:0x%x\n"), info.Fname, info.Sname, info.Fbase, info.Saddr) | ||
} | ||
|
||
func main() { | ||
t := &T{100} | ||
t.Demo() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#if defined(__linux__) | ||
#define _GNU_SOURCE | ||
#include <features.h> | ||
#endif | ||
|
||
#include <dlfcn.h> | ||
|
||
void *llgo_address() { | ||
return __builtin_return_address(0); | ||
} | ||
|
||
int llgo_addrinfo(void *addr, Dl_info *info) { | ||
return dladdr(addr, info); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package debug | ||
|
||
import ( | ||
"unsafe" | ||
|
||
"github.com/goplus/llgo/c" | ||
) | ||
|
||
const ( | ||
LLGoPackage = "link" | ||
LLGoFiles = "_wrap/debug.c" | ||
) | ||
|
||
type Info struct { | ||
Fname *c.Char | ||
Fbase c.Pointer | ||
Sname *c.Char | ||
Saddr c.Pointer | ||
} | ||
|
||
//go:linkname Address C.llgo_address | ||
func Address() unsafe.Pointer | ||
|
||
//go:linkname Addrinfo C.llgo_addrinfo | ||
func Addrinfo(addr unsafe.Pointer, info *Info) c.Int |