Skip to content

Commit

Permalink
Merge pull request #64 from oxinabox/ox/noselfbreak
Browse files Browse the repository at this point in the history
Make @Enter not go into the Debugger source.
  • Loading branch information
oxinabox authored Jul 14, 2019
2 parents ac86370 + 908a57c commit f60c606
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 7 deletions.
22 changes: 17 additions & 5 deletions src/MagneticReadHead.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,23 @@ end
Begin debugging and break on the start of the_code.
"""
macro enter(body)
quote
ctx = HandEvalCtx($(__module__), StepContinue)
iron_debug(ctx) do
ctx.metadata.stepping_mode = StepIn
$(esc(body))
if body isa Expr && body.head==:call && body.args[1] isa Symbol
body = MacroTools.striplines(body)
break_target = :(InteractiveUtils.which($(body.args[1]), Base.typesof($(body.args[2:end])...)))
quote
ctx = HandEvalCtx($(__module__), StepContinue)
set_breakpoint!($(esc(break_target)))
try
iron_debug(ctx) do
$(esc(body))
end
finally
rm_breakpoint!($(esc(break_target)))
end
end
else
quote
error("Expression too complex to `@enter`. Please use `@run` with manual breakpoint set")
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions src/breakpoints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ for (name, list) in ((:breakpoint, :breakon_rules), (:uninstrumented, :no_instru
@eval function $(rm!)(the_rules::BreakpointRules, args...)
old_num_rules = length(the_rules.$list)
to_remove = rules(args...)
filter!(x->xto_remove, the_rules.$list)
filter!(!in(to_remove), the_rules.$list)
if length(the_rules.$list) == old_num_rules
@info("No matching $($name) was found, so none removed")
@info("No matching rule was found, so none removed")
end
return the_rules.$list
end
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ test_files = (
"test_behavour.jl",
"test_breadcrumbs.jl",
"test_breakpoint_rules.jl",
"test_breakpoints.jl",
"test_inner_repl.jl",
"test_locate.jl",
"test_method_utils.jl",
Expand Down
10 changes: 10 additions & 0 deletions test/test_breakpoints.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using MagneticReadHead
using Test

@testset "Should be able to add and remove breakpoints" begin
@test length(set_breakpoint!(Test)) == 1
@test length(rm_breakpoint!(Test)) == 0

@test length(set_uninstrumented!(Test)) == 1
@test length(rm_uninstrumented!(Test)) == 0
end
22 changes: 22 additions & 0 deletions test/test_ui.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,28 @@ clear_breakpoints!(); clear_uninstrumenteds!()
@test first.(record) == [eg2, eg2, eg2]
#end

###############################################

clear_breakpoints!(); clear_uninstrumenteds!()
#@testset "@enter" begin
make_readline_patch(["CC"])
record = make_recording_breakpoint_hit_patch()

@enter eg1()
@test first.(record) == [eg1]
@test isempty(list_breakpoints())
#end

clear_breakpoints!(); clear_uninstrumenteds!()
#@testset "@enter, too complex" begin
make_readline_patch(["CC"])
record = make_recording_breakpoint_hit_patch()

@test_throws ErrorException (@enter (()->eg1())())
@test isempty(list_breakpoints())
#end



###############################################
clear_breakpoints!(); clear_uninstrumenteds!()
Expand Down

0 comments on commit f60c606

Please sign in to comment.