88 lines · python
1"""2Test expression command options.3 4Test cases:5 6o test_expr_options:7 Test expression command options.8"""9 10 11import lldb12import lldbsuite.test.lldbutil as lldbutil13from lldbsuite.test.decorators import *14from lldbsuite.test.lldbtest import *15 16 17class ExprOptionsTestCase(TestBase):18 def setUp(self):19 # Call super's setUp().20 TestBase.setUp(self)21 22 self.main_source = "main.cpp"23 self.main_source_spec = lldb.SBFileSpec(self.main_source)24 self.line = line_number("main.cpp", "// breakpoint_in_main")25 self.exe = self.getBuildArtifact("a.out")26 27 def test_expr_options(self):28 """These expression command options should work as expected."""29 self.build()30 31 # Set debugger into synchronous mode32 self.dbg.SetAsync(False)33 34 (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(35 self, "// breakpoint_in_main", self.main_source_spec36 )37 38 frame = thread.GetFrameAtIndex(0)39 options = lldb.SBExpressionOptions()40 41 # test --language on C++ expression using the SB API's42 43 # Make sure we can evaluate a C++11 expression.44 val = frame.EvaluateExpression("foo != nullptr")45 self.assertTrue(val.IsValid())46 self.assertSuccess(val.GetError())47 self.DebugSBValue(val)48 49 # Make sure it still works if language is set to C++11:50 options.SetLanguage(lldb.eLanguageTypeC_plus_plus_11)51 val = frame.EvaluateExpression("foo != nullptr", options)52 self.assertTrue(val.IsValid())53 self.assertSuccess(val.GetError())54 self.DebugSBValue(val)55 56 # Make sure it fails if language is set to C:57 options.SetLanguage(lldb.eLanguageTypeC)58 val = frame.EvaluateExpression("foo != nullptr", options)59 self.assertTrue(val.IsValid())60 self.assertFalse(val.GetError().Success())61 62 def test_expr_options_lang(self):63 """These expression language options should work as expected."""64 self.build()65 66 # Set debugger into synchronous mode67 self.dbg.SetAsync(False)68 69 (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(70 self, "// breakpoint_in_main", self.main_source_spec71 )72 73 frame = thread.GetFrameAtIndex(0)74 options = lldb.SBExpressionOptions()75 76 # Make sure we can retrieve `id` variable if language is set to C++11:77 options.SetLanguage(lldb.eLanguageTypeC_plus_plus_11)78 val = frame.EvaluateExpression("id == 0", options)79 self.assertTrue(val.IsValid())80 self.assertSuccess(val.GetError())81 self.DebugSBValue(val)82 83 # Make sure we can't retrieve `id` variable if language is set to ObjC:84 options.SetLanguage(lldb.eLanguageTypeObjC)85 val = frame.EvaluateExpression("id == 0", options)86 self.assertTrue(val.IsValid())87 self.assertFalse(val.GetError().Success())88