if (pid < 0)
pid = -1;
if (pid_sym_.find(pid) == pid_sym_.end())
- pid_sym_[pid] = bcc_symcache_new(pid);
+ pid_sym_[pid] = bcc_symcache_new(pid, nullptr);
void* cache = pid_sym_[pid];
bcc_symbol symbol;
*/
#include <cxxabi.h>
+#include <cstring>
#include <fcntl.h>
#include <linux/elf.h>
#include <string.h>
setns(mount_ns_->self_fd_, CLONE_NEWNS);
}
-ProcSyms::ProcSyms(int pid)
+ProcSyms::ProcSyms(int pid, struct bcc_symbol_option *option)
: pid_(pid), procstat_(pid), mount_ns_instance_(new ProcMountNS(pid_)) {
+ if (option)
+ std::memcpy(&symbol_option_, option, sizeof(bcc_symbol_option));
+ else
+ symbol_option_ = {
+ .use_debug_file = 1,
+ .check_debug_file_crc = 1,
+ .use_symbol_type = (1 << STT_FUNC) | (1 << STT_GNU_IFUNC)
+ };
load_modules();
}
[=](const ProcSyms::Module &m) { return m.name_ == modname; });
if (it == ps->modules_.end()) {
auto module = Module(
- modname, check_mount_ns ? ps->mount_ns_instance_.get() : nullptr);
+ modname, check_mount_ns ? ps->mount_ns_instance_.get() : nullptr,
+ &ps->symbol_option_);
if (module.init())
it = ps->modules_.insert(ps->modules_.end(), std::move(module));
else
return false;
}
-ProcSyms::Module::Module(const char *name, ProcMountNS *mount_ns)
+ProcSyms::Module::Module(const char *name, ProcMountNS *mount_ns,
+ struct bcc_symbol_option *option)
: name_(name),
loaded_(false),
mount_ns_(mount_ns),
+ symbol_option_(option),
type_(ModuleType::UNKNOWN) {}
bool ProcSyms::Module::init() {
if (type_ == ModuleType::PERF_MAP)
bcc_perf_map_foreach_sym(name_.c_str(), _add_symbol, this);
if (type_ == ModuleType::EXEC || type_ == ModuleType::SO)
- bcc_elf_foreach_sym(name_.c_str(), _add_symbol, this);
+ bcc_elf_foreach_sym(name_.c_str(), _add_symbol, symbol_option_, this);
std::sort(syms_.begin(), syms_.end());
}
extern "C" {
-void *bcc_symcache_new(int pid) {
+void *bcc_symcache_new(int pid, struct bcc_symbol_option *option) {
if (pid < 0)
return static_cast<void *>(new KSyms());
- return static_cast<void *>(new ProcSyms(pid));
+ return static_cast<void *>(new ProcSyms(pid, option));
}
void bcc_free_symcache(void *symcache, int pid) {
uint32_t use_symbol_type;
};
-void *bcc_symcache_new(int pid);
+void *bcc_symcache_new(int pid, struct bcc_symbol_option *option);
void bcc_free_symcache(void *symcache, int pid);
// The demangle_name pointer in bcc_symbol struct is returned from the
#include <vector>
#include "file_desc.h"
+#include "bcc_syms.h"
class ProcStat {
std::string procfs_;
Range(uint64_t s, uint64_t e) : start(s), end(e) {}
};
- Module(const char *name, ProcMountNS* mount_ns);
+ Module(const char *name, ProcMountNS* mount_ns,
+ struct bcc_symbol_option *option);
bool init();
std::string name_;
std::vector<Range> ranges_;
bool loaded_;
ProcMountNS *mount_ns_;
+ bcc_symbol_option *symbol_option_;
ModuleType type_;
std::unordered_set<std::string> symnames_;
std::vector<Module> modules_;
ProcStat procstat_;
std::unique_ptr<ProcMountNS> mount_ns_instance_;
+ bcc_symbol_option symbol_option_;
static int _add_module(const char *, uint64_t, uint64_t, bool, void *);
bool load_modules();
public:
- ProcSyms(int pid);
+ ProcSyms(int pid, struct bcc_symbol_option *option = nullptr);
virtual void refresh();
virtual bool resolve_addr(uint64_t addr, struct bcc_symbol *sym, bool demangle = true);
virtual bool resolve_name(const char *module, const char *name,
bool Argument::get_global_address(uint64_t *address, const std::string &binpath,
const optional<int> &pid) const {
if (pid) {
- return ProcSyms(*pid)
+ static struct bcc_symbol_option default_option = {
+ .use_debug_file = 1,
+ .check_debug_file_crc = 1,
+ .use_symbol_type = BCC_SYM_ALL_TYPES
+ };
+ return ProcSyms(*pid, &default_option)
.resolve_name(binpath.c_str(), deref_ident_->c_str(), address);
}
int pid, struct bcc_symbol_option *option,
struct bcc_symbol *sym);
void bcc_procutils_free(const char *ptr);
-void *bcc_symcache_new(int pid);
+void *bcc_symcache_new(int pid, struct bcc_symbol_option *option);
void bcc_symbol_free_demangle_name(struct bcc_symbol *sym);
int bcc_symcache_resolve(void *symcache, uint64_t addr, struct bcc_symbol *sym);
void bcc_symcache_refresh(void *resolver);
local function create_cache(pid)
return {
- _CACHE = libbcc.bcc_symcache_new(pid or -1),
+ _CACHE = libbcc.bcc_symcache_new(pid or -1, nil),
resolve = function(self, addr)
local sym = SYM()
if libbcc.bcc_symcache_resolve(self._CACHE, addr, sym) < 0 then
class SymbolCache(object):
def __init__(self, pid):
- self.cache = lib.bcc_symcache_new(pid)
+ self.cache = lib.bcc_symcache_new(
+ pid, ct.cast(None, ct.POINTER(bcc_symbol_option)))
def resolve(self, addr, demangle):
"""
lib.bcc_foreach_function_symbol.argtypes = [ct.c_char_p, _SYM_CB_TYPE]
lib.bcc_symcache_new.restype = ct.c_void_p
-lib.bcc_symcache_new.argtypes = [ct.c_int]
+lib.bcc_symcache_new.argtypes = [ct.c_int, ct.POINTER(bcc_symbol_option)]
lib.bcc_free_symcache.restype = ct.c_void_p
lib.bcc_free_symcache.argtypes = [ct.c_void_p, ct.c_int]
TEST_CASE("resolve symbol addresses for a given PID", "[c_api]") {
struct bcc_symbol sym;
- void *resolver = bcc_symcache_new(getpid());
+ void *resolver = bcc_symcache_new(getpid(), nullptr);
REQUIRE(resolver);
child = spawn_child(0, true, true, mntns_func);
REQUIRE(child > 0);
- void *resolver = bcc_symcache_new(child);
+ void *resolver = bcc_symcache_new(child, nullptr);
REQUIRE(resolver);
REQUIRE(bcc_symcache_resolve_name(resolver, "/tmp/libz.so.1", "zlibVersion",
child = spawn_child(map_addr, /* own_pidns */ false, false, perf_map_func);
REQUIRE(child > 0);
- void *resolver = bcc_symcache_new(child);
+ void *resolver = bcc_symcache_new(child, nullptr);
REQUIRE(resolver);
REQUIRE(bcc_symcache_resolve(resolver, (unsigned long long)map_addr,
child = spawn_child(map_addr, /* own_pidns */ true, false, perf_map_func);
REQUIRE(child > 0);
- void *resolver = bcc_symcache_new(child);
+ void *resolver = bcc_symcache_new(child, nullptr);
REQUIRE(resolver);
REQUIRE(bcc_symcache_resolve(resolver, (unsigned long long)map_addr,
perf_map_func_mntns);
REQUIRE(child > 0);
- void *resolver = bcc_symcache_new(child);
+ void *resolver = bcc_symcache_new(child, nullptr);
REQUIRE(resolver);
REQUIRE(bcc_symcache_resolve(resolver, (unsigned long long)map_addr,
string path = perf_map_path(child);
REQUIRE(make_perf_map_file(path, (unsigned long long)map_addr) == 0);
- void *resolver = bcc_symcache_new(child);
+ void *resolver = bcc_symcache_new(child, nullptr);
REQUIRE(resolver);
REQUIRE(bcc_symcache_resolve(resolver, (unsigned long long)map_addr,