[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: SourceFile attribute



I'm using Soot to build control-flow and data-flow graphs.  Someone else
is using my graphs for his tool, and he wants to write a debugger, so he
wants to be able to map operations to lines of source code.  The tricky
part is that sometimes I inline methods, so not all the operations may
have come from the same source file.  Now I know that inlining wipes out
the line number tags by default, but I found a way to use them still.
The problem is, the numbers alone aren't meaningful.  Here's an example
that isn't very practical, but illustrates the problem:

In Distance.java:

1: public class Distance {
2:   public static double dist(double x1, double y1, double x2,
3:                             double y2) {
4:     return Math.sqrt(Square.sq(x1 - x2) + Square.sq(y1 - y2));
5:   }
6: }

In Square.java:

1: public class Square {
2:   public static double sq(double x) {
3:     return x * x;
4:   }
5: }

Now here's the jimple body of the method after inlining Square.sq, with
the line numbers for each statement at the beginning of the line.  (I 
have retained the line numbers on the inlined statements):

public static double dist(double double double double )
{
   double x1, y1, x2, y2, $d0, $d1, x#1, $d2, x#2, $d3;
   java.lang.Object $r0, $r1, $r2, $r3, $r4, $r5, $r6;

   x1 := @parameter0: double;
   y1 := @parameter1: double;
   x2 := @parameter2: double;
   y2 := @parameter3: double;
[4]  $d0 = x1 - x2;
   x#1 = $d0;
[3]  $d2 = x#1 * x#1;
[3]  $d0 = $d2;
[4]  $d1 = y1 - y2;
   x#2 = $d1;
[3]  $d3 = x#2 * x#2;
[3]  $d1 = $d3;
[4]  $d0 = $d0 + $d1;
[4]  $d0 = staticinvoke <java.lang.Math: double sqrt(double)>($d0);
[4]  return $d0;
}

The line numbers are perfectly correct, but if all we had was the jimple 
body, we couldn't match statements to lines of source code.  On the 
other hand, if each SootMethod (or just the jimple body that has the 
line numbers on the statements) had a tag for the source file, I could 
generate this after inlining:

public static double dist(double double double double )
{
   double x1, y1, x2, y2, $d0, $d1, x#1, $d2, x#2, $d3;
   java.lang.Object $r0, $r1, $r2, $r3, $r4, $r5, $r6;

   x1 := @parameter0: double;
   y1 := @parameter1: double;
   x2 := @parameter2: double;
   y2 := @parameter3: double;
[Distance.java: 4]  $d0 = x1 - x2;
   x#1 = $d0;
[Square.java: 3]  $d2 = x#1 * x#1;
[Square.java: 3]  $d0 = $d2;
[Distance.java: 4]  $d1 = y1 - y2;
   x#2 = $d1;
[Square.java: 3]  $d3 = x#2 * x#2;
[Square.java: 3]  $d1 = $d3;
[Distance.java: 4]  $d0 = $d0 + $d1;
[Distance.java: 4]  $d0 = staticinvoke <java.lang.Math: double 
sqrt(double)>($d0);
[Distance.java: 4]  return $d0;
}

Feng QIAN wrote:
 >>no problem using them except one:  I don't have access to the SourceFile
 >>attribute that would give meaningful context for the line numbers.
 >
 >
 > Sootified class files were generated by jasmin, I believe the SourceFile
 > attribute is 'your_class_name.jasmin', I only saw this is useful what you
 > get an exception. Do you mean something else of 'meaningful context'?
 >
 > Feng
 >
 >


-- 
Nathan Kitchen
kitchen@ee.byu.edu