[Soot-list] Soot beginner having issues

Eric Bodden eric.bodden at ec-spride.de
Thu Jan 24 04:16:24 EST 2013


Hi.

Have you tried to use a debugger? Should be easy to find that way...

Eric

On 24 January 2013 02:12, Tomer Arazy <tomerarazy at gmail.com> wrote:
> As part of a school project I'm trying to implement Reaching Definitions
> Analysis (yes, I know Soot Already have one).
> When i'm running the analysis directly using
> Scene.v().loadClassAndSupport("Test.TestClass") it works fine.
> But when i'm trying to run the analysis in the "jtp" phase it seems it
> doesn't get pass the ReachingDefintionAnalysis "super" constructor.
> I'm running it as described in this tutorial:
> http://www.bodden.de/2008/09/22/soot-intra/
>
> I've trying to fix this for hours to but I have no clue what I'm doing
> wrong...
>
>
> I have the following files - all of them have the necessary imports and the
> Soot class path is set correctly.
> Main.java :
>
> public class 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)
> {
>               G.v().out.println("[" + body.getMethod().getName() +
>                                  "]     Constructing
> ReachingDefenitions...");
>               BriefUnitGraph graph = new BriefUnitGraph(body);
>               ReachingDefenitions rd = new ReachingDefenitions(graph);
>               Iterator<Unit> unitIt = graph.iterator();
>
> while(unitIt.hasNext()){
>      Unit s = unitIt.next();
> G.v().out.println("----------------------------");
>     G.v().out.println(s.toString());
>     List<DefinitionStmt> before =  rd.getDefsBefore(s);
>     if (before != null) {
>     G.v().out.print("Before : ");
>     for (DefinitionStmt def : before) {
>     G.v().out.print(def.toString() + " , ");
>     }
>     G.v().out.println();
>     }
>     List<DefinitionStmt> after =  rd.getDefsAfter(s);
>     if (after != null) {
>     G.v().out.print("After : ");
>     for (DefinitionStmt def : after) {
>     G.v().out.print(def.toString() + " , ");
>     }
>     G.v().out.println();
>     }
> }
>      }
>    }));
>  PhaseOptions.v().setPhaseOption("jb", "use-original-names:true");
>  soot.Main.main(args);
> }
> }
>
> ReachingDefenitions.java :
>
> public class ReachingDefenitions {
> protected Map<Unit, List<DefinitionStmt>>
> reachingDefsBefore,reachingDefsAfter;
>
> @SuppressWarnings("unchecked")
> public ReachingDefenitions(DirectedGraph<Unit> graph)
>     {
> // Run analysis
> ReachingDefintionAnalysis analysis = new ReachingDefintionAnalysis(graph);
>         // build map
>
>     reachingDefsBefore = new HashMap<Unit,
> List<DefinitionStmt>>(graph.size() * 2 + 1, 0.7f);
>     reachingDefsAfter = new HashMap<Unit, List<DefinitionStmt>>(graph.size()
> * 2 + 1, 0.7f);
>
>     Iterator<Unit> unitIt = graph.iterator();
>
>         while(unitIt.hasNext()){
>             Unit s = unitIt.next();
>             //FlowSet set = analysis.getFlowBefore(s);
>             FlowSet set = analysis.getFlowAfter(s);
>             reachingDefsAfter.put
>                 (s,
> Collections.unmodifiableList((List<DefinitionStmt>)set.toList()));
>             set = analysis.getFlowBefore(s);
>             reachingDefsBefore.put
>             (s,
> Collections.unmodifiableList((List<DefinitionStmt>)set.toList()));
>         }
>     }
>
>     /**
>      * Returns a list of locals guaranteed to be defined at (just
>      * before) program point <tt>s</tt>.
>      **/
>     public List<DefinitionStmt> getDefsBefore(Unit s)
>     {
>         return reachingDefsBefore.get(s);
>     }
>
>     public List<DefinitionStmt> getDefsAfter(Unit s)
>     {
>         return reachingDefsAfter.get(s);
>     }
> }
>
> ReachingDefintionAnalysis.java :
>
> public class ReachingDefintionAnalysis extends
> ForwardFlowAnalysis<Unit,FlowSet> {
>
> FlowSet emptySet = new ArraySparseSet();
> protected Map<Value,FlowSet> killSet = new HashMap<Value,FlowSet>
> (graph.size() * 2 + 1, 0.7f);
> public ReachingDefintionAnalysis(DirectedGraph<Unit> graph) {
> super(graph);
> G.v().out.println("--------------2-------------");
> // Calculate the kill set in advance to improve run time
> for (Iterator<Unit> unitIt = graph.iterator(); unitIt.hasNext() ;  ) {
>             Unit s = unitIt.next();
>             if (!(s instanceof DefinitionStmt))
>             continue;
>             DefinitionStmt def = (DefinitionStmt) s;
>             Value lOp = def.getLeftOp();
>             FlowSet currKillSet = killSet.get(lOp);
>             if (currKillSet == null) {
>             currKillSet = emptySet.clone();
>             killSet.put(def.getLeftOp(),currKillSet);
>             }
>             currKillSet.add(def);
>         }
> doAnalysis();
> }
>
> @Override
> protected void flowThrough(FlowSet in, Unit d, FlowSet out) {
> in.copy(out);
> if (!(d instanceof DefinitionStmt))
> return;
> DefinitionStmt def = (DefinitionStmt) d;
> FlowSet kill = killSet.get(def.getLeftOp());
> out.difference(kill);
> out.add(def);
> }
> @Override
> protected FlowSet newInitialFlow() {
> return emptySet.clone();
> }
>
> @Override
> protected FlowSet entryInitialFlow() {
> return emptySet.clone();
> }
>
> @Override
> protected void merge(FlowSet in1, FlowSet in2, FlowSet out) {
> in1.union(in2,out);
> }
>
> @Override
> protected void copy(FlowSet source, FlowSet dest) {
> source.copy(dest);
> }
>
> }
>
>
> The class i'm trying to analyze :
> package Test;
>
> public class TestClass {
> public static void main(String[] args) {
> int a = 1;
> int b = 2;
> int c = 3;
> a = b + c;
> c = a + b;
> b = a + c;
> }
> }
>
>
> Thanks, Tomer.
>
> _______________________________________________
> Soot-list mailing list
> Soot-list at sable.mcgill.ca
> http://mailman.cs.mcgill.ca/mailman/listinfo/soot-list
>



-- 
Eric Bodden, Ph.D., http://sse.ec-spride.de/ http://bodden.de/
Head of Secure Software Engineering Group at EC SPRIDE
Tel: +49 6151 16-75422    Fax: +49 6151 16-72051
Room 3.2.14, Mornewegstr. 30, 64293 Darmstadt


More information about the Soot-list mailing list