Author: Armin Rigo <[email protected]>
Branch: reverse-debugger
Changeset: r86010:88575763814a
Date: 2016-08-03 23:25 +0200
http://bitbucket.org/pypy/pypy/changeset/88575763814a/

Log:    Add __pypy__.revdb_stop(), which makes an explicit breakpoint in
        revdb. Use it in app_main to stop just after running the program
        (including if there was an exception).

diff --git a/pypy/interpreter/app_main.py b/pypy/interpreter/app_main.py
--- a/pypy/interpreter/app_main.py
+++ b/pypy/interpreter/app_main.py
@@ -79,10 +79,16 @@
     sys.stdout if needed, etc.
     """
     try:
+        from __pypy__ import revdb_stop
+    except ImportError:
+        revdb_stop = None
+    try:
         # run it
         try:
             f(*fargs, **fkwds)
         finally:
+            if revdb_stop:
+                revdb_stop()
             sys.settrace(None)
             sys.setprofile(None)
 
diff --git a/pypy/interpreter/executioncontext.py 
b/pypy/interpreter/executioncontext.py
--- a/pypy/interpreter/executioncontext.py
+++ b/pypy/interpreter/executioncontext.py
@@ -89,7 +89,7 @@
             jit.virtual_ref_finish(frame_vref, frame)
             if self.space.config.translation.reverse_debugger:
                 from pypy.interpreter.reverse_debugging import leave_call
-                leave_call(self.topframeref(), frame)
+                leave_call(self.topframeref(), got_exception)
 
     # ________________________________________________________________
 
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
@@ -74,12 +74,16 @@
     if code.co_revdb_linestarts is None:
         build_co_revdb_linestarts(code)
 
-def leave_call(caller_frame, callee_frame):
+def leave_call(caller_frame, got_exception):
     if dbstate.breakpoint_stack_id != 0 and caller_frame is not None:
         if dbstate.breakpoint_stack_id == revdb.get_unique_id(caller_frame):
             revdb.breakpoint(-2)
     if we_are_translated():
-        stop_point_activate(-2)
+        stop_point_activate(-2 + got_exception)
+
+def stop_point():
+    if we_are_translated():
+        revdb.breakpoint(-3)
 
 
 def jump_backward(frame, jumpto):
@@ -418,10 +422,12 @@
     if cmd.c_arg1 == 0:
         revdb.send_output("%s:\n" % (
             file_and_lineno(frame, frame.get_last_lineno()),))
-        if revdb.current_place() == -2:
-            prompt = "<<"
+        if revdb.current_place() == -2:   # <= this is the arg to stop_point()
+            prompt = "<<"     # return
+        elif revdb.current_place() == -1:
+            prompt = "!!"     # exceptional return
         else:
-            prompt = "> "
+            prompt = "> "     # plain line
         display_function_part(frame, max_lines_before=8, max_lines_after=5,
                               prompt=prompt)
     elif cmd.c_arg1 == 2:
diff --git a/pypy/module/__pypy__/__init__.py b/pypy/module/__pypy__/__init__.py
--- a/pypy/module/__pypy__/__init__.py
+++ b/pypy/module/__pypy__/__init__.py
@@ -129,3 +129,6 @@
             features = detect_cpu.getcpufeatures(model)
             self.extra_interpdef('jit_backend_features',
                                     'space.wrap(%r)' % features)
+        if self.space.config.translation.reverse_debugger:
+            self.extra_interpdef('revdb_stop',
+                                 'interp_magic.revdb_stop')
diff --git a/pypy/module/__pypy__/interp_magic.py 
b/pypy/module/__pypy__/interp_magic.py
--- a/pypy/module/__pypy__/interp_magic.py
+++ b/pypy/module/__pypy__/interp_magic.py
@@ -204,3 +204,7 @@
     after changing the Python code.
     """
     return space.wrap(space._side_effects_ok())
+
+def revdb_stop(space):
+    from pypy.interpreter.reverse_debugging import stop_point
+    stop_point()
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
@@ -134,6 +134,9 @@
         elif break_at[0] == 'W':
             kind = 'watchpoint'
             name = self.pgroup.all_breakpoints.sources.get(num, '??')
+        elif num == -3:
+            kind = 'stoppoint'
+            name = 'explicit stop'
         else:
             kind = '?????point'
             name = repr(break_at)
@@ -191,9 +194,11 @@
         printing = []
         for num in b.regular_breakpoint_nums():
             kind, name = self._bp_kind(num)
-            printing.append('%s %s %d: %s' % (
+            printing.append('%s %s%s: %s' % (
                 'Reverse-hit' if backward else 'Hit',
-                kind, num, name))
+                kind,
+                '' if kind == 'stoppoint' else ' %d' % (num,),
+                name))
         self.print_extra_pending_info = '\n'.join(printing)
         if self.pgroup.get_current_time() != b.time:
             target_time = b.time
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to