Skip to content

Commit

Permalink
Implement step over.
Browse files Browse the repository at this point in the history
It takes care to try and do the right thing in the case of recursion,
and recognizes when you step to a stack frame below the one you were
doing a step over in, so it will pause just outside of it.
  • Loading branch information
jnthn committed Oct 11, 2012
1 parent 62d9a65 commit 9bec898
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion lib/Debugger/UI/CommandLine.pm
Expand Up @@ -197,13 +197,14 @@ my class SourceFile {

# Holds the current state of the debugger.
my class DebugState {
my enum RunMode <Step StepOut RunToThrowOrBreakpoint RunToUnhandledOrBreakpoint>;
my enum RunMode <Step StepOver StepOut RunToThrowOrBreakpoint RunToUnhandledOrBreakpoint>;
my RunMode $run_mode = Step;
my Bool $dying = False;
my Bool $in_prompt = False;
my %breakpoints;
my $cur_ex;
my %stepping_out_of;
my %stepping_over_in;

method set_current_exception($ex) {
$cur_ex = $ex;
Expand Down Expand Up @@ -271,6 +272,22 @@ my class DebugState {
when Step {
True
}
when StepOver {
ENTER $in_prompt = True;
LEAVE $in_prompt = False;
my $depth = +lines(Backtrace.new().full) - 1;
if $depth < %stepping_over_in<depth> ||
$filename eq %stepping_over_in<file> &&
%sources{$filename}.routine_containing($from, $to) eq %stepping_over_in<routine> &&
$depth == %stepping_over_in<depth> {
$run_mode = Step;
%stepping_over_in = ();
True
}
else {
False
}
}
when StepOut {
if $filename ne %stepping_out_of<file> ||
%sources{$filename}.routine_containing($from, $to) ne %stepping_out_of<routine> {
Expand Down Expand Up @@ -370,6 +387,20 @@ my class DebugState {
return;
}
}
when 's' {
if $dying {
self.complain_about_being_dying();
}
else {
my $cur_routine = %sources{$cur_file}.routine_containing($from, $to);
$run_mode = StepOver;
%stepping_over_in =
file => $cur_file,
routine => $cur_routine,
depth => +lines(Backtrace.new().full) - 4;
return;
}
}
when 'so' {
if $dying {
self.complain_about_being_dying();
Expand Down Expand Up @@ -434,6 +465,7 @@ my class DebugState {
method usage() {
join "\n",
('<enter> single step, stepping into any calls' unless $dying),
('s step to next statement, stepping over any calls' unless $dying),
('so step out of the current routine' unless $dying),
('r run until the next breakpoint or unhnadled exception' unless $dying),
('rt run until the next breakpoint or an exception is thrown' unless $dying),
Expand Down

0 comments on commit 9bec898

Please sign in to comment.