Re: Incorrect Parameter Order
"ThanhVu (Vu) Nguyen" <[email protected]> Sat, 02 Dec 2017 06:04:22 +0000
| Newsgroups | gmane.comp.java.objectweb.asm |
|---|---|
| Message-ID | <CA+OL+Mj2WHAwysn_FWc4UsQdNcom8zMYvisqbXx34+6X8JK3gg@mail.gmail.com> |
Thanks for the javap tip. I figured out the problem (I shouldn't use visietMethodInsn because that will add the println to where I call trace, instead of adding the println inside the trace function). Another question, assume my class has a method called "foo" and "trace". Can I obtain Method objects that represent these method ? So that I can quickly get information about parameter, types etc of the methods. @Eliot I want to use ASM because I might not have the program src code as input, just the class file (compiled with debugging info). Currently I am learning ASM so I just use some simple examples that can be done by just parsing the src directly. On Fri, Dec 1, 2017 at 9:33 PM Eliot Moss <[email protected]> wrote: > 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 > -- 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