Skip to content

Commit

Permalink
Merge pull request #97 from JuliaDebug/teh/linenumber
Browse files Browse the repository at this point in the history
Try harder to find the line number
  • Loading branch information
timholy authored Mar 5, 2019
2 parents 153e235 + 026e81b commit 8a3e084
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/interpret.jl
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ determined, `loc == nothing`. Otherwise `loc == (filepath, line)`.
When `frame` represents top-level code,
"""
function CodeTracking.whereis(framecode::JuliaFrameCode, pc)
codeloc = framecode.code.codelocs[convert(Int, pc)]
codeloc = codelocation(framecode.code, convert(Int, pc))
codeloc == 0 && return nothing
lineinfo = framecode.code.linetable[codeloc]
return framecode.scope isa Method ?
Expand All @@ -700,12 +700,21 @@ CodeTracking.whereis(frame::JuliaStackFrame, pc=frame.pc[]) = whereis(frame.code
# Note: linenumber is now an internal method for use by `next_line!`
# If you want to know the actual line number in a file, call `whereis`.
function linenumber(framecode::JuliaFrameCode, pc)
codeloc = framecode.code.codelocs[convert(Int, pc)]
codeloc = codelocation(framecode.code, convert(Int, pc))
codeloc == 0 && return nothing
return framecode.code.linetable[codeloc].line
end
linenumber(frame::JuliaStackFrame, pc=frame.pc[]) = linenumber(frame.code, pc)

function codelocation(code::CodeInfo, idx)
codeloc = code.codelocs[idx]
while codeloc == 0 && code.code[idx] === nothing && idx < length(code.code)
idx += 1
codeloc = code.codelocs[idx]
end
return codeloc
end

"""
stmtidx = statementnumber(frame, line)
Expand Down
3 changes: 3 additions & 0 deletions test/interpret.jl
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ frame = JuliaInterpreter.enter_call(f, 3)
@test whereis(frame, JuliaInterpreter.JuliaProgramCounter(1))[2] == defline + 1
@test whereis(frame, JuliaInterpreter.JuliaProgramCounter(3))[2] == defline + 4
@test whereis(frame, JuliaInterpreter.JuliaProgramCounter(5))[2] == defline + 6
m = which(iterate, Tuple{Dict}) # this method has `nothing` as its first statement and codeloc == 0
framecode = JuliaInterpreter.get_framecode(m)
@test JuliaInterpreter.linenumber(framecode, 1) == m.line

# issue #28
let a = ['0'], b = ['a']
Expand Down

0 comments on commit 8a3e084

Please sign in to comment.