Skip to content

Commit bf14122

Browse files
authored
Merge pull request #96 from JuliaDebug/teh/breakpoints_fileline
Support `breakpoint(filename, lineno)`
2 parents 390bb66 + 0fb7830 commit bf14122

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/breakpoints.jl

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ using JuliaInterpreter: JuliaFrameCode, JuliaStackFrame, BreakpointState,
55
truecondition, falsecondition, prepare_framecode, get_framecode,
66
sparam_syms, linenumber, statementnumber
77
using Base.Meta: isexpr
8-
using InteractiveUtils
8+
using CodeTracking, InteractiveUtils
99

1010
export @breakpoint, breakpoint, enable, disable, remove
1111

@@ -238,6 +238,33 @@ function breakpoint(f, condition::Condition=nothing)
238238
return bps
239239
end
240240

241+
"""
242+
breakpoint(filename, line)
243+
244+
Set a breakpoint at the specified file and line number.
245+
"""
246+
function breakpoint(filename::AbstractString, line::Integer, args...)
247+
sigs = signatures_at(filename, line)
248+
if sigs === nothing
249+
# TODO: build a Revise-free fallback. Note this won't work well for methods with keywords.
250+
error("no signatures found at $filename, $line. Restarting and `using Revise` may fix this problem.")
251+
end
252+
for sig in sigs
253+
method = JuliaInterpreter.whichtt(sig)
254+
method === nothing && continue
255+
# Check to see if this method really contains that line. Methods that fill in a default positional argument,
256+
# keyword arguments, and @generated sections may not contain the line.
257+
_, line1 = whereis(method)
258+
offset = line1 - method.line
259+
src = JuliaInterpreter.get_source(method)
260+
lastline = src.linetable[end]
261+
if lastline.line + offset >= line
262+
return breakpoint(method, line, args...)
263+
end
264+
end
265+
error("no signatures found at $filename, $line among the signatures $sigs")
266+
end
267+
241268
"""
242269
@breakpoint f(args...) condition=nothing
243270
@breakpoint f(args...) line condition=nothing

test/breakpoints.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@ end
7070
@test isa(bp, Breakpoints.BreakpointRef)
7171
@test JuliaInterpreter.finish_stack!(stack) == 2
7272

73+
# Breakpoints by file/line
74+
if isdefined(Main, :Revise)
75+
remove()
76+
method = which(JuliaInterpreter.locals, Tuple{JuliaStackFrame})
77+
breakpoint(String(method.file), method.line+1)
78+
frame = JuliaInterpreter.enter_call(loop_radius2, 2)
79+
ret = @interpret JuliaInterpreter.locals(frame)
80+
@test isa(bp, Breakpoints.BreakpointRef)
81+
end
82+
7383
# Direct return
7484
@breakpoint gcd(1,1) a==5
7585
@test @interpret(gcd(10,20)) == 10

0 commit comments

Comments
 (0)