0

For the below code, calling Add method from Calculator main method, the data passed is 1, 2. I need the data passing between the method calls. I was able to get the callgraph. Can any one help me how to get intermediate data in java Screenshot - https://i.stack.imgur.com/LCp1Y.jpg

package dr;

public class Calculator {
    public static void main(String args[]){
        Addition ob1 = new Addition();
        Multiplication ob2 = new Multiplication();
        int result1 = ob1.Add(1, 2);
        int result2 = ob2.Multiply(2, 4);
        System.out.println(result1);
        System.out.println(result2);
    }
}

class Multiplication {
    public int Multiply(int[enter image description here][1] a, int b){
        return a*b;enter image description here
    }
}

class Addition {
    public int Add(int a, int b){
        return a + b;
    }
}
  • You want to see what the parameters values are, when a function is called? Why can't you add logging of the parameters, to that function? – Ira Baxter Jun 12 '16 at 22:14
  • I think the OP is referring to this: https://github.com/gousiosg/java-callgraph – Georgios Gousios Jun 13 '16 at 08:27
  • @IraBaxter I want to analyze any open source project jar file, during dynamic execution of jar, i need to collect intermediate data. Logging is not good approach as any open source project may contain thousands of methods where it is not possible to log every parameter. I want to do it by instrumentation – Naga Krishna Jun 13 '16 at 15:43
  • @NagaKrishna: Logging *is* instrumentation. The only argument is who installs it, and when. Sounds like you want to modify the byte code for specific methods to record parameters. Why do you need a call graph? – Ira Baxter Jun 13 '16 at 17:08
  • @IraBaxter: i want to analyze a jar file (specifically any open source project) starting from main method how the calls are made till the end. for each method call i need to record input data to method and output data returned by method. Can you suggest me how to do this in java – Naga Krishna Jun 13 '16 at 18:29
  • For binary (jar) files, you'll need to use a byte-code analyzer/transformer tool like BCEL, and compute all the call graphs/code modifications yourself. For source files, you could use a program transformation engine, that could modify the source code with instrumentation before the code was compiled an run. I don't know a lot more about BCEL and friends... I know a lot more about source-to-source transformations tools. – Ira Baxter Jun 13 '16 at 22:01
  • @IraBaxter Thanks Baxter, i am some how able to move forward using Java Assist, which is similar to BCEL. [Tutorial](http://jboss-javassist.github.io/javassist/tutorial/tutorial2.html#intro) – Naga Krishna Jun 13 '16 at 23:18

0 Answers0