Commit 966edb21 authored by Mark Drayton's avatar Mark Drayton Committed by 4ast

ProcSyms: deduplicate symbol names (#598)

parent 52561540
...@@ -132,7 +132,8 @@ bool ProcSyms::resolve_name(const char *module, const char *name, ...@@ -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, int ProcSyms::Module::_add_symbol(const char *symname, uint64_t start,
uint64_t end, int flags, void *p) { uint64_t end, int flags, void *p) {
Module *m = static_cast<Module *>(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; return 0;
} }
...@@ -160,7 +161,7 @@ bool ProcSyms::Module::find_name(const char *symname, uint64_t *addr) { ...@@ -160,7 +161,7 @@ bool ProcSyms::Module::find_name(const char *symname, uint64_t *addr) {
load_sym_table(); load_sym_table();
for (Symbol &s : syms_) { for (Symbol &s : syms_) {
if (s.name == symname) { if (*(s.name) == symname) {
*addr = is_so() ? start_ + s.start : s.start; *addr = is_so() ? start_ + s.start : s.start;
return true; return true;
} }
...@@ -176,7 +177,7 @@ bool ProcSyms::Module::find_addr(uint64_t addr, struct bcc_symbol *sym) { ...@@ -176,7 +177,7 @@ bool ProcSyms::Module::find_addr(uint64_t addr, struct bcc_symbol *sym) {
sym->module = name_.c_str(); sym->module = name_.c_str();
sym->offset = offset; 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()) if (it != syms_.begin())
--it; --it;
else else
...@@ -184,7 +185,7 @@ bool ProcSyms::Module::find_addr(uint64_t addr, struct bcc_symbol *sym) { ...@@ -184,7 +185,7 @@ bool ProcSyms::Module::find_addr(uint64_t addr, struct bcc_symbol *sym) {
if (it != syms_.end() if (it != syms_.end()
&& offset >= it->start && offset < it->start + it->size) { && 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); sym->offset = (offset - it->start);
return true; return true;
} }
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <algorithm> #include <algorithm>
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#include <unordered_set>
#include <vector> #include <vector>
#include <sys/types.h> #include <sys/types.h>
...@@ -63,9 +64,9 @@ public: ...@@ -63,9 +64,9 @@ public:
class ProcSyms : SymbolCache { class ProcSyms : SymbolCache {
struct Symbol { 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) {} : name(name), start(start), size(size), flags(flags) {}
std::string name; const std::string *name;
uint64_t start; uint64_t start;
uint64_t size; uint64_t size;
int flags; int flags;
...@@ -81,6 +82,7 @@ class ProcSyms : SymbolCache { ...@@ -81,6 +82,7 @@ class ProcSyms : SymbolCache {
std::string name_; std::string name_;
uint64_t start_; uint64_t start_;
uint64_t end_; uint64_t end_;
std::unordered_set<std::string> symnames_;
std::vector<Symbol> syms_; std::vector<Symbol> syms_;
void load_sym_table(); void load_sym_table();
......
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