-
Notifications
You must be signed in to change notification settings - Fork 1
/
dbgtrace.lua
61 lines (54 loc) · 1.84 KB
/
dbgtrace.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
local about_to_jump = false
local jump_origin = nil
local trace = {}
function precycle_handler(state, pos)
inst = state.cpu:disassemble(state.cpu.registers.PC)
if (inst.pretty.op == "JSR" or (inst.pretty.op == "SET" and inst.pretty.b == "PC")) then
jump_origin = state.cpu.registers.PC
about_to_jump = true
end
end
function postcycle_handler(state, pos)
if about_to_jump then
if #trace > 0 and
trace[#trace]["from"] == jump_origin and
trace[#trace]["to"] == state.cpu.registers.PC then
trace[#trace]["count"] = trace[#trace]["count"] + 1
else
trace[#trace + 1] = {
from = jump_origin,
to = state.cpu.registers.PC,
count = 1
}
end
--print("Landed in " .. string.format("%04X", state.cpu.registers.PC) .. ".")
about_to_jump = false
end
end
function where_handler(state, params)
--local pos = trace[#trace]["to"]
local i = 0
while i < 10 do
if trace[#trace - i].count == 1 then
print(string.format("%04X", trace[#trace - i]["to"]) .. " was jumped to from "
.. string.format("%04X", trace[#trace - i]["from"]))
else
print(string.format("%04X", trace[#trace - i]["to"]) .. " was jumped to from "
.. string.format("%04X", trace[#trace - i]["from"])
.. " (" .. trace[#trace - i].count .. " times)")
end
i = i + 1
end
end
function setup()
add_command("where", where_handler)
add_hook("precycle", precycle_handler)
add_hook("postcycle", postcycle_handler)
end
MODULE = {
Type = "Debugger",
Name = "Backtracing",
Version = "1.0",
SDescription = "Simple backtracing debugger command",
URL = "http://dcputoolcha.in/docs/modules/list/dbgtrace.html"
};