예제 #1
0
파일: plugin.py 프로젝트: evdenis/sprute
def on_pass_execution(p, fn):
   if p.name == '*free_lang_data':
      super_ops = set()
      inode_ops = set()
      dentry_ops = set()
      file_ops = set()

      for var in gcc.get_variables():
         if isinstance(var.decl.type, gcc.RecordType):
            ops = None
            if var.decl.type.name:
               if var.decl.type.name.name == 'super_operations':
                  ops = super_ops
               elif var.decl.type.name.name == 'inode_operations':
                  ops = inode_ops
               elif var.decl.type.name.name == 'file_operations':
                  ops = file_ops
               elif var.decl.type.name.name == 'dentry_operations':
                  ops = dentry_ops

            if ops != None and var.decl.initial:
               ops.update(['{}={}'.format(a.name, b.operand.name) for a,b in var.decl.initial.elements if ( isinstance(b, gcc.AddrExpr) and isinstance(b.operand, gcc.FunctionDecl))])

      if super_ops or inode_ops or dentry_ops or file_ops:
         with open('%s-vfs_ops.sprute' % (gcc.get_dump_base_name()), 'w') as f:
            for i in [['super', super_ops], ['inode', inode_ops], ['dentry', dentry_ops], ['file', file_ops]]:
               if i[1]:
                  f.write("\n".join(map(lambda x: i[0] + ';' + x, i[1])) + '\n' )
예제 #2
0
    def execute(self, fun):
        if fun:
            log('%s', fun)
            if self.verify_pyargs:
                check_pyargs(fun)

            if self.only_on_python_code:
                # Only run the refcount checker on code that
                # includes <Python.h>:
                if not get_PyObject():
                    return

            # The refcount code is too buggy for now to be on by default:
            if self.verify_refcounting:
                if 0:
                    # Profiled version:
                    import cProfile
                    prof_filename = '%s.%s.refcount-profile' % (gcc.get_dump_base_name(),
                                                                fun.decl.name)
                    cProfile.runctx('self._check_refcounts(fun)',
                                    globals(), locals(),
                                    filename=prof_filename)
                    import pstats
                    prof = pstats.Stats(prof_filename)
                    prof.sort_stats('cumulative').print_stats(20)
                else:
                    # Normal mode (without profiler):
                    self._check_refcounts(fun)
예제 #3
0
    def execute(self, fun):
        if fun:
            log('%s', fun)
            if self.verify_pyargs:
                check_pyargs(fun)

            if self.only_on_python_code:
                # Only run the refcount checker on code that
                # includes <Python.h>:
                if not get_PyObject():
                    return

            # The refcount code is too buggy for now to be on by default:
            if self.verify_refcounting:
                if 0:
                    # Profiled version:
                    import cProfile
                    prof_filename = '%s.%s.refcount-profile' % (
                        gcc.get_dump_base_name(), fun.decl.name)
                    cProfile.runctx('self._check_refcounts(fun)',
                                    globals(),
                                    locals(),
                                    filename=prof_filename)
                    import pstats
                    prof = pstats.Stats(prof_filename)
                    prof.sort_stats('cumulative').print_stats(20)
                else:
                    # Normal mode (without profiler):
                    self._check_refcounts(fun)
예제 #4
0
def main(**kwargs):
    global output_file
    output_file = open(gcc.get_dump_base_name() + '.gdb_exc.py', 'w')
    # We used to use attributes here, but there didn't seem to be a
    # big benefit over hard-coding.
    output_file.write('declare_throw("throw_exception")\n')
    output_file.write('declare_throw("throw_verror")\n')
    output_file.write('declare_throw("throw_vfatal")\n')
    output_file.write('declare_throw("throw_error")\n')
    gcc.register_callback(gcc.PLUGIN_FINISH_UNIT, close_output)
    ps = GdbExceptionChecker(output_file)
    ps.register_after('ssa')
예제 #5
0
def main(**kwargs):
    global output_file
    output_file = open(gcc.get_dump_base_name() + '.gdb_exc.py', 'w')
    # We used to use attributes here, but there didn't seem to be a
    # big benefit over hard-coding.
    output_file.write('declare_throw("throw_exception")\n')
    output_file.write('declare_throw("throw_verror")\n')
    output_file.write('declare_throw("throw_vfatal")\n')
    output_file.write('declare_throw("throw_error")\n')
    gcc.register_callback(gcc.PLUGIN_FINISH_UNIT, close_output)
    ps = GdbExceptionChecker(output_file)
    ps.register_after('ssa')
예제 #6
0
def on_pass_execution(p, fn):
    if p.name == '*free_lang_data':
        # The '*free_lang_data' pass is called once, rather than per-function,
        # and occurs immediately after "*build_cgraph_edges", which is the
        # pass that initially builds the callgraph
        #
        # So at this point we're likely to get a good view of the callgraph
        # before further optimization passes manipulate it
        dot = callgraph_to_dot()
        # invoke_dot(dot)
        filename = '%s.gv' % (gcc.get_dump_base_name())
        with open(filename, "w") as f:
            f.write(dot)
예제 #7
0
def log(msg, *args):
    if logging_enabled:
        # Only do the work of expanding the message if logging is enabled:
        expanded_msg = msg % args
        if 1:
            global logfile
            if not logfile:
                filename = gcc.get_dump_base_name() + '.cpychecker-log.txt'
                logfile = open(filename, 'w')
            logfile.write(expanded_msg)
            logfile.write('\n')
        if 0:
            sys.stderr.write(expanded_msg)
            sys.stderr.write('\n')
예제 #8
0
#
#   This program is distributed in the hope that it will be useful, but
#   WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#   General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see
#   <http://www.gnu.org/licenses/>.


# Verify working with GCC's dump files

import gcc

print('gcc.get_dump_base_name(): %r' % gcc.get_dump_base_name())

pass_dumpfile = None
class TestPass(gcc.GimplePass):
    def execute(self, fun):
        global pass_dumpfile
        print('within TestPass.execute, for %r' % fun)
        pass_dumpfile = gcc.get_dump_file_name()
        if 0:
            print('pass_dumpfile: %r' % pass_dumpfile)

        # Dumping of strings:
        gcc.dump('hello world')

        # Dumping of other objects:
        gcc.dump(42)
예제 #9
0
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful, but
#   WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#   General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see
#   <http://www.gnu.org/licenses/>.

# Verify working with GCC's dump files

import gcc

print('gcc.get_dump_base_name(): %r' % gcc.get_dump_base_name())

pass_dumpfile = None


class TestPass(gcc.GimplePass):
    def execute(self, fun):
        global pass_dumpfile
        print('within TestPass.execute, for %r' % fun)
        pass_dumpfile = gcc.get_dump_file_name()
        if 0:
            print('pass_dumpfile: %r' % pass_dumpfile)

        # Dumping of strings:
        gcc.dump('hello world')