timholy / Rebugger.jl

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

Rebugger fails to register the keybind when compiled with PackageCompiler #62

Closed tkf closed 5 years ago

tkf commented 5 years ago

To reproduce, run this Makefile like this

git clone https://github.com/tkf/julia-sysimage-recipes
cd julia-sysimage-recipes/rebugger
make
# make JULIA=$(which custom-julia)  # for using another julia executable
make repl

This launches a Julia REPL with Rebugger AOT-compiled into the system image. You can see that rebugrepl_init is not called properly:

$ make repl
$(cat build/1.1.0/julia_executable) --sysimage build/1.1.0/sys.so --startup-file=no
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.1.0 (2019-01-21)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> using Rebugger

julia> Rebugger.rebug_prompt_ref
Base.RefValue{Union{Nothing, Prompt}}(nothing)

julia> Rebugger.rebugrepl_init()

julia> Rebugger.rebug_prompt_ref
Base.RefValue{Union{Nothing, Prompt}}("Prompt(\"rebug> \",...)")

To see the actual error, you can edit Rebugger.__init__ like this

diff --git a/src/Rebugger.jl b/src/Rebugger.jl
index 99ed2d0..8150197 100644
--- a/src/Rebugger.jl
+++ b/src/Rebugger.jl
@@ -54,7 +54,14 @@ function rebugrepl_init(main_repl, repl_inited)
 end

 function __init__()
-    schedule(Task(rebugrepl_init))
+    task = Task() do
+        try
+            rebugrepl_init()
+        catch exception
+            @error "Initializing Rebugger's keybinding failed" exception=(exception, catch_backtrace())
+        end
+    end
+    schedule(task)
 end

which yields (after compiling it with PackageCompiler):

┌ Error: Initializing Rebugger's keybinding failed
│   exception =
│    Conflicting definitions for keyseq \es within one keymap
│    Stacktrace:
│     [1] error(::String) at ./error.jl:33
│     [2] #add_nested_key!#22(::Any, ::Any, ::Dict, ::Any, ::Any) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/REPL/src/LineEdit.jl:1277
│     [3] (::getfield(REPL.LineEdit, Symbol("#kw##add_nested_key!")))(::Any, ::typeof(REPL.LineEdit.add_nested_key!), ::Dict, ::Any, ::Any) at ./none:0
│     [4] #add_keybindings#28(::Bool, ::Base.Iterators.Pairs{Symbol,String,Tuple{Symbol,Symbol,Symbol},NamedTuple{(:stacktrace, :interpret, :stepin),Tuple{String,String,String}}}, ::Function, ::REPL.LineEditREPL) at /home/takafumi/.julia/dev/Rebugger/src/ui.jl:511
│     [5] (::getfield(Rebugger, Symbol("#kw##add_keybindings")))(::NamedTuple{(:override, :stacktrace, :interpret, :stepin),Tuple{Bool,String,String,String}}, ::typeof(Rebugger.add_keybindings), ::REPL.LineEditREPL) at ./none:0
│     [6] rebugrepl_init(::REPL.LineEditREPL, ::Bool) at /home/takafumi/.julia/dev/Rebugger/src/Rebugger.jl:57
│     [7] rebugrepl_init() at /home/takafumi/.julia/dev/Rebugger/src/Rebugger.jl:44
│     [8] (::getfield(Rebugger, Symbol("##35#36")))() at /home/takafumi/.julia/dev/Rebugger/src/Rebugger.jl:64
└ @ Rebugger ~/.julia/dev/Rebugger/src/Rebugger.jl:66
tkf commented 5 years ago

0.3.1 fixes the issue for my setup. Thanks a lot!