Search in sources :

Example 1 with DotGraph

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

the class CFGToDotGraph method drawCFG.

/**
 * Create a <code>DotGraph</code> whose nodes and edges depict the
 * control flow in a <code>ExceptionalGraph</code>, with
 * distinguished edges for exceptional control flow.
 *
 * @param graph the control flow graph
 *
 * @return a visualization of <code>graph</code>.
 */
public <N> DotGraph drawCFG(ExceptionalGraph<N> graph) {
    Body body = graph.getBody();
    DotGraph canvas = initDotGraph(body);
    DotNamer namer = new DotNamer((int) (graph.size() / 0.7f), 0.7f);
    NodeComparator nodeComparator = new NodeComparator(namer);
    // comparisons between graphs of a given method.
    for (Iterator<N> nodesIt = graph.iterator(); nodesIt.hasNext(); ) {
        namer.getName(nodesIt.next());
    }
    for (Iterator<N> nodesIt = graph.iterator(); nodesIt.hasNext(); ) {
        N node = nodesIt.next();
        canvas.drawNode(namer.getName(node));
        for (Iterator<N> succsIt = sortedIterator(graph.getUnexceptionalSuccsOf(node), nodeComparator); succsIt.hasNext(); ) {
            N succ = succsIt.next();
            DotGraphEdge edge = canvas.drawEdge(namer.getName(node), namer.getName(succ));
            edge.setAttribute(unexceptionalControlFlowAttr);
        }
        for (Iterator<N> succsIt = sortedIterator(graph.getExceptionalSuccsOf(node), nodeComparator); succsIt.hasNext(); ) {
            N succ = succsIt.next();
            DotGraphEdge edge = canvas.drawEdge(namer.getName(node), namer.getName(succ));
            edge.setAttribute(exceptionalControlFlowAttr);
        }
        if (showExceptions) {
            for (Iterator<ExceptionDest<N>> destsIt = sortedIterator(graph.getExceptionDests(node), new ExceptionDestComparator(namer)); destsIt.hasNext(); ) {
                ExceptionDest<N> dest = destsIt.next();
                Object handlerStart = dest.getHandlerNode();
                if (handlerStart == null) {
                    // Giving each escaping exception its own, invisible
                    // exceptional exit node produces a less cluttered
                    // graph.
                    handlerStart = new Object() {

                        public String toString() {
                            return "Esc";
                        }
                    };
                    DotGraphNode escapeNode = canvas.drawNode(namer.getName(handlerStart));
                    escapeNode.setStyle(DotGraphConstants.NODE_STYLE_INVISIBLE);
                }
                DotGraphEdge edge = canvas.drawEdge(namer.getName(node), namer.getName(handlerStart));
                edge.setAttribute(exceptionEdgeAttr);
                edge.setLabel(formatThrowableSet(dest.getThrowables()));
            }
        }
    }
    setStyle(graph.getHeads(), canvas, namer, DotGraphConstants.NODE_STYLE_FILLED, headAttr);
    setStyle(graph.getTails(), canvas, namer, DotGraphConstants.NODE_STYLE_FILLED, tailAttr);
    if (!isBrief) {
        formatNodeText(graph.getBody(), canvas, namer);
    }
    return canvas;
}
Also used : ExceptionDest(soot.toolkits.graph.ExceptionalGraph.ExceptionDest) DotGraphEdge(soot.util.dot.DotGraphEdge) DotGraph(soot.util.dot.DotGraph) DotGraphNode(soot.util.dot.DotGraphNode)

Example 2 with DotGraph

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

the class CFGToDotGraph method drawCFG.

/**
 * Create a <code>DotGraph</code> whose nodes and edges depict
 * a control flow graph without distinguished
 * exceptional edges.
 *
 * @param graph a <code>DirectedGraph</code> representing a CFG
 *              (probably an instance of {@link UnitGraph}, {@link BlockGraph},
 *              or one of their subclasses).
 *
 * @param body the <code>Body</code> represented by <code>graph</code> (used
 * to format the text within nodes).  If no body is available, pass
 * <code>null</code>.
 *
 * @return a visualization of <code>graph</code>.
 */
public <N> DotGraph drawCFG(DirectedGraph<N> graph, Body body) {
    DotGraph canvas = initDotGraph(body);
    DotNamer<N> namer = new DotNamer<N>((int) (graph.size() / 0.7f), 0.7f);
    NodeComparator<N> comparator = new NodeComparator<N>(namer);
    // to have the same label in different graphs of a given method).
    for (Iterator<N> nodesIt = graph.iterator(); nodesIt.hasNext(); ) {
        namer.getName(nodesIt.next());
    }
    for (Iterator<N> nodesIt = graph.iterator(); nodesIt.hasNext(); ) {
        N node = nodesIt.next();
        canvas.drawNode(namer.getName(node));
        for (Iterator<N> succsIt = sortedIterator(graph.getSuccsOf(node), comparator); succsIt.hasNext(); ) {
            N succ = succsIt.next();
            canvas.drawEdge(namer.getName(node), namer.getName(succ));
        }
    }
    setStyle(graph.getHeads(), canvas, namer, DotGraphConstants.NODE_STYLE_FILLED, headAttr);
    setStyle(graph.getTails(), canvas, namer, DotGraphConstants.NODE_STYLE_FILLED, tailAttr);
    if (!isBrief) {
        formatNodeText(body, canvas, namer);
    }
    return canvas;
}
Also used : DotGraph(soot.util.dot.DotGraph)

Example 3 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
 * ExceptionalGraph} if the current phase is being dumped.
 *
 * @param g the graph to dump.
 */
public void dumpGraph(ExceptionalGraph g) {
    if (alreadyDumping) {
        return;
    }
    try {
        alreadyDumping = true;
        String phaseName = phaseStack.currentPhase();
        if (isCFGDumpingPhase(phaseName)) {
            try {
                String outputFile = nextGraphFileName(g.getBody(), phaseName + "-" + getClassIdent(g) + "-");
                CFGToDotGraph drawer = new CFGToDotGraph();
                drawer.setShowExceptions(Options.v().show_exception_dests());
                DotGraph dotGraph = drawer.drawCFG(g);
                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 4 with DotGraph

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

the class CFGViewer method print_cfg.

protected void print_cfg(Body body) {
    DirectedGraph<Unit> graph = graphtype.buildGraph(body);
    DotGraph canvas = graphtype.drawGraph(drawer, graph, body);
    String methodname = body.getMethod().getSubSignature();
    String classname = body.getMethod().getDeclaringClass().getName().replaceAll("\\$", "\\.");
    String filename = soot.SourceLocator.v().getOutputDir();
    if (filename.length() > 0) {
        filename = filename + java.io.File.separator;
    }
    filename = filename + classname + " " + methodname.replace(java.io.File.separatorChar, '.') + DotGraph.DOT_EXTENSION;
    logger.debug("Generate dot file in " + filename);
    canvas.plot(filename);
}
Also used : DotGraph(soot.util.dot.DotGraph) CFGToDotGraph(soot.util.cfgcmd.CFGToDotGraph) Unit(soot.Unit)

Example 5 with DotGraph

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

the class AbstractInterproceduralAnalysis method drawAsOneDot.

/**
 * Dump the interprocedural analysis result as a graph. One node / subgraph
 * for each analysed method that contains the method summary, and call-to
 * edges.
 *
 * Note: this graph does not show filtered-out methods for which a
 * conservative summary was asked via summaryOfUnanalysedMethod.
 *
 * @param name output filename
 *
 * @see fillDotGraph
 */
public void drawAsOneDot(String name) {
    DotGraph dot = new DotGraph(name);
    dot.setGraphLabel(name);
    dot.setGraphAttribute("compound", "true");
    // dot.setGraphAttribute("rankdir","LR");
    int id = 0;
    Map<SootMethod, Integer> idmap = new HashMap<SootMethod, Integer>();
    // draw sub-graph cluster
    for (SootMethod m : dg) {
        DotGraph sub = dot.createSubGraph("cluster" + id);
        DotGraphNode label = sub.drawNode("head" + id);
        idmap.put(m, id);
        sub.setGraphLabel("");
        label.setLabel("(" + order.get(m) + ") " + m.toString());
        label.setAttribute("fontsize", "18");
        label.setShape("box");
        if (data.containsKey(m)) {
            fillDotGraph("X" + id, data.get(m), sub);
        }
        id++;
    }
    // connect edges
    for (SootMethod m : dg) {
        for (SootMethod mm : dg.getSuccsOf(m)) {
            DotGraphEdge edge = dot.drawEdge("head" + idmap.get(m), "head" + idmap.get(mm));
            edge.setAttribute("ltail", "cluster" + idmap.get(m));
            edge.setAttribute("lhead", "cluster" + idmap.get(mm));
        }
    }
    File f = new File(SourceLocator.v().getOutputDir(), name + DotGraph.DOT_EXTENSION);
    dot.plot(f.getPath());
}
Also used : DotGraphEdge(soot.util.dot.DotGraphEdge) DotGraph(soot.util.dot.DotGraph) SootMethod(soot.SootMethod) DotGraphNode(soot.util.dot.DotGraphNode) 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