Skip to content

Commit 4e588a9

Browse files
author
Mark Moseley
committed
bugfixes
1 parent 6ab79c5 commit 4e588a9

File tree

5 files changed

+306
-315
lines changed

5 files changed

+306
-315
lines changed

Diff for: ext/ruby_debug/ruby_debug.c

+29-93
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <insns_info.inc>
1111
#include "ruby_debug.h"
1212

13-
#define DEBUG_VERSION "0.11"
13+
#define DEBUG_VERSION "0.12"
1414

1515
#define GET_CFP debug_context->cfp[check_frame_number(debug_context, frame)]
1616

@@ -22,8 +22,6 @@
2222
#define RUBY_VERSION_1_9_1
2323
#endif
2424

25-
#define STACK_SIZE_INCREMENT 128
26-
2725
RUBY_EXTERN int rb_vm_get_sourceline(const rb_control_frame_t *cfp); /* from vm.c */
2826
RUBY_EXTERN VALUE rb_iseq_compile_with_option(VALUE src, VALUE file, VALUE line, VALUE opt); /* from iseq.c */
2927

@@ -34,10 +32,8 @@ typedef struct {
3432
static VALUE hook_off = Qtrue;
3533
static VALUE tracing = Qfalse;
3634
static VALUE locker = Qnil;
37-
static VALUE keep_frame_binding = Qfalse;
3835
static VALUE debug = Qfalse;
3936
static VALUE catchall = Qtrue;
40-
static VALUE track_frame_args = Qfalse;
4137
static VALUE skip_next_exception= Qfalse;
4238

4339
static VALUE last_context = Qnil;
@@ -339,13 +335,15 @@ FUNC_FASTCALL(do_catchall)(rb_thread_t *th, rb_control_frame_t *cfp)
339335
thread_context_lookup(th->self, &context, &debug_context, 0);
340336
if (debug_context == NULL)
341337
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
342340

343341
size = sizeof(rb_control_frame_t) *
344342
((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);
346344

347-
free(debug_context->frames);
348-
debug_context->frames = NULL;
345+
free(debug_context->saved_frames);
346+
debug_context->saved_frames = NULL;
349347

350348
CTX_FL_SET(debug_context, CTX_FL_CATCHING);
351349
th->cfp = debug_context->cfp[0];
@@ -363,6 +361,8 @@ create_exception_catchall(debug_context_t *debug_context)
363361
cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
364362

365363
debug_context->start_cfp = cfp;
364+
if (catchall == Qfalse)
365+
return;
366366

367367
iseq = cfp->iseq;
368368
iseq->catch_table_size++;
@@ -399,6 +399,10 @@ create_exception_catchall(debug_context_t *debug_context)
399399
debug_context->catch_iseq.iseq_encoded[0] = bin_opt_call_c_function;
400400
debug_context->catch_iseq.iseq_encoded[1] = (VALUE)do_catchall;
401401
}
402+
// TODO: add instructions
403+
// getdynamic #$!, 0
404+
// throw 0
405+
// to remove need for "catchall called improperly" in do_catchall()
402406
debug_context->catch_iseq.iseq_size = 2;
403407
debug_context->catch_iseq.mark_ary = rb_ary_new();
404408
debug_context->catch_iseq.insn_info_table = &debug_context->catch_info_entry;
@@ -468,7 +472,6 @@ debug_context_create(VALUE thread)
468472
debug_context->stop_line = -1;
469473
debug_context->stop_frame = -1;
470474
debug_context->stop_reason = CTX_STOP_NONE;
471-
debug_context->stack_len = STACK_SIZE_INCREMENT;
472475
debug_context->thread_id = ref2id(thread);
473476
debug_context->breakpoint = Qnil;
474477
debug_context->jump_pc = NULL;
@@ -481,7 +484,7 @@ debug_context_create(VALUE thread)
481484
debug_context->cur_cfp = NULL;
482485
debug_context->top_cfp = NULL;
483486
debug_context->catch_cfp = NULL;
484-
debug_context->frames = NULL;
487+
debug_context->saved_frames = NULL;
485488
debug_context->cfp = NULL;
486489
if(rb_obj_class(thread) == cDebugThread)
487490
CTX_FL_SET(debug_context, CTX_FL_IGNORE);
@@ -839,13 +842,21 @@ save_frames(debug_context_t *debug_context)
839842
debug_context->catch_table.errinfo = rb_errinfo();
840843

841844
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);
844847

845848
size = sizeof(rb_control_frame_t) *
846849
((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+
}
849860
}
850861

851862
static void
@@ -879,9 +890,12 @@ debug_event_hook(rb_event_flag_t event, VALUE data, VALUE self, ID mid, VALUE kl
879890
return;
880891
thread_context_lookup(th->self, &context, &debug_context, 1);
881892

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) &&
883895
(strcmp(RSTRING_PTR(iseq->name), "binding_n") == 0))
884896
return;
897+
if (iseq && (klass == cContext || klass == 0) && (strcmp(RSTRING_PTR(iseq->name), "frame_binding") == 0))
898+
return;
885899

886900
if (debug_context->top_cfp && th->cfp >= debug_context->top_cfp)
887901
return;
@@ -1378,56 +1392,6 @@ debug_set_tracing(VALUE self, VALUE value)
13781392
return value;
13791393
}
13801394

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-
14311395
/* :nodoc: */
14321396
static VALUE
14331397
debug_debug(VALUE self)
@@ -1696,19 +1660,6 @@ optional_frame_position(int argc, VALUE *argv)
16961660
return level;
16971661
}
16981662

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-
17121663
/*
17131664
* call-seq:
17141665
* context.frame_binding(frame_position=0) -> binding
@@ -1730,13 +1681,7 @@ context_frame_binding(int argc, VALUE *argv, VALUE self)
17301681
GetThreadPtr(context_thread_0(debug_context), th);
17311682
cfp = GET_CFP;
17321683

1733-
//cfp = rb_vm_get_ruby_level_next_cfp(th, cfp);
17341684
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-
17401685
GetBindingPtr(bindval, bind);
17411686
bind->env = rb_vm_make_env_object(th, cfp);
17421687
return bindval;
@@ -2382,7 +2327,6 @@ Init_context()
23822327
rb_define_method(cContext, "tracing=", context_set_tracing, 1);
23832328
rb_define_method(cContext, "ignored?", context_ignored, 0);
23842329
rb_define_method(cContext, "frame_args", context_frame_args, -1);
2385-
rb_define_method(cContext, "frame_args_info", context_frame_args_info, -1);
23862330
rb_define_method(cContext, "frame_binding", context_frame_binding, -1);
23872331
rb_define_method(cContext, "frame_class", context_frame_class, -1);
23882332
rb_define_method(cContext, "frame_file", context_frame_file, -1);
@@ -2493,14 +2437,6 @@ Init_ruby_debug()
24932437
rb_define_module_function(mDebugger, "debug_load", debug_debug_load, -1);
24942438
rb_define_module_function(mDebugger, "skip", debug_skip, 0);
24952439
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);
25042440
rb_define_module_function(mDebugger, "debug", debug_debug, 0);
25052441
rb_define_module_function(mDebugger, "debug=", debug_set_debug, 1);
25062442
rb_define_module_function(mDebugger, "catchall", debug_catchall, 0);

Diff for: ext/ruby_debug/ruby_debug.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ typedef struct {
5757
rb_control_frame_t *cur_cfp;
5858
rb_control_frame_t *top_cfp;
5959
rb_control_frame_t *catch_cfp;
60-
rb_control_frame_t *frames;
60+
rb_control_frame_t *saved_frames;
6161
//
6262
struct RData catch_rdata;
6363
struct rb_iseq_struct catch_iseq;

Diff for: test/data/scope-var.cmd

+1
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ step
3939
step
4040
step
4141
step
42+
cont

0 commit comments

Comments
 (0)