Skip to content

Commit 026e81b

Browse files
committed
Try harder to find the line number
1 parent 5855707 commit 026e81b

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/interpret.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ determined, `loc == nothing`. Otherwise `loc == (filepath, line)`.
689689
When `frame` represents top-level code,
690690
"""
691691
function CodeTracking.whereis(framecode::JuliaFrameCode, pc)
692-
codeloc = framecode.code.codelocs[convert(Int, pc)]
692+
codeloc = codelocation(framecode.code, convert(Int, pc))
693693
codeloc == 0 && return nothing
694694
lineinfo = framecode.code.linetable[codeloc]
695695
return framecode.scope isa Method ?
@@ -700,12 +700,21 @@ CodeTracking.whereis(frame::JuliaStackFrame, pc=frame.pc[]) = whereis(frame.code
700700
# Note: linenumber is now an internal method for use by `next_line!`
701701
# If you want to know the actual line number in a file, call `whereis`.
702702
function linenumber(framecode::JuliaFrameCode, pc)
703-
codeloc = framecode.code.codelocs[convert(Int, pc)]
703+
codeloc = codelocation(framecode.code, convert(Int, pc))
704704
codeloc == 0 && return nothing
705705
return framecode.code.linetable[codeloc].line
706706
end
707707
linenumber(frame::JuliaStackFrame, pc=frame.pc[]) = linenumber(frame.code, pc)
708708

709+
function codelocation(code::CodeInfo, idx)
710+
codeloc = code.codelocs[idx]
711+
while codeloc == 0 && code.code[idx] === nothing && idx < length(code.code)
712+
idx += 1
713+
codeloc = code.codelocs[idx]
714+
end
715+
return codeloc
716+
end
717+
709718
"""
710719
stmtidx = statementnumber(frame, line)
711720

test/interpret.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,9 @@ frame = JuliaInterpreter.enter_call(f, 3)
219219
@test whereis(frame, JuliaInterpreter.JuliaProgramCounter(1))[2] == defline + 1
220220
@test whereis(frame, JuliaInterpreter.JuliaProgramCounter(3))[2] == defline + 4
221221
@test whereis(frame, JuliaInterpreter.JuliaProgramCounter(5))[2] == defline + 6
222+
m = which(iterate, Tuple{Dict}) # this method has `nothing` as its first statement and codeloc == 0
223+
framecode = JuliaInterpreter.get_framecode(m)
224+
@test JuliaInterpreter.linenumber(framecode, 1) == m.line
222225

223226
# issue #28
224227
let a = ['0'], b = ['a']

0 commit comments

Comments
 (0)