@@ -2,24 +2,31 @@ using JuliaInterpreter, Test
2
2
using JuliaInterpreter: enter_call, enter_call_expr, get_return, @lookup
3
3
using Base. Meta: isexpr
4
4
5
- function step_through (frame)
6
- r = root (frame)
7
- @test debug_command (JuliaInterpreter. finish_and_return!, frame, " c" ) === nothing
8
- @test r. callee === nothing
9
- return get_return (r)
10
- end
5
+ const ALL_COMMANDS = (:n , :s , :c , :finish , :nc , :se , :si )
11
6
12
- function step_through_function (f, args... )
13
- frame = JuliaInterpreter. enter_call (f, args... )
7
+ function step_through_command (fr:: Frame , cmd:: Symbol )
14
8
while true
15
- ret = JuliaInterpreter. debug_command (JuliaInterpreter. finish_and_return!, frame, " s " )
9
+ ret = JuliaInterpreter. debug_command (JuliaInterpreter. finish_and_return!, fr, cmd )
16
10
ret == nothing && break
17
- frame, pc = ret
11
+ fr, pc = ret
12
+ end
13
+ @test fr. callee === nothing
14
+ @test fr. caller === nothing
15
+ return get_return (fr)
16
+ end
17
+
18
+ function step_through_frame (frame_creator)
19
+ rets = []
20
+ for cmd in ALL_COMMANDS
21
+ frame = frame_creator ()
22
+ ret = step_through_command (frame, cmd)
23
+ push! (rets, ret)
18
24
end
19
- @test frame. callee === nothing
20
- @test frame. caller === nothing
21
- return JuliaInterpreter. get_return (frame)
25
+ @test all (ret -> ret == rets[1 ], rets)
26
+ return rets[1 ]
22
27
end
28
+ step_through (f, args... ; kwargs... ) = step_through_frame (() -> enter_call (f, args... ; kwargs... ))
29
+ step_through (expr:: Expr ) = step_through_frame (() -> enter_call_expr (expr))
23
30
24
31
@generated function generatedfoo (x)
25
32
:(return x)
@@ -45,7 +52,7 @@ struct B{T} end
45
52
# @testset "Debug" begin
46
53
@testset " Basics" begin
47
54
frame = enter_call (map, x-> 2 x, 1 : 10 )
48
- @test debug_command (frame, " finish" ) === nothing
55
+ @test debug_command (frame, : finish ) === nothing
49
56
@test frame. caller === frame. callee === nothing
50
57
@test get_return (frame) == map (x-> 2 x, 1 : 10 )
51
58
@@ -55,65 +62,62 @@ struct B{T} end
55
62
end
56
63
for (args, kwargs) in (((1 ,), ()), ((1 , 2 ), (x= 7 , y= 33 )))
57
64
frame = enter_call (complicated_keyword_stuff, args... ; kwargs... )
58
- f, pc = debug_command (frame, " n " )
65
+ f, pc = debug_command (frame, :n )
59
66
@test f === frame
60
67
@test isa (pc, Int)
61
- @test debug_command (frame, " finish" ) === nothing
68
+ @test debug_command (frame, : finish ) === nothing
62
69
@test frame. caller === frame. callee === nothing
63
70
@test get_return (frame) == complicated_keyword_stuff (args... ; kwargs... )
64
71
end
65
72
66
73
f22 () = string (:(a+ b))
67
- @test step_through (enter_call (f22)) == " a + b"
68
- @test step_through_function (f22) == " a + b"
74
+ @test step_through (f22) == " a + b"
69
75
f22 () = string (QuoteNode (:a ))
70
- @test step_through (enter_call (f22)) == " :a"
71
- @test step_through_function (f22) == " :a"
76
+ @test step_through (f22) == " :a"
72
77
73
78
frame = enter_call (trivial, 2 )
74
- @test debug_command (frame, " s " ) === nothing
79
+ @test debug_command (frame, :s ) === nothing
75
80
@test get_return (frame) == 2
76
81
77
- @test step_through (enter_call (trivial, 2 )) == 2
78
- @test step_through_function (trivial, 2 ) == 2
79
- @test step_through (enter_call_expr (:($ (+ )(1 ,2.5 )))) == 3.5
80
- @test step_through (enter_call_expr (:($ (sin)(1 )))) == sin (1 )
81
- @test step_through (enter_call_expr (:($ (gcd)(10 ,20 )))) == gcd (10 , 20 )
82
+ @test step_through (trivial, 2 ) == 2
83
+ @test step_through (:($ (+ )(1 ,2.5 ))) == 3.5
84
+ @test step_through (:($ (sin)(1 ))) == sin (1 )
85
+ @test step_through (:($ (gcd)(10 ,20 ))) == gcd (10 , 20 )
82
86
end
83
87
84
88
@testset " generated" begin
85
89
frame = enter_call_expr (:($ (callgenerated)()))
86
- f, pc = debug_command (frame, " s " )
90
+ f, pc = debug_command (frame, :s )
87
91
@test isa (pc, BreakpointRef)
88
92
@test JuliaInterpreter. scopeof (f). name == :generatedfoo
89
93
stmt = JuliaInterpreter. pc_expr (f)
90
94
@test stmt. head == :return
91
- @test debug_command (frame, " c " ) === nothing
95
+ @test debug_command (frame, :c ) === nothing
92
96
@test frame. callee === nothing
93
97
@test get_return (frame) === 1
94
98
# This time, step into the generated function itself
95
99
frame = enter_call_expr (:($ (callgenerated)()))
96
- f, pc = debug_command (frame, " sg " )
100
+ f, pc = debug_command (frame, :sg )
97
101
@test isa (pc, BreakpointRef)
98
102
@test JuliaInterpreter. scopeof (f). name == :generatedfoo
99
103
stmt = JuliaInterpreter. pc_expr (f)
100
104
@test stmt. head == :return
101
- f2, pc = debug_command (f, " finish" )
105
+ f2, pc = debug_command (f, : finish )
102
106
@test JuliaInterpreter. scopeof (f2). name == :callgenerated
103
107
# Now finish the regular function
104
- @test debug_command (frame, " finish" ) === nothing
108
+ @test debug_command (frame, : finish ) === nothing
105
109
@test frame. callee === nothing
106
110
@test get_return (frame) === Int
107
111
108
112
# Parametric generated function (see #157)
109
113
frame = fr = JuliaInterpreter. enter_call (callgeneratedparams)
110
114
while fr. pc < JuliaInterpreter. nstatements (fr. framecode) - 1
111
- fr, pc = debug_command (fr, " se " )
115
+ fr, pc = debug_command (fr, :se )
112
116
end
113
- fr, pc = debug_command (fr, " sg " )
117
+ fr, pc = debug_command (fr, :sg )
114
118
@test JuliaInterpreter. scopeof (fr). name == :generatedparams
115
- fr, pc = debug_command (fr, " finish" )
116
- @test debug_command (fr, " finish" ) === nothing
119
+ fr, pc = debug_command (fr, : finish )
120
+ @test debug_command (fr, : finish ) === nothing
117
121
@test JuliaInterpreter. get_return (fr) == (Int, 2 )
118
122
end
119
123
@@ -124,33 +128,33 @@ struct B{T} end
124
128
end
125
129
frame = JuliaInterpreter. enter_call_expr (:($ (optional)()))
126
130
# First call steps in and executes the first statement
127
- f, pc = debug_command (frame, " n " )
131
+ f, pc = debug_command (frame, :n )
128
132
@test frame != = f
129
133
# cos(1.0)
130
- debug_command (f, " n " )
134
+ debug_command (f, :n )
131
135
# return
132
- f2, pc = debug_command (f, " n " )
136
+ f2, pc = debug_command (f, :n )
133
137
@test f2 === frame
134
- @test debug_command (frame, " n " ) === nothing
138
+ @test debug_command (frame, :n ) === nothing
135
139
end
136
140
137
141
@testset " Keyword arguments" begin
138
142
f (x; b = 1 ) = x+ b
139
143
g () = f (1 ; b = 2 )
140
144
frame = JuliaInterpreter. enter_call_expr (:($ (g)()));
141
- fr, pc = debug_command (frame, " nc " )
142
- fr, pc = debug_command (fr, " nc " )
143
- fr, pc = debug_command (fr, " nc " )
144
- fr, pc = debug_command (fr, " s " )
145
- fr, pc = debug_command (fr, " finish" )
146
- @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
147
151
@test frame. callee === nothing
148
152
@test get_return (frame) == 3
149
153
150
154
frame = JuliaInterpreter. enter_call (f, 2 ; b = 4 )
151
155
fr = JuliaInterpreter. maybe_step_through_wrapper! (frame)
152
- fr, pc = debug_command (fr, " nc " )
153
- fr, pc = debug_command (fr, " nc " )
156
+ fr, pc = debug_command (fr, :nc )
157
+ fr, pc = debug_command (fr, :nc )
154
158
@test get_return (frame) == 6
155
159
end
156
160
@@ -167,16 +171,16 @@ struct B{T} end
167
171
frame = fr = JuliaInterpreter. enter_call (f)
168
172
pc = fr. pc
169
173
while pc <= JuliaInterpreter. nstatements (fr. framecode) - 2
170
- fr, pc = debug_command (fr, " se " )
174
+ fr, pc = debug_command (fr, :se )
171
175
end
172
- fr, pc = debug_command (frame, " si " )
176
+ fr, pc = debug_command (frame, :si )
173
177
@test stacklength (frame) == 2
174
178
frame = fr = JuliaInterpreter. enter_call (f)
175
179
pc = fr. pc
176
180
while pc <= JuliaInterpreter. nstatements (fr. framecode) - 2
177
- fr, pc = debug_command (fr, " se " )
181
+ fr, pc = debug_command (fr, :se )
178
182
end
179
- fr, pc = debug_command (frame, " s " )
183
+ fr, pc = debug_command (frame, :s )
180
184
@test stacklength (frame) > 2
181
185
push! (scopes, JuliaInterpreter. scopeof (fr))
182
186
end
@@ -195,21 +199,21 @@ struct B{T} end
195
199
end
196
200
""" ," file.jl" )
197
201
frame = JuliaInterpreter. enter_call_expr (:($ (test_macro)()))
198
- f, pc = debug_command (frame, " n " ) # a is set
199
- f, pc = debug_command (f, " n " ) # b is set
200
- f, pc = debug_command (f, " n " ) # x is set
201
- f, pc = debug_command (f, " n " ) # y is set
202
- f, pc = debug_command (f, " n " ) # z is set
203
- @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
204
208
end
205
209
206
210
@testset " Quoting" begin
207
211
# Test that symbols don't get an extra QuoteNode
208
212
f_symbol () = :limit => true
209
213
frame = JuliaInterpreter. enter_call (f_symbol)
210
- fr, pc = debug_command (frame, " s " )
211
- fr, pc = debug_command (fr, " finish" )
212
- @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
213
217
@test get_return (frame) == f_symbol ()
214
218
end
215
219
@@ -220,13 +224,13 @@ struct B{T} end
220
224
# depending on whether this is in or out of a @testset, the first statement may differ
221
225
stmt1 = fr. framecode. src. code[1 ]
222
226
if isexpr (stmt1, :call ) && @lookup (frame, stmt1. args[1 ]) === getfield
223
- fr, pc = debug_command (fr, " se " )
227
+ fr, pc = debug_command (fr, :se )
224
228
end
225
- fr, pc = debug_command (fr, " s " )
226
- fr, pc = debug_command (fr, " n " )
229
+ fr, pc = debug_command (fr, :s )
230
+ fr, pc = debug_command (fr, :n )
227
231
@test root (fr) != = fr
228
- fr, pc = debug_command (fr, " finish" )
229
- @test debug_command (fr, " finish" ) === nothing
232
+ fr, pc = debug_command (fr, : finish )
233
+ @test debug_command (fr, : finish ) === nothing
230
234
@test get_return (frame) === 2
231
235
end
232
236
@@ -236,15 +240,14 @@ struct B{T} end
236
240
return x + y
237
241
end
238
242
B_inst = B {Int} ()
239
- step_through (JuliaInterpreter. enter_call (B_inst, 10 )) == B_inst (10 )
240
- step_through_function (B_inst, 10 ) == B_inst (10 )
243
+ step_through (B_inst, 10 ) == B_inst (10 )
241
244
end
242
245
243
246
@testset " Exceptions" begin
244
247
# Don't break on caught exceptions
245
248
err_caught = Any[nothing ]
246
249
function f_exc_outer ()
247
- try
250
+ try
248
251
f_exc_inner ()
249
252
catch err;
250
253
err_caught[1 ] = err
@@ -254,18 +257,18 @@ struct B{T} end
254
257
end
255
258
f_exc_inner () = error ()
256
259
fr = JuliaInterpreter. enter_call (f_exc_outer)
257
- fr, pc = debug_command (fr, " s " )
258
- fr, pc = debug_command (fr, " n " )
259
- fr, pc = debug_command (fr, " n " )
260
- 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 )
261
264
@test get_return (fr) == 2
262
265
@test first (err_caught) isa ErrorException
263
266
@test stacklength (fr) == 1
264
267
265
268
err_caught = Any[nothing ]
266
269
fr = JuliaInterpreter. enter_call (f_exc_outer)
267
- fr, pc = debug_command (fr, " s " )
268
- debug_command (fr, " c " )
270
+ fr, pc = debug_command (fr, :s )
271
+ debug_command (fr, :c )
269
272
@test get_return (root (fr)) == 2
270
273
@test first (err_caught) isa ErrorException
271
274
@test stacklength (root (fr)) == 1
@@ -274,23 +277,23 @@ struct B{T} end
274
277
f_outer () = g_inner ()
275
278
g_inner () = error ()
276
279
fr = JuliaInterpreter. enter_call (f_outer)
277
- @test_throws ErrorException debug_command (fr, " finish" )
280
+ @test_throws ErrorException debug_command (fr, : finish )
278
281
@test stacklength (fr) == 1
279
282
280
283
# Break on error
281
284
try
282
- JuliaInterpreter . break_on_error[] = true
285
+ break_on ( :error )
283
286
fr = JuliaInterpreter. enter_call (f_outer)
284
- fr, pc = debug_command (JuliaInterpreter. finish_and_return!, fr, " finish" )
287
+ fr, pc = debug_command (JuliaInterpreter. finish_and_return!, fr, : finish )
285
288
@test fr. framecode. scope. name == :error
286
289
287
290
fundef () = undef_func ()
288
291
frame = JuliaInterpreter. enter_call (fundef)
289
- fr, pc = debug_command (frame, " s " )
292
+ fr, pc = debug_command (frame, :s )
290
293
@test isa (pc, BreakpointRef)
291
294
@test pc. err isa UndefVarError
292
295
finally
293
- JuliaInterpreter . break_on_error[] = false
296
+ break_off ( :error )
294
297
end
295
298
296
299
@testset " breakpoints" begin
@@ -308,21 +311,21 @@ struct B{T} end
308
311
method_start = ln - 9
309
312
fr = enter_call (f_bp, 2 )
310
313
@test JuliaInterpreter. linenumber (fr) == method_start + 1
311
- fr, pc = JuliaInterpreter. debug_command (fr, " c " )
314
+ fr, pc = JuliaInterpreter. debug_command (fr, :c )
312
315
# Hit the breakpoint x1
313
316
@test JuliaInterpreter. linenumber (fr) == method_start + 3
314
317
@test pc isa BreakpointRef
315
- fr, pc = JuliaInterpreter. debug_command (fr, " n " )
318
+ fr, pc = JuliaInterpreter. debug_command (fr, :n )
316
319
@test JuliaInterpreter. linenumber (fr) == method_start + 4
317
- fr, pc = JuliaInterpreter. debug_command (fr, " c " )
320
+ fr, pc = JuliaInterpreter. debug_command (fr, :c )
318
321
# Hit the breakpoint again x2
319
322
@test pc isa BreakpointRef
320
323
@test JuliaInterpreter. linenumber (fr) == method_start + 3
321
- fr, pc = JuliaInterpreter. debug_command (fr, " c " )
324
+ fr, pc = JuliaInterpreter. debug_command (fr, :c )
322
325
# Hit the breakpoint for the last time x3
323
326
@test pc isa BreakpointRef
324
327
@test JuliaInterpreter. linenumber (fr) == method_start + 3
325
- JuliaInterpreter. debug_command (fr, " c " )
328
+ JuliaInterpreter. debug_command (fr, :c )
326
329
@test get_return (fr) == 2
327
330
end
328
331
end
0 commit comments