Author: Armin Rigo <[email protected]>
Branch: reverse-debugger
Changeset: r85495:6d53b2a13d23
Date: 2016-07-01 18:47 +0200
http://bitbucket.org/pypy/pypy/changeset/6d53b2a13d23/
Log: Signals work with a little tweak
diff --git a/pypy/interpreter/reverse_debugging.py
b/pypy/interpreter/reverse_debugging.py
--- a/pypy/interpreter/reverse_debugging.py
+++ b/pypy/interpreter/reverse_debugging.py
@@ -7,6 +7,7 @@
from pypy.interpreter.baseobjspace import W_Root
from pypy.interpreter import gateway, typedef, pycode, pytraceback, pyframe
from pypy.module.marshal import interp_marshal
+from pypy.interpreter.executioncontext import AbstractActionFlag
class DBState:
@@ -21,6 +22,16 @@
dbstate = DBState()
+pycode.PyCode.co_revdb_linestarts = None # or a string: see below
+
+# invariant: "f_revdb_nextline_instr" is the bytecode offset of
+# the start of the line that follows "last_instr".
+pyframe.PyFrame.f_revdb_nextline_instr = 0
+
+
+# ____________________________________________________________
+
+
def setup_revdb(space):
"""Called at run-time, before the space is set up.
@@ -47,11 +58,7 @@
revdb.register_debug_command(revdb.CMD_WATCHVALUES, lambda_watchvalues)
-pycode.PyCode.co_revdb_linestarts = None # or a string: see below
-
-# invariant: "f_revdb_nextline_instr" is the bytecode offset of
-# the start of the line that follows "last_instr".
-pyframe.PyFrame.f_revdb_nextline_instr = 0
+# ____________________________________________________________
def enter_call(caller_frame, callee_frame):
@@ -221,6 +228,9 @@
dbstate.metavars[index] = w_obj
+# ____________________________________________________________
+
+
def fetch_cur_frame():
ec = dbstate.space.getexecutioncontext()
frame = ec.topframeref()
@@ -526,3 +536,46 @@
w_dict = space.builtin.w_dict
w_res = prog.exec_code(space, w_dict, w_dict)
return space.str_w(space.repr(w_res))
+
+
+# ____________________________________________________________
+
+
+class RDBSignalActionFlag(AbstractActionFlag):
+ # Used instead of pypy.module.signal.interp_signal.SignalActionFlag
+ # when we have reverse-debugging. That other class would work too,
+ # but inefficiently: it would generate two words of data per bytecode.
+ # This class is tweaked to generate one byte per _SIG_TICKER_COUNT
+ # bytecodes, at the expense of not reacting to signals instantly.
+
+ _SIG_TICKER_COUNT = 100
+ _ticker_cache = 0
+ _ticker_count = _SIG_TICKER_COUNT * 10
+
+ def get_ticker(self):
+ return self._ticker_cache
+
+ def reset_ticker(self, value):
+ self._ticker_cache = value
+
+ def rearm_ticker(self):
+ self._ticker_cache = -1
+
+ def decrement_ticker(self, by):
+ if we_are_translated():
+ c = self._ticker_count - 1
+ if c < 0:
+ c = self._update_ticker_from_signals()
+ self._ticker_count = c
+ if self.has_bytecode_counter: # this 'if' is constant-folded
+ print ("RDBSignalActionFlag: has_bytecode_counter: "
+ "not supported for now")
+ raise NotImplementedError
+ return self._ticker_cache
+
+ def _update_ticker_from_signals(self):
+ from rpython.rlib import rsignal
+ if rsignal.pypysig_check_and_reset():
+ self.rearm_ticker()
+ return self._SIG_TICKER_COUNT
+ _update_ticker_from_signals._dont_inline_ = True
diff --git a/pypy/module/signal/__init__.py b/pypy/module/signal/__init__.py
--- a/pypy/module/signal/__init__.py
+++ b/pypy/module/signal/__init__.py
@@ -46,7 +46,11 @@
space.check_signal_action = interp_signal.CheckSignalAction(space)
space.actionflag.register_periodic_action(space.check_signal_action,
use_bytecode_counter=False)
- space.actionflag.__class__ = interp_signal.SignalActionFlag
+ if space.config.translation.reverse_debugger:
+ from pypy.interpreter.reverse_debugging import RDBSignalActionFlag
+ space.actionflag.__class__ = RDBSignalActionFlag
+ else:
+ space.actionflag.__class__ = interp_signal.SignalActionFlag
# xxx yes I know the previous line is a hack
def startup(self, space):
diff --git a/rpython/rlib/rsignal.py b/rpython/rlib/rsignal.py
--- a/rpython/rlib/rsignal.py
+++ b/rpython/rlib/rsignal.py
@@ -87,6 +87,8 @@
pypysig_getaddr_occurred = external('pypysig_getaddr_occurred', [],
lltype.Ptr(LONG_STRUCT), _nowrapper=True,
elidable_function=True)
+pypysig_check_and_reset = external('pypysig_check_and_reset', [],
+ lltype.Bool, _nowrapper=True)
c_alarm = external('alarm', [rffi.INT], rffi.INT)
c_pause = external('pause', [], rffi.INT, releasegil=True)
c_siginterrupt = external('siginterrupt', [rffi.INT, rffi.INT], rffi.INT,
diff --git a/rpython/translator/c/src/signals.h
b/rpython/translator/c/src/signals.h
--- a/rpython/translator/c/src/signals.h
+++ b/rpython/translator/c/src/signals.h
@@ -37,4 +37,11 @@
void *pypysig_getaddr_occurred(void);
#define pypysig_getaddr_occurred() ((void *)(&pypysig_counter))
+inline static char pypysig_check_and_reset(void) {
+ /* used by reverse_debugging */
+ char result = pypysig_counter.value < 0;
+ pypysig_counter.value = 0;
+ return result;
+}
+
#endif
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit