Project

General

Profile

Actions

Feature #20249

open

Introduce a backtrace-only mode for rb_bug()

Added by osyoyu (Daisuke Aritomo) 10 months ago. Updated 9 months ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:116640]

Description

Background

When a segfault or some unexpected situation occurs, rb_bug() is called and prints some few hundred to thousands of lines.

The most helpful parts are (arguably) "Ruby level backtrace information" and "C-level backtrace information", but those parts are buried in the very lengthy report.
In particular, the "Other runtime information" which contains the list of loaded features (scripts?) and the process memory map could be extremely long despite it does not come very useful, at least when developing C extensions.

Even a minimal report from a simple script would consist of 250 lines and require 7 PgUps on my MacBook Air (13 inch) to reach the backtrace part, which contains all the information I need.

Proposal

My proposal is to default to a "minimal report" mode with a limited set of sections, perhaps only "Ruby level backtrace information" and "C level backtrace information" only

When a full report is desired (i.e. for bug reports), the user could re-run the script with an special environment variable, such as RUBY_FULL_CRASH_REPORT=1.
Rust implmements a similar pattern. It doesn't print the full backtrace on panics by default; instead, it guides the user to re-run the program with RUST_BACKTRACE=1.

It might be hard to reproduce some crashes and segfaults, especially in long-running daemons. It might be nice to default to the "full" mode when stdout is not a tty, since daemons tend to run in non-tty environments.

Appendix

A typical crash report would look like this:

../../example.rb: [BUG]
ruby 3.4.0dev (2024-01-20T15:27:19Z master 366b14c0cd) [arm64-darwin23]

-- Crash Report log information --------------------------------------------
(5 lines)

-- Control frame information -----------------------------------------------
(~50 lines)

-- Ruby level backtrace information ----------------------------------------
(depends on program; typically ~50 lines in Rails)

-- C level backtrace information -------------------------------------------
(50+-ish lines, depends on program)

-- Machine register context ------------------------------------------------
(~10 lines)

-- Threading information ---------------------------------------------------
(2 lines)

-- Other runtime information -----------------------------------------------
* Loaded script (1 line)
* Loaded features (depends on program; 800+ lines in Rails)
* Process memory map (depends on environment; around 200 lines?)
Actions

Also available in: Atom PDF

Like3
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0