Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add module.GetSymbolByAddr / GetDemangleSymbolByAddr #232

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions bcc/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,14 @@ func (bpf *Module) RemoveXDP(devName string) error {
return bpf.attachXDP(devName, -1, 0)
}

// translate address to symbol for specific pid
func (bpf *Module) GetSymbolByAddr(addr uint64, pid int) string {
return bccSymbolByAddr(addr,pid,1)
}
func (bpf *Module) GetDemangleSymbolByAddr(addr uint64, pid int) string {
return bccSymbolByAddr(addr,pid,0)
}

func GetSyscallFnName(name string) string {
return GetSyscallPrefix() + name
}
Expand Down
27 changes: 26 additions & 1 deletion bcc/symbol.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,32 @@ type bccSymbolOption struct {
checkDebugFileCrc int
useSymbolType uint32
}

//return symbol assigned to the address
func bccSymbolByAddr(addr uint64, pid int, demangle int) string{
pidC := C.int(pid)
so := &bccSymbolOption{}
soC := (*C.struct_bcc_symbol_option)(unsafe.Pointer(so))
cache := C.bcc_symcache_new(pidC, soC)
sym := &bccSymbol{}
symC := (*C.struct_bcc_symbol)(unsafe.Pointer(sym))
addrC := C.uint64_t(addr)
defer C.bcc_symbol_free_demangle_name(symC)
if demangle > 0 {
res := C.bcc_symcache_resolve(cache, addrC, symC)
if res < 0 {
return ""
}else{
return C.GoString(symC.demangle_name)
}
}else{
res := C.bcc_symcache_resolve_no_demangle(cache, addrC, symC)
if res < 0 {
return ""
}else{
return C.GoString(symC.name) //symC.name
}
}
}
// resolveSymbolPath returns the file and offset to locate symname in module
func resolveSymbolPath(module string, symname string, addr uint64, pid int) (string, uint64, error) {
if pid == -1 {
Expand Down