diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-05-19 07:12:45 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-05-19 07:12:45 +0000 |
commit | 87023a1dcc548f0eb7ccfacd64d795093d1c7e17 (patch) | |
tree | 9ea63636e5b5c2e9e0cc4106433a04b506799daf /eval_error.c | |
parent | 5b58d8e6d8d187f37750540535f741cf6c2b661a (diff) |
eval_error.c: enrich backtrace
* eval_error.c (print_backtrace): add frame number when printing
in reverse order. [Feature #8661]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58786 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'eval_error.c')
-rw-r--r-- | eval_error.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/eval_error.c b/eval_error.c index 597f5d8d14..b671149bad 100644 --- a/eval_error.c +++ b/eval_error.c @@ -137,6 +137,11 @@ print_backtrace(const VALUE eclass, const VALUE errat, int reverse) long i; long len = RARRAY_LEN(errat); int skip = eclass == rb_eSysStackError; + const int threshold = 1000000000; + int width = ((int)log10((double)(len > threshold ? + ((len - 1) / threshold) : + len - 1)) + + (len < ? 0 : 9) + 1); #define TRACE_MAX (TRACE_HEAD+TRACE_TAIL+5) #define TRACE_HEAD 8 @@ -145,7 +150,9 @@ print_backtrace(const VALUE eclass, const VALUE errat, int reverse) for (i = 1; i < len; i++) { VALUE line = RARRAY_AREF(errat, reverse ? len - i : i); if (RB_TYPE_P(line, T_STRING)) { - warn_print_str(rb_sprintf("\tfrom %"PRIsVALUE"\n", line)); + VALUE str = rb_str_new_cstr("\t"); + if (reverse) rb_str_catf(str, "%*ld: ", width, len - i); + warn_print_str(rb_str_catf(str, "from %"PRIsVALUE"\n", line)); } if (skip && i == TRACE_HEAD && len > TRACE_MAX) { warn_print_str(rb_sprintf("\t ... %ld levels...\n", @@ -185,7 +192,7 @@ rb_threadptr_error_print(rb_thread_t *volatile th, volatile VALUE errinfo) } } if (rb_stderr_tty_p()) { - if (0) warn_print("Traceback (most recent call last):\n"); + warn_print("Traceback (most recent call last):\n"); print_backtrace(eclass, errat, TRUE); print_errinfo(eclass, errat, emesg); } |