]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/expression_command/options/TestExprOptions.py
Vendor import of lldb trunk r256945:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / expression_command / options / TestExprOptions.py
1 """
2 Test expression command options.
3
4 Test cases:
5
6 o test_expr_options:
7   Test expression command options.
8 """
9
10 from __future__ import print_function
11
12
13
14 import os, time
15 import lldb
16 import lldbsuite.test.lldbutil as lldbutil
17 from lldbsuite.test.lldbtest import *
18
19 class 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
32     def test_expr_options(self):
33         """These expression command options should work as expected."""
34         self.build()
35
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
57         # test --language on C++ expression using the SB API's
58
59         # Make sure we can evaluate a C++11 expression.
60         val = frame.EvaluateExpression('foo != nullptr')
61         self.assertTrue(val.IsValid())
62         self.assertTrue(val.GetError().Success())
63         self.DebugSBValue(val)
64
65         # 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)
71
72         # 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())