Skip to content

Commit

Permalink
ProcSyms: deduplicate symbol names (iovisor#598)
Browse files Browse the repository at this point in the history
  • Loading branch information
markdrayton authored and 4ast committed Jul 8, 2016
1 parent 5256154 commit 966edb2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/cc/bcc_syms.cc
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ bool ProcSyms::resolve_name(const char *module, const char *name,
int ProcSyms::Module::_add_symbol(const char *symname, uint64_t start,
uint64_t end, int flags, void *p) {
Module *m = static_cast<Module *>(p);
m->syms_.emplace_back(symname, start, end, flags);
auto res = m->symnames_.emplace(symname);
m->syms_.emplace_back(&*(res.first), start, end, flags);
return 0;
}

Expand Down Expand Up @@ -160,7 +161,7 @@ bool ProcSyms::Module::find_name(const char *symname, uint64_t *addr) {
load_sym_table();

for (Symbol &s : syms_) {
if (s.name == symname) {
if (*(s.name) == symname) {
*addr = is_so() ? start_ + s.start : s.start;
return true;
}
Expand All @@ -176,15 +177,15 @@ bool ProcSyms::Module::find_addr(uint64_t addr, struct bcc_symbol *sym) {
sym->module = name_.c_str();
sym->offset = offset;

auto it = std::upper_bound(syms_.begin(), syms_.end(), Symbol("", offset, 0));
auto it = std::upper_bound(syms_.begin(), syms_.end(), Symbol(nullptr, offset, 0));
if (it != syms_.begin())
--it;
else
it = syms_.end();

if (it != syms_.end()
&& offset >= it->start && offset < it->start + it->size) {
sym->name = it->name.c_str();
sym->name = it->name->c_str();
sym->offset = (offset - it->start);
return true;
}
Expand Down
6 changes: 4 additions & 2 deletions src/cc/syms.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <algorithm>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <sys/types.h>
Expand Down Expand Up @@ -63,9 +64,9 @@ class KSyms : SymbolCache {

class ProcSyms : SymbolCache {
struct Symbol {
Symbol(const char *name, uint64_t start, uint64_t size, int flags = 0)
Symbol(const std::string *name, uint64_t start, uint64_t size, int flags = 0)
: name(name), start(start), size(size), flags(flags) {}
std::string name;
const std::string *name;
uint64_t start;
uint64_t size;
int flags;
Expand All @@ -81,6 +82,7 @@ class ProcSyms : SymbolCache {
std::string name_;
uint64_t start_;
uint64_t end_;
std::unordered_set<std::string> symnames_;
std::vector<Symbol> syms_;

void load_sym_table();
Expand Down

0 comments on commit 966edb2

Please sign in to comment.