72
73 static void JNICALL
74 MethodEntry(jvmtiEnv *jvmti_env,
75 JNIEnv* jni_env,
76 jthread thread,
77 jmethodID method) {
78
79 struct MethodName * mn;
80
81 mn = getMethodName(jvmti_env, method);
82 if ( ! mn )
83 return;
84
85 if ( strcmp(mn->classSig, gszDebuggeeClassName) == 0 ) {
86 NSK_DISPLAY2("Entering method: %s.%s\n", mn->classSig, mn->methodName);
87
88 if ( strcmp(mn->methodName, gszDebuggeeMethodName) == 0 ) {
89 gIsMethodEntryWorking = JNI_TRUE;
90
91 if ( ! gIsBreakpointSet )
92 NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, jvmti_env, JVMTI_ENABLE, JVMTI_EVENT_SINGLE_STEP, NULL));
93 }
94 }
95
96 free(mn);
97 }
98
99 static void JNICALL
100 SingleStep(jvmtiEnv *jvmti_env,
101 JNIEnv* jni_env,
102 jthread thread,
103 jmethodID method,
104 jlocation location) {
105
106 char * locStr;
107 gIsSingleStepWorking = JNI_TRUE;
108
109 locStr = locationToString(jvmti_env, method, location);
110
111 if (locStr == NULL) {
112 NSK_DISPLAY0("Error: Single step event has no location\n");
113 gErrorHappened = JNI_TRUE;
114 } else {
115 NSK_DISPLAY1("Single step event: %s\n", locStr);
116 free(locStr);
117 }
118
119 NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, gJvmtiEnv, JVMTI_DISABLE, JVMTI_EVENT_SINGLE_STEP, NULL));
120
121 if ( ! gIsDebuggerCompatible ) {
122 if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetBreakpoint, jvmti_env, method, location)) )
123 return;
124
125 NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, gJvmtiEnv, JVMTI_ENABLE, JVMTI_EVENT_BREAKPOINT, NULL));
126 gIsBreakpointSet = JNI_TRUE;
127
128 NSK_DISPLAY0("Pop a frame\n");
129 NSK_JVMTI_VERIFY(NSK_CPP_STUB2(PopFrame, gJvmtiEnv, thread));
130 } else {
131 if ( gIsFirstCall ) {
132 NSK_DISPLAY0("Pop a frame\n");
133 NSK_JVMTI_VERIFY(NSK_CPP_STUB2(PopFrame, gJvmtiEnv, thread));
134 gIsFirstCall = JNI_FALSE;
135 } else {
136 gIsFirstCall = JNI_TRUE;
137 }
138 }
139 }
140
141 static void JNICALL
142 Breakpoint(jvmtiEnv *jvmti_env,
143 JNIEnv* jni_env,
144 jthread thread,
145 jmethodID method,
146 jlocation location) {
147
148
149 char * locStr;
150 gIsBreakpointWorking = JNI_TRUE;
151
152 locStr = locationToString(jvmti_env, method, location);
153 if (locStr == NULL) {
154 NSK_DISPLAY0("Error: Breakpoint event has no location\n");
155 gErrorHappened = JNI_TRUE;
156 } else {
157 NSK_DISPLAY1("Breakpoint event at: %s\n", locStr);
158 free(locStr);
159 }
160
161 NSK_JVMTI_VERIFY(NSK_CPP_STUB3(ClearBreakpoint, jvmti_env, method, location));
162 NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, gJvmtiEnv, JVMTI_DISABLE, JVMTI_EVENT_BREAKPOINT, NULL));
163 gIsBreakpointSet = JNI_FALSE;
164
165 NSK_DISPLAY0("Forcing early return.\n");
166 NSK_JVMTI_VERIFY(NSK_CPP_STUB3(ForceEarlyReturnInt, jvmti_env, thread, 0));
167 }
168
169 jint Agent_Initialize(JavaVM * vm, char * options, void * reserved) {
170 jvmtiEventCallbacks callbacks;
171 jvmtiCapabilities caps;
172
173 if ( ! NSK_VERIFY(nsk_jvmti_parseOptions(options)) )
174 return JNI_ERR;
175
176 if ( ! NSK_VERIFY((gJvmtiEnv = nsk_jvmti_createJVMTIEnv(vm, reserved)) != NULL) )
177 return JNI_ERR;
178
179 if ( nsk_jvmti_findOptionValue("debuggerCompatible") ) {
180 gIsDebuggerCompatible = JNI_TRUE;
181 }
182
183 memset(&caps, 0, sizeof(caps));
184 caps.can_generate_method_entry_events = 1;
185 caps.can_generate_single_step_events = 1;
186 caps.can_generate_breakpoint_events = ! gIsDebuggerCompatible;
187 caps.can_pop_frame = 1;
188 caps.can_force_early_return = 1;
189
190 if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, gJvmtiEnv, &caps)) )
191 return JNI_ERR;
192
193 memset(&callbacks, 0, sizeof(callbacks));
194 callbacks.MethodEntry = &MethodEntry;
195 callbacks.SingleStep = &SingleStep;
196 callbacks.Breakpoint = &Breakpoint;
197
198 if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, gJvmtiEnv, &callbacks, sizeof(callbacks))) )
199 return JNI_ERR;
200
201 if ( ! NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode, gJvmtiEnv, JVMTI_ENABLE, JVMTI_EVENT_METHOD_ENTRY, NULL) ) )
202 return JNI_ERR;
203
204 return JNI_OK;
205 }
206 }
|
72
73 static void JNICALL
74 MethodEntry(jvmtiEnv *jvmti_env,
75 JNIEnv* jni_env,
76 jthread thread,
77 jmethodID method) {
78
79 struct MethodName * mn;
80
81 mn = getMethodName(jvmti_env, method);
82 if ( ! mn )
83 return;
84
85 if ( strcmp(mn->classSig, gszDebuggeeClassName) == 0 ) {
86 NSK_DISPLAY2("Entering method: %s.%s\n", mn->classSig, mn->methodName);
87
88 if ( strcmp(mn->methodName, gszDebuggeeMethodName) == 0 ) {
89 gIsMethodEntryWorking = JNI_TRUE;
90
91 if ( ! gIsBreakpointSet )
92 NSK_JVMTI_VERIFY(jvmti_env->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_SINGLE_STEP, NULL));
93 }
94 }
95
96 free(mn);
97 }
98
99 static void JNICALL
100 SingleStep(jvmtiEnv *jvmti_env,
101 JNIEnv* jni_env,
102 jthread thread,
103 jmethodID method,
104 jlocation location) {
105
106 char * locStr;
107 gIsSingleStepWorking = JNI_TRUE;
108
109 locStr = locationToString(jvmti_env, method, location);
110
111 if (locStr == NULL) {
112 NSK_DISPLAY0("Error: Single step event has no location\n");
113 gErrorHappened = JNI_TRUE;
114 } else {
115 NSK_DISPLAY1("Single step event: %s\n", locStr);
116 free(locStr);
117 }
118
119 NSK_JVMTI_VERIFY(gJvmtiEnv->SetEventNotificationMode(JVMTI_DISABLE, JVMTI_EVENT_SINGLE_STEP, NULL));
120
121 if ( ! gIsDebuggerCompatible ) {
122 if ( ! NSK_JVMTI_VERIFY(jvmti_env->SetBreakpoint(method, location)) )
123 return;
124
125 NSK_JVMTI_VERIFY(gJvmtiEnv->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_BREAKPOINT, NULL));
126 gIsBreakpointSet = JNI_TRUE;
127
128 NSK_DISPLAY0("Pop a frame\n");
129 NSK_JVMTI_VERIFY(gJvmtiEnv->PopFrame(thread));
130 } else {
131 if ( gIsFirstCall ) {
132 NSK_DISPLAY0("Pop a frame\n");
133 NSK_JVMTI_VERIFY(gJvmtiEnv->PopFrame(thread));
134 gIsFirstCall = JNI_FALSE;
135 } else {
136 gIsFirstCall = JNI_TRUE;
137 }
138 }
139 }
140
141 static void JNICALL
142 Breakpoint(jvmtiEnv *jvmti_env,
143 JNIEnv* jni_env,
144 jthread thread,
145 jmethodID method,
146 jlocation location) {
147
148
149 char * locStr;
150 gIsBreakpointWorking = JNI_TRUE;
151
152 locStr = locationToString(jvmti_env, method, location);
153 if (locStr == NULL) {
154 NSK_DISPLAY0("Error: Breakpoint event has no location\n");
155 gErrorHappened = JNI_TRUE;
156 } else {
157 NSK_DISPLAY1("Breakpoint event at: %s\n", locStr);
158 free(locStr);
159 }
160
161 NSK_JVMTI_VERIFY(jvmti_env->ClearBreakpoint(method, location));
162 NSK_JVMTI_VERIFY(gJvmtiEnv->SetEventNotificationMode(JVMTI_DISABLE, JVMTI_EVENT_BREAKPOINT, NULL));
163 gIsBreakpointSet = JNI_FALSE;
164
165 NSK_DISPLAY0("Forcing early return.\n");
166 NSK_JVMTI_VERIFY(jvmti_env->ForceEarlyReturnInt(thread, 0));
167 }
168
169 jint Agent_Initialize(JavaVM * vm, char * options, void * reserved) {
170 jvmtiEventCallbacks callbacks;
171 jvmtiCapabilities caps;
172
173 if ( ! NSK_VERIFY(nsk_jvmti_parseOptions(options)) )
174 return JNI_ERR;
175
176 if ( ! NSK_VERIFY((gJvmtiEnv = nsk_jvmti_createJVMTIEnv(vm, reserved)) != NULL) )
177 return JNI_ERR;
178
179 if ( nsk_jvmti_findOptionValue("debuggerCompatible") ) {
180 gIsDebuggerCompatible = JNI_TRUE;
181 }
182
183 memset(&caps, 0, sizeof(caps));
184 caps.can_generate_method_entry_events = 1;
185 caps.can_generate_single_step_events = 1;
186 caps.can_generate_breakpoint_events = ! gIsDebuggerCompatible;
187 caps.can_pop_frame = 1;
188 caps.can_force_early_return = 1;
189
190 if ( ! NSK_JVMTI_VERIFY(gJvmtiEnv->AddCapabilities(&caps)) )
191 return JNI_ERR;
192
193 memset(&callbacks, 0, sizeof(callbacks));
194 callbacks.MethodEntry = &MethodEntry;
195 callbacks.SingleStep = &SingleStep;
196 callbacks.Breakpoint = &Breakpoint;
197
198 if ( ! NSK_JVMTI_VERIFY(gJvmtiEnv->SetEventCallbacks(&callbacks, sizeof(callbacks))) )
199 return JNI_ERR;
200
201 if ( ! NSK_JVMTI_VERIFY(gJvmtiEnv->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_METHOD_ENTRY, NULL) ) )
202 return JNI_ERR;
203
204 return JNI_OK;
205 }
206 }
|