Skip to content

Commit

Permalink
Closes #85
Browse files Browse the repository at this point in the history
  • Loading branch information
David Rodríguez committed Jan 9, 2015
1 parent a568cd4 commit 88451b5
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- `tracevar` now requires the full global variable name (with "$").
- `catch` command is not allowed in post_mortem mode anymore. It was not
working anyways (#92).
- `step` is now more user friendly when used in combination with `up` (see #85).

### Fixed
- Code reloading issues.
Expand Down
23 changes: 18 additions & 5 deletions ext/byebug/byebug.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,13 @@ call_at_line_check(VALUE context_obj, debug_context_t * dc, VALUE breakpoint,

/* TracePoint API event handlers */

static void
update_frame_dest(debug_context_t * dc)
{
dc->dest_frame = dc->calced_stack_size;
CTX_FL_UNSET(dc, CTX_FL_IGNORE_STEPS);
}

static void
line_event(VALUE trace_point, void *data)
{
Expand All @@ -281,14 +288,15 @@ line_event(VALUE trace_point, void *data)
if (RTEST(tracing))
call_at_tracing(context, dc, file, line);

dc->steps = dc->steps <= 0 ? -1 : dc->steps - 1;
if (!CTX_FL_TEST(dc, CTX_FL_IGNORE_STEPS))
{
dc->steps = dc->steps <= 0 ? -1 : dc->steps - 1;
}

if (dc->calced_stack_size <= dc->dest_frame)
{
update_frame_dest(dc);
dc->lines = dc->lines <= 0 ? -1 : dc->lines - 1;
if (dc->calced_stack_size < dc->dest_frame)
{
dc->dest_frame = dc->calced_stack_size;
}
}

if (dc->steps == 0 || dc->lines == 0
Expand All @@ -310,6 +318,11 @@ call_event(VALUE trace_point, void *data)

EVENT_SETUP;

if (dc->calced_stack_size <= dc->dest_frame)
{
update_frame_dest(dc);
}

dc->calced_stack_size++;

dc->steps_out = dc->steps_out <= 0 ? -1 : dc->steps_out + 1;
Expand Down
1 change: 1 addition & 0 deletions ext/byebug/byebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#define CTX_FL_TRACING (1<<4) /* call at_tracing method */
#define CTX_FL_WAS_RUNNING (1<<5) /* thread was previously running */
#define CTX_FL_STOP_ON_RET (1<<6) /* can stop on method 'end' */
#define CTX_FL_IGNORE_STEPS (1<<7) /* doesn't countdown steps to break */

/* macro functions */
#define CTX_FL_TEST(c,f) ((c)->flags & (f))
Expand Down
22 changes: 17 additions & 5 deletions ext/byebug/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,26 +385,38 @@ Context_stop_reason(VALUE self)

/*
* call-seq:
* context.step_into(steps)
* context.step_into(steps, frame = 0)
*
* Stops the current context after a number of +steps+ are made.
* Stops the current context after a number of +steps+ are made from frame
* +frame+ (by default the newest one).
*/
static VALUE
Context_step_into(int argc, VALUE * argv, VALUE self)
{
VALUE steps;
VALUE steps, v_frame;
int n_args, from_frame;
debug_context_t *context;

Data_Get_Struct(self, debug_context_t, context);

if (context->calced_stack_size == 0)
rb_raise(rb_eRuntimeError, "No frames collected.");

rb_scan_args(argc, argv, "10", &steps);
if (FIX2INT(steps) < 0)
n_args = rb_scan_args(argc, argv, "11", &steps, &v_frame);

if (FIX2INT(steps) <= 0)
rb_raise(rb_eRuntimeError, "Steps argument can't be negative.");

from_frame = n_args == 1 ? 0 : FIX2INT(v_frame);

if (from_frame < 0 || from_frame >= context->calced_stack_size)
rb_raise(rb_eRuntimeError, "Destination frame (%d) is out of range (%d)",
from_frame, context->calced_stack_size);
else if (from_frame > 0)
CTX_FL_SET(context, CTX_FL_IGNORE_STEPS);

context->steps = FIX2INT(steps);
context->dest_frame = context->calced_stack_size - from_frame;

return steps;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/byebug/commands/stepping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def execute
steps, err = parse_steps(@match[1], 'Steps')
return errmsg(err) unless steps

@state.context.step_into(steps)
@state.context.step_into(steps, @state.frame)
@state.proceed
end

Expand Down
24 changes: 17 additions & 7 deletions test/commands/stepping_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,24 +163,34 @@ def program
5: class #{example_class}
6: def a
7: byebug
8: r = b
8: r = b(c)
9: r + 1
10: end
11:
12: def b
12: def b(p)
13: r = 2
14: r + 1
14: p + r
15: end
16: end
17:
18: #{example_class}.new.a
19: end
16:
17: def c
18: s = 3
19: s + 2
20: end
21: end
22:
23: #{example_class}.new.a
24: end
EOC
end

def test_step_then_up_then_next_advances_in_the_upper_frame
enter 'step', 'up', 'next'
debug_code(program) { assert_equal 9, state.line }
end

def test_step_then_up_then_steps_in_from_the_upper_frame
enter 'step', 'up', 'step'
debug_code(program) { assert_equal 13, state.line }
end
end
end

0 comments on commit 88451b5

Please sign in to comment.