1
0
mirror of https://github.com/mnaberez/py65.git synced 2025-04-08 19:40:03 +00:00

Move breakpoints out of AddressParser and into Monitor

This commit is contained in:
Mike Naberezny 2014-12-13 19:44:47 -08:00
parent 56cee6fbbd
commit 442501f338
3 changed files with 17 additions and 21 deletions

View File

@ -46,6 +46,7 @@ class Monitor(cmd.Cmd):
if argv is None:
argv = sys.argv
self._reset(self.mpu_type)
self._breakpoints = []
self._width = 78
self.prompt = "."
self._add_shortcuts()
@ -437,7 +438,7 @@ class Monitor(cmd.Cmd):
def _run(self, stopcodes=[]):
last_instruct = None
if not self._address_parser.breakpoints:
if not self._breakpoints:
while last_instruct not in stopcodes:
self._mpu.step()
last_instruct = self._mpu.memory[self._mpu.pc]
@ -447,11 +448,11 @@ class Monitor(cmd.Cmd):
while last_instruct not in stopcodes and not breakpoint:
self._mpu.step()
last_instruct = self._mpu.memory[self._mpu.pc]
if self._mpu.pc in self._address_parser.breakpoints:
self._output("Breakpoint %d reached." % self._address_parser.breakpoints.index(self._mpu.pc))
if self._mpu.pc in self._breakpoints:
msg = "Breakpoint %d reached."
self._output(msg % self._breakpoints.index(self._mpu.pc))
breakpoint = True
def help_radix(self):
self._output("radix [H|D|O|B]")
self._output("Set default radix to hex, decimal, octal, or binary.")
@ -761,11 +762,12 @@ class Monitor(cmd.Cmd):
address = self._address_parser.number(split[0])
if address not in self._address_parser.breakpoints:
self._output("Breakpoint %d added at $%04X" % (len(self._address_parser.breakpoints), address))
self._address_parser.breakpoints.append(address)
else:
if address in self._breakpoints:
self._output("Breakpoint already present at $%04X" % address)
else:
self._breakpoints.append(address)
msg = "Breakpoint %d added at $%04X"
self._output(msg % (len(self._breakpoints), address))
def help_add_breakpoint(self):
self._output("add_breakpoint <address|label>")
@ -787,8 +789,8 @@ class Monitor(cmd.Cmd):
self._output("Illegal number: %s" % args)
return
if self._address_parser.breakpoints[number] is not None:
self._address_parser.breakpoints[number] = None
if self._breakpoints[number] is not None:
self._breakpoints[number] = None
self._output("Breakpoint %d removed" % number)
else:
self._output("Breakpoint %d already removed" % number)
@ -798,7 +800,7 @@ class Monitor(cmd.Cmd):
self._output("Delete the breakpoint on execution marked by the given number")
def do_list_breakpoints(self, args):
for (index, bp) in enumerate(self._address_parser.breakpoints):
for (index, bp) in enumerate(self._breakpoints):
if bp is None:
continue
label = self._address_parser.label_for(bp, '')

View File

@ -67,7 +67,7 @@ class MonitorTests(unittest.TestCase):
mon.do_add_breakpoint('ffd2')
out = stdout.getvalue()
address_parser = mon._address_parser
self.assertTrue(0xffd2 in address_parser.breakpoints)
self.assertTrue(0xffd2 in mon._breakpoints)
def test_do_add_breakpoint_adds_number(self):
stdout = StringIO()
@ -76,7 +76,7 @@ class MonitorTests(unittest.TestCase):
address_parser.labels['chrout'] = 0xffd2
mon.do_add_breakpoint('chrout')
out = stdout.getvalue()
self.assertTrue(0xffd2 in address_parser.breakpoints)
self.assertTrue(0xffd2 in mon._breakpoints)
# add_label
@ -461,7 +461,7 @@ class MonitorTests(unittest.TestCase):
def test_goto_stops_execution_at_breakpoint(self):
stdout = StringIO()
mon = Monitor(stdout=stdout)
mon._address_parser.breakpoints = [ 0x02 ]
mon._breakpoints = [ 0x02 ]
mon._mpu.memory = [ 0xEA, 0xEA, 0xEA, 0xEA ]
mon.do_goto('0')
out = stdout.getvalue()

View File

@ -5,7 +5,7 @@ class AddressParser(object):
"""Parse user input into addresses or ranges of addresses.
"""
def __init__(self, maxwidth=16, radix=16, labels={}, breakpoints=[]):
def __init__(self, maxwidth=16, radix=16, labels={}):
"""Maxwidth is the maximum width of an address in bits.
Radix is the default radix to use when one is not specified
as a prefix of any input. Labels are a dictionary of label
@ -18,12 +18,6 @@ class AddressParser(object):
for k, v in labels.items():
self.labels[k] = self._constrain(v)
self.breakpoints = []
for v in breakpoints:
address = self._constrain(v)
if address not in self.breakpoints:
self.breakpoints.append(address)
def _get_maxwidth(self):
return self._maxwidth