[Soot-list] CallGraph question

Ondrej Lhotak olhotak at sable.mcgill.ca
Fri Mar 25 19:24:47 EST 2005


I tried it out, and as far as I can see, the presence of the call edge
to charAt is not related to the presence of line 4. The call edge
depends on what you pass into str when you call function5. If you have
the call:
        new Bar().function5(1,2,"foo");
then str is the string "foo", so calling charAt on it will invoke
String.charAt, so the call graph has an edge. If you have the call:
        new Bar().function5(1,2,null);
then str is null, so calling charAt in it will invoke nothing and throw
an exception, so the call graph has no edge.

If you have no calls to function5 in your program, the call graph would
normally not include function5. But your code adds it as an entry point,
so it does get included in the call graph. However, having it be an
entry point doesn't tell Soot what will be passed as parameters, so it
assumes that nothing will.

Ondrej

On Fri, Mar 25, 2005 at 07:12:10PM -0500, Jia Chen wrote:
> Thanks a lot for the response. I updated my Soot release and got it
> working now. However, there is still something strange happening.
> 
> When I have the code being analyzed as follows:
> 
> 1. public void function5(int pram1, int pram2, String str) {
> 2.	IfStatement ifStmt = new IfStatement();
> 3.	int i = 0, j = 0;
> 4.	String str2 = "testing";
> 5.	str.charAt(0);
> 6.	i = pram2;
> 7.	function6(i, j);
> 8.	int b = function8(j, i);
> 9. }
> 
> 
> the output is:
> CLINIT edge: $r2 = new com.jchen27.tempclass.IfStatement in
> <com.jchen27.tempclass.Bar: void function5(int,int,java.lang.String)>
> ==> <java.lang.Object: void <clinit>()>
> VIRTUAL edge: virtualinvoke r0.<com.jchen27.tempclass.Bar: int
> function8(int,int)>(i2, i5) in <com.jchen27.tempclass.Bar: void
> function5(int,int,java.lang.String)> ==> <com.jchen27.tempclass.Bar:
> int function8(int,int)>
> VIRTUAL edge: virtualinvoke r0.<com.jchen27.tempclass.Bar: void
> function6(int,int)>(i5, i2) in <com.jchen27.tempclass.Bar: void
> function5(int,int,java.lang.String)> ==> <com.jchen27.tempclass.Bar:
> void function6(int,int)>
> VIRTUAL edge: virtualinvoke r1.<java.lang.String: char charAt(int)>(0)
> in <com.jchen27.tempclass.Bar: void
> function5(int,int,java.lang.String)> ==> <java.lang.String: char
> charAt(int)>
> SPECIAL edge: specialinvoke $r2.<com.jchen27.tempclass.IfStatement:
> void <init>()>() in <com.jchen27.tempclass.Bar: void
> function5(int,int,java.lang.String)> ==>
> <com.jchen27.tempclass.IfStatement: void <init>()>
> 
> however if I remove line 4, the VIRTUAL edge char charAt(int)
> disappear, any idea?
> 
> Thx,
> Jia
> 
> On Thu, 24 Mar 2005 19:51:32 -0500, Ondrej Lhotak
> <olhotak at sable.mcgill.ca> wrote:
> > I tried to run your code on the latest Soot release. I did not get the
> > output that you did, but instead, I got an exception in the
> > soot.toolkits.exceptions.ThrowableSet$Manager class. The reason for this
> > exception is because basic classes necessary for the functioning of Soot
> > (such as the various exceptions defined by the VM) were not loaded. They
> > were not loaded because you are not extending Soot in the recommended
> > way (by adding a subclass of BodyTransformer or SceneTransformer; see
> > the Soot tutorials), but just calling into Soot directly. If you do want
> > to call into Soot directly, you need to add the following two lines
> > after the first line of code from your e-mail:
> > 
> >         soot.options.Options.v().set_whole_program(true);
> >         scene.loadBasicClasses();
> > 
> > If I add those two lines, the output I get is:
> > 
> > <verbose Spark output deleted>
> > CLINIT edge: $r1 = new IfStatement in <Bar: void function5(int,int)> ==> <java.lang.Object: void <clinit>()>
> > VIRTUAL edge: virtualinvoke r0.<Bar: int function8(int,int)>(i2, i5) in <Bar: void function5(int,int)> ==> <Bar: int function8(int,int)>
> > VIRTUAL edge: virtualinvoke r0.<Bar: void function6(int,int)>(i5, i2) in <Bar: void function5(int,int)> ==> <Bar: void function6(int,int)>
> > SPECIAL edge: specialinvoke $r1.<IfStatement: void <init>()>() in <Bar: void function5(int,int)> ==> <IfStatement: void <init>()>
> > VIRTUAL edge: virtualinvoke r3.<java.lang.String: char charAt(int)>(0) in <Bar: void function5(int,int)> ==> <java.lang.String: char charAt(int)>
> > 
> > This is the correct output. Note that I had to add the functions necessary to
> > get the code that you're analyzing to compile:
> > 
> > public class Bar {
> >     public static final void main(String[] args) {
> >         new Bar().function5(1,2);
> >     }
> >     public int function8(int i, int j) {
> >         return 1;
> >     }
> >     public void function6(int i, int j) {
> >     }
> >     public void function5(int pram1, int pram2) {
> >         IfStatement ifStmt = new IfStatement();
> >         int i = 0, j = 0;
> > 
> >         String str = "testing";
> >         str.charAt(0);
> >         i = pram2;
> >         function6(i, j);
> >         int b = function8(j, i);
> > }
> > }
> > 
> > Ondrej
> > 
> > On Thu, Mar 24, 2005 at 07:04:04PM -0500, Jia Chen wrote:
> > > Hi All,
> > >
> > > I am working on a project that requires finding out all the methods
> > > that are invoked as a result of one method being invoked. So I found a
> > > piece of cod that builds a CallGraph from a method. However, when I
> > > iterated through all out-going edges from the method, all I could see
> > > were SPECIAL, STATIC, and FINALIZE edges. Can anyone tell me how I can
> > > get the other edges also? Follows is the code I am using.
> > >
> > > Thanks in advance.
> > > Jia
> > >
> > > // ---- Code using Soot ----------------------------------------------
> > > Scene scene = Scene.v();
> > > SootClass sootClass = scene.loadClassAndSupport(className);
> > >
> > > Scene.v().setEntryPoints(sootClass.getMethods());
> > > Map sparkOptions = new HashMap();
> > > sparkOptions.put("enabled", "true");
> > > sparkOptions.put("on-fly-cg", "true");
> > > sparkOptions.put("set-impl", "hybrid");
> > > sparkOptions.put("propagator", "worklist");
> > > sparkOptions.put("verbose", "true");
> > > SparkTransformer.v().transform("cg", sparkOptions);
> > >
> > > SootMethod sMethod = sootClass.getMethod(methodName);
> > > CallGraph callGraph = scene.getCallGraph();
> > > Iterator iter = callGraph.edgesOutOf((MethodOrMethodContext)sMethod);
> > >
> > > while (iter.hasNext()) {
> > >       System.out.println(iter.next());
> > > }
> > > // ---- End of Code using Soot ----------------------------------------
> > >
> > > // ---- Function being analyzed --------------------------
> > > public void function5(int pram1, int pram2) {
> > >       IfStatement ifStmt = new IfStatement();
> > >       int i = 0, j = 0;
> > >
> > >       String str = "testing";
> > >       str.charAt(0);
> > >       i = pram2;
> > >       function6(i, j);
> > >       b = function8(j, i);
> > > }
> > > // ---- End of function being analyzed --------------------
> > >
> > > // ---- Output ----------------------------------------------
> > > SPECIAL edge: specialinvoke $r2.<tempclass.IfStatement: void
> > > <init>()>() in <.tempclass.IfStatement: void function5(int,int)> ==>
> > > <tempclass.IfStatement: void <init>()>
> > > // ---- End of Output ----------------------------------------
> > > _______________________________________________
> > > Soot-list mailing list
> > > Soot-list at sable.mcgill.ca
> > > http://www.sable.mcgill.ca/mailman/listinfo/soot-list
> > >
> >
> 


More information about the Soot-list mailing list