Skip to content

Commit

Permalink
Add finish+ to step one in calling method rather than stop before met…
Browse files Browse the repository at this point in the history
…hod return.
  • Loading branch information
rocky committed Dec 27, 2010
1 parent 9d9b214 commit 310e391
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 27 deletions.
36 changes: 19 additions & 17 deletions processor/command/finish.rb
Expand Up @@ -8,25 +8,27 @@ class Trepan::Command::FinishCommand < Trepan::Command
unless defined?(HELP)
NAME = File.basename(__FILE__, '.rb')
HELP = <<-HELP
#{NAME} [levels]
#{NAME}
#{NAME}+
Continue execution until leaving the current function.
Sometimes this is called 'step out'.
Continue execution until leaving the current method. Sometimes this
is called 'step out'.
When `levels' is specified, that many frame levels need to be
popped. The default is 1. Note that 'yield' and exceptions raised my
reduce the number of stack frames. Also, if a thread is switched, we
stop ignoring levels.
Normally, stopping occurs just before the return on or yield out of a
method. However sometimes one wants go to the calling method or place
just beyond the current method.For this, suffix the command or an
alias of it with a plus sign. The disadvantange of this is that you
will no longer be in the scope of the method and so you won't be able
to see variables of that method.
'next>' is similar in that it stops at a return, but it doesn't
guarantee the stack level is the same as or less than the current
one.
Examples:
#{NAME}
#{NAME}+
See the break command if you want to stop at a particular point in a
program. In general, '#{NAME}', 'step' and 'next' may slow a program down
while 'break' will have less overhead.
See also commands:
'continue', 'break', 'next', 'nexti', 'step' for other ways to continue.
HELP
ALIASES = %w(fin)
ALIASES = %w(fin finish+ fin+)
CATEGORY = 'running'
# execution_set = ['Running']
MAX_ARGS = 1 # Need at most this many.
Expand All @@ -36,19 +38,19 @@ class Trepan::Command::FinishCommand < Trepan::Command

# This method runs the command
def run(args) # :nodoc
opts = {}
opts = @proc.parse_next_step_suffix(args[0])
if args.size == 1
# Form is: "finish" which means "finish 1"
level_count = 0
else
count_str = args[1]
opts = {
count_opts = {
:msg_on_error =>
"The '#{NAME}' command argument must eval to an integer. Got: %s" %
count_str,
:min_value => 1
}
count = @proc.get_an_int(count_str, opts)
count = @proc.get_an_int(count_str, count_opts)
return unless count
# step 1 is core.level_count = 0 or "stop next event"
level_count = count - 1
Expand Down
2 changes: 1 addition & 1 deletion processor/command/step.rb
Expand Up @@ -55,7 +55,7 @@ def run(args)
return cmd.run([replace_cmd] + args[2..-1])
else
step_str = args[1]
opts = @proc.parse_next_step_suffix(step_str)
opts = @proc.parse_next_step_suffix(args[0])
count_opts = {
:msg_on_error =>
"The #{NAME} command argument must eval to an integer. Got: %s" %
Expand Down
2 changes: 1 addition & 1 deletion processor/main.rb
Expand Up @@ -257,7 +257,7 @@ def process_commands
end
if @return_to_program
after_cmdloop
if @step_count >= 0
if @step_count >= 0 && 'finish' != @return_to_program
@step_bp = step_over_by(1)
run_command('disassemble') if settings[:debugstep]
dbgr.listen('step' == @return_to_program)
Expand Down
20 changes: 12 additions & 8 deletions processor/running.rb
Expand Up @@ -34,14 +34,14 @@ class CmdProcessor
# # execution.
# # FIXME: turn line_number into a condition.

def continue(how_to_continue)
def continue(return_to_program)
@next_thread = nil
@step_count = -1 # No more event stepping
if 'step-finish' == how_to_continue
if 'step-finish' == return_to_program
step_to_return_or_yield
how_to_continue = 'step'
return_to_program = 'step'
end
@return_to_program = how_to_continue
@return_to_program = return_to_program
end

# Does whatever setup needs to be done to set to ignore stepping
Expand All @@ -52,6 +52,8 @@ def finish(level_count=0, opts={})
continue('finish')
@next_thread = @current_thread

@step_count = 2 if 'nostack' == opts[:different_pos]

# # Try high-speed (run-time-assisted) method
# @frame.trace_off = true # No more tracing in this frame
# @frame.return_stop = true # don't need to
Expand All @@ -72,8 +74,8 @@ def step_finish

# Does whatever needs to be done to set to step program
# execution.
def step(how_to_continue, step_count=1, opts={}, condition=nil)
continue(how_to_continue)
def step(return_to_program, step_count=1, opts={}, condition=nil)
continue(return_to_program)
@step_count = step_count
@different_pos = opts[:different_pos] if
opts.keys.member?(:different_pos)
Expand Down Expand Up @@ -167,7 +169,7 @@ def stepping_skip?
end

# Only skip on these kinds of events
unless %w(step-call line).include?(@event)
unless %w(step-call line return).include?(@event)
msg "skip non-line: #{@event} #{debug_loc}" if @settings[:debugskip]
return false
end
Expand All @@ -187,6 +189,7 @@ def stepping_skip?
msg("last: #{@last_pos.inspect}, ")
msg("new: #{new_pos.inspect}")
msg("skip: #{should_skip.inspect}, event: #{@event}")
msg("@step_count: #{@step_count}")
end

@last_pos[2] = new_pos[2] if 'nostack' == @different_pos
Expand Down Expand Up @@ -222,7 +225,8 @@ def stepping_skip?
# @stop_events = nil
end

@return_to_program = 'step' if should_skip && !@return_to_program
@return_to_program = 'step' if should_skip &&
(!@return_to_program || 'finish' == @return_to_program)
return should_skip
end

Expand Down

0 comments on commit 310e391

Please sign in to comment.