Commit fcb2ed8e authored by Teng Qin's avatar Teng Qin

Use bcc_symbol_option in bcc_foreach_function_symbol

This commit changes `bcc_foreach_symbol` to use the new `bcc_symbol_option` to
control it only wants function symbols. Also renamed it to
bcc_foreach_function_symbol and added comments for better information.

This commit maintained current behavior of the function to prefer use
debug file and check debug file CRC. We could add option to configure
that behavior in the future if needed.
parent 0336a290
......@@ -31,6 +31,10 @@
#include "syms.h"
#include "vendor/tinyformat.hpp"
#ifndef STT_GNU_IFUNC
#define STT_GNU_IFUNC 10
#endif
ino_t ProcStat::getinode_() {
struct stat s;
return (!stat(procfs_.c_str(), &s)) ? s.st_ino : -1;
......@@ -456,23 +460,24 @@ struct sym_search_t {
int *actual;
};
// see <elf.h>
#define ELF_TYPE_IS_FUNCTION(flags) (((flags) & 0xf) == 2)
static int _list_sym(const char *symname, uint64_t addr, uint64_t end,
int flags, void *payload) {
if (!ELF_TYPE_IS_FUNCTION(flags) || addr == 0)
return 0;
SYM_CB cb = (SYM_CB)payload;
static int _sym_cb_wrapper(const char *symname, uint64_t addr, uint64_t end,
int flags, void *payload) {
SYM_CB cb = (SYM_CB) payload;
return cb(symname, addr);
}
int bcc_foreach_symbol(const char *module, SYM_CB cb) {
int bcc_foreach_function_symbol(const char *module, SYM_CB cb) {
if (module == 0 || cb == 0)
return -1;
return bcc_elf_foreach_sym(module, _list_sym, (void *)cb);
static struct bcc_symbol_option default_option = {
.use_debug_file = 1,
.check_debug_file_crc = 1,
.use_symbol_type = (1 << STT_FUNC) | (1 << STT_GNU_IFUNC)
};
return bcc_elf_foreach_sym(
module, _sym_cb_wrapper, &default_option, (void *)cb);
}
int bcc_resolve_symname(const char *module, const char *symname,
......
......@@ -56,7 +56,12 @@ 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_foreach_symbol(const char *module, SYM_CB cb);
// Call cb on every function symbol in the specified module. Uses simpler
// SYM_CB callback mainly for easier to use in Python API.
// Will prefer use debug file and check debug file CRC when reading the module.
int bcc_foreach_function_symbol(const char *module, SYM_CB cb);
int bcc_find_symbol_addr(struct bcc_symbol *sym);
int bcc_resolve_symname(const char *module, const char *symname,
const uint64_t addr, int pid, struct bcc_symbol *sym);
......
......@@ -773,7 +773,8 @@ class BPF(object):
addresses.append((dname, addr))
return 0
res = lib.bcc_foreach_symbol(name.encode('ascii'), _SYM_CB_TYPE(sym_cb))
res = lib.bcc_foreach_function_symbol(
name.encode('ascii'), _SYM_CB_TYPE(sym_cb))
if res < 0:
raise Exception("Error %d enumerating symbols in %s" % (res, name))
return addresses
......
......@@ -152,8 +152,8 @@ lib.bcc_resolve_symname.argtypes = [
ct.c_char_p, ct.c_char_p, ct.c_ulonglong, ct.c_int, ct.POINTER(bcc_symbol)]
_SYM_CB_TYPE = ct.CFUNCTYPE(ct.c_int, ct.c_char_p, ct.c_ulonglong)
lib.bcc_foreach_symbol.restype = ct.c_int
lib.bcc_foreach_symbol.argtypes = [ct.c_char_p, _SYM_CB_TYPE]
lib.bcc_foreach_function_symbol.restype = ct.c_int
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]
......
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