Commit a037df7d authored by Alastair Robertson's avatar Alastair Robertson

Fix bug when attaching probes to functions with long names

parent cd898c90
...@@ -63,11 +63,11 @@ AttachedProbe::~AttachedProbe() ...@@ -63,11 +63,11 @@ AttachedProbe::~AttachedProbe()
{ {
case ProbeType::kprobe: case ProbeType::kprobe:
case ProbeType::kretprobe: case ProbeType::kretprobe:
err = bpf_detach_kprobe(eventname()); err = bpf_detach_kprobe(eventname().c_str());
break; break;
case ProbeType::uprobe: case ProbeType::uprobe:
case ProbeType::uretprobe: case ProbeType::uretprobe:
err = bpf_detach_uprobe(eventname()); err = bpf_detach_uprobe(eventname().c_str());
break; break;
default: default:
abort(); abort();
...@@ -89,25 +89,21 @@ std::string AttachedProbe::eventprefix() const ...@@ -89,25 +89,21 @@ std::string AttachedProbe::eventprefix() const
} }
} }
const char *AttachedProbe::eventname() const std::string AttachedProbe::eventname() const
{ {
std::string event;
std::ostringstream offset_str; std::ostringstream offset_str;
switch (probe_.type) switch (probe_.type)
{ {
case ProbeType::kprobe: case ProbeType::kprobe:
case ProbeType::kretprobe: case ProbeType::kretprobe:
event = eventprefix() + probe_.attach_point; return eventprefix() + probe_.attach_point;
break;
case ProbeType::uprobe: case ProbeType::uprobe:
case ProbeType::uretprobe: case ProbeType::uretprobe:
offset_str << std::hex << offset(); offset_str << std::hex << offset();
event = eventprefix() + probe_.path + "_" + offset_str.str(); return eventprefix() + probe_.path + "_" + offset_str.str();
break;
default: default:
abort(); abort();
} }
return event.c_str();
} }
uint64_t AttachedProbe::offset() const uint64_t AttachedProbe::offset() const
...@@ -157,7 +153,7 @@ void AttachedProbe::attach_kprobe() ...@@ -157,7 +153,7 @@ void AttachedProbe::attach_kprobe()
void *cb_cookie = nullptr; void *cb_cookie = nullptr;
perf_reader_ = bpf_attach_kprobe(progfd_, attachtype(probe_.type), perf_reader_ = bpf_attach_kprobe(progfd_, attachtype(probe_.type),
eventname(), probe_.attach_point.c_str(), eventname().c_str(), probe_.attach_point.c_str(),
pid, cpu, group_fd, cb, cb_cookie); pid, cpu, group_fd, cb, cb_cookie);
if (perf_reader_ == nullptr) if (perf_reader_ == nullptr)
...@@ -173,7 +169,7 @@ void AttachedProbe::attach_uprobe() ...@@ -173,7 +169,7 @@ void AttachedProbe::attach_uprobe()
void *cb_cookie = nullptr; void *cb_cookie = nullptr;
perf_reader_ = bpf_attach_uprobe(progfd_, attachtype(probe_.type), perf_reader_ = bpf_attach_uprobe(progfd_, attachtype(probe_.type),
eventname(), probe_.path.c_str(), offset(), eventname().c_str(), probe_.path.c_str(), offset(),
pid, cpu, group_fd, cb, cb_cookie); pid, cpu, group_fd, cb, cb_cookie);
if (perf_reader_ == nullptr) if (perf_reader_ == nullptr)
......
...@@ -19,7 +19,7 @@ public: ...@@ -19,7 +19,7 @@ public:
private: private:
std::string eventprefix() const; std::string eventprefix() const;
const char *eventname() const; std::string eventname() const;
uint64_t offset() const; uint64_t offset() const;
void load_prog(); void load_prog();
void attach_kprobe(); void attach_kprobe();
......
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