Commit 03ab5e8f authored by Sasha Goldshtein's avatar Sasha Goldshtein

Fix symbol resolution by name (SymbolCache.resolve_name)

The implementation of `ProcSyms::resolve_name` was only valid for
kernel symbols, when there is no module. When a module was provided,
it would segfault due to the module being null. Fixed by making
`bcc_symcache_resolve_name` take an additional module parameter,
which, for kernel symbols, is simply null (`None` from Python).
parent 01553853
...@@ -226,10 +226,10 @@ int bcc_symcache_resolve(void *resolver, uint64_t addr, ...@@ -226,10 +226,10 @@ int bcc_symcache_resolve(void *resolver, uint64_t addr,
return cache->resolve_addr(addr, sym) ? 0 : -1; return cache->resolve_addr(addr, sym) ? 0 : -1;
} }
int bcc_symcache_resolve_name(void *resolver, const char *name, int bcc_symcache_resolve_name(void *resolver, const char *module,
uint64_t *addr) { const char *name, uint64_t *addr) {
SymbolCache *cache = static_cast<SymbolCache *>(resolver); SymbolCache *cache = static_cast<SymbolCache *>(resolver);
return cache->resolve_name(nullptr, name, addr) ? 0 : -1; return cache->resolve_name(module, name, addr) ? 0 : -1;
} }
void bcc_symcache_refresh(void *resolver) { void bcc_symcache_refresh(void *resolver) {
......
...@@ -35,7 +35,8 @@ void *bcc_symcache_new(int pid); ...@@ -35,7 +35,8 @@ void *bcc_symcache_new(int pid);
void bcc_free_symcache(void *symcache, int pid); void bcc_free_symcache(void *symcache, int pid);
int bcc_symcache_resolve(void *symcache, uint64_t addr, struct bcc_symbol *sym); int bcc_symcache_resolve(void *symcache, uint64_t addr, struct bcc_symbol *sym);
int bcc_symcache_resolve_name(void *resolver, const char *name, uint64_t *addr); int bcc_symcache_resolve_name(void *resolver, const char *module,
const char *name, uint64_t *addr);
void bcc_symcache_refresh(void *resolver); void bcc_symcache_refresh(void *resolver);
int bcc_resolve_global_addr(int pid, const char *module, const uint64_t address, int bcc_resolve_global_addr(int pid, const char *module, const uint64_t address,
......
...@@ -68,9 +68,10 @@ class SymbolCache(object): ...@@ -68,9 +68,10 @@ class SymbolCache(object):
return (sym.demangle_name.decode(), sym.offset, return (sym.demangle_name.decode(), sym.offset,
ct.cast(sym.module, ct.c_char_p).value.decode()) ct.cast(sym.module, ct.c_char_p).value.decode())
def resolve_name(self, name): def resolve_name(self, module, name):
addr = ct.c_ulonglong() addr = ct.c_ulonglong()
if lib.bcc_symcache_resolve_name(self.cache, name, ct.pointer(addr)) < 0: if lib.bcc_symcache_resolve_name(
self.cache, module, name, ct.pointer(addr)) < 0:
return -1 return -1
return addr.value return addr.value
...@@ -1023,7 +1024,7 @@ class BPF(object): ...@@ -1023,7 +1024,7 @@ class BPF(object):
Translate a kernel name into an address. This is the reverse of Translate a kernel name into an address. This is the reverse of
ksym. Returns -1 when the function name is unknown.""" ksym. Returns -1 when the function name is unknown."""
return BPF._sym_cache(-1).resolve_name(name) return BPF._sym_cache(-1).resolve_name(None, name)
def num_open_kprobes(self): def num_open_kprobes(self):
"""num_open_kprobes() """num_open_kprobes()
......
...@@ -154,7 +154,7 @@ lib.bcc_symcache_resolve.argtypes = [ct.c_void_p, ct.c_ulonglong, ct.POINTER(bcc ...@@ -154,7 +154,7 @@ lib.bcc_symcache_resolve.argtypes = [ct.c_void_p, ct.c_ulonglong, ct.POINTER(bcc
lib.bcc_symcache_resolve_name.restype = ct.c_int lib.bcc_symcache_resolve_name.restype = ct.c_int
lib.bcc_symcache_resolve_name.argtypes = [ lib.bcc_symcache_resolve_name.argtypes = [
ct.c_void_p, ct.c_char_p, ct.POINTER(ct.c_ulonglong)] ct.c_void_p, ct.c_char_p, ct.c_char_p, ct.POINTER(ct.c_ulonglong)]
lib.bcc_symcache_refresh.restype = None lib.bcc_symcache_refresh.restype = None
lib.bcc_symcache_refresh.argtypes = [ct.c_void_p] lib.bcc_symcache_refresh.argtypes = [ct.c_void_p]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment