import cli def callback(): # print 'called' cli.specify_vm_interrupt(simulator, cli.INTERRUPT_TIMER, 1) cli.register_callback(simulator, callback)
#!/usr/bin/env python """ Main script that starts up the simulator's interface """ import sys import cli def empty_callback(): """ Needed so Python can call PyErr_CheckSignals in case the user hits ^C. We could also set a signal handler for SIGINT and call vm_break_async_signal, which would be a lot faster, but we wouldn't be able to interrupt any Python code (not from the C signal handler at least). """ banner = "Welcome to the simulator's debugging interface. Type help for help." if __name__ == '__main__': if len(sys.argv) != 2: sys.stderr.write("Usage: %s program\n" % sys.argv[0]) else: simulator_cli = cli.SimulatorCLI(sys.argv[1]) cli.register_callback(simulator_cli.simulator, empty_callback) simulator_cli.simulator.load_plugins() simulator_cli.cmdloop(banner)
""" This is an example plugin that defines a callback which is called at every step. 'simulator' is a global variable automatically available. A plugin may inspect and alter the state of the simulation and may specify new interrupts that should be triggered by using 'cli.specify_vm_interrupt'. """ import sys import cli def cycle_progress_bar(): import time; time.sleep(0.005) sys.stdout.write('%s\r' % simulator.cycles) sys.stdout.flush() def specify_interrupt(): # Specify an interrupt that should be triggered after 1 cycle has passed cli.specify_vm_interrupt(simulator, cli.INTERRUPT_TIMER, 1) cli.register_callback(simulator, cycle_progress_bar) cli.register_callback(simulator, specify_interrupt)