debugger refactor
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
local Array = require('opus.array')
|
local Array = require('opus.array')
|
||||||
local Config = require('opus.config')
|
local Config = require('opus.config')
|
||||||
local fuzzy = require('opus.fuzzy')
|
|
||||||
local UI = require('opus.ui')
|
local UI = require('opus.ui')
|
||||||
local Util = require('opus.util')
|
local Util = require('opus.util')
|
||||||
|
|
||||||
@@ -492,7 +491,7 @@ local page = UI.Page {
|
|||||||
UI.Window.resize(self)
|
UI.Window.resize(self)
|
||||||
|
|
||||||
w, h = self.width, self.height
|
w, h = self.width, self.height
|
||||||
actions.set_cursor(x, y)
|
actions.set_cursor()
|
||||||
actions.dirty_all()
|
actions.dirty_all()
|
||||||
actions.redraw()
|
actions.redraw()
|
||||||
end,
|
end,
|
||||||
@@ -940,7 +939,7 @@ actions = {
|
|||||||
local routine = {
|
local routine = {
|
||||||
focused = true,
|
focused = true,
|
||||||
title = fs.getName(fileInfo.path),
|
title = fs.getName(fileInfo.path),
|
||||||
chainExit = function(_, result)
|
onExit = function(_, result)
|
||||||
-- display results of process before closing window
|
-- display results of process before closing window
|
||||||
if result then -- clean exit
|
if result then -- clean exit
|
||||||
-- any errors will be picked up by multishells
|
-- any errors will be picked up by multishells
|
||||||
@@ -1467,12 +1466,19 @@ actions = {
|
|||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
local args = { ... }
|
local args, options = Util.parse( ... )
|
||||||
local filename = args[1] and shell.resolve(args[1])
|
local filename = args[1] and shell.resolve(args[1])
|
||||||
if not (actions.load(filename) or actions.load(config.filename) or actions.load('untitled.lua')) then
|
if not (actions.load(filename) or actions.load(config.filename) or actions.load('untitled.lua')) then
|
||||||
error('Error opening file')
|
error('Error opening file')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if tonumber(options.line) then
|
||||||
|
scrollY = math.max(0, tonumber(options.line) - math.floor(h / 2))
|
||||||
|
actions.go_to(1, tonumber(options.line))
|
||||||
|
actions.set_cursor()
|
||||||
|
actions.dirty_all()
|
||||||
|
end
|
||||||
|
|
||||||
UI:setPage(page)
|
UI:setPage(page)
|
||||||
local s, m = pcall(function() UI:start() end)
|
local s, m = pcall(function() UI:start() end)
|
||||||
if not s then
|
if not s then
|
||||||
|
|||||||
@@ -78,4 +78,9 @@
|
|||||||
category = "Apps",
|
category = "Apps",
|
||||||
run = "write",
|
run = "write",
|
||||||
},
|
},
|
||||||
|
[ "c543ece81605c7d202121c62080a0db4020fc2c75bfac35d101d7f3e93c93949" ] = {
|
||||||
|
category = "Apps",
|
||||||
|
run = "ascii",
|
||||||
|
title = "Ascii",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,4 +4,3 @@ packages/common/colors.lua urlfs https://raw.githubusercontent.com/kepler155c/op
|
|||||||
packages/common/cowsay.lua urlfs https://pastebin.com/raw/n00VQJsw
|
packages/common/cowsay.lua urlfs https://pastebin.com/raw/n00VQJsw
|
||||||
packages/common/calc.lua urlfs https://pastebin.com/raw/nAinUn1h
|
packages/common/calc.lua urlfs https://pastebin.com/raw/nAinUn1h
|
||||||
packages/common/write.lua urlfs https://pastebin.com/raw/RSyhCjqv
|
packages/common/write.lua urlfs https://pastebin.com/raw/RSyhCjqv
|
||||||
packages/common/apis/debugger.lua urlfs https://raw.githubusercontent.com/slembcke/debugger.lua/master/debugger.lua
|
|
||||||
@@ -6,10 +6,8 @@ local fs = _G.fs
|
|||||||
local dbg = {
|
local dbg = {
|
||||||
hooks = { },
|
hooks = { },
|
||||||
waits = { },
|
waits = { },
|
||||||
debugger = nil,
|
|
||||||
breakpoints = nil,
|
breakpoints = nil,
|
||||||
}
|
}
|
||||||
_G._dbg = dbg -- for testing purposes
|
|
||||||
|
|
||||||
local function breakpointHook(info)
|
local function breakpointHook(info)
|
||||||
if dbg.breakpoints then
|
if dbg.breakpoints then
|
||||||
@@ -155,12 +153,7 @@ local function hook()
|
|||||||
while dbg.waits[1] ~= h do
|
while dbg.waits[1] ~= h do
|
||||||
os.sleep(.1)
|
os.sleep(.1)
|
||||||
end
|
end
|
||||||
os.queueEvent('debuggerX', dbg.debugger.uid, snapshot)
|
local cmd, param = dbg.read(snapshot)
|
||||||
|
|
||||||
local e, cmd, param
|
|
||||||
repeat
|
|
||||||
e, cmd, param = os.pullEvent('debugger')
|
|
||||||
until e == 'debugger'
|
|
||||||
|
|
||||||
table.remove(dbg.waits, 1)
|
table.remove(dbg.waits, 1)
|
||||||
|
|
||||||
@@ -187,7 +180,7 @@ function dbg.call(fn, ...)
|
|||||||
local args = { ... }
|
local args = { ... }
|
||||||
return xpcall(
|
return xpcall(
|
||||||
function()
|
function()
|
||||||
fn(table.unpack(args))
|
return fn(table.unpack(args))
|
||||||
end,
|
end,
|
||||||
function(err)
|
function(err)
|
||||||
dbg.hooks[coroutine.running()].eval = stepHook()
|
dbg.hooks[coroutine.running()].eval = stepHook()
|
||||||
|
|||||||
@@ -46,6 +46,18 @@ local function startClient()
|
|||||||
error(msg, -1)
|
error(msg, -1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
dbg.read = function(snapshot)
|
||||||
|
os.sleep(0) -- not sure why, but we need a sleep before :resume
|
||||||
|
-- directly resuming debugger routine to prevent
|
||||||
|
-- serialization of the snapshot
|
||||||
|
dbg.debugger:resume('debuggerX', dbg.debugger.uid, snapshot)
|
||||||
|
local e, cmd, param
|
||||||
|
repeat
|
||||||
|
e, cmd, param = os.pullEvent('debugger')
|
||||||
|
until e == 'debugger'
|
||||||
|
return cmd, param
|
||||||
|
end
|
||||||
|
|
||||||
-- breakpoint table is shared across processes
|
-- breakpoint table is shared across processes
|
||||||
dbg.breakpoints = breakpoints
|
dbg.breakpoints = breakpoints
|
||||||
dbg.debugger = debugger
|
dbg.debugger = debugger
|
||||||
@@ -106,8 +118,6 @@ local page = UI.Page {
|
|||||||
y = 1, ey = '50%',
|
y = 1, ey = '50%',
|
||||||
tabs = UI.Tabs {
|
tabs = UI.Tabs {
|
||||||
ey = -2,
|
ey = -2,
|
||||||
unselectedBackgroundColor = 'black',
|
|
||||||
|
|
||||||
locals = UI.Tab {
|
locals = UI.Tab {
|
||||||
title = 'Locals',
|
title = 'Locals',
|
||||||
index = 1,
|
index = 1,
|
||||||
@@ -361,11 +371,12 @@ local page = UI.Page {
|
|||||||
self:draw()
|
self:draw()
|
||||||
end,
|
end,
|
||||||
|
|
||||||
editFile = function(_, file)
|
editFile = function(self, file)
|
||||||
if fs.exists(file) then
|
if fs.exists(file) then
|
||||||
|
local line = self.source:getSelected().line
|
||||||
multishell.openTab(_ENV, {
|
multishell.openTab(_ENV, {
|
||||||
path = 'sys/apps/shell.lua',
|
path = 'sys/apps/shell.lua',
|
||||||
args = { 'edit ' .. file },
|
args = { ('edit --line=%d %s'):format(line , file) },
|
||||||
focused = true,
|
focused = true,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
@@ -424,8 +435,12 @@ local page = UI.Page {
|
|||||||
local t = event.selected.raw
|
local t = event.selected.raw
|
||||||
for k,v in pairs(t) do
|
for k,v in pairs(t) do
|
||||||
local depth = event.selected.depth or 0
|
local depth = event.selected.depth or 0
|
||||||
table.insert(event.selected.children,
|
table.insert(event.selected.children, {
|
||||||
{ name = (' '):rep(depth + 2) .. k, value = tostring(v), raw = v, depth = depth + 2 })
|
name = (' '):rep(depth + 2) .. tostring(k),
|
||||||
|
value = tostring(v),
|
||||||
|
raw = v,
|
||||||
|
depth = depth + 2
|
||||||
|
})
|
||||||
end
|
end
|
||||||
table.sort(event.selected.children, function(a, b) return a.name < b.name end)
|
table.sort(event.selected.children, function(a, b) return a.name < b.name end)
|
||||||
end
|
end
|
||||||
@@ -468,6 +483,7 @@ Event.on('debuggerX', function(_, uid, data)
|
|||||||
for k,v in pairs(getfenv(data.info.func)) do
|
for k,v in pairs(getfenv(data.info.func)) do
|
||||||
table.insert(t, { name = k, value = tostring(v), raw = v })
|
table.insert(t, { name = k, value = tostring(v), raw = v })
|
||||||
end
|
end
|
||||||
|
table.sort(t, function(a, b) return a.name < b.name end)
|
||||||
page.container.tabs.env.grid:setValues(t)
|
page.container.tabs.env.grid:setValues(t)
|
||||||
page.container.tabs.env.grid.orig = Util.shallowCopy(t)
|
page.container.tabs.env.grid.orig = Util.shallowCopy(t)
|
||||||
|
|
||||||
|
|||||||
7
debugger/etc/apps.db
Normal file
7
debugger/etc/apps.db
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
[ "1a03bd2fd107c453f3183e30b9716f82200671e8270fbbefbe602f5a48705527" ] = {
|
||||||
|
run = "fileui --exec=debug.lua --title=debug",
|
||||||
|
title = "Debug",
|
||||||
|
category = "Apps",
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -1,3 +1,14 @@
|
|||||||
|
--[[
|
||||||
|
-- a very simple debugger implementation
|
||||||
|
local dbg = require('debugger')
|
||||||
|
dbg.read = function(snapshot)
|
||||||
|
print(('%s: %d'):format(snapshot.info.source, snapshot.info.currentline))
|
||||||
|
write('> ')
|
||||||
|
return read()
|
||||||
|
end
|
||||||
|
dbg.stopIn(debug.getinfo(1).func)
|
||||||
|
]]
|
||||||
|
|
||||||
local function m2(a)
|
local function m2(a)
|
||||||
return a
|
return a
|
||||||
end
|
end
|
||||||
@@ -43,7 +54,6 @@ local chunk = load([[
|
|||||||
local j = chunk()
|
local j = chunk()
|
||||||
print(j)
|
print(j)
|
||||||
|
|
||||||
require('opus.util').print(coroutine)
|
|
||||||
local co = coroutine.create(function(args)
|
local co = coroutine.create(function(args)
|
||||||
print('in coroutine')
|
print('in coroutine')
|
||||||
return 'hi'
|
return 'hi'
|
||||||
|
|||||||
Reference in New Issue
Block a user