Skip to content

Commit a3cb3e6

Browse files
authored
Merge branch 'master' into teh/fix_161
2 parents 46e5452 + d486348 commit a3cb3e6

File tree

7 files changed

+152
-112
lines changed

7 files changed

+152
-112
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "JuliaInterpreter"
22
uuid = "aa1ae85d-cabe-5617-a682-6adf51b2e16a"
3-
version = "0.1.1"
3+
version = "0.2.0"
44

55
[deps]
66
CodeTracking = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2"

docs/src/dev_reference.md

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ breakpoint
6060
enable
6161
disable
6262
remove
63+
break_on
64+
break_off
6365
JuliaInterpreter.dummy_breakpoint
6466
```
6567

src/JuliaInterpreter.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ using CodeTracking
1414

1515
export @interpret, Compiled, Frame, root, leaf,
1616
BreakpointRef, breakpoint, @breakpoint, breakpoints, enable, disable, remove,
17-
debug_command, @bp
17+
debug_command, @bp, break_on, break_off
1818

1919
module CompiledCalls
2020
# This module is for handling intrinsics that must be compiled (llvmcall)

src/breakpoints.jl

+34
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,40 @@ function remove()
129129
return nothing
130130
end
131131

132+
"""
133+
break_on(states...)
134+
135+
Turn on automatic breakpoints when any of the conditions described in `states` occurs.
136+
The supported states are:
137+
138+
- `:error`: trigger a breakpoint any time an uncaught exception is thrown
139+
"""
140+
function break_on(states::Vararg{Symbol})
141+
for state in states
142+
if state == :error
143+
break_on_error[] = true
144+
else
145+
throw(ArgumentError(string("unsupported state :", state)))
146+
end
147+
end
148+
end
149+
150+
"""
151+
break_off(states...)
152+
153+
Turn off automatic breakpoints when any of the conditions described in `states` occurs.
154+
See [`break_on`](@ref) for a description of valid states.
155+
"""
156+
function break_off(states::Vararg{Symbol})
157+
for state in states
158+
if state == :error
159+
break_on_error[] = false
160+
else
161+
throw(ArgumentError(string("unsupported state :", state)))
162+
end
163+
end
164+
end
165+
132166
"""
133167
breakpoint(f, sig)
134168
breakpoint(f, sig, line)

src/commands.jl

+24-24
Original file line numberDiff line numberDiff line change
@@ -297,38 +297,38 @@ end
297297
298298
Perform one "debugger" command. `cmd` should be one of:
299299
300-
- "n": advance to the next line
301-
- "s": step into the next call
302-
- "c": continue execution until termination or reaching a breakpoint
303-
- "finish": finish the current frame and return to the parent
300+
- `:n`: advance to the next line
301+
- `:s`: step into the next call
302+
- `:c`: continue execution until termination or reaching a breakpoint
303+
- `:finish`: finish the current frame and return to the parent
304304
305305
or one of the 'advanced' commands
306306
307-
- "nc": step forward to the next call
308-
- "se": execute a single statement
309-
- "si": execute a single statement, stepping in if it's a call
310-
- "sg": step into the generator of a generated function
307+
- `:nc`: step forward to the next call
308+
- `:se`: execute a single statement
309+
- `:si`: execute a single statement, stepping in if it's a call
310+
- `:sg`: step into the generator of a generated function
311311
312312
`rootistoplevel` and `ret` are as described for [`JuliaInterpreter.maybe_reset_frame!`](@ref).
313313
"""
314-
function debug_command(@nospecialize(recurse), frame::Frame, cmd::AbstractString, rootistoplevel::Bool=false)
314+
function debug_command(@nospecialize(recurse), frame::Frame, cmd::Symbol, rootistoplevel::Bool=false)
315315
istoplevel = rootistoplevel && frame.caller === nothing
316316
cmd0 = cmd
317-
if cmd == "si"
317+
if cmd == :si
318318
stmt = pc_expr(frame)
319-
cmd = is_call(stmt) ? "s" : "se"
319+
cmd = is_call(stmt) ? :s : :se
320320
end
321321
try
322-
cmd == "nc" && return maybe_reset_frame!(recurse, frame, next_call!(recurse, frame, istoplevel), rootistoplevel)
323-
cmd == "n" && return maybe_reset_frame!(recurse, frame, next_line!(recurse, frame, istoplevel), rootistoplevel)
324-
cmd == "se" && return maybe_reset_frame!(recurse, frame, step_expr!(recurse, frame, istoplevel), rootistoplevel)
322+
cmd == :nc && return maybe_reset_frame!(recurse, frame, next_call!(recurse, frame, istoplevel), rootistoplevel)
323+
cmd == :n && return maybe_reset_frame!(recurse, frame, next_line!(recurse, frame, istoplevel), rootistoplevel)
324+
cmd == :se && return maybe_reset_frame!(recurse, frame, step_expr!(recurse, frame, istoplevel), rootistoplevel)
325325

326326
enter_generated = false
327-
if cmd == "sg"
327+
if cmd == :sg
328328
enter_generated = true
329-
cmd = "s"
329+
cmd = :s
330330
end
331-
if cmd == "s"
331+
if cmd == :s
332332
pc = maybe_next_call!(recurse, frame, istoplevel)
333333
(isa(pc, BreakpointRef) || pc === nothing) && return maybe_reset_frame!(recurse, frame, pc, rootistoplevel)
334334
stmt0 = stmt = pc_expr(frame, pc)
@@ -345,7 +345,7 @@ function debug_command(@nospecialize(recurse), frame::Frame, cmd::AbstractString
345345
end
346346
if isa(ret, BreakpointRef)
347347
newframe = leaf(frame)
348-
cmd0 == "si" && return newframe, ret
348+
cmd0 == :si && return newframe, ret
349349
newframe = maybe_step_through_wrapper!(recurse, newframe)
350350
return newframe, BreakpointRef(newframe.framecode, 0)
351351
end
@@ -354,21 +354,21 @@ function debug_command(@nospecialize(recurse), frame::Frame, cmd::AbstractString
354354
frame.pc += 1
355355
return frame, frame.pc
356356
end
357-
if cmd == "c"
357+
if cmd == :c
358358
r = root(frame)
359359
ret = finish_stack!(recurse, r, rootistoplevel)
360360
return isa(ret, BreakpointRef) ? (leaf(r), ret) : nothing
361361
end
362-
cmd == "finish" && return maybe_reset_frame!(recurse, frame, finish!(recurse, frame, istoplevel), rootistoplevel)
362+
cmd == :finish && return maybe_reset_frame!(recurse, frame, finish!(recurse, frame, istoplevel), rootistoplevel)
363363
catch err
364364
frame = unwind_exception(frame, err)
365-
if cmd == "c"
366-
return debug_command(recurse, frame, "c", istoplevel)
365+
if cmd == :c
366+
return debug_command(recurse, frame, :c, istoplevel)
367367
else
368-
return debug_command(recurse, frame, "nc", istoplevel)
368+
return debug_command(recurse, frame, :nc, istoplevel)
369369
end
370370
end
371371
throw(ArgumentError("command $cmd not recognized"))
372372
end
373-
debug_command(frame::Frame, cmd::AbstractString, rootistoplevel::Bool=false) =
373+
debug_command(frame::Frame, cmd::Symbol, rootistoplevel::Bool=false) =
374374
debug_command(finish_and_return!, frame, cmd, rootistoplevel)

test/breakpoints.jl

+3-2
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ end
130130

131131
# break on error
132132
try
133-
JuliaInterpreter.break_on_error[] = true
133+
@test_throws ArgumentError("unsupported state :missing") break_on(:missing)
134+
break_on(:error)
134135

135136
inner(x) = error("oops")
136137
outer() = inner(1)
@@ -158,7 +159,7 @@ end
158159
@test v isa ErrorException
159160
@test stacklength(frame) == 1
160161
finally
161-
JuliaInterpreter.break_on_error[] = false
162+
break_off(:error)
162163
end
163164

164165
# Breakpoint display

0 commit comments

Comments
 (0)