[pypy-commit] pypy reverse-debugger: Fix interact.py
arigo
pypy.commits at gmail.com
Mon Jun 20 05:21:39 EDT 2016
Author: Armin Rigo <arigo at tunes.org>
Branch: reverse-debugger
Changeset: r85235:d761ca2cb60e
Date: 2016-06-20 11:22 +0200
http://bitbucket.org/pypy/pypy/changeset/d761ca2cb60e/
Log: Fix interact.py
diff --git a/rpython/translator/revdb/interact.py b/rpython/translator/revdb/interact.py
--- a/rpython/translator/revdb/interact.py
+++ b/rpython/translator/revdb/interact.py
@@ -1,7 +1,7 @@
import sys, re
import subprocess, socket
import traceback
-from rpython.translator.revdb.message import *
+from rpython.translator.revdb.process import ReplayProcessGroup, maxint64
r_cmdline = re.compile(r"(\S+)\s*(.*)")
@@ -17,38 +17,17 @@
revdb_log_filename,))
if executable is None:
executable = fields[1]
- #
- s1, s2 = socket.socketpair()
- subproc = subprocess.Popen(
- [executable, '--revdb-replay', revdb_log_filename,
- str(s2.fileno())])
- s2.close()
- self.subproc = subproc
- child = ReplayProcess(subproc.pid, s1)
- msg = child.expect(ANSWER_INIT, INIT_VERSION_NUMBER, Ellipsis)
- self.total_stop_points = msg.arg2
- msg = child.expect(ANSWER_STD, 1, Ellipsis)
- child.update_times(msg)
- self.active_child = child
- self.paused_children = []
- #
- # fixed time division for now
- if self.total_stop_points < 1:
- raise ValueError("no stop points recorded in %r" % (
- revdb_log_filename,))
- self.fork_points = {1: child.clone()}
- p = 1
- while p < self.total_stop_points and len(self.fork_points) < 30:
- p += int((self.total_stop_points - p) * 0.25) + 1
- self.fork_points[p] = None
+ self.pgroup = ReplayProcessGroup(executable, revdb_log_filename)
def interact(self):
last_command = ''
while True:
- last_time = self.active_child.current_time
+ last_time = self.pgroup.get_current_time()
prompt = '(%d)$ ' % last_time
+ sys.stdout.write(prompt)
+ sys.stdout.flush()
try:
- cmdline = raw_input(prompt).strip()
+ cmdline = raw_input().strip()
except EOFError:
print
cmdline = 'quit'
@@ -57,6 +36,7 @@
match = r_cmdline.match(cmdline)
if not match:
continue
+ last_command = cmdline
command, argument = match.groups()
try:
runner = getattr(self, 'command_' + command)
@@ -67,7 +47,6 @@
runner(argument)
except Exception as e:
traceback.print_exc()
- last_command = cmdline
def command_help(self, argument):
"""Display commands summary"""
@@ -76,29 +55,42 @@
if name.startswith('command_'):
command = name[len('command_'):]
docstring = getattr(self, name).__doc__ or 'undocumented'
- print '\t%s\t%s' % (command, docstring)
+ print '\t%-12s %s' % (command, docstring)
def command_quit(self, argument):
"""Exit the debugger"""
+ self.pgroup.close()
sys.exit(0)
- def change_child(self, target_time):
- """If 'target_time' is not soon after 'self.active_child',
- close it and fork another child."""
- assert 1 <= target_time <= self.total_stop_points
- best = max([key for key in self.fork_points if key <= target_time])
- if best < self.active_child.current_time <= target_time:
- pass # keep 'active_child'
- else:
- self.active_child.close()
- self.active_child = self.fork_points[best].clone()
+ def command_go(self, argument):
+ """Jump to time ARG"""
+ self.pgroup.jump_in_time(int(argument))
- def command_go(self, argument):
- """Go to time ARG"""
- target_time = int(argument)
- if target_time < 1:
- target_time = 1
- if target_time > self.total_stop_points:
- target_time = self.total_stop_points
- self.change_child(target_time)
- self.active_child.forward(target_time - self.active_child.current_time)
+ def command_info(self, argument):
+ """Display various info ('info help' for more)"""
+ display = getattr(self, 'cmd_info_' + argument, self.cmd_info_help)
+ return display()
+
+ def cmd_info_help(self):
+ """Display info topics summary"""
+ print 'Available info topics:'
+ for name in dir(self):
+ if name.startswith('cmd_info_'):
+ command = name[len('cmd_info_'):]
+ docstring = getattr(self, name).__doc__ or 'undocumented'
+ print '\tinfo %-12s %s' % (command, docstring)
+
+ def cmd_info_paused(self):
+ """List current paused subprocesses"""
+ lst = [str(n) for n in sorted(self.pgroup.paused)]
+ print ', '.join(lst)
+
+ def command_step(self, argument):
+ """Run forward ARG steps (default 1)"""
+ self.pgroup.go_forward(int(argument or '1'))
+ command_s = command_step
+
+ def command_continue(self, argument):
+ """Run forward"""
+ self.pgroup.go_forward(maxint64)
+ command_c = command_continue
diff --git a/rpython/translator/revdb/process.py b/rpython/translator/revdb/process.py
--- a/rpython/translator/revdb/process.py
+++ b/rpython/translator/revdb/process.py
@@ -3,6 +3,9 @@
from rpython.translator.revdb.message import *
+maxint64 = int(2**63 - 1)
+
+
class Breakpoint(Exception):
def __init__(self, num):
self.num = num
@@ -183,3 +186,9 @@
# else, start from a fork
self._resume(max(time for time in self.paused if time <= target_time))
self.go_forward(target_time - self.get_current_time())
+
+ def close(self):
+ """Close all subprocesses.
+ """
+ for subp in [self.active] + self.paused.values():
+ subp.close()
diff --git a/rpython/translator/revdb/test/test_basic.py b/rpython/translator/revdb/test/test_basic.py
--- a/rpython/translator/revdb/test/test_basic.py
+++ b/rpython/translator/revdb/test/test_basic.py
@@ -256,7 +256,7 @@
def test_fork(self):
child = self.replay()
- child2 = child.fork()
+ child2 = child.clone()
child.send(Message(CMD_FORWARD, 2))
child.expect(ANSWER_STD, 3, Ellipsis)
child2.send(Message(CMD_FORWARD, 1))
@@ -389,116 +389,3 @@
child.expect(120, 3)
child.send(Message(CMD_FORWARD, 0))
child.expect(ANSWER_STD, 3, Ellipsis)
-
- def test_get_unique_id_and_track_object(self):
- child = self.replay()
- child.expectx('(3)$ ')
- child.sendline('r print-id')
- child.expect(re.escape('<<<print-id>>>\r\n')
- + r'obj.x=1002 (\d+) (\d+)'
- + re.escape('\r\n'
- 'blipped\r\n'
- '(3)$ '))
- object_id_3rd = int(child.match.group(1))
- created_objects_3rd = int(child.match.group(2))
- assert 0 < object_id_3rd < created_objects_3rd
- #
- child.sendline('__go 1')
- child.expectx('(1)$ ')
- child.sendline('r print-id')
- child.expect(re.escape('<<<print-id>>>\r\n')
- + r'obj.x=1000 (\d+) (\d+)'
- + re.escape('\r\n'
- 'blipped\r\n'
- '(1)$ '))
- object_id_1st = int(child.match.group(1))
- created_objects_1st = int(child.match.group(2))
- assert 0 < object_id_1st < created_objects_1st
- assert created_objects_1st <= object_id_3rd # only created afterwards
- #
- child.sendline('r track-object %d' % object_id_3rd)
- child.expectx('<<<track-object %d>>>\r\n' % object_id_3rd +
- 'blipped\r\n'
- '(1)$ ')
- for i in [1, 2]:
- child.sendline('r get-tracked-object')
- child.expectx('<<<get-tracked-object>>>\r\n'
- 'none\r\n'
- 'blipped\r\n'
- '(%d)$ ' % i)
- child.sendline('__forward 1')
- child.expectx('(%d)$ ' % (i + 1))
- child.sendline('r get-tracked-object')
- child.expectx('<<<get-tracked-object>>>\r\n'
- 'got obj.x=1002\r\n'
- 'blipped\r\n'
- '(3)$ ')
- child.sendline('__go 3')
- child.expectx('(3)$ ')
- child.sendline('r get-tracked-object')
- child.expectx('<<<get-tracked-object>>>\r\n'
- 'none\r\n'
- 'blipped\r\n'
- '(3)$ ')
- #
- child.sendline('__go 2')
- child.expectx('(2)$ ')
- child.sendline('r print-id')
- child.expect(re.escape('<<<print-id>>>\r\n')
- + r'obj.x=1001 (\d+) (\d+)'
- + re.escape('\r\n'
- 'blipped\r\n'
- '(2)$ '))
- object_id_2nd = int(child.match.group(1))
- created_objects_2nd = int(child.match.group(2))
- #
- child.sendline('r track-object %d' % object_id_2nd)
- child.expectx('<<<track-object %d>>>\r\n' % object_id_2nd +
- 'cannot track the creation of an object already created\r\n'
- 'blipped\r\n'
- '(2)$ ')
- child.sendline('r track-object 0')
- child.expectx('<<<track-object 0>>>\r\n'
- 'cannot track a prebuilt or debugger-created object\r\n'
- 'blipped\r\n'
- '(2)$ ')
- child.sendline('__go 1')
- child.expectx('(1)$ ')
- child.sendline('r track-object %d' % object_id_2nd)
- child.expectx('<<<track-object %d>>>\r\n' % object_id_2nd +
- 'blipped\r\n'
- '(1)$ ')
- child.sendline('__forward 2')
- child.expectx('(3)$ ')
- child.sendline('r get-tracked-object')
- child.expectx('<<<get-tracked-object>>>\r\n'
- 'got obj.x=1001\r\n'
- 'blipped\r\n'
- '(3)$ ')
- child.sendline('__forward 1')
- child.expectx('At end.\r\n'
- '(3)$ ')
- child.sendline('r get-tracked-object')
- child.expectx('<<<get-tracked-object>>>\r\n'
- 'none\r\n'
- 'blipped\r\n'
- '(3)$ ')
-
- def test_first_created_uid(self):
- child = self.replay()
- child.expectx('(3)$ ')
- child.sendline('r first-created-uid')
- child.expectx('<<<first-created-uid>>>\r\n')
- child.expect('first-created-uid=(\d+)\r\n')
- first_created_id = int(child.match.group(1))
- child.expectx('blipped\r\n'
- '(3)$ ')
- child.sendline('__go 1')
- child.expectx('(1)$ ')
- child.sendline('r print-id')
- child.expect(re.escape('<<<print-id>>>\r\n')
- + r'obj.x=1000 (\d+) (\d+)'
- + re.escape('\r\n'
- 'blipped\r\n'
- '(1)$ '))
- assert int(child.match.group(2)) == first_created_id
More information about the pypy-commit
mailing list