diff options
author | Nobuyoshi Nakada <[email protected]> | 2023-08-01 03:04:42 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2023-09-25 22:57:28 +0900 |
commit | ac244938e8b97c8bd42d1dc8ed820091e6ef5537 (patch) | |
tree | d31693cc37095ca9f6a21092e8c254273b05915c /vm_backtrace.c | |
parent | acd44902b917230066b4fc7ea6c7e12556274512 (diff) |
Dump backtraces to an arbitrary stream
Diffstat (limited to 'vm_backtrace.c')
-rw-r--r-- | vm_backtrace.c | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/vm_backtrace.c b/vm_backtrace.c index 42debfba3d..34ebde0f0b 100644 --- a/vm_backtrace.c +++ b/vm_backtrace.c @@ -71,7 +71,7 @@ calc_pos(const rb_iseq_t *iseq, const VALUE *pc, int *lineno, int *node_id) #if VMDEBUG && defined(HAVE_BUILTIN___BUILTIN_TRAP) else { /* SDR() is not possible; that causes infinite loop. */ - rb_print_backtrace(); + rb_print_backtrace(stderr); __builtin_trap(); } #endif @@ -1003,31 +1003,38 @@ vm_backtrace_print(FILE *fp) &arg); } +struct oldbt_bugreport_arg { + FILE *fp; + int count; +}; + static void oldbt_bugreport(void *arg, VALUE file, int line, VALUE method) { + struct oldbt_bugreport_arg *p = arg; + FILE *fp = p->fp; const char *filename = NIL_P(file) ? "ruby" : RSTRING_PTR(file); - if (!*(int *)arg) { - fprintf(stderr, "-- Ruby level backtrace information " + if (!p->count) { + fprintf(fp, "-- Ruby level backtrace information " "----------------------------------------\n"); - *(int *)arg = 1; + p->count = 1; } if (NIL_P(method)) { - fprintf(stderr, "%s:%d:in unknown method\n", filename, line); + fprintf(fp, "%s:%d:in unknown method\n", filename, line); } else { - fprintf(stderr, "%s:%d:in `%s'\n", filename, line, RSTRING_PTR(method)); + fprintf(fp, "%s:%d:in `%s'\n", filename, line, RSTRING_PTR(method)); } } void -rb_backtrace_print_as_bugreport(void) +rb_backtrace_print_as_bugreport(FILE *fp) { struct oldbt_arg arg; - int i = 0; + struct oldbt_bugreport_arg barg = {fp, 0}; arg.func = oldbt_bugreport; - arg.data = (int *)&i; + arg.data = &barg; backtrace_each(GET_EC(), oldbt_init, |