예제 #1
0
def get_printable_location(next_instr, is_being_profiled, bytecode):
    from pypy.tool.stdlib_opcode import opcode_method_names
    from pypy.interpreter.pytraceback import offset2lineno
    bytecode_name = opcode_method_names[ord(bytecode.co_code[next_instr])]
    lineno = offset2lineno(bytecode, intmask(next_instr))
    return '%s;%s:%d-%d~#%d %s' % (
        bytecode.co_name, bytecode.co_filename, bytecode.co_firstlineno,
        lineno, next_instr, bytecode_name)
예제 #2
0
def get_location(next_instr, is_being_profiled, bytecode):
    from pypy.tool.stdlib_opcode import opcode_method_names
    from pypy.interpreter.pytraceback import offset2lineno
    bcindex = ord(bytecode.co_code[next_instr])
    opname = ""
    if 0 <= bcindex < len(opcode_method_names):
        opname = opcode_method_names[bcindex]
    name = bytecode.co_name
    if not name:
        name = ""
    line = offset2lineno(bytecode, intmask(next_instr))
    return (bytecode.co_filename, line,
            name, intmask(next_instr), opname)
예제 #3
0
파일: error.py 프로젝트: xx312022850/pypy
def source_lines(graph, block, operindex=None, offset=None, long=False, \
    show_lines_of_code=SHOW_DEFAULT_LINES_OF_CODE):
    if block is not None:
        if block is graph.returnblock:
            return ['<return block>']
    try:
        source = graph.source
    except AttributeError:
        return ['no source!']
    else:
        graph_lines = source.split("\n")
        if offset is not None:
            linestart = offset2lineno(graph.func.func_code, offset)
            linerange = (linestart, linestart)
            here = None
        else:
            if block is None or not block.operations:
                return []

            def toline(operindex):
                return offset2lineno(graph.func.func_code,
                                     block.operations[operindex].offset)

            if operindex is None:
                linerange = (toline(0), toline(-1))
                if not long:
                    return ['?']
                here = None
            else:
                operline = toline(operindex)
                if long:
                    linerange = (toline(0), toline(-1))
                    here = operline
                else:
                    linerange = (operline, operline)
                    here = None
        lines = [
            "Happened at file %s line %d" %
            (graph.filename, here or linerange[0]), ""
        ]
        for n in range(max(0, linerange[0]-show_lines_of_code), \
            min(linerange[1]+1+show_lines_of_code, len(graph_lines)+graph.startline)):
            if n == here:
                prefix = '==> '
            else:
                prefix = '    '
            lines.append(prefix + graph_lines[n - graph.startline])
        lines.append("")
        return lines
예제 #4
0
파일: error.py 프로젝트: Debug-Orz/Sypy
def source_lines1(graph, block, operindex=None, offset=None, long=False, \
    show_lines_of_code=SHOW_DEFAULT_LINES_OF_CODE):
    if block is not None:
        if block is graph.returnblock:
            return ['<return block>']
    try:
        source = graph.source
    except AttributeError:
        return ['no source!']
    else:
        graph_lines = source.split("\n")
        if offset is not None:
            linestart = offset2lineno(graph.func.func_code, offset)
            linerange = (linestart, linestart)
            here = None
        else:
            if block is None or not block.operations:
                return []
            def toline(operindex):
                return offset2lineno(graph.func.func_code, block.operations[operindex].offset)
            if operindex is None:
                linerange =  (toline(0), toline(-1))
                if not long:
                    return ['?']
                here = None
            else:
                operline = toline(operindex)
                if long:
                    linerange =  (toline(0), toline(-1))
                    here = operline
                else:
                    linerange = (operline, operline)
                    here = None
        lines = ["Happened at file %s line %d" % (graph.filename, here or linerange[0]), ""]
        for n in range(max(0, linerange[0]-show_lines_of_code), \
            min(linerange[1]+1+show_lines_of_code, len(graph_lines)+graph.startline)):
            if n == here:
                prefix = '==> '
            else:
                prefix = '    '
            lines.append(prefix + graph_lines[n-graph.startline])
        lines.append("")
        return lines
예제 #5
0
파일: pyframe.py 프로젝트: enyst/plexnet
 def get_last_lineno(self):
     "Returns the line number of the instruction currently being executed."
     return pytraceback.offset2lineno(self.pycode, self.last_instr)
예제 #6
0
 def get_last_lineno(self):
     "Returns the line number of the instruction currently being executed."
     return pytraceback.offset2lineno(self.pycode, self.last_instr)
예제 #7
0
파일: error.py 프로젝트: xx312022850/pypy
 def toline(operindex):
     return offset2lineno(graph.func.func_code,
                          block.operations[operindex].offset)
예제 #8
0
    def visit_Block(self, block, tagcolor):
        # do the block itself
        name = self.blockname(block)
        if not isinstance(block, Block):
            data = "BROKEN BLOCK\\n%r" % (block, )
            self.emit_node(name, label=data)
            return

        lines = []
        for op in block.operations:
            lines.extend(repr(op).split('\n'))
        lines.append("")
        numblocks = len(block.exits)
        color = "black"
        fillcolor = getattr(block, "blockcolor", "white")
        if not numblocks:
            shape = "box"
            if len(block.inputargs) == 1:
                lines[-1] += 'return %s' % tuple(block.inputargs)
                fillcolor = RETURN_COLOR
            elif len(block.inputargs) == 2:
                lines[-1] += 'raise %s, %s' % tuple(block.inputargs)
                fillcolor = EXCEPT_COLOR
        elif numblocks == 1:
            shape = "box"
        else:
            color = "red"
            shape = "octagon"

        if block.exitswitch is not None:
            lines.append("exitswitch: %s" % block.exitswitch)

        iargs = " ".join(map(repr, block.inputargs))
        if self.VERBOSE:
            if block.exc_handler:
                eh = ' (EH)'
            else:
                eh = ''
            data = "%s%s%s\\n" % (name, block.at(), eh)
        else:
            data = "%s\\n" % (name, )
        data += "inputargs: %s\\n\\n" % (iargs, )
        if self.VERBOSE and block.operations and self.func:
            maxoffs = max([op.offset for op in block.operations])
            if maxoffs >= 0:
                minoffs = min(
                    [op.offset for op in block.operations if op.offset >= 0])
                minlineno = offset2lineno(self.func.func_code, minoffs)
                maxlineno = offset2lineno(self.func.func_code, maxoffs)
                filename = inspect.getsourcefile(self.func)
                source = "\l".join([
                    linecache.getline(filename, line).rstrip()
                    for line in range(minlineno, maxlineno + 1)
                ])
                if minlineno == maxlineno:
                    data = data + r"line %d:\n%s\l\n" % (minlineno, source)
                else:
                    data = data + r"lines %d-%d:\n%s\l\n" % (minlineno,
                                                             maxlineno, source)

        data = data + "\l".join(lines)

        self.emit_node(name,
                       label=data,
                       shape=shape,
                       color=color,
                       style="filled",
                       fillcolor=fillcolor)

        # do links/exits
        for link in block.exits:
            name2 = self.blockname(link.target)
            label = " ".join(map(repr, link.args))
            if link.exitcase is not None:
                label = "%s: %s" % (repr(link.exitcase).replace('\\',
                                                                '\\\\'), label)
                self.emit_edge(name, name2, label, style="dotted", color="red")
            else:
                self.emit_edge(name, name2, label, style="solid")
예제 #9
0
파일: error.py 프로젝트: Debug-Orz/Sypy
 def toline(operindex):
     return offset2lineno(graph.func.func_code, block.operations[operindex].offset)
예제 #10
0
파일: make_dot.py 프로젝트: alkorzt/pypy
    def visit_Block(self, block, tagcolor):
        # do the block itself
        name = self.blockname(block)
        if not isinstance(block, Block):
            data = "BROKEN BLOCK\\n%r" % (block,)
            self.emit_node(name, label=data)
            return

        lines = []
        for op in block.operations:
            lines.extend(repr(op).split("\n"))
        lines.append("")
        numblocks = len(block.exits)
        color = "black"
        fillcolor = getattr(block, "blockcolor", "white")
        if not numblocks:
            shape = "box"
            if len(block.inputargs) == 1:
                lines[-1] += "return %s" % tuple(block.inputargs)
                fillcolor = RETURN_COLOR
            elif len(block.inputargs) == 2:
                lines[-1] += "raise %s, %s" % tuple(block.inputargs)
                fillcolor = EXCEPT_COLOR
        elif numblocks == 1:
            shape = "box"
        else:
            color = "red"
            shape = "octagon"

        if block.exitswitch is not None:
            lines.append("exitswitch: %s" % block.exitswitch)

        iargs = " ".join(map(repr, block.inputargs))
        if self.VERBOSE:
            if block.exc_handler:
                eh = " (EH)"
            else:
                eh = ""
            data = "%s%s%s\\n" % (name, block.at(), eh)
        else:
            data = "%s\\n" % (name,)
        data += "inputargs: %s\\n\\n" % (iargs,)
        if self.VERBOSE and block.operations and self.func:
            maxoffs = max([op.offset for op in block.operations])
            if maxoffs >= 0:
                minoffs = min([op.offset for op in block.operations if op.offset >= 0])
                minlineno = offset2lineno(self.func.func_code, minoffs)
                maxlineno = offset2lineno(self.func.func_code, maxoffs)
                filename = inspect.getsourcefile(self.func)
                source = "\l".join(
                    [linecache.getline(filename, line).rstrip() for line in range(minlineno, maxlineno + 1)]
                )
                if minlineno == maxlineno:
                    data = data + r"line %d:\n%s\l\n" % (minlineno, source)
                else:
                    data = data + r"lines %d-%d:\n%s\l\n" % (minlineno, maxlineno, source)

        data = data + "\l".join(lines)

        self.emit_node(name, label=data, shape=shape, color=color, style="filled", fillcolor=fillcolor)

        # do links/exits
        for link in block.exits:
            name2 = self.blockname(link.target)
            label = " ".join(map(repr, link.args))
            if link.exitcase is not None:
                label = "%s: %s" % (repr(link.exitcase).replace("\\", "\\\\"), label)
                self.emit_edge(name, name2, label, style="dotted", color="red")
            else:
                self.emit_edge(name, name2, label, style="solid")