[Soot-list] Counting exits in a loop - understanding Jimple "goto [?= nop]"

John Dean jdean4 at kc.rr.com
Tue Jul 17 08:22:53 EDT 2012


All,
Thanks for the explanations. They help!
I think what's being said is the stmt print mechanism won't show me the goto label, so if I want to analyze what's going on, I need to do more. Eric says "When you print an entire body, then all stmts that gotos jump to are labeled" and "the best way to figure out such targets is to use a debugger." At this point, I don't need to analyze my gotos further, but if and when I do, I'll try looking at block instruction outputs and using a debugger. (Aside: Using a debugger will be a challenge. I am able to enter and edit my code using Eclipse, but I have to use Ant from a command line to run the program. After a day of trying, running Ant from Eclipse won't work for my Transcut program.)

 that labels are printed when an entire block  - maybe look at the block or
At this point, I don't need to fully

Thanks,
John

-----Original Message-----
From: soot-list-bounces at sable.mcgill.ca [mailto:soot-list-bounces at sable.mcgill.ca] On Behalf Of David Given
Sent: Tuesday, July 17, 2012 4:07 AM
To: soot-list at sable.mcgill.ca
Subject: Re: [Soot-list] Counting exits in a loop - understanding Jimple "goto [?= nop]"

John Dean wrote:
[...]
> You say "When you operating at runtime, the targets of the goto 
> instructions will be two disctinct Units." So for the "goto nop" that 
> shows up in my list of statements, what are the "targets," that are "two distinct Units"?
> Likewise, for the "goto [?= nop]" statement: What are the "targets," 
> that are "two distinct Units"?

You're being misled by the way it's being printed --- I ran into this with cowjac.

Each body is a graph of statements. The goto statement's target is just another statement. The naive way to turn a goto instruction to a string just prints 'goto' followed by the string value of the target statement.

So 'goto nop' is appearing because the target of the goto is a nop instruction *which is somewhere else in the graph*.

When you actually do this for real, then instead of just turning the goto's target into a string you want to generate a label reference instead. The pseudocode something like this:

when generating code for a goto:
  print "goto "
  print label for goto's target statement

for all statements in method body
  does this statement need a label?
    print label for statement
  generate code for statement

The code Soot uses to emit Jimple, which does this, is here:

https://github.com/Sable/soot/blob/master/src/soot/Printer.java
...in the printStatementsInBody() method.

(What would actually be kinda nice is a soot postprocessing phase that walked the instruction graph and added label tags to each Unit; this area is a bit counterintuitive...)

--
┌─── dg@cowlark.com ───── http://www.cowlark.com ───── │ "Parents let children ride bicycles on the street. But parents do not │ allow children to hear vulgar words. Therefore we can deduce that │ cursing is more dangerous than being hit by a car." --- Scott Adams

-----Original Message-----
From: eric.bodden at gmail.com [mailto:eric.bodden at gmail.com] On Behalf Of Eric Bodden
Sent: Monday, July 16, 2012 10:10 PM
To: john.dean at park.edu
Cc: Phil Pratt-Szeliga; soot-list at sable.mcgill.ca
Subject: Re: [Soot-list] Counting exits in a loop - understanding Jimple "goto [?= nop]"

Hi John.

This is all just an issue of pretty printing. When you print an entire body, then all stmts that gotos jump to are labeled ,so that you can properly distinguish all the targets of a goto. When you print an individual goto statement, however, things are more tricky. After all, without numbering each and every statement, how would you denote the target of a goto statement? Currently Soot just prints the textual representation of that target statement but that may be ambiguous if there are multiple statements that look alike. Currently the best way to figure out such targets is to use a debugger, I am afraid.

Eric





More information about the Soot-list mailing list