[Soot-list] Adding an attribute to a line of code

Ondrej Lhotak olhotak at uwaterloo.ca
Mon May 24 08:52:01 EDT 2010


On Sat, May 22, 2010 at 07:05:17PM +0000, saswat78 at gmail.com wrote:
> Hello,
> 
> I think when Soot outputs Jasmin code, it does not know the offset where
> bytecode corresponding to a Unit will be placed in the class file. It is only
> after Jasmin assembles, bytecodes are known. So I guess it is not possible to
> map a label, which is internal to soot, to bytecode offset.

Soot comes (or used to come) with a modified Jasmin that does exactly
this. Once Jasmin has figured out the bytecode offset of each
instruction, it rewrites the labels to the bytecode offsets. See:
http://www.sable.mcgill.ca/publications/papers/2001-2/sable-paper-2001-2.pdf

> But I can think of a solution that uses the feature of embedding line numbers
> in the class file to indirectly infer the mapping from tags attached to Units
> to their corresponding tags.
> 
> 1. Add a Tag (e.g., IndexTag) to each Unit that holds the statement's index in
> the method body. This will automatically generate a mapping from a Unit's label
> to its index in the class file.
> 2. When outputing Jasmin code for a Unit, output the unit's index as its line
> number using ".line" jasmin primitive.
> 
> Above should enable you to map a bytecode to its index (using the Line number
> table in the class file), and then the index to its label, and then the label
> to its tag.
> 
> To do the second step, you will have to edit soot/baf/JasminClass.jave to add
> following two lines right before where the jasmin code for a unit is output. It
> is around line 250 in that file.
> 
> IndexTag lnTag = (IndexTag) s.getTag("IndexTag");
> if(lnTag != null) emit(".line " + lnTag.getLineNumber());
> 
> Note that soot does not currently output line numbers in jasmin code. If it
> did, you could have used the LineNumberTag's to encode the index instead of
> line number. I think soot should output line number tags using .line primitives
> by default.
> 
> Saswat
> 
> 
> On May 21, 2010 12:49pm, Arie Zilberstein <arie.zilberstein at gmail
> .com> wrote:
> > Hi Eric,
> >
> >
> >
> > Thanks for your help. From what I've seen, Unit-level tags are aggregated
> >
> > into a method-level attribute. This attribute contains a "map" from labels
> >
> > to each tag's byte array representation. But how may an outside consumer
> >
> > make use of those labels? In my example, I require that ASM processes the
> >
> > produced classfile.
> >
> >
> >
> > The problem is that, I could not find the correspondence between the label
> >
> > number and the bytecode offset... It would've been perfect if the tag
> >
> > contained the bytecode offset of the instruction, but I think that this data
> >
> > is not available in Jasmin at the moment of code emission.
> >
> >
> >
> > Here's an example label that Soot produced:
> >
> >
> >
> > %label0%AAA=%label1%AAA=%label2%AAA=
> >
> >
> >
> > Thanks,
> >
> > Arie
> >
> >
> >
> > -----Original Message-----
> >
> > From: eric.bodden at googlemail.com [mailto:eric.bodden at googlemail.com] On
> >
> > Behalf Of Eric Bodden
> >
> > Sent: Friday, May 21, 2010 8:23 AM
> >
> > To: Arie Zilberstein
> >
> > Cc: soot-list at sable.mcgill.ca
> >
> > Subject: Re: [Soot-list] Adding an attribute to a line of code
> >
> >
> >
> > Hi Arie.
> >
> >
> >
> > If I remember correctly then there is o such thing as a unit-level
> >
> > attribute in bytecode. There are only method-level attributes that can
> >
> > refer to units via instruction offsets. I believe that this is what
> >
> > the aggregaters are meant for: convert a list of unit-level tags to a
> >
> > single method-level tag that encodes the unit-to-attribute relation
> >
> > correctly. I think there should be some code in Soot that already does
> >
> > that for certain attributes.
> >
> >
> >
> > If you have suggestions on how to make this any easier, please let us
> >
> > know. This is definitely one of the areas of Soot that I think may
> >
> > still benefit from improvements.
> >
> >
> >
> > Happy tagging,
> >
> > Eric
> >
> >
> >
> > --
> >
> > Dr. Eric Bodden
> >
> > Software Technology Group, Technische Universität Darmstadt, Germany
> >
> > Tel: +49 6151 16-5478    Fax: +49 6151 16-5410
> >
> > Mailing Address: S2|02 A209, Hochschulstraße 10, 64289 Darmstadt
> >
> >
> >
> >
> >
> >
> >
> > On 21 May 2010 02:33, Arie Zilberstein arie.zilberstein at gmail.com> wrote:
> >
> > > Hi,
> >
> > > I'm having a lot of trouble adding an attribute to a line of code.
> >
> > > I attach my own custom Tag to a (Jimple) Unit but that tag never gets
> >
> > > translated into a Java attribute.
> >
> > > It seems that Soot only outputs field, class or method-level attributes. A
> >
> > > tag on a Unit will at best get aggregated by a TagAggregator and will be
> >
> > > lost; instead a method-level attribute will be created.
> >
> > > Am I doing something wrong? I analyzed the code thoroughly and could not
> >
> > > find the way.
> >
> > > I even found a tutorial
> >
> > > (http://www.sable.mcgill.ca/soot/tutorial/tagclass/index.html) but it
> >
> > failed
> >
> > > in the same way. I'm using the SVN trunk version of soot.
> >
> > > Thanks,
> >
> > > Arie
> >
> > > _______________________________________________
> >
> > > Soot-list mailing list
> >
> > > Soot-list at sable.mcgill.ca
> >
> > > http://mailman.cs.mcgill.ca/mailman/listinfo/soot-list
> >
> > >
> >
> > >
> >
> >
> >
> > _______________________________________________
> >
> > Soot-list mailing list
> >
> > Soot-list at sable.mcgill.ca
> >
> > http://mailman.cs.mcgill.ca/mailman/listinfo/soot-list
> >

> _______________________________________________
> 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