Author: Armin Rigo <ar...@tunes.org> Branch: reverse-debugger Changeset: r86941:fad74c992868 Date: 2016-09-07 17:30 +0200 http://bitbucket.org/pypy/pypy/changeset/fad74c992868/
Log: in-progress diff --git a/rpython/rlib/src/boehm-rawrefcount.h b/rpython/rlib/src/boehm-rawrefcount.h --- a/rpython/rlib/src/boehm-rawrefcount.h +++ b/rpython/rlib/src/boehm-rawrefcount.h @@ -4,6 +4,9 @@ OP_GC_RAWREFCOUNT_CREATE_LINK_PYOBJ(): not implemented, maybe not needed */ +#ifdef RPY_REVERSE_DEBUGGER +/* these macros are defined in src-revdb/revdb_include.h */ +#else #define OP_GC_RAWREFCOUNT_CREATE_LINK_PYPY(gcobj, pyobj, r) \ gc_rawrefcount_create_link_pypy(gcobj, pyobj) @@ -15,6 +18,7 @@ #define OP_GC_RAWREFCOUNT_NEXT_DEAD(r) \ r = gc_rawrefcount_next_dead() +#endif RPY_EXTERN void gc_rawrefcount_create_link_pypy(/*gcobj_t*/void *gcobj, diff --git a/rpython/translator/revdb/src-revdb/revdb.c b/rpython/translator/revdb/src-revdb/revdb.c --- a/rpython/translator/revdb/src-revdb/revdb.c +++ b/rpython/translator/revdb/src-revdb/revdb.c @@ -1762,7 +1762,8 @@ return result; } -RPY_EXTERN RPyString *rpy_reverse_db_dtoa(double d) +RPY_EXTERN +RPyString *rpy_reverse_db_dtoa(double d) { char buffer[128], *p; RPyString *result; @@ -1782,6 +1783,153 @@ } +static void *rawrefcount_tree; /* {pyobj: gcobj} */ + +struct rawrefcount_link2_s { + void *pyobj; + void *gcobj; +}; + +static int _rrtree_compare(const void *obj1, const void *obj2) +{ + const struct rawrefcount_link2_s *r1 = obj1; + const struct rawrefcount_link2_s *r2 = obj2; + void *p1 = r1->pyobj; + void *p2 = r2->pyobj; + if (p1 < p2) + return -1; + if (p1 == p2) + return 0; + else + return 1; +} + +static void _rrtree_add(void *pyobj, void *gcobj) +{ + /* Note: we always allocate an indirection through a + struct rawrefcount_link2_s, so that Boehm knows that + 'gcobj' must be kept alive. */ + struct rawrefcount_link2_s *node, **item; + node = GC_MALLOC_UNCOLLECTABLE(sizeof(struct rawrefcount_link2_s)); + node->pyobj = pyobj; + node->gcobj = gcobj; + item = tsearch(node, &rawrefcount_tree, _rrtree_compare); + if (item == NULL) { + fprintf(stderr, "_rrtree_add: out of memory\n"); + exit(1); + } + if (*item != node) { + fprintf(stderr, "_rrtree_add: duplicate object\n"); + exit(1); + } +} + +RPY_EXTERN +void rpy_reverse_db_rawrefcount_create_link_pypy(void *gcobj, void *pyobj) +{ + if (!RPY_RDB_REPLAY) { + gc_rawrefcount_create_link_pypy(gcobj, pyobj); + } + else { + _rrtree_add(pyobj, gcobj); + } +} + +RPY_EXTERN +void *rpy_reverse_db_rawrefcount_from_obj(void *gcobj) +{ + void *r; + RPY_REVDB_EMIT(r = gc_rawrefcount_from_obj(gcobj);, void *_e, r); + return r; +} + +RPY_EXTERN +void *rpy_reverse_db_rawrefcount_to_obj(void *pyobj) +{ + unsigned char flag; + + if (!RPY_RDB_REPLAY) { + void *r = gc_rawrefcount_to_obj(pyobj); + RPY_REVDB_EMIT(flag = 0xEE + !r;, unsigned char _e, flag); + return r; + } + else { + RPY_REVDB_EMIT(abort();, unsigned char _e, flag); + switch (flag) { + + case 0xEF: + /* when recording, this call to to_obj() returned NULL */ + return NULL; + + case 0xEE: + /* when recording, this call to to_obj() didn't return NULL */ + break; + + default: + fprintf(stderr, "bad byte in rawrefcount_to_obj\n"); + exit(1); + } + + struct rawrefcount_link2_s **item, dummy; + dummy.pyobj = pyobj; + item = tfind(&dummy, &rawrefcount_tree, _rrtree_compare); + if (item == NULL) { + fprintf(stderr, "rawrefcount_to_obj: not found in tree\n"); + exit(1); + } + return (*item)->gcobj; + } +} + +RPY_EXTERN +void *rpy_reverse_db_rawrefcount_next_dead(void) +{ + unsigned char flag; + + if (!RPY_RDB_REPLAY) { + void *r = gc_rawrefcount_next_dead(); + RPY_REVDB_EMIT(flag = 0xEC + !r;, unsigned char _e, flag); + if (r) { + RPY_REVDB_EMIT(;, void *_e, r); + } + return r; + } + else { + RPY_REVDB_EMIT(abort();, unsigned char _e, flag); + switch (flag) { + + case 0xED: + /* when recording, this call to next_dead() returned NULL */ + return NULL; + + case 0xEE: + /* when recording, this call to next_dead() didn't return NULL */ + break; + + default: + fprintf(stderr, "bad byte in rawrefcount_next_dead\n"); + exit(1); + } + + void *pyobj; + RPY_REVDB_EMIT(abort();, void *_e, pyobj); + + struct rawrefcount_link2_s **item, *entry, dummy; + dummy.pyobj = pyobj; + item = tfind(&dummy, &rawrefcount_tree, _rrtree_compare); + if (item == NULL) { + fprintf(stderr, "rawrefcount_next_dead: not found in tree\n"); + exit(1); + } + entry = *item; + tdelete(entry, &rawrefcount_tree, _rrtree_compare); + GC_FREE(entry); + + return pyobj; + } +} + + /* ------------------------------------------------------------ */ diff --git a/rpython/translator/revdb/src-revdb/revdb_include.h b/rpython/translator/revdb/src-revdb/revdb_include.h --- a/rpython/translator/revdb/src-revdb/revdb_include.h +++ b/rpython/translator/revdb/src-revdb/revdb_include.h @@ -38,7 +38,7 @@ if (rpy_rev_fileno >= 0) { \ fprintf(stderr, \ "%s %s:%d: %0*llx\n", \ - mode, __FILE__, __LINE__, 2 * sizeof(_e), \ + mode, __FILE__, (int)__LINE__, (int)(2 * sizeof(_e)), \ ((unsigned long long)_e) & ((2ULL << (8*sizeof(_e)-1)) - 1)); \ } #endif @@ -51,7 +51,7 @@ seeing_uid(uid); \ fprintf(stderr, \ "[nobj] %s:%d: obj %llu\n", \ - __FILE__, __LINE__, (unsigned long long) uid); \ + __FILE__, (int)__LINE__, (unsigned long long) uid); \ } #endif @@ -251,6 +251,19 @@ } while (0) +#define OP_GC_RAWREFCOUNT_CREATE_LINK_PYPY(gcobj, pyobj, r) \ + rpy_reverse_db_rawrefcount_create_link_pypy(gcobj, pyobj) + +#define OP_GC_RAWREFCOUNT_FROM_OBJ(gcobj, r) \ + r = rpy_reverse_db_rawrefcount_from_obj(gcobj) + +#define OP_GC_RAWREFCOUNT_TO_OBJ(pyobj, r) \ + r = rpy_reverse_db_rawrefcount_to_obj(pyobj) + +#define OP_GC_RAWREFCOUNT_NEXT_DEAD(r) \ + r = rpy_reverse_db_rawrefcount_next_dead() + + RPY_EXTERN void rpy_reverse_db_flush(void); /* must be called with the lock */ RPY_EXTERN void rpy_reverse_db_fetch(const char *file, int line); RPY_EXTERN void rpy_reverse_db_stop_point(long place); @@ -275,5 +288,10 @@ RPY_EXTERN void rpy_reverse_db_set_thread_breakpoint(int64_t tnum); RPY_EXTERN double rpy_reverse_db_strtod(RPyString *s); RPY_EXTERN RPyString *rpy_reverse_db_dtoa(double d); +RPY_EXTERN void rpy_reverse_db_rawrefcount_create_link_pypy(void *gcobj, + void *pyobj); +RPY_EXTERN void *rpy_reverse_db_rawrefcount_from_obj(void *gcobj); +RPY_EXTERN void *rpy_reverse_db_rawrefcount_to_obj(void *pyobj); +RPY_EXTERN void *rpy_reverse_db_rawrefcount_next_dead(void); /* ------------------------------------------------------------ */ _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit