I am no expert in this stuff (far from it), although through using BCEL I've learned a hell of a lot about the byte code etc. Therefore I assume someone on this list will be able to correct me if I'm wrong, but I understood that if the variable is "created" with the involvement of a store instruction (as you seem to be dealing with?), the variable will not be available until after that store instruction (+1).
Hope that gives some explanation. Mac -----Original Message----- From: Eric Sheridan [mailto:[EMAIL PROTECTED] Sent: 27 July 2007 02:43 To: BCEL Users List Subject: RE: getLocalVariable help Arrin and Mac, Thanks for your help! Everything seems to be working well. My code snippet is as follows: StoreInstruction storeInstruction = (StoreInstruction)instruction; int index = storeInstruction.getIndex(); int pc = ihs[i].getPosition() + 1; LocalVariable lv = lvt.getLocalVariable(index, pc); For some reason, I had to add a '1' to getPosition() for it to work. Printing out the LocalVariableTable revealed that getPosition() was always one less than what was found in the LocalVariableTable. Not sure why, just happy it works. Thanks again! -Eric -----Original Message----- From: Nicholson, Jonathan O H [mailto:[EMAIL PROTECTED] Sent: Wed 7/25/2007 11:58 PM To: BCEL Users List Subject: RE: getLocalVariable help Eric, To add to Arrin's reply, when I do this I start from an InstructionHandle. It has been a while since I have looked at my code for this, but if I remember correctly from an InstructionHandle you can retrieve both the instruction its self and the instructions pc (which I believe is the method getPosition()). E.g. (roughly) InstructionHandle ih = <however you get the handle, make it, etc>; LocalVariable v = <LocalVariableTable>.getLocalVariable(ih.getInstruction().getIndex(), ih.getPosition()); <do whatever with v> This may not be the "best" way, but it works how I have used it so far. Note that if the pc is 0 (and I remember correctly) it is one of the arguments of the method, which may or may not be useful information depending on what you are doing with the variable. Hope that helps Mac -----Original Message----- From: Eric Sheridan [mailto:[EMAIL PROTECTED] Sent: 26 July 2007 01:32 To: bcel-user@jakarta.apache.org Subject: getLocalVariable help Group, I am a relatively new BCEL user and I am trying to invoke the getLocalVariable(int index, int pc) method on the LocalVariableTable object. I am unable to determine how to access the current pc, the second parameter required for the method. What is the best way to obtain this value? Thanks in advance for everyone's help! -Eric --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]