Fix JVMTI GetStackTrace bug
GetStackTrace would incorrectly return ERR(ILLEGAL_ARGUMENT) if the
number frames returned was less then the start depth and start depth
was >= 0. This made some legal stack trace calls impossible.
Instead it should have been checking that at least one frame was
retrieved (since otherwise the start-depth was off the stack).
Test: ./test.py --host
Bug: 132196976
Change-Id: I9f959569f90dbb75de0010173b119472a4b5864e
diff --git a/openjdkjvmti/ti_stack.cc b/openjdkjvmti/ti_stack.cc
index 62204c9..75f0556 100644
--- a/openjdkjvmti/ti_stack.cc
+++ b/openjdkjvmti/ti_stack.cc
@@ -232,7 +232,7 @@
size_t index = 0;
};
-jvmtiError StackUtil::GetStackTrace(jvmtiEnv* jvmti_env ATTRIBUTE_UNUSED,
+jvmtiError StackUtil::GetStackTrace(jvmtiEnv* jvmti_env,
jthread java_thread,
jint start_depth,
jint max_frame_count,
@@ -282,7 +282,9 @@
return ERR(THREAD_NOT_ALIVE);
}
*count_ptr = static_cast<jint>(closure.index);
- if (closure.index < static_cast<size_t>(start_depth)) {
+ if (closure.index == 0) {
+ JVMTI_LOG(INFO, jvmti_env) << "The stack is not large enough for a start_depth of "
+ << start_depth << ".";
return ERR(ILLEGAL_ARGUMENT);
}
return ERR(NONE);