Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/cc/api/BPF.cc
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,35 @@ StatusTuple BPF::detach_uprobe(const std::string& binary_path,
return StatusTuple::OK();
}

// Detach all uprobes associated with the given binary path.
// This function cleans up all matching uprobes without checking if the binary file exists.
// It simply matches the sanitized binary path in the event names and detaches them.

StatusTuple BPF::detach_all_uprobes_for_binary(const std::string& binary_path) {
bool has_error = false;
std::string error_msg;
std::vector<std::string> to_detach;

// Sanitize the binary path as used in event names
std::string sanitized_path = sanitize_str(binary_path, &BPF::uprobe_path_validator);
// Find all uprobes for this binary
for (auto& it : uprobes_) {
if (it.first.find(sanitized_path) != std::string::npos) {
auto res = detach_uprobe_event(it.first, it.second);
if (!res.ok()) {
error_msg += "Failed to detach uprobe event " + it.first + ": ";
error_msg += res.msg() + "\n";
has_error = true;
}
uprobes_.erase(it.first);
}
}
if (has_error)
return StatusTuple(-1, error_msg);
else
return StatusTuple::OK();
}

StatusTuple BPF::detach_usdt_without_validation(const USDT& u, pid_t pid) {
auto& probe = *static_cast<::USDT::Probe*>(u.probe_.get());
bool failed = false;
Expand Down
1 change: 1 addition & 0 deletions src/cc/api/BPF.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class BPF {
bpf_probe_attach_type attach_type = BPF_PROBE_ENTRY,
pid_t pid = -1,
uint64_t symbol_offset = 0);
StatusTuple detach_all_uprobes_for_binary(const std::string& binary_path);
StatusTuple attach_usdt(const USDT& usdt, pid_t pid = -1);
StatusTuple attach_usdt_all();
StatusTuple detach_usdt(const USDT& usdt, pid_t pid = -1);
Expand Down
Loading