예제 #1
0
def describe_trace(trace, report, annotator):
    """
    Buffer up more details about the path through the function that
    leads to the error, using report.add_inform()
    """
    awaiting_target = None
    for t in trace.transitions:
        log('transition: %s', t)
        srcloc = t.src.get_gcc_loc_or_none()
        if t.desc:
            if srcloc:
                report.add_inform(t.src.get_gcc_loc(report.fun),
                                  ('%s at: %s' %
                                   (t.desc, get_src_for_loc(srcloc))))
            else:
                report.add_inform(t.src.get_gcc_loc(report.fun), '%s' % t.desc)

            if t.src.stmtnode.bb != t.dest.stmtnode.bb:
                # Tell the user where conditionals reach:
                destloc = t.dest.get_gcc_loc_or_none()
                if destloc:
                    report.add_inform(
                        destloc, 'reaching: %s' % get_src_for_loc(destloc))

        if annotator:
            notes = annotator.get_notes(t)
            for note in notes:
                if note.loc and note.loc == srcloc:
                    report.add_inform(note.loc, note.msg)
예제 #2
0
def describe_trace(trace, report, annotator):
    """
    Buffer up more details about the path through the function that
    leads to the error, using report.add_inform()
    """
    awaiting_target = None
    for t in trace.transitions:
        log('transition: %s', t)
        srcloc = t.src.get_gcc_loc_or_none()
        if t.desc:
            if srcloc:
                report.add_inform(t.src.get_gcc_loc(report.fun),
                                  ('%s at: %s'
                                   % (t.desc, get_src_for_loc(srcloc))))
            else:
                report.add_inform(t.src.get_gcc_loc(report.fun),
                                  '%s' % t.desc)

            if t.src.loc.bb != t.dest.loc.bb:
                # Tell the user where conditionals reach:
                destloc = t.dest.get_gcc_loc_or_none()
                if destloc:
                    report.add_inform(destloc,
                                      'reaching: %s' % get_src_for_loc(destloc))

        if annotator:
            notes = annotator.get_notes(t)
            for note in notes:
                if note.loc and note.loc == srcloc:
                    report.add_inform(note.loc, note.msg)
예제 #3
0
    def check_callsite(stmt, parser, funcname, format_idx, varargs_idx,
                       with_size_t):
        log('got call at %s', stmt.loc)
        log(get_src_for_loc(stmt.loc))
        # log('stmt: %r %s', (stmt, stmt))
        # log('args: %r', stmt.args)
        # for arg in stmt.args:
        #    # log('  arg: %s %r', (arg, arg))

        # We expect the following args:
        #   args[0]: PyObject *input_tuple
        #   args[1]: char * format
        #   args[2...]: output pointers

        if len(stmt.args) >= format_idx:
            fmt_string = get_format_string(stmt, format_idx)
            if fmt_string:
                log('fmt_string: %r', fmt_string)

                loc = stmt.loc

                # Figure out expected types, based on the format string...
                try:
                    fmt = parser.from_string(fmt_string, with_size_t)
                except FormatStringWarning:
                    err = sys.exc_info()[1]
                    err.emit_as_warning(stmt.loc)
                    return
                log('fmt: %r', fmt.args)

                exp_types = list(fmt.iter_exp_types())
                log('exp_types: %r', exp_types)

                # ...then compare them against the actual types:
                varargs = stmt.args[varargs_idx:]
                # log('varargs: %r', varargs)
                if len(varargs) < len(exp_types):
                    NotEnoughVars(funcname, fmt, varargs).emit_as_warning(loc)
                    return

                if len(varargs) > len(exp_types):
                    TooManyVars(funcname, fmt, varargs).emit_as_warning(loc)
                    return

                for index, ((exp_arg, exp_type),
                            vararg) in enumerate(zip(exp_types, varargs)):
                    if not compatible_type(
                            exp_type, vararg.type, actualarg=vararg):
                        err = MismatchingType(funcname, fmt,
                                              index + varargs_idx + 1,
                                              exp_arg.code, exp_type, vararg)
                        if hasattr(vararg, 'location'):
                            loc = vararg.location
                        else:
                            loc = stmt.loc
                        err.emit_as_warning(loc)
    def check_callsite(stmt, parser, funcname, format_idx, varargs_idx, with_size_t):
        log('got call at %s', stmt.loc)
        log(get_src_for_loc(stmt.loc))
        # log('stmt: %r %s', (stmt, stmt))
        # log('args: %r', stmt.args)
        # for arg in stmt.args:
        #    # log('  arg: %s %r', (arg, arg))
            

        # We expect the following args:
        #   args[0]: PyObject *input_tuple
        #   args[1]: char * format
        #   args[2...]: output pointers

        if len(stmt.args) >= format_idx:
            fmt_string = get_format_string(stmt, format_idx)
            if fmt_string:
                log('fmt_string: %r', fmt_string)

                loc = stmt.loc

                # Figure out expected types, based on the format string...
                try:
                    fmt = parser.from_string(fmt_string, with_size_t)
                except FormatStringWarning:
                    err = sys.exc_info()[1]
                    err.emit_as_warning(stmt.loc)
                    return
                log('fmt: %r', fmt.args)

                exp_types = list(fmt.iter_exp_types())
                log('exp_types: %r', exp_types)

                # ...then compare them against the actual types:
                varargs = stmt.args[varargs_idx:]
                # log('varargs: %r', varargs)
                if len(varargs) < len(exp_types):
                    NotEnoughVars(funcname, fmt, varargs).emit_as_warning(loc)
                    return

                if len(varargs) > len(exp_types):
                    TooManyVars(funcname, fmt, varargs).emit_as_warning(loc)
                    return

                for index, ((exp_arg, exp_type), vararg) in enumerate(zip(exp_types, varargs)):
                    if not compatible_type(exp_type, vararg.type, actualarg=vararg):
                        err = MismatchingType(funcname, fmt,
                                              index + varargs_idx + 1,
                                              exp_arg.code, exp_type, vararg)
                        if hasattr(vararg, 'location'):
                            loc = vararg.location
                        else:
                            loc = stmt.loc
                        err.emit_as_warning(loc)
예제 #5
0
    def to_dot_html(self, ctxt):
        from gccutils.dot import Table, Tr, Td, Text, Br, Font
        from gccutils import get_src_for_loc

        loc = self.get_gcc_loc()
        if loc:
            table = Table()
            code = get_src_for_loc(loc).rstrip()
            tr = table.add_child(Tr())
            td = tr.add_child(Td(align='left'))
            td.add_child(Text('%4i %s' % (self.stmt.loc.line, code)))
            td.add_child(Br())
            td.add_child(Text(' ' * (5 + self.stmt.loc.column-1) + '^'))
            td.add_child(Br())
            td.add_child(Text(str(self)))
            return table
            # return Font([table], face="monospace")
        else:
            return Text(str(self))
예제 #6
0
    def to_dot_html(self, ctxt):
        from gccutils.dot import Table, Tr, Td, Text, Br, Font
        from gccutils import get_src_for_loc

        loc = self.get_gcc_loc()
        if loc:
            table = Table()
            code = get_src_for_loc(loc).rstrip()
            tr = table.add_child(Tr())
            td = tr.add_child(Td(align='left'))
            td.add_child(Text('%4i %s' % (self.stmt.loc.line, code)))
            td.add_child(Br())
            td.add_child(Text(' ' * (5 + self.stmt.loc.column - 1) + '^'))
            td.add_child(Br())
            td.add_child(Text(str(self)))
            return table
            # return Font([table], face="monospace")
        else:
            return Text(str(self))
예제 #7
0
    def state_to_dot_label(self, state, prevstate):
        result = '<table cellborder="0" border="0" cellspacing="0">\n'

        # Show data:
        result += '<tr><td colspan="2"><table border="0" cellborder="1">'
        result += ('<tr> %s %s %s</tr>\n'
                  % (self._dot_td('Expression'),
                     self._dot_td('lvalue'),
                     self._dot_td('rvalue')))
        for key in state.region_for_var:
            region = state.region_for_var[key]
            value = state.value_for_region.get(region, None)

            # Highlight new and changing values:
            is_new_key = True
            is_different_value = False
            if prevstate:
                if key in prevstate.region_for_var:
                    is_new_key = False
                    prevregion = prevstate.region_for_var[key]
                    prevvalue = prevstate.value_for_region.get(prevregion, None)
                    if value != prevvalue:
                        is_different_value = True

            if is_new_key:
                bgcolor = 'green'
                value_bgcolor = 'green'
            else:
                bgcolor = None
                if is_different_value:
                    value_bgcolor = 'green'
                else:
                    value_bgcolor = None

            result += ('<tr> %s %s %s</tr>\n'
                       % (self._dot_td(key, bgcolor=bgcolor),
                          self._dot_td(region, bgcolor=bgcolor),
                          self._dot_td(value, bgcolor=value_bgcolor)))

        # Show any return value:
        if state.return_rvalue:
            result += ('<tr> %s %s %s</tr>\n'
                       % (self._dot_td(''),
                          self._dot_td('Return Value', bgcolor='green'),
                          self._dot_td(state.return_rvalue, bgcolor='green')))
        result += '</table></td></tr>'

        # Show location:
        stmt = state.loc.get_stmt()
        if stmt:
            if stmt.loc:
                result += ('<tr><td>'
                           + self.to_html('%4i ' % stmt.loc.line)
                           + self.code_to_html(get_src_for_loc(stmt.loc))
                           + '<br/>'
                           + (' ' * (5 + stmt.loc.column-1)) + '^'
                           + '</td></tr>\n')
                result += '<tr><td></td>' + self.stmt_to_html(stmt, state.loc.idx) + '</tr>\n'

        result += '</table>\n'
        return result