Skip to content

Commit

Permalink
Fix symbol resolution by name (SymbolCache.resolve_name)
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
goldshtn committed Feb 21, 2017
1 parent 0155385 commit 03ab5e8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/cc/bcc_syms.cc
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,10 @@ int bcc_symcache_resolve(void *resolver, uint64_t addr,
return cache->resolve_addr(addr, sym) ? 0 : -1;
}

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) {
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) {
Expand Down
3 changes: 2 additions & 1 deletion src/cc/bcc_syms.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ void *bcc_symcache_new(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_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);

int bcc_resolve_global_addr(int pid, const char *module, const uint64_t address,
Expand Down
7 changes: 4 additions & 3 deletions src/python/bcc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ def resolve(self, addr):
return (sym.demangle_name.decode(), sym.offset,
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()
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 addr.value

Expand Down Expand Up @@ -1023,7 +1024,7 @@ def ksymname(name):
Translate a kernel name into an address. This is the reverse of
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):
"""num_open_kprobes()
Expand Down
2 changes: 1 addition & 1 deletion src/python/bcc/libbcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class bcc_symbol(ct.Structure):

lib.bcc_symcache_resolve_name.restype = ct.c_int
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.argtypes = [ct.c_void_p]
Expand Down

0 comments on commit 03ab5e8

Please sign in to comment.