forked from gcv/julia-snail
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use DebugAdapter.jl + dape to provide debugging capabilities from repl. Requires julia-vscode/DebugAdapter.jl#95 to be merged first.
- Loading branch information
Showing
4 changed files
with
106 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
## This program is free software; you can redistribute it and/or modify | ||
## it under the terms of the GNU General Public License as published by | ||
## the Free Software Foundation, either version 3 of the License, or | ||
## (at your option) any later version. | ||
|
||
## This program is distributed in the hope that it will be useful, | ||
## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
## GNU General Public License for more details. | ||
|
||
## You should have received a copy of the GNU General Public License | ||
## along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
module Debug | ||
|
||
export @enter, @run | ||
|
||
Main.JuliaSnail.@with_pkg_env (@__DIR__) begin | ||
import DebugAdapter | ||
import Sockets | ||
import Logging | ||
end | ||
|
||
port = 12124 | ||
conn = missing | ||
session = missing | ||
server = missing | ||
ready = Channel{Bool}(1) | ||
|
||
function init() | ||
# Logging.global_logger(Logging.SimpleLogger(Logging.Debug)) | ||
end | ||
|
||
function start() | ||
global server = Sockets.listen(port) | ||
Threads.@spawn begin | ||
while true | ||
@debug "Listening on port $port" | ||
global conn = Sockets.accept(server) | ||
@debug "Accepted connection" | ||
global session = DebugAdapter.DebugSession(conn) | ||
# When using the attach request, the terminate request does not work. | ||
session.capabilities.supportsTerminateRequest = false | ||
@debug "Starting debug session" | ||
put!(ready, true) | ||
DebugAdapter.run(session) | ||
end | ||
end | ||
end | ||
|
||
function run(mod, code, filepath; stop_on_entry=false) | ||
if ismissing(server) | ||
start() | ||
end | ||
soe = ":json-false" | ||
if stop_on_entry | ||
soe = "t" | ||
end | ||
Main.JuliaSnail.send_to_client(""" | ||
(dape `(:request "attach" | ||
host "localhost" | ||
port $port | ||
:type "julia" | ||
:stopOnEntry $soe)) | ||
""") | ||
# Wait for the session to be ready. | ||
take!(ready) | ||
DebugAdapter.debug_code(session, mod, code, filepath) | ||
end | ||
|
||
macro enter(command) | ||
Base.remove_linenums!(command) | ||
:(run(Main, $(string(command)), $(string(__source__.file)), stop_on_entry=true)) | ||
end | ||
|
||
macro run(command) | ||
Base.remove_linenums!(command) | ||
:(run(Main, $(string(command)), $(string(__source__.file)), stop_on_entry=false)) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[deps] | ||
DebugAdapter = "17994d07-08fe-42cc-bc1b-7af499b1ea47" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
;;; debug.el --- Julia Snail -*- lexical-binding: t -*- | ||
|
||
(defun julia-snail/debug-init (repl-buf) | ||
(julia-snail--send-to-server | ||
'("JuliaSnail" "Extensions") | ||
"load([\"debug\" \"Debug.jl\"]); Debug.init()" | ||
:repl-buf repl-buf | ||
:async nil | ||
:async-poll-maximum 120000)) | ||
|
||
(provide 'julia-snail/debug) |