我正在编写一个程序,我希望在程序执行期间访问局部变量的变量名,并将它们从外部传递出去。 我知道Java在编译期间会转储局部变量名称,除非在调试模式下编译。
看过一些后,看来JDI / JPDA是这种工作的方式。 假设ref引用一个ThreadReference ,以下是我到目前为止:
ref.suspend(); StackFrame currentFrame = ref.frame(0); List<LocalVariable> vars = currentFrame.visibleVariables(); ref.resume();两个问题:
我在正确的轨道上,还是有更好的方法来做到这一点? 我如何获得设置为ref的ThreadReference ? LocatableEvent似乎是我需要的,但任何人都可以提供如何使用它的例子吗?提前谢谢了!
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:
Am I on the right track, or is there a better way to do this? 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!
最满意答案
没有很多人有这方面的经验。
寻找答案。 我有链接到代码,但他们不再。 无法删除这个答案,因为它被接受的答案。
Not a lot of people have experience with this stuff.
Look elsewhere for an answer. I had links to code but they are no longer. Cannot delete this answer because it was accepted answer.
更多推荐
发布评论