Add a 'step' command to vdb

This commit is contained in:
Charles Cooper 2019-05-09 12:01:59 -07:00
parent 3c372ae696
commit 8aed791e15
3 changed files with 29 additions and 10 deletions

View File

@ -30,6 +30,7 @@ if tb_limit:
aparser = argparse.ArgumentParser(description='Vyper {0} quick CLI runner'.format(vyper.__version__))
aparser.add_argument('input_file', help='Vyper sourcecode to run')
aparser.add_argument('call_list', help='call list, without parameters: func, with parameters func(1, 2, 3). Semicolon separated')
aparser.add_argument('--trace', action='store_true', help='very verbose logging')
aparser.add_argument('-i', help='init args, comma separated', default=None, dest='init_args')
args = aparser.parse_args()
@ -133,6 +134,8 @@ if __name__ == '__main__':
init_args = args.init_args.split(',') if args.init_args else []
tester, w3 = get_tester(code)
setattr(vdb.debug_computation.DebugComputation, 'trace', args.trace)
# Built list of calls to make.
calls = []
for signature in args.call_list.split(';'):

View File

@ -27,17 +27,22 @@ class DebugComputation(ByzantiumComputation):
source_map = None
stdin = None
stdout = None
step_mode = False
trace = False
pc = 0
@classmethod
def run_debugger(self, computation, line_no):
VyperDebugCmd(
res = VyperDebugCmd(
computation,
line_no=line_no,
source_code=self.source_code,
source_map=self.source_map,
stdin=self.stdin,
stdout=self.stdout
).cmdloop()
)
res.cmdloop()
self.step_mode = res.step_mode
return line_no
@classmethod
@ -82,16 +87,19 @@ class DebugComputation(ByzantiumComputation):
opcode_fn = computation.get_opcode_fn(opcode)
pc_to_execute = max(0, computation.code.pc - 1)
computation.logger.trace(
"OPCODE: 0x%x (%s) | pc: %s",
opcode,
opcode_fn.mnemonic,
pc_to_execute,
)
if cls.trace:
print(
"NEXT OPCODE: 0x%x (%s) | pc: %s..%s" %
(opcode,
opcode_fn.mnemonic,
cls.pc,
pc_to_execute)
)
cls.pc = pc_to_execute
is_breakpoint, line_no = cls.is_breakpoint(pc_to_execute, continue_line_nos)
if is_breakpoint and cls.enable_debug:
if (is_breakpoint or cls.step_mode) and cls.enable_debug:
cls.run_debugger(computation, line_no)
continue_line_nos.append(line_no)

View File

@ -49,6 +49,7 @@ class VyperDebugCmd(cmd.Cmd):
self.line_no = line_no
self.global_vars = source_map.get("globals", {})
self.local_vars = source_map.get("locals", {})
self.step_mode = False
super().__init__(stdin=stdin, stdout=stdout)
if stdout or stdin:
self.use_rawinput = False
@ -74,9 +75,15 @@ class VyperDebugCmd(cmd.Cmd):
self._print_code_position()
def postloop(self):
self.stdout.write('Exiting vdb' + '\n')
if not self.step_mode:
self.stdout.write('Exiting vdb' + '\n')
super().postloop()
def do_step(self, *args):
""" Step to next instruction """
self.step_mode = True
return True
def do_state(self, *args):
""" Show current EVM state information. """
self.stdout.write('Block Number => {}'.format(self.computation.state.block_number) + '\n')
@ -208,6 +215,7 @@ class VyperDebugCmd(cmd.Cmd):
def do_continue(self, *args):
""" Exit vdb """
self.step_mode = False
return True
def do_EOF(self, line):