blob: 2c0eb6551eacc6a2341bb37f6faa723d84933dcf [file] [log] [blame]
Dawn Perchik15663c52015-07-25 00:19:39 +00001"""
2Test expression command options.
3
4Test cases:
5
6o test_expr_options:
7 Test expression command options.
8"""
9
Zachary Turner35d017f2015-10-23 17:04:29 +000010from __future__ import print_function
11
Zachary Turner0a0490b2015-10-27 20:12:05 +000012import use_lldb_suite
Zachary Turner77db4a82015-10-22 20:06:20 +000013
Dawn Perchik15663c52015-07-25 00:19:39 +000014import os, time
Dawn Perchik15663c52015-07-25 00:19:39 +000015import lldb
16import lldbutil
17from lldbtest import *
18
19class ExprOptionsTestCase(TestBase):
20
21 mydir = TestBase.compute_mydir(__file__)
22
23 def setUp(self):
24 # Call super's setUp().
25 TestBase.setUp(self)
26
27 self.main_source = "main.cpp"
28 self.main_source_spec = lldb.SBFileSpec (self.main_source)
29 self.line = line_number('main.cpp', '// breakpoint_in_main')
30 self.exe = os.path.join(os.getcwd(), "a.out")
31
Dawn Perchik009d1102015-09-04 01:02:30 +000032 def test_expr_options(self):
Dawn Perchik15663c52015-07-25 00:19:39 +000033 """These expression command options should work as expected."""
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000034 self.build()
Dawn Perchik15663c52015-07-25 00:19:39 +000035
36 # Set debugger into synchronous mode
37 self.dbg.SetAsync(False)
38
39 # Create a target by the debugger.
40 target = self.dbg.CreateTarget(self.exe)
41 self.assertTrue(target, VALID_TARGET)
42
43 # Set breakpoints inside main.
44 breakpoint = target.BreakpointCreateBySourceRegex('// breakpoint_in_main', self.main_source_spec)
45 self.assertTrue(breakpoint)
46
47 # Now launch the process, and do not stop at entry point.
48 process = target.LaunchSimple(None, None, self.get_process_working_directory())
49 self.assertTrue(process, PROCESS_IS_VALID)
50
51 threads = lldbutil.get_threads_stopped_at_breakpoint(process, breakpoint)
52 self.assertEqual(len(threads), 1)
53
54 frame = threads[0].GetFrameAtIndex(0)
55 options = lldb.SBExpressionOptions()
56
Dawn Perchik009d1102015-09-04 01:02:30 +000057 # test --language on C++ expression using the SB API's
Dawn Perchik15663c52015-07-25 00:19:39 +000058
Dawn Perchik009d1102015-09-04 01:02:30 +000059 # Make sure we can evaluate 'ns::func'.
60 val = frame.EvaluateExpression('foo != nullptr')
61 self.assertTrue(val.IsValid())
62 self.assertTrue(val.GetError().Success())
63 self.DebugSBValue(val)
Dawn Perchik15663c52015-07-25 00:19:39 +000064
Dawn Perchik009d1102015-09-04 01:02:30 +000065 # Make sure it still works if language is set to C++11:
66 options.SetLanguage(lldb.eLanguageTypeC_plus_plus_11)
67 val = frame.EvaluateExpression('foo != nullptr', options)
68 self.assertTrue(val.IsValid())
69 self.assertTrue(val.GetError().Success())
70 self.DebugSBValue(val)
Dawn Perchik15663c52015-07-25 00:19:39 +000071
Dawn Perchik009d1102015-09-04 01:02:30 +000072 # Make sure it fails if language is set to C:
73 options.SetLanguage(lldb.eLanguageTypeC)
74 val = frame.EvaluateExpression('foo != nullptr', options)
75 self.assertTrue(val.IsValid())
76 self.assertFalse(val.GetError().Success())