Author: Armin Rigo <[email protected]>
Branch: reverse-debugger
Changeset: r84938:9b3d9afb873c
Date: 2016-06-05 17:15 +0200
http://bitbucket.org/pypy/pypy/changeset/9b3d9afb873c/
Log: Start to write the logic to emit a log file
diff --git a/rpython/translator/c/database.py b/rpython/translator/c/database.py
--- a/rpython/translator/c/database.py
+++ b/rpython/translator/c/database.py
@@ -32,11 +32,13 @@
exctransformer=None,
thread_enabled=False,
sandbox=False,
- split_gc_address_space=False):
+ split_gc_address_space=False,
+ reversedb=False):
self.translator = translator
self.standalone = standalone
self.sandbox = sandbox
self.split_gc_address_space = split_gc_address_space
+ self.reversedb = reversedb
if gcpolicyclass is None:
gcpolicyclass = gc.RefcountingGcPolicy
self.gcpolicy = gcpolicyclass(self, thread_enabled)
diff --git a/rpython/translator/c/funcgen.py b/rpython/translator/c/funcgen.py
--- a/rpython/translator/c/funcgen.py
+++ b/rpython/translator/c/funcgen.py
@@ -2,6 +2,7 @@
from rpython.translator.c.support import cdecl
from rpython.translator.c.support import llvalue_from_constant, gen_assignments
from rpython.translator.c.support import c_string_constant, barebonearray
+from rpython.translator.c.primitive import PRIMITIVE_FLOATS
from rpython.flowspace.model import Variable, Constant
from rpython.rtyper.lltypesystem.lltype import (Ptr, Void, Bool, Signed,
Unsigned,
SignedLongLong, Float, UnsignedLongLong, Char, UniChar, ContainerType,
@@ -424,6 +425,14 @@
def OP_JIT_CONDITIONAL_CALL(self, op):
return 'abort(); /* jit_conditional_call */'
+ def _reverse_db_emit(self, T, value):
+ if T is Void:
+ return '/* rpy_reverse_db_emit_void(%s); */' % (value,)
+ elif T in PRIMITIVE_FLOATS:
+ return 'rpy_reverse_db_emit_float(%s);' % (value,)
+ else:
+ return 'rpy_reverse_db_emit((Signed)%s);' % (value,)
+
# low-level operations
def generic_get(self, op, sourceexpr):
T = self.lltypemap(op.result)
@@ -431,6 +440,9 @@
result = '%s = %s;' % (newvalue, sourceexpr)
if T is Void:
result = '/* %s */' % result
+ if self.db.reversedb:
+ if self.lltypemap(op.args[0]).TO._gckind != 'gc':
+ result += '\t' + self._reverse_db_emit(T, newvalue)
return result
def generic_set(self, op, targetexpr):
diff --git a/rpython/translator/c/genc.py b/rpython/translator/c/genc.py
--- a/rpython/translator/c/genc.py
+++ b/rpython/translator/c/genc.py
@@ -115,6 +115,8 @@
def get_eci(self):
pypy_include_dir = py.path.local(__file__).join('..')
include_dirs = [pypy_include_dir]
+ if self.config.translation.reversedb:
+ include_dirs.append(pypy_include_dir.join('..', 'reversedb'))
return ExternalCompilationInfo(include_dirs=include_dirs)
def build_database(self):
@@ -133,7 +135,8 @@
thread_enabled=self.config.translation.thread,
sandbox=self.config.translation.sandbox,
split_gc_address_space=
-
self.config.translation.split_gc_address_space)
+
self.config.translation.split_gc_address_space,
+ reversedb=self.config.translation.reversedb)
self.db = db
# give the gc a chance to register interest in the start-up functions
it
@@ -215,6 +218,8 @@
defines['COUNT_OP_MALLOCS'] = 1
if self.config.translation.sandbox:
defines['RPY_SANDBOXED'] = 1
+ if self.config.translation.reversedb:
+ defines['RPY_REVERSE_DB'] = 1
if CBuilder.have___thread is None:
CBuilder.have___thread = self.translator.platform.check___thread()
if not self.standalone:
@@ -822,7 +827,7 @@
defines['PYPY_LONG_BIT'] = LONG_BIT
defines['PYPY_LONGLONG_BIT'] = LONGLONG_BIT
-def add_extra_files(eci):
+def add_extra_files(database, eci):
srcdir = py.path.local(__file__).join('..', 'src')
files = [
srcdir / 'entrypoint.c', # ifdef PYPY_STANDALONE
@@ -841,6 +846,9 @@
]
if _CYGWIN:
files.append(srcdir / 'cygwin_wait.c')
+ if database.reversedb:
+ from rpython.translator.reversedb import rdb_genc
+ files += rdb_genc.extra_files()
return eci.merge(ExternalCompilationInfo(separate_module_files=files))
@@ -889,6 +897,6 @@
print >>fi, "#define PYPY_INSTRUMENT_NCOUNTER %d" % n
fi.close()
- eci = add_extra_files(eci)
+ eci = add_extra_files(database, eci)
eci = eci.convert_sources_to_files()
return eci, filename, sg.getextrafiles(), headers_to_precompile
diff --git a/rpython/translator/c/primitive.py
b/rpython/translator/c/primitive.py
--- a/rpython/translator/c/primitive.py
+++ b/rpython/translator/c/primitive.py
@@ -223,6 +223,7 @@
Address: name_address,
GCREF: name_gcref,
}
+PRIMITIVE_FLOATS = set([Float, SingleFloat, LongFloat])
PrimitiveType = {
SignedLongLong: 'long long @',
diff --git a/rpython/translator/c/src/entrypoint.c
b/rpython/translator/c/src/entrypoint.c
--- a/rpython/translator/c/src/entrypoint.c
+++ b/rpython/translator/c/src/entrypoint.c
@@ -82,6 +82,10 @@
pypy_asm_stack_bottom();
instrument_setup();
+#ifdef RPY_REVERSE_DB
+ rpy_reverse_db_setup(argc, argv);
+#endif
+
#ifndef MS_WINDOWS
/* this message does no longer apply to win64 :-) */
if (sizeof(void*) != SIZEOF_LONG) {
diff --git a/rpython/translator/c/src/g_include.h
b/rpython/translator/c/src/g_include.h
--- a/rpython/translator/c/src/g_include.h
+++ b/rpython/translator/c/src/g_include.h
@@ -50,3 +50,7 @@
#ifdef __CYGWIN__
#include "src/cygwin_wait.h"
#endif
+
+#ifdef RPY_REVERSE_DB
+#include "rdb-src/rdb_include.h"
+#endif
diff --git a/rpython/translator/reversedb/rdb-src/rdb.c
b/rpython/translator/reversedb/rdb-src/rdb.c
new file mode 100644
--- /dev/null
+++ b/rpython/translator/reversedb/rdb-src/rdb.c
@@ -0,0 +1,60 @@
+#include "common_header.h"
+#include <stdlib.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include "rdb-src/rdb_include.h"
+
+#define RDB_SIGNATURE 0x0A424452 /* "RDB\n" */
+#define RDB_VERSION 0x00FF0001
+
+
+Signed *rpy_rev_buf_p, *rpy_rev_buf_end;
+static Signed rpy_rev_buffer[2048];
+static int rpy_rev_fileno = -1;
+
+
+RPY_EXTERN
+void rpy_reverse_db_setup(int argc, char *argv[])
+{
+ /* init-time setup */
+
+ char *filename = getenv("PYPYRDB");
+ if (filename && *filename)
+ putenv("PYPYRDB=");
+ else
+ filename = "/dev/null";
+
+ rpy_rev_fileno = open(filename, O_WRONLY | O_CLOEXEC |
+ O_CREAT | O_NOCTTY | O_TRUNC, 0600);
+ if (rpy_rev_fileno < 0) {
+ fprintf(stderr, "Fatal error: can't create PYPYRDB file '%s'\n",
+ filename);
+ abort();
+ }
+
+ rpy_rev_buf_p = rpy_rev_buffer;
+ rpy_rev_buf_end = rpy_rev_buffer +
+ sizeof(rpy_rev_buffer) / sizeof(rpy_rev_buffer[0]);
+ atexit(rpy_reverse_db_flush);
+
+ rpy_reverse_db_emit(RDB_SIGNATURE);
+ rpy_reverse_db_emit(RDB_VERSION);
+ rpy_reverse_db_emit(0);
+ rpy_reverse_db_emit(0);
+ rpy_reverse_db_emit(argc);
+}
+
+RPY_EXTERN
+void rpy_reverse_db_flush(void)
+{
+ /* write the current buffer content to the OS */
+
+ ssize_t size = (rpy_rev_buf_p - rpy_rev_buffer) *
sizeof(rpy_rev_buffer[0]);
+ rpy_rev_buf_p = rpy_rev_buffer;
+ if (size > 0 && write(rpy_rev_fileno, rpy_rev_buffer, size) != size) {
+ fprintf(stderr, "Fatal error: writing to PYPYRDB file: %m\n");
+ abort();
+ }
+}
diff --git a/rpython/translator/reversedb/rdb-src/rdb_include.h
b/rpython/translator/reversedb/rdb-src/rdb_include.h
new file mode 100644
--- /dev/null
+++ b/rpython/translator/reversedb/rdb-src/rdb_include.h
@@ -0,0 +1,23 @@
+
+
+RPY_EXTERN void rpy_reverse_db_setup(int argc, char *argv[]);
+RPY_EXTERN void rpy_reverse_db_flush(void);
+
+
+RPY_EXTERN Signed *rpy_rev_buf_p, *rpy_rev_buf_end;
+
+
+static inline void rpy_reverse_db_emit(Signed value) {
+ *(rpy_rev_buf_p++) = value;
+ if (rpy_rev_buf_p == rpy_rev_buf_end)
+ rpy_reverse_db_flush();
+}
+static inline void rpy_reverse_db_emit_float(double value) {
+ /* xxx for 'long double' this can loose some precision */
+ Signed sval[8 / SIZEOF_LONG];
+ assert(sizeof(double) == 8);
+ memcpy(sval, &value, sizeof(value));
+ rpy_reverse_db_emit(sval[0]);
+ if (SIZEOF_LONG <= 4)
+ rpy_reverse_db_emit(sval[1]);
+}
diff --git a/rpython/translator/reversedb/rdb_genc.py
b/rpython/translator/reversedb/rdb_genc.py
new file mode 100644
--- /dev/null
+++ b/rpython/translator/reversedb/rdb_genc.py
@@ -0,0 +1,7 @@
+import py
+
+def extra_files():
+ srcdir = py.path.local(__file__).join('..', 'rdb-src')
+ return [
+ srcdir / 'rdb.c',
+ ]
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit