"""
Test that --allow-jit=false does disallow JITting:
"""
import lldb
import lldbsuite.test.lldbutil as lldbutil
from lldbsuite.test.lldbtest import *
from lldbsuite.test.decorators import *
class TestAllowJIT(TestBase):
NO_DEBUG_INFO_TESTCASE = True
def test_allow_jit_expr_command(self):
"""Test the --allow-jit command line flag"""
self.build()
self.main_source_file = lldb.SBFileSpec("main.c")
self.expr_cmd_test()
def test_allow_jit_options(self):
"""Test the SetAllowJIT SBExpressionOption setting"""
self.build()
self.main_source_file = lldb.SBFileSpec("main.c")
self.expr_options_test()
def expr_cmd_test(self):
(target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
self, "Set a breakpoint here", self.main_source_file
)
frame = thread.GetFrameAtIndex(0)
interp = self.dbg.GetCommandInterpreter()
self.expect("expr --allow-jit 1 -- call_me(10)", substrs=["(int) $", "= 18"])
self.expect(
"expr --allow-jit 0 -- call_me(10)",
error=True,
substrs=["Can't evaluate the expression without a running target"],
)
def expr_options_test(self):
(target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
self, "Set a breakpoint here", self.main_source_file
)
frame = thread.GetFrameAtIndex(0)
options = lldb.SBExpressionOptions()
self.assertTrue(options.GetAllowJIT(), "Default is true")
result = frame.EvaluateExpression("call_me(10)", options)
self.assertSuccess(result.GetError())
self.assertEqual(result.GetValueAsSigned(), 18, "got the right value.")
options.SetAllowJIT(False)
self.assertFalse(options.GetAllowJIT(), "Got False after setting to False")
result = frame.EvaluateExpression("call_me(10)", options)
self.assertTrue(result.GetError().Fail(), "expression failed with no JIT")
self.assertIn(
"Can't evaluate the expression without a running target",
result.GetError().GetCString(),
"Got right error",
)
options.SetAllowJIT(True)
self.assertTrue(options.GetAllowJIT(), "Set back to True correctly")
result = frame.EvaluateExpression("call_me(10)", options)
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"""
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")
)
self.expect(
"expr --allow-jit true --top-level -- int top_level_f() { return 2; }"
)
self.expect_expr("top_level_f()", result_value="2")