use of soot.Body in project soot by Sable.
the class UnitThrowAnalysis method mightThrow.
/**
* Returns the set of types that might be thrown as a result of
* calling the specified method.
*
* @param sm method whose exceptions are to be returned.
* @param doneSet The set of methods that were already processed
*
* @return a representation of the set of {@link
* java.lang.Throwable Throwable} types that <code>m</code> might
* throw.
*/
private ThrowableSet mightThrow(SootMethod sm, Set<SootMethod> doneSet) {
// Do not run in loops
if (!doneSet.add(sm))
return ThrowableSet.Manager.v().EMPTY;
// unsound, but would otherwise always bloat our result set.
if (!sm.hasActiveBody())
return ThrowableSet.Manager.v().EMPTY;
// We need a mapping between unit and exception
final PatchingChain<Unit> units = sm.getActiveBody().getUnits();
Map<Unit, Collection<Trap>> unitToTraps = sm.getActiveBody().getTraps().isEmpty() ? null : new HashMap<Unit, Collection<Trap>>();
for (Trap t : sm.getActiveBody().getTraps()) {
for (Iterator<Unit> unitIt = units.iterator(t.getBeginUnit(), units.getPredOf(t.getEndUnit())); unitIt.hasNext(); ) {
Unit unit = unitIt.next();
Collection<Trap> unitsForTrap = unitToTraps.get(unit);
if (unitsForTrap == null) {
unitsForTrap = new ArrayList<Trap>();
unitToTraps.put(unit, unitsForTrap);
}
unitsForTrap.add(t);
}
}
ThrowableSet methodSet = ThrowableSet.Manager.v().EMPTY;
if (sm.hasActiveBody()) {
Body methodBody = sm.getActiveBody();
for (Unit u : methodBody.getUnits()) {
if (u instanceof Stmt) {
Stmt stmt = (Stmt) u;
ThrowableSet curStmtSet;
if (stmt.containsInvokeExpr()) {
InvokeExpr inv = stmt.getInvokeExpr();
curStmtSet = mightThrow(inv.getMethod(), doneSet);
} else
curStmtSet = mightThrow(u);
// The exception might be caught along the way
if (unitToTraps != null) {
Collection<Trap> trapsForUnit = unitToTraps.get(stmt);
if (trapsForUnit != null)
for (Trap t : trapsForUnit) {
Pair p = curStmtSet.whichCatchableAs(t.getException().getType());
curStmtSet = curStmtSet.remove(p.getCaught());
}
}
methodSet = methodSet.add(curStmtSet);
}
}
}
return methodSet;
}
use of soot.Body in project soot by Sable.
the class CFGGraphType method loadAltGraph.
private static DirectedGraph loadAltGraph(String className, Body b) {
try {
Class<?> graphClass = AltClassLoader.v().loadClass(className);
Class<?>[] paramTypes = new Class[] { Body.class };
Constructor constructor = graphClass.getConstructor(paramTypes);
DirectedGraph result = (DirectedGraph) constructor.newInstance(new Object[] { b });
return result;
}// don't need to declare them: perhaps a shoddy tactic.
catch (ClassNotFoundException e) {
if (DEBUG) {
logger.error(e.getMessage(), e);
}
throw new IllegalArgumentException("Unable to find " + className + " in alternate classpath: " + e.getMessage());
} catch (NoSuchMethodException e) {
if (DEBUG) {
logger.error(e.getMessage(), e);
}
throw new IllegalArgumentException("There is no " + className + "(Body) constructor: " + e.getMessage());
} catch (InstantiationException e) {
if (DEBUG) {
logger.error(e.getMessage(), e);
}
throw new IllegalArgumentException("Unable to instantiate " + className + " in alternate classpath: " + e.getMessage());
} catch (IllegalAccessException e) {
if (DEBUG) {
logger.error(e.getMessage(), e);
}
throw new IllegalArgumentException("Unable to access " + className + "(Body) in alternate classpath: " + e.getMessage());
} catch (InvocationTargetException e) {
if (DEBUG) {
logger.error(e.getMessage(), e);
}
throw new IllegalArgumentException("Unable to invoke " + className + "(Body) in alternate classpath: " + e.getMessage());
}
}
use of soot.Body in project soot by Sable.
the class RunVeryBusyAnalysis method main.
public static void main(String[] args) {
args = new String[] { "testers.VeryBusyClass" };
if (args.length == 0) {
System.out.println("Usage: java RunVeryBusyAnalysis class_to_analyse");
System.exit(0);
}
String sep = File.separator;
String pathSep = File.pathSeparator;
String path = System.getProperty("java.home") + sep + "lib" + sep + "rt.jar";
path += pathSep + "." + sep + "tutorial" + sep + "guide" + sep + "examples" + sep + "analysis_framework" + sep + "src";
Options.v().set_soot_classpath(path);
SootClass sClass = Scene.v().loadClassAndSupport(args[0]);
sClass.setApplicationClass();
Scene.v().loadNecessaryClasses();
for (SootMethod m : sClass.getMethods()) {
Body b = m.retrieveActiveBody();
System.out.println("=======================================");
System.out.println(m.toString());
UnitGraph graph = new ExceptionalUnitGraph(b);
VeryBusyExpressions vbe = new SimpleVeryBusyExpressions(graph);
for (Unit u : graph) {
List<AbstractBinopExpr> before = vbe.getBusyExpressionsBefore(u);
List<AbstractBinopExpr> after = vbe.getBusyExpressionsAfter(u);
UnitPrinter up = new NormalUnitPrinter(b);
up.setIndent("");
System.out.println("---------------------------------------");
u.toString(up);
System.out.println(up.output());
System.out.print("Busy in: {");
sep = "";
for (AbstractBinopExpr e : before) {
System.out.print(sep);
System.out.print(e.toString());
sep = ", ";
}
System.out.println("}");
System.out.print("Busy out: {");
sep = "";
for (AbstractBinopExpr e : after) {
System.out.print(sep);
System.out.print(e.toString());
sep = ", ";
}
System.out.println("}");
System.out.println("---------------------------------------");
}
System.out.println("=======================================");
}
}
use of soot.Body in project soot by Sable.
the class GraphComparer method makeUnitPrinter.
/**
* Utility method that returns a {@link LabeledUnitPrinter} for printing
* the {@link Unit}s in graph.
*
* @param g the graph for which to return a {@link LabeledUnitPrinter}.
* @return A {@link LabeledUnitPrinter} for printing the {@link Unit}s in
* <tt>g</tt> if <tt>g</tt> is a control flow graph. Returns
* <tt>null</tt> if <tt>g</tt> is not a control flow graph.
*/
private static LabeledUnitPrinter makeUnitPrinter(DirectedGraph g) {
Body b = getGraphsBody(g);
if (b == null) {
return null;
} else {
BriefUnitPrinter printer = new BriefUnitPrinter(b);
printer.noIndent();
return printer;
}
}
use of soot.Body in project soot by Sable.
the class MyMain method main.
public static void main(String[] args) {
PackManager.v().getPack("jtp").add(new Transform("jtp.myTransform", new BodyTransformer() {
protected void internalTransform(Body body, String phase, Map options) {
new MyAnalysis(new ExceptionalUnitGraph(body));
// use G.v().out instead of System.out so that Soot can
// redirect this output to the Eclipse console
G.v().out.println(body.getMethod());
}
}));
soot.Main.main(args);
}
Aggregations