8201224: Make string buffer size dynamic in mlvmJvmtiUtils.c

Calculate the string size for the buffer first

Reviewed-by: amenkov, sspitsyn, iklam
This commit is contained in:
Jean Christophe Beyler 2018-08-22 09:33:18 -07:00
parent 51f697962c
commit 49b859b9d3
3 changed files with 44 additions and 12 deletions
test/hotspot/jtreg/vmTestbase/vm/mlvm
indy/func/jvmti
share

@ -165,8 +165,14 @@ SingleStep(jvmtiEnv *jvmti_env,
char * locStr;
gIsSingleStepWorking = JNI_TRUE;
locStr = locationToString(jvmti_env, method, location);
NSK_DISPLAY1("Single step event: %s\n", locStr);
free(locStr);
if (locStr == NULL) {
NSK_DISPLAY0("Error in Single step event: locationToString failed\n");
gIsErrorOccured = JNI_TRUE;
} else {
NSK_DISPLAY1("Single step event: %s\n", locStr);
free(locStr);
}
popFrameLogic(jvmti_env, thread);
}

@ -37,6 +37,7 @@ static char * gszDebuggeeClassName = "NONE";
static jboolean gIsMethodEntryWorking = JNI_FALSE;
static jboolean gIsSingleStepWorking = JNI_FALSE;
static jboolean gIsBreakpointWorking = JNI_FALSE;
static jboolean gErrorHappened = JNI_FALSE;
static jboolean gIsBreakpointSet = JNI_FALSE;
static jboolean gIsFirstCall = JNI_TRUE;
@ -63,7 +64,8 @@ Java_vm_mlvm_indy_func_jvmti_stepBreakPopReturn_INDIFY_1Test_checkStatus(JNIEnv
if ( ! gIsDebuggerCompatible )
NSK_DISPLAY1("Breakpoint event fired? %i\n", gIsBreakpointWorking);
return gIsMethodEntryWorking && gIsSingleStepWorking && (gIsBreakpointWorking || gIsDebuggerCompatible);
return gIsMethodEntryWorking && !gErrorHappened && gIsSingleStepWorking
&& (gIsBreakpointWorking || gIsDebuggerCompatible);
}
static void JNICALL
@ -103,8 +105,14 @@ SingleStep(jvmtiEnv *jvmti_env,
gIsSingleStepWorking = JNI_TRUE;
locStr = locationToString(jvmti_env, method, location);
NSK_DISPLAY1("Single step event: %s\n", locStr);
free(locStr);
if (locStr == NULL) {
NSK_DISPLAY0("Error: Single step event has no location\n");
gErrorHappened = JNI_TRUE;
} else {
NSK_DISPLAY1("Single step event: %s\n", locStr);
free(locStr);
}
NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, gJvmtiEnv, JVMTI_DISABLE, JVMTI_EVENT_SINGLE_STEP, NULL));
@ -140,8 +148,13 @@ Breakpoint(jvmtiEnv *jvmti_env,
gIsBreakpointWorking = JNI_TRUE;
locStr = locationToString(jvmti_env, method, location);
NSK_DISPLAY1("Breakpoint event at: %s\n", locStr);
free(locStr);
if (locStr == NULL) {
NSK_DISPLAY0("Error: Breakpoint event has no location\n");
gErrorHappened = JNI_TRUE;
} else {
NSK_DISPLAY1("Breakpoint event at: %s\n", locStr);
free(locStr);
}
NSK_JVMTI_VERIFY(NSK_CPP_STUB3(ClearBreakpoint, jvmti_env, method, location));
NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, gJvmtiEnv, JVMTI_DISABLE, JVMTI_EVENT_BREAKPOINT, NULL));

@ -76,18 +76,31 @@ struct MethodName * getMethodName(jvmtiEnv * pJvmtiEnv, jmethodID method) {
char * locationToString(jvmtiEnv * pJvmtiEnv, jmethodID method, jlocation location) {
struct MethodName * pMN;
// gcc 7.3 claims that snprintf below can output between 6 and 531 bytes. Setting buffer size to 600.
char r[600];
int len;
char * result;
const char * const format = "%s .%s :" JLONG_FORMAT;
pMN = getMethodName(pJvmtiEnv, method);
if ( ! pMN )
return strdup("NONE");
snprintf(r, sizeof(r), "%s .%s :%lx", pMN->classSig, pMN->methodName, (long) location);
len = snprintf(NULL, 0, format, pMN->classSig, pMN->methodName, location) + 1;
if (len <= 0) {
free(pMN);
return NULL;
}
result = malloc(len);
if (result == NULL) {
free(pMN);
return NULL;
}
snprintf(result, len, format, pMN->classSig, pMN->methodName, location);
free(pMN);
return strdup(r);
return result;
}
void * getTLS(jvmtiEnv * pJvmtiEnv, jthread thread, jsize sizeToAllocate) {