[PATCH v2 1/5] unwind-libdw: add -kk/--stack-traces=source option
Dmitry V. Levin
ldv at strace.io
Wed Nov 22 07:51:45 UTC 2023
On Sun, Nov 19, 2023 at 02:30:21PM +0900, Masatake YAMATO wrote:
> This change adds source code information to stack traces printed with
> -k option if strace links to libdw.
>
> An example output:
>
> exit_group(0) = ?
> +++ exited with 0 +++
> > /usr/lib64/libc.so.6(_exit+0x1d) [0xdb44d] ../sysdeps/unix/sysv/linux/_exit.c:30
> > /usr/lib64/libc.so.6(__run_exit_handlers+0x125) [0x40165] /usr/src/debug/glibc-2.37-4.fc38.x86_64/stdlib/exit.c:134
> > /usr/lib64/libc.so.6(exit+0x1d) [0x402ed] /usr/src/debug/glibc-2.37-4.fc38.x86_64/stdlib/exit.c:141
> > /usr/lib64/libc.so.6(__libc_start_call_main+0x80) [0x27b50] ../sysdeps/nptl/libc_start_call_main.h:74
> > /usr/lib64/libc.so.6(__libc_start_main@@GLIBC_2.34+0x8a) [0x27c0a] ../csu/libc-start.c:360
> > /usr/bin/ls(_start+0x24) [0x6d54]
>
> This change also adds --stack-traces=symbol option as an alias for the
> original -k/--stack-traces options.
>
> NOTE: If the target program is built with clang, -gdwarf-aranges option
> must be specified in addition to -g for making -kk option work.
> See https://sourceware.org/bugzilla/show_bug.cgi?id=30948 ahout this
> limitation.
>
> * NEWS: Mention this.
> * doc/strace.1.in: Document this.
> * src/defs.h (stack_trace_modes): New enum.
> (stack_trace_modes::STACK_TRACE_OFF,STACK_TRACE_ON,
> STACK_TRACE_WITH_SRCINFO): New enumerators.
> (stack_trace_enabled): Rename this variabel declaration to...
> (stack_trace_mode): ... this. The type is also changed from bool to
> enum stack_trace_modes.
> (unwind_init): Add a bool parameter.
> * src/filter_seccomp.c (traced_by_seccomp): Use the new variable name,
> stack_trace_mode.
> * src/strace.c (stack_trace_enabled): Rename this variabel to...
> (stack_trace_mode): ... this.
> [ENABLE_STACKTRACE]/[USE_LIBDW] (K_OPT): Add "kk" option.
> [ENABLE_STACKTRACE] (usage): Print --stack-traces=symbol options.
> [ENABLE_STACKTRACE]/[USE_LIBDW] (usage): Print -kk and
> --strack-traces=source options.
> [ENABLE_STACKTRACE] (after_successful_attach): Use the new variable
> name, stack_trace_mode.
> (GETOPT_STACK): New enumerator.
> (init::longopts): Let --stack-traces take an option argument. Use
> GETOPT_STACK as the val for --stack-traces.
> [ENABLE_STACKTRACE] (init): Handle -kk and --stack-traces=source
> options.
> (init): Pass ture to unwind_init() if -kk or --stack-traces=source is
> given.
> (print_stopped): Use the new variable
> name, stack_trace_mode.
> * src/syscall.c (update_personality): Use the new variable
> name, stack_trace_mode.
> (syscall_entering_trace): Ditto.
> (syscall_exiting_trace): Ditto.
> * src/unwind.h (unwind_call_action_fn): add parameters
> source_filename and source_line as parameters.
> (struct unwind_unwinder_t::init): Add a bool parameter.
> * src/unwind.c (unwind_init): Add with_srcinfo parameter and
> pass it to init method of backend.
> (STACK_ENTRY_SYMBOL_WITH_SRCINFO_FMT): New format string for
> printing stack trace entries with source code information.
> (print_call_cb): Add source_filename and source_line as
> parameters. Build stack trace entries with
> STACK_ENTRY_SYMBOL_WITH_SRCINFO_FMT if source_filename is given.
> (queue_put): Add source_filename and source_line as parameters.
> Pass them to sprint_call_or_error().
> (queue_put_call): Do the same as queue_put.
> (queue_put_error): Pass NULL as source_filename, 0 as source_line to
> queue_put().
> * src/unwind-libdw.c (struct cache_entry::source_filename,
> struct cache_entry::source_line): New members.
> (with_srcinfo): New file local variable.
> (init): Set with_srcinfo.
> (frame_callback): Get source information for pc from
> dwfl_module_getsrc() and dwfl_lineinfo(). Pass the source information
> to call_action method and fill the source_filename and source_line members
> of cache entry.
> * src/unwind-libunwind.c (init, print_stack_frame): Adjust the code to
> the updated interface declared in unwind.h.
> * tests/Makefile.am (check_SCRIPTS): add strace-kk.test.
> (check_DATA): strace-kk.expected.
> [ENABLE_STACKTRACE]/[USE_LIBDW] (STACKTRACE_TESTS): add
> strace-kk.test.
> * tests/strace-k.test: Add KOPT_SHORT and KOPT_LONG variables
> to make the test case reusable for testing -kk option. Don't
> hardcode -k and --stack-traces. Add a new pattern for
> testing -kk/--stack-traces=source.
> * tests/strace-kk.expected: New file.
> * tests/strace-kk.test: New test case.
> * tests/options-syntax.test: update expecting output.
>
> Changes in v2:
> * fold too long lines,
> * withdraw the changes of diagnostics about combining -kk and -c,
> * update the error messages in src/strace.c (init::k::STACK_TRACE_ON,
> (init::k::GETOPT_STACK),
> * use "source" as a specifier to enable "stack traces with source
> information" instead of "+source",
> * fix a typo about the short option (s/K/k/) in the man page, add
> * add comments about description about -k/-kk option.
I think it's ready to be merged now. Thanks for the cool feature!
--
ldv
More information about the Strace-devel
mailing list