@@ -2,9 +2,9 @@ using JuliaInterpreter, Test
2
2
using JuliaInterpreter: enter_call, enter_call_expr, get_return, @lookup
3
3
using Base. Meta: isexpr
4
4
5
- const ALL_COMMANDS = (" n " , " s " , " c " , " finish" , " nc " , " se " , " si " )
5
+ const ALL_COMMANDS = (:n , :s , :c , : finish, :nc , :se , :si )
6
6
7
- function step_through_command (fr:: Frame , cmd:: String )
7
+ function step_through_command (fr:: Frame , cmd:: Symbol )
8
8
while true
9
9
ret = JuliaInterpreter. debug_command (JuliaInterpreter. finish_and_return!, fr, cmd)
10
10
ret == nothing && break
@@ -52,7 +52,7 @@ struct B{T} end
52
52
# @testset "Debug" begin
53
53
@testset " Basics" begin
54
54
frame = enter_call (map, x-> 2 x, 1 : 10 )
55
- @test debug_command (frame, " finish" ) === nothing
55
+ @test debug_command (frame, : finish ) === nothing
56
56
@test frame. caller === frame. callee === nothing
57
57
@test get_return (frame) == map (x-> 2 x, 1 : 10 )
58
58
@@ -62,10 +62,10 @@ struct B{T} end
62
62
end
63
63
for (args, kwargs) in (((1 ,), ()), ((1 , 2 ), (x= 7 , y= 33 )))
64
64
frame = enter_call (complicated_keyword_stuff, args... ; kwargs... )
65
- f, pc = debug_command (frame, " n " )
65
+ f, pc = debug_command (frame, :n )
66
66
@test f === frame
67
67
@test isa (pc, Int)
68
- @test debug_command (frame, " finish" ) === nothing
68
+ @test debug_command (frame, : finish ) === nothing
69
69
@test frame. caller === frame. callee === nothing
70
70
@test get_return (frame) == complicated_keyword_stuff (args... ; kwargs... )
71
71
end
@@ -76,7 +76,7 @@ struct B{T} end
76
76
@test step_through (f22) == " :a"
77
77
78
78
frame = enter_call (trivial, 2 )
79
- @test debug_command (frame, " s " ) === nothing
79
+ @test debug_command (frame, :s ) === nothing
80
80
@test get_return (frame) == 2
81
81
82
82
@test step_through (trivial, 2 ) == 2
@@ -87,37 +87,37 @@ struct B{T} end
87
87
88
88
@testset " generated" begin
89
89
frame = enter_call_expr (:($ (callgenerated)()))
90
- f, pc = debug_command (frame, " s " )
90
+ f, pc = debug_command (frame, :s )
91
91
@test isa (pc, BreakpointRef)
92
92
@test JuliaInterpreter. scopeof (f). name == :generatedfoo
93
93
stmt = JuliaInterpreter. pc_expr (f)
94
94
@test stmt. head == :return && stmt. args[1 ] === Int
95
- @test debug_command (frame, " c " ) === nothing
95
+ @test debug_command (frame, :c ) === nothing
96
96
@test frame. callee === nothing
97
97
@test get_return (frame) === Int
98
98
# This time, step into the generated function itself
99
99
frame = enter_call_expr (:($ (callgenerated)()))
100
- f, pc = debug_command (frame, " sg " )
100
+ f, pc = debug_command (frame, :sg )
101
101
@test isa (pc, BreakpointRef)
102
102
@test JuliaInterpreter. scopeof (f). name == :generatedfoo
103
103
stmt = JuliaInterpreter. pc_expr (f)
104
104
@test stmt. head == :return && @lookup (f, stmt. args[1 ]) === 1
105
- f2, pc = debug_command (f, " finish" )
105
+ f2, pc = debug_command (f, : finish )
106
106
@test JuliaInterpreter. scopeof (f2). name == :callgenerated
107
107
# Now finish the regular function
108
- @test debug_command (frame, " finish" ) === nothing
108
+ @test debug_command (frame, : finish ) === nothing
109
109
@test frame. callee === nothing
110
110
@test get_return (frame) === 1
111
111
112
112
# Parametric generated function (see #157)
113
113
frame = fr = JuliaInterpreter. enter_call (callgeneratedparams)
114
114
while fr. pc < JuliaInterpreter. nstatements (fr. framecode) - 1
115
- fr, pc = debug_command (fr, " se " )
115
+ fr, pc = debug_command (fr, :se )
116
116
end
117
- fr, pc = debug_command (fr, " sg " )
117
+ fr, pc = debug_command (fr, :sg )
118
118
@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
121
121
@test JuliaInterpreter. get_return (fr) == (Int, 2 )
122
122
end
123
123
@@ -128,33 +128,33 @@ struct B{T} end
128
128
end
129
129
frame = JuliaInterpreter. enter_call_expr (:($ (optional)()))
130
130
# First call steps in and executes the first statement
131
- f, pc = debug_command (frame, " n " )
131
+ f, pc = debug_command (frame, :n )
132
132
@test frame != = f
133
133
# cos(1.0)
134
- debug_command (f, " n " )
134
+ debug_command (f, :n )
135
135
# return
136
- f2, pc = debug_command (f, " n " )
136
+ f2, pc = debug_command (f, :n )
137
137
@test f2 === frame
138
- @test debug_command (frame, " n " ) === nothing
138
+ @test debug_command (frame, :n ) === nothing
139
139
end
140
140
141
141
@testset " Keyword arguments" begin
142
142
f (x; b = 1 ) = x+ b
143
143
g () = f (1 ; b = 2 )
144
144
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
151
151
@test frame. callee === nothing
152
152
@test get_return (frame) == 3
153
153
154
154
frame = JuliaInterpreter. enter_call (f, 2 ; b = 4 )
155
155
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 )
158
158
@test get_return (frame) == 6
159
159
end
160
160
@@ -171,16 +171,16 @@ struct B{T} end
171
171
frame = fr = JuliaInterpreter. enter_call (f)
172
172
pc = fr. pc
173
173
while pc <= JuliaInterpreter. nstatements (fr. framecode) - 2
174
- fr, pc = debug_command (fr, " se " )
174
+ fr, pc = debug_command (fr, :se )
175
175
end
176
- fr, pc = debug_command (frame, " si " )
176
+ fr, pc = debug_command (frame, :si )
177
177
@test stacklength (frame) == 2
178
178
frame = fr = JuliaInterpreter. enter_call (f)
179
179
pc = fr. pc
180
180
while pc <= JuliaInterpreter. nstatements (fr. framecode) - 2
181
- fr, pc = debug_command (fr, " se " )
181
+ fr, pc = debug_command (fr, :se )
182
182
end
183
- fr, pc = debug_command (frame, " s " )
183
+ fr, pc = debug_command (frame, :s )
184
184
@test stacklength (frame) > 2
185
185
push! (scopes, JuliaInterpreter. scopeof (fr))
186
186
end
@@ -199,21 +199,21 @@ struct B{T} end
199
199
end
200
200
""" ," file.jl" )
201
201
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
208
208
end
209
209
210
210
@testset " Quoting" begin
211
211
# Test that symbols don't get an extra QuoteNode
212
212
f_symbol () = :limit => true
213
213
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
217
217
@test get_return (frame) == f_symbol ()
218
218
end
219
219
@@ -224,13 +224,13 @@ struct B{T} end
224
224
# depending on whether this is in or out of a @testset, the first statement may differ
225
225
stmt1 = fr. framecode. src. code[1 ]
226
226
if isexpr (stmt1, :call ) && @lookup (frame, stmt1. args[1 ]) === getfield
227
- fr, pc = debug_command (fr, " se " )
227
+ fr, pc = debug_command (fr, :se )
228
228
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 )
231
231
@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
234
234
@test get_return (frame) === 2
235
235
end
236
236
@@ -257,18 +257,18 @@ struct B{T} end
257
257
end
258
258
f_exc_inner () = error ()
259
259
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 )
264
264
@test get_return (fr) == 2
265
265
@test first (err_caught) isa ErrorException
266
266
@test stacklength (fr) == 1
267
267
268
268
err_caught = Any[nothing ]
269
269
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 )
272
272
@test get_return (root (fr)) == 2
273
273
@test first (err_caught) isa ErrorException
274
274
@test stacklength (root (fr)) == 1
@@ -277,19 +277,19 @@ struct B{T} end
277
277
f_outer () = g_inner ()
278
278
g_inner () = error ()
279
279
fr = JuliaInterpreter. enter_call (f_outer)
280
- @test_throws ErrorException debug_command (fr, " finish" )
280
+ @test_throws ErrorException debug_command (fr, : finish )
281
281
@test stacklength (fr) == 1
282
282
283
283
# Break on error
284
284
try
285
285
JuliaInterpreter. break_on_error[] = true
286
286
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 )
288
288
@test fr. framecode. scope. name == :error
289
289
290
290
fundef () = undef_func ()
291
291
frame = JuliaInterpreter. enter_call (fundef)
292
- fr, pc = debug_command (frame, " s " )
292
+ fr, pc = debug_command (frame, :s )
293
293
@test isa (pc, BreakpointRef)
294
294
@test pc. err isa UndefVarError
295
295
finally
@@ -311,21 +311,21 @@ struct B{T} end
311
311
method_start = ln - 9
312
312
fr = enter_call (f_bp, 2 )
313
313
@test JuliaInterpreter. linenumber (fr) == method_start + 1
314
- fr, pc = JuliaInterpreter. debug_command (fr, " c " )
314
+ fr, pc = JuliaInterpreter. debug_command (fr, :c )
315
315
# Hit the breakpoint x1
316
316
@test JuliaInterpreter. linenumber (fr) == method_start + 3
317
317
@test pc isa BreakpointRef
318
- fr, pc = JuliaInterpreter. debug_command (fr, " n " )
318
+ fr, pc = JuliaInterpreter. debug_command (fr, :n )
319
319
@test JuliaInterpreter. linenumber (fr) == method_start + 4
320
- fr, pc = JuliaInterpreter. debug_command (fr, " c " )
320
+ fr, pc = JuliaInterpreter. debug_command (fr, :c )
321
321
# Hit the breakpoint again x2
322
322
@test pc isa BreakpointRef
323
323
@test JuliaInterpreter. linenumber (fr) == method_start + 3
324
- fr, pc = JuliaInterpreter. debug_command (fr, " c " )
324
+ fr, pc = JuliaInterpreter. debug_command (fr, :c )
325
325
# Hit the breakpoint for the last time x3
326
326
@test pc isa BreakpointRef
327
327
@test JuliaInterpreter. linenumber (fr) == method_start + 3
328
- JuliaInterpreter. debug_command (fr, " c " )
328
+ JuliaInterpreter. debug_command (fr, :c )
329
329
@test get_return (fr) == 2
330
330
end
331
331
end
0 commit comments