Skip to content

Commit 23c26ff

Browse files
committed
Do not live track variables, instead retroactively workout what is define when a breakpoint is hit
1 parent 64e8d13 commit 23c26ff

File tree

4 files changed

+155
-159
lines changed

4 files changed

+155
-159
lines changed

src/MagneticReadHead.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ module MagneticReadHead
33
using Base: invokelatest
44
using Cassette
55
using MacroTools
6-
using OrderedCollections
76
using InteractiveUtils
87
using CodeTracking
98
# We don't use Revise, but if it isn't loaded CodeTracking has issues
109
using Revise: Revise
10+
using OrderedCollections
1111

12-
export @iron_debug
12+
export @iron_debug
1313

1414
include("utils.jl")
1515
include("method_utils.jl")
@@ -38,7 +38,6 @@ macro iron_debug(body)
3838
# Disable any stepping left-over
3939
ctx.metadata.stepping_mode = StepContinue()
4040
end
41-
4241
end
4342
end
4443

src/break_action.jl

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ end
2929
function breadcrumbs(io, file::AbstractString, line_num; nbefore=2, nafter=2)
3030
@assert(nbefore >= 0)
3131
@assert(nafter >= 0)
32-
32+
3333
all_lines = loc_for_file(file)
3434
first_line_num = max(1, line_num - nbefore)
3535
last_line_num = min(length(all_lines), line_num + nafter)
36-
36+
3737
for ln in first_line_num:last_line_num
3838
line = all_lines[ln]
3939
if ln == line_num
@@ -54,34 +54,36 @@ end
5454
# this function exists only for mocking so we can test it.
5555
breakpoint_hit(meth, statement_ind) = nothing
5656

57-
function iron_repl(metadata::HandEvalMeta, meth, statement_ind)
57+
function iron_repl(metadata::HandEvalMeta, meth, statement_ind, variables)
5858
breakpoint_hit(meth, statement_ind)
5959
breadcrumbs(meth, statement_ind)
60-
60+
6161
printstyled("Vars: "; color=:light_yellow)
62-
println(join(keys(metadata.variables), ", "))
62+
println(join(keys(variables), ", "))
6363
print_commands()
64-
65-
run_repl(metadata.variables, metadata.eval_module)
66-
end
6764

65+
run_repl(variables, metadata.eval_module)
66+
end
6867

6968
"""
70-
break_action(metadata, meth, statement_ind)
69+
should_breakon
70+
Determines if we should actualy break at a potential breakpoint
71+
"""
72+
function should_break(ctx, meth, statement_ind)
73+
return ctx.metadata.stepping_mode isa StepNext ||
74+
should_breakon(ctx.metadata.breakpoint_rules, meth, statement_ind)
75+
end
76+
7177

72-
This determines what we should do when we hit a potential point to break at.
73-
We check if we should actually break here,
74-
and if so open up a REPL.
75-
if not, then we continue.
7678
"""
77-
function break_action(metadata, meth, statement_ind)
78-
if !(metadata.stepping_mode isa StepNext
79-
|| should_breakon(metadata.breakpoint_rules, meth, statement_ind)
80-
)
81-
# Only break on StepNext and actual breakpoints
82-
return
83-
end
79+
break_action
8480
85-
code_word = iron_repl(metadata, meth, statement_ind)
81+
What to do when a breakpoint is hit
82+
"""
83+
function break_action(ctx, meth, statement_ind, slotnames, slotvals)
84+
metadata = ctx.metadata
85+
# TODO we probably need to drop the first few slots as they will contain various metadata
86+
variables = LittleDict(slotnames, slotvals)
87+
code_word = iron_repl(metadata, meth, statement_ind, variables)
8688
actions[code_word].act(metadata)
8789
end

src/core_control.jl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,16 @@ parent_stepping_mode(::StepOut) = StepNext() # This is what they want
2323

2424

2525
mutable struct HandEvalMeta
26-
variables::LittleDict{Symbol, Any}
2726
eval_module::Module
2827
stepping_mode::SteppingMode
2928
breakpoint_rules::BreakpointRules
3029
end
3130

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

3534
function HandEvalMeta(eval_module, stepping_mode)
3635
return HandEvalMeta(
37-
LittleDict{Symbol,Any}(),
3836
eval_module,
3937
stepping_mode,
4038
GLOBAL_BREAKPOINT_RULES
@@ -55,21 +53,23 @@ function Cassette.overdub(ctx::HandEvalCtx, @nospecialize(f), @nospecialize(args
5553
# This is basically the epicenter of all the logic
5654
# We control the flow of stepping modes
5755
# and which methods are instrumented or not.
58-
method = methodof(f, args...)
59-
should_recurse =
60-
ctx.metadata.stepping_mode isa StepIn ||
61-
should_instrument(ctx.metadata.breakpoint_rules, method)
56+
# method = methodof(f, args...)
57+
should_recurse = true
58+
#ctx.metadata.stepping_mode isa StepIn ||
59+
# should_instrument(ctx.metadata.breakpoint_rules, method)
6260

6361
if should_recurse
6462
if Cassette.canrecurse(ctx, f, args...)
65-
_ctx = HandEvalCtx(ctx.metadata.eval_module, child_stepping_mode(ctx))
63+
# TODO: Workout this logic
64+
#_ctx = HandEvalCtx(ctx.metadata.eval_module, child_stepping_mode(ctx))
6665
try
67-
return Cassette.recurse(_ctx, f, args...)
66+
return Cassette.recurse(ctx, f, args...)
6867
finally
69-
ctx.metadata.stepping_mode = parent_stepping_mode(_ctx)
68+
# TODO: workout this logic
69+
#ctx.metadata.stepping_mode = parent_stepping_mode(ctx)
7070
end
7171
else
72-
@warn "Not able to enter into method." f method
72+
# @warn "Not able to enter into method." f method
7373
return Cassette.fallback(ctx, f, args...)
7474
end
7575
else # !should_recurse

0 commit comments

Comments
 (0)