From 98e7497e4d255d6cce4a9f8847359e6d17454723 Mon Sep 17 00:00:00 2001 From: Timo Kluck Date: Mon, 12 Nov 2018 22:57:46 +0100 Subject: [PATCH] Fix backtrace line numbers following macros 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`. --- src/julia-syntax.scm | 4 ++-- test/backtrace.jl | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/julia-syntax.scm b/src/julia-syntax.scm index 904ad0164cdc6..a2b37fe1259f9 100644 --- a/src/julia-syntax.scm +++ b/src/julia-syntax.scm @@ -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)) diff --git a/test/backtrace.jl b/test/backtrace.jl index 0da3779c88eda..9c7847ac34741 100644 --- a/test/backtrace.jl +++ b/test/backtrace.jl @@ -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