aboutsummaryrefslogtreecommitdiffstats
path: root/error.c
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2019-08-15 13:48:58 +0900
committerGitHub <noreply@github.com>2019-08-15 13:48:58 +0900
commit53a55aeff3d409b4894d077f2b3b874fac53e387 (patch)
tree53fbb9e4b71206f521ef31cad981dc2241566644 /error.c
parent132b7eb104ed2f5d9966adb2f0edacb2406f40fb (diff)
downloadruby-53a55aeff3d409b4894d077f2b3b874fac53e387.tar.gz
introduce RUBY_ON_BUG envval. (#2331)
`rb_bug()` is called at critical bug, MRI can't run anymore. To make debug easy, this patch introduces RUBY_ON_BUG environment variable to specify the process which is called with pid. [Feature #16090] [GH #2331] RUBY_ON_BUG='gdb -p' ruby xxx.rb In this case, if ruby interpreter causes critical bug, and call rb_bug(), then "gdb -p [PID]' is called by system(3). You can debug on invoked gdb. This feature is limited on RUBY_DEVEL build.
Diffstat (limited to 'error.c')
-rw-r--r--error.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/error.c b/error.c
index 786c525be8..8c3aaded95 100644
--- a/error.c
+++ b/error.c
@@ -429,8 +429,9 @@ bug_report_file(const char *file, int line)
if ((ssize_t)fwrite(buf, 1, len, out) == (ssize_t)len ||
(ssize_t)fwrite(buf, 1, len, (out = stdout)) == (ssize_t)len) {
- return out;
+ return out;
}
+
return NULL;
}
@@ -519,6 +520,17 @@ bug_report_begin_valist(FILE *out, const char *fmt, va_list args)
snprintf(buf, sizeof(buf), "\n%s\n\n", ruby_description);
fputs(buf, out);
preface_dump(out);
+
+#if RUBY_DEVEL
+ const char *cmd = getenv("RUBY_ON_BUG");
+ if (cmd) {
+ snprintf(buf, sizeof(buf), "%s %d", cmd, getpid());
+ int r = system(buf);
+ if (r == -1) {
+ snprintf(buf, sizeof(buf), "Launching RUBY_ON_BUG command failed.");
+ }
+ }
+#endif
}
#define bug_report_begin(out, fmt) do { \