Search in sources :

Example 6 with DotGraph

use of soot.util.dot.DotGraph in project soot by Sable.

the class AbstractInterproceduralAnalysis method doAnalysis.

/**
 * Carry out the analysis.
 *
 * Call this from your InterproceduralAnalysis constructor, just after
 * super(cg). Then , you will be able to call drawAsDot, for instance.
 *
 * @param verbose
 */
protected void doAnalysis(boolean verbose) {
    // queue class
    class IntComparator implements Comparator<SootMethod> {

        @Override
        public int compare(SootMethod o1, SootMethod o2) {
            return order.get(o1) - order.get(o2);
        }
    }
    SortedSet<SootMethod> queue = new TreeSet<SootMethod>(new IntComparator());
    // init
    for (SootMethod o : order.keySet()) {
        data.put(o, newInitialSummary());
        queue.add(o);
    }
    // only for debug pretty-printing
    Map<SootMethod, Integer> nb = new HashMap<SootMethod, Integer>();
    // fixpoint iterations
    while (!queue.isEmpty()) {
        SootMethod m = queue.first();
        queue.remove(m);
        S newSummary = newInitialSummary();
        S oldSummary = data.get(m);
        if (nb.containsKey(m)) {
            nb.put(m, nb.get(m) + 1);
        } else {
            nb.put(m, 1);
        }
        if (verbose) {
            logger.debug(" |- processing " + m.toString() + " (" + nb.get(m) + "-st time)");
        }
        analyseMethod(m, newSummary);
        if (!oldSummary.equals(newSummary)) {
            // summary for m changed!
            data.put(m, newSummary);
            queue.addAll(dg.getPredsOf(m));
        }
    }
    // fixpoint verification
    if (doCheck) {
        for (SootMethod m : order.keySet()) {
            S newSummary = newInitialSummary();
            S oldSummary = data.get(m);
            analyseMethod(m, newSummary);
            if (!oldSummary.equals(newSummary)) {
                logger.debug("inter-procedural fixpoint not reached for method " + m.toString());
                DotGraph gm = new DotGraph("false_fixpoint");
                DotGraph gmm = new DotGraph("next_iterate");
                gm.setGraphLabel("false fixpoint: " + m.toString());
                gmm.setGraphLabel("fixpoint next iterate: " + m.toString());
                fillDotGraph("", oldSummary, gm);
                fillDotGraph("", newSummary, gmm);
                gm.plot(m.toString() + "_false_fixpoint.dot");
                gmm.plot(m.toString() + "_false_fixpoint_next.dot");
                throw new Error("AbstractInterproceduralAnalysis sanity check failed!!!");
            }
        }
    }
}
Also used : DotGraph(soot.util.dot.DotGraph) SootMethod(soot.SootMethod)

Example 7 with DotGraph

use of soot.util.dot.DotGraph in project soot by Sable.

the class PurityIntraproceduralAnalysis method drawAsOneDot.

/**
 * Draw the result of the intra-procedural analysis as one big dot file,
 * named className.methodName.dot, containing one purity graph for each
 * statement in the method.
 *
 * @param prefix
 * @param name
 */
public void drawAsOneDot(String prefix, String name) {
    DotGraph dot = new DotGraph(name);
    dot.setGraphLabel(name);
    dot.setGraphAttribute("compound", "true");
    dot.setGraphAttribute("rankdir", "LR");
    Map<Unit, Integer> node = new HashMap<Unit, Integer>();
    int id = 0;
    for (Unit stmt : graph) {
        PurityGraphBox ref = getFlowAfter(stmt);
        DotGraph sub = dot.createSubGraph("cluster" + id);
        DotGraphNode label = sub.drawNode("head" + id);
        String lbl = stmt.toString();
        if (lbl.startsWith("lookupswitch")) {
            lbl = "lookupswitch...";
        }
        if (lbl.startsWith("tableswitch")) {
            lbl = "tableswitch...";
        }
        sub.setGraphLabel(" ");
        label.setLabel(lbl);
        label.setAttribute("fontsize", "18");
        label.setShape("box");
        ref.g.fillDotGraph("X" + id, sub);
        node.put(stmt, id);
        id++;
    }
    for (Unit src : graph) {
        for (Unit dst : graph.getSuccsOf(src)) {
            DotGraphEdge edge = dot.drawEdge("head" + node.get(src), "head" + node.get(dst));
            edge.setAttribute("ltail", "cluster" + node.get(src));
            edge.setAttribute("lhead", "cluster" + node.get(dst));
        }
    }
    File f = new File(SourceLocator.v().getOutputDir(), prefix + name + DotGraph.DOT_EXTENSION);
    dot.plot(f.getPath());
}
Also used : HashMap(java.util.HashMap) DotGraphEdge(soot.util.dot.DotGraphEdge) DotGraph(soot.util.dot.DotGraph) DotGraphNode(soot.util.dot.DotGraphNode) File(java.io.File)

Example 8 with DotGraph

use of soot.util.dot.DotGraph in project soot by Sable.

the class CFGToDotGraph method initDotGraph.

/**
 * A utility method that initializes a DotGraph object for use in any
 * variety of drawCFG().
 *
 * @param body The <code>Body</code> that the graph will represent
 *		 (used in the graph's title).  If no <code>Body</code>
 *             is available, pass <code>null</code>.
 *
 * @return a <code>DotGraph</code> for visualizing <code>body</code>.
 */
private DotGraph initDotGraph(Body body) {
    String graphname = "cfg";
    if (body != null) {
        graphname = body.getMethod().getSubSignature();
    }
    DotGraph canvas = new DotGraph(graphname);
    canvas.setGraphLabel(graphname);
    if (!onePage) {
        canvas.setPageSize(8.5, 11.0);
    }
    if (isBrief) {
        canvas.setNodeShape(DotGraphConstants.NODE_SHAPE_CIRCLE);
    } else {
        canvas.setNodeShape(DotGraphConstants.NODE_SHAPE_BOX);
    }
    return canvas;
}
Also used : DotGraph(soot.util.dot.DotGraph)

Example 9 with DotGraph

use of soot.util.dot.DotGraph in project soot by Sable.

the class PhaseDumper method dumpGraph.

/**
 * Asks the <code>PhaseDumper</code> to dump the passed {@link
 * DirectedGraph} if the current phase is being dumped.
 *
 * @param g the graph to dump.
 *
 * @param body the {@link Body} represented by <code>g</code>.
 */
public void dumpGraph(DirectedGraph g, Body b) {
    if (alreadyDumping) {
        return;
    }
    try {
        alreadyDumping = true;
        String phaseName = phaseStack.currentPhase();
        if (isCFGDumpingPhase(phaseName)) {
            try {
                String outputFile = nextGraphFileName(b, phaseName + "-" + getClassIdent(g) + "-");
                DotGraph dotGraph = new CFGToDotGraph().drawCFG(g, b);
                dotGraph.plot(outputFile);
            } catch (java.io.IOException e) {
                // Don't abort execution because of an I/O error, but
                // report the error.
                logger.debug("PhaseDumper.dumpBody() caught: " + e.toString());
                logger.error(e.getMessage(), e);
            }
        }
    } finally {
        alreadyDumping = false;
    }
}
Also used : CFGToDotGraph(soot.util.cfgcmd.CFGToDotGraph) DotGraph(soot.util.dot.DotGraph) CFGToDotGraph(soot.util.cfgcmd.CFGToDotGraph)

Example 10 with DotGraph

use of soot.util.dot.DotGraph in project soot by Sable.

the class AbstractInterproceduralAnalysis method drawAsManyDot.

/**
 * Dump the each summary computed by the interprocedural analysis as a
 * separate graph.
 *
 * @param prefix         is prepended before method name in output filename
 * @param drawUnanalysed do you also want info for the unanalysed methods
 *                       required by the analysis via
 *                       summaryOfUnanalysedMethod ?
 *
 * @see fillDotGraph
 */
public void drawAsManyDot(String prefix, boolean drawUnanalysed) {
    for (SootMethod m : data.keySet()) {
        DotGraph dot = new DotGraph(m.toString());
        dot.setGraphLabel(m.toString());
        fillDotGraph("X", data.get(m), dot);
        File f = new File(SourceLocator.v().getOutputDir(), prefix + m.toString() + DotGraph.DOT_EXTENSION);
        dot.plot(f.getPath());
    }
    if (drawUnanalysed) {
        for (SootMethod m : unanalysed.keySet()) {
            DotGraph dot = new DotGraph(m.toString());
            dot.setGraphLabel(m.toString() + " (unanalysed)");
            fillDotGraph("X", unanalysed.get(m), dot);
            File f = new File(SourceLocator.v().getOutputDir(), prefix + m.toString() + "_u" + DotGraph.DOT_EXTENSION);
            dot.plot(f.getPath());
        }
    }
}
Also used : DotGraph(soot.util.dot.DotGraph) SootMethod(soot.SootMethod) File(java.io.File)

Aggregations

DotGraph (soot.util.dot.DotGraph)10 File (java.io.File)3 SootMethod (soot.SootMethod)3 CFGToDotGraph (soot.util.cfgcmd.CFGToDotGraph)3 DotGraphEdge (soot.util.dot.DotGraphEdge)3 DotGraphNode (soot.util.dot.DotGraphNode)3 HashMap (java.util.HashMap)1 Unit (soot.Unit)1 ExceptionDest (soot.toolkits.graph.ExceptionalGraph.ExceptionDest)1