Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Debugger fails to activate #251

Open
tbenst opened this issue Apr 24, 2020 · 9 comments
Open

Debugger fails to activate #251

tbenst opened this issue Apr 24, 2020 · 9 comments

Comments

@tbenst
Copy link

tbenst commented Apr 24, 2020

I find that @bp often doesn't do anything. Simple example below, where @bp in f works as expected but g does not.

julia> using Debugger
julia> function f(x)
       if x < 0
       @bp
       else
       println("all good")
       end
       end
f (generic function with 1 method)

julia> @run(f(2))
all good

julia> @run(f(-2))
Hit breakpoint:
In f(x) at REPL[11]:2
 1  function f(x)
 2  if x < 0
>3  @bp
 4  else
 5  println("all good")
 6  end
 7  end

About to run: return
1|debug> c

julia> function g(x)
       x = 4
       @bp
       3+x
       end
g (generic function with 1 method)

julia> @run g(3)
7
@KristofferC
Copy link
Member

Right now, you need to have at least a function call before the @bp.

julia> function g(x)
            3+x
            @bp
            3+x
        end
g (generic function with 1 method)

julia> @run g(3)
Hit breakpoint:
In g(x) at REPL[14]:2
 1  function g(x)
 2         3+x
●3         @bp
>4         3+x
 5         end

@pfitzseb
Copy link
Member

#148 should fix sinmple cases though.

@cgrudz
Copy link

cgrudz commented Jun 3, 2020

I am also having trouble with the above issue, and an issue mentioned in #249. Particularly, the n command in the debugger steps over lines until there is another call, as mentioned in the comment by @KristofferC. However, I often want to check that assignments have produced the correct entries / dimensions/ etc while I am developing code. Can the debugger be implemented to stop and step at each line of user written source code, rather than just calls? I was expecting behavior similar to the Python debugger with the pdb.set_trace(), n and c commands.

@timholy
Copy link
Member

timholy commented Jun 4, 2020

@cgrudz, just dev JuliaInterpreter and make this change:

$ git diff
diff --git a/src/commands.jl b/src/commands.jl
index a2d8a44..a033374 100644
--- a/src/commands.jl
+++ b/src/commands.jl
@@ -199,7 +199,8 @@ function until_line!(@nospecialize(recurse), frame::Frame, line::Union{Nothing,
     pc = next_until!(predicate, frame, istoplevel)
     (pc === nothing || isa(pc, BreakpointRef)) && return pc
     maybe_step_through_kwprep!(recurse, frame, istoplevel)
-    maybe_next_call!(recurse, frame, istoplevel)
+    return frame.pc
+    # maybe_next_call!(recurse, frame, istoplevel)
 end
 until_line!(frame::Frame, line::Union{Nothing, Integer}=nothing, istoplevel::Bool=false) = until_line!(finish_and_return!, frame, line, istoplevel)
 

Be sure to report back whether you like it or not.

@cgrudz
Copy link

cgrudz commented Jun 4, 2020

@timholy, thanks for this, I apologize for not understanding but what do you mean by dev JuliaInterpreter? I'd definitely like to give it a try but I'm just getting started with Julia.

@timholy
Copy link
Member

timholy commented Jun 4, 2020

Sorry, that's a package management command. See https://julialang.github.io/Pkg.jl/v1/managing-packages/ for documentation; briefly, you hit ] at the REPL, at which point it switches into package-management mode, and then you type dev JuliaInterpreter. From that point you're using a full git-checkout located in your .julia/dev folder. You can edit the source code there freely. Just ]free JuliaInterpreter if you want to go back to official releases.

When I make that change locally, we actually pass our tests. One view might be that this is a sign that we could safely make that change, and then stepping through assignment statements would be possible. Alternatively, it could be a sign that our test coverage simply isn't adequate. I am not confident in ruling out the latter, which is why I suggest doing this as an experiment to see how you like it.

I'd check this myself, but most of my real-world coding projects over the last couple of weeks (and likely for the next week or more) have been at a lower level where the infrastructure for the debugger isn't yet defined. So realistically I won't know how this works in practice anytime soon. Hence I wanted to give you the tools to try this for yourself and see how it works out.

@cgrudz
Copy link

cgrudz commented Jun 4, 2020

@timholy thanks for this! That's a quite helpful explanation, I just made the edit and I'll be giving this a try. I'm testing speed improvements re-writing numpy code into Julia and so far so good -- I'll keep this posted with my experience of the debugger.

@cgrudz
Copy link

cgrudz commented Jul 30, 2020

@timholy, I've put a decent amount of work now into converting the code and using the debugger with the edit you suggested above -- it has worked well for line by line stepping and stepping into functions, and basically matches my experience with ipdb and pdb.

Thanks for the help!

@dafred94
Copy link

@cgrudz, just dev JuliaInterpreter and make this change:

$ git diff
diff --git a/src/commands.jl b/src/commands.jl
index a2d8a44..a033374 100644
--- a/src/commands.jl
+++ b/src/commands.jl
@@ -199,7 +199,8 @@ function until_line!(@nospecialize(recurse), frame::Frame, line::Union{Nothing,
     pc = next_until!(predicate, frame, istoplevel)
     (pc === nothing || isa(pc, BreakpointRef)) && return pc
     maybe_step_through_kwprep!(recurse, frame, istoplevel)
-    maybe_next_call!(recurse, frame, istoplevel)
+    return frame.pc
+    # maybe_next_call!(recurse, frame, istoplevel)
 end
 until_line!(frame::Frame, line::Union{Nothing, Integer}=nothing, istoplevel::Bool=false) = until_line!(finish_and_return!, frame, line, istoplevel)
 

Be sure to report back whether you like it or not.

I did exactly this and it still won't help in my case.
My code:

# in file dbg_test.jl
import Debugger

function myfunc(x::Int, y::Int)
  println("yehaw")
  Debugger.@bp
  a = 33.55
  return x*y*a
end

for i in 1:10
  println(myfunc(i, 10))
end

Then if i run julia dbg_test.jl, it will print the lines as expected but never enter the debugger interface.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants