From 1f3142a4477a10bfe566c17837c2a0b9f6cba00f Mon Sep 17 00:00:00 2001 From: ko1 Date: Fri, 25 May 2012 04:50:10 +0000 Subject: * vm.c: refactoring backtrace related funcitons. (1) unify similar functions (rb_backtrace_each() and backtrace_object()). backtrace_each() is a unified function. variation: a) backtrace_object(): create backtrace object. b) vm_backtrace_str_ary(): create bt as an array of string. c) vm_backtrace_print(): print backtrace to specified file. d) rb_backtrace_print_as_bugreport(): print backtrace on bugreport style. (2) remove rb_backtrace_each(). Use backtrace_each() instead. (3) chang the type of lev parameter to size_t. a) lev == 0 means current frame (exception, etc use it). b) lev == 1 means upper frame (caller(0) use it). * vm_core.h, vm_dump.c, vm_eval.c: ditto. * vm.c (backtrace_object(), vm_backtrace_str_ary()): fix to return a correct size of caller(lev) array. Let n be a "caller(0).size" then ln as caller(lev).size should be (n - lev). However, the previous implementation returns a wrong size array (ln > n - lev). [ruby-dev:45673] * test/ruby/test_backtrace.rb: add tests for backtrace. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35787 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- vm_dump.c | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) (limited to 'vm_dump.c') diff --git a/vm_dump.c b/vm_dump.c index 133499c..bc7af85 100644 --- a/vm_dump.c +++ b/vm_dump.c @@ -572,24 +572,6 @@ rb_vmdebug_thread_dump_state(VALUE self) return Qnil; } -static int -bugreport_backtrace(void *arg, VALUE file, int line, VALUE method) -{ - const char *filename = NIL_P(file) ? "ruby" : RSTRING_PTR(file); - if (!*(int *)arg) { - fprintf(stderr, "-- Ruby level backtrace information " - "----------------------------------------\n"); - *(int *)arg = 1; - } - if (NIL_P(method)) { - fprintf(stderr, "%s:%d:in unknown method\n", filename, line); - } - else { - fprintf(stderr, "%s:%d:in `%s'\n", filename, line, RSTRING_PTR(method)); - } - return 0; -} - #if defined(__FreeBSD__) && defined(__OPTIMIZE__) #undef HAVE_BACKTRACE #endif @@ -774,6 +756,8 @@ dump_thread(void *arg) } #endif +void rb_backtrace_print_as_bugreport(void); + void rb_vm_bugreport(void) { @@ -787,12 +771,9 @@ rb_vm_bugreport(void) #endif const rb_vm_t *const vm = GET_VM(); if (vm) { - int i = 0; SDR(); - - if (rb_backtrace_each(bugreport_backtrace, &i)) { - fputs("\n", stderr); - } + rb_backtrace_print_as_bugreport(); + fputs("\n", stderr); } #if HAVE_BACKTRACE || defined(_WIN32) -- cgit v1.1