From a0ed165cf25a5f3cdbb07175821b3eee4d4c274a Mon Sep 17 00:00:00 2001 From: Namhyung Kim Date: Fri, 29 Nov 2024 13:34:37 -0800 Subject: [PATCH] session: Introduce session_find_filter() It first searches the main filter tree and check dlopen libraries. Signed-off-by: Namhyung Kim --- uftrace.h | 2 ++ utils/fstack.c | 2 +- utils/session.c | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/uftrace.h b/uftrace.h index 6d3c7d197..952bf68c0 100644 --- a/uftrace.h +++ b/uftrace.h @@ -490,6 +490,8 @@ void session_add_dlopen(struct uftrace_session *sess, uint64_t timestamp, unsign const char *libname, bool needs_srcline); struct uftrace_symbol *session_find_dlsym(struct uftrace_session *sess, uint64_t timestamp, unsigned long addr); +struct uftrace_filter *session_find_filter(struct uftrace_session *sess, struct uftrace_record *rec, + struct uftrace_trigger *tr); void delete_sessions(struct uftrace_session_link *sess); struct uftrace_record; diff --git a/utils/fstack.c b/utils/fstack.c index 5250a1cae..df8669bb8 100644 --- a/utils/fstack.c +++ b/utils/fstack.c @@ -1375,7 +1375,7 @@ int read_task_args(struct uftrace_task_reader *task, struct uftrace_record *rsta return -1; } - fl = uftrace_match_filter(rstack->addr, &sess->filters, &tr); + fl = session_find_filter(sess, rstack, &tr); if (fl == NULL) { pr_dbg("cannot find filter: %lx\n", rstack->addr); return -1; diff --git a/utils/session.c b/utils/session.c index 2a83cd0f5..943d42d4b 100644 --- a/utils/session.c +++ b/utils/session.c @@ -400,6 +400,27 @@ struct uftrace_symbol *session_find_dlsym(struct uftrace_session *sess, uint64_t return NULL; } +static struct uftrace_dlopen_list *session_find_dlopen(struct uftrace_session *sess, + uint64_t timestamp, unsigned long addr) +{ + struct uftrace_dlopen_list *pos; + struct uftrace_symbol *sym; + + list_for_each_entry_reverse(pos, &sess->dlopen_libs, list) { + if (pos->time > timestamp) + continue; + + if (pos->mod == NULL) + continue; + + sym = find_sym(&pos->mod->symtab, addr - pos->base); + if (sym) + return pos; + } + + return NULL; +} + void delete_session(struct uftrace_session *sess) { struct uftrace_dlopen_list *udl, *tmp; @@ -789,6 +810,23 @@ struct uftrace_dbg_loc *task_find_loc_addr(struct uftrace_session_link *sessions return NULL; } +struct uftrace_filter *session_find_filter(struct uftrace_session *sess, struct uftrace_record *rec, + struct uftrace_trigger *tr) +{ + struct uftrace_filter *ret; + struct uftrace_dlopen_list *dl; + + ret = uftrace_match_filter(rec->addr, &sess->filters, tr); + if (ret) + return ret; + + dl = session_find_dlopen(sess, rec->time, rec->addr); + if (dl == NULL) + return NULL; + + return uftrace_match_filter(rec->addr, &dl->filters, tr); +} + #ifdef UNIT_TEST static struct uftrace_session_link test_sessions;