Skip to content

Commit

Permalink
Add ability to scope and stop only in certain stack frames. Fixes #558
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan Phoenix committed Nov 5, 2010
1 parent 2d843fd commit 0011b65
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 25 deletions.
39 changes: 23 additions & 16 deletions lib/debugger.rb
Expand Up @@ -130,28 +130,35 @@ def start(offset=0)
# stoping at a breakpoint.
#
def listen(step_into=false)
if @channel
if step_into
@channel << :step
else
@channel << true
while true
if @channel
if step_into
@channel << :step
else
@channel << true
end
end
end

# Wait for someone to stop
bp, thr, chan, locs = @local_channel.receive
# Wait for someone to stop
bp, thr, chan, locs = @local_channel.receive

# Uncache all frames since we stopped at a new place
@frames = []
# Uncache all frames since we stopped at a new place
@frames = []

@locations = locs
@breakpoint = bp
@debuggee_thread = thr
@channel = chan
@locations = locs
@breakpoint = bp
@debuggee_thread = thr
@channel = chan

@current_frame = frame(0)
@current_frame = frame(0)

bp.hit! if bp
if bp
# Only break out if the hit was valid
break if bp.hit!(locs.first)
else
break
end
end

puts
info "Breakpoint: #{@current_frame.describe}"
Expand Down
14 changes: 10 additions & 4 deletions lib/debugger/breakpoint.rb
Expand Up @@ -29,9 +29,9 @@ def describe
"#{descriptor} - #{location}"
end

def for_step!
def for_step!(scope)
@temp = true
@for_step = true
@for_step = scope
end

def set_temp!
Expand All @@ -58,12 +58,18 @@ def remove!
@method.clear_breakpoint(@ip)
end

def hit!
return unless @temp
def hit!(loc)
return true unless @temp

if @for_step
return false unless loc.variables == @for_step
end

remove!

@paired_bp.remove! if @paired_bp

return true
end

def delete!
Expand Down
10 changes: 5 additions & 5 deletions lib/debugger/commands.rb
Expand Up @@ -255,7 +255,7 @@ def step_to_parent
ip = f.ip

bp = BreakPoint.for_ip(exec, ip)
bp.for_step!
bp.for_step!(current_frame.variables)
bp.activate

return bp
Expand All @@ -273,8 +273,8 @@ def set_breakpoints_between(exec, start_ip, fin_ip)
bp1.paired_with(bp2)
bp2.paired_with(bp1)

bp1.for_step!
bp2.for_step!
bp1.for_step!(current_frame.variables)
bp2.for_step!(current_frame.variables)

bp1.activate
bp2.activate
Expand All @@ -288,7 +288,7 @@ def set_breakpoints_between(exec, start_ip, fin_ip)
end

bp = BreakPoint.for_ip(exec, ip)
bp.for_step!
bp.for_step!(current_frame.variables)
bp.activate

return bp
Expand Down Expand Up @@ -379,7 +379,7 @@ def run(args)
line = exec.line_from_ip(next_ip)

bp = BreakPoint.for_ip(exec, next_ip)
bp.for_step!
bp.for_step!(current_frame.variables)
bp.activate
end

Expand Down
4 changes: 4 additions & 0 deletions lib/debugger/frame.rb
Expand Up @@ -31,6 +31,10 @@ def ip
@location.ip
end

def variables
@location.variables
end

def local_variables
method.local_names
end
Expand Down

0 comments on commit 0011b65

Please sign in to comment.