[Soot-list] PointsToSet question for instance fields in a class
Aiwu Shi
ashi01 at cis.poly.edu
Mon Dec 12 12:44:44 EST 2005
I am doing points-to analysis using SPARK, I want to get the PointsToSet for all fields in a class, including static fields and other instance fields.
we know, I can call the reachingObjects(SootField f) to get the PointsToSet of static field f.
however, we have direct method call for instance fields. so, I do as follows.
in method Jimple body, the Local r0=@this, accessing instance field f (this.f) is same as r0.f, so, I get the PointsToSet of instance field f, using reachingObjects(r0, f).
I did that, it doesnt work!. I got the PointsToSet is empty!!!!, anything wrong for me, please help.
the following is my main class.
//load the analyzed class into Scene
SootClass sc = Scene.v().loadClassAndSupport("SampleClass");
Scene.v().setEntryPoints(sc.getMethods());
System.out.println(sc);
//set the PointsToAnalysis with phase options
options.put("enabled", "true");
options.put("on-fly-cg", "true");
options.put("set-impl", "hybrid");
options.put("propagator", "worklist");
options.put("verbose", "true");
System.out.println(options);
//PointsToAnalysis spark = new PAG(new SparkOptions(options));
SparkTransformer.v().transform("cg.spark",options);
//get the points-to analysis instance
PointsToAnalysis pa = Scene.v().getPointsToAnalysis();
System.out.println(pa);
//show the fields in the analyzed class
Iterator itr = sc.getFields().iterator();
while (itr.hasNext()) {
SootField sf = (SootField) itr.next();
if(sf.isStatic()){
PointsToSetInternal pt=(PointsToSetInternal)pa.reachingObjects(sf);
System.out.println(pt.size());
System.out.println(pt.forall(new PtSetVisitor()));
System.out.println("Static Field:-------- "+sf);
}
if(!sf.isStatic()){
temp=sf;
}
}
//show the methods in the analyzed class
Iterator itr1 = sc.getMethods().iterator();
while (itr1.hasNext()) {
SootMethod sm = (SootMethod) itr1.next();
System.out.println(sm);
//get the active body
Body bd = sm.retrieveActiveBody();
System.out.println(bd.getUnits());
//get the locals
Iterator itr2 = bd.getLocals().iterator();
while (itr2.hasNext()) {
Local lc = (Local) itr2.next();
System.out.println(lc.getName());
//r0=@this, we want to get the PointsToSet of this.f
if(lc.getName().equals("r0")){
System.out.println(temp);
PointsToSetInternal ptf=(PointsToSetInternal)pa.reachingObjects(lc,temp);
System.out.println("r0."+temp+ptf.size());
}else{
PointsToSet pts = pa.reachingObjects(lc);
if (pts instanceof PointsToSetInternal) {
PointsToSetInternal ptInternal = (PointsToSetInternal) pts;
System.out.println(ptInternal.size()+ " PointsToSetInternal");
System.out.println(ptInternal.forall(new PtSetVisitor()));
} else if (pts instanceof Union) {
System.out.println("Type: " + pts.getClass());
} else {
System.out.println("Type: " + pts.getClass());
}
}
}
}
}
}
the following is my SampleClass to be analyzed.
public class SampleClass {
static C z;
public C f;
public C f2(){
C x;
C y;
x = new C();
y = new C("lll");
y=x;
z=y;
this.f=z;
return x;
}
void f1(){
C a=new C();
z=a;
}
}
class C{
public C(){
}
public C(String str){
str="constructor 2";
}
}
thanks
Aiwu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.CS.McGill.CA/pipermail/soot-list/attachments/20051212/cd226721/attachment.htm
More information about the Soot-list
mailing list