ext/byebug/byebug.c in byebug-3.2.0 vs ext/byebug/byebug.c in byebug-3.3.0
- old
+ new
@@ -10,16 +10,15 @@
static VALUE breakpoints = Qnil;
static VALUE tracepoints = Qnil;
static VALUE raised_exception = Qnil;
-/* Implements thread syncronization, we must stop threads when debugging */
+/* To allow thread syncronization, we must stop threads when debugging */
VALUE locker = Qnil;
-/* Threads table */
+/* Hash table with active threads and their associated contexts */
VALUE threads = Qnil;
-VALUE cThreadsTable;
#define IS_STARTED (catchpoints != Qnil)
static void
check_started()
{
@@ -32,19 +31,17 @@
static void
trace_print(rb_trace_arg_t *trace_arg, debug_context_t *dc)
{
if (trace_arg)
{
- int i = 0;
const char *event = rb_id2name(SYM2ID(rb_tracearg_event(trace_arg)));
char *path = RSTRING_PTR(rb_tracearg_path(trace_arg));
int line = NUM2INT(rb_tracearg_lineno(trace_arg));
- VALUE v_mid = rb_tracearg_method_id(trace_arg);
- const char *mid = NIL_P(v_mid) ? "" : rb_id2name(SYM2ID(v_mid));
-
- for (i = 0; i < dc->calced_stack_size; i++) putc('-', stdout);
- printf("(%d)->[#%d] %s@%s:%d %s\n",
+ VALUE v_mid_sym = rb_tracearg_method_id(trace_arg);
+ VALUE v_mid_id = NIL_P(v_mid_sym) ? Qnil : SYM2ID(v_mid_sym);
+ const char *mid = NIL_P(v_mid_id) ? "" : rb_id2name(v_mid_id);
+ printf("%*s (%d)->[#%d] %s@%s:%d %s\n", dc->calced_stack_size, "",
dc->calced_stack_size, dc->thnum, event, path, line, mid);
}
}
static void
@@ -53,11 +50,11 @@
VALUE thread;
dc->stop_reason = CTX_STOP_NONE;
/* checks for dead threads */
- check_thread_contexts();
+ check_threads_table();
/* release a lock */
locker = Qnil;
/* let the next thread to run */
@@ -70,14 +67,15 @@
rb_trace_arg_t *trace_arg = rb_tracearg_from_tracepoint(trace_point); \
debug_context_t *dc; \
VALUE context; \
thread_context_lookup(rb_thread_current(), &context); \
Data_Get_Struct(context, debug_context_t, dc); \
+
+#define EVENT_COMMON \
if (verbose == Qtrue) trace_print(trace_arg, dc); \
+ if (!trace_common(trace_arg, dc)) { return; } \
-#define EVENT_COMMON if (!trace_common(trace_arg, dc)) { return; }
-
static int
trace_common(rb_trace_arg_t *trace_arg, debug_context_t *dc)
{
/* return if thread marked as 'ignored', like byebug's control thread */
if (CTX_FL_TEST(dc, CTX_FL_IGNORE))
@@ -214,11 +212,11 @@
{
dc->lines = dc->lines <= 0 ? -1 : dc->lines - 1;
if (dc->calced_stack_size < dc->dest_frame)
{
dc->dest_frame = dc->calced_stack_size;
- rb_funcall(mByebug, rb_intern("print"), 1,
+ rb_funcall(mByebug, rb_intern("puts"), 1,
rb_str_new2("Next went up a frame because previous frame finished\n"));
}
}
}
@@ -456,12 +454,12 @@
VALUE thread = rb_ary_entry(list, i);
thread_context_lookup(thread, &context);
rb_ary_push(new_list, context);
}
- threads_clear(threads);
Data_Get_Struct(threads, threads_table_t, t_tbl);
+ st_clear(t_tbl->tbl);
for (i = 0; i < RARRAY_LENINT(new_list); i++)
{
context = rb_ary_entry(new_list, i);
Data_Get_Struct(context, debug_context_t, dc);
@@ -567,11 +565,11 @@
else
{
locker = Qnil;
breakpoints = rb_ary_new();
catchpoints = rb_hash_new();
- threads = threads_create();
+ threads = create_threads_table();
register_tracepoints(self);
result = Qtrue;
}
@@ -604,10 +602,12 @@
bb_start(self);
context = bb_current_context(self);
Data_Get_Struct(context, debug_context_t, dc);
+ dc->calced_stack_size = 1;
+
if (RTEST(stop)) dc->steps = 1;
/* Initializing $0 to the script's path */
ruby_script(RSTRING_PTR(file));
rb_load_protect(file, 0, &state);
@@ -707,11 +707,11 @@
* Returns an array of breakpoints.
*/
static VALUE
bb_breakpoints(VALUE self)
{
- return breakpoints;
+ return NIL_P(breakpoints) ? rb_ary_new() : breakpoints;
}
/*
* call-seq:
* Byebug.catchpoints -> array
@@ -781,11 +781,10 @@
rb_define_module_function(mByebug, "tracing?" , bb_tracing , 0);
rb_define_module_function(mByebug, "tracing=" , bb_set_tracing , 1);
rb_define_module_function(mByebug, "verbose?" , bb_verbose , 0);
rb_define_module_function(mByebug, "verbose=" , bb_set_verbose , 1);
- cThreadsTable = rb_define_class_under(mByebug, "ThreadsTable", rb_cObject);
-
+ Init_threads_table(mByebug);
Init_context(mByebug);
Init_breakpoint(mByebug);
rb_global_variable(&breakpoints);
rb_global_variable(&catchpoints);