Skip to content

Commit

Permalink
Merge pull request #117 from JuliaDebug/sp/infiltry-tests
Browse files Browse the repository at this point in the history
chore: infiltry tests, docs, improvements
  • Loading branch information
pfitzseb authored Apr 8, 2024
2 parents d411f15 + 542666c commit 9b0d328
Show file tree
Hide file tree
Showing 23 changed files with 896 additions and 12 deletions.
1 change: 1 addition & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ jobs:
- uses: codecov/codecov-action@v4
with:
file: lcov.info
token: ${{ secrets.CODECOV_TOKEN }}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ infil> ?

@locals: Print local variables. @locals x y only prints x and y.

@exception: Print the exception that triggered the current @infiltry session, if any.

@exfiltrate: Save all local variables into the store. @exfiltrate x y saves x and y; this variant can also exfiltrate variables defined in the infil> REPL.

@toggle: Toggle infiltrating at this @infiltrate spot (clear all with Infiltrator.clear_disabled!()).
Expand Down
1 change: 1 addition & 0 deletions docs/src/API/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This means that you'll need to use [Revise.jl](https://github.com/timholy/Revise
in VS Code, or just plain old `@eval` to apply `@infiltrate` statements in your package code.
```@docs
@infiltrate
@infiltry
infiltrate
@exfiltrate
```
Expand Down
42 changes: 30 additions & 12 deletions src/Infiltrator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ using REPL.LineEdit: getproperty
using REPL.LineEdit
using Markdown

export @infiltrate, @exfiltrate, @withstore, safehouse, exfiltrated, infiltrate
export @infiltrate, @infiltry, @exfiltrate, @withstore, safehouse, exfiltrated, infiltrate

const REPL_HOOKED = Ref{Bool}(false)
const INFILTRATION_LOCK = Ref{ReentrantLock}()
Expand Down Expand Up @@ -117,12 +117,12 @@ Equivalent to:
@infiltrate
end
"""
macro infiltry(ex)
macro infiltry(expr)
return quote
try
$(esc(ex))
catch
$(Infiltrator.start_prompt)($(__module__), Base.@locals, $(String(__source__.file)), $(__source__.line))
$(esc(expr))
catch ex
$(Infiltrator.start_prompt)($(__module__), Base.@locals, $(String(__source__.file)), $(__source__.line), ex, catch_backtrace())
end
end
end
Expand Down Expand Up @@ -265,7 +265,7 @@ function set_store!(s::Session, m::Module)
nothing
end

function start_prompt(mod, locals, file, fileline;
function start_prompt(mod, locals, file, fileline, ex = nothing, bt = nothing;
terminal = TEST_TERMINAL_REF[],
repl = TEST_REPL_REF[],
nostack = TEST_NOSTACK[]
Expand Down Expand Up @@ -299,6 +299,7 @@ function start_prompt(mod, locals, file, fileline;
last = something(findfirst(x -> x.func === StackTraces.top_level_scope_sym, trace),
length(trace))
trace = trace[start:last]
bt = bt === nothing ? nothing : crop_backtrace(bt)

if CHECK_TASK[] && !active_repl_backend.in_eval
b = IOBuffer()
Expand Down Expand Up @@ -343,21 +344,28 @@ function start_prompt(mod, locals, file, fileline;
return
end

print(io, "Infiltrating ")
if ex !== nothing
printstyled(io, "EXCEPTION"; color=:red, bold=true)
print(io, " while infiltrating ")
else
print(io, "Infiltrating ")
end

if Threads.nthreads() > 1
print(io, "(on thread $(Threads.threadid())) ")
end
if length(trace) > 0
if nostack
println(io, "<unknown>")
print(io, "<unknown>")
else
print_verbose_stackframe(io, trace[1])
end
else
println(io, "top-level frame")
print(io, "top-level frame")
end
println(io)
debugprompt(mod, locals, trace, terminal, repl, nostack, file=file, fileline=fileline)
println(io)
debugprompt(mod, locals, trace, terminal, repl, ex, bt; nostack=nostack, file=file, fileline=fileline)
println(io)
finally
unlock(INFILTRATION_LOCK[])
Expand All @@ -374,6 +382,7 @@ The following commands are special cased:
- `?`: Print this help text.
- `@trace`: Print the current stack trace.
- `@locals`: Print local variables. `@locals x y` only prints `x` and `y`.
- `@exception`: Print the exception that triggered the current `@infiltry` session, if any.
- `@exfiltrate`: Save all local variables into the store. `@exfiltrate x y` saves `x` and `y`;
this variant can also exfiltrate variables defined in the `infil>` REPL.
- `@toggle`: Toggle infiltrating at this `@infiltrate` spot (clear all with `Infiltrator.clear_disabled!()`).
Expand Down Expand Up @@ -488,7 +497,7 @@ end

const PROMPT = Ref{Any}()

function debugprompt(mod, locals, trace, terminal, repl, nostack = false; file, fileline)
function debugprompt(mod, locals, trace, terminal, repl, ex, bt; nostack = false, file, fileline)
io = Base.pipe_writer(terminal)

evalmod = init_transient_eval_module(mod, locals)
Expand Down Expand Up @@ -541,6 +550,15 @@ function debugprompt(mod, locals, trace, terminal, repl, nostack = false; file,
exfiltrate_locals(io, evalmod, locals, sline)
LineEdit.reset_state(s)
return true
elseif sline == "@exception"
if ex !== nothing && bt !== nothing
Base.display_error(io, ex, nostack ? bt[1:1] : bt)
else
println(io, "No exception available")
end
println(io)
LineEdit.reset_state(s)
return true
elseif sline == "@toggle"
spot = (file, fileline)
ds = getfield(store, :disabled)
Expand Down Expand Up @@ -883,7 +901,7 @@ function completions(c::InfiltratorCompletionProvider, full, partial)
prepend!(ret, map(REPL.REPLCompletions.completion_text, comps))

# Infiltrator commands completions
commands = ["?", "@trace", "@locals", "@toggle", "@exit", "@continue", "@exfiltrate"]
commands = ["?", "@trace", "@locals", "@toggle", "@exit", "@continue", "@exfiltrate", "@exception"]
prepend!(ret, filter!(c -> startswith(c, partial), commands))

unique!(ret), range, should_complete
Expand Down
66 changes: 66 additions & 0 deletions test/outputs/Julia_f_1.1.multiout
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
|
| • @locals: Print local variables. @locals x y only prints x and y.
|
| • @exception: Print the exception that triggered the current
| @infiltry session, if any.
|
| • @exfiltrate: Save all local variables into the store. @exfiltrate
| x y saves x and y; this variant can also exfiltrate variables
| defined in the infil> REPL.
Expand Down Expand Up @@ -65,6 +68,9 @@
|
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
Expand Down Expand Up @@ -106,6 +112,9 @@
|
| • @locals: Print local variables. @locals x y only prints x and y.
|
| • @exception: Print the exception that triggered the current
| @infiltry session, if any.
|
| • @exfiltrate: Save all local variables into the store. @exfiltrate
| x y saves x and y; this variant can also exfiltrate variables
| defined in the infil> REPL.
Expand Down Expand Up @@ -149,6 +158,9 @@
|
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
Expand Down Expand Up @@ -192,6 +204,9 @@
|
| • @locals: Print local variables. @locals x y only prints x and y.
|
| • @exception: Print the exception that triggered the current
| @infiltry session, if any.
|
| • @exfiltrate: Save all local variables into the store. @exfiltrate
| x y saves x and y; this variant can also exfiltrate variables
| defined in the infil> REPL.
Expand Down Expand Up @@ -239,6 +254,9 @@
|
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
Expand Down Expand Up @@ -286,6 +304,9 @@
|
| • @locals: Print local variables. @locals x y only prints x and y.
|
| • @exception: Print the exception that triggered the current
| @infiltry session, if any.
|
| • @exfiltrate: Save all local variables into the store. @exfiltrate
| x y saves x and y; this variant can also exfiltrate variables
| defined in the infil> REPL.
Expand Down Expand Up @@ -339,6 +360,9 @@
|
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
Expand Down Expand Up @@ -392,6 +416,9 @@
|
| • @locals: Print local variables. @locals x y only prints x and y.
|
| • @exception: Print the exception that triggered the current
| @infiltry session, if any.
|
| • @exfiltrate: Save all local variables into the store. @exfiltrate
| x y saves x and y; this variant can also exfiltrate variables
| defined in the infil> REPL.
Expand Down Expand Up @@ -450,6 +477,9 @@
|
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
Expand Down Expand Up @@ -508,6 +538,9 @@
|
| • @locals: Print local variables. @locals x y only prints x and y.
|
| • @exception: Print the exception that triggered the current
| @infiltry session, if any.
|
| • @exfiltrate: Save all local variables into the store. @exfiltrate
| x y saves x and y; this variant can also exfiltrate variables
| defined in the infil> REPL.
Expand Down Expand Up @@ -569,6 +602,9 @@
|
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
Expand Down Expand Up @@ -630,6 +666,9 @@
|
| • @locals: Print local variables. @locals x y only prints x and y.
|
| • @exception: Print the exception that triggered the current
| @infiltry session, if any.
|
| • @exfiltrate: Save all local variables into the store. @exfiltrate
| x y saves x and y; this variant can also exfiltrate variables
| defined in the infil> REPL.
Expand Down Expand Up @@ -694,6 +733,9 @@
|
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
Expand Down Expand Up @@ -758,6 +800,9 @@
|
| • @locals: Print local variables. @locals x y only prints x and y.
|
| • @exception: Print the exception that triggered the current
| @infiltry session, if any.
|
| • @exfiltrate: Save all local variables into the store. @exfiltrate
| x y saves x and y; this variant can also exfiltrate variables
| defined in the infil> REPL.
Expand Down Expand Up @@ -825,6 +870,9 @@
|
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
Expand Down Expand Up @@ -892,6 +940,9 @@
|
| • @locals: Print local variables. @locals x y only prints x and y.
|
| • @exception: Print the exception that triggered the current
| @infiltry session, if any.
|
| • @exfiltrate: Save all local variables into the store. @exfiltrate
| x y saves x and y; this variant can also exfiltrate variables
| defined in the infil> REPL.
Expand Down Expand Up @@ -962,6 +1013,9 @@
|
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
Expand Down Expand Up @@ -1032,6 +1086,9 @@
|
| • @locals: Print local variables. @locals x y only prints x and y.
|
| • @exception: Print the exception that triggered the current
| @infiltry session, if any.
|
| • @exfiltrate: Save all local variables into the store. @exfiltrate
| x y saves x and y; this variant can also exfiltrate variables
| defined in the infil> REPL.
Expand Down Expand Up @@ -1105,6 +1162,9 @@
|
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
Expand Down Expand Up @@ -1178,6 +1238,9 @@
|
| • @locals: Print local variables. @locals x y only prints x and y.
|
| • @exception: Print the exception that triggered the current
| @infiltry session, if any.
|
| • @exfiltrate: Save all local variables into the store. @exfiltrate
| x y saves x and y; this variant can also exfiltrate variables
| defined in the infil> REPL.
Expand Down Expand Up @@ -1254,6 +1317,9 @@
|
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
Expand Down
Loading

0 comments on commit 9b0d328

Please sign in to comment.