-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug.py
72 lines (54 loc) · 1.84 KB
/
debug.py
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
import time
class debug:
validopcodes = []
breakpoints = []
def __init__(self, reg, addr):
self.instructionCount = 0
self.logevry = 100000
self.currentTime = time.time()
self.register = reg
self.addressapce = addr
self.oldreg = None
def tick(self, opcode):
self.instructionCount += 1
self.checkBreakpoint(self.instructionCount, opcode)
if(self.logevry > 0 and self.instructionCount % self.logevry == 0):
print("{} {} {}".format(self.instructionCount, opcode, time.time()-self.currentTime))
self.currentTime = time.time()
return True
def trace(self, opcode):
registerStatus = self.register.getStatus().split("PC")[0]
if(registerStatus != self.oldreg):
print("Opcode : {}".format(opcode.label))
print(registerStatus)
self.oldreg = registerStatus
def addBreakpoint(self, instruction, log=True):
if(instruction not in self.breakpoints):
if(type(instruction) == int):
if(log):
print("Added breakpoint when instructionCount == {}".format(instruction))
else:
opcodeLabel = self.validopcodes[int(instruction, 16)].label
if(log):
print("Added breakpoint on instruction '{}'".format(opcodeLabel))
self.breakpoints.append(instruction)
def giveOpcodes(self, opcodeList):
self.validopcodes = opcodeList
def checkBreakpoint(self, value, currentopcode=None):
if(value in self.breakpoints):
def commands():
print("press [c] to continue, [cc] to continue one instruction, [r] to get register and [q] to exit")
command = input()
if(command == "c"):
pass
elif(command == "r"):
print(self.register.getStatus())
elif(command == "cc"):
self.addBreakpoint(self.instructionCount + 1, log=False)
elif(command == "q"):
print("bye")
exit(0)
else:
return commands()
print("*breakpoint at {}[{}]*".format(value, currentopcode))
commands()