Single pump for both lua and mdb outputs
This commit is contained in:
15
debugger.lua
15
debugger.lua
@ -79,6 +79,16 @@ function debugger.on_state(state)
|
|||||||
debugger.state = state
|
debugger.state = state
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function debugger.on_break(file, line, reason)
|
||||||
|
debugger.log(string.format("breakpoint hit: %s:%d", file, line))
|
||||||
|
-- Temporary continue at unknown breaks
|
||||||
|
if file=='?' and line==-1 then
|
||||||
|
if debugger.debugrunner.caps.can_continue then
|
||||||
|
debugger.debugrunner:continue()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function debugger.run(target, name, r, view)
|
function debugger.run(target, name, r, view)
|
||||||
if debugger.debugrunner then
|
if debugger.debugrunner then
|
||||||
if debugger.state == "paused" then
|
if debugger.state == "paused" then
|
||||||
@ -101,10 +111,7 @@ function debugger.run(target, name, r, view)
|
|||||||
on_stderr = debugger.on_stderr,
|
on_stderr = debugger.on_stderr,
|
||||||
on_exit = debugger.on_exit,
|
on_exit = debugger.on_exit,
|
||||||
on_state = debugger.on_state,
|
on_state = debugger.on_state,
|
||||||
|
on_break = debugger.on_break,
|
||||||
on_break = function(file, line, reason)
|
|
||||||
debugger.log(string.format("breakpoint hit: %s:%d", file, line))
|
|
||||||
end,
|
|
||||||
})
|
})
|
||||||
-- And run
|
-- And run
|
||||||
debugger.debugrunner:run(target, name)
|
debugger.debugrunner:run(target, name)
|
||||||
|
|||||||
@ -15,12 +15,29 @@ local function get_plugin_root()
|
|||||||
return dirname(here) -- …/jpdebug
|
return dirname(here) -- …/jpdebug
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Check if string starts with a substring
|
||||||
|
local function starts_with(str, word)
|
||||||
|
return str:sub(1, #word) == word
|
||||||
|
end
|
||||||
|
|
||||||
-- ------------------- Runner API --------------------------------
|
-- ------------------- Runner API --------------------------------
|
||||||
|
|
||||||
---@class luadebug: runner
|
---@class luadebug: runner
|
||||||
local luadebug = debugger.runner:new({
|
local luadebug = debugger.runner:new({
|
||||||
name = "luadebug",
|
name = "luadebug",
|
||||||
proc = nil ---@type process|nil
|
proc = nil, ---@type process|nil
|
||||||
|
|
||||||
|
caps = {
|
||||||
|
can_pause = false,
|
||||||
|
can_continue = true,
|
||||||
|
can_step_in = true,
|
||||||
|
can_step_over = true,
|
||||||
|
can_step_out = true,
|
||||||
|
can_breakpoints = true,
|
||||||
|
has_stack = true,
|
||||||
|
has_locals = true,
|
||||||
|
can_eval = false,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
function luadebug:run(target, name)
|
function luadebug:run(target, name)
|
||||||
@ -48,24 +65,13 @@ function luadebug:run(target, name)
|
|||||||
|
|
||||||
self.on_state('connecting')
|
self.on_state('connecting')
|
||||||
|
|
||||||
-- output pump
|
-- Start output pump
|
||||||
core.add_thread(function()
|
self:pumps()
|
||||||
while true do
|
end
|
||||||
core.redraw = true
|
|
||||||
coroutine.yield(0.016) -- 60FPS
|
function luadebug:continue()
|
||||||
local sout = self.proc:read_stdout()
|
self.mdb:write('run\n')
|
||||||
local serr = self.proc:read_stderr()
|
self.on_state('running')
|
||||||
if sout == nil or serr == nil then
|
|
||||||
-- Make sure to read stderr for the last time
|
|
||||||
if serr and serr~="" then self.on_stderr(serr) end
|
|
||||||
local exitcode = self.proc:wait(process.WAIT_INFINITE)
|
|
||||||
self.on_exit(exitcode)
|
|
||||||
break
|
|
||||||
end
|
|
||||||
if sout and sout~="" then self.on_stdout(sout) end
|
|
||||||
if serr and serr~="" then self.on_stderr(serr) end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function luadebug:wait(time)
|
function luadebug:wait(time)
|
||||||
@ -171,28 +177,57 @@ function luadebug:spawn_mdb(lua)
|
|||||||
end
|
end
|
||||||
|
|
||||||
self.mdb = proc
|
self.mdb = proc
|
||||||
|
end
|
||||||
|
|
||||||
self.mdb:write('run\n')
|
-- ---------------- Pumps ---------------------------------------
|
||||||
|
function luadebug:pumps()
|
||||||
-- output pump
|
|
||||||
core.add_thread(function()
|
core.add_thread(function()
|
||||||
while true do
|
while true do
|
||||||
core.redraw = true
|
core.redraw = true
|
||||||
coroutine.yield(0.016) -- 60FPS
|
coroutine.yield(0.016) -- 60FPS
|
||||||
local sout = self.mdb:read_stdout()
|
|
||||||
local serr = self.mdb:read_stderr()
|
-- LUA PROGRAM OUTPUT
|
||||||
|
if true then
|
||||||
|
local sout = self.proc:read_stdout()
|
||||||
|
local serr = self.proc:read_stderr()
|
||||||
|
|
||||||
if sout == nil or serr == nil then
|
if sout == nil or serr == nil then
|
||||||
-- Make sure to read stderr for the last time
|
-- Make sure to read stderr for the last time
|
||||||
if serr and serr~="" then self.on_stderr(serr) end
|
if serr and serr~="" then self.on_stderr(serr) end
|
||||||
local exitcode = self.mdb:wait(process.WAIT_INFINITE)
|
local exitcode = self.proc:wait(process.WAIT_INFINITE)
|
||||||
self.on_exit(exitcode)
|
self.on_exit(exitcode)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
if sout and sout~="" then self.on_stdout('mdb> '..sout) end
|
if sout and sout~="" then self.on_stdout(sout) end
|
||||||
if serr and serr~="" then self.on_stderr('mdb> '..serr) end
|
if serr and serr~="" then self.on_stderr(serr) end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- MDB OUTPUT
|
||||||
|
if true then
|
||||||
|
local sout = self.mdb:read_stdout()
|
||||||
|
local serr = self.mdb:read_stderr()
|
||||||
|
|
||||||
|
if sout == nil or serr == nil then
|
||||||
|
-- Make sure to read stderr for the last time
|
||||||
|
if serr and serr~="" then self.on_stderr(serr) end
|
||||||
|
local exitcode = self.proc:wait(process.WAIT_INFINITE)
|
||||||
|
self.on_exit(exitcode)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
if sout and sout~="" then self.on_stdout("mdb> "..sout) end
|
||||||
|
if serr and serr~="" then self.on_stderr("mdb> "..serr) end
|
||||||
|
|
||||||
|
if sout and sout~="" then
|
||||||
|
-- Check output
|
||||||
|
if starts_with(sout, "Paused") then
|
||||||
|
self.on_state('paused')
|
||||||
|
self.on_break('?', -1, 'paused')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
return luadebug
|
|
||||||
|
|
||||||
|
return luadebug
|
||||||
|
|||||||
Reference in New Issue
Block a user