I'm writing a native agent to java using the JVMTI libraries and trying to get the capability for accessing local variables. when loading the agent in the OnLoad phase that capability can be enabled, but when loading it in the live phase (OnAttach) is seems to be not possible and when I'm trying to add it I'm getting the error - JVMTI_ERROR_ABSENT_INFORMATION.
That is my OnAttach function (C language)
JNIEXPORT
jint
JNICALL
Agent_OnAttach(
JavaVM *jvm,
char *options,
void *reserved
)
{
jvmtiEnv *jvmti;
jvmtiCapabilities PotentialCap, RequestedCap;
jvmtiError error;
memset(&RequestedCap, 0, sizeof(RequestedCap));
jvm->GetEnv((PVOID*)&jvmti, JVMTI_VERSION_1_0);
jvmti->GetPotentialCapabilities(&PotentialCap);
RequestedCap.can_access_local_variables = 1;
error = jvmti->AddCapabilities(&RequestedCap);
if (error != JVMTI_ERROR_NONE)
{
MessageBox(
NULL,
L"Fail to request local variable access",
L"Native Agent",
NULL);
}
return JNI_OK;
}
Is there any way to enable local variable access in live phase?
Thanks