Skip to content

Commit

Permalink
Fix backtrace line numbers following macros
Browse files Browse the repository at this point in the history
The `CodeInfo` block has a field `codelocs` that indexes into an array
with full `LineInfoNode` objects. This data model allows de-duplication,
and in practice it does (only) `uniq`-style deduplication, i.e. only
consecutive equal objects are deduplicated by this scheme.

The lambda `compact-ir` generates this structure. This commit fixes a bug
where it mixes monotonously increasing the indices (for `codeloc`) with
push/pop operations. This is wrong because the latest `LineInfoNode`
object is always at the end of the current size of the array; not
one position after the current `LineInfoNode`.
  • Loading branch information
tkluck committed Nov 12, 2018
1 parent 96ce5ba commit 98e7497
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -4049,13 +4049,13 @@ f(x) = yt(x)
`(line ,current-line ,current-file)
`(line ,current-line ,current-file ,(caar locstack)))
linetable))
(set! current-loc (+ 1 current-loc)))))
(set! current-loc (- (length linetable) 1)))))
((and (length> e 2) (eq? (car e) 'meta) (eq? (cadr e) 'push_loc))
(set! locstack (cons (list current-loc current-line current-file) locstack))
(set! current-file (caddr e))
(set! current-line 0)
(set! linetable (cons `(line ,current-line ,current-file ,current-loc) linetable))
(set! current-loc (+ 1 current-loc)))
(set! current-loc (- (length linetable) 1)))
((and (length= e 2) (eq? (car e) 'meta) (eq? (cadr e) 'pop_loc))
(let ((l (car locstack)))
(set! locstack (cdr locstack))
Expand Down
12 changes: 12 additions & 0 deletions test/backtrace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,15 @@ let bt, found = false
end
@test found
end

# issue 28618
let bt, found = false
@info ""
bt = backtrace()
for frame in map(StackTraces.lookup, bt)
if frame[1].line == @__LINE__() - 2 && frame[1].file == Symbol(@__FILE__)
found = true; break
end
end
@test found
end

0 comments on commit 98e7497

Please sign in to comment.