From a597f7c9c38a73d26ca4541b07f0c3408b2e7ca8 Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Sun, 1 May 2016 12:52:46 +0200 Subject: [PATCH] cc: Implement `bcc_resolve_global_addr` helper --- src/cc/bcc_syms.cc | 26 ++++++++++++++++++++++++++ src/cc/bcc_syms.h | 2 ++ 2 files changed, 28 insertions(+) diff --git a/src/cc/bcc_syms.cc b/src/cc/bcc_syms.cc index b656893..005ec61 100644 --- a/src/cc/bcc_syms.cc +++ b/src/cc/bcc_syms.cc @@ -199,6 +199,32 @@ void bcc_symcache_refresh(void *resolver) { cache->refresh(); } +struct mod_st { + const char *name; + uint64_t start; +}; + +static int _find_module(const char *modname, uint64_t start, uint64_t end, + void *p) { + struct mod_st *mod = (struct mod_st *)p; + if (!strcmp(modname, mod->name)) { + mod->start = start; + return -1; + } + return 0; +} + +int bcc_resolve_global_addr(int pid, const char *module, const uint64_t address, + uint64_t *global) { + struct mod_st mod = {module, 0x0}; + if (bcc_procutils_each_module(pid, _find_module, &mod) < 0 || + mod.start == 0x0) + return -1; + + *global = mod.start + address; + return 0; +} + static int _find_sym(const char *symname, uint64_t addr, uint64_t end, int flags, void *payload) { struct bcc_symbol *sym = (struct bcc_symbol *)payload; diff --git a/src/cc/bcc_syms.h b/src/cc/bcc_syms.h index d82054a..41e57f2 100644 --- a/src/cc/bcc_syms.h +++ b/src/cc/bcc_syms.h @@ -33,6 +33,8 @@ 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); void bcc_symcache_refresh(void *resolver); +int bcc_resolve_global_addr(int pid, const char *module, const uint64_t address, + uint64_t *global); int bcc_find_symbol_addr(struct bcc_symbol *sym); int bcc_resolve_symname(const char *module, const char *symname, const uint64_t addr, struct bcc_symbol *sym); -- 2.7.4