75 #endif |
75 #endif |
76 jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { |
76 jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) { |
77 jint res; |
77 jint res; |
78 jvmtiError err; |
78 jvmtiError err; |
79 |
79 |
80 if ((res = vm->GetEnv((void **) &jvmti, JVMTI_VERSION_1_1)) != JNI_OK) { |
80 res = vm->GetEnv((void **) &jvmti, JVMTI_VERSION_1_1); |
|
81 if (res != JNI_OK) { |
81 printf("%s: Failed to call GetEnv: error=%d\n", __FILE__, res); |
82 printf("%s: Failed to call GetEnv: error=%d\n", __FILE__, res); |
82 return JNI_ERR; |
83 return JNI_ERR; |
83 } |
84 } |
84 |
85 |
85 err = jvmti->GetPotentialCapabilities(&caps); |
86 err = jvmti->GetPotentialCapabilities(&caps); |
164 "signature=\"%s\"; location=%d\n", |
165 "signature=\"%s\"; location=%d\n", |
165 i, breakpoints[i].inst?"instance":"static", |
166 i, breakpoints[i].inst?"instance":"static", |
166 breakpoints[i].m_name, breakpoints[i].m_sign, breakpoints[i].loc); |
167 breakpoints[i].m_name, breakpoints[i].m_sign, breakpoints[i].loc); |
167 } |
168 } |
168 |
169 |
169 if ((err = (jvmti->SetBreakpoint(breakpoints[i].mid, |
170 err = jvmti->SetBreakpoint(breakpoints[i].mid, breakpoints[i].loc); |
170 breakpoints[i].loc))) != JVMTI_ERROR_NONE) { |
171 if (err != JVMTI_ERROR_NONE) { |
171 printf("%s: Failed to call SetBreakpoint(): error=%d: %s\n", |
172 printf("%s: Failed to call SetBreakpoint(): error=%d: %s\n", |
172 __FILE__, err, TranslateError(err)); |
173 __FILE__, err, TranslateError(err)); |
173 return STATUS_FAILED; |
174 return STATUS_FAILED; |
174 } |
175 } |
175 |
176 |
176 err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, |
177 err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_BREAKPOINT, NULL); |
177 JVMTI_EVENT_BREAKPOINT, NULL); |
|
178 if (err != JVMTI_ERROR_NONE) { |
178 if (err != JVMTI_ERROR_NONE) { |
179 printf("Failed to enable BREAKPOINT event: %s (%d)\n", |
179 printf("Failed to enable BREAKPOINT event: %s (%d)\n", |
180 TranslateError(err), err); |
180 TranslateError(err), err); |
181 return STATUS_FAILED; |
181 return STATUS_FAILED; |
182 } |
182 } |
208 classDef.class_bytes = (unsigned char *) env->GetByteArrayElements(classBytes, NULL); |
208 classDef.class_bytes = (unsigned char *) env->GetByteArrayElements(classBytes, NULL); |
209 |
209 |
210 if (vrb == 1) |
210 if (vrb == 1) |
211 printf(">>>>>>>> Invoke RedefineClasses():\n\tnew class byte count=%d\n", |
211 printf(">>>>>>>> Invoke RedefineClasses():\n\tnew class byte count=%d\n", |
212 classDef.class_byte_count); |
212 classDef.class_byte_count); |
213 if ((err = (jvmti->RedefineClasses(1, &classDef))) != JVMTI_ERROR_NONE) { |
213 err = jvmti->RedefineClasses(1, &classDef); |
|
214 if (err != JVMTI_ERROR_NONE) { |
214 printf("%s: Failed to call RedefineClasses(): error=%d: %s\n", |
215 printf("%s: Failed to call RedefineClasses(): error=%d: %s\n", |
215 __FILE__, err, TranslateError(err)); |
216 __FILE__, err, TranslateError(err)); |
216 printf("\tFor more info about this error see the JVMTI spec.\n"); |
217 printf("\tFor more info about this error see the JVMTI spec.\n"); |
217 return STATUS_FAILED; |
218 return STATUS_FAILED; |
218 } |
219 } |
259 __FILE__, breakpoints[i].m_name, breakpoints[i].m_sign); |
260 __FILE__, breakpoints[i].m_name, breakpoints[i].m_sign); |
260 return STATUS_FAILED; |
261 return STATUS_FAILED; |
261 } |
262 } |
262 } |
263 } |
263 |
264 |
264 if ((err = (jvmti->ClearBreakpoint(breakpoints[i].mid, |
265 err = jvmti->ClearBreakpoint(breakpoints[i].mid, breakpoints[i].loc); |
265 breakpoints[i].loc))) != JVMTI_ERROR_NOT_FOUND) { |
266 if (err != JVMTI_ERROR_NOT_FOUND) { |
266 printf( |
267 printf( |
267 "TEST FAILED: Breakpoint #%d in the %s method:\n" |
268 "TEST FAILED: Breakpoint #%d in the %s method:\n" |
268 "\tname=\"%s\"; signature=\"%s\"; location=%d was not cleared:\n" |
269 "\tname=\"%s\"; signature=\"%s\"; location=%d was not cleared:\n" |
269 "\tClearBreakpoint() returned the error %d: %s\n\n", |
270 "\tClearBreakpoint() returned the error %d: %s\n\n", |
270 i, breakpoints[i].inst?"instance":"static", |
271 i, breakpoints[i].inst?"instance":"static", |
280 i, breakpoints[i].inst?"instance":"static", |
281 i, breakpoints[i].inst?"instance":"static", |
281 breakpoints[i].m_name, breakpoints[i].m_sign, |
282 breakpoints[i].m_name, breakpoints[i].m_sign, |
282 breakpoints[i].loc, err, TranslateError(err)); |
283 breakpoints[i].loc, err, TranslateError(err)); |
283 } |
284 } |
284 |
285 |
285 if ((err = (jvmti->SetBreakpoint(breakpoints[i].mid, |
286 err = jvmti->SetBreakpoint(breakpoints[i].mid, breakpoints[i].loc); |
286 breakpoints[i].loc))) == JVMTI_ERROR_DUPLICATE) { |
287 if (err == JVMTI_ERROR_DUPLICATE) { |
287 printf( |
288 printf( |
288 "TEST FAILED: the function SetBreakpoint() returned the error %d: %s\n" |
289 "TEST FAILED: the function SetBreakpoint() returned the error %d: %s\n" |
289 "\ti.e. the breakpoint #%d has not been really cleared.\n\n", |
290 "\ti.e. the breakpoint #%d has not been really cleared.\n\n", |
290 err, TranslateError(err), i); |
291 err, TranslateError(err), i); |
291 totRes = STATUS_FAILED; |
292 totRes = STATUS_FAILED; |