]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
DRAFT libdwfl: add dwfl_process_tracker_find_pid
authorSerhei Makarov <serhei@serhei.io>
Fri, 14 Feb 2025 15:02:49 +0000 (10:02 -0500)
committerSerhei Makarov <serhei@serhei.io>
Fri, 14 Feb 2025 18:22:45 +0000 (13:22 -0500)
* 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.

libdw/libdw.map
libdwfl/dwfl_process_tracker.c
libdwfl/libdwfl.h

index 5f43248ad96d68bd2b242af04e9131fc0b9e9927..ce990a09e989091b7a3641f8299606b26b7bd76d 100644 (file)
@@ -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;
index f1d1feb5c31333bc5e13015c459a064002719aab..89fd2b36ad3a5e51d9b03d749f1347d9e1746bc6 100644 (file)
@@ -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);
index c27da8876a71bab724a2ed05fab4f979d8b37806..16b351cf7e8e7344b93f24c5a8f00b51ff7cb4cf 100644 (file)
@@ -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);