Slide 17
Slide 17 text
JVMTI - Get Stack Trace
/* Get Stack Trace */
err = (*jvmti)->GetStackTrace(jvmti, thr, 0, 5, &frames, &count);
if (err != JVMTI_ERROR_NONE) {
printf("(GetThreadInfo) Error expected: %d, got: %d\n", JVMTI_ERROR_NONE, err);
describe(err);
printf("\n");
}
printf("Number of records filled: %d\n", count);
if (err == JVMTI_ERROR_NONE && count >=1) {
char *methodName;
methodName = "yet_to_call()";
char *declaringClassName;
jclass declaring_class;
int i=0;
printf("Exception Stack Trace\n");
printf("=====================\n");
printf("Stack Trace Depth: %d\n", count);
for ( i=0; i < count; i++) {
err = (*jvmti)->GetMethodName(jvmti, frames[i].method, &methodName, NULL, NULL);
if (err == JVMTI_ERROR_NONE) {
err = (*jvmti)->GetMethodDeclaringClass(jvmti, frames[i].method, &declaring_class);
err = (*jvmti)->GetClassSignature(jvmti, declaring_class, &declaringClassName, NULL);
if (err == JVMTI_ERROR_NONE) {
printf("at method %s() in class %s\n", methodName, declaringClassName);
}
}
}
}
17
*A lot of code*