summaryrefslogtreecommitdiff
path: root/vm_backtrace.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-10-08 15:56:01 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-10-08 15:56:01 +0000
commit21e858e518c4cec31f4c56caa37682db38bac6a3 (patch)
tree5f1abbb9fd29a2e0357b05037ee267e114e9a11f /vm_backtrace.c
parent42976d75f32c4321d602038d74be922efa4dcacd (diff)
load.c: display backtrace to $stderr
* load.c (load_lock): display backtrace to $stderr at circular require. * vm_backtrace.c (rb_backtrace_print_to): new function to print backtrace to the given output. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43204 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm_backtrace.c')
-rw-r--r--vm_backtrace.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/vm_backtrace.c b/vm_backtrace.c
index 8155c85..1f2e8c3 100644
--- a/vm_backtrace.c
+++ b/vm_backtrace.c
@@ -768,6 +768,35 @@ rb_backtrace(void)
vm_backtrace_print(stderr);
}
+static void
+oldbt_print_to(void *data, VALUE file, int lineno, VALUE name)
+{
+ VALUE output = (VALUE)data;
+ VALUE str = rb_sprintf("\tfrom %"PRIsVALUE":%d:in ", file, lineno);
+
+ if (NIL_P(name)) {
+ rb_str_cat2(str, "unknown method\n");
+ }
+ else {
+ rb_str_catf(str, " `%"PRIsVALUE"'\n", name);
+ }
+ rb_io_write(output, str);
+}
+
+void
+rb_backtrace_print_to(VALUE output)
+{
+ struct oldbt_arg arg;
+
+ arg.func = oldbt_print_to;
+ arg.data = (void *)output;
+ backtrace_each(GET_THREAD(),
+ oldbt_init,
+ oldbt_iter_iseq,
+ oldbt_iter_cfunc,
+ &arg);
+}
+
VALUE
rb_make_backtrace(void)
{