GithubHelp home page GithubHelp logo

michicho / controlflow Goto Github PK

View Code? Open in Web Editor NEW

This project forked from toby1984/controlflow

0.0 1.0 0.0 1.64 MB

A tool that analyzes the byte-code of Java .class files and generates control-flow graphs in Graphviz (dot) format from it.

Home Page: http://www2.code-sourcery.de/blog/?p=23

License: Apache License 2.0

Java 100.00%

controlflow's Introduction

(C) 2013 [email protected]

This project actually contains two different applications:

  1. A tool for generating control-flow graphs from bytecode (conveniently packages as a self-executable JAR)

  2. (work-in-progress) A Java instrumentation agent that utilizes control-flow analysis to inject bytecode for counting the number of executed bytecode instructions per thread

screenshot

BUILDING

Requirements:

JDK 1.7 or higher Maven 2.2.1 or higher

Just run 'mvn clean package' and you should find a self-executable JAR named "controlflow.jar" inside the /target folder.

CREATING CONTROL-FLOW GRAPHS

First, install the fantastic Graphviz tool (http://www.graphviz.org/). On Linux systems, most distributions come with a package (probably named 'graphviz') that can be installed using the package manager.

Now we're ready to create some fancy graphs ! We'll try a simple test class first that is already included in the controlflow.jar.

Execute the following commands:

java -jar target/controlflow.jar -constructors -dir dot de.codesourcery.asm.TestClass

The tool does not generate control-flow graphs for constructors by default so I pass the '-constructors' option to include them. See below for a complete list of available command-line options.

You should now have a folder named 'dot' with the following files:

dot/init___V.dot dot/testMethod__Z_V.dot

Now use the graphviz tool to generate PNG files (graphviz also supports a host of other file formats) from them:

dot -O -Tpng dot/init___V.dot dot -O -Tpng dot/testMethod__Z_V.dot

The 'dot' folder should now also contain the PNG files:

dot/init___V.dot dot/init___V.dot.png dot/testMethod__Z_V.dot dot/testMethod__Z_V.dot.png

COMMAND-LINE OPTIONS

The control-flow grapher (self-executable JAR) supports the following command-line syntax:

Usage: [-debug] [-v] [-constructors] [-search ] [-match ] -dir

[-debug] => enable debug output [-v] => enable verbose output [-search => Substitute for JVM -classpath option since that one does not work with self-executable JARs -dir => outputs .dot files to this directory [-constructors] => include constructors in flow analysis [-match ] => only analyze methods whose name matches this regex => name of class to analyze

PROFILING AGENT

Note that this is very much WIP and I mostly used this as a sample application for my control-flow analysis.

CAVEAT: Do NOT use this on production systems ! I'm a novice at bytecode generation and didn't read very much of the JVM spec yet ...

The class transformation done by this Java agent is non-trivial because it is introducing new code at the start of each control block and not just at the start of each method...

  1. To run an instrumented example application

java "-javaagent:target/controlflow.jar=packages=TestClass;debugDir=tmp" -classpath target/controlflow.jar de.codesourcery.asm.profiling.TestApplication

Because of the 'debugDir' option, transformed classes will be written to ./tmp

  1. Create control-flow graphs in .dot format for transformed classes

java -jar target/controlflow.jar -constructors -search tmp -dir dot de.codesourcery.asm.TestClass

Files will be written to ./dot

  1. Create PNG from .dot file (requires graphviz to be installed)

dot -O -Tpng dot/testMethod__Z_V.dot

(this will generate dot/testMethod__Z_V.dot.png)

controlflow's People

Contributors

toby1984 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.