soot-oss / soot

Soot - A Java optimization framework
GNU Lesser General Public License v2.1
2.89k stars 709 forks source link

Backward slicing code example with Soot #1599

Open msintaha opened 3 years ago

msintaha commented 3 years ago

Hi,

I want to implement backward slicing of a statement within a method which would give me the set of statements given a slice criterion. Is there any example to do this? Please help! I think this should have an example of its own as there have been many requests in the soot mailing list regarding this.

patricklam commented 3 years ago

I'm not aware of any examples, but I'm sure that we would incorporate it in the docs if there were.

On Sun, Apr 25, 2021 at 10:16 AM Mifta Sintaha @.***> wrote:

Hi,

I want to implement backward slicing of a statement within a method which would give me the set of statements given a slice criterion. Is there any example to do this? Please help! I think this should have an example of its own as there have been many requests in the soot mailing list regarding this.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/soot-oss/soot/issues/1599, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOKE5UWAOKZF6MNULIIJ23TKM7KLANCNFSM43QSJFZQ .

msintaha commented 3 years ago

Can you give an idea on how to implement this then? There has been a paper published on Soot Static slicing back in 2006 and in all this time, nobody contributed an example or explanation on how to implement this. It doesn't seem so straightforward, so any hints on how to implement this would be great!

patricklam commented 3 years ago

I don't have any hints, sorry.

On Mon, Apr 26, 2021 at 2:59 AM Mifta Sintaha @.***> wrote:

Can you give an idea on how to implement this then? There has been a paper published on Soot Static slicing back in 2006 and in all this time, nobody contributed an example or explanation on how to implement this. It doesn't seem so straightforward, so any hints on how to implement this would be great!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/soot-oss/soot/issues/1599#issuecomment-826338312, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOKE5U5EO6QRTGSA2G3TGTTKQU45ANCNFSM43QSJFZQ .

MarcMil commented 3 years ago

You could use a worklist approach containing worklist items with the current unit/method and the set of variables needed at that location. Using a unit graph, you can work you way backwards. Upon reaching the start of the method, you can leverage the call graph to see possible calling statements and add them to the worklist. Beware of recursion and be sure to limit the number of steps.

MarcMil commented 3 years ago

Also, for each invocation statement you might need to branch out into an callee. Thus, your worklist item should have a stack of methods to maintain the caller context when the analysis reaches the start of the method.