summaryrefslogtreecommitdiffstatshomepage
path: root/plugins/gdbstub
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/gdbstub')
-rw-r--r--plugins/gdbstub/init.lua50
1 files changed, 26 insertions, 24 deletions
diff --git a/plugins/gdbstub/init.lua b/plugins/gdbstub/init.lua
index e34b0dcfb5d..1d358518965 100644
--- a/plugins/gdbstub/init.lua
+++ b/plugins/gdbstub/init.lua
@@ -1,11 +1,11 @@
-- license:BSD-3-Clause
-- copyright-holders: Carl
-local exports = {}
-exports.name = "gdbstub"
-exports.version = "0.0.1"
-exports.description = "GDB stub plugin"
-exports.license = "The BSD 3-Clause License"
-exports.author = { name = "Carl" }
+local exports = {
+ name = "gdbstub",
+ version = "0.0.1",
+ description = "GDB stub plugin",
+ license = "BSD-3-Clause",
+ author = { name = "Carl" } }
local gdbstub = exports
@@ -25,6 +25,8 @@ local regmaps = {
regmaps.i486 = regmaps.i386
regmaps.pentium = regmaps.i386
+local reset_subscription, stop_subscription
+
function gdbstub.startplugin()
local debugger
local debug
@@ -35,18 +37,18 @@ function gdbstub.startplugin()
local consolelast
local running
- emu.register_start(function ()
- debugger = manager:machine():debugger()
+ reset_subscription = emu.add_machine_reset_notifier(function ()
+ debugger = manager.machine.debugger
if not debugger then
print("gdbstub: debugger not enabled")
return
end
- cpu = manager:machine().devices[":maincpu"]
+ cpu = manager.machine.devices[":maincpu"]
if not cpu then
print("gdbstub: maincpu not found")
end
- if not regmaps[cpu:shortname()] then
- print("gdbstub: no register map for cpu " .. cpu:shortname())
+ if not regmaps[cpu.shortname] then
+ print("gdbstub: no register map for cpu " .. cpu.shortname)
cpu = nil
end
consolelog = debugger.consolelog
@@ -56,7 +58,7 @@ function gdbstub.startplugin()
running = false
end)
- emu.register_stop(function()
+ stop_subscription = emu.add_machine_stop_notifier(function ()
consolelog = nil
cpu = nil
debug = nil
@@ -98,7 +100,7 @@ function gdbstub.startplugin()
consolelast = #consolelog
if #consolelog > last and msg:find("Stopped at", 1, true) then
local point = tonumber(msg:match("Stopped at breakpoint ([0-9]+)"))
- local map = regmaps[cpu:shortname()]
+ local map = regmaps[cpu.shortname]
running = false
if not point then
point = tonumber(msg:match("Stopped at watchpoint ([0-9]+"))
@@ -152,7 +154,7 @@ function gdbstub.startplugin()
if packet then
packet:gsub("}(.)", function(s) return string.char(string.byte(s) ~ 0x20) end)
local cmd = packet:sub(1, 1)
- local map = regmaps[cpu:shortname()]
+ local map = regmaps[cpu.shortname]
if cmd == "g" then
local regs = {}
for reg, idx in pairs(map.togdb) do
@@ -175,7 +177,7 @@ function gdbstub.startplugin()
local data = ""
local space = cpu.spaces["program"]
for count = 1, len do
- data = data .. string.format("%.2x", space:read_log_u8(addr))
+ data = data .. string.format("%.2x", space:readv_u8(addr))
addr = addr + 1
end
socket:write("+$" .. data .. "#" .. chksum(data))
@@ -188,14 +190,14 @@ function gdbstub.startplugin()
if addr and len and data then
addr = tonumber(addr, 16)
local space = cpu.spaces["program"]
- data:gsub("%x%x", function(s) space:write_log_u8(addr + count, tonumber(s, 16)) count = count + 1 end)
+ data:gsub("%x%x", function(s) space:writev_u8(addr + count, tonumber(s, 16)) count = count + 1 end)
socket:write("+$OK#9a")
else
socket:write("+$E00#a5")
end
elseif cmd == "s" then
if #packet == 1 then
- cpu:debug():step()
+ cpu.debug:step()
socket:write("+$OK#9a")
socket:write("$S05#B8")
running = false
@@ -204,7 +206,7 @@ function gdbstub.startplugin()
end
elseif cmd == "c" then
if #packet == 1 then
- cpu:debug():go()
+ cpu.debug:go()
socket:write("+$OK#9a")
else
socket:write("+$E00#a5")
@@ -219,7 +221,7 @@ function gdbstub.startplugin()
socket:write("+$E00#a5")
return
end
- local idx = cpu:debug():bpset(addr)
+ local idx = cpu.debug:bpset(addr)
breaks.byaddr[addr] = idx
breaks.byidx[idx] = addr
socket:write("+$OK#9a")
@@ -228,7 +230,7 @@ function gdbstub.startplugin()
socket:write("+$E00#a5")
return
end
- local idx = cpu:debug():wpset(cpu.spaces["program"], "w", addr, 1)
+ local idx = cpu.debug:wpset(cpu.spaces["program"], "w", addr, 1)
watches.byaddr[addr] = idx
watches.byidx[idx] = {addr = addr, type = "watch"}
socket:write("+$OK#9a")
@@ -237,7 +239,7 @@ function gdbstub.startplugin()
socket:write("+$E00#a5")
return
end
- local idx = cpu:debug():wpset(cpu.spaces["program"], "r", addr, 1)
+ local idx = cpu.debug:wpset(cpu.spaces["program"], "r", addr, 1)
watches.byaddr[addr] = idx
watches.byidx[idx] = {addr = addr, type = "rwatch"}
socket:write("+$OK#9a")
@@ -246,7 +248,7 @@ function gdbstub.startplugin()
socket:write("+$E00#a5")
return
end
- local idx = cpu:debug():wpset(cpu.spaces["program"], "rw", addr, 1)
+ local idx = cpu.debug:wpset(cpu.spaces["program"], "rw", addr, 1)
watches.byaddr[addr] = idx
watches.byidx[idx] = {addr = addr, type = "awatch"}
socket:write("+$OK#9a")
@@ -262,7 +264,7 @@ function gdbstub.startplugin()
return
end
local idx = breaks.byaddr[addr]
- cpu:debug():bpclr(idx)
+ cpu.debug:bpclr(idx)
breaks.byaddr[addr] = nil
breaks.byidx[idx] = nil
socket:write("+$OK#9a")
@@ -272,7 +274,7 @@ function gdbstub.startplugin()
return
end
local idx = watches.byaddr[addr]
- cpu:debug():wpclr(idx)
+ cpu.debug:wpclr(idx)
watches.byaddr[addr] = nil
watches.byidx[idx] = nil
socket:write("+$OK#9a")