Merge pull request #22 from charles-cooper/step_mode
Add a 'step' command to vdb
This commit is contained in:
commit
3d124222f2
|
@ -30,6 +30,7 @@ if tb_limit:
|
||||||
aparser = argparse.ArgumentParser(description='Vyper {0} quick CLI runner'.format(vyper.__version__))
|
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('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('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')
|
aparser.add_argument('-i', help='init args, comma separated', default=None, dest='init_args')
|
||||||
|
|
||||||
args = aparser.parse_args()
|
args = aparser.parse_args()
|
||||||
|
@ -133,6 +134,8 @@ if __name__ == '__main__':
|
||||||
init_args = args.init_args.split(',') if args.init_args else []
|
init_args = args.init_args.split(',') if args.init_args else []
|
||||||
tester, w3 = get_tester(code)
|
tester, w3 = get_tester(code)
|
||||||
|
|
||||||
|
setattr(vdb.debug_computation.DebugComputation, 'trace', args.trace)
|
||||||
|
|
||||||
# Built list of calls to make.
|
# Built list of calls to make.
|
||||||
calls = []
|
calls = []
|
||||||
for signature in args.call_list.split(';'):
|
for signature in args.call_list.split(';'):
|
||||||
|
|
|
@ -27,17 +27,22 @@ class DebugComputation(ByzantiumComputation):
|
||||||
source_map = None
|
source_map = None
|
||||||
stdin = None
|
stdin = None
|
||||||
stdout = None
|
stdout = None
|
||||||
|
step_mode = False
|
||||||
|
trace = False
|
||||||
|
pc = 0
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def run_debugger(self, computation, line_no):
|
def run_debugger(self, computation, line_no):
|
||||||
VyperDebugCmd(
|
res = VyperDebugCmd(
|
||||||
computation,
|
computation,
|
||||||
line_no=line_no,
|
line_no=line_no,
|
||||||
source_code=self.source_code,
|
source_code=self.source_code,
|
||||||
source_map=self.source_map,
|
source_map=self.source_map,
|
||||||
stdin=self.stdin,
|
stdin=self.stdin,
|
||||||
stdout=self.stdout
|
stdout=self.stdout
|
||||||
).cmdloop()
|
)
|
||||||
|
res.cmdloop()
|
||||||
|
self.step_mode = res.step_mode
|
||||||
return line_no
|
return line_no
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -82,16 +87,19 @@ class DebugComputation(ByzantiumComputation):
|
||||||
opcode_fn = computation.get_opcode_fn(opcode)
|
opcode_fn = computation.get_opcode_fn(opcode)
|
||||||
|
|
||||||
pc_to_execute = max(0, computation.code.pc - 1)
|
pc_to_execute = max(0, computation.code.pc - 1)
|
||||||
computation.logger.trace(
|
if cls.trace:
|
||||||
"OPCODE: 0x%x (%s) | pc: %s",
|
print(
|
||||||
opcode,
|
"NEXT OPCODE: 0x%x (%s) | pc: %s..%s" %
|
||||||
|
(opcode,
|
||||||
opcode_fn.mnemonic,
|
opcode_fn.mnemonic,
|
||||||
pc_to_execute,
|
cls.pc,
|
||||||
|
pc_to_execute)
|
||||||
)
|
)
|
||||||
|
cls.pc = pc_to_execute
|
||||||
|
|
||||||
is_breakpoint, line_no = cls.is_breakpoint(pc_to_execute, continue_line_nos)
|
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)
|
cls.run_debugger(computation, line_no)
|
||||||
continue_line_nos.append(line_no)
|
continue_line_nos.append(line_no)
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,7 @@ class VyperDebugCmd(cmd.Cmd):
|
||||||
self.line_no = line_no
|
self.line_no = line_no
|
||||||
self.global_vars = source_map.get("globals", {})
|
self.global_vars = source_map.get("globals", {})
|
||||||
self.local_vars = source_map.get("locals", {})
|
self.local_vars = source_map.get("locals", {})
|
||||||
|
self.step_mode = False
|
||||||
super().__init__(stdin=stdin, stdout=stdout)
|
super().__init__(stdin=stdin, stdout=stdout)
|
||||||
if stdout or stdin:
|
if stdout or stdin:
|
||||||
self.use_rawinput = False
|
self.use_rawinput = False
|
||||||
|
@ -74,9 +75,15 @@ class VyperDebugCmd(cmd.Cmd):
|
||||||
self._print_code_position()
|
self._print_code_position()
|
||||||
|
|
||||||
def postloop(self):
|
def postloop(self):
|
||||||
|
if not self.step_mode:
|
||||||
self.stdout.write('Exiting vdb' + '\n')
|
self.stdout.write('Exiting vdb' + '\n')
|
||||||
super().postloop()
|
super().postloop()
|
||||||
|
|
||||||
|
def do_stepi(self, *args):
|
||||||
|
""" Step to next instruction """
|
||||||
|
self.step_mode = True
|
||||||
|
return True
|
||||||
|
|
||||||
def do_state(self, *args):
|
def do_state(self, *args):
|
||||||
""" Show current EVM state information. """
|
""" Show current EVM state information. """
|
||||||
self.stdout.write('Block Number => {}'.format(self.computation.state.block_number) + '\n')
|
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):
|
def do_continue(self, *args):
|
||||||
""" Exit vdb """
|
""" Exit vdb """
|
||||||
|
self.step_mode = False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def do_EOF(self, line):
|
def do_EOF(self, line):
|
||||||
|
|
Loading…
Reference in New Issue