[PATCH 01/13] libebl [1/13]: api for perf register handling, start with x86_64

2025-03-16 Thread Serhei Makarov
First patch of a series that reworks eu-stacktrace functionality into a library interface for other profiling tools. * * * As it happens, Linux perf_events and DWARF can prescribe completely different layouts for the register file, requiring non-obvious code for translation. This makes sense to p

[PATCH 02/13] libdwfl [2/13]: expose setfunc callback for libdwfl+libebl clients

2025-03-16 Thread Serhei Makarov
Renaming to dwfl_set_initial_registers_thread. This callback was private to one file, but now that other tools (eu-stacktrace, sysprof via the dwfl_perf_sample_getframes) are invoking the ebl set_initial_registers_sample api, we need to expose it. Otherwise, clients would need to reimplement this

[PATCH 07/13] eu-stacktrace [7/13]: use Dwfl_Process_Tracker for Elf * caching

2025-03-16 Thread Serhei Makarov
* src/stacktrace.c (tracker): New global variable. (sample_callbacks): Use dwfl_process_tracker_find_elf for caching. (sysprof_init_dwfl): Use dwfl_begin_with_tracker. (main): Initialize and clean up tracker. --- src/stacktrace.c | 11 --- 1 file changed, 8 insertions(+), 3 deletions

[PATCH 04/13] libdwfl [4/13]: add dwfl_perf_sample_preferred_regs_mask

2025-03-16 Thread Serhei Makarov
Since libebl is a private interface, subsequent patches in the series introduce another api wrapping the libebl perf register handling. In this patch, add an interface to access the preferred set of registers that libdwfl would like to see to allow proper unwinding of stack sample data. * libdwfl

[PATCH 08/13] libdwfl [8/13]: Dwfl* caching via dwfl_process_tracker

2025-03-16 Thread Serhei Makarov
The Dwfl_Process_Tracker also includes a dynamicsizehash cache which maps process ids to Dwfl * (or rather, dwfltracker_dwfl_info * allowing the table entry to be replaced). Dwfls created from the tracker are automatically added to it, and removed on dwfl_end(). * libdwfl/libdwflP.h (dwfltracker_

[PATCH 09/13] libdwfl [9/13]: add dwfl_process_tracker_find_pid

2025-03-16 Thread Serhei Makarov
New function that retrieves the Dwfl for a particular PID, or, if the Dwfl is absent, creates it via a provided callback and adds it to the table later, when the PID is confirmed via dwfl_attach_state. * libdwfl/libdwfl.h (dwfl_process_tracker_find_pid): New function. * libdwfl/dwfl_process_tracke

[PATCH 13/13] eu-stacktrace [13/13]: use dwfl_perf_sample_getframes

2025-03-16 Thread Serhei Makarov
Remove the code from src/stacktrace.c that is now covered by libdwfl/dwfl_perf_frame.c and dwfl_perf_sample_getframes. * src/stacktrace.c (show_memory_reads): Remove this verbose option as the relevant code is inside libdwfl now. (struct __sample_arg): Remove, handled by libdwfl/dwfl_perf_fram

[PATCH 12/13] libdwfl [12/13]: add dwfl_perf_sample_getframes

2025-03-16 Thread Serhei Makarov
This is a new interface for unwinding that doesn't require the Dwfl to be attached to a live process (via ptrace) or via corefile. Instead, data from a perf_events stack sample is provided along with an Elf struct used to identify the architecture. Based on code from eu-stacktrace. * libdwfl/libdw

[PATCH 11/13] libebl [11/13]: provide access to register file pc, sp

2025-03-16 Thread Serhei Makarov
These additional libebl hooks are needed to extract the location of the stack frame in-memory from the perf_events register sample, when dwfl_perf_sample_getframes is implemented in the next patch. Implementing x86_64 for now, just as with the earlier ebl patches. * libebl/libebl.h (ebl_sample_ba

[PATCH 10/13] eu-stacktrace [10/13]: use dwfl_process_tracker_find_pid

2025-03-16 Thread Serhei Makarov
Initial minimal change to ensure dwfl_process_tracker_find_pid is tested. For now, we keep the additional dwfltab code in stacktrace.c, since it's used to track statistics. In future follow-ups, it will be good to switch to storing eu-stacktrace statistics in dwfl->process->callbacks_arg. This req

[PATCH 03/13] libebl [3/13]: eu-stacktrace: use new register handling api

2025-03-16 Thread Serhei Makarov
Change the sample_set_initial_registers callback in eu-stacktrace to use the proper libebl ebl_set_initial_registers_sample function. * src/Makefile.am (stacktrace_LDADD): Add libebl. * src/stacktrace.c (sample_registers_cb): New function, though identical to pid_thread_state_registers_cb. (sa

[PATCH 05/13] libdwfl [5/13]: introduce Dwfl_Process_Tracker

2025-03-16 Thread Serhei Makarov
New data structure to coordinate caching Elf data among multiple Dwfl structs attached to different processes. Meant to reduce the overhead for profilers that use elfutils for unwinding. The caching is well-justified, as the prior approach (e.g. in eu-stacktrace, sysprof-live-unwinder) of creating

[PATCH 2/9 v4] libdw: Add locking to dwarf_getsrcfiles, dwarf_getsrclines, dwarf_macro_getsrcfiles

2025-03-16 Thread Aaron Merey
* libdw/dwarf_begin_elf.c (dwarf_begin_elf): Init macro_lock. * libdw/dwarf_end.c (cu_free): Free src_lock. (dwarf_end): Free macro_lock. * libdw/dwarf_getsrcfiles.c (dwarf_getsrcfiles): Use src_lock. * libdw/dwarf_getsrclines.c (dwarf_getsrclines): Ditto.

[PATCH 06/13] libdwfl [6/13]: Elf* caching via dwfl_process_tracker

2025-03-16 Thread Serhei Makarov
The Dwfl_Process_Tracker includes a dynamicsizehash cache which maps file paths to Elf * (or rather, dwfl_tracker_elf_info * storing fd and Elf *). We provide a dwfl_process_tracker_find_elf callback which checks the cache for an already-loaded Elf * and, if missing, populates the cache with the f