[Soot-list] soot
Peng Li
lipeng360 at gmail.com
Thu Oct 5 19:32:08 EDT 2006
HI
Given a jimple stmt, I am using soot to find the associated line number in
java source code, I am using the following method,
Set the phase
PhaseOptions.v().setPhaseOption("tag.ln", "on");
Add the following code in internalTransform,
int lineNumber = 0;
Unit unit =(Unit)stmt;
LineNumberTag tag = (LineNumberTag)unit.getTag("LineNumberTag");
if (tag != null)
lineNumber = tag.getLineNumber();
System.out.println("line number is "+lineNumber);
But the line number is always 0, that means tag is always null. Could anyone
tell me what is the problem, Thank you very much for your help.
Cheers
Peng Li
import soot.*;
import soot.jimple.*;
import soot.jimple.toolkits.scalar.ConstantPropagatorAndFolder;
import soot.tagkit.LineNumberTag;
import soot.toolkits.graph.BriefUnitGraph;
import soot.util.*;
import java.util.*;
public class ReturnInstrumenter extends BodyTransformer{
private static ReturnInstrumenter instance = new ReturnInstrumenter();
private ReturnInstrumenter() {}
public static ReturnInstrumenter v() { return instance; }
public static void main(String[] args)
{
String[] a={"com.oreilly.struts.storefront.order.CheckoutAction"};
Scene.v
().setSootClassPath("C:/workspace/ReturnValue/sootOutput;C:/j2sdk1.4.2_12/jre/lib/rt.jar");
PhaseOptions.v().setPhaseOption("tag.ln", "on");
PackManager.v().getPack("jtp").add(new Transform("jtp.instrumenter",
ReturnInstrumenter.v()));
Scene.v().addBasicClass("java.io.PrintStream",SootClass.SIGNATURES);
soot.Main.main(a);
}
protected void internalTransform(Body body, String phase, Map options) {
BriefUnitGraph cfg=new BriefUnitGraph(body);
SootMethod method = body.getMethod();
Chain units = body.getUnits();
Iterator stmtIt = units.snapshotIterator();
while(stmtIt.hasNext())
{
Stmt stmt = (Stmt) stmtIt.next();
if(stmt instanceof ReturnStmt)
{
int lineNumber = 0;
Unit unit =(Unit)stmt;
LineNumberTag tag = (LineNumberTag)unit.getTag("LineNumberTag");
if (tag != null)
lineNumber = tag.getLineNumber();
System.out.println("line number is "+lineNumber);
}
}
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.CS.McGill.CA/pipermail/soot-list/attachments/20061006/b9d13890/attachment.htm
More information about the Soot-list
mailing list