summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog12
-rw-r--r--common.mk9
-rw-r--r--internal.h13
-rw-r--r--vm.c2
-rw-r--r--vm_backtrace.c137
-rw-r--r--vm_core.h1
-rw-r--r--vm_dump.c3
-rw-r--r--vm_eval.c128
8 files changed, 165 insertions, 140 deletions
diff --git a/ChangeLog b/ChangeLog
index 64da335..7edcd0d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+Sun Jun 3 00:49:11 2012 Koichi Sasada <ko1@atdot.net>
+
+ * common.mk: fix to build vm_backtrace.c only itself (vm_backtrace.c
+ is no longer included from vm.c). I hope this separation reduce
+ compile time of vm.c.
+
+ * internal.h: ditto.
+
+ * vm.c, vm_core.h, vm_dump.c, vm_eval.c: ditto.
+
+ * vm_eval.c: some functions (callee, etc) moved to vm_backtrace.c.
+
Sun Jun 3 00:20:53 2012 Koichi Sasada <ko1@atdot.net>
* vm_backtrace.c: added. Separate backtrace related functions to
diff --git a/common.mk b/common.mk
index fe8e0e7..d5eaff4 100644
--- a/common.mk
+++ b/common.mk
@@ -91,6 +91,7 @@ COMMONOBJS = array.$(OBJEXT) \
iseq.$(OBJEXT) \
vm.$(OBJEXT) \
vm_dump.$(OBJEXT) \
+ vm_backtrace.$(OBJEXT) \
thread.$(OBJEXT) \
cont.$(OBJEXT) \
$(BUILTIN_ENCOBJS) \
@@ -752,13 +753,17 @@ vm.$(OBJEXT): {$(VPATH)}vm.c {$(VPATH)}gc.h {$(VPATH)}iseq.h \
{$(VPATH)}vm_insnhelper.c {$(VPATH)}vm_insnhelper.h {$(VPATH)}vm_exec.c \
{$(VPATH)}vm_exec.h {$(VPATH)}insns.def {$(VPATH)}vmtc.inc \
{$(VPATH)}vm.inc {$(VPATH)}insns.inc {$(VPATH)}debug.h \
- {$(VPATH)}internal.h {$(VPATH)}vm.h {$(VPATH)}constant.h {$(VPATH)}vm_backtrace.c
+ {$(VPATH)}internal.h {$(VPATH)}vm.h {$(VPATH)}constant.h
vm_dump.$(OBJEXT): {$(VPATH)}vm_dump.c $(RUBY_H_INCLUDES) \
- $(VM_CORE_H_INCLUDES) {$(VPATH)}debug.h {$(VPATH)}addr2line.h
+ $(VM_CORE_H_INCLUDES) {$(VPATH)}debug.h {$(VPATH)}addr2line.h \
+ {$(VPATH)}internal.h
debug.$(OBJEXT): {$(VPATH)}debug.c $(RUBY_H_INCLUDES) \
$(ENCODING_H_INCLUDES) $(VM_CORE_H_INCLUDES) {$(VPATH)}eval_intern.h \
{$(VPATH)}util.h {$(VPATH)}debug.h
id.$(OBJEXT): {$(VPATH)}id.c $(RUBY_H_INCLUDES) $(ID_H_INCLUDES)
+vm_backtrace.$(OBJEXT): {$(VPATH)}vm_backtrace.c \
+ $(VM_CORE_H_INCLUDES) $(RUBY_H_INCLUDES) \
+ {$(VPATH)}internal.h {$(VPATH)}iseq.h
miniprelude.$(OBJEXT): {$(VPATH)}miniprelude.c $(RUBY_H_INCLUDES) \
$(VM_CORE_H_INCLUDES) {$(VPATH)}debug.h {$(VPATH)}internal.h
prelude.$(OBJEXT): {$(VPATH)}prelude.c $(RUBY_H_INCLUDES) \
diff --git a/internal.h b/internal.h
index 99fd4fe..6bf4cf3 100644
--- a/internal.h
+++ b/internal.h
@@ -190,7 +190,6 @@ VALUE rb_obj_is_mutex(VALUE obj);
VALUE ruby_suppress_tracing(VALUE (*func)(VALUE, int), VALUE arg, int always);
void rb_thread_execute_interrupts(VALUE th);
void rb_clear_trace_func(void);
-VALUE rb_thread_backtrace(VALUE thval);
VALUE rb_get_coverages(void);
/* thread_pthread.c, thread_win32.c */
@@ -207,9 +206,6 @@ void rb_vm_inc_const_missing_count(void);
void rb_thread_mark(void *th);
const void **rb_vm_get_insns_address_table(void);
VALUE rb_sourcefilename(void);
-int rb_backtrace_p(VALUE obj);
-VALUE rb_backtrace_to_str_ary(VALUE obj);
-VALUE rb_vm_backtrace_object();
/* vm_dump.c */
void rb_vm_bugreport(void);
@@ -225,6 +221,15 @@ int rb_method_defined_by(VALUE obj, ID mid, VALUE (*cfunc)(ANYARGS));
/* miniprelude.c, prelude.c */
void Init_prelude(void);
+/* vm_backtrace.c */
+void Init_vm_backtrace(void);
+VALUE rb_thread_backtrace(VALUE thval);
+VALUE rb_make_backtrace(void);
+void rb_backtrace_print_as_bugreport(void);
+int rb_backtrace_p(VALUE obj);
+VALUE rb_backtrace_to_str_ary(VALUE obj);
+VALUE rb_vm_backtrace_object();
+
#if defined __GNUC__ && __GNUC__ >= 4
#pragma GCC visibility push(default)
#endif
diff --git a/vm.c b/vm.c
index 0be740c..80e4949 100644
--- a/vm.c
+++ b/vm.c
@@ -26,7 +26,6 @@
#include "vm_method.c"
#include "vm_eval.c"
-#include "vm_backtrace.c"
#include <assert.h>
@@ -2155,6 +2154,7 @@ Init_VM(void)
}
vm_init_redefined_flag();
+ /* vm_backtrac.c */
Init_vm_backtrace();
}
diff --git a/vm_backtrace.c b/vm_backtrace.c
index 9216a54..e21b580 100644
--- a/vm_backtrace.c
+++ b/vm_backtrace.c
@@ -9,7 +9,12 @@
**********************************************************************/
-/* this file is included by vm.c */
+#include "ruby/ruby.h"
+#include "ruby/encoding.h"
+
+#include "internal.h"
+#include "vm_core.h"
+#include "iseq.h"
static VALUE rb_cBacktrace;
static VALUE rb_cFrameInfo;
@@ -586,13 +591,13 @@ backtrace_load_data(VALUE self, VALUE str)
return self;
}
-static VALUE
+VALUE
vm_backtrace_str_ary(rb_thread_t *th, int lev, int n)
{
return backtrace_to_str_ary2(backtrace_object(th), lev, n);
}
-static VALUE
+VALUE
vm_backtrace_frame_ary(rb_thread_t *th, int lev, int n)
{
return backtrace_to_frame_ary(backtrace_object(th), lev, n);
@@ -701,7 +706,129 @@ rb_backtrace_print_as_bugreport(void)
&arg);
}
-static void
+void
+rb_backtrace(void)
+{
+ vm_backtrace_print(stderr);
+}
+
+VALUE
+rb_make_backtrace(void)
+{
+ return vm_backtrace_str_ary(GET_THREAD(), 0, 0);
+}
+
+VALUE
+rb_thread_backtrace(VALUE thval)
+{
+ rb_thread_t *th;
+ GetThreadPtr(thval, th);
+
+ switch (th->status) {
+ case THREAD_RUNNABLE:
+ case THREAD_STOPPED:
+ case THREAD_STOPPED_FOREVER:
+ break;
+ case THREAD_TO_KILL:
+ case THREAD_KILLED:
+ return Qnil;
+ }
+
+ return vm_backtrace_str_ary(th, 0, 0);
+}
+
+/*
+ * call-seq:
+ * caller(start=1) -> array or nil
+ *
+ * Returns the current execution stack---an array containing strings in
+ * the form ``<em>file:line</em>'' or ``<em>file:line: in
+ * `method'</em>''. The optional _start_ parameter
+ * determines the number of initial stack entries to omit from the
+ * result.
+ *
+ * Returns +nil+ if _start_ is greater than the size of
+ * current execution stack.
+ *
+ * def a(skip)
+ * caller(skip)
+ * end
+ * def b(skip)
+ * a(skip)
+ * end
+ * def c(skip)
+ * b(skip)
+ * end
+ * c(0) #=> ["prog:2:in `a'", "prog:5:in `b'", "prog:8:in `c'", "prog:10:in `<main>'"]
+ * c(1) #=> ["prog:5:in `b'", "prog:8:in `c'", "prog:11:in `<main>'"]
+ * c(2) #=> ["prog:8:in `c'", "prog:12:in `<main>'"]
+ * c(3) #=> ["prog:13:in `<main>'"]
+ * c(4) #=> []
+ * c(5) #=> nil
+ */
+
+static VALUE
+rb_f_caller(int argc, VALUE *argv)
+{
+ VALUE level, vn;
+ int lev, n;
+
+ rb_scan_args(argc, argv, "02", &level, &vn);
+
+ lev = NIL_P(level) ? 1 : NUM2INT(level);
+
+ if (NIL_P(vn)) {
+ n = 0;
+ }
+ else {
+ n = NUM2INT(vn);
+ if (n == 0) {
+ return rb_ary_new();
+ }
+ }
+
+ if (lev < 0) {
+ rb_raise(rb_eArgError, "negative level (%d)", lev);
+ }
+ if (n < 0) {
+ rb_raise(rb_eArgError, "negative n (%d)", n);
+ }
+
+ return vm_backtrace_str_ary(GET_THREAD(), lev+1, n);
+}
+
+static VALUE
+rb_f_caller_frame_info(int argc, VALUE *argv)
+{
+ VALUE level, vn;
+ int lev, n;
+
+ rb_scan_args(argc, argv, "02", &level, &vn);
+
+ lev = NIL_P(level) ? 1 : NUM2INT(level);
+
+ if (NIL_P(vn)) {
+ n = 0;
+ }
+ else {
+ n = NUM2INT(vn);
+ if (n == 0) {
+ return rb_ary_new();
+ }
+ }
+
+ if (lev < 0) {
+ rb_raise(rb_eArgError, "negative level (%d)", lev);
+ }
+ if (n < 0) {
+ rb_raise(rb_eArgError, "negative n (%d)", n);
+ }
+
+ return vm_backtrace_frame_ary(GET_THREAD(), lev+1, n);
+}
+
+/* called from Init_vm() in vm.c */
+void
Init_vm_backtrace(void)
{
/* ::RubyVM::Backtrace */
@@ -722,4 +849,6 @@ Init_vm_backtrace(void)
rb_define_method(rb_cFrameInfo, "iseq", frame_info_iseq_m, 0);
rb_define_method(rb_cFrameInfo, "to_s", frame_info_to_str_m, 0);
rb_define_singleton_method(rb_cFrameInfo, "caller", rb_f_caller_frame_info, -1);
+
+ rb_define_global_function("caller", rb_f_caller, -1);
}
diff --git a/vm_core.h b/vm_core.h
index 9daabda..764f142 100644
--- a/vm_core.h
+++ b/vm_core.h
@@ -678,7 +678,6 @@ void rb_thread_reset_timer_thread(void);
void rb_thread_wakeup_timer_thread(void);
int ruby_thread_has_gvl_p(void);
-VALUE rb_make_backtrace(void);
typedef int rb_backtrace_iter_func(void *, VALUE, int, VALUE);
rb_control_frame_t *rb_vm_get_ruby_level_next_cfp(rb_thread_t *th, rb_control_frame_t *cfp);
int rb_vm_get_sourceline(const rb_control_frame_t *);
diff --git a/vm_dump.c b/vm_dump.c
index bc7af85..185646d 100644
--- a/vm_dump.c
+++ b/vm_dump.c
@@ -12,6 +12,7 @@
#include "ruby/ruby.h"
#include "addr2line.h"
#include "vm_core.h"
+#include "internal.h"
/* see vm_insnhelper.h for the values */
#ifndef VMDEBUG
@@ -756,8 +757,6 @@ dump_thread(void *arg)
}
#endif
-void rb_backtrace_print_as_bugreport(void);
-
void
rb_vm_bugreport(void)
{
diff --git a/vm_eval.c b/vm_eval.c
index b9cfee0..dee646c 100644
--- a/vm_eval.c
+++ b/vm_eval.c
@@ -20,9 +20,8 @@ static VALUE vm_exec(rb_thread_t *th);
static void vm_set_eval_stack(rb_thread_t * th, VALUE iseqval, const NODE *cref);
static int vm_collect_local_variables_in_heap(rb_thread_t *th, VALUE *dfp, VALUE ary);
-static VALUE vm_backtrace_str_ary(rb_thread_t *th, int lev, int n);
-static VALUE vm_backtrace_frame_ary(rb_thread_t *th, int lev, int n);
-static void vm_backtrace_print(FILE *fp);
+/* vm_backtrace.c */
+VALUE vm_backtrace_str_ary(rb_thread_t *th, int lev, int n);
typedef enum call_type {
CALL_PUBLIC,
@@ -1579,127 +1578,6 @@ rb_catch_obj(VALUE tag, VALUE (*func)(), VALUE data)
/*
* call-seq:
- * caller(start=1) -> array or nil
- *
- * Returns the current execution stack---an array containing strings in
- * the form ``<em>file:line</em>'' or ``<em>file:line: in
- * `method'</em>''. The optional _start_ parameter
- * determines the number of initial stack entries to omit from the
- * result.
- *
- * Returns +nil+ if _start_ is greater than the size of
- * current execution stack.
- *
- * def a(skip)
- * caller(skip)
- * end
- * def b(skip)
- * a(skip)
- * end
- * def c(skip)
- * b(skip)
- * end
- * c(0) #=> ["prog:2:in `a'", "prog:5:in `b'", "prog:8:in `c'", "prog:10:in `<main>'"]
- * c(1) #=> ["prog:5:in `b'", "prog:8:in `c'", "prog:11:in `<main>'"]
- * c(2) #=> ["prog:8:in `c'", "prog:12:in `<main>'"]
- * c(3) #=> ["prog:13:in `<main>'"]
- * c(4) #=> []
- * c(5) #=> nil
- */
-
-static VALUE
-rb_f_caller(int argc, VALUE *argv)
-{
- VALUE level, vn;
- int lev, n;
-
- rb_scan_args(argc, argv, "02", &level, &vn);
-
- lev = NIL_P(level) ? 1 : NUM2INT(level);
-
- if (NIL_P(vn)) {
- n = 0;
- }
- else {
- n = NUM2INT(vn);
- if (n == 0) {
- return rb_ary_new();
- }
- }
-
- if (lev < 0) {
- rb_raise(rb_eArgError, "negative level (%d)", lev);
- }
- if (n < 0) {
- rb_raise(rb_eArgError, "negative n (%d)", n);
- }
-
- return vm_backtrace_str_ary(GET_THREAD(), lev+1, n);
-}
-
-static VALUE
-rb_f_caller_frame_info(int argc, VALUE *argv)
-{
- VALUE level, vn;
- int lev, n;
-
- rb_scan_args(argc, argv, "02", &level, &vn);
-
- lev = NIL_P(level) ? 1 : NUM2INT(level);
-
- if (NIL_P(vn)) {
- n = 0;
- }
- else {
- n = NUM2INT(vn);
- if (n == 0) {
- return rb_ary_new();
- }
- }
-
- if (lev < 0) {
- rb_raise(rb_eArgError, "negative level (%d)", lev);
- }
- if (n < 0) {
- rb_raise(rb_eArgError, "negative n (%d)", n);
- }
-
- return vm_backtrace_frame_ary(GET_THREAD(), lev+1, n);
-}
-
-void
-rb_backtrace(void)
-{
- vm_backtrace_print(stderr);
-}
-
-VALUE
-rb_make_backtrace(void)
-{
- return vm_backtrace_str_ary(GET_THREAD(), 0, 0);
-}
-
-VALUE
-rb_thread_backtrace(VALUE thval)
-{
- rb_thread_t *th;
- GetThreadPtr(thval, th);
-
- switch (th->status) {
- case THREAD_RUNNABLE:
- case THREAD_STOPPED:
- case THREAD_STOPPED_FOREVER:
- break;
- case THREAD_TO_KILL:
- case THREAD_KILLED:
- return Qnil;
- }
-
- return vm_backtrace_str_ary(th, 0, 0);
-}
-
-/*
- * call-seq:
* local_variables -> array
*
* Returns the names of the current local variables.
@@ -1834,6 +1712,4 @@ Init_vm_eval(void)
rb_define_method(rb_cModule, "class_exec", rb_mod_module_exec, -1);
rb_define_method(rb_cModule, "module_eval", rb_mod_module_eval, -1);
rb_define_method(rb_cModule, "class_eval", rb_mod_module_eval, -1);
-
- rb_define_global_function("caller", rb_f_caller, -1);
}