Re: Incorrect Parameter Order
Eliot Moss <[email protected]> Fri, 1 Dec 2017 22:33:14 -0500
| Newsgroups | gmane.comp.java.objectweb.asm |
|---|---|
| Message-ID | <[email protected]> |
On 12/1/2017 6:30 PM, ThanhVu (Vu) Nguyen wrote:
> I want to instrument a function to print out its parameter values
> For example, void trace(b,d){} becomes void trace{System.out.println(b+ " " + d);}
>
> And trace is invoked from another function, e.g.,
> foo(){
> int a = 0;
> int b = 1;
> int c = 2;
> int d = 3;
> trace(b,d);
> }
>
> So after the instrument I want the program to print
> 1 3 when running foo
>
> I wrote some code for ASM to do it, but I did it wrong because it always print
> 0 1 (i.e., . the values of a and b. I suspect I didn't use the correct arg index, but I am not
> sure how to make it right.
>
> Essentially my code contains a loop in visitMethodInsn that prints something like
I think you probably meant:
void trace(int b, int d) {} ==>
void trace(int b, int d) {System.out.println(b+" "+d);}
Somewhat agreeing with a previous responder, you can simply write that out,
compile it, and use javap to see the bytecode the compiler produces.
I will guess that your problem is that you meant for the trace method to
be static. If it is not static, then local 0 is "this" and b will be in
local 1, etc.
I also wonder if what you're doing overall is generating this class using
a program, a program that extracts the various desired forms from other
program text. If you're doing that, then you could just have that program
generate the source code and run it through javac rather more easily than
doing this task with ASM. (A reason to do it with ASM is if you want to
build a class file on the fly and pass it into a running a VM.)
Regards - Eliot
--
You receive this message as a subscriber of the [email protected] mailing list.
To unsubscribe: mailto:[email protected]
For general help: mailto:[email protected]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws