[Soot-list] About how to get the source code line number

=?GB2312?B?0Oy9oQ==?= fightmyway at gmail.com
Tue Sep 30 00:42:25 EDT 2008


En, I find the thread in mailist about how to get the source code line
number, but i still find no tags.

I run the application like this:

javac -g VeryBusyClass.java

java -cp jasminclasses-2.3.0.jar;polyglotclasses-1.3.5.jar;sootclasses-2.3.0.jar
soot.Main  -keep-line-number -cp . -pp VeryBusyClass

javac -classpath
jasminclasses-2.3.0.jar;polyglotclasses-1.3.5.jar;sootclasses-2.3.0.jar;.
RunVeryBusyAnalysis.java

java -cp
jasminclasses-2.3.0.jar;polyglotclasses-1.3.5.jar;sootclasses-2.3.0.jar;.
RunVeryBusyAnalysis

and the source code is attached

I want to use the line number to create the control flow graph. I use the
UnitGraph, and I print out every unit. I find the unit the diff from
statement in the source. The mapping is not 1:1 but 1:N as one source line
can map to any number of bytecodes.
So if I can use the code like i have attached, can i create the CFG with one
line in source respresented one node? It mean i ought use the information i
get to create it by myself? or Is there have a convenient way to create the
classical CFG?Any suggestion?

Thank you very much?



>>>>>>>>>>>

On Sun, Feb 08, 2004 at 09:31:56PM +0800, #HUANG YUE# wrote:
>    I `d like to show original source code line number in control flow graph. I

> know from mailing list that there is an attribute that can help to realize.
>
>
>
>    But after I wrote the codes as shown in list, I found that no tags found in
> the units. I am not sure which part is not correct. Hope you could give me some

> help on this case.

You need two things to get the source code line numbers:

1) When you compile the code you will be analyzing, you need to use the
-g switch to javac. Otherwise, javac does not insert source line

information into the bytecode, so Soot does not find it there.

2) You need to give the -keep-line-number command-line switch to Soot.
Otherwise, by default, it throws away the source line numbers to save
memory.


Hope that helps.

Ondrej

>>>>>>>>>>>>>>>>>>>>>

public class RunVeryBusyAnalysis
{
	public static void main(String[] args) {
		args = new String[] {"VeryBusyClass"};
		
		if (args.length == 0) {
			System.out.println("Usage: java RunVeryBusyAnalysis class_to_analyse");
			System.exit(0);
		}
		
		SootClass sClass = Scene.v().loadClassAndSupport(args[0]);		
		sClass.setApplicationClass();
		
		Iterator methodIt = sClass.getMethods().iterator();
		while (methodIt.hasNext()) {
			SootMethod m = (SootMethod)methodIt.next();
			Body b = m.retrieveActiveBody();
			
			System.out.println("=======================================");			
			System.out.println(m.toString());
			
			HashMap lineNumberMap = new HashMap();
		    Integer lastLineNumber = new Integer(0);
		    for (Iterator i = b.getUnits().iterator(); i.hasNext(); ) {
			    Unit unit = (Unit)i.next();
			    for (Iterator j = unit.getTags().iterator(); j.hasNext(); ) {
				    Tag tag = (Tag)j.next();
				    if (tag instanceof LineNumberTag) {
					    byte[] value = tag.getValue();
					    int lineNumber = ((value[0] & 0xff) << 8)
						| (value[1] & 0xff);
					    if (lineNumber != lastLineNumber.intValue())
						    lastLineNumber = new Integer(lineNumber);
				    }
				    System.out.println(lastLineNumber + unit.toString());
				    lineNumberMap.put(unit, lastLineNumber);
			    }
		    }
		}
	}
}


public class VeryBusyClass
{
	public static void main(String[] args) {	
		int x = 10;
		int a = x - 1;
		int b = x - 2;

		while (x > 0) {
			System.out.println(a*b - x);
			x = x - 1;
		}
		int m=100,n=10;
		if(m==100)
			m=m/n;
		else
			m=m*n+n;
		
		System.out.println(a*b);
	}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.CS.McGill.CA/pipermail/soot-list/attachments/20080930/2f5cdce6/attachment.htm


More information about the Soot-list mailing list