[pypy-commit] pypy reverse-debugger: Write the argv in "clear text" inside the PYPYRDB log file, and
arigo
pypy.commits at gmail.com
Sun Jun 12 02:46:27 EDT 2016
Author: Armin Rigo <arigo at tunes.org>
Branch: reverse-debugger
Changeset: r85104:d1c588f9f886
Date: 2016-06-12 08:47 +0200
http://bitbucket.org/pypy/pypy/changeset/d1c588f9f886/
Log: Write the argv in "clear text" inside the PYPYRDB log file, and
display them again in --replay
diff --git a/rpython/translator/revdb/rdb-src/revdb.c b/rpython/translator/revdb/rdb-src/revdb.c
--- a/rpython/translator/revdb/rdb-src/revdb.c
+++ b/rpython/translator/revdb/rdb-src/revdb.c
@@ -14,12 +14,12 @@
#include "src/rtyper.h"
#include "rdb-src/revdb_include.h"
-#define RDB_SIGNATURE 0x0A424452 /* "RDB\n" */
+#define RDB_SIGNATURE "RDB:"
#define RDB_VERSION 0x00FF0001
typedef struct {
- Signed signature, version;
+ Signed version;
Signed reserved1, reserved2;
int argc;
char **argv;
@@ -99,6 +99,7 @@
{
char *filename = getenv("PYPYRDB");
rdb_header_t h;
+ int i;
assert(RPY_RDB_REPLAY == 0);
rpy_revdb.buf_p = rpy_rev_buffer;
@@ -115,8 +116,14 @@
}
atexit(rpy_reverse_db_flush);
+ write_all(RDB_SIGNATURE, strlen(RDB_SIGNATURE));
+ for (i = 0; i < argc; i++) {
+ write_all(" ", 1);
+ write_all(argv[i], strlen(argv[i]));
+ }
+ write_all("\n\0", 2);
+
memset(&h, 0, sizeof(h));
- h.signature = RDB_SIGNATURE;
h.version = RDB_VERSION;
h.argc = argc;
h.argv = argv;
@@ -258,6 +265,8 @@
char **argv = *argv_p;
char *filename;
rdb_header_t h;
+ char input[sizeof(rdb_header_t)];
+ ssize_t count;
if (argc != 3) {
fprintf(stderr, "syntax: %s --replay <RevDB-file>\n", argv[0]);
@@ -273,13 +282,23 @@
assert(RPY_RDB_REPLAY == 1);
- read_all(&h, sizeof(h));
-
- if (h.signature != RDB_SIGNATURE) {
+ read_all(input, strlen(RDB_SIGNATURE));
+ if (strncmp(input, RDB_SIGNATURE, strlen(RDB_SIGNATURE)) != 0) {
fprintf(stderr, "'%s' is not a RevDB file (or wrong platform)\n",
filename);
exit(1);
}
+ fprintf(stderr, "%s", RDB_SIGNATURE);
+ do {
+ count = read_at_least(input, 1, sizeof(input) - 1);
+ input[count] = 0;
+ fprintf(stderr, "%s", input);
+ } while (strlen(input) == count);
+
+ count -= (strlen(input) + 1);
+ memcpy(&h, input + strlen(input) + 1, count);
+
+ read_all(((char *)&h) + count, sizeof(h) - count);
if (h.version != RDB_VERSION) {
fprintf(stderr, "RevDB file version mismatch (got %lx, expected %lx)\n",
(long)h.version, (long)RDB_VERSION);
@@ -288,10 +307,12 @@
*argc_p = h.argc;
*argv_p = h.argv;
- if (lseek(rpy_rev_fileno, -sizeof(uint64_t), SEEK_END) < 0 ||
+ count = lseek(rpy_rev_fileno, 0, SEEK_CUR);
+ if (count < 0 ||
+ lseek(rpy_rev_fileno, -sizeof(uint64_t), SEEK_END) < 0 ||
read(rpy_rev_fileno, &total_stop_points,
sizeof(uint64_t)) != sizeof(uint64_t) ||
- lseek(rpy_rev_fileno, sizeof(h), SEEK_SET) != sizeof(h)) {
+ lseek(rpy_rev_fileno, count, SEEK_SET) != count) {
fprintf(stderr, "%s: %m\n", filename);
exit(1);
}
diff --git a/rpython/translator/revdb/test/test_basic.py b/rpython/translator/revdb/test/test_basic.py
--- a/rpython/translator/revdb/test/test_basic.py
+++ b/rpython/translator/revdb/test/test_basic.py
@@ -14,17 +14,20 @@
class RDB(object):
- def __init__(self, filename):
+ def __init__(self, filename, expected_argv):
with open(filename, 'rb') as f:
+ header = f.readline()
self.buffer = f.read()
+ assert header == 'RDB: ' + ' '.join(expected_argv) + '\n'
#
self.cur = 0
- x = self.next(); assert x == 0x0A424452
+ x = self.next('c'); assert x == '\x00'
x = self.next(); assert x == 0x00FF0001
x = self.next(); assert x == 0
x = self.next(); assert x == 0
self.argc = self.next()
self.argv = self.next()
+ self.read_check_argv(expected_argv)
def next(self, mode='P'):
p = self.cur
@@ -81,8 +84,8 @@
print >> sys.stderr, stderr
return stdout
-def fetch_rdb(self):
- return RDB(self.rdbname)
+def fetch_rdb(self, expected_argv):
+ return RDB(self.rdbname, map(str, expected_argv))
class TestRecording(object):
@@ -96,8 +99,7 @@
return 9
self.compile(main, [], backendopt=False)
assert self.run('abc d') == '[abc, d]\n'
- rdb = self.fetch_rdb()
- rdb.read_check_argv([self.exename, 'abc', 'd'])
+ rdb = self.fetch_rdb([self.exename, 'abc', 'd'])
# write() call
x = rdb.next(); assert x == len('[abc, d]\n')
x = rdb.next('i'); assert x == 0 # errno
@@ -116,8 +118,7 @@
match = re.match(r'\[(-?\d+), \1, \1]\n', out)
assert match
hash_value = int(match.group(1))
- rdb = self.fetch_rdb()
- rdb.read_check_argv([self.exename, 'Xx'])
+ rdb = self.fetch_rdb([self.exename, 'Xx'])
# compute_identity_hash() call, but only the first one
x = rdb.next(); assert intmask(x) == intmask(hash_value)
# write() call
@@ -139,8 +140,7 @@
self.compile(main, [], backendopt=False)
out = self.run('Xx')
assert out == '42\n'
- rdb = self.fetch_rdb()
- rdb.read_check_argv([self.exename, 'Xx'])
+ rdb = self.fetch_rdb([self.exename, 'Xx'])
# write() call (it used to be the case that vtable reads where
# recorded too; the single byte fetched from the vtable from
# the '.x' in main() would appear here)
@@ -163,8 +163,7 @@
self.compile(main, [], backendopt=False)
out = self.run('Xx')
assert out == '41\n'
- rdb = self.fetch_rdb()
- rdb.read_check_argv([self.exename, 'Xx'])
+ rdb = self.fetch_rdb([self.exename, 'Xx'])
# write() call
x = rdb.next(); assert x == len(out)
x = rdb.next('i'); assert x == 0 # errno
@@ -198,7 +197,8 @@
return 9
compile(cls, main, [], backendopt=False)
assert run(cls, 'abc d ef') == 'abc\nd\nef\n'
- assert fetch_rdb(cls).number_of_stop_points() == 3
+ rdb = fetch_rdb(cls, [cls.exename, 'abc', 'd', 'ef'])
+ assert rdb.number_of_stop_points() == 3
def test_go(self):
child = self.replay()
More information about the pypy-commit
mailing list