All Projects → davidmalcolm → Gcc Python Plugin

davidmalcolm / Gcc Python Plugin

Licence: gpl-3.0
GCC plugin that embeds CPython inside the compiler

Programming Languages

python
139335 projects - #7 most used programming language
c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to Gcc Python Plugin

Reading
A list of computer-science readings I recommend
Stars: ✭ 1,919 (+1270.71%)
Mutual labels:  static-analysis
Mazewalker
Toolkit for enriching and speeding up static malware analysis
Stars: ✭ 132 (-5.71%)
Mutual labels:  static-analysis
I18n Tasks
Manage translation and localization with static analysis, for Ruby i18n
Stars: ✭ 1,748 (+1148.57%)
Mutual labels:  static-analysis
Malwarelab vm Setup
Setup scripts for my Malware Analysis VMs
Stars: ✭ 126 (-10%)
Mutual labels:  static-analysis
Frama C Snapshot
Release snapshots of the Frama-C platform for source code analysis
Stars: ✭ 129 (-7.86%)
Mutual labels:  static-analysis
Just Another Android App
An Android base app with loads of cool libraries/configuration NOT MAINTAINED
Stars: ✭ 1,654 (+1081.43%)
Mutual labels:  static-analysis
Config Lint
Command line tool to validate configuration files
Stars: ✭ 118 (-15.71%)
Mutual labels:  static-analysis
Semgrep Rules
Semgrep rules registry
Stars: ✭ 140 (+0%)
Mutual labels:  static-analysis
Rstcheck
Checks syntax of reStructuredText and code blocks nested within it
Stars: ✭ 130 (-7.14%)
Mutual labels:  static-analysis
Dependency Cruiser
Validate and visualize dependencies. Your rules. JavaScript, TypeScript, CoffeeScript. ES6, CommonJS, AMD.
Stars: ✭ 2,326 (+1561.43%)
Mutual labels:  static-analysis
Find Sec Bugs
The SpotBugs plugin for security audits of Java web applications and Android applications. (Also work with Kotlin, Groovy and Scala projects)
Stars: ✭ 1,748 (+1148.57%)
Mutual labels:  static-analysis
Ruby Type Inference
Dynamic definitions and types provider for ruby static analysis
Stars: ✭ 129 (-7.86%)
Mutual labels:  static-analysis
Typestat
Converts JavaScript to TypeScript and TypeScript to better TypeScript.
Stars: ✭ 136 (-2.86%)
Mutual labels:  static-analysis
Zpa
A parser and source code analyzer for PL/SQL and Oracle SQL.
Stars: ✭ 124 (-11.43%)
Mutual labels:  static-analysis
Awesome Machine Learning Deep Learning Mathematics
A curated list of mathematics documents ,Concepts, Study Materials , Algorithms and Codes available across the internet for machine learning and deep learning
Stars: ✭ 138 (-1.43%)
Mutual labels:  static-analysis
Argus Saf
Argus static analysis framework
Stars: ✭ 117 (-16.43%)
Mutual labels:  static-analysis
Nodejsscan
nodejsscan is a static security code scanner for Node.js applications.
Stars: ✭ 1,874 (+1238.57%)
Mutual labels:  static-analysis
Mutant
Automated code reviews via mutation testing - semantic code coverage.
Stars: ✭ 1,794 (+1181.43%)
Mutual labels:  static-analysis
Cscout
C code refactoring browser
Stars: ✭ 139 (-0.71%)
Mutual labels:  static-analysis
Php testability
Analyses and reports testability issues of a php codebase
Stars: ✭ 136 (-2.86%)
Mutual labels:  static-analysis

gcc-python

This is a plugin for GCC, which links against libpython, and (I hope) allows you to invoke arbitrary Python scripts from inside the compiler. The aim is to allow you to write GCC plugins in Python.

The plugin is Free Software, licensed under the GPLv3 (or later).

It's still at the "experimental proof-of-concept stage"; expect crashes and tracebacks (I'm new to insides of GCC, and I may have misunderstood things).

It's already possible to use this to add additional compiler errors/warnings, e.g. domain-specific checks, or static analysis. One of my goals for this is to "teach" GCC about the common mistakes people make when writing extensions for CPython, but it could be used e.g. to teach GCC about GTK's reference-counting semantics, or about locking in the Linux kernel, or about signal-safety in APIs.

Other ideas include visualizations of code structure. Given a gcc.CFG instance, gccutils.render_to_dot(cfg) and gccutils.invoke_dot(cfg) will use graphviz and eog to plot a handy visualization of a control flow graph, showing the source code interleaved with GCC's GIMPLE internal representation.

The documentation can be seen at:

http://gcc-python-plugin.readthedocs.io/en/latest/index.html

Requirements

  • GCC: 4.6 or later (it uses APIs that weren't exposed to plugins in 4.5)

    • tested with 4.8, 4.9, 5, 6, 7, and 8.
  • GCC plugin development package: usually available in distribution packages such as gcc-N-plugin-dev or gcc-plugin-devel.

  • Python: requires 2.7 or 3.2 or later

  • "six": The libcpychecker code uses the "six_" Python compatibility library to smooth over Python 2 vs Python 3 differences, both at build-time and run-time

    .. _six: http://pypi.python.org/pypi/six/

Usage

I use::

make

to build the plugin and run the tests

You can also use::

make demo

to demonstrate the new compiler errors.

Development has been on x86_64 and I don't know to what extent it will be compatible with other architectures.

There isn't an installer yet. In theory you should be able to add these arguments to the gcc invocation::

gcc -fplugin=python.so -fplugin-arg-python-script=PATH_TO_SCRIPT.py OTHER_ARGS

and have it run your script as the plugin starts up.

The plugin automatically adds the absolute path to its own directory to the end of its sys.path, so that it can find support modules, such as gccutils.py and libcpychecker.

The exact API is still in flux; you can currently connect to events by registering callbacks e.g. to be called for each function in the source at different passes.

It exposes GCC's various types as Python objects, within a "gcc" module. You can see the API by running::

import gcc
help(gcc)

from within a script.

Overview of the code

This is currently three projects in one:

gcc-python-*: the plugin for GCC. The entrypoint (init_plugin) is in gcc-python.c.

libcpychecker and cpychecker.py: a Python library (and a driver script), written for the plugin, in which I'm building new compiler warnings to help people find bugs in CPython extension code.

cpybuilder: a handy module for programatically generating C source code for CPython extensions. I use this both to generate parts of the GCC plugin, and also in the selftests for the cpychecker script. (I initially attempted to use Cython for the former, but wrapping the "tree" type hierarchy required more programatic control)

Coding style: Python and GCC each have their own coding style guide for C. I've chosen to follow Python's (PEP-7), as I prefer it (although my code is admittedly a mess in places).

You'll find API documentation within the "docs" directory, written in the reStructuredText format (as is this file, in fact). If you have Sphinx_ installed, you can regenerate these docs using::

make html

within the docs directory. Sphinx is the python-sphinx package on a Fedora/RHEL box.

.. _Sphinx: http://sphinx.pocoo.org/

More detailed documentation can be seen within docs/getting-involved.rst.

Enjoy! David Malcolm [email protected]

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].