[Soot-list] PROBLEM SOLVED: How to determine whether there exists a use for a variable definition later on in the cfg

John Dean jdean4 at kc.rr.com
Sun Jul 29 14:13:02 EDT 2012


Eric,

Thanks for the feedback.
Yes, I thought that since SimpleLocalDefs and SimpleLocalUses rely only on a
UnitGraph for parameters, they would store definitions and uses for the
entire method. I thought it was the SimpleLocalUses's getUsesOf(Unit) method
that retrieved a subset of uses - those that are inside the unit's block.
That's what my testing shows when I run the following:

defs = new SimpleLocalDefs(g);
uses = new SimpleLocalUses(g, defs);
unitValueBoxPairList = (List<UnitValueBoxPair>) uses.getUsesOf(stmt);

If SimpleLocalUses's getUsesOf and CombinedDUAnalysis's getUsesOf methods
both are supposed to return uses for the entire method as you suggest, then
why are there 2 classes that have the same method with the same
functionality?

Thanks,
John

-----Original Message-----
From: eric.bodden at gmail.com [mailto:eric.bodden at gmail.com] On Behalf Of Eric
Bodden
Sent: Sunday, July 29, 2012 10:50 AM
To: john.dean at park.edu
Cc: soot-list at sable.mcgill.ca
Subject: Re: [Soot-list] PROBLEM SOLVED: How to determine whether there
exists a use for a variable definition later on in the cfg

Hi John.

I am afraid I cannot quite follow your line of reasoning.
SimpleLocalUses is just defined as the inverse of whatever LocalDefs
analysis you put in. Moreover, to the best of my knowledge, even
SimpleLocalDefs searches the entire method body and not just the same basic
block.

Best wishes,
Eric

On 29 July 2012 00:58, John Dean <jdean4 at kc.rr.com> wrote:
> All,
> To prevent anyone from needlessly spending time on my prior questions....
>
> After much of the day yesterday and today, I finally stumbled upon a 
> soot class that does I need - CombinedDUAnalysis.
> Like SimpleLocalUses, CombinedDUAnalysis contains a getUsesOf(Unit)
method.
> Both methods retrieve uses for the local variable in the Unit 
> argument. The difference is that CombinedDUAnalysis's version searches 
> throughout the method, whereas SimpleLocalUses's version searches just 
> in the block that the Unit argument resides.
>
> If anyone is inclined to update the API for those 2 classes, so the 
> difference is more clear, that might be helpful, but I'm happy regardless.
> CombinedDUAnalysis saves the day!
>
> Thanks,
> John
>
> -----Original Message-----
> From: soot-list-bounces at sable.mcgill.ca 
> [mailto:soot-list-bounces at sable.mcgill.ca] On Behalf Of John Dean
> Sent: Saturday, July 28, 2012 1:15 PM
> To: soot-list at sable.mcgill.ca
> Subject: [Soot-list] How to determine whether there exists a use for a 
> variable definition later on in the cfg
>
> Hi all,
>
> I attempted to send this same email 6 hours ago, but I'm afraid that 
> it might have gotten lost in cyberspace since I didn't receive it as a 
> subscriber to the soot mailing list. Thus, I'm sending it again. 
> Forgive me if you have already received it.
>
> As a follow-up to my email below this one....
> If I'm correct that SimpleLocalUses.getUsesOf(Unit)  retrieves only 
> variable uses that are within the loop and not the ones outside of the 
> loop, then should I try to use the AllVariableUses class instead? And 
> call its getUsesForLocal method?
>
> If using AllVariableUses.getUsesForLocal is the proper way to go, then 
> how do I create an AllVariableUses object? The api defines the 
> constructor as
> this:
>
> AllVariableUses(ASTMethodNode node)
>
> But then there's the problem of creating an ASTMethodNode object. It's 
> constructor is as follows:
>
> ASTMethodNode(List<Object> body)
>
> The api doesn't tell me what sort of List<Object> to use.
>
> As you can see, I'm struggling to solve my problem. Any suggestions 
> would be greatly appreciated.
>
> Thanks,
> John
>
> -----Original Message-----
> From: soot-list-bounces at sable.mcgill.ca 
> [mailto:soot-list-bounces at sable.mcgill.ca] On Behalf Of John Dean
> Sent: Friday, July 27, 2012 9:57 PM
> To: 'Phil Pratt-Szeliga'; soot-list at sable.mcgill.ca
> Subject: Re: [Soot-list] How to determine whether there exists a use 
> for a variable definition later on in the cfg
>
> All,
>
> After much testing, it appears that the getUsesOf(Unit)  method call 
> retrieves only variable uses that are within the loop and not the ones 
> that I'm interested in - the ones outside of the loop. My guess is 
> that that's a limitation due to the difficulty of tracking down 
> dependencies. Does anyone know of a way to successfully retrieve uses 
> for a variable, anywhere in a method, after the variable has been
assigned?
>
> If you want to see my tests to make sure I'm thinking about things 
> properly, here is a source code fragment that I've tested:
>
> int x = 0;
> while (x < 2)
> {
>     x = x + 1;
> }
> int y = x;
>
> And here are the generated units for that code:
>
> x = 0;
>
> label0:
>   nop;
>   if x < 2 goto label1;
>   goto label2;
>
> label1:
>   nop;
>   temp$1 = x;
>   temp$2 = temp$1 + 1;
>   x = temp$2;
>   goto label0;
>
> label2:
>   nop;
>   y = x;
>   return;
>
> When I run the following code, unitValueBoxPairList is an empty list.
> Apparently, getUsesOf does not bother to go to the label2 code to find 
> x being used.
>
> defs = new SimpleLocalDefs(g);
> uses = new SimpleLocalUses(g, defs);
> unitValueBoxPairList = (List<UnitValueBoxPair>) uses.getUsesOf(stmt);
>
> 1. Is my thinking correct?
>
> 2. Does anyone know of a way to successfully retrieve uses for a 
> variable, anywhere in a method, after the variable has been assigned?
>
> Thanks,
> John
>
>
> -----Original Message-----
> From: phil.pratt.szeliga at gmail.com 
> [mailto:phil.pratt.szeliga at gmail.com] On Behalf Of Phil Pratt-Szeliga
> Sent: Friday, July 27, 2012 12:58 PM
> To: john.dean at park.edu
> Cc: soot-list at sable.mcgill.ca
> Subject: Re: [Soot-list] How to determine whether there exists a use 
> for a variable definition later on in the cfg
>
> Hi John,
>
>> Or better yet, I suppose
>> I can use List's contains method with my list of loop statements to 
>> test whether a retrieved statement (from getUsesOf) is in my list of 
>> loop statements. That should work because the contains method relies 
>> on the equals method.
>
> Yes, this is what I had in mind. :)
>
> Phil Pratt-Szeliga
> Syracuse University
>
> -----Original Message-----
> From: John Dean [mailto:jdean4 at kc.rr.com]
> Sent: Friday, July 27, 2012 12:24 PM
> To: 'Phil Pratt-Szeliga'
> Cc: 'soot-list at sable.mcgill.ca'
> Subject: RE: [Soot-list] How to determine whether there exists a use 
> for a variable definition later on in the cfg
>
> Phil (and anyone else?),
> Thanks for the suggestion!
>
> Fortuanately, I've already borrowed/written code to detect loops.
>
> I think you are saying that if I use the default equals method from 
> the Object class (which tests for the same reference address) to 
> compare one of the retrieved units from getUsesOf() with each unit in 
> the loop, equals will return true only if the units are the same exact 
> unit reference (both from within the loop)? Is that right?
>
> So, for example, if there's an x = y statement inside the loop and 
> there's also an x = y statement outside of the loop, then those 2 
> statements will return false when compared using the equals method. Or 
> better yet, I suppose I can use List's contains method with my list of 
> loop statements to test whether a retrieved statement (from getUsesOf) 
> is in my list of loop statements. That should work because the 
> contains method relies on the equals method.
>
> Does it sound like I'm on the right track?
>
> Thanks,
> John
>
>
> _______________________________________________
> 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



--
Eric Bodden, Ph.D., http://bodden.de/
Head of Secure Software Engineering Group at EC SPRIDE
Tel: +49 6151 16-75422    Fax: +49 6151 16-72051
Room 3.2.14, Mornewegstr. 30, 64293 Darmstadt



More information about the Soot-list mailing list