9
9
#include <insns_info.inc>
10
10
#include "ruby_debug.h"
11
11
12
- #define DEBUG_VERSION "0.11.30.pre3 "
12
+ #define DEBUG_VERSION "0.11.30.pre4 "
13
13
14
14
#define FRAME_N (n ) (&debug_context->frames[debug_context->stack_size-(n)-1])
15
15
#define GET_FRAME (FRAME_N(check_frame_number(debug_context, frame)))
@@ -134,55 +134,16 @@ real_class(VALUE klass)
134
134
return klass ;
135
135
}
136
136
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
-
156
137
inline static VALUE
157
138
ref2id (VALUE obj )
158
139
{
159
- return rb_obj_id ( obj ) ;
140
+ return obj ;
160
141
}
161
142
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
183
144
id2ref (VALUE id )
184
145
{
185
- return rb_rescue ( id2ref_unprotected , id , id2ref_error , 0 ) ;
146
+ return id ;
186
147
}
187
148
188
149
inline static VALUE
@@ -256,18 +217,31 @@ remove_from_locked()
256
217
return thread ;
257
218
}
258
219
220
+ static int is_living_thread (VALUE thread );
221
+
259
222
static 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 )
261
224
{
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
+ }
263
236
return ST_CONTINUE ;
264
237
}
265
238
266
239
static void
267
240
threads_table_mark (void * data )
268
241
{
269
242
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 );
271
245
}
272
246
273
247
static void
@@ -279,7 +253,7 @@ threads_table_free(void* data)
279
253
}
280
254
281
255
static VALUE
282
- threads_table_create ()
256
+ threads_table_create (void )
283
257
{
284
258
threads_table_t * threads_table ;
285
259
@@ -288,52 +262,48 @@ threads_table_create()
288
262
return Data_Wrap_Struct (cThreadsTable , threads_table_mark , threads_table_free , threads_table );
289
263
}
290
264
291
- static int
292
- threads_table_clear_i (VALUE key , VALUE value , VALUE dummy )
293
- {
294
- return ST_DELETE ;
295
- }
296
-
297
265
static void
298
266
threads_table_clear (VALUE table )
299
267
{
300
268
threads_table_t * threads_table ;
301
269
302
270
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 );
304
272
}
305
273
306
- static VALUE
274
+ static int
307
275
is_thread_alive (VALUE thread )
308
276
{
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 ;
316
280
}
317
281
318
282
static 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 )
320
290
{
321
291
VALUE thread ;
322
292
323
- thread = id2ref (key );
324
- if (!rb_obj_is_kind_of (thread , rb_cThread ))
293
+ if (!value )
325
294
{
326
295
return ST_DELETE ;
327
296
}
328
- if (rb_protect (is_thread_alive , thread , 0 ) != Qtrue )
297
+ thread = id2ref ((VALUE )key );
298
+ if (!is_living_thread (thread ))
329
299
{
330
300
return ST_DELETE ;
331
301
}
332
302
return ST_CONTINUE ;
333
303
}
334
304
335
305
static void
336
- check_thread_contexts ()
306
+ check_thread_contexts (void )
337
307
{
338
308
threads_table_t * threads_table ;
339
309
@@ -740,11 +710,6 @@ debug_event_hook(rb_event_flag_t event, VALUE data, VALUE self, ID mid, VALUE kl
740
710
char * file = (char * )rb_sourcefile ();
741
711
int line = rb_sourceline ();
742
712
int moved = 0 ;
743
- #ifndef HAVE_RB_METHOD_ENTRY
744
- NODE * node = NULL ;
745
- #else
746
- rb_method_entry_t * me = NULL ;
747
- #endif
748
713
rb_thread_t * thread = GET_THREAD ();
749
714
struct rb_iseq_struct * iseq = thread -> cfp -> iseq ;
750
715
@@ -762,12 +727,6 @@ debug_event_hook(rb_event_flag_t event, VALUE data, VALUE self, ID mid, VALUE kl
762
727
763
728
if (mid == ID_ALLOCATOR ) return ;
764
729
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
-
771
730
/* return if thread is marked as 'ignored'.
772
731
debugger's threads are marked this way
773
732
*/
@@ -978,11 +937,7 @@ debug_event_hook(rb_event_flag_t event, VALUE data, VALUE self, ID mid, VALUE kl
978
937
case RUBY_EVENT_C_RETURN :
979
938
{
980
939
/* 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 ))
986
941
break ;
987
942
}
988
943
case RUBY_EVENT_RETURN :
0 commit comments