Repository navigation
Expand file tree
/
Copy pathscript-debug.lua
More file actions
1220 lines (1174 loc) · 44.3 KB
/
Copy pathscript-debug.lua
File metadata and controls
1220 lines (1174 loc) · 44.3 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local bit = require("bit")
local debugger = {
breakpointList = {},
counter = 0,
}
local utility = {
storeOpcodes = {
[0x28] = 'STORE', -- sb
[0x29] = 'STORE', -- sh
[0x2a] = 'STORE', -- swl
[0x2b] = 'STORE', -- sw
[0x2e] = 'STORE', -- swr
[0x3a] = 'STORE', -- swc2
},
loadOpcodes = {
[0x20] = 'LOAD', -- lb
[0x24] = 'LOAD', -- lbu
[0x21] = 'LOAD', -- lh
[0x25] = 'LOAD', -- lhu
[0x23] = 'LOAD', -- lw
[0x22] = 'LOAD', -- lwl
[0x26] = 'LOAD', -- lwr
},
}
local color = {
blue = 0xffd94545,
green = 0xff00a64b,
lightGreen = 0xff00bf56,
orange = 0xff02abe2,
red = 0xff6666ff,
pink = 0xfff066ff,
grey = 0xffA69d9d,
}
function utility:isStore(code)
local opcode = bit.rshift(code, 26)
local t = utility.storeOpcodes[opcode]
if t == nil then
return false, nil
end
local offsett = bit.band(code, 0xffff)
return true, offsett
end
function utility:isLoad(code)
local opcode = bit.rshift(code, 26)
local t = utility.loadOpcodes[opcode]
if t == nil then
return false, nil
end
local offsett = bit.band(code, 0xffff)
return true, offsett
end
function utility:get_register_value(register)
return PCSX.getRegisters().GPR.r[register]
end
function utility:get4ByteFromMemory(address)
local mem = PCSX.getMemPtr()
local pointer = mem + address - 0x80000000
pointer = ffi.cast('uint32_t*', pointer)
return pointer[0]
end
function utility:get2ByteFromMemory(address)
local mem = PCSX.getMemPtr()
local pointer = mem + address - 0x80000000
pointer = ffi.cast('uint16_t*', pointer)
return pointer[0]
end
function utility:readValueFromMemory(address, bytes)
local value = PCSX.getMemPtr()[(address - 0x80000000)]
if bytes == 2 then value = utility:get2ByteFromMemory(address)
elseif bytes == 4 then value = utility:get4ByteFromMemory(address)
end
return value
end
function utility:isEqualityTrue(memValue, value, equality)
local bool = false
if equality == 0 then bool = memValue == value
elseif equality == 1 then bool = memValue ~= value
elseif equality == 2 then bool = memValue > value
elseif equality == 3 then bool = memValue >= value
elseif equality == 4 then bool = memValue < value
elseif equality == 5 then bool = memValue <= value
end
return bool
end
function utility:setValueInMemory(address, value, bytes)
local pointer = ffi.cast('uint8_t*', (PCSX.getMemPtr() + address - 0x80000000))
if bytes == 2 then pointer = ffi.cast('uint16_t*', (PCSX.getMemPtr() + address - 0x80000000))
elseif bytes == 4 then pointer = ffi.cast('uint32_t*', (PCSX.getMemPtr() + address - 0x80000000))
end
pointer[0] = value
end
function debugger:breakpoint(address, name, type_, bytes)
if address < 0 then return end
if address < 0x80000000 then address = address + 0x80000000 end
debugger.breakpointList[debugger.counter] = PCSX.addBreakpoint(address, type_, bytes, name, function(address, w, c) PCSX.pauseEmulator() end)
debugger.counter = debugger.counter + 1
end
function debugger:breakpointOnWriteChangeFun(address, bytes, label)
local code = utility:get4ByteFromMemory(PCSX.getRegisters().pc)
local isStoreCode, offset = utility:isStore(code)
if isStoreCode then
local address = utility:getRegisterValue(bit.band(bit.rshift(code, 21), 0x1f)) + offset
local new_value = utility:getRegisterValue(bit.band(bit.rshift(code, 16), 0x1f))
local old_value = utility:readValueFromMemory(address, bytes);
if old_value ~= new_value then
PCSX.pauseEmulator()
end
end
end
function debugger:breakpointOnWriteChange(address, name, bytes)
if address < 0 then return end
if address < 0x80000000 then address = address + 0x80000000 end
debugger.breakpointList[debugger.counter] = PCSX.addBreakpoint(address, 'Write', bytes, name, debugger.breakpointOnWriteChangeFun)
debugger.counter = debugger.counter + 1
end
function debugger:breakpointReadWriteEqualityFun(exe_address, type_, bytes, name, value, equality)
return PCSX.addBreakpoint(exe_address, type_, bytes, name, function(address, w, c)
local code = utility:get4ByteFromMemory(PCSX.getRegisters().pc)
local bool, offset = utility:isLoad(code)
if bool then
local address = utility:getRegisterValue(bit.band(bit.rshift(code, 21), 0x1f)) + offset
local mem_value = utility:readValueFromMemory(address, bytes)
if utility:isEqualityTrue(mem_value, value, equality) then
PCSX.pauseEmulator()
end
end
end)
end
function debugger:breakpointReadWriteEquality(address, type_, bytes, name, value, equality)
if address < 0 then return end
if address < 0x80000000 then address = address + 0x80000000 end
debugger.breakpointList[debugger.counter] = debugger:breakpointReadWriteEqualityFun(address, type_, bytes, name, value, equality)
debugger.counter = debugger.counter + 1
end
function debugger:breakpointExecRegisterEqualityFun(exe_address, name, register, equality, value)
return PCSX.addBreakpoint(exe_address, 'Exec', 4, name, function(address, w, c)
if utility:isEqualityTrue(utility:getRegisterValue(register), value, equality) then
PCSX.pauseEmulator()
end
end)
end
function debugger:breakpointExecRegisterEquality(address, name, register, equality, value)
if address < 0 then return end
if address < 0x80000000 then address = address + 0x80000000 end
debugger.breakpointList[debugger.counter] = debugger:breakpointExecRegisterEqualityFun(address, name, register, equality, value)
debugger.counter = debugger.counter + 1
end
function debugger:breakpointReadWritePCEqualityFun(exe_address, type_, bytes, name, pc, equality)
return PCSX.addBreakpoint(exe_address, type_, bytes, name, function(address, w, c)
if utility:isEqualityTrue(PCSX.getRegisters().pc, pc, equality) then
PCSX.pauseEmulator()
end
end)
end
function debugger:breakpointReadWritePCEquality(address, type_, bytes, name, pc, equality)
if address < 0 then return end
if address < 0x80000000 then address = address + 0x80000000 end
debugger.breakpointList[debugger.counter] = debugger:breakpointReadWritePCEqualityFun(address, type_, bytes, name, pc, equality)
debugger.counter = debugger.counter + 1
end
function debugger:breakpointExecMemoryEqualityFun(mem_address, type_, bytes, name, value, equality, pc)
return PCSX.addBreakpoint(mem_address, type_, bytes, name, function(address, w, c)
if PCSX.getRegisters().pc == pc then
local mem_value = utility:readValueFromMemory(mem_address, bytes)
if utility:isEqualityTrue(mem_value, value, equality) then
PCSX.pauseEmulator()
end
end
end)
end
function debugger:breakpointExecMemoryEquality(address, bytes, name, value, equality, pc)
if address < 0 then return end
if address < 0x80000000 then address = address + 0x80000000 end
debugger.breakpointList[debugger.counter] = debugger:breakpointExecMemoryEqualityFun(address, 'Read', bytes, name, value, equality, pc)
debugger.counter = debugger.counter + 1
debugger.breakpointList[debugger.counter] = debugger:breakpointExecMemoryEqualityFun(address, 'Write', bytes, name, value, equality, pc)
debugger.counter = debugger.counter + 1
end
function debugger:breakpointWhatInstructionAccessesFun(address, name, data)
return PCSX.addBreakpoint(address, 'Exec', 4, name, function(address, w, c)
local code = utility:get4ByteFromMemory(PCSX.getRegisters().pc)
local bool, offset = utility:isLoad(code)
if bool then
local mem_address = utility:getRegisterValue(bit.band(bit.rshift(code, 21), 0x1f)) + offset
if data[mem_address] == nil then data[mem_address] = { address = mem_address, count = 0, type = 'R' } end
data[mem_address].count = data[mem_address].count + 1
end
bool, offset = utility:isStore(code)
if bool then
local mem_address = utility:getRegisterValue(bit.band(bit.rshift(code, 21), 0x1f)) + offset
if data[mem_address] == nil then data[mem_address] = { address = mem_address, count = 0, type = 'W' } end
data[mem_address].count = data[mem_address].count + 1
end
end)
end
local instructionAccessesTable = {}
function debugger:breakpointWhatInstructionAccesses(address, name)
if address < 0 then return end
if address < 0x80000000 then address = address + 0x80000000 end
if instructionAccessesTable[address] ~= nil then return end
instructionAccessesTable[address] = { address = address, data = {}, name = name, breakpoint = nil }
instructionAccessesTable[address].breakpoint = debugger:breakpointWhatInstructionAccessesFun(address, name, instructionAccessesTable[address].data)
end
function debugger:breakpointWhatAccessThisMemoryFun(address, bytes, type_, name, data, symbol)
return PCSX.addBreakpoint(address, type_, bytes, name, function(address, w, c)
local exe_address = PCSX.getRegisters().pc
if data[exe_address] == nil then
data[exe_address] = { address = exe_address, count = 0, type = symbol, code = utility:get4ByteFromMemory(exe_address) }
end
data[exe_address].count = data[exe_address].count + 1
end)
end
local accessThisMemoryTable = {}
function debugger:breakpointWhatAccessThisMemory(address, bytes, name)
if address < 0 then return end
if address < 0x80000000 then address = address + 0x80000000 end
if accessThisMemoryTable[address] ~= nil then return end
accessThisMemoryTable[address] = { address = address, data = {}, name = name, breakpoint = nil }
accessThisMemoryTable[address].read_breakpoint = debugger:breakpointWhatAccessThisMemoryFun(address, bytes, 'Read', name, accessThisMemoryTable[address].data, 'R')
accessThisMemoryTable[address].write_breakpoint = debugger:breakpointWhatAccessThisMemoryFun(address, bytes, 'Write', name, accessThisMemoryTable[address].data, 'W')
end
local watcherTable = {}
function debugger:watchValue(address, bytes, name)
if address < 0 then return end
if address < 0x80000000 then address = address + 0x80000000 end
if watcherTable[address] ~= nil then return end
watcherTable[address] = { address = address, name = name, bytes = bytes, valueStr = '', hex = false }
end
local breakpointLabel = ''
local byteList = {
{ name = 'Byte' , value = 1 },
{ name = '2 Byte' , value = 2 },
{ name = '4 Bytes', value = 4 },
}
local equalityList = {
{ name = '==', value = 0 },
{ name = '!=', value = 1 },
{ name = '>' , value = 2 },
{ name = '>=', value = 3 },
{ name = '<' , value = 4 },
{ name = '<=', value = 5 },
}
local registerList = {
{ name = 'at', value = 0x01 },
{ name = 'v0', value = 0x02 },
{ name = 'v1', value = 0x03 },
{ name = 'a0', value = 0x04 },
{ name = 'a1', value = 0x05 },
{ name = 'a2', value = 0x06 },
{ name = 'a3', value = 0x07 },
{ name = 't0', value = 0x08 },
{ name = 't1', value = 0x09 },
{ name = 't2', value = 0x0a },
{ name = 't3', value = 0x0b },
{ name = 't4', value = 0x0c },
{ name = 't5', value = 0x0d },
{ name = 't6', value = 0x0e },
{ name = 't7', value = 0x0f },
{ name = 's0', value = 0x10 },
{ name = 's1', value = 0x11 },
{ name = 's2', value = 0x12 },
{ name = 's3', value = 0x13 },
{ name = 's4', value = 0x14 },
{ name = 's5', value = 0x15 },
{ name = 's6', value = 0x16 },
{ name = 's7', value = 0x17 },
{ name = 't8', value = 0x18 },
{ name = 't9', value = 0x19 },
}
--
local execAddr = 0
local execAddrStr = ''
--
local readWriteChangeAddr = 0
local readWriteChangeAddrStr = ''
local readWriteChangeBytes = 1
local readWriteChangeBytesStr = 'Byte'
--
local readWriteEqualityAddr = 0
local readWriteEqualityAddrStr = ''
local readWriteEquality = 0
local readWriteEqualityStr = '=='
local readWriteEqualityBytes = 1
local readWriteEqualityBytesStr = 'Byte'
local readWriteEqualityAddrVal = 0
local readWriteEqualityAddrValStr = ''
local readWriteEqualityHex = false
--
local execRegisterEqualityAddr = 0
local execRegisterEqualityAddrStr = ''
local execRegisterEqualityReg = 0x01
local execRegisterEqualityRegStr = 'at'
local execRegisterEquality = 0
local execRegisterEqualityStr = '=='
local execRegisterEqualityVal = 0
local execRegisterEqualityValStr = ''
local execRegisterEqualityHex = true
--
local readWritePCAddr = 0
local readWritePCAddrStr = ''
local readWritePCEquality = 0
local readWritePCEqualityStr = '=='
local readWritePCBytes = 1
local readWritePCBytesStr = 'Byte'
local readWritePCVal = 0
local readWritePCValStr = ''
--
local execMemoryAddr = 0
local execMemoryAddrStr = ''
local execMemoryBytes = 1
local execMemoryBytesStr = 'Byte'
local execMemoryVal = 0
local execMemoryValStr = ''
local execMemoryValHex = false
local execMemoryEquality = 0
local execMemoryEqualityStr = '=='
local execMemoryPC = 0
local execMemoryPCStr = ''
--
local instructionAccessesAddr = 0
local instructionAccessesAddrStr = ''
local removeInstructionAccessesTable = {}
--
local accessThisMemoryAddr = 0
local accessThisMemoryAddrStr = ''
local accessThisMemoryBytes = 1
local accessThisMemoryBytesStr = 'Byte'
local removeAccessThisMemoryTable = {}
--
local watcherAddr = 0
local watcherAddrStr = ''
local watcherBytes = 1
local watcherBytesStr = 'Byte'
local removeWatcherTable = {}
local function Render0thRow()
imgui.TextUnformatted('Label: ')
imgui.SameLine()
local bool, value = imgui.extra.InputText('##break-point-label', breakpointLabel)
if bool then breakpointLabel = value end
if imgui.IsItemHovered() then
if imgui.IsMouseDoubleClicked(imgui.constant.MouseButton.Left) then imgui.SetClipboardText(breakpointLabel) end
if imgui.IsMouseDoubleClicked(imgui.constant.MouseButton.Right) then breakpointLabel = imgui.GetClipboardText() end
end
end
local function Render1stRow()
imgui.Separator() imgui.TextUnformatted('|1| ') imgui.SameLine()
imgui.TextUnformatted('Address:')
imgui.SameLine()
imgui.SetNextItemWidth(75)
local bool, value = imgui.extra.InputText('##exec-address', execAddrStr)
if bool then
value = tonumber(value, 16)
if value then
execAddr = value
execAddrStr = string.format('%08x', value)
end
end
if imgui.IsItemHovered() then
if imgui.IsMouseDoubleClicked(imgui.constant.MouseButton.Left) then imgui.SetClipboardText(execAddrStr) end
if imgui.IsMouseDoubleClicked(imgui.constant.MouseButton.Right) then
value = tonumber(imgui.GetClipboardText(), 16)
if value then
execAddr = value
execAddrStr = string.format('%x', execAddr)
end
end
end
imgui.SameLine()
imgui.PushStyleVar(imgui.constant.StyleVar.FrameRounding, 3)
imgui.PushStyleColor(imgui.constant.Col.Button, color.orange)
if imgui.Button('Exec##exec-button', 70, 22) then debugger:breakpoint(execAddr, breakpointLabel, 'Exec', 1) end
imgui.PopStyleColor()
imgui.PopStyleVar()
end
local function Render2ndRow()
imgui.Separator() imgui.TextUnformatted('|2| ') imgui.SameLine()
imgui.TextUnformatted('Address:')
imgui.SameLine()
imgui.SetNextItemWidth(75)
local bool, value = imgui.extra.InputText('##read-write-change-address', readWriteChangeAddrStr)
if bool then
value = tonumber(value, 16)
if (bool) then
readWriteChangeAddr = value
readWriteChangeAddrStr = string.format('%08x', value)
end
end
if imgui.IsItemHovered() then
if imgui.IsMouseDoubleClicked(imgui.constant.MouseButton.Left) then imgui.SetClipboardText(readWriteChangeAddrStr) end
if imgui.IsMouseDoubleClicked(imgui.constant.MouseButton.Right) then
value = tonumber(imgui.GetClipboardText(), 16)
if value then
readWriteChangeAddr = value
readWriteChangeAddrStr = string.format('%x', readWriteChangeAddr)
end
end
end
imgui.SameLine()
imgui.PushItemWidth(65)
imgui.safe.BeginCombo('##read-write-change-bytes', readWriteChangeBytesStr , function()
for k, v in pairs(byteList) do
if imgui.Selectable(v.name) then
readWriteChangeBytes = v.value
readWriteChangeBytesStr = v.name
end
end
end)
imgui.SameLine()
imgui.PushStyleVar(imgui.constant.StyleVar.FrameRounding, 3)
imgui.PushStyleColor(imgui.constant.Col.Button, color.blue)
if imgui.Button('Read##read-write-change1-button', 70, 22) then debugger:breakpoint(readWriteChangeAddr, breakpointLabel, 'Read', readWriteChangeBytes) end
imgui.PopStyleColor()
imgui.PopStyleVar()
imgui.SameLine()
imgui.PushStyleVar(imgui.constant.StyleVar.FrameRounding, 3)
imgui.PushStyleColor(imgui.constant.Col.Button, color.green)
if imgui.Button('Write##read-write-change2-button', 70, 22) then debugger:breakpoint(readWriteChangeAddr, breakpointLabel, 'Write', readWriteChangeBytes) end
imgui.PopStyleColor()
imgui.PopStyleVar()
imgui.SameLine()
imgui.PushStyleVar(imgui.constant.StyleVar.FrameRounding, 3)
imgui.PushStyleColor(imgui.constant.Col.Button, color.lightGreen)
if imgui.Button('Write on Change##read-write-change2-button', 100, 22) then debugger:breakpointOnWriteChange(readWriteChangeAddr, breakpointLabel, readWriteChangeBytes) end
imgui.PopStyleColor()
imgui.PopStyleVar()
end
local function Render3rdRow()
imgui.Separator() imgui.TextUnformatted('|3| ') imgui.SameLine()
imgui.TextUnformatted('Address:')
imgui.SameLine()
imgui.SetNextItemWidth(75)
local bool, value = imgui.extra.InputText('##read-write-equality', readWriteEqualityAddrStr)
if bool then
value = tonumber(value, 16)
if (value) then
readWriteEqualityAddr = value
readWriteEqualityAddrStr = string.format('%08x', value)
end
end
if imgui.IsItemHovered() then
if imgui.IsMouseDoubleClicked(imgui.constant.MouseButton.Left) then imgui.SetClipboardText(readWriteEqualityAddrStr) end
if imgui.IsMouseDoubleClicked(imgui.constant.MouseButton.Right) then
value = tonumber(imgui.GetClipboardText(), 16)
if value then
readWriteEqualityAddr = value
readWriteEqualityAddrStr = string.format('%x', readWriteEqualityAddr)
end
end
end
imgui.SameLine()
imgui.PushItemWidth(65)
imgui.safe.BeginCombo('##read-write-equality-bytes', readWriteEqualityBytesStr , function()
for k, v in pairs(byteList) do
if imgui.Selectable(v.name) then
readWriteEqualityBytes = v.value
readWriteEqualityBytesStr = v.name
end
end
end)
imgui.SameLine()
imgui.PushItemWidth(40)
imgui.safe.BeginCombo('##read-write-equality-value-equality', readWriteEqualityStr , function()
for k, v in pairs(equalityList) do
if imgui.Selectable(v.name) then
readWriteEquality = v.value
readWriteEqualityStr = v.name
end
end
end)
imgui.SameLine()
imgui.TextUnformatted('Value:')
imgui.SameLine()
imgui.SetNextItemWidth(65)
bool, value = imgui.extra.InputText('##read-write-equality-value', readWriteEqualityAddrValStr)
if bool then
local base = 10
local base_format = '%d'
if readWriteEqualityHex then
base = 16
base_format = '0x%x'
end
value = tonumber(value, base)
if (value) then
readWriteEqualityAddrVal = value
readWriteEqualityAddrValStr = string.format(base_format, value)
end
end
if imgui.IsItemHovered() then
if imgui.IsMouseDoubleClicked(imgui.constant.MouseButton.Left) then imgui.SetClipboardText(readWriteEqualityAddrValStr) end
if imgui.IsMouseDoubleClicked(imgui.constant.MouseButton.Right) then
local base = 10
local base_format = '%d'
if readWriteEqualityHex then
base = 16
base_format = '0x%x'
end
value = tonumber(imgui.GetClipboardText(), base)
if value then
readWriteEqualityAddrVal = value
readWriteEqualityAddrValStr = string.format(base_format, readWriteEqualityAddrVal)
end
end
end
imgui.SameLine()
bool, value = imgui.Checkbox('Hex##read-write-equality-hex', readWriteEqualityHex)
if bool then
readWriteEqualityHex = value
if (value) then readWriteEqualityAddrValStr = string.format('0x%x', readWriteEqualityAddrVal)
else readWriteEqualityAddrValStr = string.format('%d', readWriteEqualityAddrVal) end
end
imgui.SameLine()
imgui.PushStyleVar(imgui.constant.StyleVar.FrameRounding, 3)
imgui.PushStyleColor(imgui.constant.Col.Button, color.blue)
if imgui.Button('Read##read-write-equality1-button', 70, 22) then debugger:breakpointReadWriteEquality(readWriteEqualityAddr, 'Read', readWriteEqualityBytes, breakpointLabel, readWriteEqualityAddrVal, readWriteEquality) end
imgui.PopStyleColor()
imgui.PopStyleVar()
imgui.SameLine()
imgui.PushStyleVar(imgui.constant.StyleVar.FrameRounding, 3)
imgui.PushStyleColor(imgui.constant.Col.Button, color.green)
if imgui.Button('Write##read-write-equality2-button', 70, 22) then debugger:breakpointReadWriteEquality(readWriteEqualityAddr, 'Write', readWriteEqualityBytes, breakpointLabel, readWriteEqualityAddrVal, readWriteEquality) end
imgui.PopStyleColor()
imgui.PopStyleVar()
end
local function Render4thRow()
imgui.Separator() imgui.TextUnformatted('|4| ') imgui.SameLine()
imgui.TextUnformatted('Address:')
imgui.SameLine()
imgui.SetNextItemWidth(75)
local bool, value = imgui.extra.InputText('##exec-register-equality-address', execRegisterEqualityAddrStr)
if bool then
value = tonumber(value, 16)
if (value) then
execRegisterEqualityAddr = value
execRegisterEqualityAddrStr = string.format('%08x', value)
end
end
if imgui.IsItemHovered() then
if imgui.IsMouseDoubleClicked(imgui.constant.MouseButton.Left) then imgui.SetClipboardText(execRegisterEqualityAddrStr) end
if imgui.IsMouseDoubleClicked(imgui.constant.MouseButton.Right) then
value = tonumber(imgui.GetClipboardText(), 16)
if value then
execRegisterEqualityAddr = value
execRegisterEqualityAddrStr = string.format('%x', execRegisterEqualityAddr)
end
end
end
imgui.SameLine()
imgui.PushItemWidth(65)
imgui.safe.BeginCombo('##exec-register-equality-reg', execRegisterEqualityRegStr , function()
for k, v in pairs(registerList) do
if imgui.Selectable(v.name) then
execRegisterEqualityReg = v.value
execRegisterEqualityRegStr = v.name
end
end
end)
imgui.SameLine()
imgui.PushItemWidth(40)
imgui.safe.BeginCombo('##exec-register-equality', execRegisterEqualityStr , function()
for k, v in pairs(equalityList) do
if imgui.Selectable(v.name) then
execRegisterEquality = v.value
execRegisterEqualityStr = v.name
end
end
end)
imgui.SameLine()
imgui.TextUnformatted('Value:')
imgui.SameLine()
imgui.SetNextItemWidth(65)
bool, value = imgui.extra.InputText('##exec-register-equality-value', execRegisterEqualityValStr)
if bool then
local base = 10
local base_format = '%d'
if execRegisterEqualityHex then
base = 16
base_format = '0x%x'
end
value = tonumber(value, base)
if (value) then
execRegisterEqualityVal = value
execRegisterEqualityValStr = string.format(base_format, value)
end
end
if imgui.IsItemHovered() then
if imgui.IsMouseDoubleClicked(imgui.constant.MouseButton.Left) then imgui.SetClipboardText(execRegisterEqualityValStr) end
if imgui.IsMouseDoubleClicked(imgui.constant.MouseButton.Right) then
local base = 10
local base_format = '%d'
if execRegisterEqualityHex then
base = 16
base_format = '0x%x'
end
value = tonumber(imgui.GetClipboardText(), base)
if value then
execRegisterEqualityVal = value
execRegisterEqualityValStr = string.format(base_format, execRegisterEqualityVal)
end
end
end
imgui.SameLine()
bool, value = imgui.Checkbox('Hex##exec-register-equality-hex', execRegisterEqualityHex)
if bool then
execRegisterEqualityHex = value
if (value) then execRegisterEqualityValStr = string.format('0x%x', execRegisterEqualityVal)
else execRegisterEqualityValStr = string.format('%d', execRegisterEqualityVal) end
end
imgui.SameLine()
imgui.PushStyleVar(imgui.constant.StyleVar.FrameRounding, 3)
imgui.PushStyleColor(imgui.constant.Col.Button, color.orange)
if imgui.Button('Exec##exec-register-equality-button', 70, 22) then debugger:breakpointExecRegisterEquality(execRegisterEqualityAddr, breakpointLabel, execRegisterEqualityReg, execRegisterEquality, execRegisterEqualityVal) end
imgui.PopStyleColor()
imgui.PopStyleVar()
end
local function Render5thRow()
imgui.Separator() imgui.TextUnformatted('|5| ') imgui.SameLine()
imgui.TextUnformatted('Address:')
imgui.SameLine()
imgui.SetNextItemWidth(75)
local bool, value = imgui.extra.InputText('##instruction-accesses-address', instructionAccessesAddrStr)
if bool then
value = tonumber(value, 16)
if (value) then
instructionAccessesAddr = value
instructionAccessesAddrStr = string.format('%08x', value)
end
end
if imgui.IsItemHovered() then
if imgui.IsMouseDoubleClicked(imgui.constant.MouseButton.Left) then imgui.SetClipboardText(instructionAccessesAddrStr) end
if imgui.IsMouseDoubleClicked(imgui.constant.MouseButton.Right) then
value = tonumber(imgui.GetClipboardText(), 16)
if value then
instructionAccessesAddr = value
instructionAccessesAddrStr = string.format('%x', instructionAccessesAddr)
end
end
end
imgui.SameLine()
imgui.PushStyleVar(imgui.constant.StyleVar.FrameRounding, 3)
imgui.PushStyleColor(imgui.constant.Col.Button, color.red)
if imgui.Button('What Instruction Accesses##instruction-accesses-button', 160, 22) then debugger:breakpointWhatInstructionAccesses(instructionAccessesAddr, breakpointLabel) end
imgui.PopStyleColor()
imgui.PopStyleVar()
end
local function Render6thRow()
imgui.Separator() imgui.TextUnformatted('|6| ') imgui.SameLine()
imgui.TextUnformatted('Address:')
imgui.SameLine()
imgui.SetNextItemWidth(75)
local bool, value = imgui.extra.InputText('##access-this-memory-address', accessThisMemoryAddrStr)
if bool then
value = tonumber(value, 16)
if (value) then
accessThisMemoryAddr = value
accessThisMemoryAddrStr = string.format('%08x', value)
end
end
if imgui.IsItemHovered() then
if imgui.IsMouseDoubleClicked(imgui.constant.MouseButton.Left) then imgui.SetClipboardText(accessThisMemoryAddrStr) end
if imgui.IsMouseDoubleClicked(imgui.constant.MouseButton.Right) then
value = tonumber(imgui.GetClipboardText(), 16)
if value then
accessThisMemoryAddr = value
accessThisMemoryAddrStr = string.format('%x', accessThisMemoryAddr)
end
end
end
imgui.SameLine()
imgui.PushItemWidth(65)
imgui.safe.BeginCombo('##access-this-memory-bytes', accessThisMemoryBytesStr , function()
for k, v in pairs(byteList) do
if imgui.Selectable(v.name) then
accessThisMemoryBytes = v.value
accessThisMemoryBytesStr = v.name
end
end
end)
imgui.SameLine()
imgui.PushStyleVar(imgui.constant.StyleVar.FrameRounding, 3)
imgui.PushStyleColor(imgui.constant.Col.Button, color.pink)
if imgui.Button('What Access this Memory##access-this-memory-button', 160, 22) then debugger:breakpointWhatAccessThisMemory(accessThisMemoryAddr, accessThisMemoryBytes, breakpointLabel) end
imgui.PopStyleColor()
imgui.PopStyleVar()
end
local function Render7thRow()
imgui.Separator() imgui.TextUnformatted('|7| ') imgui.SameLine()
imgui.TextUnformatted('Address:')
imgui.SameLine()
imgui.SetNextItemWidth(75)
bool, value = imgui.extra.InputText('##read-write-pc', readWritePCAddrStr)
if bool then
value = tonumber(value, 16)
if (value) then
readWritePCAddr = value
readWritePCAddrStr = string.format('%08x', value)
end
end
if imgui.IsItemHovered() then
if imgui.IsMouseDoubleClicked(imgui.constant.MouseButton.Left) then imgui.SetClipboardText(readWritePCAddrStr) end
if imgui.IsMouseDoubleClicked(imgui.constant.MouseButton.Right) then
value = tonumber(imgui.GetClipboardText(), 16)
if value then
readWritePCAddr = value
readWritePCAddrStr = string.format('%x', readWritePCAddr)
end
end
end
imgui.SameLine()
imgui.PushItemWidth(65)
imgui.safe.BeginCombo('##read-write-pc-bytes', readWritePCBytesStr , function()
for k, v in pairs(byteList) do
if imgui.Selectable(v.name) then
readWritePCBytes = v.value
readWritePCBytesStr = v.name
end
end
end)
imgui.SameLine()
imgui.TextUnformatted('PC:')
imgui.SameLine()
imgui.SetNextItemWidth(60)
bool, value = imgui.extra.InputText('##read-write-pc-value', readWritePCValStr)
if bool then
value = tonumber(value, 16)
if (value) then
readWritePCVal = value
readWritePCValStr = string.format('%x', value)
end
end
if imgui.IsItemHovered() then
if imgui.IsMouseDoubleClicked(imgui.constant.MouseButton.Left) then imgui.SetClipboardText(readWritePCValStr) end
if imgui.IsMouseDoubleClicked(imgui.constant.MouseButton.Right) then
value = tonumber(imgui.GetClipboardText(), 16)
if value then
readWritePCVal = value
readWritePCValStr = string.format('%x', value)
end
end
end
imgui.SameLine()
imgui.PushItemWidth(40)
imgui.safe.BeginCombo('##read-write-pc-value-equality', readWritePCEqualityStr , function()
for k, v in pairs(equalityList) do
if imgui.Selectable(v.name) then
readWritePCEquality = v.value
readWritePCEqualityStr = v.name
end
if v.value == 1 then break end
end
end)
imgui.SameLine()
imgui.PushStyleVar(imgui.constant.StyleVar.FrameRounding, 3)
imgui.PushStyleColor(imgui.constant.Col.Button, color.blue)
if imgui.Button('Read##read-write-pc-1-button', 70, 22) then debugger:breakpointReadWritePCEquality(readWritePCAddr, 'Read', readWritePCBytes, breakpointLabel, readWritePCVal, readWritePCEquality) end
imgui.PopStyleColor()
imgui.PopStyleVar()
imgui.SameLine()
imgui.PushStyleVar(imgui.constant.StyleVar.FrameRounding, 3)
imgui.PushStyleColor(imgui.constant.Col.Button, color.green)
if imgui.Button('Write##read-write-pc-2-button', 70, 22) then debugger:breakpointReadWritePCEquality(readWritePCAddr, 'Write', readWritePCBytes, breakpointLabel, readWritePCVal, readWritePCEquality) end
imgui.PopStyleColor()
imgui.PopStyleVar()
end
local function Render8thRow()
imgui.Separator() imgui.TextUnformatted('|8| ') imgui.SameLine()
imgui.TextUnformatted('Address:')
imgui.SameLine()
imgui.SetNextItemWidth(75)
bool, value = imgui.extra.InputText('##exec-memory-address', execMemoryAddrStr)
if bool then
value = tonumber(value, 16)
if (value) then
execMemoryAddr = value
execMemoryAddrStr = string.format('%08x', value)
end
end
if imgui.IsItemHovered() then
if imgui.IsMouseDoubleClicked(imgui.constant.MouseButton.Left) then imgui.SetClipboardText(execMemoryAddrStr) end
if imgui.IsMouseDoubleClicked(imgui.constant.MouseButton.Right) then
value = tonumber(imgui.GetClipboardText(), 16)
if value then
execMemoryAddr = value
execMemoryAddrStr = string.format('%x', execMemoryAddr)
end
end
end
imgui.SameLine()
imgui.PushItemWidth(65)
imgui.safe.BeginCombo('##exec-memroy-bytes', execMemoryBytesStr , function()
for k, v in pairs(byteList) do
if imgui.Selectable(v.name) then
execMemoryBytes = v.value
execMemoryBytesStr = v.name
end
end
end)
imgui.SameLine()
imgui.PushItemWidth(40)
imgui.safe.BeginCombo('##exec-memroy-equality', execMemoryEqualityStr , function()
for k, v in pairs(equalityList) do
if imgui.Selectable(v.name) then
execMemoryEquality = v.value
execMemoryEqualityStr = v.name
end
end
end)
imgui.SameLine()
imgui.TextUnformatted('Value:')
imgui.SameLine()
imgui.SetNextItemWidth(65)
bool, value = imgui.extra.InputText('##exec-memory-value', execMemoryValStr)
if bool then
local base = 10
local base_format = '%d'
if execMemoryValHex then
base = 16
base_format = '0x%x'
end
value = tonumber(value, base)
if (value) then
execMemoryVal = value
execMemoryValStr = string.format(base_format, value)
end
end
if imgui.IsItemHovered() then
if imgui.IsMouseDoubleClicked(imgui.constant.MouseButton.Left) then imgui.SetClipboardText(execMemoryValStr) end
if imgui.IsMouseDoubleClicked(imgui.constant.MouseButton.Right) then
local base = 10
local base_format = '%d'
if execMemoryValHex then
base = 16
base_format = '0x%x'
end
value = tonumber(imgui.GetClipboardText(), base)
if value then
execMemoryVal = value
execMemoryValStr = string.format(base_format, execMemoryVal)
end
end
end
imgui.SameLine()
bool, value = imgui.Checkbox('Hex##exec-memroy-hex', execMemoryValHex)
if bool then
execMemoryValHex = value
if (value) then execMemoryValStr = string.format('0x%x', execMemoryVal)
else execMemoryValStr = string.format('%d', execMemoryVal) end
end
imgui.SameLine()
imgui.TextUnformatted('PC:')
imgui.SameLine()
imgui.SetNextItemWidth(60)
bool, value = imgui.extra.InputText('##exec-memory-pc', execMemoryPCStr)
if bool then
value = tonumber(value, 16)
if (value) then
execMemoryPC = value
execMemoryPCStr = string.format('%x', value)
end
end
if imgui.IsItemHovered() then
if imgui.IsMouseDoubleClicked(imgui.constant.MouseButton.Left) then imgui.SetClipboardText(execMemoryPCStr) end
if imgui.IsMouseDoubleClicked(imgui.constant.MouseButton.Right) then
value = tonumber(imgui.GetClipboardText(), 16)
if value then
execMemoryPC = value
execMemoryPCStr = string.format('%x', value)
end
end
end
imgui.SameLine()
imgui.PushStyleVar(imgui.constant.StyleVar.FrameRounding, 3)
imgui.PushStyleColor(imgui.constant.Col.Button, color.orange)
if imgui.Button('Exec##exec-memory-button', 70, 22) then debugger:breakpointExecMemoryEquality(execMemoryAddr, execMemoryBytes, breakpointLabel, execMemoryVal, execMemoryEquality, execMemoryPC) end
imgui.PopStyleColor()
imgui.PopStyleVar()
end
local function Render9thRow()
imgui.Separator() imgui.TextUnformatted('|9| ') imgui.SameLine()
imgui.TextUnformatted('Address:')
imgui.SameLine()
imgui.SetNextItemWidth(75)
local bool, value = imgui.extra.InputText('##watcher-address', watcherAddrStr)
if bool then
value = tonumber(value, 16)
if (value) then
watcherAddr = value
watcherAddrStr = string.format('%08x', value)
end
end
if imgui.IsItemHovered() then
if imgui.IsMouseDoubleClicked(imgui.constant.MouseButton.Left) then imgui.SetClipboardText(watcherAddrStr) end
if imgui.IsMouseDoubleClicked(imgui.constant.MouseButton.Right) then
value = tonumber(imgui.GetClipboardText(), 16)
if value then
watcherAddr = value
watcherAddrStr = string.format('%x', value)
end
end
end
imgui.SameLine()
imgui.PushItemWidth(65)
imgui.safe.BeginCombo('##watcher-bytes', watcherBytesStr , function()
for k, v in pairs(byteList) do
if imgui.Selectable(v.name) then
watcherBytes = v.value
watcherBytesStr = v.name
end
end
end)
imgui.SameLine()
imgui.PushStyleVar(imgui.constant.StyleVar.FrameRounding, 3)
imgui.PushStyleColor(imgui.constant.Col.Button, color.grey)
if imgui.Button('Add##watcher-button', 70, 22) then debugger:watchValue(watcherAddr, watcherBytes, breakpointLabel) end
imgui.PopStyleColor()
imgui.PopStyleVar()
end
local function RenderChildWindows()
for k, v in pairs(instructionAccessesTable) do
imgui.PushID('instruction_accesses_table')
imgui.safe.Begin(string.format('Accessed addresses by %08x', v.address), function ()
imgui.TextUnformatted("Name: ") imgui.SameLine() imgui.TextUnformatted(v.name)
imgui.BeginTable(string.format('t%x', v.address), 4, imgui.constant.TableFlags.Borders)
imgui.TableSetupColumn("index", imgui.constant.TableColumnFlags.WidthFixed)
imgui.TableSetupColumn("Address", imgui.constant.TableColumnFlags.WidthFixed)
imgui.TableSetupColumn("Count", imgui.constant.TableColumnFlags.WidthFixed)
imgui.TableSetupColumn("Type", imgui.constant.TableColumnFlags.WidthFixed)
imgui.TableHeadersRow()
local i = 1
for k1, v1 in pairs(v.data) do
imgui.TableNextRow()
imgui.TableNextColumn()
imgui.TextUnformatted(i)
imgui.TableNextColumn()
if imgui.SmallButton(string.format('%08x##%d%d', v1.address, v.address, v1.address)) then
imgui.SetClipboardText(string.format('%08x', v1.address))
end
if imgui.IsMouseClicked(imgui.constant.MouseButton.Right) and imgui.IsItemHovered() then
PCSX.GUI.jumpToMemory(v1.address)
end
imgui.TableNextColumn()
imgui.TextUnformatted(v1.count)
imgui.TableNextColumn()
imgui.TextUnformatted(v1.type)
end
imgui.EndTable()
if imgui.Button(string.format('%08x', v.address)) then
PCSX.GUI.jumpToPC(v.address)
imgui.SetClipboardText(string.format('%08x', v.address))
end
imgui.SameLine()
if imgui.Button('Copy All') then
local value = ''
for k1, v1 in pairs(v.data) do
value = value .. string.format('%08x\n', v1.address)
end
imgui.SetClipboardText(value)
end
imgui.SameLine()
if v.breakpoint:isEnabled() then
if imgui.Button('Stop') then v.breakpoint:disable() end
else
if imgui.Button('Start') then v.breakpoint:enable() end
end
imgui.SameLine()