Skip to content

Commit

Permalink
Fixes #54
Browse files Browse the repository at this point in the history
Sometimes TracePoint API events are generated for dead or aborting
threads. Just ignore those events.
  • Loading branch information
David Rodríguez committed Jan 3, 2015
1 parent ad327bb commit 399cd14
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
4 changes: 4 additions & 0 deletions ext/byebug/byebug.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ cleanup(debug_context_t * dc)
rb_trace_arg_t *trace_arg = rb_tracearg_from_tracepoint(trace_point); \
debug_context_t *dc; \
VALUE context; \
\
if (!is_living_thread(rb_thread_current())) \
return; \
\
thread_context_lookup(rb_thread_current(), &context); \
Data_Get_Struct(context, debug_context_t, dc); \
\
Expand Down
1 change: 1 addition & 0 deletions ext/byebug/byebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ extern VALUE create_threads_table(void);
extern void check_threads_table(void);
extern void thread_context_lookup(VALUE thread, VALUE *context);
extern void halt_while_other_thread_is_active(debug_context_t *dc);
extern int is_living_thread(VALUE thread);

/* global variables */
extern VALUE locker;
Expand Down
28 changes: 18 additions & 10 deletions ext/byebug/threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,6 @@ create_threads_table(void)
return Data_Wrap_Struct(cThreadsTable, t_tbl_mark, t_tbl_free, t_tbl);
}

/*
* The condition to be in the thread's table is to be either running or
* sleeping, namely, to be Thread#alive?
*/
static int
is_living_thread(VALUE thread)
{
return rb_funcall(thread, rb_intern("alive?"), 0) == Qtrue;
}

/*
* Checks a single entry in the threads table.
*
Expand All @@ -77,6 +67,24 @@ check_thread_i(st_data_t key, st_data_t value, st_data_t dummy)
return ST_CONTINUE;
}

/*
* Checks whether a thread is either in the running or sleeping state.
*/
int
is_living_thread(VALUE thread)
{
VALUE status = rb_funcall(thread, rb_intern("status"), 0);

if (status == Qfalse)
return 0;

if (rb_str_cmp(status, rb_str_new2("run")) == 0
|| rb_str_cmp(status, rb_str_new2("sleep")) == 0)
return 1;

return 0;
}

/*
* Checks threads table for dead/finished threads.
*/
Expand Down
1 change: 0 additions & 1 deletion test/commands/eval_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def program
end

def test_eval_properly_evaluates_an_expression_using_timeout
skip('for now')
enter 'eval Timeout::timeout(60) { 1 }'
debug_code(program)
check_output_includes '1'
Expand Down

0 comments on commit 399cd14

Please sign in to comment.