[Soot-list] Using Soot as a library / PhaseOptions

Matthew Hague Matthew.Hague at comlab.ox.ac.uk
Thu Nov 27 05:11:45 EST 2008


Forwarded to keep the discussing public.

Matt

----- Forwarded message from Matthew Hague <Matthew.Hague at comlab.ox.ac.uk> -----

Date: Thu, 27 Nov 2008 10:09:38 +0000
From: Matthew Hague <Matthew.Hague at comlab.ox.ac.uk>
To: Eric Bodden <eric.bodden at mail.mcgill.ca>
Cc: Matthew Hague <Matthew.Hague at comlab.ox.ac.uk>
Subject: Re: [Soot-list] Using Soot as a library / PhaseOptions


Hi,

Thanks again for the responses.  I have put together a small test class based
on the example i took from an earlier message to the list.  In particular, i
am not calling soot.Main.main():

    public class SootTest {
        public static void main(String[] args) {
            if (args.length == 0) {
                System.exit(0);
            }

            Options.v().set_verbose(true);
            Options.v().set_output_format(Options.output_format_jimple);

            PhaseOptions.v().setPhaseOption("jap.npc", "on");

            SootClass sClass = Scene.v().loadClassAndSupport(args[0]);
            sClass.setApplicationClass();

            Iterator methodIt = sClass.getMethods().iterator();
            while (methodIt.hasNext()) {
                SootMethod m = (SootMethod)methodIt.next();
                Body b = m.retrieveActiveBody();
            }
        }
    }


When running this program on a class, the jap phase is never executed.  I
have found that i can remedy the problem by calling PackManager.v().runPacks() each time a class is loaded (setting the output format to Jimple fixed the problem i had with this earlier).  

Is this the best solution?  Is there any way to enable the phases after jb to
run automatically when a class is loaded?

Thanks,

Matt




On Wed, Nov 26, 2008 at 11:19:07PM -0500, Eric Bodden wrote:
> Matthew, I took the time to write a little tutorial on packs because
> this seems to confuse many people. You should find your answer in the
> discussion of the jimple packs (in particular jap):
> 
> http://www.bodden.de/2008/11/26/soot-packs/
> 
> Please let me know if this is sufficient.
> 
> Eric
> 
> 2008/11/26 Eric Bodden <eric.bodden at mail.mcgill.ca>:
> > Are you sure that you used...
> >
> > PhaseOptions.v().setPhaseOption("jap.npc", "on");
> >
> > ... before calling main(..) ?
> >
> > With -verbose enabled I see...
> >
> > Applying phase jap.npc to <TestClass: void main(java.lang.String[])>.
> >
> > ... which indicates that the pack should definitely be applied, even
> > with default options.
> >
> > Eric
> >
> > 2008/11/26 Eric Bodden <eric.bodden at mail.mcgill.ca>:
> >> I think looking at PackManager should answer most of your questions:
> >>
> >> http://kickjava.com/src/soot/PackManager.java.htm
> >>
> >> In particular, jap is only run if Jimple is produced, it seems.
> >>
> >> Eric
> >>
> >> 2008/11/26 Matthew Hague <Matthew.Hague at comlab.ox.ac.uk>:
> >>>
> >>> Hi,
> >>>
> >>> Thanks for the reply.
> >>>
> >>> The problem seems to be that the jap pack is not being run at all.  If i use:
> >>>
> >>>  PhaseOptions.v().setPhaseOption("jb.lp", "on");
> >>>
> >>> then the local packer runs as expected (and does not run if i don't enable
> >>> it).  But, if i use:
> >>>
> >>>  PhaseOptions.v().setPhaseOption("jap.npc", "on");
> >>>
> >>> there are no null pointer tags (similarly for other jap tools).  I can use:
> >>>
> >>>  PackManager.v().runPacks(); // (or runBodyPacks())
> >>>
> >>> after loading a class.  However, since the jb.lp option does not require the
> >>> extra step (which causes further problems for me at the moment...), i suspect
> >>> i'm missing something else.
> >>>
> >>> Although i plan to add my own annotation tool, my immediate concern is
> >>> getting the null pointer annotator to run.
> >>>
> >>> Thanks,
> >>>
> >>> Matt
> >>>
> >>>
> >>> On Wed, Nov 26, 2008 at 01:06:46PM -0500, Eric Bodden wrote:
> >>>> Matthew, the "jap" pack is run after all other packs.
> >>>>
> >>>> I recommend reading the PLDI tutorial
> >>>> (http://www.sable.mcgill.ca/soot/tutorial/pldi03/tutorial.pdf) in
> >>>> particular the diagram on page number 100.
> >>>>
> >>>> To run your analysis after the jap pack has been applied, simply add
> >>>> your transformer to the jap pack.
> >>>>
> >>>> Eric
> >>>>
> >>>>
> >>>> 2008/11/26 Matthew Hague <Matthew.Hague at comlab.ox.ac.uk>:
> >>>> >
> >>>> > Hi,
> >>>> >
> >>>> > I am attempting to use Soot as a library, as in this example from the mailing
> >>>> > list:
> >>>> >
> >>>> >  http://www.sable.mcgill.ca/pipermail/soot-list/2008-July/001862.html
> >>>> >
> >>>> >  > public static void main(String[] args) {
> >>>> >  >
> >>>> >  >                if (args.length == 0) {
> >>>> >  >                        System.out.println("Usage: java RunLiveAnalysis
> >>>> >  > class_to_analyse");
> >>>> >  >                        System.exit(0);
> >>>> >  >                }
> >>>> >  >
> >>>> >  >                SootClass sClass = Scene.v().loadClassAndSupport(args[0]);
> >>>> >  >
> >>>> >  >                sClass.setApplicationClass();
> >>>> >  >
> >>>> >  >                Iterator methodIt = sClass.getMethods().iterator();
> >>>> >  >                while (methodIt.hasNext()) {
> >>>> >  >                        SootMethod m = (SootMethod)methodIt.next();
> >>>> >  >                        Body b = m.retrieveActiveBody();
> >>>> >  >                        ....
> >>>> >
> >>>> > I would like to make use of the various optimisations and analyses provided
> >>>> > by Soot, and be able to add some of my own.
> >>>> >
> >>>> > If i add a line:
> >>>> >
> >>>> >  PhaseOptions.v().setPhaseOption("jb.lp", "on");
> >>>> >
> >>>> > towards the top of the main method, then the local variable packer is
> >>>> > (automatically) run on the Jimple retrieved from m.retrieveActiveBody().
> >>>> > However, when i try,
> >>>> >
> >>>> >  PhaseOptions.v().setPhaseOption("jap.npc", "on");
> >>>> >
> >>>> > I do not get null pointer tags as expected. I have also tried enabling "jap"
> >>>> > explicitly, and using Options.v().parse(<options>) to set command line
> >>>> > options (instead of using ParseOptions directly), all to no avail.
> >>>> >
> >>>> > Does anyone know what i might be missing?
> >>>> >
> >>>> > I can call NullPointerTagger.v().transform(body) each time a body is
> >>>> > retrieved, if necessary, but this does not seem like the neatest solution.
> >>>> >
> >>>> > Thanks,
> >>>> >
> >>>> > Matthew Hague
> >>>> > _______________________________________________
> >>>> > Soot-list mailing list
> >>>> > Soot-list at sable.mcgill.ca
> >>>> > http://mailman.cs.mcgill.ca/mailman/listinfo/soot-list
> >>>> >
> >>>>
> >>>>
> >>>>
> >>>> --
> >>>> Eric Bodden
> >>>> Sable Research Group, McGill University, Montréal, Canada
> >>>> Got an interesting job offer? http://www.bodden.de/hire-me/
> >>>
> >>
> >>
> >>
> >> --
> >> Eric Bodden
> >> Sable Research Group, McGill University, Montréal, Canada
> >> Got an interesting job offer? http://www.bodden.de/hire-me/
> >>
> >
> >
> >
> > --
> > Eric Bodden
> > Sable Research Group, McGill University, Montréal, Canada
> > Got an interesting job offer? http://www.bodden.de/hire-me/
> >
> 
> 
> 
> -- 
> Eric Bodden
> Sable Research Group, McGill University, Montréal, Canada
> Got an interesting job offer? http://www.bodden.de/hire-me/

----- End forwarded message -----


More information about the Soot-list mailing list