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
This commit is contained in:
parent
5b58d8e6d8
commit
87023a1dcc
11
eval_error.c
11
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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user