]> git.ipfire.org Git - thirdparty/elfutils.git/commit
libdwfl_stacktrace [11/12]: add dwflst_perf_sample_getframes
authorSerhei Makarov <serhei@serhei.io>
Wed, 23 Apr 2025 00:19:39 +0000 (20:19 -0400)
committerSerhei Makarov <serhei@serhei.io>
Fri, 25 Apr 2025 14:15:37 +0000 (10:15 -0400)
commitd6223eb9ad12a3e6f48426a1e5c377aff011306f
tree64dd8aba1434a60fcd9699e995afc9854d282b71
parent7738d9ef305033fd1078d952bba9370915830f79
libdwfl_stacktrace [11/12]: add dwflst_perf_sample_getframes

Changes for v6:

- Minor fixes as requested.

Changes for v4:

- Separate out libdwfl_stacktrace, as requested.

Changes for v3:

- use const void *stack, not void *, to allow users
  to pass a const stack sample

Changes for v2:

- use renamed __libdwfl_set_initial_registers_thread

- oops, should use provided sample_arg->perf_regs_mask
  in sample_set_initial registers

* * *

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_stacktrace/libdwfl_stacktrace.h (dwflst_perf_sample_getframes):
  New function.
* libdwfl_stacktrace/dwflst_perf_frame.c
  (struct __libdwfl_stacktrace_perf_sample_info): New struct, based on
  src/stacktrace.c struct sample_arg.
  (sample_next_thread): New function, based on src/stacktrace.c.
  (sample_getthread): Ditto.
  (copy_word_64): New macro, based on src/stacktrace.c.
  (copy_word_32): Ditto.
  (copy_word): Ditto.
  (elf_memory_read): New function, based on src/stacktrace.c.
  (sample_memory_read): Ditto.
  (sample_set_initial_registers): Ditto.
  (sample_detach): Ditto.
  (sample_thread_callbacks): New struct, set of callbacks based on
  src/stacktrace.c sample_thread_callbacks.
  (dwflst_perf_sample_getframes): New function, based on parts of
  src/stacktrace.c sysprof_find_dwfl. If the Dwfl is not attached,
  attaches it with sample_thread_callbacks and
  __libdwfl_stacktrace_perf_sample_info. Populates the
  __libdwfl_stacktrace_perf_sample_info with data from the stack
  sample and calls dwfl_getthread_frames to unwind it using the
  sample_thread_callbacks.
* libdw/libdw.map (ELFUTILS_0.193): Add dwflst_perf_sample_getframes.
libdw/libdw.map
libdwfl_stacktrace/dwflst_perf_frame.c
libdwfl_stacktrace/libdwfl_stacktrace.h