
Issue #20249 has been updated by ko1 (Koichi Sasada). At devmeeting yesterday, we concluded to have a new environment variable to control the `rb_bug()` crash report(as @Eregon said on https://bugs.ruby-lang.org/issues/20249#note-9). There are two proposals: * Introduce new environment variable * `RUBY_CRASH_REPORT_MODE`, `_OPTION`, `_CONFIG`, ... * Extend `RUBY_CRASH_REPORT` with options * `RUBY_CRASH_REPORT=path` style keeps current behavior * `RUBY_CRASH_REPORT=key1=val,key2=val,...` (if envstr =~ `/^\[a-z]+=/`) I prefer to extend `RUBY_CRASH_REPORT` but is it possible to use the path name like `foo=bar`? @katei told us that swift has `SWIFT_BACKTRACE` https://github.com/apple/swift/blob/main/docs/Backtracing.rst#how-do-i-confi... to configurate the backtrace output. And we also have some keys to control crash report (for developers). The followings are bikeshed fuel: If we allow key=value style options, maybe the following: * items (examples): * bt: Ruby-level backtrace * vmbt: Ruby-level backtrace with VM information * cbt: C-level backtrace * parallel * regs: Register information * lf: loaded features * mm: memory maps * further possibilities * allbts: bakcktraces for all threads * style (or preset or set?): preset configurations * default: current setting? * short: only bt and cbt? * full: all of them? * path: output filename To satisfy the current proposal, we can use path and style. Further bikeshed: I also want to show short crash report on TTY but I want to get full report in a file. It can be more complicated. Another concern is, `rb_bug()` will be called on critical situation and checking internal information (e.g. traversing backtrace) will cause duplicate SEGV. So the order is important. We need to care the order. ---------------------------------------- Feature #20249: Introduce a backtrace-only mode for rb_bug() https://bugs.ruby-lang.org/issues/20249#change-106791 * Author: osyoyu (Daisuke Aritomo) * Status: Open * Priority: Normal ---------------------------------------- ## 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?) -- https://bugs.ruby-lang.org/