Author: Armin Rigo <ar...@tunes.org> Branch: reverse-debugger Changeset: r85124:6494d80c50d8 Date: 2016-06-13 13:03 +0200 http://bitbucket.org/pypy/pypy/changeset/6494d80c50d8/
Log: object_to_id diff --git a/rpython/rlib/revdb.py b/rpython/rlib/revdb.py --- a/rpython/rlib/revdb.py +++ b/rpython/rlib/revdb.py @@ -5,6 +5,8 @@ from rpython.rtyper.lltypesystem.lloperation import llop from rpython.rtyper.extregistry import ExtRegistryEntry from rpython.rtyper.annlowlevel import llhelper, hlstr +from rpython.rtyper.annlowlevel import cast_base_ptr_to_instance +from rpython.rtyper.rclass import OBJECTPTR def stop_point(): @@ -52,6 +54,15 @@ """ return llop.revdb_creation_time_of(lltype.SignedLongLong, x) +@specialize.argtype(0) +def object_to_id(x): + return llop.revdb_object_to_id(lltype.Signed, x) + +@specialize.arg(0) +def id_to_object(Class, object_id): + x = llop.revdb_id_to_object(OBJECTPTR, object_id) + return cast_base_ptr_to_instance(Class, x) + @specialize.arg(1) def go_forward(time_delta, callback, arg_string): """For RPython debug commands: tells that after this function finishes, diff --git a/rpython/rtyper/lltypesystem/lloperation.py b/rpython/rtyper/lltypesystem/lloperation.py --- a/rpython/rtyper/lltypesystem/lloperation.py +++ b/rpython/rtyper/lltypesystem/lloperation.py @@ -572,6 +572,8 @@ 'revdb_set_value': LLOp(), 'revdb_identityhash': LLOp(), 'revdb_creation_time_of': LLOp(sideeffects=False), + 'revdb_object_to_id': LLOp(sideeffects=False), + 'revdb_id_to_object': LLOp(sideeffects=False), } # ***** Run test_lloperation after changes. ***** 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 @@ -79,7 +79,7 @@ #define OP_REVDB_SEND_OUTPUT(ll_string, r) \ rpy_reverse_db_send_output(ll_string) -#define OP_REVDB_CHANGE_TIME(mode, time, callback, ll_string, r) \ +#define OP_REVDB_CHANGE_TIME(mode, time, callback, ll_string, r) \ rpy_reverse_db_change_time(mode, time, callback, ll_string) #define OP_REVDB_GET_VALUE(value_id, r) \ @@ -88,9 +88,15 @@ #define OP_REVDB_IDENTITYHASH(obj, r) \ r = rpy_reverse_db_identityhash((struct pypy_header0 *)(obj)) -#define OP_REVDB_CREATION_TIME_OF(x, r) \ +#define OP_REVDB_CREATION_TIME_OF(x, r) \ r = ((struct pypy_header0 *)x)->h_ctime +#define OP_REVDB_OBJECT_TO_ID(x, r) \ + r = (Signed)x + +#define OP_REVDB_ID_TO_OBJECT(x, r) \ + r = (void *)x + RPY_EXTERN void rpy_reverse_db_flush(void); RPY_EXTERN char *rpy_reverse_db_fetch(int expected_size, const char *file, int line); 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 @@ -292,6 +292,9 @@ def setup_class(cls): # + class Stuff: + pass + # def g(cmdline): if len(cmdline) > 5: raise ValueError @@ -333,6 +336,12 @@ revdb.jump_in_time(2, changed_time, "xyzzy") if cmdline == 'set-break-after-0': dbstate.break_after = 0 + if cmdline == 'print-id': + revdb.send_output('%d\n' % (revdb.object_to_id(dbstate.stuff),)) + if cmdline.startswith('check-id '): + obj_id = int(cmdline[len('check-id '):]) + revdb.send_output("%d\n" % + int(revdb.id_to_object(Stuff, obj_id) is dbstate.stuff)) revdb.send_output('blipped\n') lambda_blip = lambda: blip # @@ -341,6 +350,7 @@ dbstate = DBState() # def main(argv): + dbstate.stuff = Stuff() revdb.register_debug_command('r', lambda_blip) for i, op in enumerate(argv[1:]): revdb.stop_point() @@ -439,3 +449,22 @@ child.sendline('__forward 5') child.expectx('breakpoint!\r\n' '(2)$ ') + + def test_object_to_id(self): + child = self.replay() + child.expectx('(3)$ ') + child.sendline('r print-id') + child.expect(re.escape('<<<print-id>>>\r\n') + + r'(-?\d+)' + + re.escape('\r\n' + 'blipped\r\n' + '(3)$ ')) + object_id = child.match.group(1) + for at_time in [1, 2, 3]: + child.sendline('__go %d' % at_time) + child.expectx('(%d)$ ' % at_time) + child.sendline('r check-id ' + object_id) + child.expectx('<<<check-id %s>>>\r\n' % (object_id,) + + '1\r\n' + + 'blipped\r\n' + + '(%d)$ ' % at_time) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit