[Soot-list] a problem in the points-to analysis using SPARK
Zhang Yufeng
yuffonzhang at 163.com
Thu Mar 14 11:37:05 EDT 2013
Hi Michael,
Thank you very much for your help!
As you said, I add a call point in the main method, //new Use().go();
and the points-to sets of local variables are not empty any more.
However, I get the following results:
go
main
[3,3] Container intersect? true
[3,7] Container intersect? true
[3,11] Container intersect? true
[7,7] Container intersect? true
[7,11] Container intersect? true
[11,11] Container intersect? true
The line "[3,7] Container intersect? true" means that the local variable 'Container c1' and 'Container c2' in the go() method of class 'Use' may refer to the same object.
But this is impossible.
I am new to Soot. I think I am confused by so many options.
Yufeng
发件人: Michael Faes
发送时间: 2013-03-14 22:36:52
收件人: Zhang Yufeng
抄送: soot-list
主题: Re: [Soot-list] a problem in the points-to analysis using SPARK
I think your problem is that the main method is empty. Add a call to
go() and see what happens.
Michael
-------- Original-Nachricht --------
Betreff: [Soot-list] a problem in the points-to analysis using SPARK
Von: Zhang Yufeng <yuffonzhang at 163.com>
An: soot-list <soot-list at sable.mcgill.ca>
Datum: 14.03.2013 15:17
> Hi all,
> I am new to Soot.
> Now I am trying to use the points-to analysis using SPARK.
> I copy the code from the example of the tutorial "soot survivors document".
> But I can't get the points-to set for any local variables.
> Indeed, all the points-to set I get are empty.
> I don't know what is wrong.
> My codes are as follows.
> ==============
> Here are the classes I want to analyze:
> ================Container.java
> public class Container {
> private Item item = new Item();
> void setItem(Item item) {
> this.item = item;
> }
> Item getItem() {
> return this.item;
> }
> }
> ==================Item.java
> public class Item {
> Object data;
> public static void main(String[] args) {}
> }
> ==================Use.java
> public class Use {
>
> public void go() {
>
> Container c1 = new Container();
> Item i1 = new Item();
> c1.setItem(i1);
> Container c2 = new Container();
> Item i2 = new Item();
> c2.setItem(i2);
> Container c3 = c2;
>
> }
> public static void main(String[] args) {}
>
> }
> I want to analyze the points-to sets of the local variables in the
> method Use.go().
> The code I used to invoke SPARK is as follows:
> =====================TestPointTo.java
> public class TestPointTo {
>
> private static SootClass loadClass(String name, boolean main) {
> SootClass c = Scene.v().loadClassAndSupport(name);
> c.setApplicationClass();
> if (main) Scene.v().setMainClass(c);
> return c;
> }
> public static void main(String[] args) {
>
> soot.options.Options.v().set_keep_line_number(true);
> soot.options.Options.v().set_whole_program(true);
> soot.options.Options.v().setPhaseOption("cg","verbose:false");
> loadClass("Item", false);
> loadClass("Container", false);
> SootClass c = loadClass(args[0], true);
>
> soot.Scene.v().loadNecessaryClasses();
> soot.Scene.v().setEntryPoints(EntryPoints.v().all());
> HashMap opt = new HashMap();
> opt.put("enabled","true"); // enabled, necessary
> // opt.put("verbose","true");
> opt.put("ignore-types","false");
> opt.put("force-gc","false");
> opt.put("pre-jimplify","false");
> opt.put("vta","false");
> opt.put("rta","false");
> opt.put("field-based","false");
> opt.put("types-for-sites","false");
> opt.put("merge-stringbuffer","true");
> opt.put("string-constants","false");
> opt.put("simulate-natives","true");
> opt.put("simple-edges-bidirectional","true");
> opt.put("on-fly-cg","true");
> opt.put("simplify-offline","false");
> opt.put("simplify-sccs","false");
> opt.put("ignore-types-for-sccs","false");
> opt.put("propagator","worklist");
> opt.put("set-impl","double");
> opt.put("double-set-old","hybrid");
> opt.put("double-set-new","hybrid");
> opt.put("dump-html","false");
> opt.put("dump-pag","false");
> opt.put("dump-solution","false");
> opt.put("topo-sort","false");
> opt.put("dump-types","true");
> opt.put("class-method-var","true");
> opt.put("dump-answer","false");
> opt.put("add-tags","false");
> opt.put("set-mass","false");
> SparkTransformer.v().transform("",opt);
>
> Map/*<Local>*/ ls = getLocals(c,args[1],"Container");
> printLocalIntersects(ls);
>
> }
> private static void printLocalIntersects(Map/*<Integer,Local>*/ ls) {
>
> soot.PointsToAnalysis pta = Scene.v().getPointsToAnalysis();
> Iterator i1 = ls.entrySet().iterator();
> while (i1.hasNext()) {
> Map.Entry e1 = (Map.Entry)i1.next();
> int p1 = ((Integer)e1.getKey()).intValue();
> Local l1 = (Local)e1.getValue();
> PointsToSet r1 = pta.reachingObjects(l1);
> Iterator i2 = ls.entrySet().iterator();
> while (i2.hasNext()) {
> Map.Entry e2 = (Map.Entry)i2.next();
> int p2 = ((Integer)e2.getKey()).intValue();
> Local l2 = (Local)e2.getValue();
> PointsToSet r2 = pta.reachingObjects(l2);
> if (p1<=p2)
> System.out.println("["+p1+","+p2+"]\t Container intersect? "+r1.hasNonEmptyIntersection(r2));
> }
> }
>
> }
> private static Map/*<Integer,Local>*/ getLocals(SootClass sc, String methodname, String typename) {
> Map res = new HashMap();
> Iterator mi = sc.getMethods().iterator();
> while (mi.hasNext()) {
> SootMethod sm = (SootMethod)mi.next();
> System.err.println(sm.getName());
> if (sm.getName().equals(methodname) && sm.isConcrete()) {
> JimpleBody jb = (JimpleBody)sm.retrieveActiveBody();
> Iterator ui = jb.getUnits().iterator();
> while (ui.hasNext()) {
> Stmt s = (Stmt)ui.next();
> int line = getLineNumber(s);
>
> // find definitions
> Iterator bi = s.getDefBoxes().iterator();
> while (bi.hasNext()) {
>
> Object o = bi.next();
>
> if (o instanceof ValueBox) {
> Value v = ((ValueBox)o).getValue();
> if (v.getType().toString().equals(typename) && v instanceof Local)
> res.put(new Integer(line),v);
> }
> }
> }
> }
> }
> return res;
> }
> private static int getLineNumber(Stmt s) {
>
> Iterator ti = s.getTags().iterator();
> LineNumberTag line = (LineNumberTag) s.getTag("LineNumberTag");
> if(line != null)
> return Integer.parseInt(line.toString());
> else {
>
> System.out.println("not define line number tag");
> return -1;
>
> }
>
> }
>
> }
> Does anybody know what is the problem?
> Thank you.
> Yufeng
>
>
> _______________________________________________
> Soot-list mailing list
> Soot-list at sable.mcgill.ca
> http://mailman.cs.mcgill.ca/mailman/listinfo/soot-list
>
.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.cs.mcgill.ca/pipermail/soot-list/attachments/20130314/fbe359ab/attachment-0001.html
More information about the Soot-list
mailing list