@@ -71,6 +71,8 @@ import org.jetbrains.kotlin.psi.*
71
71
import org.jetbrains.kotlin.psi.codeFragmentUtil.debugTypeInfo
72
72
import org.jetbrains.kotlin.psi.codeFragmentUtil.suppressDiagnosticsInDebugMode
73
73
import org.jetbrains.kotlin.resolve.AnalyzingUtils
74
+ import org.jetbrains.kotlin.resolve.DescriptorUtils
75
+ import org.jetbrains.kotlin.resolve.jvm.AsmTypes
74
76
import org.jetbrains.kotlin.resolve.BindingContext
75
77
import org.jetbrains.kotlin.resolve.BindingTrace
76
78
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
@@ -79,6 +81,9 @@ import org.jetbrains.org.objectweb.asm.*
79
81
import org.jetbrains.org.objectweb.asm.Opcodes.ASM5
80
82
import org.jetbrains.org.objectweb.asm.tree.MethodNode
81
83
import java.util.*
84
+ import java.util.concurrent.Executors
85
+ import java.util.concurrent.TimeUnit
86
+ import java.util.concurrent.TimeoutException
82
87
83
88
internal val RECEIVER_NAME = " \$ receiver"
84
89
internal val THIS_NAME = " this"
@@ -144,6 +149,10 @@ class KotlinEvaluator(val codeFragment: KtCodeFragment, val sourcePosition: Sour
144
149
145
150
return result.toJdiValue(context)
146
151
}
152
+ catch (e: TimeoutException ) {
153
+ // TODO logError(e)
154
+ exception(" Evaluation of ${codeFragment.getText()} was interrupted because it took more than 10 seconds" )
155
+ }
147
156
catch (e: EvaluateException ) {
148
157
throw e
149
158
}
@@ -159,9 +168,9 @@ class KotlinEvaluator(val codeFragment: KtCodeFragment, val sourcePosition: Sour
159
168
attachmentByPsiFile(codeFragment),
160
169
Attachment (" breakpoint.info" , " line: ${sourcePosition.line} " ))
161
170
LOG .error(LogMessageEx .createEvent(
162
- " Couldn't evaluate expression" ,
163
- ExceptionUtil .getThrowableText(e),
164
- mergeAttachments(* attachments)))
171
+ " Couldn't evaluate expression" ,
172
+ ExceptionUtil .getThrowableText(e),
173
+ mergeAttachments(* attachments)))
165
174
166
175
val cause = if (e.message != null ) " : ${e.message} " else " "
167
176
exception(" An exception occurs during Evaluate Expression Action $cause " )
@@ -238,11 +247,27 @@ class KotlinEvaluator(val codeFragment: KtCodeFragment, val sourcePosition: Sour
238
247
context.suspendContext.thread?.threadReference!! ,
239
248
context.suspendContext.getInvokePolicy())
240
249
241
- resultValue = interpreterLoop(
242
- this ,
243
- makeInitialFrame(this , args.zip(argumentTypes).map { boxOrUnboxArgumentIfNeeded(eval, it.first, it.second) }),
244
- eval
245
- )
250
+ val executor = Executors .newSingleThreadExecutor();
251
+ val future = executor.submit {
252
+ resultValue = interpreterLoop(
253
+ this ,
254
+ makeInitialFrame(this , args.zip(argumentTypes).map { boxOrUnboxArgumentIfNeeded(eval, it.first, it.second) }),
255
+ eval
256
+ )
257
+ }
258
+
259
+ try {
260
+ future.get(10 , TimeUnit .SECONDS )
261
+ }
262
+ catch (e: TimeoutException ) {
263
+ context.suspendContext.thread?.threadReference?.resume()
264
+ throw e
265
+ }
266
+ finally {
267
+ executor.shutdownNow()
268
+
269
+ allRequests.forEach { it.enable() }
270
+ }
246
271
247
272
allRequests.forEach { it.enable() }
248
273
}
0 commit comments