10
10
#include <insns_info.inc>
11
11
#include "ruby_debug.h"
12
12
13
- #define DEBUG_VERSION "0.11 "
13
+ #define DEBUG_VERSION "0.12 "
14
14
15
15
#define GET_CFP debug_context->cfp[check_frame_number(debug_context, frame)]
16
16
22
22
#define RUBY_VERSION_1_9_1
23
23
#endif
24
24
25
- #define STACK_SIZE_INCREMENT 128
26
-
27
25
RUBY_EXTERN int rb_vm_get_sourceline (const rb_control_frame_t * cfp ); /* from vm.c */
28
26
RUBY_EXTERN VALUE rb_iseq_compile_with_option (VALUE src , VALUE file , VALUE line , VALUE opt ); /* from iseq.c */
29
27
@@ -34,10 +32,8 @@ typedef struct {
34
32
static VALUE hook_off = Qtrue ;
35
33
static VALUE tracing = Qfalse ;
36
34
static VALUE locker = Qnil ;
37
- static VALUE keep_frame_binding = Qfalse ;
38
35
static VALUE debug = Qfalse ;
39
36
static VALUE catchall = Qtrue ;
40
- static VALUE track_frame_args = Qfalse ;
41
37
static VALUE skip_next_exception = Qfalse ;
42
38
43
39
static VALUE last_context = Qnil ;
@@ -339,13 +335,15 @@ FUNC_FASTCALL(do_catchall)(rb_thread_t *th, rb_control_frame_t *cfp)
339
335
thread_context_lookup (th -> self , & context , & debug_context , 0 );
340
336
if (debug_context == NULL )
341
337
rb_raise (rb_eRuntimeError , "Lost context in catchall" );
338
+ if (debug_context -> saved_frames == NULL )
339
+ rb_raise (rb_eRuntimeError , "catchall called improperly" ); // TODO: throw
342
340
343
341
size = sizeof (rb_control_frame_t ) *
344
342
((debug_context -> cfp [debug_context -> cfp_count - 1 ] - debug_context -> cfp [0 ]) + 1 );
345
- memcpy (debug_context -> cfp [0 ], debug_context -> frames , size );
343
+ memcpy (debug_context -> cfp [0 ], debug_context -> saved_frames , size );
346
344
347
- free (debug_context -> frames );
348
- debug_context -> frames = NULL ;
345
+ free (debug_context -> saved_frames );
346
+ debug_context -> saved_frames = NULL ;
349
347
350
348
CTX_FL_SET (debug_context , CTX_FL_CATCHING );
351
349
th -> cfp = debug_context -> cfp [0 ];
@@ -363,6 +361,8 @@ create_exception_catchall(debug_context_t *debug_context)
363
361
cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME (cfp );
364
362
365
363
debug_context -> start_cfp = cfp ;
364
+ if (catchall == Qfalse )
365
+ return ;
366
366
367
367
iseq = cfp -> iseq ;
368
368
iseq -> catch_table_size ++ ;
@@ -399,6 +399,10 @@ create_exception_catchall(debug_context_t *debug_context)
399
399
debug_context -> catch_iseq .iseq_encoded [0 ] = bin_opt_call_c_function ;
400
400
debug_context -> catch_iseq .iseq_encoded [1 ] = (VALUE )do_catchall ;
401
401
}
402
+ // TODO: add instructions
403
+ // getdynamic #$!, 0
404
+ // throw 0
405
+ // to remove need for "catchall called improperly" in do_catchall()
402
406
debug_context -> catch_iseq .iseq_size = 2 ;
403
407
debug_context -> catch_iseq .mark_ary = rb_ary_new ();
404
408
debug_context -> catch_iseq .insn_info_table = & debug_context -> catch_info_entry ;
@@ -468,7 +472,6 @@ debug_context_create(VALUE thread)
468
472
debug_context -> stop_line = -1 ;
469
473
debug_context -> stop_frame = -1 ;
470
474
debug_context -> stop_reason = CTX_STOP_NONE ;
471
- debug_context -> stack_len = STACK_SIZE_INCREMENT ;
472
475
debug_context -> thread_id = ref2id (thread );
473
476
debug_context -> breakpoint = Qnil ;
474
477
debug_context -> jump_pc = NULL ;
@@ -481,7 +484,7 @@ debug_context_create(VALUE thread)
481
484
debug_context -> cur_cfp = NULL ;
482
485
debug_context -> top_cfp = NULL ;
483
486
debug_context -> catch_cfp = NULL ;
484
- debug_context -> frames = NULL ;
487
+ debug_context -> saved_frames = NULL ;
485
488
debug_context -> cfp = NULL ;
486
489
if (rb_obj_class (thread ) == cDebugThread )
487
490
CTX_FL_SET (debug_context , CTX_FL_IGNORE );
@@ -839,13 +842,21 @@ save_frames(debug_context_t *debug_context)
839
842
debug_context -> catch_table .errinfo = rb_errinfo ();
840
843
841
844
debug_context -> catch_cfp = GET_THREAD ()-> cfp ;
842
- if (debug_context -> frames != NULL )
843
- free (debug_context -> frames );
845
+ if (debug_context -> saved_frames != NULL )
846
+ free (debug_context -> saved_frames );
844
847
845
848
size = sizeof (rb_control_frame_t ) *
846
849
((debug_context -> cfp [debug_context -> cfp_count - 1 ] - debug_context -> cfp [0 ]) + 1 );
847
- debug_context -> frames = (rb_control_frame_t * )malloc (size );
848
- memcpy (debug_context -> frames , debug_context -> cfp [0 ], size );
850
+ debug_context -> saved_frames = (rb_control_frame_t * )malloc (size );
851
+ memcpy (debug_context -> saved_frames , debug_context -> cfp [0 ], size );
852
+
853
+ for (size = 0 ; size < debug_context -> cfp_count ; size ++ )
854
+ {
855
+ rb_binding_t * bind ;
856
+ VALUE bindval = binding_alloc (rb_cBinding );
857
+ GetBindingPtr (bindval , bind );
858
+ bind -> env = rb_vm_make_env_object (GET_THREAD (), debug_context -> cfp [size ]);
859
+ }
849
860
}
850
861
851
862
static void
@@ -879,9 +890,12 @@ debug_event_hook(rb_event_flag_t event, VALUE data, VALUE self, ID mid, VALUE kl
879
890
return ;
880
891
thread_context_lookup (th -> self , & context , & debug_context , 1 );
881
892
882
- if (iseq && (self == rb_mKernel || self == mDebugger ) &&
893
+ debug_context -> catch_cfp = NULL ;
894
+ if (iseq && (self == rb_mKernel || self == mDebugger || klass == cContext || klass == 0 ) &&
883
895
(strcmp (RSTRING_PTR (iseq -> name ), "binding_n" ) == 0 ))
884
896
return ;
897
+ if (iseq && (klass == cContext || klass == 0 ) && (strcmp (RSTRING_PTR (iseq -> name ), "frame_binding" ) == 0 ))
898
+ return ;
885
899
886
900
if (debug_context -> top_cfp && th -> cfp >= debug_context -> top_cfp )
887
901
return ;
@@ -1378,56 +1392,6 @@ debug_set_tracing(VALUE self, VALUE value)
1378
1392
return value ;
1379
1393
}
1380
1394
1381
- /*
1382
- * call-seq:
1383
- * Debugger.track_fame_args? -> bool
1384
- *
1385
- * Returns +true+ if the debugger track frame argument values on calls.
1386
- */
1387
- static VALUE
1388
- debug_track_frame_args (VALUE self )
1389
- {
1390
- return track_frame_args ;
1391
- }
1392
-
1393
- /*
1394
- * call-seq:
1395
- * Debugger.track_frame_args = bool
1396
- *
1397
- * Setting to +true+ will make the debugger save argument info on calls.
1398
- */
1399
- static VALUE
1400
- debug_set_track_frame_args (VALUE self , VALUE value )
1401
- {
1402
- track_frame_args = RTEST (value ) ? Qtrue : Qfalse ;
1403
- return value ;
1404
- }
1405
-
1406
- /*
1407
- * call-seq:
1408
- * Debugger.keep_frame_binding? -> bool
1409
- *
1410
- * Returns +true+ if the debugger will collect frame bindings.
1411
- */
1412
- static VALUE
1413
- debug_keep_frame_binding (VALUE self )
1414
- {
1415
- return keep_frame_binding ;
1416
- }
1417
-
1418
- /*
1419
- * call-seq:
1420
- * Debugger.keep_frame_binding = bool
1421
- *
1422
- * Setting to +true+ will make the debugger create frame bindings.
1423
- */
1424
- static VALUE
1425
- debug_set_keep_frame_binding (VALUE self , VALUE value )
1426
- {
1427
- keep_frame_binding = RTEST (value ) ? Qtrue : Qfalse ;
1428
- return value ;
1429
- }
1430
-
1431
1395
/* :nodoc: */
1432
1396
static VALUE
1433
1397
debug_debug (VALUE self )
@@ -1696,19 +1660,6 @@ optional_frame_position(int argc, VALUE *argv)
1696
1660
return level ;
1697
1661
}
1698
1662
1699
- /*
1700
- * call-seq:
1701
- * context.frame_args_info(frame_position=0) -> list
1702
- if track_frame_args or nil otherwise
1703
- *
1704
- * Deprecated.
1705
- */
1706
- static VALUE
1707
- context_frame_args_info (int argc , VALUE * argv , VALUE self )
1708
- {
1709
- return (Qnil );
1710
- }
1711
-
1712
1663
/*
1713
1664
* call-seq:
1714
1665
* context.frame_binding(frame_position=0) -> binding
@@ -1730,13 +1681,7 @@ context_frame_binding(int argc, VALUE *argv, VALUE self)
1730
1681
GetThreadPtr (context_thread_0 (debug_context ), th );
1731
1682
cfp = GET_CFP ;
1732
1683
1733
- //cfp = rb_vm_get_ruby_level_next_cfp(th, cfp);
1734
1684
bindval = binding_alloc (rb_cBinding );
1735
-
1736
- if (cfp == 0 ) {
1737
- rb_raise (rb_eRuntimeError , "Can't create Binding Object on top of Fiber." );
1738
- }
1739
-
1740
1685
GetBindingPtr (bindval , bind );
1741
1686
bind -> env = rb_vm_make_env_object (th , cfp );
1742
1687
return bindval ;
@@ -2382,7 +2327,6 @@ Init_context()
2382
2327
rb_define_method (cContext , "tracing=" , context_set_tracing , 1 );
2383
2328
rb_define_method (cContext , "ignored?" , context_ignored , 0 );
2384
2329
rb_define_method (cContext , "frame_args" , context_frame_args , -1 );
2385
- rb_define_method (cContext , "frame_args_info" , context_frame_args_info , -1 );
2386
2330
rb_define_method (cContext , "frame_binding" , context_frame_binding , -1 );
2387
2331
rb_define_method (cContext , "frame_class" , context_frame_class , -1 );
2388
2332
rb_define_method (cContext , "frame_file" , context_frame_file , -1 );
@@ -2493,14 +2437,6 @@ Init_ruby_debug()
2493
2437
rb_define_module_function (mDebugger , "debug_load" , debug_debug_load , -1 );
2494
2438
rb_define_module_function (mDebugger , "skip" , debug_skip , 0 );
2495
2439
rb_define_module_function (mDebugger , "debug_at_exit" , debug_at_exit , 0 );
2496
- rb_define_module_function (mDebugger , "keep_frame_binding?" ,
2497
- debug_keep_frame_binding , 0 );
2498
- rb_define_module_function (mDebugger , "keep_frame_binding=" ,
2499
- debug_set_keep_frame_binding , 1 );
2500
- rb_define_module_function (mDebugger , "track_frame_args?" ,
2501
- debug_track_frame_args , 0 );
2502
- rb_define_module_function (mDebugger , "track_frame_args=" ,
2503
- debug_set_track_frame_args , 1 );
2504
2440
rb_define_module_function (mDebugger , "debug" , debug_debug , 0 );
2505
2441
rb_define_module_function (mDebugger , "debug=" , debug_set_debug , 1 );
2506
2442
rb_define_module_function (mDebugger , "catchall" , debug_catchall , 0 );
0 commit comments