[pypy-svn] pypy lltrace: Write the recording logic in its own file. Add a number that identifies
arigo
commits-noreply at bitbucket.org
Tue Feb 22 14:59:51 CET 2011
Author: Armin Rigo <arigo at tunes.org>
Branch: lltrace
Changeset: r42210:7cd9093a53f9
Date: 2011-02-22 13:25 +0100
http://bitbucket.org/pypy/pypy/changeset/7cd9093a53f9/
Log: Write the recording logic in its own file. Add a number that
identifies the location of the setfield.
diff --git a/pypy/translator/c/src/debug_lltrace.h b/pypy/translator/c/src/debug_lltrace.h
new file mode 100644
--- /dev/null
+++ b/pypy/translator/c/src/debug_lltrace.h
@@ -0,0 +1,62 @@
+
+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 /******************************************************/
diff --git a/pypy/translator/c/src/g_include.h b/pypy/translator/c/src/g_include.h
--- a/pypy/translator/c/src/g_include.h
+++ b/pypy/translator/c/src/g_include.h
@@ -46,6 +46,7 @@
# 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"
diff --git a/pypy/translator/c/src/support.h b/pypy/translator/c/src/support.h
--- a/pypy/translator/c/src/support.h
+++ b/pypy/translator/c/src/support.h
@@ -103,27 +103,6 @@
# 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 */
diff --git a/pypy/translator/c/funcgen.py b/pypy/translator/c/funcgen.py
--- a/pypy/translator/c/funcgen.py
+++ b/pypy/translator/c/funcgen.py
@@ -491,8 +491,11 @@
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)
More information about the Pypy-commit
mailing list