diff --git a/com.ibm.wala.core/src/com/ibm/wala/dataflow/IFDS/BackwardsSupergraph.java b/com.ibm.wala.core/src/com/ibm/wala/dataflow/IFDS/BackwardsSupergraph.java index 7352b225b..3d61c7e89 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/dataflow/IFDS/BackwardsSupergraph.java +++ b/com.ibm.wala.core/src/com/ibm/wala/dataflow/IFDS/BackwardsSupergraph.java @@ -18,6 +18,7 @@ import com.ibm.wala.util.collections.Iterator2Collection; import com.ibm.wala.util.debug.Assertions; import com.ibm.wala.util.debug.Trace; import com.ibm.wala.util.debug.UnimplementedError; +import com.ibm.wala.util.graph.Graph; import com.ibm.wala.util.intset.IntSet; /** @@ -29,7 +30,7 @@ import com.ibm.wala.util.intset.IntSet; * * @author sfink */ -public class BackwardsSupergraph implements ISupergraph { +public class BackwardsSupergraph implements ISupergraph { /** * DEBUG_LEVEL: @@ -40,26 +41,37 @@ public class BackwardsSupergraph implements ISupergraph { * */ static final int DEBUG_LEVEL = 0; - private final ISupergraph delegate; + + private final ISupergraph delegate; + private final ExitFilter exitFilter = new ExitFilter(); /** * @param forwardGraph - * the graph to ``reverse'' + * the graph to ``reverse'' */ - private BackwardsSupergraph(ISupergraph forwardGraph) { + private BackwardsSupergraph(ISupergraph forwardGraph) { this.delegate = forwardGraph; } - - public static BackwardsSupergraph make(ISupergraph forwardGraph) { + + public static BackwardsSupergraph make(ISupergraph forwardGraph) { return new BackwardsSupergraph(forwardGraph); } + /* + * TODO: for now, this is not inverted. + * + * @see com.ibm.wala.dataflow.IFDS.ISupergraph#getProcedureGraph() + */ + public Graph

getProcedureGraph() { + return delegate.getProcedureGraph(); + } + /* * @see com.ibm.wala.dataflow.IFDS.ISupergraph#getMain() */ public P getMain() throws UnsupportedOperationException { - throw new UnsupportedOperationException(); + return delegate.getMain(); } /* @@ -91,14 +103,15 @@ public class BackwardsSupergraph implements ISupergraph { public Iterator getCalledNodes(T ret) { if (DEBUG_LEVEL > 1) { Trace.println(getClass() + " getCalledNodes " + ret); - Trace.printCollection("called nodes ", Iterator2Collection.toCollection(new FilterIterator(getSuccNodes(ret), exitFilter))); + Trace.printCollection("called nodes ", Iterator2Collection.toCollection(new FilterIterator(getSuccNodes(ret), + exitFilter))); } return new FilterIterator(getSuccNodes(ret), exitFilter); } - + /** - * get the "normal" successors (sic) for a return site; i.e., the "normal" CFG predecessors - * that are not call nodes. + * get the "normal" successors (sic) for a return site; i.e., the "normal" CFG + * predecessors that are not call nodes. * * @see com.ibm.wala.dataflow.IFDS.ISupergraph#getCalledNodes(java.lang.Object) */ @@ -110,14 +123,14 @@ public class BackwardsSupergraph implements ISupergraph { return getProcOf(ret).equals(getProcOf((T) o)); } }; - Iterator sameProcPreds = new FilterIterator(allPreds,sameProc); + Iterator sameProcPreds = new FilterIterator(allPreds, sameProc); Filter notCall = new Filter() { @SuppressWarnings("unchecked") public boolean accepts(Object o) { return !delegate.isCall((T) o); } }; - return new FilterIterator(sameProcPreds,notCall); + return new FilterIterator(sameProcPreds, notCall); } /* @@ -202,10 +215,9 @@ public class BackwardsSupergraph implements ISupergraph { public Iterator getSuccNodes(T N) { return delegate.getPredNodes(N); } - - + public boolean hasEdge(T src, T dst) { - return delegate.hasEdge(dst,src); + return delegate.hasEdge(dst, src); } /* @@ -222,7 +234,7 @@ public class BackwardsSupergraph implements ISupergraph { public void addEdge(Object src, Object dst) throws UnsupportedOperationException { throw new UnsupportedOperationException(); } - + public void removeEdge(Object src, Object dst) throws UnsupportedOperationException { throw new UnsupportedOperationException(); } @@ -240,7 +252,7 @@ public class BackwardsSupergraph implements ISupergraph { public T[] getEntriesForProcedure(P object) { return delegate.getExitsForProcedure(object); } - + /* * @see com.ibm.wala.dataflow.IFDS.ISupergraph#getEntriesForProcedure(java.lang.Object) */ @@ -312,32 +324,33 @@ public class BackwardsSupergraph implements ISupergraph { public void removeIncomingEdges(Object node) throws UnsupportedOperationException { throw new UnsupportedOperationException(); - + } public void removeOutgoingEdges(T node) throws UnsupportedOperationException { throw new UnsupportedOperationException(); } - /* + /* * @see com.ibm.wala.dataflow.IFDS.ISupergraph#getNumberOfBlocks(java.lang.Object) */ public int getNumberOfBlocks(P procedure) { return delegate.getNumberOfBlocks(procedure); } - /* + /* * @see com.ibm.wala.dataflow.IFDS.ISupergraph#getLocalBlockNumber(java.lang.Object) */ public int getLocalBlockNumber(T n) { return delegate.getLocalBlockNumber(n); } - /* - * @see com.ibm.wala.dataflow.IFDS.ISupergraph#getLocalBlock(java.lang.Object, int) + /* + * @see com.ibm.wala.dataflow.IFDS.ISupergraph#getLocalBlock(java.lang.Object, + * int) */ public T getLocalBlock(P procedure, int i) { - return delegate.getLocalBlock(procedure,i); + return delegate.getLocalBlock(procedure, i); } public int getNumber(T N) { diff --git a/com.ibm.wala.core/src/com/ibm/wala/dataflow/IFDS/ISupergraph.java b/com.ibm.wala.core/src/com/ibm/wala/dataflow/IFDS/ISupergraph.java index 5be1bb922..7d697b6ae 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/dataflow/IFDS/ISupergraph.java +++ b/com.ibm.wala.core/src/com/ibm/wala/dataflow/IFDS/ISupergraph.java @@ -12,6 +12,7 @@ package com.ibm.wala.dataflow.IFDS; import java.util.Iterator; +import com.ibm.wala.util.graph.Graph; import com.ibm.wala.util.graph.NumberedGraph; /** @@ -45,6 +46,11 @@ public interface ISupergraph extends NumberedGraph { * @return an identifier for the main procedure for this supergraph */ P getMain(); + + /** + * @return the graph of procedures (e.g. a call graph) over which this supergraph is induced. + */ + Graph

getProcedureGraph(); /** * @param n diff --git a/com.ibm.wala.core/src/com/ibm/wala/dataflow/IFDS/PartiallyCollapsedSupergraph.java b/com.ibm.wala.core/src/com/ibm/wala/dataflow/IFDS/PartiallyCollapsedSupergraph.java index 930e54558..1db5ac422 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/dataflow/IFDS/PartiallyCollapsedSupergraph.java +++ b/com.ibm.wala.core/src/com/ibm/wala/dataflow/IFDS/PartiallyCollapsedSupergraph.java @@ -40,6 +40,7 @@ import com.ibm.wala.util.debug.Assertions; import com.ibm.wala.util.debug.Trace; import com.ibm.wala.util.debug.UnimplementedError; import com.ibm.wala.util.graph.AbstractGraph; +import com.ibm.wala.util.graph.Graph; import com.ibm.wala.util.graph.GraphIntegrity; import com.ibm.wala.util.graph.NumberedEdgeManager; import com.ibm.wala.util.graph.NumberedNodeManager; @@ -94,6 +95,10 @@ public class PartiallyCollapsedSupergraph extends AbstractGraph implemen return isEntry(o); } }; + + public Graph getProcedureGraph() { + return cg; + } /** * @param cg diff --git a/com.ibm.wala.core/src/com/ibm/wala/dataflow/IFDS/TabulationResult.java b/com.ibm.wala.core/src/com/ibm/wala/dataflow/IFDS/TabulationResult.java index d89df6673..e166a82ca 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/dataflow/IFDS/TabulationResult.java +++ b/com.ibm.wala.core/src/com/ibm/wala/dataflow/IFDS/TabulationResult.java @@ -21,7 +21,7 @@ import com.ibm.wala.util.intset.SparseIntSet; * * @author sfink */ -public interface TabulationResult { +public interface TabulationResult { /** * get the bitvector of facts that hold at the entry to a given node * @@ -33,7 +33,7 @@ public interface TabulationResult { /** * @return the governing IFDS problem */ - public TabulationProblem getProblem(); + public TabulationProblem getProblem(); /** * @return the set of supergraph nodes for which any fact is reached diff --git a/com.ibm.wala.core/src/com/ibm/wala/dataflow/IFDS/TabulationSolver.java b/com.ibm.wala.core/src/com/ibm/wala/dataflow/IFDS/TabulationSolver.java index d436c8a49..593675152 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/dataflow/IFDS/TabulationSolver.java +++ b/com.ibm.wala.core/src/com/ibm/wala/dataflow/IFDS/TabulationSolver.java @@ -67,7 +67,7 @@ public class TabulationSolver { *
  • 2 Detailed debugging * */ - protected static final int DEBUG_LEVEL = 0; + protected static final int DEBUG_LEVEL = 2; static protected final boolean verbose = true && ("true".equals(System.getProperty("com.ibm.wala.util.fixedpoint.impl.verbose")) ? true : false); @@ -208,7 +208,7 @@ public class TabulationSolver { * @return a representation of the result * @throws SolverInterruptedException */ - public TabulationResult solve() throws SolverInterruptedException { + public TabulationResult solve() throws SolverInterruptedException { EngineTimings.startVirtual("TabulationSolver.solve()"); EngineTimings.startVirtual("TabulationSolver.initialize"); @@ -604,12 +604,13 @@ public class TabulationSolver { reached.foreach(new IntSetAction() { public void act(int d1) { - // eagerly propagate 0 into the callee for fact d1. this is a - // heuristic intended - // to realize better order for merges - if (d1 != 0) { - propagate(callee, d1, callee, 0); - } + // This is buggy. Who says 0 always propagates? +// // eagerly propagate 0 into the callee for fact d1. this is a +// // heuristic intended +// // to realize better order for merges +// if (d1 != 0) { +// propagate(callee, d1, callee, 0); +// } propagate(callee, d1, callee, d1); // cache the fact that we've flowed -> by a // call flow @@ -970,7 +971,7 @@ public class TabulationSolver { /** * @author sfink */ - public class Result implements TabulationResult { + public class Result implements TabulationResult { /** * get the bitvector of facts that hold at the entry to a given node @@ -1050,7 +1051,7 @@ public class TabulationSolver { /* * @see com.ibm.wala.dataflow.IFDS.TabulationResult#getProblem() */ - public TabulationProblem getProblem() { + public TabulationProblem getProblem() { return problem; } diff --git a/com.ibm.wala.core/src/com/ibm/wala/ipa/cfg/BasicBlockInContext.java b/com.ibm.wala.core/src/com/ibm/wala/ipa/cfg/BasicBlockInContext.java index 952d6738a..5d68e637a 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/ipa/cfg/BasicBlockInContext.java +++ b/com.ibm.wala.core/src/com/ibm/wala/ipa/cfg/BasicBlockInContext.java @@ -116,7 +116,7 @@ public final class BasicBlockInContext extends NodeWit @Override public String toString() { - return delegate.toString() + "(node:" + node.getGraphNodeId() + ")"; + return delegate.toString(); } } diff --git a/com.ibm.wala.core/src/com/ibm/wala/ipa/slicer/SDGSupergraph.java b/com.ibm.wala.core/src/com/ibm/wala/ipa/slicer/SDGSupergraph.java index 0f5a06199..bafe8a9e3 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/ipa/slicer/SDGSupergraph.java +++ b/com.ibm.wala.core/src/com/ibm/wala/ipa/slicer/SDGSupergraph.java @@ -23,6 +23,7 @@ import com.ibm.wala.util.collections.Filter; import com.ibm.wala.util.collections.FilterIterator; import com.ibm.wala.util.collections.IteratorUtil; import com.ibm.wala.util.debug.Assertions; +import com.ibm.wala.util.graph.Graph; import com.ibm.wala.util.intset.IntSet; import com.ibm.wala.util.intset.SparseIntSet; @@ -50,6 +51,11 @@ class SDGSupergraph implements ISupergraph { this.srcStatement = src; this.backward = backward; } + + public Graph getProcedureGraph() { + Assertions.UNREACHABLE(); + return null; + } public Object[] getEntry(Statement n) { Assertions.UNREACHABLE(); diff --git a/com.ibm.wala.core/src/com/ibm/wala/ipa/slicer/Slicer.java b/com.ibm.wala.core/src/com/ibm/wala/ipa/slicer/Slicer.java index e9b1d7286..c133a506c 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/ipa/slicer/Slicer.java +++ b/com.ibm.wala.core/src/com/ibm/wala/ipa/slicer/Slicer.java @@ -227,7 +227,7 @@ public class Slicer { } TabulationSolver solver = TabulationSolver.make(p); - TabulationResult tr = null; + TabulationResult tr = null; try { tr = solver.solve(); } catch (SolverInterruptedException e) { @@ -371,7 +371,7 @@ public class Slicer { * Convert the results of the tabulation to a slice, represented as a * Collection */ - private static Collection result2Slice(final TabulationResult result) { + private static Collection result2Slice(final TabulationResult result) { return result.getSupergraphNodesReached(); // final Collection nodes = new // Iterator2Collection(sdg.iterateLazyNodes()); diff --git a/com.ibm.wala.core/src/com/ibm/wala/viz/DotUtil.java b/com.ibm.wala.core/src/com/ibm/wala/viz/DotUtil.java index db55a428c..5f118fa92 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/viz/DotUtil.java +++ b/com.ibm.wala.core/src/com/ibm/wala/viz/DotUtil.java @@ -30,12 +30,13 @@ import com.ibm.wala.util.warnings.WalaException; * */ public class DotUtil { + + /** + * Recent versions of dot appear to croak on long labels. Sigh. + */ + private final static int MAX_LABEL_LENGTH = 75; /** - * @param g - * @param labels - * @throws WalaException - * @throws IllegalArgumentException if g is null */ public static void dotify(Graph g, NodeDecorator labels, String dotFile, String psFile, String dotExe) throws WalaException { if (g == null) { @@ -283,12 +284,17 @@ public class DotUtil { // } // private static String getLabel(Object o, NodeDecorator d) throws WalaException { + String result = null; if (d == null) { - return o.toString(); + result = o.toString(); } else { - String result = d.getLabel(o); - return result == null ? o.toString() : result; + result = d.getLabel(o); + result = result == null ? o.toString() : result; } + if (result.length() >= MAX_LABEL_LENGTH) { + result = result.substring(0, MAX_LABEL_LENGTH - 3) + "..."; + } + return result; } private static String getPort(Object o, NodeDecorator d) throws WalaException { diff --git a/com.ibm.wala.core/src/com/ibm/wala/viz/GhostviewUtil.java b/com.ibm.wala.core/src/com/ibm/wala/viz/GhostviewUtil.java index 61a9e4595..37a944400 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/viz/GhostviewUtil.java +++ b/com.ibm.wala.core/src/com/ibm/wala/viz/GhostviewUtil.java @@ -92,8 +92,6 @@ public class GhostviewUtil { } /** - * @author sfink - * * A node decorator which concatenates the labels from two other node * decorators */ diff --git a/com.ibm.wala.core/src/com/ibm/wala/viz/IFDSExplorer.java b/com.ibm.wala.core/src/com/ibm/wala/viz/IFDSExplorer.java index aa3979b5a..e6b8da7da 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/viz/IFDSExplorer.java +++ b/com.ibm.wala.core/src/com/ibm/wala/viz/IFDSExplorer.java @@ -15,31 +15,25 @@ import java.util.Collection; import java.util.Properties; import com.ibm.wala.dataflow.IFDS.TabulationResult; -import com.ibm.wala.ipa.callgraph.CGNode; -import com.ibm.wala.ipa.callgraph.CallGraph; -import com.ibm.wala.ipa.cfg.BasicBlockInContext; import com.ibm.wala.properties.WalaProperties; -import com.ibm.wala.ssa.ISSABasicBlock; import com.ibm.wala.util.debug.Assertions; import com.ibm.wala.util.debug.Trace; +import com.ibm.wala.util.graph.Graph; import com.ibm.wala.util.graph.InferGraphRoots; -import com.ibm.wala.util.intset.IntSet; import com.ibm.wala.util.warnings.WalaException; /** - * Explore the result of an IFDS problem with an SWT viewer and - * ghostview. + * Explore the result of an IFDS problem with an SWT viewer and ghostview. * * @author Stephen Fink */ -public class IFDSExplorer { +public class IFDSExplorer { /** * absolute path name to invoke dot */ protected static String dotExe = null; - /** * Absolute path name to invoke ghostview */ @@ -53,19 +47,23 @@ public class IFDSExplorer { gvExe = newGvExe; } - public static void viewIFDS(CallGraph cg, TabulationResult r) throws WalaException { - + /** + * We pass in the supergraph to allow viewing of a forward supergraph with the results of a backwards problem. + */ + public static void viewIFDS(TabulationResult r) throws WalaException { + if (r == null) { throw new IllegalArgumentException("r is null"); } assert gvExe != null; assert dotExe != null; - + // dump the domain to stderr System.err.println("Domain:\n" + r.getProblem().getDomain().toString()); Trace.println("Domain:\n" + r.getProblem().getDomain().toString()); - - Properties p = null;; + + Properties p = null; + ; try { p = WalaProperties.loadProperties(); } catch (WalaException e) { @@ -76,29 +74,14 @@ public class IFDSExplorer { String dotFile = p.getProperty(WalaProperties.OUTPUT_DIR) + File.separatorChar + "ir.dt"; final SWTTreeViewer v = new SWTTreeViewer(); - v.setGraphInput(cg); + Graph

    g = r.getProblem().getSupergraph().getProcedureGraph(); + v.setGraphInput(g); v.setBlockInput(true); - Collection roots = InferGraphRoots.inferRoots(cg); + Collection

    roots = InferGraphRoots.inferRoots(g); v.setRootsInput(roots); - v.getPopUpActions().add(new ViewAnnotatedIRAction(v,cg,psFile,dotFile,dotExe,gvExe, new IFDSAnnotator(r))); + v.getPopUpActions().add(new ViewIFDSLocalAction(v, r, psFile, dotFile, dotExe, gvExe)); v.run(); } - - private final static class IFDSAnnotator extends BasicBlockDecorator { - final private TabulationResult r; - public IFDSAnnotator(TabulationResult r) { - this.r = r; - } - @SuppressWarnings("unchecked") - public String getLabel(Object o) throws WalaException { - ISSABasicBlock bb = (ISSABasicBlock)o; - Object b = new BasicBlockInContext(getCurrentNode(),bb); - IntSet result = r.getResult(b); - String label = result == null ? "no result" : result.toString(); - return label + "\\n-----\\n"; - } - - } public static String getDotExe() { return dotExe; diff --git a/com.ibm.wala.core/src/com/ibm/wala/viz/SWTTreeViewer.java b/com.ibm.wala.core/src/com/ibm/wala/viz/SWTTreeViewer.java index cb800ef53..e601c9f26 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/viz/SWTTreeViewer.java +++ b/com.ibm.wala.core/src/com/ibm/wala/viz/SWTTreeViewer.java @@ -15,6 +15,7 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.List; +import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.ITreeContentProvider; @@ -70,7 +71,7 @@ public class SWTTreeViewer extends EJfaceApplicationRunner { * @generated * @ordered */ - final protected List popUpActions = new LinkedList(); + final protected List popUpActions = new LinkedList(); /** * @@ -132,7 +133,7 @@ public class SWTTreeViewer extends EJfaceApplicationRunner { * * @generated */ - public List getPopUpActions() { + public List getPopUpActions() { return popUpActions; } @@ -236,7 +237,7 @@ public class SWTTreeViewer extends EJfaceApplicationRunner { if (getPopUpActions().size() > 0) { MenuManager mm = new MenuManager(); treeViewer.getTree().setMenu(mm.createContextMenu(treeViewer.getTree())); - for (Iterator it = getPopUpActions().iterator(); it.hasNext(); ) { + for (Iterator it = getPopUpActions().iterator(); it.hasNext(); ) { mm.add(it.next()); } }