added stepping functionality to the debugger
parent
521cb73ad6
commit
39d5212d3d
@ -1,31 +1,46 @@
|
|||||||
import typing
|
import typing
|
||||||
|
from .Registers import Registers
|
||||||
if typing.TYPE_CHECKING:
|
if typing.TYPE_CHECKING:
|
||||||
from . import *
|
from . import *
|
||||||
|
|
||||||
|
|
||||||
def launch_debug_session(cpu: 'CPU', mmu: 'MMU', reg: 'Registers', prompt=""):
|
def launch_debug_session(cpu: 'CPU', mmu: 'MMU', reg: 'Registers', prompt=""):
|
||||||
if not cpu.conf.debug_instruction:
|
if not cpu.conf.debug_instruction or cpu.active_debug:
|
||||||
return
|
return
|
||||||
import code
|
import code
|
||||||
import readline
|
import readline
|
||||||
import rlcompleter
|
import rlcompleter
|
||||||
|
|
||||||
# setup some aliases
|
cpu.active_debug = True
|
||||||
|
|
||||||
|
# setup some aliases:
|
||||||
registers = reg
|
registers = reg
|
||||||
regs = reg
|
regs = reg
|
||||||
memory = mmu
|
memory = mmu
|
||||||
mem = mmu
|
mem = mmu
|
||||||
syscall_interface = cpu.syscall_int
|
syscall_interface = cpu.syscall_int
|
||||||
|
|
||||||
|
# setup helper functions:
|
||||||
def dump(what, *args, **kwargs):
|
def dump(what, *args, **kwargs):
|
||||||
if isinstance(what, Registers):
|
if isinstance(what, Registers):
|
||||||
regs.dump(*args, **kwargs)
|
regs.dump(*args, **kwargs)
|
||||||
else:
|
else:
|
||||||
mmu.dump(what, *args, **kwargs)
|
mmu.dump(what, *args, **kwargs)
|
||||||
|
|
||||||
|
def ins():
|
||||||
|
print("Current instruction at 0x{:08X}:".format(cpu.pc))
|
||||||
|
return mmu.read_ins(cpu.pc)
|
||||||
|
|
||||||
|
def cont(verbose=True):
|
||||||
|
cpu.continue_from_debugger(verbose)
|
||||||
|
|
||||||
|
def step():
|
||||||
|
cpu.step()
|
||||||
|
|
||||||
sess_vars = globals()
|
sess_vars = globals()
|
||||||
sess_vars.update(locals())
|
sess_vars.update(locals())
|
||||||
|
|
||||||
readline.set_completer(rlcompleter.Completer(sess_vars).complete)
|
readline.set_completer(rlcompleter.Completer(sess_vars).complete)
|
||||||
readline.parse_and_bind("tab: complete")
|
readline.parse_and_bind("tab: complete")
|
||||||
code.InteractiveConsole(sess_vars).interact(banner=prompt, exitmsg="Resuming simulation")
|
code.InteractiveConsole(sess_vars).interact(banner=prompt, exitmsg="Exiting debugger")
|
||||||
|
cpu.active_debug = False
|
||||||
|
Loading…
Reference in New Issue