Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CPU Debugging improvements #61

Merged
merged 2 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions lua/wire/client/text_editor/modes/zcpu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,27 @@ function EDITOR:PopulateMenu(menu)
CPULib.SetDebugBreakpoint( self.chosenfile, caretPos )
end)
end
menu:AddOption("Display line using IP", function()
CPULib.Debugger.PreferredTracker = "IP"
CPULib.Debugger.PreferredTrackerFriendlyName = "IP"
end)
menu:AddOption("Display line using CS:IP", function()
CPULib.Debugger.PreferredTracker = "CSIP"
CPULib.Debugger.PreferredTrackerFriendlyName = "CS:IP"
end)
menu:AddOption("Display line using PHYS IP", function()
CPULib.Debugger.PreferredTracker = "PHYSIP"
CPULib.Debugger.PreferredTrackerFriendlyName = "PHYS IP"
end)
if CPULib.Debugger.FollowTracker then
menu:AddOption("Don't follow the displayed line", function()
CPULib.Debugger.FollowTracker = false
end)
else
menu:AddOption("Follow the displayed line", function()
CPULib.Debugger.FollowTracker = true
end)
end
end

function EDITOR:Paint()
Expand Down
64 changes: 46 additions & 18 deletions lua/wire/cpulib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
CPULib.Debugger.Labels = {}
CPULib.Debugger.PositionByPointer = {}
CPULib.Debugger.PointersByLine = {}
CPULib.Debugger.PreferredTracker = "IP"
CPULib.Debugger.PreferredTrackerFriendlyName = "IP"
CPULib.Debugger.FollowTracker = true

CPULib.Debugger.Breakpoint = {}

Expand Down Expand Up @@ -76,23 +79,24 @@
CPULib.ErrorCallback = errorCallback

-- Run the timer
timer.Create("cpulib_compile",1/60,0,CPULib.OnCompileTimer)

Check warning on line 82 in lua/wire/cpulib.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator
CPULib.Compiling = true
end

------------------------------------------------------------------------------
-- Make sure the file is opened in the tab
function CPULib.SelectTab(editor,fileName)
function CPULib.SelectTab(editor,fileName,dontForceChange)
if not editor then return end
local editorType = string.lower(editor.EditorType)
local fullFileName = editorType.."chip\\"..fileName

Check warning on line 91 in lua/wire/cpulib.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator

Check warning on line 91 in lua/wire/cpulib.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator

if string.sub(fileName,1,7) == editorType.."chip" then

Check warning on line 93 in lua/wire/cpulib.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator
fullFileName = fileName
end

local currentTab = editor:GetActiveTabIndex()
local sourceTab
for tab=1,editor:GetNumTabs() do

Check warning on line 99 in lua/wire/cpulib.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator
if editor:GetEditor(tab).chosenfile == fullFileName then
sourceTab = tab
end
Expand All @@ -101,8 +105,13 @@
if not sourceTab then
editor:LoadFile(fullFileName,true)
sourceTab = editor:GetActiveTabIndex()
if dontForceChange then
editor:SetActiveTab(currentTab)
end
else
editor:SetActiveTab(sourceTab)
if not dontForceChange then
editor:SetActiveTab(sourceTab)
end
end

return editor:GetEditor(sourceTab),sourceTab
Expand All @@ -114,9 +123,9 @@
CPULib.Compile(source,fileName,
function(warnings)
if #warnings > 0 then
editor.C.Val:Update(nil,warnings," "..#warnings.." Warnings, with "..(HCOMP.WritePointer or "?").." bytes compiled.", Color(163, 130, 64, 255))

Check warning on line 126 in lua/wire/cpulib.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator

Check warning on line 126 in lua/wire/cpulib.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator

Check warning on line 126 in lua/wire/cpulib.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator

Check warning on line 126 in lua/wire/cpulib.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace after ')'
else
editor.C.Val:Update(nil, nil, " Success, "..(HCOMP.WritePointer or "?").." bytes compiled.", Color(50, 128, 20))

Check warning on line 128 in lua/wire/cpulib.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator
end
end,
function(error,errorPos)
Expand Down Expand Up @@ -290,7 +299,17 @@
else
table.insert(result,"IP = "..(CPULib.Debugger.Variables.IP or "#####"))
end

if CPULib.Debugger.Variables.IP == INVALID_BREAKPOINT_IP then
table.insert(result,"CS:IP = #####")
else
table.insert(result,"CS:IP = "..((CPULib.Debugger.Variables.CSIP) or "#####"))
end
if CPULib.Debugger.Variables.IP == INVALID_BREAKPOINT_IP then
table.insert(result,"PHYS IP = #####")
else
table.insert(result,"PHYS IP = "..(CPULib.Debugger.Variables.PHYSIP or "#####"))
end
table.insert(result,"Following "..CPULib.Debugger.PreferredTrackerFriendlyName)
if CPULib.InterruptText then
table.insert(result,"")
table.insert(result,CPULib.InterruptText)
Expand All @@ -308,7 +327,7 @@
CPULib.Debugger.Breakpoint = {}
CPULib.Debugger.Variables = {}
CPULib.Debugger.FirstFile = nil
CPULib.DebugUpdateHighlights()
CPULib.DebugUpdateHighlights(not CPULib.Debugger.FollowTracker)
end

net.Receive("CPULib.InvalidateDebugger", function(netlen)
Expand Down Expand Up @@ -352,15 +371,15 @@
function CPULib.DebugUpdateHighlights(dontForcePosition)
if ZCPU_Editor then
-- Highlight current position
local currentPosition = CPULib.Debugger.PositionByPointer[CPULib.Debugger.Variables.IP]
local currentPosition = CPULib.Debugger.PositionByPointer[CPULib.Debugger.Variables[CPULib.Debugger.PreferredTracker or "IP"]]

if currentPosition then
-- Clear all highlighted lines
for tab=1,ZCPU_Editor:GetNumTabs() do
ZCPU_Editor:GetEditor(tab):ClearHighlightedLines()
end

local textEditor = CPULib.SelectTab(ZCPU_Editor,currentPosition.File)
local textEditor = CPULib.SelectTab(ZCPU_Editor,currentPosition.File,not CPULib.Debugger.FollowTracker)
if textEditor then
textEditor:HighlightLine(currentPosition.Line,130,0,0,255)
if not dontForcePosition then
Expand Down Expand Up @@ -397,21 +416,24 @@
------------------------------------------------------------------------------
-- Debug data arrived from server
function CPULib.OnDebugData_Registers(um)
CPULib.Debugger.Variables.IP = um:ReadFloat()
CPULib.Debugger.Variables.EAX = um:ReadFloat()
CPULib.Debugger.Variables.EBX = um:ReadFloat()
CPULib.Debugger.Variables.ECX = um:ReadFloat()
CPULib.Debugger.Variables.EDX = um:ReadFloat()
CPULib.Debugger.Variables.ESI = um:ReadFloat()
CPULib.Debugger.Variables.EDI = um:ReadFloat()
CPULib.Debugger.Variables.EBP = um:ReadFloat()
CPULib.Debugger.Variables.ESP = um:ReadFloat()

CPULib.Debugger.Variables.CS = um:ReadFloat()
CPULib.Debugger.Variables.IP = um:ReadFloat()
CPULib.Debugger.Variables.PHYSPAGE = um:ReadFloat()
CPULib.Debugger.Variables.EAX = um:ReadFloat()
CPULib.Debugger.Variables.EBX = um:ReadFloat()
CPULib.Debugger.Variables.ECX = um:ReadFloat()
CPULib.Debugger.Variables.EDX = um:ReadFloat()
CPULib.Debugger.Variables.ESI = um:ReadFloat()
CPULib.Debugger.Variables.EDI = um:ReadFloat()
CPULib.Debugger.Variables.EBP = um:ReadFloat()
CPULib.Debugger.Variables.ESP = um:ReadFloat()
CPULib.Debugger.Variables.CSIP = CPULib.Debugger.Variables.CS + CPULib.Debugger.Variables.IP
CPULib.Debugger.Variables.PHYSIP = CPULib.Debugger.Variables.PHYSPAGE*128 + CPULib.Debugger.Variables.CSIP%128
for reg=0,31 do
CPULib.Debugger.Variables["R"..reg] = um:ReadFloat()
end

CPULib.DebugUpdateHighlights()
CPULib.DebugUpdateHighlights(not CPULib.Debugger.FollowTracker)
end
usermessage.Hook("cpulib_debugdata_registers", CPULib.OnDebugData_Registers)

Expand Down Expand Up @@ -613,7 +635,13 @@

if not onlyMemPointers then
umsg.Start("cpulib_debugdata_registers", umsgrp)
umsg.Float(VM.CS)
umsg.Float(VM.IP)
if(VM.CurrentPage.Remapped == 1) then
umsg.Float(VM.CurrentPage.MappedIndex)
else
umsg.Float(math.floor((VM.CS+VM.IP)/128))
end
umsg.Float(VM.EAX)
umsg.Float(VM.EBX)
umsg.Float(VM.ECX)
Expand Down
Loading