From fb6ec5f012eaf3bceff6d8b1658e8483ffa966b3 Mon Sep 17 00:00:00 2001 From: Viet Anh Duong Date: Tue, 21 Nov 2023 07:42:53 +0000 Subject: [PATCH] Add comments Signed-off-by: Viet Anh Duong --- bcc/module.go | 15 +++++++++++++-- examples/bcc/stack_trace/stack_trace.go | 4 ++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/bcc/module.go b/bcc/module.go index 02d9b01..f851a74 100644 --- a/bcc/module.go +++ b/bcc/module.go @@ -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 == "" { @@ -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) } diff --git a/examples/bcc/stack_trace/stack_trace.go b/examples/bcc/stack_trace/stack_trace.go index d7d77cb..8ed1e81 100644 --- a/examples/bcc/stack_trace/stack_trace.go +++ b/examples/bcc/stack_trace/stack_trace.go @@ -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) } }