2 Test expression command options.
7 Test expression command options.
12 import lldbsuite
.test
.lldbutil
as lldbutil
13 from lldbsuite
.test
.decorators
import *
14 from lldbsuite
.test
.lldbtest
import *
17 class ExprOptionsTestCase(TestBase
):
19 # Call super's setUp().
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")
27 def test_expr_options(self
):
28 """These expression command options should work as expected."""
31 # Set debugger into synchronous mode
32 self
.dbg
.SetAsync(False)
34 (target
, process
, thread
, bkpt
) = lldbutil
.run_to_source_breakpoint(
35 self
, "// breakpoint_in_main", self
.main_source_spec
38 frame
= thread
.GetFrameAtIndex(0)
39 options
= lldb
.SBExpressionOptions()
41 # test --language on C++ expression using the SB API's
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
)
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
)
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())
63 def test_expr_options_lang(self
):
64 """These expression language options should work as expected."""
67 # Set debugger into synchronous mode
68 self
.dbg
.SetAsync(False)
70 (target
, process
, thread
, bkpt
) = lldbutil
.run_to_source_breakpoint(
71 self
, "// breakpoint_in_main", self
.main_source_spec
74 frame
= thread
.GetFrameAtIndex(0)
75 options
= lldb
.SBExpressionOptions()
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
)
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())