简体   繁体   English

JVMTI GetLocalVariableTable()始终提供JVMTI_ERROR_ABSENT_INFORMATION

[英]JVMTI GetLocalVariableTable() always gives JVMTI_ERROR_ABSENT_INFORMATION

First of all, I have tried to find the solution to my problem for a while, but got nothing useful. 首先,一段时间以来,我一直试图找到解决问题的方法,但没有任何用处。 Therefore, I want to have some suggestions from the experts. 因此,我想向专家们提出一些建议。

I'm using JVMTI to write an agent, in which I need to get local variable info of some method. 我正在使用JVMTI编写代理,在其中我需要获取某种方法的局部变量信息。 Here's the summary of what I did: 这是我所做的摘要:

(1) Turn on the corresponding capability. (1)打开相应的功能。

JNIEXPORT jint JNICALL
Agent_OnLoad(JavaVM *jvm, char *options, void *reserved)
{
  ...
  jvmtiCapabilities capa = {0};
  ...
  capa.can_access_local_variables = 1;
  ...
}

(2) During the live phase (in my case, the handler of VMInit event), get the jclass through JNI FindClass() , and then get the jmethodID through JNI GetMethodID() (of course, if it's static method, I use GetStaticMethodID() ). (2)在直播阶段(在我的情况下,处理程序VMInit事件),得到jclass通过JNI FindClass()然后拿到jmethodID通过JNI GetMethodID()当然,如果它的静态方法,我用GetStaticMethodID() )。 Each step is checked, and jclass and jmethodID are all good. 每一步都经过检查,并且jclassjmethodID都很好。

(3) Then, I try to get the local variable table. (3)然后,我尝试获取局部变量表。

...
jvmtiLocalVariableEntry *entTab = NULL;
jint entCnt = 0;
jvmtiError errNum = jvmti->GetLocalVariableTable(mthID, &entCnt, &entTab);
...

I checked the errNum, and find it is JVMTI_ERROR_ABSENT_INFORMATION every time. 我检查了errNum,发现它每次都是JVMTI_ERROR_ABSENT_INFORMATION。 I also tried this in other event handlers, which behave the same. 我也在其他事件处理程序中尝试过,它们的行为相同。

Any ideas or suggestions? 有什么想法或建议吗?

Thanks! 谢谢!

The JVMTI_ERROR_ABSENT_INFORMATION error indicates that the method you're trying to load the local variable table for doesn't have a proper LocalVariableTable attribute in the corresponding file. JVMTI_ERROR_ABSENT_INFORMATION错误指示您尝试为其加载局部变量表的方法在相应的文件中没有适当的LocalVariableTable属性。

If you have access to the original source code, you can compile it with javac using the -g option to generate it. 如果您有权访问原始源代码,则可以使用-g选项使用javac对其进行javac以生成它。

If you just want to get the method signature information, you can try the GetMethodName function. 如果只想获取方法签名信息,则可以尝试GetMethodName函数。 Otherwise, you need to obtain a stack frame containing the method in question and you can retrieve the values of all the local variables using GetLocal* by passing in the slot number. 否则,您需要获取一个包含所讨论方法的堆栈框架,并且可以通过传入插槽号来使用GetLocal *检索所有局部变量的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM