[前][次][番号順一覧][スレッド一覧]

ruby-changes:72261

From: Chris <ko1@a...>
Date: Tue, 21 Jun 2022 06:57:34 +0900 (JST)
Subject: [ruby-changes:72261] 31b2cd38c5 (master): Include JIT information in crash reports

https://git.ruby-lang.org/ruby.git/commit/?id=31b2cd38c5

From 31b2cd38c5dcf4a0c51ca56ecdddf7461b8ac86c Mon Sep 17 00:00:00 2001
From: Chris Seaton <chris.seaton@s...>
Date: Tue, 14 Jun 2022 16:08:36 +0100
Subject: Include JIT information in crash reports

Since enabling YJIT or MJIT drastically changes what could go wrong at
runtime, it's good to be front and center about whether they are enabled
when dumping a crash report. Previously, `RUBY_DESCRIPTION` and the
description printed when crashing can be different when a JIT is on.

Introduce a new internal data global, `rb_dynamic_description`, and set
it to be the same as `RUBY_DESCRIPTION` during initialization; use it
when crashing.

 * version.c: Init_ruby_description(): Initialize and use
       `rb_dynamic_description`.
 * error.c: Change crash reports to use `rb_dynamic_description`.
 * ruby.c: Call `Init_ruby_description()` earlier. Slightly more work
       for when we exit right after printing the description but that
       was deemed acceptable.
 * include/ruby/version.h: Talk about how JIT info is not in
      `ruby_description`.
 * test/-ext-/bug_reporter/test_bug_reporter.rb: Remove handling for
       crash description being different from `RUBY_DESCRIPTION`.
 * test/ruby/test_rubyoptions.rb: ditto

Co-authored-by: Nobuyoshi Nakada <nobu@r...>
Co-authored-by: Alan Wu <alanwu@r...>
---
 error.c                                      |  8 ++++----
 include/ruby/version.h                       |  3 ++-
 ruby.c                                       |  6 +++---
 test/-ext-/bug_reporter/test_bug_reporter.rb |  2 --
 test/ruby/test_rubyoptions.rb                |  2 +-
 version.c                                    | 15 ++++++---------
 6 files changed, 16 insertions(+), 20 deletions(-)

diff --git a/error.c b/error.c
index 35e797f5b9..d5721b2eca 100644
--- a/error.c
+++ b/error.c
@@ -82,7 +82,7 @@ static struct { https://github.com/ruby/ruby/blob/trunk/error.c#L82
     st_table *id2enum, *enum2id;
 } warning_categories;
 
-extern const char ruby_description[];
+extern const char *rb_dynamic_description;
 
 static const char *
 rb_strerrno(int err)
@@ -730,7 +730,7 @@ bug_report_begin_valist(FILE *out, const char *fmt, va_list args) https://github.com/ruby/ruby/blob/trunk/error.c#L730
     fputs("[BUG] ", out);
     vsnprintf(buf, sizeof(buf), fmt, args);
     fputs(buf, out);
-    snprintf(buf, sizeof(buf), "\n%s\n\n", ruby_description);
+    snprintf(buf, sizeof(buf), "\n%s\n\n", rb_dynamic_description);
     fputs(buf, out);
     preface_dump(out);
 }
@@ -866,7 +866,7 @@ rb_async_bug_errno(const char *mesg, int errno_arg) https://github.com/ruby/ruby/blob/trunk/error.c#L866
 	write_or_abort(2, errno_str, strlen(errno_str));
     }
     WRITE_CONST(2, "\n\n");
-    write_or_abort(2, ruby_description, strlen(ruby_description));
+    write_or_abort(2, rb_dynamic_description, strlen(rb_dynamic_description));
     abort();
 }
 
@@ -882,7 +882,7 @@ rb_assert_failure(const char *file, int line, const char *name, const char *expr https://github.com/ruby/ruby/blob/trunk/error.c#L882
     FILE *out = stderr;
     fprintf(out, "Assertion Failed: %s:%d:", file, line);
     if (name) fprintf(out, "%s:", name);
-    fprintf(out, "%s\n%s\n\n", expr, ruby_description);
+    fprintf(out, "%s\n%s\n\n", expr, rb_dynamic_description);
     preface_dump(out);
     rb_vm_bugreport(NULL);
     bug_report_end(out);
diff --git a/include/ruby/version.h b/include/ruby/version.h
index f10b58f9c7..18b3abc8d7 100644
--- a/include/ruby/version.h
+++ b/include/ruby/version.h
@@ -137,7 +137,8 @@ RUBY_EXTERN const int  ruby_patchlevel; https://github.com/ruby/ruby/blob/trunk/include/ruby/version.h#L137
 
 /**
  * This is what `ruby -v` prints to the standard error.  Something like:
- * `"ruby 2.5.9p229 (2021-04-05 revision 67829) [x86_64-linux]"`
+ * `"ruby 2.5.9p229 (2021-04-05 revision 67829) [x86_64-linux]"`. This doesn't
+ * include runtime options like a JIT being enabled.
  */
 RUBY_EXTERN const char ruby_description[];
 
diff --git a/ruby.c b/ruby.c
index 9e38572751..191e8a7a71 100644
--- a/ruby.c
+++ b/ruby.c
@@ -1826,10 +1826,11 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt) https://github.com/ruby/ruby/blob/trunk/ruby.c#L1826
         rb_yjit_init();
 #endif
     }
-    if (opt->dump & (DUMP_BIT(version) | DUMP_BIT(version_v))) {
 #if USE_MJIT
-        mjit_opts.on = opt->mjit.on; /* used by ruby_show_version(). mjit_init() still can't be called here. */
+    mjit_opts.on = opt->mjit.on; /* used by Init_ruby_description(). mjit_init() still can't be called here. */
 #endif
+    Init_ruby_description();
+    if (opt->dump & (DUMP_BIT(version) | DUMP_BIT(version_v))) {
 	ruby_show_version();
 	if (opt->dump & DUMP_BIT(version)) return Qtrue;
     }
@@ -1888,7 +1889,6 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt) https://github.com/ruby/ruby/blob/trunk/ruby.c#L1889
         mjit_init(&opt->mjit);
 #endif
 
-    Init_ruby_description();
     Init_enc();
     lenc = rb_locale_encoding();
     rb_enc_associate(rb_progname, lenc);
diff --git a/test/-ext-/bug_reporter/test_bug_reporter.rb b/test/-ext-/bug_reporter/test_bug_reporter.rb
index 990b6a2cc5..6e955e2cbd 100644
--- a/test/-ext-/bug_reporter/test_bug_reporter.rb
+++ b/test/-ext-/bug_reporter/test_bug_reporter.rb
@@ -7,8 +7,6 @@ class TestBugReporter < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/-ext-/bug_reporter/test_bug_reporter.rb#L7
     omit if ENV['RUBY_ON_BUG']
 
     description = RUBY_DESCRIPTION
-    description = description.sub(/\+MJIT /, '') if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled?
-    description = description.sub(/\+YJIT /, '') if defined?(RubyVM::YJIT.enabled?) && RubyVM::YJIT.enabled?
     expected_stderr = [
       :*,
       /\[BUG\]\sSegmentation\sfault.*\n/,
diff --git a/test/ruby/test_rubyoptions.rb b/test/ruby/test_rubyoptions.rb
index ab15006e4c..757cbcf41f 100644
--- a/test/ruby/test_rubyoptions.rb
+++ b/test/ruby/test_rubyoptions.rb
@@ -740,7 +740,7 @@ class TestRubyOptions < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rubyoptions.rb#L740
         -e:(?:1:)?\s\[BUG\]\sSegmentation\sfault.*\n
       )x,
       %r(
-        #{ Regexp.quote(NO_JIT_DESCRIPTION) }\n\n
+        #{ Regexp.quote(RUBY_DESCRIPTION) }\n\n
       )x,
       %r(
         (?:--\s(?:.+\n)*\n)?
diff --git a/version.c b/version.c
index 7d4478eeb6..a628952907 100644
--- a/version.c
+++ b/version.c
@@ -47,6 +47,9 @@ static const char ruby_description_with_yjit[] = RUBY_DESCRIPTION_WITH(" +YJIT") https://github.com/ruby/ruby/blob/trunk/version.c#L47
 const char ruby_copyright[] = RUBY_COPYRIGHT;
 const char ruby_engine[] = "ruby";
 
+// Might change after initialization
+const char *rb_dynamic_description = ruby_description;
+
 /*! Defines platform-depended Ruby-level constants */
 void
 Init_version(void)
@@ -104,9 +107,11 @@ Init_ruby_description(void) https://github.com/ruby/ruby/blob/trunk/version.c#L107
     VALUE description;
 
     if (MJIT_OPTS_ON) {
+        rb_dynamic_description = ruby_description_with_mjit;
         description = MKSTR(description_with_mjit);
     }
     else if (rb_yjit_enabled_p()) {
+        rb_dynamic_description = ruby_description_with_yjit;
         description = MKSTR(description_with_yjit);
     }
     else {
@@ -122,15 +127,7 @@ Init_ruby_description(void) https://github.com/ruby/ruby/blob/trunk/version.c#L127
 void
 ruby_show_version(void)
 {
-    if (MJIT_OPTS_ON) {
-        PRINT(description_with_mjit);
-    }
-    else if (rb_yjit_enabled_p()) {
-        PRINT(description_with_yjit);
-    }
-    else {
-        PRINT(description);
-    }
+    puts(rb_dynamic_description);
 
 #ifdef RUBY_LAST_COMMIT_TITLE
     fputs("last_commit=" RUBY_LAST_COMMIT_TITLE, stdout);
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]