JDevlieghere created this revision. JDevlieghere added reviewers: jingham, Michael137, teemperor. Herald added a project: All. JDevlieghere requested review of this revision.
Check the interrupt flag while interpreting IR expressions and allow the user to interrupt them. https://reviews.llvm.org/D156822 Files: lldb/source/Expression/IRInterpreter.cpp lldb/test/API/commands/expression/ir-interpreter/TestIRInterpreter.py
Index: lldb/test/API/commands/expression/ir-interpreter/TestIRInterpreter.py =================================================================== --- lldb/test/API/commands/expression/ir-interpreter/TestIRInterpreter.py +++ lldb/test/API/commands/expression/ir-interpreter/TestIRInterpreter.py @@ -47,6 +47,40 @@ self.assertGreaterEqual(duration_sec, 1) self.assertLess(duration_sec, 30) + def test_interpreter_interrupt(self): + """Test interrupting the IRInterpreter.""" + self.build() + self.target = self.dbg.CreateTarget(self.getBuildArtifact("a.out")) + self.assertTrue(self.target, VALID_TARGET) + + # A non-trivial infinite loop. + inf_loop = "for (unsigned i = 0; i < 100; ++i) --i; 1" + + options = lldb.SBExpressionOptions() + + # This is an IRInterpreter specific test, so disable the JIT. + options.SetAllowJIT(False) + + # Make sure we have a pretty long (10s) timeout so we have a chance to + # interrupt the interpreted expression. + options.SetTimeoutInMicroSeconds(10000000) + + self.dbg.RequestInterrupt() + + self.dbg.SetAsync(True) + res = self.target.EvaluateExpression(inf_loop, options) + self.dbg.SetAsync(False) + + # Be sure to turn this off again: + def cleanup(): + if self.dbg.InterruptRequested(): + self.dbg.CancelInterruptRequest() + + self.addTearDownHook(cleanup) + + interrupt_error = "Interrupted while interpreting expression" + self.assertIn(interrupt_error, str(res.GetError())) + def setUp(self): # Call super's setUp(). TestBase.setUp(self) Index: lldb/source/Expression/IRInterpreter.cpp =================================================================== --- lldb/source/Expression/IRInterpreter.cpp +++ lldb/source/Expression/IRInterpreter.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "lldb/Expression/IRInterpreter.h" +#include "lldb/Core/Debugger.h" #include "lldb/Core/Module.h" #include "lldb/Core/ModuleSpec.h" #include "lldb/Core/ValueObject.h" @@ -464,6 +465,8 @@ "Interpreter doesn't handle one of the expression's operands"; static const char *interpreter_internal_error = "Interpreter encountered an internal error"; +static const char *interrupt_error = + "Interrupted while interpreting expression"; static const char *bad_value_error = "Interpreter couldn't resolve a value during execution"; static const char *memory_allocation_error = @@ -726,6 +729,9 @@ frame.Jump(&function.front()); + lldb_private::Process *process = exe_ctx.GetProcessPtr(); + lldb_private::Target* target = exe_ctx.GetTargetPtr(); + using clock = std::chrono::steady_clock; // Compute the time at which the timeout has been exceeded. @@ -741,6 +747,15 @@ return false; } + // If we have access to the debugger we can honor an interrupt request. + if (target) { + if (INTERRUPT_REQUESTED(target->GetDebugger(), "Interrupted in IR interpreting.")) { + error.SetErrorToGenericError(); + error.SetErrorString(interrupt_error); + return false; + } + } + const Instruction *inst = &*frame.m_ii; LLDB_LOGF(log, "Interpreting %s", PrintValue(inst).c_str()); @@ -1432,7 +1447,7 @@ } // Make sure we have a valid process - if (!exe_ctx.GetProcessPtr()) { + if (!process) { error.SetErrorToGenericError(); error.SetErrorString("unable to get the process"); return false; @@ -1538,10 +1553,10 @@ return false; } - exe_ctx.GetProcessPtr()->SetRunningUserExpression(true); + process->SetRunningUserExpression(true); // Execute the actual function call thread plan - lldb::ExpressionResults res = exe_ctx.GetProcessRef().RunThreadPlan( + lldb::ExpressionResults res = process->RunThreadPlan( exe_ctx, call_plan_sp, options, diagnostics); // Check that the thread plan completed successfully @@ -1551,7 +1566,7 @@ return false; } - exe_ctx.GetProcessPtr()->SetRunningUserExpression(false); + process->SetRunningUserExpression(false); // Void return type if (returnType->isVoidTy()) {
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits