[pypy-commit] pypy reverse-debugger: in-progress
arigo
pypy.commits at gmail.com
Mon Jun 20 05:50:32 EDT 2016
Author: Armin Rigo <arigo at tunes.org>
Branch: reverse-debugger
Changeset: r85236:e59f9c4f668a
Date: 2016-06-20 11:51 +0200
http://bitbucket.org/pypy/pypy/changeset/e59f9c4f668a/
Log: in-progress
diff --git a/rpython/rlib/revdb.py b/rpython/rlib/revdb.py
--- a/rpython/rlib/revdb.py
+++ b/rpython/rlib/revdb.py
@@ -10,6 +10,11 @@
from rpython.rtyper.lltypesystem import rffi
+CMD_PRINT = 1
+CMD_BACKTRACE = 2
+ANSWER_TEXT = 20
+
+
def stop_point():
"""Indicates a point in the execution of the RPython program where
the reverse-debugger can stop. When reverse-debugging, we see
@@ -26,6 +31,9 @@
"""For RPython debug commands: writes an answer block to stdout"""
llop.revdb_send_answer(lltype.Void, cmd, arg1, arg2, arg3, extra)
+def send_output(text):
+ send_answer(ANSWER_TEXT, extra=text)
+
def current_time():
"""For RPython debug commands: returns the current time."""
return llop.revdb_get_value(lltype.SignedLongLong, 'c')
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
@@ -61,6 +61,7 @@
"""Exit the debugger"""
self.pgroup.close()
sys.exit(0)
+ command_q = command_quit
def command_go(self, argument):
"""Jump to time ARG"""
@@ -87,10 +88,27 @@
def command_step(self, argument):
"""Run forward ARG steps (default 1)"""
- self.pgroup.go_forward(int(argument or '1'))
+ arg = int(argument or '1')
+ self.pgroup.go_forward(arg)
command_s = command_step
+ def command_bstep(self, argument):
+ """Run backward ARG steps (default 1)"""
+ arg = int(argument or '1')
+ self.pgroup.jump_in_time(self.pgroup.get_current_time() - arg)
+ command_bs = command_bstep
+
def command_continue(self, argument):
"""Run forward"""
self.pgroup.go_forward(maxint64)
command_c = command_continue
+
+ def command_print(self, argument):
+ """Print an expression"""
+ self.pgroup.print_cmd(argument)
+ command_p = command_print
+
+ def command_backtrace(self, argument):
+ """Show the backtrace"""
+ self.pgroup.show_backtrace()
+ command_bt = command_backtrace
diff --git a/rpython/translator/revdb/message.py b/rpython/translator/revdb/message.py
--- a/rpython/translator/revdb/message.py
+++ b/rpython/translator/revdb/message.py
@@ -4,6 +4,10 @@
CMD_FORK = -1
CMD_QUIT = -2
CMD_FORWARD = -3
+# extra commands which are not handled by revdb.c, but
+# by revdb.register_debug_command()
+CMD_PRINT = 1
+CMD_BACKTRACE = 2
ANSWER_INIT = -20
ANSWER_STD = -21
@@ -11,6 +15,8 @@
ANSWER_AT_END = -23
ANSWER_BREAKPOINT = -24
+ANSWER_TEXT = 20
+
class Message(object):
"""Represent messages sent and received to subprocesses
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
@@ -76,7 +76,10 @@
def close(self):
"""Close this subprocess."""
- self.send(Message(CMD_QUIT))
+ try:
+ self.send(Message(CMD_QUIT))
+ except socket.error:
+ pass
def forward(self, steps):
"""Move this subprocess forward in time."""
@@ -95,6 +98,17 @@
raise Breakpoint(bkpt_num)
return msg
+ def print_text_answer(self):
+ while True:
+ msg = self.recv()
+ if msg.cmd == ANSWER_TEXT:
+ print msg.extra
+ elif msg.cmd == ANSWER_STD:
+ self.update_times(msg)
+ break
+ else:
+ print >> sys.stderr, "unexpected message %d" % (msg.cmd,)
+
class ReplayProcessGroup(object):
"""Handle a family of subprocesses.
@@ -169,21 +183,12 @@
def jump_in_time(self, target_time):
"""Jump in time at the given 'target_time'.
- This function can close the active subprocess. But you should
- remove the breakpoints first, in case the same subprocess remains
- active.
+ This function always closes the active subprocess.
"""
if target_time < 1:
target_time = 1
if target_time > self.total_stop_points:
target_time = self.total_stop_points
-
- cur_time = self.get_current_time()
- if target_time >= cur_time: # can go forward
- if cur_time >= max(self.paused): # current time is past all forks
- self.go_forward(target_time - cur_time)
- return
- # 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())
@@ -192,3 +197,15 @@
"""
for subp in [self.active] + self.paused.values():
subp.close()
+
+ def print_cmd(self, expression):
+ """Print an expression.
+ """
+ self.active.send(Message(CMD_PRINT, extra=expression))
+ self.active.print_text_answer()
+
+ def show_backtrace(self):
+ """Show the backtrace.
+ """
+ self.active.send(Message(CMD_BACKTRACE))
+ self.active.print_text_answer()
diff --git a/rpython/translator/revdb/src-revdb/revdb.c b/rpython/translator/revdb/src-revdb/revdb.c
--- a/rpython/translator/revdb/src-revdb/revdb.c
+++ b/rpython/translator/revdb/src-revdb/revdb.c
@@ -551,6 +551,7 @@
s = make_rpy_string(cmd->extra_size);
memcpy(_RPyString_AsString(s), extra, cmd->extra_size);
}
+ pending_after_forward = &answer_std;
execute_rpy_function(rpy_revdb_command_funcs[i], cmd, s);
}
More information about the pypy-commit
mailing list