[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Problems on using getDefBoxes() to get methods writing array fields
On Mon, Jun 16, 2003 at 09:29:00PM -0700, Tao Xie wrote:
> Hi,
> I followed Ondrej's suggestions to successfully get a list of methods that
> write the non-array fields, but I couldn't get the methods that write the array
> fields (except for the constructor method). So could you help me in this?
This is because the other methods actually don't write the array fields
The field "elems" in your example is a pointer to an array,
and this pointer is only written in the constructor. When the other
methods write to the array, they write to the array pointed to by the
field, not to the field itself.
If you look at the Jimple code, you'll see that a write like this.f[i] = j
turns into something like:
r1 = getfield this.f
r1[i] = j
Ondrej
> Thanks!
>
> Tao
>
> For example, my code is:
> Body activeBody = method.getActiveBody();
>
> Iterator defBoxIt = activeBody.getDefBoxes().iterator();
> while (defBoxIt.hasNext()) {
> ValueBox box = (ValueBox) defBoxIt.next();
> Value v = box.getValue();
> System.out.println("Method: "+method.getName()+" Write All:"+ v.toString());
> if (v instanceof FieldRef) {
> FieldRef sfr = (FieldRef)v;
> SootField sf = sfr.getField();
> System.out.println("Method: "+method.getName()+" Write Field:"+ sf.getName
> ());
> }
> }
>
> Running it on the class in the end of this message, I got following trace:
> Method: <init> Write All:r0
> Method: <init> Write All:r0.<uniqueBoundedStack: int numberOfElements>
> Method: <init> Write Field:numberOfElements
> Method: <init> Write All:r0.<uniqueBoundedStack: int max>
> Method: <init> Write Field:max
> Method: <init> Write All:$i0
> Method: <init> Write All:$r1
> Method: <init> Write All:r0.<uniqueBoundedStack: int[] elems>
> Method: <init> Write Field:elems
> Method: push Write All:r0
> Method: push Write All:i0
> Method: push Write All:z0
> Method: push Write All:i1
> Method: push Write All:$r1
> Method: push Write All:$i3
> Method: push Write All:z0
> Method: push Write All:i1
> Method: push Write All:$i4
> Method: push Write All:i2
> Method: push Write All:$r2
> Method: push Write All:$r3
> Method: push Write All:$i5
> Method: push Write All:$i6
> Method: push Write All:$r2[i2]
> Method: push Write All:i2
> Method: push Write All:$i7
> Method: push Write All:$i8
> Method: push Write All:$r4
> Method: push Write All:$i9
> Method: push Write All:$i10
> Method: push Write All:$r4[$i10]
> Method: push Write All:$i11
> Method: push Write All:$i12
> Method: push Write All:$r5
> Method: push Write All:$i13
> Method: push Write All:$r5[$i13]
> Method: push Write All:$i14
> Method: push Write All:$i15
> Method: push Write All:r0.<uniqueBoundedStack: int numberOfElements>
> Method: push Write Field:numberOfElements
> Method: push Write All:$r7
>
> public class uniqueBoundedStack {
> private int[] elems;
> private int numberOfElements;
> private int max;
>
> public uniqueBoundedStack() {
> numberOfElements = 0;
> max = 2;
> elems = new int[max];
> }
>
> public void push(int k) {
> int index;
> boolean alreadyMember;
>
> alreadyMember = false;
>
> for(index=0; index<numberOfElements; index++) {
> if(k==elems[index]) {
> alreadyMember = true;
> break;
> }
> }
>
> if (alreadyMember) {
> for (int j=index; j<numberOfElements-1; j++) {
> elems[j] = elems[j+1];
> }
> elems[numberOfElements-1] = k;
> }
> else {
> if (numberOfElements < max) {
> elems[numberOfElements] = k;
> numberOfElements++;
> return;
> } else {
> System.out.println("Stack full, cannot push");
> return;
> }
> }
> }
> ......
> }
> >Spark doesn't keep such a summary, so you'll have to build one yourself.
> >It shouldn't be too hard, though. For each method that you're interested
> >in:
> >1) Get its body with getActiveBody()
> >2) Get the List of the body's def boxes with body.getDefBoxes()
> >3) Iterate through it. Each element is a ValueBox. Get its value, and
> >see if it's a StaticFieldRef.
> >4) Do the same for body.getUseBoxes() (UseBoxes give values read;
> >DefBoxes give values written)
> >
> >Ondrej
> >
> >On Tue, Apr 22, 2003 at 04:30:58PM +0200, Richard Stahl wrote:
> >> Hello,
> >>
> >> I would like to get the following info out of the Spark:
> >>
> >> for all class fields of a class (classes) get all methods (and/or basic
> >> blocks) acccessing (reading and/or writing) the field, i.e.,
> >> field-access summaries.
> >>
> >> In case, there is not simple and straightforward way to do this: Could
> >> you, please, give me an advice (opinion) on where to start and what to
> >> use (from the SOOT/Spark API) to get this info in an efficient way?
> >>
> >> Thanks a lot.
> >>
> >> Best regards,
> >>
> >> Richard
> >