views:

99

answers:

1

I'm currently writing a program in which I would like to access the variable names of local variables during execution of a program and pass them off externally. I'm aware that Java will dump local variable names during compilation unless compiled in debug mode.

After looking around some, it seems that JDI/JPDA is the way to go for this kind of work. Assuming ref refers to a ThreadReference, the following is what I have thus far:

ref.suspend();
StackFrame currentFrame = ref.frame(0);
List<LocalVariable> vars = currentFrame.visibleVariables();
ref.resume();

Two questions:

  1. Am I on the right track, or is there a better way to do this?
  2. How do I acquire the ThreadReference to set to ref? LocatableEvent seems to be what I need, but can anyone provide an example on how to use it?

Many thanks in advance!

+1  A: 

Not a lot of people have experience with this stuff.
If I were in you shoes I would look at the sample code ( http://download.oracle.com/docs/cd/E17409_01/javase/6/docs/technotes/guides/jpda/examples.html ) and also at the JPDA docs

Romain Hippeau
Looks like this is the best I'm going to get... :) Thanks for the info, but I found the JDPA docs to be super confusing.
allie