Added separate debugger file and fixed shell to new form

This commit is contained in:
2025-10-25 20:07:49 +02:00
parent f6c031849f
commit abedca2394
4 changed files with 148 additions and 110 deletions

View File

@ -8,6 +8,8 @@ local config = require "core.config"
local TreeView = require "plugins.treeview"
local ToolbarView = require "plugins.toolbarview"
local debugger = require "plugins.jpdebug.debugger"
core.jpdebug = core.jpdebug or {}
-- Global list of all the runners
@ -19,10 +21,6 @@ local active_view = nil
-- The selected target
local selected_target = nil
-- The running system
local running_proc = nil
local running_runner = nil
-- Table containing all debug information (like breakpoints)
local debug_info = {}
@ -156,12 +154,7 @@ end
-- ---------- run target & pipe stdout/stderr into the view ----------
local function run_target(target, name)
-- Check if something is alredy running
if running_proc then
core.error("[jpdebug] Already a runner active")
return
end
-- Create/get view to push text to
-- TODO fix this, it throws a node is locked error once in a while
local view = nil
if active_view then
@ -177,53 +170,16 @@ local function run_target(target, name)
-- Check if we have a runner
for runner_name,runner in pairs(core.jpdebug.runners) do
if runner_name == target.type then
-- Found a runner
running_proc = runner:run(target, name, debug_info)
running_runner = runner
if running_proc == nil then
core.error("[jpdebug] Could not run the target")
view:push("stderr", "Could not run the target")
return
end
view:clear()
-- background pump (non-blocking I/O)
core.add_thread(function()
while true do
core.redraw = true
coroutine.yield(0.016) -- ~60fps
if running_proc == nil then
return
end
local out = runner:read_stdout(running_proc)
if out == nil then
-- stdout pipe closed: try drain stderr and break when both closed
local err = runner:read_stderr(running_proc)
if err ~= nil and err ~= "" then view:push("stderr", err) end
break
end
if out ~= "" then view:push("stdout", out) end
local err = runner:read_stderr(running_proc)
if err ~= nil and err ~= "" then view:push("stderr", err) end
end
if running_proc then
local code = runner:wait(running_proc, process.WAIT_INFINITE)
view:push("stdout", ("\n[exit] code=%s\n"):format(tostring(code)))
end
running_proc = nil
running_runner = nil
end)
debugger.run(target, name, runner, view)
return view
end
end
-- No suitable runners found
core.error("[jpdebug] No suitable runners found for target %s", name)
view:push("stderr", "No suitable runners found for target "..name)
debugger.error(string.format("No suitable runners found for target %s", name))
end
-- ---------- Reload a module on the go ------------------------------
local function hot_require(name, into)
-- blow away the cached module
package.loaded[name] = nil
@ -243,7 +199,11 @@ local function hot_require(name, into)
end
end
-- Load the runners table on the go
local function load_runners()
-- TODO Remove: reload debugger as well here
debugger = hot_require("plugins.jpdebug.debugger", core.jpdebug.debugger)
local runner_shell = hot_require("plugins.jpdebug.runners.shell", core.jpdebug.runners.shell)
local runner_luadebug = hot_require("plugins.jpdebug.runners.luadebug", core.jpdebug.runners.luadebug)
core.jpdebug.runners[runner_shell.name] = runner_shell
@ -268,7 +228,7 @@ if required_toolbar_plugins and ToolbarView then
local t = {
{symbol = "A", command = "jpdebug:set-target"},
}
if running_proc == nil then
if not debugger.is_running() then
table.insert(t, {symbol = "B", command = "jpdebug:run"})
else
table.insert(t, {symbol = "D", command = "jpdebug:stop"})
@ -311,16 +271,7 @@ command.add(nil, {
end,
["jpdebug:stop"] = function()
core.log(dump(running_proc))
if running_runner then
running_runner:kill(running_proc)
end
core.log("[jpdebug] Stopped runner")
if active_view then
active_view:push("stdout", " ... Stopped")
end
running_proc = nil
running_runner = nil
debugger.stop()
end,
-- The set target command