Skip to content

Commit 1a77218

Browse files
KristofferCtimholy
authored andcommitted
Use compiled mode when there is no chance we will encounter a breakpoint (#180)
1 parent 87314a4 commit 1a77218

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/commands.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,19 @@ function unwind_exception(frame::Frame, exc)
298298
rethrow(exc)
299299
end
300300

301+
const always_run_recursive_interpret = Ref(false)
302+
function any_active_breakpoint()
303+
for bp in _breakpoints
304+
if bp.isactive && bp.condition !== always_false
305+
return true
306+
end
307+
end
308+
return break_on_error[]
309+
end
310+
function run_in_compiled()
311+
return !any_active_breakpoint() && !always_run_recursive_interpret[]
312+
end
313+
301314
"""
302315
ret = debug_command(recurse, frame, cmd, rootistoplevel=false)
303316
ret = debug_command(frame, cmd, rootistoplevel=false)
@@ -319,6 +332,7 @@ or one of the 'advanced' commands
319332
`rootistoplevel` and `ret` are as described for [`JuliaInterpreter.maybe_reset_frame!`](@ref).
320333
"""
321334
function debug_command(@nospecialize(recurse), frame::Frame, cmd::Symbol, rootistoplevel::Bool=false)
335+
recurse = run_in_compiled() ? Compiled() : recurse
322336
istoplevel = rootistoplevel && frame.caller === nothing
323337
cmd0 = cmd
324338
if cmd == :si

test/debug.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ using JuliaInterpreter, Test
22
using JuliaInterpreter: enter_call, enter_call_expr, get_return, @lookup
33
using Base.Meta: isexpr
44

5+
# We want to test recursive interpretation
6+
JuliaInterpreter.always_run_recursive_interpret[] = true
7+
@test !JuliaInterpreter.run_in_compiled()
8+
59
const ALL_COMMANDS = (:n, :s, :c, :finish, :nc, :se, :si)
610

711
function step_through_command(fr::Frame, cmd::Symbol)
@@ -350,4 +354,18 @@ struct B{T} end
350354
@test debug_command(frame, :c) === nothing
351355
@test get_return(frame) == sum(a)
352356
end
357+
358+
@testset "compiled mode when no breakpoints" begin
359+
try
360+
JuliaInterpreter.always_run_recursive_interpret[] = false
361+
remove()
362+
@test JuliaInterpreter.run_in_compiled()
363+
fr = JuliaInterpreter.enter_call(sin, 2.0)
364+
JuliaInterpreter.debug_command(fr, :c)
365+
@test get_return(fr) == sin(2.0)
366+
finally
367+
JuliaInterpreter.always_run_recursive_interpret[] = true
368+
end
369+
end
370+
353371
# end

0 commit comments

Comments
 (0)