Skip to content

Commit dc02ebb

Browse files
authored
add toggle for Compiled mode (#102)
1 parent f9d6d8d commit dc02ebb

File tree

6 files changed

+456
-9
lines changed

6 files changed

+456
-9
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Basic Commands:
4747
- `w rm [i::Int]`: remove all or the `i`:th watch expression
4848
- `o`: open the current line in an editor
4949
- `q`: quit the debugger, returning `nothing`
50+
- `C`: toggle compiled mode
5051

5152
Advanced commands:
5253
- `nc`: step to the next call
@@ -125,6 +126,16 @@ Stacktrace:
125126
[...]
126127
```
127128
129+
### Compiled mode
130+
131+
In order to fully support breakpoints, the debugger interprets all code, even code that is stepped over.
132+
Currently, there are cases where the interpreter is too slow for this to be feasible.
133+
A workaround is to use "compiled mode" which is toggled by pressing `C` in the debug REPL mode (note the change of prompt color).
134+
When using compiled mode, code that is stepped over will be executed
135+
by the normal julia compiler and run just as fast as normally.
136+
The drawback is of course that breakpoints in code that is stepped over are missed.
137+
138+
128139
### Syntax highlighting
129140
130141
The source code preview is syntax highlighted and this highlighting has some options.

src/Debugger.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ using REPL.LineEdit
1111
using REPL.REPLCompletions
1212

1313
using CodeTracking
14-
using JuliaInterpreter: JuliaInterpreter, Frame, @lookup, FrameCode, BreakpointRef, debug_command, leaf, root, BreakpointState
14+
using JuliaInterpreter: JuliaInterpreter, Frame, @lookup, FrameCode, BreakpointRef, debug_command, leaf, root, BreakpointState,
15+
finish_and_return!, Compiled
1516

1617
using JuliaInterpreter: pc_expr, moduleof, linenumber, extract_args,
1718
root, caller, whereis, get_return, nstatements
@@ -41,16 +42,21 @@ mutable struct DebuggerState
4142
level::Int
4243
broke_on_error::Bool
4344
watch_list::Vector
45+
mode
4446
repl
4547
terminal
4648
main_mode
4749
julia_prompt::Ref{LineEdit.Prompt}
4850
standard_keymap
4951
overall_result
5052
end
51-
DebuggerState(stack, repl, terminal) = DebuggerState(stack, 1, false, WATCH_LIST, repl, terminal, nothing, Ref{LineEdit.Prompt}(), nothing, nothing)
53+
DebuggerState(stack, repl, terminal) = DebuggerState(stack, 1, false, WATCH_LIST, finish_and_return!, repl, terminal, nothing, Ref{LineEdit.Prompt}(), nothing, nothing)
5254
DebuggerState(stack, repl) = DebuggerState(stack, repl, nothing)
5355

56+
function toggle_mode(state)
57+
state.mode = (state.mode === finish_and_return! ? (state.mode = Compiled()) : (state.mode = finish_and_return!))
58+
end
59+
5460
function active_frame(state)
5561
frame = state.frame
5662
for i in 1:(state.level - 1)

src/commands.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ end
4040
function execute_command(state::DebuggerState, ::Union{Val{:c},Val{:nc},Val{:n},Val{:se},Val{:s},Val{:si},Val{:sg},Val{:so}}, cmd::AbstractString)
4141
assert_allow_step(state) || return false
4242
cmd == "so" && (cmd = "finish")
43-
ret = debug_command(state.frame, Symbol(cmd))
43+
ret = debug_command(state.mode, state.frame, Symbol(cmd))
4444
if ret === nothing
4545
state.overall_result = get_return(root(state.frame))
4646
state.frame = nothing
@@ -163,6 +163,7 @@ function execute_command(state::DebuggerState, ::Val{:?}, cmd::AbstractString)
163163
- `w rm [i::Int]`: remove all or the `i`:th watch expression\\
164164
- `o`: open the current line in an editor\\
165165
- `q`: quit the debugger, returning `nothing`\\
166+
- `C`: toggle compiled mode\\
166167
Advanced commands:\\
167168
- `nc`: step to the next call\\
168169
- `se`: step one expression step\\

src/repl.jl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ function RunDebugger(frame, repl = Base.active_repl, terminal = Base.active_repl
44
state = DebuggerState(frame, repl, terminal)
55

66
# Setup debug panel
7+
normal_prefix = Sys.iswindows() ? "\e[33m" : "\e[38;5;166m"
8+
compiled_prefix = "\e[96m"
79
panel = LineEdit.Prompt(promptname(state.level, "debug");
8-
prompt_prefix = Sys.iswindows() ? "\e[33m" : "\e[38;5;166m",
10+
prompt_prefix = () -> state.mode == Compiled() ? compiled_prefix : normal_prefix,
911
prompt_suffix = Base.text_colors[:normal],
1012
on_enter = s->true)
1113

@@ -68,6 +70,15 @@ function RunDebugger(frame, repl = Base.active_repl, terminal = Base.active_repl
6870
else
6971
LineEdit.edit_insert(s,key)
7072
end
73+
end,
74+
"C" => function (s, args...)
75+
if isempty(s) || position(LineEdit.buffer(s)) == 0
76+
toggle_mode(state)
77+
write(state.terminal, '\r')
78+
LineEdit.write_prompt(state.terminal, panel)
79+
else
80+
LineEdit.edit_insert(s,key)
81+
end
7182
end
7283
)
7384

test/ui.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ end
5353
using TerminalRegressionTests
5454

5555
function run_terminal_test(frame, commands, validation)
56-
TerminalRegressionTests.automated_test(joinpath(@__DIR__, validation), commands) do emuterm
57-
#TerminalRegressionTests.create_automated_test(joinpath(@__DIR__, validation), commands) do emuterm
56+
#TerminalRegressionTests.automated_test(joinpath(@__DIR__, validation), commands) do emuterm
57+
TerminalRegressionTests.create_automated_test(joinpath(@__DIR__, validation), commands) do emuterm
5858
repl = REPL.LineEditREPL(emuterm, true)
5959
repl.interface = REPL.setup_interface(repl)
6060
repl.specialdisplay = REPL.REPLDisplay(repl)
@@ -70,7 +70,7 @@ end
7070
["n\n","`", "my_gc\t\n", "a\n", UP_ARROW, UP_ARROW, UP_ARROW, CTRL_C,
7171
"w add a\n", "w add sin(a)\n", "w add b\n", "w\n", "w rm 1\n", "w\n",
7272
"s\n", "fr 1\n", "fr 2\n", "f 2\n", "f 1\n",
73-
"bt\n", "st\n", "c\n", "c\n"],
73+
"bt\n", "st\n", "C", "c\n", "C", "c\n"],
7474
"ui/history_gcd.multiout")
7575

7676
if v"1.1">= VERSION < v"1.2"

0 commit comments

Comments
 (0)