Debugger.jl icon indicating copy to clipboard operation
Debugger.jl copied to clipboard

Debugger jumps to the wrong "end"

Open ghost opened this issue 6 years ago • 3 comments

I have the following simple code

module TestIf
export test_code
function test_code(head, top_ex)
    for ex in top_ex.args
        if typeof(ex) == LineNumberNode
            continue
        elseif typeof(ex) == Expr
            println("Expression!")
        else
            println("nothing!")
        end
    end
end
end

Then I run Debugger like this:

@enter test_code(:Test, quote
       a = Float()
       @someMacro begin
       b = a + 1
       end
       end)

then I do 'n' two times and get this stage:

1|debug> n
In test_code(head, top_ex) at C:\Users\Cong Van\Documents\Debugger.jl\test\TestIf.jl:4
  6              continue
  7          elseif typeof(ex) == Expr
  8              println("Expression!")
  9          else
>10              println("nothing!")
 11          end
 12      end
 13  end

which is not correct. I think it should be at the 'end' of if statement. Any idea?

ghost avatar Apr 12 '19 18:04 ghost

Julia's iterator protocol lowers for loops into iterate statements as described in https://docs.julialang.org/en/v1/manual/interfaces/index.html#man-interface-iteration-1 which is where we are stopping at the second n. We might want to have a default mode that skips over iterate calls since they are not present in the original source code.

KristofferC avatar Apr 12 '19 19:04 KristofferC

So, I tried to trace this problem and the active line number comes from "JuliaInterpreter.whereis(meth)", tracing to "codeloc = code.codelocs[idx]", which is from the field "Core.CoreInfo.codelocs". I assume codelocs is the mapping between the "compiled codes" and the original Julia codes. Should this mapping be improved? Like mapping "iterate" line to the "for" loop line?

sonolac avatar Apr 12 '19 21:04 sonolac

Well, that iterate call comes after the function body so it is a bit odd to map it to a line

1] for x in A
2]    print(x)
3] end

is lowered into something like (with line numbers to the left)

1] tmp = iterate(A)
1] tmp == nothing && @goto loop_end
1] @label loop_start
1] x, state = tmp
2] print(x)
2] tmp = iterate(A, state)
2] tmp == nothing && @goto loop_end
2] @goto loop_start
2] @label loop_end

It would be a bit odd to map the second iterate call to line number 1.

KristofferC avatar Apr 15 '19 14:04 KristofferC