Skip to content

Commit

Permalink
Do not live track variables, instead retroactively workout what is de…
Browse files Browse the repository at this point in the history
…fine when a breakpoint is hit
  • Loading branch information
oxinabox committed Apr 22, 2019
1 parent 64e8d13 commit 23c26ff
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 159 deletions.
5 changes: 2 additions & 3 deletions src/MagneticReadHead.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ module MagneticReadHead
using Base: invokelatest
using Cassette
using MacroTools
using OrderedCollections
using InteractiveUtils
using CodeTracking
# We don't use Revise, but if it isn't loaded CodeTracking has issues
using Revise: Revise
using OrderedCollections

export @iron_debug
export @iron_debug

include("utils.jl")
include("method_utils.jl")
Expand Down Expand Up @@ -38,7 +38,6 @@ macro iron_debug(body)
# Disable any stepping left-over
ctx.metadata.stepping_mode = StepContinue()
end

end
end

Expand Down
44 changes: 23 additions & 21 deletions src/break_action.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ end
function breadcrumbs(io, file::AbstractString, line_num; nbefore=2, nafter=2)
@assert(nbefore >= 0)
@assert(nafter >= 0)

all_lines = loc_for_file(file)
first_line_num = max(1, line_num - nbefore)
last_line_num = min(length(all_lines), line_num + nafter)

for ln in first_line_num:last_line_num
line = all_lines[ln]
if ln == line_num
Expand All @@ -54,34 +54,36 @@ end
# this function exists only for mocking so we can test it.
breakpoint_hit(meth, statement_ind) = nothing

function iron_repl(metadata::HandEvalMeta, meth, statement_ind)
function iron_repl(metadata::HandEvalMeta, meth, statement_ind, variables)
breakpoint_hit(meth, statement_ind)
breadcrumbs(meth, statement_ind)

printstyled("Vars: "; color=:light_yellow)
println(join(keys(metadata.variables), ", "))
println(join(keys(variables), ", "))
print_commands()

run_repl(metadata.variables, metadata.eval_module)
end

run_repl(variables, metadata.eval_module)
end

"""
break_action(metadata, meth, statement_ind)
should_breakon
Determines if we should actualy break at a potential breakpoint
"""
function should_break(ctx, meth, statement_ind)
return ctx.metadata.stepping_mode isa StepNext ||
should_breakon(ctx.metadata.breakpoint_rules, meth, statement_ind)
end


This determines what we should do when we hit a potential point to break at.
We check if we should actually break here,
and if so open up a REPL.
if not, then we continue.
"""
function break_action(metadata, meth, statement_ind)
if !(metadata.stepping_mode isa StepNext
|| should_breakon(metadata.breakpoint_rules, meth, statement_ind)
)
# Only break on StepNext and actual breakpoints
return
end
break_action
code_word = iron_repl(metadata, meth, statement_ind)
What to do when a breakpoint is hit
"""
function break_action(ctx, meth, statement_ind, slotnames, slotvals)
metadata = ctx.metadata
# TODO we probably need to drop the first few slots as they will contain various metadata
variables = LittleDict(slotnames, slotvals)
code_word = iron_repl(metadata, meth, statement_ind, variables)
actions[code_word].act(metadata)
end
22 changes: 11 additions & 11 deletions src/core_control.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,16 @@ parent_stepping_mode(::StepOut) = StepNext() # This is what they want


mutable struct HandEvalMeta
variables::LittleDict{Symbol, Any}
eval_module::Module
stepping_mode::SteppingMode
breakpoint_rules::BreakpointRules
end

# TODO: Workout how we are actually going to do this in a nonglobal way
# TODO: Workout how and if we are actually going to do this in a nonglobal way
const GLOBAL_BREAKPOINT_RULES = BreakpointRules()

function HandEvalMeta(eval_module, stepping_mode)
return HandEvalMeta(
LittleDict{Symbol,Any}(),
eval_module,
stepping_mode,
GLOBAL_BREAKPOINT_RULES
Expand All @@ -55,21 +53,23 @@ function Cassette.overdub(ctx::HandEvalCtx, @nospecialize(f), @nospecialize(args
# This is basically the epicenter of all the logic
# We control the flow of stepping modes
# and which methods are instrumented or not.
method = methodof(f, args...)
should_recurse =
ctx.metadata.stepping_mode isa StepIn ||
should_instrument(ctx.metadata.breakpoint_rules, method)
# method = methodof(f, args...)
should_recurse = true
#ctx.metadata.stepping_mode isa StepIn ||
# should_instrument(ctx.metadata.breakpoint_rules, method)

if should_recurse
if Cassette.canrecurse(ctx, f, args...)
_ctx = HandEvalCtx(ctx.metadata.eval_module, child_stepping_mode(ctx))
# TODO: Workout this logic
#_ctx = HandEvalCtx(ctx.metadata.eval_module, child_stepping_mode(ctx))
try
return Cassette.recurse(_ctx, f, args...)
return Cassette.recurse(ctx, f, args...)
finally
ctx.metadata.stepping_mode = parent_stepping_mode(_ctx)
# TODO: workout this logic
#ctx.metadata.stepping_mode = parent_stepping_mode(ctx)
end
else
@warn "Not able to enter into method." f method
# @warn "Not able to enter into method." f method
return Cassette.fallback(ctx, f, args...)
end
else # !should_recurse
Expand Down
Loading

0 comments on commit 23c26ff

Please sign in to comment.