[Soot-list] Soot does not get line numbers of source code

Amit ciphermaker99 at gmail.com
Sun Oct 28 05:36:34 EDT 2012


Found the solution. Posting so others may find this useful. The right way
is to do the following (in Scala, but will give the idea):

    val srcLineNo = try{
      code.getTag("SourceLnPosTag").asInstanceOf[SourceLnPosTag].startLn
    } catch {
      case any =>
        try {

code.getTag("LineNumberTag").asInstanceOf[soot.tagkit.LineNumberTag].getLineNumber
        } catch {
          case any =>   0
        }
    }


On Sun, Oct 28, 2012 at 2:45 PM, Amit <ciphermaker99 at gmail.com> wrote:

> I have some .java files that I want to do DFA on. The problem is that soot
> sometime cannot get the line numbers.
> Here is how I invoke soot (scala code)
>
>       soot.G.reset();
>       PackManager.v().getPack("jap").add(new Transform("jap.myTransform",
> TrapBodyTransformer));
>       PhaseOptions.v().setPhaseOption("tag.ln", "on");
>       Options.v.set_process_dir(List(inputDir));
>       Options.v.set_output_dir(outputDir);
>       Options.v.set_output_format(Options.output_format_jimple);
>       Options.v.set_allow_phantom_refs(true);
>       Options.v.set_src_prec(Options.src_prec_java);
>       Options.v.set_whole_program(false);
>       Options.v.set_exclude(List("java","sun", "java.lang"));
>       Options.v.set_keep_line_number(true);
>
> Options.v.set_soot_classpath(inputDir+"c:\\lib\\mongodb\\mongo-2.7.3.jar");
>       Options.v.set_prepend_classpath(true);
>       Options.v.setPhaseOption("jb", "use-original-names:true");
>       Options.v.set_no_bodies_for_excluded(true);
>       Scene.v().loadNecessaryClasses();
>       PackManager.v().runPacks();
>       PackManager.v().writeOutput();
>
> Here is how I try to read line numbers:
>      import soot.{Unit => JimpleCode}
>      def getLine(code:JimpleCode) =
> code.getTag("SourceLnPosTag").asInstanceOf[SourceLnPosTag].startLn
>
> However, this works in certain cases and in others it gives a null pointer
> exception. Generally the problem comes when the line contains an invoke
> expression calling an external jar
>
> Would be great to see a solution.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.cs.mcgill.ca/pipermail/soot-list/attachments/20121028/46428813/attachment.html 


More information about the Soot-list mailing list