From: Serhei Makarov Date: Fri, 14 Feb 2025 15:02:49 +0000 (-0500) Subject: DRAFT libdwfl: add dwfl_process_tracker_find_pid X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=55fe0effdc061a6a1ab75f3c8afbc800e2d7474c;p=thirdparty%2Felfutils.git DRAFT libdwfl: add dwfl_process_tracker_find_pid * libdwfl/libdwfl.h (dwfl_process_tracker_find_pid): New function. * libdwfl/dwfl_process_tracker.h (dwfl_process_tracker_find_pid): New function; find a Dwfl in the dwfltab or create one using the provided callback. * libdw/libdw.map: Add dwfl_process_tracker_find_pid. --- diff --git a/libdw/libdw.map b/libdw/libdw.map index 5f43248a..ce990a09 100644 --- a/libdw/libdw.map +++ b/libdw/libdw.map @@ -392,4 +392,5 @@ ELFUTILS_0.193 { dwfl_begin_with_tracker; dwfl_process_tracker_end; dwfl_process_tracker_find_elf; + dwfl_process_tracker_find_pid; } ELFUTILS_0.192; diff --git a/libdwfl/dwfl_process_tracker.c b/libdwfl/dwfl_process_tracker.c index f1d1feb5..89fd2b36 100644 --- a/libdwfl/dwfl_process_tracker.c +++ b/libdwfl/dwfl_process_tracker.c @@ -65,6 +65,27 @@ Dwfl *dwfl_begin_with_tracker (Dwfl_Process_Tracker *tracker) return dwfl; } +Dwfl *dwfl_process_tracker_find_pid (Dwfl_Process_Tracker *tracker, + pid_t pid, + Dwfl *(*callback) (Dwfl_Process_Tracker *, + pid_t, void *), + void *arg) +{ + Dwfl *dwfl = NULL; + dwfltracker_dwfl_info *ent = dwfltracker_dwfltab_find(&tracker->dwfltab, pid); + if (ent != NULL && !ent->invalid) + dwfl = ent->dwfl; + if (dwfl == NULL && callback != NULL) + dwfl = callback(tracker, pid, arg); + if (dwfl != NULL) + { + assert (dwfl->tracker == tracker); + /* XXX: dwfl added to dwfltab when dwfl->process set in dwfl_attach_state. */ + } + + return dwfl; +} + void __libdwfl_add_dwfl_to_tracker (Dwfl *dwfl) { Dwfl_Process_Tracker *tracker = dwfl->tracker; assert (tracker != NULL); diff --git a/libdwfl/libdwfl.h b/libdwfl/libdwfl.h index c27da887..16b351cf 100644 --- a/libdwfl/libdwfl.h +++ b/libdwfl/libdwfl.h @@ -133,6 +133,17 @@ extern Dwfl_Process_Tracker *dwfl_process_tracker_begin (const Dwfl_Callbacks *c extern Dwfl *dwfl_begin_with_tracker (Dwfl_Process_Tracker *tracker) __nonnull_attribute__ (1); +/* Find the Dwfl corresponding to PID. If CALLBACK is non-NULL + and the Dwfl has not been created, invoke CALLBACK to create + the Dwfl and then store it in the tracker. */ +extern Dwfl *dwfl_process_tracker_find_pid (Dwfl_Process_Tracker *tracker, + pid_t pid, + Dwfl *(*callback) (Dwfl_Process_Tracker *tracker, + pid_t pid, + void *arg), + void *arg) + __nonnull_attribute__ (1); + /* End a multi-process session. */ extern void dwfl_process_tracker_end (Dwfl_Process_Tracker *tracker);