Feature #17638


Support backtracing with the libbacktrace library

Added by xtkoba (Tee KOBAYASHI) almost 2 years ago. Updated over 1 year ago.

Target version:


It seems that Ruby's current addr2line.c has trouble with the DWARF 5 debugging format (Bug #17585).

I propose that there be an option to use the libbacktrace library instead of addr2line.c.

A patch is attached for that. When using libbacktrace, the C level backtrace information looks as follows:

-- C level backtrace information -------------------------------------------
0x7f0cc2b3b372 rb_vm_bugreport
0x7f0cc291e188 rb_bug_for_fatal_signal
0x7f0cc2a8a137 sigsegv
0x7f0cc281a9bf ???
0x7f0cc247ddf7 ???
0x7f0cc2a8990d rb_f_kill
0x7f0cc2a2e684 proc_rb_f_kill
0x7f0cc2b0f2a4 ractor_safe_call_cfunc_m1
0x7f0cc2b0fecb vm_call_cfunc_with_frame
0x7f0cc2b10088 vm_call_cfunc
0x7f0cc2b11b3b vm_call_method_each_type
0x7f0cc2b11fde vm_call_method
0x7f0cc2b121ca vm_call_general
0x7f0cc2b144e7 vm_sendish
0x7f0cc2b1b196 vm_exec_core
0x7f0cc2b308f5 rb_vm_exec
0x7f0cc2b316e8 rb_iseq_eval_main
0x7f0cc292778d rb_ec_exec_node
0x7f0cc29278d3 ruby_run_node
0x55ad53234234 main
0x7f0cc2468e59 ???
0x55ad532340f9 ???
0xffffffffffffffff ???

The source code of libbacktrace is available from:


ruby-libbacktrace.patch (1.72 KB) ruby-libbacktrace.patch xtkoba (Tee KOBAYASHI), 02/17/2021 12:51 PM
ruby-libbacktrace-using-backtrace.patch (2.05 KB) ruby-libbacktrace-using-backtrace.patch xtkoba (Tee KOBAYASHI), 02/27/2021 10:44 PM
ruby-cygwin-backtrace.patch (1.24 KB) ruby-cygwin-backtrace.patch xtkoba (Tee KOBAYASHI), 02/27/2021 10:48 PM

Updated by xtkoba (Tee KOBAYASHI) almost 2 years ago

The patch attached here presents an alternative way of using libbacktrace, in which the return addresses are retrieved by backtrace(3) and passed to the libbacktrace functions backtrace_syminfo and backtrace_pcinfo. This patch has to be applied after the main patch.

Updated by xtkoba (Tee KOBAYASHI) almost 2 years ago

The patch attached here is to be applied after the main patch and the patch in #note-1, and is for an experiment of backtracing on Cygwin. To make it work correctly, the use of sigaltstack(2) has to be disabled, and thus this is not for a practical use.

A sample output (with input borrowed from #17661):

-- C level backtrace information -------------------------------------------
[0x100571ebb] rb_print_backtrace+0x4d
[0x100571ff7] rb_vm_bugreport+0xdf
[0x100451317] rb_bug_for_fatal_signal+0x83
[0x100514e6c] sigsegv+0x32
[0x180065994] register_frame_ctor+0x7fae38a4
[0x180149b47] register_frame_ctor+0x7fbc7a57
[0x1800639aa] register_frame_ctor+0x7fae18ba
[0x7ffe8a769aec] register_frame_ctor+0x7ffd8a1e79fc
[0x7ffe8a6f4fe8] register_frame_ctor+0x7ffd8a172ef8
[0x7ffe8a768bf9] register_frame_ctor+0x7ffd8a1e6b09
[0x10047c67c] rb_io_each_byte+0x6f
[0x10055c83c] vm_call_cfunc_with_frame+0x12c
[0x100562585] vm_sendish+0xf2
[0x1005698ca] vm_exec_core+0x1881
[0x100562c2e] rb_vm_exec+0x20e
[0x100454abe] rb_ec_exec_node+0x13b
[0x100458c7a] ruby_run_node+0x64
[0x100581d9c] main+0x7c
[0x18004adef] register_frame_ctor+0x7fac8cff
[0x180048825] register_frame_ctor+0x7fac6735
[0x1800488d3] register_frame_ctor+0x7fac67e3

Updated by mame (Yusuke Endoh) over 1 year ago

  • Status changed from Open to Assigned
  • Assignee set to naruse (Yui NARUSE)

Also available in: Atom PDF