timholy / Rebugger.jl

An expression-level debugger for Julia with a provocative command-line (REPL) user interface
Other
171 stars 18 forks source link

Doesn't seem to work on Windows due to shortcuts #14

Closed musm closed 6 years ago

musm commented 6 years ago

I can't get any of the shortcuts to work.

E.g, entering F5 actually enters the E character in the Julia prompt. Entering Alt+Shift+Enter also doesn't work to step.

This is probably a core julia issue not related to Rebugger, but it prevents its usage.

timholy commented 6 years ago

Hmm. can you report the result of read(stdin, Char) and then hitting the two crucial keys?

Eg: for Alt-Shift-Enter I get

julia> read(stdin, Char)
^[^[OM

and for F5 I get

julia> read(stdin, Char)
^[[15~

Those are a little hard to translate, but I think I can figure it out :smile:.

musm commented 6 years ago

Hmm, fresh julia 1.0 repl started from CMD

F5

julia> read(stdin,Char)
5
'5': ASCII/Unicode U+0035 (category Nd: Number, decimal digit)

I can't hit ALt-Shift-Enter with reading a single Char since that sets the CMD window into full screen.

musm commented 6 years ago

Doing the same from a julia session started from ConEmu gives

julia> read(stdin,Char)

'\r': ASCII/Unicode U+000d (category Cc: Other, control)

julia>
timholy commented 6 years ago

Which were you hitting? Is the top one F5 and the bottom one Alt-Shift-Enter? Do you have to do something to turn on your function keys? On my external keyboard I have to hold down "Fn", otherwise I just get a 5 (which is what you got).

musm commented 6 years ago

Both are for F5.

Yep my keyboard has an extra row for the function keys .

musm commented 6 years ago

Sorry both give me '\r': ASCII/Unicode U+000d (category Cc: Other, control)

musm commented 6 years ago

I don't think you can actually use the function keys, at least not in CMD. They seem to correspond to short cuts. When trying to use them in julia they spit junk. Hitting alt+shift+enter just maximize the window.

timholy commented 6 years ago

Can you configure your keybindings? "stepin" used to be F11 (which is what some other debuggers use for stepin), but for many people that's "fullscreen." Indeed, I had forgotten that when I first made that choice I had to go to (KDE) Kmenu->System Settings->Shortcuts and disable the F11 key.

This is the second key binding I've chosen and it doesn't work either (see also #15). I am beginning to fear that no matter what I choose, it's not going to work for some people. I think my best hope is to make one set of default choices on Windows, a different one on Linux, and a third on OSX. But with Linux in particular there are so many window managers presumably with different defaults...

Since there's no way I can replicate what you're experiencing, I'm going to need some help from you to determine "who's taking those keybindings" and whether it's configurable. (Just to check, CMD = windows command line?)

timholy commented 6 years ago

One more thing, since I'm struggling with Alt-Shift-Enter in another issue can you tell me whether that's working for you? Is it only F5 that's causing you trouble? nvm, I see you said that's "maximize window." Can you configure that away? It doesn't seem to be standard: https://en.wikipedia.org/wiki/Table_of_keyboard_shortcuts seems to suggest it should be "win+uparrow"

pfitzseb commented 6 years ago

Alt-Enter is standard for fullscreen in cmd. FWIW neither of the shortcuts work for me in Juno's REPL or powershell either.

Using something like ) works if adjusted here, but I couldn't figure out any function key or enter keybindings that work on Windows.

Function keys are indeed used as shortcuts. Switching the terminal to raw mode allows reading all of those keybindings afaict, but that obviously doesn't help much...

timholy commented 6 years ago

OK, it looks like we'll definitely need separate key bindings for Windows, since neither one seems to work now. Does anyone have any suggestions?

pfitzseb commented 6 years ago

I kinda like Meta-E for stepin and would like Meta-C for stacktrace, but there seems to be something wrong with LineEdit.add_nested_key! where it klobbers previous nested keybindings or something like that.

Code below works for stepin on Windows and Linux, but I can't test on MacOS:

add_key_stacktrace!(keymap) = nothing # LineEdit.add_nested_key!(keymap, "\x1bc", (s, o...) -> capture_stacktrace(s))

add_key_stepin!(keymap) = LineEdit.add_nested_key!(keymap, "\x1be", (s, o...) -> (stepin(s); enter_rebug(s)))

# These work at the `julia>` prompt and the `rebug>` prompt
const rebugger_modeswitch = Dict{Any,Any}(
    # Alt-C
    # "\x1bc"   => (s, o...) -> capture_stacktrace(s),
    # Alt-E
    "\x1be"   => (s, o...) -> (stepin(s); enter_rebug(s)),
    # Deprecate F11
    "\e[23~"   => (s, o...) -> (stepin(s); rebug_prompt_ref[].repl.header.warnmsg="stepin is now Alt-Shift-Enter"; enter_rebug(s)),
)
timholy commented 6 years ago

Thanks for the suggestion @pfitzseb! Meta-c (with a lowercase c) already means change next word to titlecase, but for me Meta-c and Meta-C (i.e., Meta-Shift-c ) is distinguishable from Meta-c. True for you (and Juno) too?

Meta-e seems available. I wonder if we should use Meta-Shift-e just for consistency? It's also available.

pfitzseb commented 6 years ago

Meta-Shift-e (and similar) don't seem to work for me on Windows (neither in Juno nor in cmd).

What do you think about Meta-e (e for "Enter expression") and Meta-s (s for "Stacktrace") instead?

timholy commented 6 years ago

I could go with that. I was kind of wondering about saving Meta-s (or perhaps Meta-Shift-s ) for "save these changes I've made at the REPL back to the file". (The idea being you do your debugging at the REPL but once you fix it's convenient not to have to find the file and copy the same change back to it.) But that's much less of a priority than simply getting the basic functionality working for most people, so I'm not attached to that idea at all.

musm commented 6 years ago

Well there definitely is a way to capture F5 and other hotkeys in windows.

See https://msdn.microsoft.com/en-us/library/windows/desktop/ms646309%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396

Example console programs can be found, .i.e http://www.cplusplus.com/forum/windows/47266/

These seems better suited for another julia module for keyboard interaction / keybindings, although not sure if there is pre existing work here.

musm commented 6 years ago

I can't get this package to work at all now with any keybindings :( Anyone can confirm?

timholy commented 6 years ago

FWIW nothing has changed with either Revise or Rebugger recently (I haven't had time). Last Rebugger release was Aug 29 and last Revise release was Oct 3. So if this is a recent change it may be due to some other package.

musm commented 6 years ago

exactly why it's so strange why it doesn't work anymore. I wonder if it is due to switching to julia 1.0.1, which might have fixed some repl code that then subtly broke Rebugger on windows...

musm commented 6 years ago

I'm hoping at least someone else can confirm before trying to investigate

pfitzseb commented 6 years ago

I'm getting

julia> show([1,2,3])
[1, 2, 3]
UndefVarError: shbegin not defined while evaluating shbegin
    #= /home/pfitzseb/.julia/packages/Rebugger/tYJpU/src/debug.jl:329 =#
    (Main.Rebugger).stashed[] = (ow, ([1, 2, 3],), (Main.Rebugger).kwstasher(; ))
    #= /home/pfitzseb/.julia/packages/Rebugger/tYJpU/src/debug.jl:330 =#
    throw(Main.Rebugger.StopException())
end

in both Windows and Linux when pressing Meta-E.

timholy commented 6 years ago

It was very helpful to see the backtrace. It seems that point is being credited with an extra two characters: the sh is presumably from show and begin is the beginning of the block. On Linux/REPL I can get the same backtrace if I move point so it's sitting on top of the o in show before I hit meta-e.

Best option would be to insert debugging statements here.

pfitzseb commented 6 years ago

Ha, true. Shoulda noticed that, I guess. I'm fairly certain the keybindings are working fine on Windows though.

Unfortunately I'm also getting a new error when the cursor is in the right position:

julia> using Revise, Rebugger

julia> using Example

julia> Example.hello("you")
"Hello, you"

The expression for method hello(who::String) in Example at /home/pfitzseb/.julia/packages/Example/kH44X/src/Example.jl:4 was unavailable. Perhaps it was untracked or generated by code.       
julia> Revise.track("/home/pfitzseb/.julia/packages/Example/kH44X/src/Example.jl")

rebug> Example.hello("you")
"Hello, you"

The expression for method hello(who::String) in Example at /home/pfitzseb/.julia/packages/Example/kH44X/src/Example.jl:4 was unavailable. Perhaps it was untracked or generated by code.
timholy commented 6 years ago

Just to check, you're no longer able to replicate a failure of the key bindings per se, right?

Unfortunately I'm also getting a new error when the cursor is in the right position:

Hmm, that's surprising:

julia> using Example
[ Info: Recompiling stale cache file /home/tim/.julia/compiled/v1.0/Example/lLvWP.ji for Example [7876af07-990d-54b4-ab0e-23690620f79a]

julia> hello("you")
"Hello, you"

hello(who::String) in Example at /home/tim/.julia/packages/Example/kH44/src/Example.jl:4
  who = you
rebug> @eval Example let (who,) = Main.Rebugger.getstored("cd25f1a0-dc54-11e8-04c3-137d2d68d070")
       begin
           "Hello, $(who)"
       end
       end
"Hello, you"

But it's definitely the case that Revise/Rebugger can't find the expression for everything. I haven't had time recently to track it down. Easiest way to debug is

julia> m = @which hello("you")
hello(who::String) in Example at /home/tim/.julia/packages/Example/kH44/src/Example.jl:4

julia> Revise.get_def(m)
:(hello(who::String) = begin
          "Hello, $(who)"
      end)

and if that fails, track down the error. (The logging macros in get_def make it hard to Rebug, but if you comment those out...)

pfitzseb commented 6 years ago

Disregard that error, I was on an old version of Rebugger. Things work fine now, except for the keybinding error when the cursor isn't positioned "correctly".

timholy commented 6 years ago

OK, so @musm you may be back in the land of "unconfirmed." What exactly happens when you hit the key combinations. Nothing?

musm commented 6 years ago

t

@timholy does the above gif help at all

musm commented 6 years ago

I tried to use

julia> str = read(stdin, String)

to help identify what keystrokes are being identified, but it frezes my REPL.

timholy commented 6 years ago

Do you hit Ctrl-D twice after typing something?

musm commented 6 years ago

Do you hit Ctrl-D twice after typing something?

Yes, but it does nothing

t

Apologies, I know I am not providing much, but I just don't know what to provide. From experience the windows julia REPL is buggy, so I wouldn't at all be surprised if this was a julia bug and nothing to do with Rebugger.

pfitzseb commented 6 years ago

What's ]st return? I set up a completley fresh Julia install in a Windows VM and Rebugger works fine there.

musm commented 6 years ago
(v1.0) pkg> st
    Status `C:\Users\Mus\.julia\environments\v1.0\Project.toml`
  [537997a7] AbstractPlotting v0.9.0
  [7d9fca2a] Arpack v0.3.0
  [6e4b80f9] BenchmarkTools v0.4.1
  [b99e7846] BinaryProvider v0.5.2
  [c5f51814] CUDAdrv v0.8.6
  [be33ccc6] CUDAnative v0.9.1
  [7057c7e9] Cassette v0.1.2
  [5ae59095] Colors v0.9.5
  [861a8166] Combinatorics v0.7.0
  [34da2185] Compat v1.3.0
  [8f4d0f93] Conda v1.1.1
  [3a865a2d] CuArrays v0.8.1
  [a93c6f00] DataFrames v0.14.1
  [0c46a032] DifferentialEquations v5.3.1
  [aaf54ef3] DistributedArrays v0.5.1
  [31c24e10] Distributions v0.16.4
  [e30172f5] Documenter v0.19.7
  [8f5d6c58] EzXML v0.9.0
  [7a1cc6ca] FFTW v0.2.4
  [53c48c17] FixedPointNumbers v0.5.3
  [587475ba] Flux v0.6.8
  [f6369f11] ForwardDiff v0.10.0
  [b38be410] FreeType v2.1.1
  [663a7486] FreeTypeAbstraction v0.4.1
  [0c68f7d7] GPUArrays v0.5.0
  [28b8d3ca] GR v0.35.0
  [4d00f742] GeometryTypes v0.6.2
  [f67ccb44] HDF5 v0.10.2
  [d334cf70] IACA v0.0.0 [`C:\Users\Mus\.julia\dev\IACA`]
  [7073ff75] IJulia v1.13.0
  [6a3955dd] ImageFiltering v0.5.0
  [6218d12a] ImageMagick v0.7.1
  [d0351b0e] InspectDR v0.3.3
  [b964fa9f] LaTeXStrings v1.0.3
  [522f3ed2] LibExpat v0.5.0
  [093fc24a] LightGraphs v1.2.0
  [9c8b4983] LightXML v0.8.0
  [10e44e05] MATLAB v0.7.0
  [1914dd2f] MacroTools v0.4.4
  [ee78f7c6] Makie v0.9.0
  [66fc600b] ModernGL v1.0.0
  [429524aa] Optim v0.17.1
  [bac558e1] OrderedCollections v1.0.2
  [9b87118b] PackageCompiler v0.5.0
  [91a5bcdd] Plots v0.21.0
  [438e738f] PyCall v1.18.5
  [d330b81b] PyPlot v2.6.3
  [ce6b1742] RDatasets v0.6.1
  [a223df75] Reactive v0.8.2
  [ee283ea6] Rebugger v0.1.4
  [295af30f] Revise v0.7.12
  [fdea26ae] SIMD v2.0.1
  [3e6341c9] SLEEF v0.5.1 [`C:\Users\Mus\.julia\dev\SLEEF`]
  [276daf66] SpecialFunctions v0.7.1
  [90137ffa] StaticArrays v0.9.2
  [24249f21] SymPy v0.8.1
  [37b6cedf] Traceur v0.2.0
  [b8865327] UnicodePlots v0.3.1
  [1986cc42] Unitful v0.12.0
  [37e2e46d] LinearAlgebra
  [d6f4376e] Markdown
  [8dfed614] Test
pfitzseb commented 6 years ago

How are you changing the Julia prompt? Can you try starting Julia without your startup file?

musm commented 6 years ago

wow, you hit the nail right on the head

here's my startup file

not using it fixes the problem

import REPL
import Pkg

atreplinit() do repl
    repl.interface = REPL.setup_interface(repl)
    repl.interface.modes[1].prompt =  () -> begin
        str = Pkg.REPLMode.promptf()
        occursin(r"(v[0-9].[0-9])", str) ? "> " : str[1:end-6] * " > "
    end
end

try
    @eval using BenchmarkTools
catch
    @warn "Could not load BenchmarkTools."
end

# try
#     @eval using Revise
#     # Turn on Revise's file-watching behavior
#     Revise.async_steal_repl_backend()
# catch
#     @warn "Could not load Revise."
# end

# try
#     @eval using Rebugger
#     # Activate Rebugger's key bindings
#     atreplinit(Rebugger.repl_init)
# catch
#     @warn "Could not turn on Rebugger key bindings."
# end
timholy commented 6 years ago

Great, I think we can close this now [EDIT: doh, already closed]. Thanks @pfitzseb!

@musm, Revise has periodically changed its startup recommendations. Latest is https://timholy.github.io/Revise.jl/latest/config.html

musm commented 6 years ago

@timholy

I guess the issue then is that it does not seem possible to utilize Rebugger with a custom prompt as defined below

import REPL
import Pkg
atreplinit() do repl
    Rebugger.repl_init

    repl.interface = REPL.setup_interface(repl)
    repl.interface.modes[1].prompt =  () -> begin
        str = Pkg.REPLMode.promptf()
        occursin(r"(v[0-9].[0-9])", str) ? "> " : str[1:end-6] * " > "
    end
end
timholy commented 6 years ago

Can you file this as a separate issue?