-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebugger.py
More file actions
67 lines (59 loc) · 2.51 KB
/
debugger.py
File metadata and controls
67 lines (59 loc) · 2.51 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
from seq import ExecEnd
import readline
class Debugger(object):
"""The Debugger allows the user to step through the micro-code"""
def __init__(self, seq):
""" Instantiate the Debugger class
Args:
seq - the seq that should be run
"""
super(Debugger, self).__init__()
self.seq = seq
self.actions = {
'stop': ['q', 'quit', 'exit', 'stop'],
'continue': ['c', 'continue', 'cont', 'run'],
'step': ['s', 'step'],
'display cpu state': ['d', 'display', 'p', 'print'],
'display memory': ['m', 'mem', 'memory'],
'display flags': ['f', 'flags', 'flag'],
'display registers': ['r', 'reg', 'registers'],
'display help': ['h', 'help'],
'display internal state': ['i', 'internal'],
}
def getHelp(self):
'''Display a list of available commands'''
cmds = ''
for k, v in self.actions.items():
cmds += '{}: {}\n'.format(k, ', '.join(v))
return 'Available commands:\n{}'.format(cmds)
def attach(self):
'''Start the seq by attaching the debugger'''
action = self.actions['step'][0]
print(self.getHelp())
try:
while action not in self.actions['stop']:
last_action = action
action = input('> ')
if action == '':
action = last_action
if action in self.actions['continue']:
while True:
self.seq.execMicroInstr()
elif action in self.actions['step']:
self.seq.execMicroInstr()
elif action in self.actions['display cpu state']:
print(self.seq.showCpu())
elif action in self.actions['display memory']:
print(self.seq.showMem())
elif action in self.actions['display flags']:
print(self.seq.showFlags())
elif action in self.actions['display registers']:
print(self.seq.showReg())
elif action in self.actions['display help']:
print(self.getHelp())
elif action in self.actions['display internal state']:
print(self.seq.showInternalState())
elif action not in self.actions['stop']:
print('Unknown action, use "h" to get help, "q" to quit')
except ExecEnd:
print(self.seq.showCpu())