Skip to content

Commit ae8371b

Browse files
viuginick1valich
authored andcommitted
Fix suspensions in debugger source code (replacement for an old, bad fix) (#73)
1 parent 0044e01 commit ae8371b

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

ext/context.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,16 @@ context_create(VALUE thread, VALUE cDebugThread) {
147147
context->stack_size = 0;
148148
locations = rb_funcall(thread, rb_intern("backtrace_locations"), 1, INT2FIX(1));
149149
context->calced_stack_size = locations != Qnil ? RARRAY_LENINT(locations) : 0;
150+
context->init_stack_size = -1;
150151

151152
context->stack = NULL;
152153
context->thnum = ++thnum_current;
153154
context->thread = thread;
154155
context->flags = 0;
155156
context->last_file = NULL;
156157
context->last_line = -1;
158+
context->hit_user_code = 0;
159+
context->script_finished = 0;
157160
context->stop_frame = -1;
158161
context->thread_pause = 0;
159162
context->stop_reason = CTX_STOP_NONE;

ext/debase_internals.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,8 @@ remove_pause_flag(VALUE thread, VALUE context_object, VALUE ignored)
303303
static void
304304
call_at_line(debug_context_t *context, char *file, int line, VALUE context_object)
305305
{
306+
context->hit_user_code = 1;
307+
306308
rb_hash_foreach(contexts, remove_pause_flag, 0);
307309
CTX_FL_UNSET(context, CTX_FL_STEPPED);
308310
CTX_FL_UNSET(context, CTX_FL_FORCE_MOVE);
@@ -331,6 +333,13 @@ process_line_event(VALUE trace_point, void *data)
331333
tp = TRACE_POINT;
332334
path = rb_tracearg_path(tp);
333335

336+
if(context->stack_size <= context->init_stack_size && context->hit_user_code) {
337+
context->script_finished = 1;
338+
}
339+
if(context->script_finished) {
340+
return;
341+
}
342+
334343
if (is_path_accepted(path)) {
335344

336345
lineno = rb_tracearg_lineno(tp);
@@ -340,6 +349,10 @@ process_line_event(VALUE trace_point, void *data)
340349
update_stack_size(context);
341350
print_event(tp, context);
342351

352+
if(context->init_stack_size == -1) {
353+
context->init_stack_size = context->stack_size;
354+
}
355+
343356
if (context->thread_pause) {
344357
context->stop_next = 1;
345358
context->dest_frame = -1;

ext/debase_internals.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ typedef struct debug_context {
6060

6161
char *last_file;
6262
int last_line;
63+
int init_stack_size;
64+
int script_finished;
65+
int hit_user_code;
6366
} debug_context_t;
6467

6568
typedef struct

0 commit comments

Comments
 (0)