Skip to content

Commit a3c0987

Browse files
CPU Debugging improvements (#61)
* CPU Debugging improvements * Open includes but switch back if not tracking line
1 parent a664318 commit a3c0987

File tree

2 files changed

+67
-18
lines changed

2 files changed

+67
-18
lines changed

lua/wire/client/text_editor/modes/zcpu.lua

+21
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,27 @@ function EDITOR:PopulateMenu(menu)
315315
CPULib.SetDebugBreakpoint( self.chosenfile, caretPos )
316316
end)
317317
end
318+
menu:AddOption("Display line using IP", function()
319+
CPULib.Debugger.PreferredTracker = "IP"
320+
CPULib.Debugger.PreferredTrackerFriendlyName = "IP"
321+
end)
322+
menu:AddOption("Display line using CS:IP", function()
323+
CPULib.Debugger.PreferredTracker = "CSIP"
324+
CPULib.Debugger.PreferredTrackerFriendlyName = "CS:IP"
325+
end)
326+
menu:AddOption("Display line using PHYS IP", function()
327+
CPULib.Debugger.PreferredTracker = "PHYSIP"
328+
CPULib.Debugger.PreferredTrackerFriendlyName = "PHYS IP"
329+
end)
330+
if CPULib.Debugger.FollowTracker then
331+
menu:AddOption("Don't follow the displayed line", function()
332+
CPULib.Debugger.FollowTracker = false
333+
end)
334+
else
335+
menu:AddOption("Follow the displayed line", function()
336+
CPULib.Debugger.FollowTracker = true
337+
end)
338+
end
318339
end
319340

320341
function EDITOR:Paint()

lua/wire/cpulib.lua

+46-18
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ if CLIENT or TESTING then
3232
CPULib.Debugger.Labels = {}
3333
CPULib.Debugger.PositionByPointer = {}
3434
CPULib.Debugger.PointersByLine = {}
35+
CPULib.Debugger.PreferredTracker = "IP"
36+
CPULib.Debugger.PreferredTrackerFriendlyName = "IP"
37+
CPULib.Debugger.FollowTracker = true
3538

3639
CPULib.Debugger.Breakpoint = {}
3740

@@ -82,7 +85,7 @@ if CLIENT or TESTING then
8285

8386
------------------------------------------------------------------------------
8487
-- Make sure the file is opened in the tab
85-
function CPULib.SelectTab(editor,fileName)
88+
function CPULib.SelectTab(editor,fileName,dontForceChange)
8689
if not editor then return end
8790
local editorType = string.lower(editor.EditorType)
8891
local fullFileName = editorType.."chip\\"..fileName
@@ -91,6 +94,7 @@ if CLIENT or TESTING then
9194
fullFileName = fileName
9295
end
9396

97+
local currentTab = editor:GetActiveTabIndex()
9498
local sourceTab
9599
for tab=1,editor:GetNumTabs() do
96100
if editor:GetEditor(tab).chosenfile == fullFileName then
@@ -101,8 +105,13 @@ if CLIENT or TESTING then
101105
if not sourceTab then
102106
editor:LoadFile(fullFileName,true)
103107
sourceTab = editor:GetActiveTabIndex()
108+
if dontForceChange then
109+
editor:SetActiveTab(currentTab)
110+
end
104111
else
105-
editor:SetActiveTab(sourceTab)
112+
if not dontForceChange then
113+
editor:SetActiveTab(sourceTab)
114+
end
106115
end
107116

108117
return editor:GetEditor(sourceTab),sourceTab
@@ -290,7 +299,17 @@ if CLIENT or TESTING then
290299
else
291300
table.insert(result,"IP = "..(CPULib.Debugger.Variables.IP or "#####"))
292301
end
293-
302+
if CPULib.Debugger.Variables.IP == INVALID_BREAKPOINT_IP then
303+
table.insert(result,"CS:IP = #####")
304+
else
305+
table.insert(result,"CS:IP = "..((CPULib.Debugger.Variables.CSIP) or "#####"))
306+
end
307+
if CPULib.Debugger.Variables.IP == INVALID_BREAKPOINT_IP then
308+
table.insert(result,"PHYS IP = #####")
309+
else
310+
table.insert(result,"PHYS IP = "..(CPULib.Debugger.Variables.PHYSIP or "#####"))
311+
end
312+
table.insert(result,"Following "..CPULib.Debugger.PreferredTrackerFriendlyName)
294313
if CPULib.InterruptText then
295314
table.insert(result,"")
296315
table.insert(result,CPULib.InterruptText)
@@ -308,7 +327,7 @@ if CLIENT or TESTING then
308327
CPULib.Debugger.Breakpoint = {}
309328
CPULib.Debugger.Variables = {}
310329
CPULib.Debugger.FirstFile = nil
311-
CPULib.DebugUpdateHighlights()
330+
CPULib.DebugUpdateHighlights(not CPULib.Debugger.FollowTracker)
312331
end
313332

314333
net.Receive("CPULib.InvalidateDebugger", function(netlen)
@@ -352,15 +371,15 @@ if CLIENT or TESTING then
352371
function CPULib.DebugUpdateHighlights(dontForcePosition)
353372
if ZCPU_Editor then
354373
-- Highlight current position
355-
local currentPosition = CPULib.Debugger.PositionByPointer[CPULib.Debugger.Variables.IP]
374+
local currentPosition = CPULib.Debugger.PositionByPointer[CPULib.Debugger.Variables[CPULib.Debugger.PreferredTracker or "IP"]]
356375

357376
if currentPosition then
358377
-- Clear all highlighted lines
359378
for tab=1,ZCPU_Editor:GetNumTabs() do
360379
ZCPU_Editor:GetEditor(tab):ClearHighlightedLines()
361380
end
362-
363-
local textEditor = CPULib.SelectTab(ZCPU_Editor,currentPosition.File)
381+
382+
local textEditor = CPULib.SelectTab(ZCPU_Editor,currentPosition.File,not CPULib.Debugger.FollowTracker)
364383
if textEditor then
365384
textEditor:HighlightLine(currentPosition.Line,130,0,0,255)
366385
if not dontForcePosition then
@@ -397,21 +416,24 @@ if CLIENT or TESTING then
397416
------------------------------------------------------------------------------
398417
-- Debug data arrived from server
399418
function CPULib.OnDebugData_Registers(um)
400-
CPULib.Debugger.Variables.IP = um:ReadFloat()
401-
CPULib.Debugger.Variables.EAX = um:ReadFloat()
402-
CPULib.Debugger.Variables.EBX = um:ReadFloat()
403-
CPULib.Debugger.Variables.ECX = um:ReadFloat()
404-
CPULib.Debugger.Variables.EDX = um:ReadFloat()
405-
CPULib.Debugger.Variables.ESI = um:ReadFloat()
406-
CPULib.Debugger.Variables.EDI = um:ReadFloat()
407-
CPULib.Debugger.Variables.EBP = um:ReadFloat()
408-
CPULib.Debugger.Variables.ESP = um:ReadFloat()
409-
419+
CPULib.Debugger.Variables.CS = um:ReadFloat()
420+
CPULib.Debugger.Variables.IP = um:ReadFloat()
421+
CPULib.Debugger.Variables.PHYSPAGE = um:ReadFloat()
422+
CPULib.Debugger.Variables.EAX = um:ReadFloat()
423+
CPULib.Debugger.Variables.EBX = um:ReadFloat()
424+
CPULib.Debugger.Variables.ECX = um:ReadFloat()
425+
CPULib.Debugger.Variables.EDX = um:ReadFloat()
426+
CPULib.Debugger.Variables.ESI = um:ReadFloat()
427+
CPULib.Debugger.Variables.EDI = um:ReadFloat()
428+
CPULib.Debugger.Variables.EBP = um:ReadFloat()
429+
CPULib.Debugger.Variables.ESP = um:ReadFloat()
430+
CPULib.Debugger.Variables.CSIP = CPULib.Debugger.Variables.CS + CPULib.Debugger.Variables.IP
431+
CPULib.Debugger.Variables.PHYSIP = CPULib.Debugger.Variables.PHYSPAGE*128 + CPULib.Debugger.Variables.CSIP%128
410432
for reg=0,31 do
411433
CPULib.Debugger.Variables["R"..reg] = um:ReadFloat()
412434
end
413435

414-
CPULib.DebugUpdateHighlights()
436+
CPULib.DebugUpdateHighlights(not CPULib.Debugger.FollowTracker)
415437
end
416438
usermessage.Hook("cpulib_debugdata_registers", CPULib.OnDebugData_Registers)
417439

@@ -617,7 +639,13 @@ if SERVER then
617639

618640
if not onlyMemPointers then
619641
umsg.Start("cpulib_debugdata_registers", umsgrp)
642+
umsg.Float(VM.CS)
620643
umsg.Float(VM.IP)
644+
if(VM.CurrentPage.Remapped == 1) then
645+
umsg.Float(VM.CurrentPage.MappedIndex)
646+
else
647+
umsg.Float(math.floor((VM.CS+VM.IP)/128))
648+
end
621649
umsg.Float(VM.EAX)
622650
umsg.Float(VM.EBX)
623651
umsg.Float(VM.ECX)

0 commit comments

Comments
 (0)