Armin Rigo avatar Armin Rigo committed 7cd9093

Write the recording logic in its own file. Add a number that identifies
the location of the setfield.

Comments (0)

Files changed (4)

pypy/translator/c/funcgen.py

         if T is Void:
             result = '/* %s */' % result
         elif gckind == 'gc':
-            result = '%s RPyTraceSet(%s);' % (result, targetexpr)
+            mark = FunctionCodeGenerator._TRACE_MARK + 1
+            FunctionCodeGenerator._TRACE_MARK = mark
+            result = '%s RPyTraceSet(%s, %d);' % (result, targetexpr, mark)
         return result
+    _TRACE_MARK = 0
 
     def OP_GETFIELD(self, op, ampersand=''):
         assert isinstance(op.args[1], Constant)

pypy/translator/c/src/debug_lltrace.h

+
+void _RPyTraceSet(void *addr, long newvalue, int mark);
+
+
+#ifndef RPY_LL_TRACE /****************************************/
+
+#  define RPyTraceSet(ptr, mark)   /* nothing */
+#  ifndef PYPY_NOT_MAIN_FILE
+void _RPyTraceSet(void *addr, long newvalue, int mark) { }
+#  endif
+
+
+#else /*******************************************************/
+
+
+#  define RPyTraceSet(ptr, mark)   _RPyTraceSet(&(ptr), (long)(ptr), mark)
+
+#  ifndef PYPY_NOT_MAIN_FILE
+
+struct _RPyTrace_s {
+  long mark;
+  void *addr;
+  long newvalue;
+};
+
+static struct _RPyTrace_s *_RPyTrace_start   = NULL;
+static struct _RPyTrace_s *_RPyTrace_stop    = NULL;
+static struct _RPyTrace_s *_RPyTrace_current = NULL;
+static int _RPyTrace_default_size = 134217728;
+
+void _RPyTrace_WrapAround(void)
+{
+  if (_RPyTrace_start == NULL)
+    {
+      char *csize = getenv("PYPYTRACE");
+      int size = csize ? atoi(csize) : 0;
+      if (size <= 0)
+        size = _RPyTrace_default_size;
+      _RPyTrace_start = malloc(size * sizeof(struct _RPyTrace_s));
+      RPyAssert(_RPyTrace_start, "not enough memory to allocate the trace");
+      _RPyTrace_stop = _RPyTrace_start + size;
+    }
+  _RPyTrace_current = _RPyTrace_start;
+  fprintf(stderr, "lltrace: buffer from %p to %p, size %ld entries\n",
+          _RPyTrace_start, _RPyTrace_stop,
+          (long)(_RPyTrace_stop - _RPyTrace_start));
+}
+
+void _RPyTraceSet(void *addr, long newvalue, int mark)
+{
+  if (_RPyTrace_current == _RPyTrace_stop)
+    _RPyTrace_WrapAround();
+  _RPyTrace_current->mark = mark;
+  _RPyTrace_current->addr = addr;
+  _RPyTrace_current->newvalue = newvalue;
+  ++_RPyTrace_current;
+}
+
+#  endif
+
+
+#endif /******************************************************/

pypy/translator/c/src/g_include.h

 #  include "src/debug_print.h"
 #  include "src/debug_traceback.h"
 #  include "src/debug_alloc.h"
+#  include "src/debug_lltrace.h"
 #ifndef AVR
 #  include "src/ll_os.h"
 #  include "src/ll_strtod.h"

pypy/translator/c/src/support.h

 #  define RPyBareItem(array, index)          ((array)[index])
 #endif
 
-
-#ifdef RPY_LL_TRACE
-#  define RPyTraceSet(ptr)   _RPyTraceSet(&(ptr), (long)(ptr))
-#else
-#  define RPyTraceSet(ptr)   /* nothing */
-#endif
-void _RPyTraceSet(void *addr, long newvalue);
-#ifndef PYPY_NOT_MAIN_FILE
-static void *_RPyTrace_start;
-static void *_RPyTrace_stop;
-static void *_RPyTrace_current = NULL;
-void _RPyTraceCreateBuffer(void)
-{
-}
-void _RPyTraceSet(void *addr, long newvalue)
-{
-  fprintf(stderr, "set 0x%x into %p\n", newvalue, addr);
-}
-#endif
-
-
 #ifndef PYPY_STANDALONE
 
 /* prototypes */
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.