[Soot-list] soot (line number)

mbatch at cs.mcgill.ca mbatch at cs.mcgill.ca
Thu Oct 5 19:52:27 EDT 2006


Peng,

Have you tried specifying the "-keep-line-number" option on the commandline?
That should do it for you. It is off by default.

Michael

P.S. for the sake of easier mailing-list archive searching and browsing,
please try to use more specific subject lines - Thanks!

On Thu, October 5, 2006 7:32 pm, Peng Li wrote:
> 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);
> }
> }
> }
> }
> _______________________________________________
> Soot-list mailing list
> Soot-list at sable.mcgill.ca
> http://mailman.cs.mcgill.ca/mailman/listinfo/soot-list
>
>




More information about the Soot-list mailing list