summaryrefslogtreecommitdiffstats
path: root/Tools/scripts
diff options
context:
space:
mode:
authorMichael W. Hudson <mwh@python.net>2002-08-15 14:59:02 (GMT)
committerMichael W. Hudson <mwh@python.net>2002-08-15 14:59:02 (GMT)
commitdd32a91cc0c8ba178d7ee5e78c30b6920aff66f4 (patch)
tree1a2062b54d3445ca788fd63c2bc63984dd85f34a /Tools/scripts
parentadd88060c1d1a98c7970e35b326e6a65a17ddf04 (diff)
downloadcpython-dd32a91cc0c8ba178d7ee5e78c30b6920aff66f4.zip
cpython-dd32a91cc0c8ba178d7ee5e78c30b6920aff66f4.tar.gz
cpython-dd32a91cc0c8ba178d7ee5e78c30b6920aff66f4.tar.bz2
This is my patch
[ 587993 ] SET_LINENO killer Remove SET_LINENO. Tracing is now supported by inspecting co_lnotab. Many sundry changes to document and adapt to this change.
Diffstat (limited to 'Tools/scripts')
-rw-r--r--Tools/scripts/trace.py49
1 files changed, 15 insertions, 34 deletions
diff --git a/Tools/scripts/trace.py b/Tools/scripts/trace.py
index 9c4819f..f96e04f 100644
--- a/Tools/scripts/trace.py
+++ b/Tools/scripts/trace.py
@@ -370,41 +370,29 @@ class CoverageResults:
except IOError, err:
sys.stderr.write("cannot save counts files because %s" % err)
-# Given a code string, return the SET_LINENO information
-def _find_LINENO_from_string(co_code):
- """return all of the SET_LINENO information from a code string"""
- import dis
+def _find_LINENO_from_code(code):
+ """return the numbers of the lines containing the source code that
+ was compiled into code"""
linenos = {}
- # This code was filched from the `dis' module then modified
- n = len(co_code)
- i = 0
- prev_op = None
- prev_lineno = 0
- while i < n:
- c = co_code[i]
- op = ord(c)
- if op == dis.SET_LINENO:
- if prev_op == op:
- # two SET_LINENO in a row, so the previous didn't
- # indicate anything. This occurs with triple
- # quoted strings (?). Remove the old one.
- del linenos[prev_lineno]
- prev_lineno = ord(co_code[i+1]) + ord(co_code[i+2])*256
- linenos[prev_lineno] = 1
- if op >= dis.HAVE_ARGUMENT:
- i = i + 3
- else:
- i = i + 1
- prev_op = op
+ line_increments = [ord(c) for c in code.co_lnotab[1::2]]
+ table_length = len(line_increments)
+
+ lineno = code.co_first_lineno
+
+ for li in line_increments:
+ linenos[lineno] = 1
+ lineno += li
+ linenos[lineno] = 1
+
return linenos
def _find_LINENO(code):
- """return all of the SET_LINENO information from a code object"""
+ """return all of the lineno information from a code object"""
import types
# get all of the lineno information from the code of this scope level
- linenos = _find_LINENO_from_string(code.co_code)
+ linenos = _find_LINENO_from_code(code)
# and check the constants for references to other code objects
for c in code.co_consts:
@@ -416,9 +404,6 @@ def _find_LINENO(code):
def find_executable_linenos(filename):
"""return a dict of the line numbers from executable statements in a file
- Works by finding all of the code-like objects in the module then searching
- the byte code for 'SET_LINENO' terms (so this won't work one -O files).
-
"""
import parser
@@ -428,10 +413,6 @@ def find_executable_linenos(filename):
ast = parser.suite(prog)
code = parser.compileast(ast, filename)
- # The only way I know to find line numbers is to look for the
- # SET_LINENO instructions. Isn't there some way to get it from
- # the AST?
-
return _find_LINENO(code)
### XXX because os.path.commonprefix seems broken by my way of thinking...