Author: Armin Rigo <[email protected]>
Branch: reverse-debugger
Changeset: r85448:45db8fd3e7a1
Date: 2016-06-29 13:30 +0200
http://bitbucket.org/pypy/pypy/changeset/45db8fd3e7a1/
Log: in-progress
diff --git a/pypy/interpreter/reverse_debugging.py
b/pypy/interpreter/reverse_debugging.py
--- a/pypy/interpreter/reverse_debugging.py
+++ b/pypy/interpreter/reverse_debugging.py
@@ -45,7 +45,7 @@
#revdb.register_debug_command(revdb.CMD_WATCHVALUES, lambda_watchvalues)
-pycode.PyCode.co_revdb_linestarts = None # or a string: a list of bits
+pycode.PyCode.co_revdb_linestarts = None # or a string: an array of bits
def potential_stop_point(frame):
@@ -71,28 +71,26 @@
def build_co_revdb_linestarts(code):
# inspired by findlinestarts() in the 'dis' standard module
- assert len(code.co_code) > 0
bits = [False] * len(code.co_code)
- bits[0] = True
- lnotab = code.co_lnotab
- addr = 0
- p = 0
- newline = True
- while p + 1 < len(lnotab):
- byte_incr = ord(lnotab[p])
- line_incr = ord(lnotab[p+1])
- if byte_incr:
- if newline:
- if addr < len(bits):
- bits[addr] = True
- newline = False
- addr += byte_incr
- if line_incr:
- newline = True
- p += 2
- if newline:
- if addr < len(bits):
- bits[addr] = True
+ if not code.hidden_applevel:
+ lnotab = code.co_lnotab
+ addr = 0
+ p = 0
+ newline = 1
+ while p + 1 < len(lnotab):
+ byte_incr = ord(lnotab[p])
+ line_incr = ord(lnotab[p+1])
+ if byte_incr:
+ if newline != 0:
+ if addr < len(bits):
+ bits[addr] = True
+ newline = 0
+ addr += byte_incr
+ newline |= line_incr
+ p += 2
+ if newline:
+ if addr < len(bits):
+ bits[addr] = True
#
byte_list = []
pending = 0
diff --git a/pypy/interpreter/test/test_reverse_debugging.py
b/pypy/interpreter/test/test_reverse_debugging.py
--- a/pypy/interpreter/test/test_reverse_debugging.py
+++ b/pypy/interpreter/test/test_reverse_debugging.py
@@ -1,5 +1,6 @@
import dis
from pypy.interpreter.reverse_debugging import *
+from hypothesis import given, strategies, example
class FakeCode:
@@ -10,11 +11,14 @@
self.co_revdb_linestarts = None
-def test_build_co_revdb_linestarts():
- fake_lnotab = ("\x01\x02\x03\x04"
- "\x00\xFF\x20\x30\x00\xFF\x00\x40"
- "\xFF\x00\x0A\x0B\xFF\x00\x0C\x00")
- code = FakeCode("?" * sum(map(ord, fake_lnotab[0::2])), fake_lnotab)
+@given(strategies.binary())
+@example("\x01\x02\x03\x04"
+ "\x00\xFF\x20\x30\x00\xFF\x00\x40"
+ "\xFF\x00\x0A\x0B\xFF\x00\x0C\x00")
+def test_build_co_revdb_linestarts(lnotab):
+ if len(lnotab) & 1:
+ lnotab = lnotab + '\x00' # make the length even
+ code = FakeCode("?" * sum(map(ord, lnotab[0::2])), lnotab)
lstart = build_co_revdb_linestarts(code)
assert lstart is code.co_revdb_linestarts
diff --git a/rpython/translator/revdb/process.py
b/rpython/translator/revdb/process.py
--- a/rpython/translator/revdb/process.py
+++ b/rpython/translator/revdb/process.py
@@ -173,9 +173,9 @@
break
elif msg.cmd == ANSWER_LINECACHE:
line = linecache.getline(msg.extra, msg.arg1)
- if not line.endswith('\n'):
- line += '\n'
- sys.stdout.write(line)
+ if line == '':
+ line = '?'
+ sys.stdout.write(line.strip() + '\n')
sys.stdout.flush()
elif msg.cmd == ANSWER_NEXTNID and pgroup is not None:
uid = msg.arg1
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
@@ -29,10 +29,14 @@
RPY_EXTERN void rpy_reverse_db_setup(int *argc_p, char **argv_p[]);
RPY_EXTERN void rpy_reverse_db_teardown(void);
-#if 0 /* enable to print locations to stderr of all the EMITs */
-# define _RPY_REVDB_PRINT(args) fprintf args
+#if 1 /* enable to print locations to stderr of all the EMITs */
+# define _RPY_REVDB_PRINT(mode) \
+ fprintf(stderr, \
+ "%s:%d: %0*llx\n", \
+ __FILE__, __LINE__, 2 * sizeof(_e), \
+ ((unsigned long long)_e) & ((2ULL << (8*sizeof(_e)-1)) - 1))
#else
-# define _RPY_REVDB_PRINT(args) /* nothing */
+# define _RPY_REVDB_PRINT(mode) /* nothing */
#endif
@@ -41,9 +45,7 @@
normal_code \
{ \
decl_e = variable; \
- _RPY_REVDB_PRINT((stderr, "%s:%d: write %0*llx\n", \
- __FILE__, __LINE__, \
- 2 * sizeof(_e), (unsigned long long)_e)); \
+ _RPY_REVDB_PRINT("write"); \
memcpy(rpy_revdb.buf_p, &_e, sizeof(_e)); \
if ((rpy_revdb.buf_p += sizeof(_e)) > rpy_revdb.buf_limit) \
rpy_reverse_db_flush(); \
@@ -54,9 +56,7 @@
char *_end1 = _src + sizeof(_e); \
memcpy(&_e, _src, sizeof(_e)); \
rpy_revdb.buf_p = _end1; \
- _RPY_REVDB_PRINT((stderr, "%s:%d: read %0*llx\n", \
- __FILE__, __LINE__, \
- 2 * sizeof(_e), (unsigned long long)_e)); \
+ _RPY_REVDB_PRINT("read"); \
if (_end1 >= rpy_revdb.buf_limit) \
rpy_reverse_db_fetch(__FILE__, __LINE__); \
variable = _e; \
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit