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,
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;
}
......@@ -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;
}
......@@ -176,7 +177,7 @@ 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
......@@ -184,7 +185,7 @@ bool ProcSyms::Module::find_addr(uint64_t addr, struct bcc_symbol *sym) {
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;
}
......
......@@ -18,6 +18,7 @@
#include <algorithm>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <sys/types.h>
......@@ -63,9 +64,9 @@ public:
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;
......@@ -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();
......
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