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