diff --git a/lldb/source/Commands/CommandObjectExpression.cpp b/lldb/source/Commands/CommandObjectExpression.cpp --- a/lldb/source/Commands/CommandObjectExpression.cpp +++ b/lldb/source/Commands/CommandObjectExpression.cpp @@ -408,6 +408,13 @@ lldb::ValueObjectSP result_valobj_sp; StackFrame *frame = exe_ctx.GetFramePtr(); + if (m_command_options.top_level && !m_command_options.allow_jit) { + result.AppendErrorWithFormat( + "Can't disable JIT compilation for top-level expressions.\n"); + result.SetStatus(eReturnStatusFailed); + return false; + } + const EvaluateExpressionOptions options = GetEvalOptions(target); ExpressionResults success = target.EvaluateExpression( expr, frame, result_valobj_sp, options, &m_fixed_expression); diff --git a/lldb/test/API/commands/expression/dont_allow_jit/TestAllowJIT.py b/lldb/test/API/commands/expression/dont_allow_jit/TestAllowJIT.py --- a/lldb/test/API/commands/expression/dont_allow_jit/TestAllowJIT.py +++ b/lldb/test/API/commands/expression/dont_allow_jit/TestAllowJIT.py @@ -80,3 +80,16 @@ self.assertSuccess(result.GetError()) self.assertEqual(result.GetValueAsSigned(), 18, "got the right value.") + def test_allow_jit_with_top_level(self): + """Test combined --allow-jit and --top-level flags""" + # Can't force interpreting for top-level expressions which are always + # injected. + self.expect("expr --allow-jit false --top-level -- int i;", error=True, + substrs=["Can't disable JIT compilation for top-level expressions."]) + + self.build() + lldbutil.run_to_source_breakpoint(self, "Set a breakpoint here", lldb.SBFileSpec("main.c")) + # Allowing JITing for top-level expressions is redundant but should work. + self.expect("expr --allow-jit true --top-level -- int top_level_f() { return 2; }") + # Make sure we actually declared a working top-level function. + self.expect_expr("top_level_f()", result_value="2")