diff --git a/daemon/user/bpftime_driver.cpp b/daemon/user/bpftime_driver.cpp index 568e129c..6e407529 100644 --- a/daemon/user/bpftime_driver.cpp +++ b/daemon/user/bpftime_driver.cpp @@ -297,8 +297,9 @@ int bpftime_driver::bpftime_perf_event_enable_server(int server_pid, int fd) { int fd_id = check_and_get_pid_fd(server_pid, fd); if (fd_id < 0) { - spdlog::error("fd {} for pid {} not exists", fd, server_pid); - return -1; + spdlog::warn("Unrecorded uprobe fd: {} for pid {}", fd, + server_pid); + return 0; } int res = bpftime_perf_event_enable(fd_id); if (res < 0) { diff --git a/daemon/user/handle_bpf_event.cpp b/daemon/user/handle_bpf_event.cpp index e2354249..3e9e7be3 100644 --- a/daemon/user/handle_bpf_event.cpp +++ b/daemon/user/handle_bpf_event.cpp @@ -244,7 +244,7 @@ static const char *perf_type_id_strings[PERF_TYPE_MAX_ID] = { "PERF_TYPE_HW_CACHE", "PERF_TYPE_RAW", "PERF_TYPE_BREAKPOINT", }; -int bpf_event_handler::handle_perf_event(const struct event *e) +int bpf_event_handler::handle_perf_event_open(const struct event *e) { spdlog::debug("handle_perf_event"); const char *type_id_str = "UNKNOWN TYPE"; @@ -257,24 +257,43 @@ int bpf_event_handler::handle_perf_event(const struct event *e) /* print output */ spdlog::info("PERF {:<6} {:<16} type:{:<16} ret:{}\n", e->pid, e->comm, type_id_str, e->perf_event_data.ret); - if (config.is_driving_bpftime && e->perf_event_data.ret > 0) { - if (perf_type == (unsigned int)uprobe_type) { - auto attr = &e->perf_event_data.attr; - // NO legacy bpf types - bool retprobe = attr->config & + + if (config.is_driving_bpftime) { + if (e->perf_event_data.ret >= 0) { + spdlog::debug( + "Handling perf event creating with perf type {}", + perf_type); + if (perf_type == (unsigned int)uprobe_type) { + auto attr = &e->perf_event_data.attr; + // NO legacy bpf types + bool retprobe = + attr->config & (1 << determine_uprobe_retprobe_bit()); - spdlog::debug("retprobe {}", retprobe); - size_t ref_ctr_off = attr->config >> - PERF_UPROBE_REF_CTR_OFFSET_SHIFT; - const char *name = e->perf_event_data.name_or_path; - uint64_t offset = e->perf_event_data.attr.probe_offset; - spdlog::debug("Creating uprobe name {} offset {} " - "ref_ctr_off {} attr->config={:x}", - name, offset, ref_ctr_off, attr->config); - driver.bpftime_uprobe_create_server( - e->pid, e->perf_event_data.ret, - e->perf_event_data.pid, name, offset, retprobe, - ref_ctr_off); + spdlog::debug("retprobe {}", retprobe); + size_t ref_ctr_off = + attr->config >> + PERF_UPROBE_REF_CTR_OFFSET_SHIFT; + const char *name = + e->perf_event_data.name_or_path; + uint64_t offset = + e->perf_event_data.attr.probe_offset; + spdlog::debug( + "Creating uprobe name {} offset {} " + "ref_ctr_off {} attr->config={:x}", + name, offset, ref_ctr_off, + attr->config); + driver.bpftime_uprobe_create_server( + e->pid, e->perf_event_data.ret, + e->perf_event_data.pid, name, offset, + retprobe, ref_ctr_off); + } else { + spdlog::warn("Unsupported perf event type: {}", + perf_type); + } + } else { + spdlog::debug( + "Ignore failed perf event creation, err={}", + e->perf_event_data.ret); } } return 0; @@ -346,7 +365,7 @@ int bpf_event_handler::handle_event(const struct event *e) return handle_open_events(e); break; case SYS_PERF_EVENT_OPEN: - return handle_perf_event(e); + return handle_perf_event_open(e); break; case SYS_BPF: return handle_bpf_event(e); diff --git a/daemon/user/handle_bpf_event.hpp b/daemon/user/handle_bpf_event.hpp index b3bea89d..cc67e6b5 100644 --- a/daemon/user/handle_bpf_event.hpp +++ b/daemon/user/handle_bpf_event.hpp @@ -20,7 +20,7 @@ class bpf_event_handler { int handle_close_event(const struct event *e); int handle_bpf_event(const struct event *e); int handle_open_events(const struct event *e); - int handle_perf_event(const struct event *e); + int handle_perf_event_open(const struct event *e); int handle_load_bpf_prog_event(const struct event *e); int handle_ioctl(const struct event *e); public: