Skip to content

Commit

Permalink
Add comments
Browse files Browse the repository at this point in the history
Signed-off-by: Viet Anh Duong <[email protected]>
  • Loading branch information
vietanhduong committed Nov 21, 2023
1 parent 83a7d89 commit fb6ec5f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
15 changes: 13 additions & 2 deletions bcc/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,11 @@ type ResolveSymbolOptions struct {
//
// Example output when both show module and show offset are set:
//
// "start_thread+0x202a0b6d [libpthread-2.24.so]"
// "net/http.HandlerFunc.ServeHTTP+0x0000002f [.app]"
//
// Example output when both show module and show offset are unset:
//
// "start_thread"
// "net/http.HandlerFunc.ServeHTTP"
func (bpf *Module) ResolveSymbol(pid int, addr uint64, opts ResolveSymbolOptions) string {
sym := bpf.GetSymCache(pid).Resolve(addr, !opts.NoDemangle)
if sym == nil || sym.Module == "" {
Expand All @@ -260,10 +260,21 @@ func (bpf *Module) ResolveSymbol(pid int, addr uint64, opts ResolveSymbolOptions
return name + module
}

// ResolveKernelSymbol translate a kernel memory address into a kernel function name, which
// is returned. When the show module is set, the module name ("kernel") is also included.
// When the show offset is set, the instruction offset as a hexadecimal number is also
// included in the string
//
// Example outout when both show module and show offset are set:
//
// "__x64_sys_epoll_pwait+0x00000077 [kernel]"
func (bpf *Module) ResolveKernelSymbol(addr uint64, opts ResolveSymbolOptions) string {
return bpf.ResolveSymbol(-1, addr, opts)
}

// ResolveKernelSymbolAddr translate a kernel name into address. This is the reverse of
// ResolveKernelSymbol. This function will return an error if unable to resolve the
// function name.
func (bpf *Module) ResolveKernelSymbolAddr(name string) (uint64, error) {
return bpf.GetSymCache(-1).ResolveName("", name)
}
Expand Down
4 changes: 2 additions & 2 deletions examples/bcc/stack_trace/stack_trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,14 @@ func main() {
if stack.userStackId > 0 {
addrs := stackTable.GetStackAddr(int(stack.userStackId), true)
for _, addr := range addrs {
symbols = append(symbols, m.ResolveSymbol(pid, addr, bcc.ResolveSymbolOptions{}))
symbols = append(symbols, m.ResolveSymbol(pid, addr, bcc.ResolveSymbolOptions{ShowOffset: true, ShowModule: true}))
}
}

if stack.kernelStackId > 0 {
addrs := stackTable.GetStackAddr(int(stack.kernelStackId), true)
for _, addr := range addrs {
sym := m.ResolveKernelSymbol(addr, bcc.ResolveSymbolOptions{ShowModule: true})
sym := m.ResolveKernelSymbol(addr, bcc.ResolveSymbolOptions{ShowModule: true, ShowOffset: true})
symbols = append(symbols, sym)
}
}
Expand Down

0 comments on commit fb6ec5f

Please sign in to comment.