Skip to content

Commit 5e3ddfc

Browse files
committed
use symbol instead of strings in debug command
1 parent ad58eb9 commit 5e3ddfc

File tree

2 files changed

+83
-83
lines changed

2 files changed

+83
-83
lines changed

src/commands.jl

Lines changed: 24 additions & 24 deletions
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/debug.jl

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

5-
const ALL_COMMANDS = ("n", "s", "c", "finish", "nc", "se", "si")
5+
const ALL_COMMANDS = (:n, :s, :c, :finish, :nc, :se, :si)
66

7-
function step_through_command(fr::Frame, cmd::String)
7+
function step_through_command(fr::Frame, cmd::Symbol)
88
while true
99
ret = JuliaInterpreter.debug_command(JuliaInterpreter.finish_and_return!, fr, cmd)
1010
ret == nothing && break
@@ -52,7 +52,7 @@ struct B{T} end
5252
# @testset "Debug" begin
5353
@testset "Basics" begin
5454
frame = enter_call(map, x->2x, 1:10)
55-
@test debug_command(frame, "finish") === nothing
55+
@test debug_command(frame, :finish) === nothing
5656
@test frame.caller === frame.callee === nothing
5757
@test get_return(frame) == map(x->2x, 1:10)
5858

@@ -62,10 +62,10 @@ struct B{T} end
6262
end
6363
for (args, kwargs) in (((1,), ()), ((1, 2), (x=7, y=33)))
6464
frame = enter_call(complicated_keyword_stuff, args...; kwargs...)
65-
f, pc = debug_command(frame, "n")
65+
f, pc = debug_command(frame, :n)
6666
@test f === frame
6767
@test isa(pc, Int)
68-
@test debug_command(frame, "finish") === nothing
68+
@test debug_command(frame, :finish) === nothing
6969
@test frame.caller === frame.callee === nothing
7070
@test get_return(frame) == complicated_keyword_stuff(args...; kwargs...)
7171
end
@@ -76,7 +76,7 @@ struct B{T} end
7676
@test step_through(f22) == ":a"
7777

7878
frame = enter_call(trivial, 2)
79-
@test debug_command(frame, "s") === nothing
79+
@test debug_command(frame, :s) === nothing
8080
@test get_return(frame) == 2
8181

8282
@test step_through(trivial, 2) == 2
@@ -87,37 +87,37 @@ struct B{T} end
8787

8888
@testset "generated" begin
8989
frame = enter_call_expr(:($(callgenerated)()))
90-
f, pc = debug_command(frame, "s")
90+
f, pc = debug_command(frame, :s)
9191
@test isa(pc, BreakpointRef)
9292
@test JuliaInterpreter.scopeof(f).name == :generatedfoo
9393
stmt = JuliaInterpreter.pc_expr(f)
9494
@test stmt.head == :return && stmt.args[1] === Int
95-
@test debug_command(frame, "c") === nothing
95+
@test debug_command(frame, :c) === nothing
9696
@test frame.callee === nothing
9797
@test get_return(frame) === Int
9898
# This time, step into the generated function itself
9999
frame = enter_call_expr(:($(callgenerated)()))
100-
f, pc = debug_command(frame, "sg")
100+
f, pc = debug_command(frame, :sg)
101101
@test isa(pc, BreakpointRef)
102102
@test JuliaInterpreter.scopeof(f).name == :generatedfoo
103103
stmt = JuliaInterpreter.pc_expr(f)
104104
@test stmt.head == :return && @lookup(f, stmt.args[1]) === 1
105-
f2, pc = debug_command(f, "finish")
105+
f2, pc = debug_command(f, :finish)
106106
@test JuliaInterpreter.scopeof(f2).name == :callgenerated
107107
# Now finish the regular function
108-
@test debug_command(frame, "finish") === nothing
108+
@test debug_command(frame, :finish) === nothing
109109
@test frame.callee === nothing
110110
@test get_return(frame) === 1
111111

112112
# Parametric generated function (see #157)
113113
frame = fr = JuliaInterpreter.enter_call(callgeneratedparams)
114114
while fr.pc < JuliaInterpreter.nstatements(fr.framecode) - 1
115-
fr, pc = debug_command(fr, "se")
115+
fr, pc = debug_command(fr, :se)
116116
end
117-
fr, pc = debug_command(fr, "sg")
117+
fr, pc = debug_command(fr, :sg)
118118
@test JuliaInterpreter.scopeof(fr).name == :generatedparams
119-
fr, pc = debug_command(fr, "finish")
120-
@test debug_command(fr, "finish") === nothing
119+
fr, pc = debug_command(fr, :finish)
120+
@test debug_command(fr, :finish) === nothing
121121
@test JuliaInterpreter.get_return(fr) == (Int, 2)
122122
end
123123

@@ -128,33 +128,33 @@ struct B{T} end
128128
end
129129
frame = JuliaInterpreter.enter_call_expr(:($(optional)()))
130130
# First call steps in and executes the first statement
131-
f, pc = debug_command(frame, "n")
131+
f, pc = debug_command(frame, :n)
132132
@test frame !== f
133133
# cos(1.0)
134-
debug_command(f, "n")
134+
debug_command(f, :n)
135135
# return
136-
f2, pc = debug_command(f, "n")
136+
f2, pc = debug_command(f, :n)
137137
@test f2 === frame
138-
@test debug_command(frame, "n") === nothing
138+
@test debug_command(frame, :n) === nothing
139139
end
140140

141141
@testset "Keyword arguments" begin
142142
f(x; b = 1) = x+b
143143
g() = f(1; b = 2)
144144
frame = JuliaInterpreter.enter_call_expr(:($(g)()));
145-
fr, pc = debug_command(frame, "nc")
146-
fr, pc = debug_command(fr, "nc")
147-
fr, pc = debug_command(fr, "nc")
148-
fr, pc = debug_command(fr, "s")
149-
fr, pc = debug_command(fr, "finish")
150-
@test debug_command(fr, "finish") === nothing
145+
fr, pc = debug_command(frame, :nc)
146+
fr, pc = debug_command(fr, :nc)
147+
fr, pc = debug_command(fr, :nc)
148+
fr, pc = debug_command(fr, :s)
149+
fr, pc = debug_command(fr, :finish)
150+
@test debug_command(fr, :finish) === nothing
151151
@test frame.callee === nothing
152152
@test get_return(frame) == 3
153153

154154
frame = JuliaInterpreter.enter_call(f, 2; b = 4)
155155
fr = JuliaInterpreter.maybe_step_through_wrapper!(frame)
156-
fr, pc = debug_command(fr, "nc")
157-
fr, pc = debug_command(fr, "nc")
156+
fr, pc = debug_command(fr, :nc)
157+
fr, pc = debug_command(fr, :nc)
158158
@test get_return(frame) == 6
159159
end
160160

@@ -171,16 +171,16 @@ struct B{T} end
171171
frame = fr = JuliaInterpreter.enter_call(f)
172172
pc = fr.pc
173173
while pc <= JuliaInterpreter.nstatements(fr.framecode) - 2
174-
fr, pc = debug_command(fr, "se")
174+
fr, pc = debug_command(fr, :se)
175175
end
176-
fr, pc = debug_command(frame, "si")
176+
fr, pc = debug_command(frame, :si)
177177
@test stacklength(frame) == 2
178178
frame = fr = JuliaInterpreter.enter_call(f)
179179
pc = fr.pc
180180
while pc <= JuliaInterpreter.nstatements(fr.framecode) - 2
181-
fr, pc = debug_command(fr, "se")
181+
fr, pc = debug_command(fr, :se)
182182
end
183-
fr, pc = debug_command(frame, "s")
183+
fr, pc = debug_command(frame, :s)
184184
@test stacklength(frame) > 2
185185
push!(scopes, JuliaInterpreter.scopeof(fr))
186186
end
@@ -199,21 +199,21 @@ struct B{T} end
199199
end
200200
""","file.jl")
201201
frame = JuliaInterpreter.enter_call_expr(:($(test_macro)()))
202-
f, pc = debug_command(frame, "n") # a is set
203-
f, pc = debug_command(f, "n") # b is set
204-
f, pc = debug_command(f, "n") # x is set
205-
f, pc = debug_command(f, "n") # y is set
206-
f, pc = debug_command(f, "n") # z is set
207-
@test debug_command(f, "n") === nothing # return
202+
f, pc = debug_command(frame, :n) # a is set
203+
f, pc = debug_command(f, :n) # b is set
204+
f, pc = debug_command(f, :n) # x is set
205+
f, pc = debug_command(f, :n) # y is set
206+
f, pc = debug_command(f, :n) # z is set
207+
@test debug_command(f, :n) === nothing # return
208208
end
209209

210210
@testset "Quoting" begin
211211
# Test that symbols don't get an extra QuoteNode
212212
f_symbol() = :limit => true
213213
frame = JuliaInterpreter.enter_call(f_symbol)
214-
fr, pc = debug_command(frame, "s")
215-
fr, pc = debug_command(fr, "finish")
216-
@test debug_command(fr, "finish") === nothing
214+
fr, pc = debug_command(frame, :s)
215+
fr, pc = debug_command(fr, :finish)
216+
@test debug_command(fr, :finish) === nothing
217217
@test get_return(frame) == f_symbol()
218218
end
219219

@@ -224,13 +224,13 @@ struct B{T} end
224224
# depending on whether this is in or out of a @testset, the first statement may differ
225225
stmt1 = fr.framecode.src.code[1]
226226
if isexpr(stmt1, :call) && @lookup(frame, stmt1.args[1]) === getfield
227-
fr, pc = debug_command(fr, "se")
227+
fr, pc = debug_command(fr, :se)
228228
end
229-
fr, pc = debug_command(fr, "s")
230-
fr, pc = debug_command(fr, "n")
229+
fr, pc = debug_command(fr, :s)
230+
fr, pc = debug_command(fr, :n)
231231
@test root(fr) !== fr
232-
fr, pc = debug_command(fr, "finish")
233-
@test debug_command(fr, "finish") === nothing
232+
fr, pc = debug_command(fr, :finish)
233+
@test debug_command(fr, :finish) === nothing
234234
@test get_return(frame) === 2
235235
end
236236

@@ -257,18 +257,18 @@ struct B{T} end
257257
end
258258
f_exc_inner() = error()
259259
fr = JuliaInterpreter.enter_call(f_exc_outer)
260-
fr, pc = debug_command(fr, "s")
261-
fr, pc = debug_command(fr, "n")
262-
fr, pc = debug_command(fr, "n")
263-
debug_command(fr, "finish")
260+
fr, pc = debug_command(fr, :s)
261+
fr, pc = debug_command(fr, :n)
262+
fr, pc = debug_command(fr, :n)
263+
debug_command(fr, :finish)
264264
@test get_return(fr) == 2
265265
@test first(err_caught) isa ErrorException
266266
@test stacklength(fr) == 1
267267

268268
err_caught = Any[nothing]
269269
fr = JuliaInterpreter.enter_call(f_exc_outer)
270-
fr, pc = debug_command(fr, "s")
271-
debug_command(fr, "c")
270+
fr, pc = debug_command(fr, :s)
271+
debug_command(fr, :c)
272272
@test get_return(root(fr)) == 2
273273
@test first(err_caught) isa ErrorException
274274
@test stacklength(root(fr)) == 1
@@ -277,19 +277,19 @@ struct B{T} end
277277
f_outer() = g_inner()
278278
g_inner() = error()
279279
fr = JuliaInterpreter.enter_call(f_outer)
280-
@test_throws ErrorException debug_command(fr, "finish")
280+
@test_throws ErrorException debug_command(fr, :finish)
281281
@test stacklength(fr) == 1
282282

283283
# Break on error
284284
try
285285
JuliaInterpreter.break_on_error[] = true
286286
fr = JuliaInterpreter.enter_call(f_outer)
287-
fr, pc = debug_command(JuliaInterpreter.finish_and_return!, fr, "finish")
287+
fr, pc = debug_command(JuliaInterpreter.finish_and_return!, fr, :finish)
288288
@test fr.framecode.scope.name == :error
289289

290290
fundef() = undef_func()
291291
frame = JuliaInterpreter.enter_call(fundef)
292-
fr, pc = debug_command(frame, "s")
292+
fr, pc = debug_command(frame, :s)
293293
@test isa(pc, BreakpointRef)
294294
@test pc.err isa UndefVarError
295295
finally
@@ -311,21 +311,21 @@ struct B{T} end
311311
method_start = ln - 9
312312
fr = enter_call(f_bp, 2)
313313
@test JuliaInterpreter.linenumber(fr) == method_start + 1
314-
fr, pc = JuliaInterpreter.debug_command(fr, "c")
314+
fr, pc = JuliaInterpreter.debug_command(fr, :c)
315315
# Hit the breakpoint x1
316316
@test JuliaInterpreter.linenumber(fr) == method_start + 3
317317
@test pc isa BreakpointRef
318-
fr, pc = JuliaInterpreter.debug_command(fr, "n")
318+
fr, pc = JuliaInterpreter.debug_command(fr, :n)
319319
@test JuliaInterpreter.linenumber(fr) == method_start + 4
320-
fr, pc = JuliaInterpreter.debug_command(fr, "c")
320+
fr, pc = JuliaInterpreter.debug_command(fr, :c)
321321
# Hit the breakpoint again x2
322322
@test pc isa BreakpointRef
323323
@test JuliaInterpreter.linenumber(fr) == method_start + 3
324-
fr, pc = JuliaInterpreter.debug_command(fr, "c")
324+
fr, pc = JuliaInterpreter.debug_command(fr, :c)
325325
# Hit the breakpoint for the last time x3
326326
@test pc isa BreakpointRef
327327
@test JuliaInterpreter.linenumber(fr) == method_start + 3
328-
JuliaInterpreter.debug_command(fr, "c")
328+
JuliaInterpreter.debug_command(fr, :c)
329329
@test get_return(fr) == 2
330330
end
331331
end

0 commit comments

Comments
 (0)