Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: refactor breakpoints #259

Merged
merged 15 commits into from May 13, 2019
5 changes: 5 additions & 0 deletions docs/src/dev_reference.md
Expand Up @@ -63,8 +63,10 @@ breakpoint
enable
disable
remove
toggle
break_on
break_off
breakpoints
JuliaInterpreter.dummy_breakpoint
```

Expand All @@ -77,6 +79,9 @@ JuliaInterpreter.FrameData
JuliaInterpreter.FrameInstance
JuliaInterpreter.BreakpointState
JuliaInterpreter.BreakpointRef
JuliaInterpreter.AbstractBreakpoint
JuliaInterpreter.BreakpointSignature
JuliaInterpreter.BreakpointFileLocation
```

## Internal storage
Expand Down
13 changes: 5 additions & 8 deletions docs/src/index.md
Expand Up @@ -29,7 +29,7 @@ julia> @interpret sum(list)

You can interrupt execution by setting breakpoints.
You can set breakpoints via packages that explicitly target debugging,
like [Juno](http://junolab.org/), [Debugger](https://github.com/JuliaDebug/Debugger.jl), and
like [Juno](https://junolab.org/), [Debugger](https://github.com/JuliaDebug/Debugger.jl), and
[Rebugger](https://github.com/timholy/Rebugger.jl).
But all of these just leverage the core functionality defined in JuliaInterpreter,
so here we'll illustrate it without using any of these other packages.
Expand All @@ -38,8 +38,7 @@ Let's set a conditional breakpoint, to be triggered any time one of the elements
argument to `sum` is bigger than 4:

```jldoctest demo1; filter = r"in Base at .*$"
julia> @breakpoint sum([1, 2]) any(x->x>4, a)
breakpoint(sum(a::AbstractArray) in Base at reducedim.jl:648, line 648)
julia> bp = @breakpoint sum([1, 2]) any(x->x>4, a);
```

Note that in writing the condition, we used `a`, the name of the argument to the relevant
Expand All @@ -53,7 +52,7 @@ Now let's see what happens:
julia> @interpret sum([1,2,3]) # no element bigger than 4, breakpoint should not trigger
6

julia> frame, bp = @interpret sum([1,2,5]) # should trigger breakpoint
julia> frame, bpref = @interpret sum([1,2,5]) # should trigger breakpoint
(Frame for sum(a::AbstractArray) in Base at reducedim.jl:648
c 1* 648 1 ─ nothing
2 648 │ %2 = (Base.#sum#550)(Colon(), #self#, a)
Expand All @@ -63,18 +62,16 @@ a = [1, 2, 5], breakpoint(sum(a::AbstractArray) in Base at reducedim.jl:648, lin

`frame` is described in more detail on the next page; for now, suffice it to say
that the `c` in the leftmost column indicates the presence of a conditional breakpoint
upon entry to `sum`. `bp` is a reference to the breakpoint. You can manipulate these
at the command line:
upon entry to `sum`. `bpref` is a reference to the breakpoint of type [`BreakpointRef`](@ref).
The breakpoint `bp` we created can be manipulated at the command line

```jldoctest demo1; filter = r"in Base at .*$"
julia> disable(bp)
false

julia> @interpret sum([1,2,5])
8

julia> enable(bp)
true

julia> @interpret sum([1,2,5])
(Frame for sum(a::AbstractArray) in Base at reducedim.jl:648
Expand Down
9 changes: 8 additions & 1 deletion src/JuliaInterpreter.jl
Expand Up @@ -14,7 +14,7 @@ using InteractiveUtils
using CodeTracking

export @interpret, Compiled, Frame, root, leaf,
BreakpointRef, breakpoint, @breakpoint, breakpoints, enable, disable, remove,
BreakpointRef, breakpoint, @breakpoint, breakpoints, enable, disable, remove, toggle,
debug_command, @bp, break_on, break_off

module CompiledCalls
Expand All @@ -39,6 +39,9 @@ include("commands.jl")
include("breakpoints.jl")

function set_compiled_methods()
###########
# Methods #
###########
# Work around #28 by preventing interpretation of all Base methods that have a ccall to memcpy
push!(compiled_methods, which(vcat, (Vector,)))
push!(compiled_methods, first(methods(Base._getindex_ra)))
Expand Down Expand Up @@ -69,6 +72,7 @@ function set_compiled_methods()
# These are currently extremely slow to interpret (https://github.com/JuliaDebug/JuliaInterpreter.jl/issues/193)
push!(compiled_methods, which(subtypes, Tuple{Module, Type}))
push!(compiled_methods, which(subtypes, Tuple{Type}))
push!(compiled_methods, which(match, Tuple{Regex, String, Int, UInt32}))

# Anything that ccalls jl_typeinf_begin cannot currently be handled
for finf in (Core.Compiler.typeinf_code, Core.Compiler.typeinf_ext, Core.Compiler.typeinf_type)
Expand All @@ -77,6 +81,9 @@ function set_compiled_methods()
end
end

###########
# Modules #
###########
push!(compiled_modules, Base.Threads)
end

Expand Down