Re: getLocalVariable help
Arrin Daley <[email protected]> Thu, 26 Jul 2007 11:41:10 +1000
| Newsgroups | gmane.comp.jakarta.bcel.user |
|---|---|
| Message-ID | <[email protected]> |
Hi Eric The pc refers to the count within the bytecode array, so the instruction your interested in should have a pc associated with it (if the InstructionList has been changed these counts will be invalid) IntructionList.setPositions() sets these counts, or I think it must be done automatically by MethodGen.getMethod(). If you are changing the InstructionList you can request a LocalVariableGen which uses InstructionHandles which maintain their targets even if the InstructionList is edited later (InstructionHandles are then converted back to pc). The pc parameter to getLocalVariable(..) is required because a local variable index can be re-used by another local variable with a different type once the original local variable is no longer required so the method needs to know which section of code or instruction you are interested in. Importantly in my experience LocalVariable tables are not to be trusted to be correct, unless you have created them yourself and know they are correct. It is possible to remove the local variable table completely or have the local variable table completely wrong and still have valid and working bytecode. LocalVariableTables like LineNumberTables are not compulsory and are only there as debugging structures. The only way I know of to get local variable information you can trust is from the instructions themselves. I hope this helps Bye Arrin Eric Sheridan wrote: >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 > > > -- Conventional wisdom says to know your limits. To know your limits you need to find them first. Finding you limits generally involves getting in over your head and hoping you live long enough to benefit from the experience. That's the fun part.