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!!!");
}
}
}
}
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());
}
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;
}
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;
}
}
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());
}
}
}
Aggregations