Author: Armin Rigo <ar...@tunes.org>
Branch: reverse-debugger
Changeset: r85322:1e5b6abe3bdb
Date: 2016-06-22 12:13 +0200
http://bitbucket.org/pypy/pypy/changeset/1e5b6abe3bdb/

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
@@ -16,9 +16,12 @@
 CMD_BREAKPOINTS = 4
 CMD_MOREINFO    = 5
 CMD_ATTACHID    = 6
+CMD_WATCH       = 7
+CMD_EXPECTED    = 8
 ANSWER_TEXT     = 20
 ANSWER_MOREINFO = 21
 ANSWER_NEXTNID  = 22
+ANSWER_COMPILED = 23
 
 
 def stop_point():
@@ -33,9 +36,6 @@
 def register_debug_command(command, lambda_func):
     """Register the extra RPython-implemented debug command."""
 
-def register_allocation_command(lambda_func):
-    """Register the extra RPython-implemented callback for allocation."""
-
 def send_answer(cmd, arg1=0, arg2=0, arg3=0, extra=""):
     """For RPython debug commands: writes an answer block to stdout"""
     llop.revdb_send_answer(lltype.Void, cmd, arg1, arg2, arg3, extra)
@@ -126,55 +126,38 @@
     _about_ = register_debug_command
 
     def compute_result_annotation(self, s_command_num, s_lambda_func):
-        from rpython.annotator import model as annmodel
-        from rpython.rtyper import llannotation
-
         command_num = s_command_num.const
         lambda_func = s_lambda_func.const
-        assert isinstance(command_num, int)
+        assert isinstance(command_num, (int, str))
         t = self.bookkeeper.annotator.translator
         if t.config.translation.reverse_debugger:
             func = lambda_func()
             try:
                 cmds = t.revdb_commands
             except AttributeError:
-                cmds = t.revdb_commands = []
-            for old_num, old_func in cmds:
-                if old_num == command_num:
-                    assert old_func is func
-                    break
-            else:
-                cmds.append((command_num, func))
+                cmds = t.revdb_commands = {}
+            old_func = cmds.setdefault(command_num, func)
+            assert old_func is func
             s_func = self.bookkeeper.immutablevalue(func)
-            s_ptr1 = llannotation.SomePtr(ll_ptrtype=_CMDPTR)
-            s_str2 = annmodel.SomeString()
+            arg_getter = getattr(self, 'arguments_' + str(command_num),
+                                 self.default_arguments)
             self.bookkeeper.emulate_pbc_call(self.bookkeeper.position_key,
-                                             s_func, [s_ptr1, s_str2])
+                                             s_func, arg_getter())
+
+    def default_arguments(self):
+        from rpython.annotator import model as annmodel
+        from rpython.rtyper import llannotation
+        return [llannotation.SomePtr(ll_ptrtype=_CMDPTR),
+                annmodel.SomeString()]
+
+    def arguments_ALLOCATING(self):
+        from rpython.annotator import model as annmodel
+        from rpython.rtyper import llannotation
+        return [annmodel.SomeInteger(knowntype=r_longlong),
+                llannotation.lltype_to_annotation(llmemory.GCREF)]
+
+    def arguments_WATCHING(self):
+        return []
 
     def specialize_call(self, hop):
         hop.exception_cannot_occur()
-
-
-class RegisterAllocationCommand(ExtRegistryEntry):
-    _about_ = register_allocation_command
-
-    def compute_result_annotation(self, s_lambda_func):
-        from rpython.annotator import model as annmodel
-        from rpython.rtyper import llannotation
-
-        lambda_func = s_lambda_func.const
-        t = self.bookkeeper.annotator.translator
-        if t.config.translation.reverse_debugger:
-            func = lambda_func()
-            try:
-                assert t.revdb_allocation_cmd is func
-            except AttributeError:
-                t.revdb_allocation_cmd = func
-            s_func = self.bookkeeper.immutablevalue(func)
-            s_int1 = annmodel.SomeInteger(knowntype=r_longlong)
-            s_ref2 = llannotation.lltype_to_annotation(llmemory.GCREF)
-            self.bookkeeper.emulate_pbc_call(self.bookkeeper.position_key,
-                                             s_func, [s_int1, s_ref2])
-
-    def specialize_call(self, hop):
-        hop.exception_cannot_occur()
diff --git a/rpython/translator/revdb/gencsupp.py 
b/rpython/translator/revdb/gencsupp.py
--- a/rpython/translator/revdb/gencsupp.py
+++ b/rpython/translator/revdb/gencsupp.py
@@ -27,27 +27,35 @@
                                          lltype.Void))
     ALLOCFUNCPTR = lltype.Ptr(lltype.FuncType([rffi.LONGLONG, llmemory.GCREF],
                                               lltype.Void))
+    WATCHFUNCPTR = lltype.Ptr(lltype.FuncType([], lltype.Signed))
 
     bk = db.translator.annotator.bookkeeper
-    cmds = getattr(db.translator, 'revdb_commands', [])
+    cmds = getattr(db.translator, 'revdb_commands', {})
+    numcmds = [(num, func) for (num, func) in cmds.items()
+                           if isinstance(num, int)]
 
     S = lltype.Struct('RPY_REVDB_COMMANDS',
-                      ('names', lltype.FixedSizeArray(rffi.INT, len(cmds) + 
1)),
-                      ('funcs', lltype.FixedSizeArray(FUNCPTR, len(cmds))),
-                      ('alloc', ALLOCFUNCPTR))
+                  ('names', lltype.FixedSizeArray(rffi.INT, len(numcmds) + 1)),
+                  ('funcs', lltype.FixedSizeArray(FUNCPTR, len(numcmds))),
+                  ('alloc', ALLOCFUNCPTR),
+                  ('watch', WATCHFUNCPTR))
     s = lltype.malloc(S, flavor='raw', immortal=True, zero=True)
 
-    for i, (name, func) in enumerate(cmds):
+    i = 0
+    for name, func in cmds.items():
         fnptr = lltype.getfunctionptr(bk.getdesc(func).getuniquegraph())
-        assert lltype.typeOf(fnptr) == FUNCPTR
-        assert isinstance(name, int) and name != 0
-        s.names[i] = rffi.cast(rffi.INT, name)
-        s.funcs[i] = fnptr
-
-    allocation_cmd = getattr(db.translator, 'revdb_allocation_cmd', None)
-    if allocation_cmd is not None:
-        s.alloc = lltype.getfunctionptr(
-            bk.getdesc(allocation_cmd).getuniquegraph())
+        if isinstance(name, int):
+            assert name != 0
+            s.names[i] = rffi.cast(rffi.INT, name)
+            s.funcs[i] = fnptr
+            i += 1
+        elif name == "ALLOCATING":
+            s.alloc = fnptr
+        elif name == "WATCHING":
+            s.watch = fnptr
+        else:
+            raise AssertionError("bad tag in register_debug_command(): %r"
+                                 % (name,))
 
     exports.EXPORTS_obj2name[s._as_obj()] = 'rpy_revdb_commands'
     db.get(s)
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
@@ -109,6 +109,15 @@
         lst = [str(n) for n in sorted(self.pgroup.paused)]
         print ', '.join(lst)
 
+    def cmd_info_breakpoints(self):
+        """List current breakpoints"""
+        lst = self.pgroup.all_breakpoints.num2name.items()
+        if lst:
+            for num, name in sorted(lst):
+                print '%8d: %s' % (num, name)
+        else:
+            print 'no breakpoints.'
+
     def move_forward(self, steps):
         self.remove_tainting()
         try:
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to