99#include <insns_info.inc>
1010#include "ruby_debug.h"
1111
12- #define DEBUG_VERSION "0.11.30.pre3 "
12+ #define DEBUG_VERSION "0.11.30.pre4 "
1313
1414#define FRAME_N (n ) (&debug_context->frames[debug_context->stack_size-(n)-1])
1515#define GET_FRAME (FRAME_N(check_frame_number(debug_context, frame)))
@@ -134,55 +134,16 @@ real_class(VALUE klass)
134134 return klass ;
135135}
136136
137- inline static void *
138- ruby_method_ptr (VALUE class , ID meth_id )
139- {
140- #ifndef HAVE_RB_METHOD_ENTRY
141- NODE * body , * method ;
142- st_lookup (RCLASS_M_TBL (class ), meth_id , (st_data_t * )& body );
143- method = (NODE * )body -> u2 .value ;
144- return (void * )method -> u2 .node -> u1 .value ;
145- #else
146- rb_method_entry_t * method ;
147- method = rb_method_entry (class , meth_id );
148- #ifdef HAVE_ST_BODY
149- return (void * )method -> body .cfunc .func ;
150- #else
151- return (void * )method -> def -> body .cfunc .func ;
152- #endif
153- #endif
154- }
155-
156137inline static VALUE
157138ref2id (VALUE obj )
158139{
159- return rb_obj_id ( obj ) ;
140+ return obj ;
160141}
161142
162- static VALUE
163- id2ref_unprotected (VALUE id )
164- {
165- typedef VALUE (* id2ref_func_t )(VALUE , VALUE );
166- static id2ref_func_t f_id2ref = NULL ;
167- if (f_id2ref == NULL )
168- {
169- f_id2ref = (id2ref_func_t )ruby_method_ptr (rb_mObjectSpace , rb_intern ("_id2ref" ));
170- }
171- return f_id2ref (rb_mObjectSpace , id );
172- }
173-
174- static VALUE
175- id2ref_error ()
176- {
177- if (debug == Qtrue )
178- rb_p (rb_errinfo ());
179- return Qnil ;
180- }
181-
182- static VALUE
143+ inline static VALUE
183144id2ref (VALUE id )
184145{
185- return rb_rescue ( id2ref_unprotected , id , id2ref_error , 0 ) ;
146+ return id ;
186147}
187148
188149inline static VALUE
@@ -256,18 +217,31 @@ remove_from_locked()
256217 return thread ;
257218}
258219
220+ static int is_living_thread (VALUE thread );
221+
259222static int
260- threads_table_mark_keyvalue (VALUE key , VALUE value , int dummy )
223+ threads_table_mark_keyvalue (st_data_t key , st_data_t value , st_data_t tbl )
261224{
262- rb_gc_mark (value );
225+ VALUE thread = id2ref ((VALUE )key );
226+ if (!value ) {
227+ return ST_CONTINUE ;
228+ }
229+ rb_gc_mark ((VALUE )value );
230+ if (is_living_thread (thread )) {
231+ rb_gc_mark (thread );
232+ }
233+ else {
234+ st_insert ((st_table * )tbl , key , 0 );
235+ }
263236 return ST_CONTINUE ;
264237}
265238
266239static void
267240threads_table_mark (void * data )
268241{
269242 threads_table_t * threads_table = (threads_table_t * )data ;
270- st_foreach (threads_table -> tbl , threads_table_mark_keyvalue , 0 );
243+ st_table * tbl = threads_table -> tbl ;
244+ st_foreach (tbl , threads_table_mark_keyvalue , (st_data_t )tbl );
271245}
272246
273247static void
@@ -279,7 +253,7 @@ threads_table_free(void* data)
279253}
280254
281255static VALUE
282- threads_table_create ()
256+ threads_table_create (void )
283257{
284258 threads_table_t * threads_table ;
285259
@@ -288,52 +262,48 @@ threads_table_create()
288262 return Data_Wrap_Struct (cThreadsTable , threads_table_mark , threads_table_free , threads_table );
289263}
290264
291- static int
292- threads_table_clear_i (VALUE key , VALUE value , VALUE dummy )
293- {
294- return ST_DELETE ;
295- }
296-
297265static void
298266threads_table_clear (VALUE table )
299267{
300268 threads_table_t * threads_table ;
301269
302270 Data_Get_Struct (table , threads_table_t , threads_table );
303- st_foreach (threads_table -> tbl , threads_table_clear_i , 0 );
271+ st_clear (threads_table -> tbl );
304272}
305273
306- static VALUE
274+ static int
307275is_thread_alive (VALUE thread )
308276{
309- typedef VALUE (* thread_alive_func_t )(VALUE );
310- static thread_alive_func_t f_thread_alive = NULL ;
311- if (!f_thread_alive )
312- {
313- f_thread_alive = (thread_alive_func_t )ruby_method_ptr (rb_cThread , rb_intern ("alive?" ));
314- }
315- return f_thread_alive (thread );
277+ rb_thread_t * th ;
278+ GetThreadPtr (thread , th );
279+ return th -> status != THREAD_KILLED ;
316280}
317281
318282static int
319- threads_table_check_i (VALUE key , VALUE value , VALUE dummy )
283+ is_living_thread (VALUE thread )
284+ {
285+ return rb_obj_is_kind_of (thread , rb_cThread ) && is_thread_alive (thread );
286+ }
287+
288+ static int
289+ threads_table_check_i (st_data_t key , st_data_t value , st_data_t dummy )
320290{
321291 VALUE thread ;
322292
323- thread = id2ref (key );
324- if (!rb_obj_is_kind_of (thread , rb_cThread ))
293+ if (!value )
325294 {
326295 return ST_DELETE ;
327296 }
328- if (rb_protect (is_thread_alive , thread , 0 ) != Qtrue )
297+ thread = id2ref ((VALUE )key );
298+ if (!is_living_thread (thread ))
329299 {
330300 return ST_DELETE ;
331301 }
332302 return ST_CONTINUE ;
333303}
334304
335305static void
336- check_thread_contexts ()
306+ check_thread_contexts (void )
337307{
338308 threads_table_t * threads_table ;
339309
@@ -740,11 +710,6 @@ debug_event_hook(rb_event_flag_t event, VALUE data, VALUE self, ID mid, VALUE kl
740710 char * file = (char * )rb_sourcefile ();
741711 int line = rb_sourceline ();
742712 int moved = 0 ;
743- #ifndef HAVE_RB_METHOD_ENTRY
744- NODE * node = NULL ;
745- #else
746- rb_method_entry_t * me = NULL ;
747- #endif
748713 rb_thread_t * thread = GET_THREAD ();
749714 struct rb_iseq_struct * iseq = thread -> cfp -> iseq ;
750715
@@ -762,12 +727,6 @@ debug_event_hook(rb_event_flag_t event, VALUE data, VALUE self, ID mid, VALUE kl
762727
763728 if (mid == ID_ALLOCATOR ) return ;
764729
765- #ifndef HAVE_RB_METHOD_ENTRY
766- node = rb_method_node (klass , mid );
767- #else
768- me = rb_method_entry (klass , mid );
769- #endif
770-
771730 /* return if thread is marked as 'ignored'.
772731 debugger's threads are marked this way
773732 */
@@ -978,11 +937,7 @@ debug_event_hook(rb_event_flag_t event, VALUE data, VALUE self, ID mid, VALUE kl
978937 case RUBY_EVENT_C_RETURN :
979938 {
980939 /* note if a block is given we fall through! */
981- #ifndef HAVE_RB_METHOD_ENTRY
982- if (!node || !c_call_new_frame_p (klass , mid ))
983- #else
984- if (!me || !c_call_new_frame_p (klass , mid ))
985- #endif
940+ if (!rb_method_boundp (klass , mid , 0 ) || !c_call_new_frame_p (klass , mid ))
986941 break ;
987942 }
988943 case RUBY_EVENT_RETURN :
0 commit comments