ext/byebug/byebug.c in byebug-1.1.0 vs ext/byebug/byebug.c in byebug-1.1.1
- old
+ new
@@ -1,17 +1,15 @@
#include <byebug.h>
static VALUE mByebug; /* Ruby Byebug Module object */
static VALUE cContext;
-static VALUE cDebugThread;
static VALUE tracing = Qfalse;
static VALUE post_mortem = Qfalse;
static VALUE debug = Qfalse;
-static VALUE locker = Qnil;
-static VALUE contexts;
+static VALUE context;
static VALUE catchpoints;
static VALUE breakpoints;
static VALUE tpLine;
static VALUE tpCall;
@@ -27,12 +25,12 @@
VALUE event = rb_tracearg_event(trace_arg);
if (ID2SYM(rb_intern("line")) == event ||
ID2SYM(rb_intern("specified_line")) == event)
{
VALUE sym = rb_tracearg_method_id(trace_arg);
- if (!NIL_P(sym))
- return rb_sprintf("%"PRIsVALUE"@%"PRIsVALUE":%d in `%"PRIsVALUE"'",
+ if (NIL_P(sym)) sym = rb_str_new_cstr("<main>");
+ return rb_sprintf("%"PRIsVALUE"@%"PRIsVALUE":%d in `%"PRIsVALUE"'",
rb_tracearg_event(trace_arg),
rb_tracearg_path(trace_arg),
FIX2INT(rb_tracearg_lineno(trace_arg)),
sym);
}
@@ -52,82 +50,27 @@
}
return rb_sprintf("No info");
}
static VALUE
-Byebug_thread_context(VALUE self, VALUE thread)
+Byebug_context(VALUE self)
{
- VALUE context;
-
- context = rb_hash_aref(contexts, thread);
if (context == Qnil) {
- context = Context_create(thread, cDebugThread);
- rb_hash_aset(contexts, thread, context);
+ context = Context_create();
}
return context;
}
-static VALUE
-Byebug_current_context(VALUE self)
-{
- return Byebug_thread_context(self, rb_thread_current());
-}
-
-/*
-static int
-remove_dead_threads(VALUE thread, VALUE context, VALUE ignored)
-{
- return (IS_THREAD_ALIVE(thread)) ? ST_CONTINUE : ST_DELETE;
-}
-*/
-
static void
cleanup(debug_context_t *context)
{
- VALUE thread;
-
context->stop_reason = CTX_STOP_NONE;
-
- /* release a lock */
- locker = Qnil;
-
- /* let the next thread run */
- thread = remove_from_locked();
- if(thread != Qnil)
- rb_thread_run(thread);
}
static int
-check_start_processing(debug_context_t *context, VALUE thread)
+check_start_processing(debug_context_t *context)
{
- /* return if thread is marked as 'ignored' */
- if(CTX_FL_TEST(context, CTX_FL_IGNORE)) return 0;
-
- while(1)
- {
- /* halt execution of the current thread if byebug is activated in another */
- while(locker != Qnil && locker != thread)
- {
- add_to_locked(thread);
- rb_thread_stop();
- }
-
- /* stop the current thread if it's marked as suspended */
- if(CTX_FL_TEST(context, CTX_FL_SUSPEND) && locker != thread)
- {
- CTX_FL_SET(context, CTX_FL_WAS_RUNNING);
- rb_thread_stop();
- }
- else break;
- }
-
- /* return if the current thread is the locker */
- if(locker != Qnil) return 0;
-
- /* only the current thread can proceed */
- locker = thread;
-
/* ignore a skipped section of code */
if(CTX_FL_TEST(context, CTX_FL_SKIPPED)) {
cleanup(context);
return 0;
}
@@ -164,13 +107,13 @@
#define EVENT_SETUP \
VALUE path, lineno, method_id, defined_class, binding, self; \
VALUE context_object; \
debug_context_t *context; \
- context_object = Byebug_current_context(mByebug); \
+ context_object = Byebug_context(mByebug); \
Data_Get_Struct(context_object, debug_context_t, context); \
- if (!check_start_processing(context, rb_thread_current())) return; \
+ if (!check_start_processing(context)) return; \
load_frame_info(trace_point, &path, &lineno, &method_id, &defined_class, \
&binding, &self); \
if (debug == Qtrue) \
printf("%s (stack_size: %d)\n", \
RSTRING_PTR(tp_inspect(trace_point)), context->stack_size); \
@@ -199,21 +142,22 @@
if (RTEST(tracing))
rb_funcall(context_object, rb_intern("at_tracing"), 2, path, lineno);
if (context->dest_frame == -1 || context->stack_size == context->dest_frame)
{
- if (moved || !CTX_FL_TEST(context, CTX_FL_FORCE_MOVE)) {
- context->stop_next = context->stop_next <= 0 ? -1 : context->stop_next-1;
- context->stop_line = context->stop_line <= 0 ? -1 : context->stop_line-1;
+ if (moved || !CTX_FL_TEST(context, CTX_FL_FORCE_MOVE))
+ {
+ context->steps = context->steps <= 0 ? -1 : context->steps - 1;
+ context->lines = context->lines <= 0 ? -1 : context->lines - 1;
}
}
else if (context->stack_size < context->dest_frame)
{
- context->stop_next = 0;
+ context->steps = 0;
}
- if (context->stop_next == 0 || context->stop_line == 0)
+ if (context->steps == 0 || context->lines == 0)
{
context->stop_reason = CTX_STOP_STEP;
reset_stepping_stop_points(context);
call_at_line(
context, RSTRING_PTR(path), FIX2INT(lineno), context_object, path, lineno);
@@ -248,12 +192,12 @@
{
EVENT_SETUP;
if (context->stack_size == context->stop_frame)
{
- context->stop_next = 1;
- context->stop_frame = 0;
+ context->steps = 1;
+ context->stop_frame = -1;
}
pop_frame(context);
cleanup(context);
}
@@ -346,11 +290,10 @@
static VALUE
Byebug_setup_tracepoints(VALUE self)
{
if (catchpoints != Qnil) return Qnil;
- contexts = rb_hash_new();
breakpoints = rb_ary_new();
catchpoints = rb_hash_new();
tpLine = rb_tracepoint_new(Qnil,
RUBY_EVENT_LINE,
@@ -387,11 +330,11 @@
}
static VALUE
Byebug_remove_tracepoints(VALUE self)
{
- contexts = Qnil;
+ context = Qnil;
breakpoints = Qnil;
catchpoints = Qnil;
if (tpLine != Qnil) {
rb_tracepoint_disable(tpLine);
@@ -418,17 +361,10 @@
tpRaise = Qnil;
}
return Qnil;
}
-static int
-values_i(VALUE key, VALUE value, VALUE ary)
-{
- rb_ary_push(ary, value);
- return ST_CONTINUE;
-}
-
#define BYEBUG_STARTED (catchpoints != Qnil)
static VALUE
Byebug_started(VALUE self)
{
return BYEBUG_STARTED;
@@ -468,11 +404,11 @@
set_current_skipped_status(VALUE status)
{
VALUE context_object;
debug_context_t *context;
- context_object = Byebug_current_context(mByebug);
+ context_object = Byebug_context(mByebug);
Data_Get_Struct(context_object, debug_context_t, context);
if (status)
CTX_FL_SET(context, CTX_FL_SKIPPED);
else
CTX_FL_UNSET(context, CTX_FL_SKIPPED);
@@ -491,14 +427,14 @@
stop = Qfalse;
}
Byebug_start(self);
- context_object = Byebug_current_context(self);
+ context_object = Byebug_context(self);
Data_Get_Struct(context_object, debug_context_t, context);
context->stack_size = 0;
- if (RTEST(stop)) context->stop_next = 1;
+ if (RTEST(stop)) context->steps = 1;
/* Initializing $0 to the script's path */
ruby_script(RSTRING_PTR(file));
rb_load_protect(file, 0, &state);
if (0 != state)
@@ -570,25 +506,10 @@
post_mortem = RTEST(value) ? Qtrue : Qfalse;
return value;
}
static VALUE
-Byebug_contexts(VALUE self)
-{
- VALUE ary;
-
- ary = rb_ary_new();
-
- /* check that all contexts point to alive threads */
- /*rb_hash_foreach(contexts, remove_dead_threads, self);*/
-
- rb_hash_foreach(contexts, values_i, ary);
-
- return ary;
-}
-
-static VALUE
Byebug_breakpoints(VALUE self)
{
return breakpoints;
}
@@ -624,13 +545,11 @@
mByebug = rb_define_module("Byebug");
rb_define_module_function(mByebug, "setup_tracepoints",
Byebug_setup_tracepoints, 0);
rb_define_module_function(mByebug, "remove_tracepoints",
Byebug_remove_tracepoints, 0);
- rb_define_module_function(mByebug, "current_context",
- Byebug_current_context, 0);
- rb_define_module_function(mByebug, "contexts", Byebug_contexts, 0);
+ rb_define_module_function(mByebug, "context", Byebug_context, 0);
rb_define_module_function(mByebug, "breakpoints", Byebug_breakpoints, 0);
rb_define_module_function(mByebug, "add_catchpoint",
Byebug_add_catchpoint, 1);
rb_define_module_function(mByebug, "catchpoints", Byebug_catchpoints, 0);
rb_define_module_function(mByebug, "_start", Byebug_start, 0);
@@ -645,15 +564,13 @@
cContext = Init_context(mByebug);
Init_breakpoint(mByebug);
- cDebugThread = rb_define_class_under(mByebug, "DebugThread", rb_cThread);
- contexts = Qnil;
+ context = Qnil;
catchpoints = Qnil;
breakpoints = Qnil;
- rb_global_variable(&locker);
rb_global_variable(&breakpoints);
rb_global_variable(&catchpoints);
- rb_global_variable(&contexts);
+ rb_global_variable(&context);
}