]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/lang/cpp/class_static/TestStaticVariables.py
Vendor import of lldb release_39 branch r276489:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / lang / cpp / class_static / TestStaticVariables.py
1 """
2 Test display and Python APIs on file and class static variables.
3 """
4
5 from __future__ import print_function
6
7
8
9 import os, time
10 import lldb
11 from lldbsuite.test.decorators import *
12 from lldbsuite.test.lldbtest import *
13 from lldbsuite.test import lldbutil
14
15 class StaticVariableTestCase(TestBase):
16
17     mydir = TestBase.compute_mydir(__file__)
18
19     def setUp(self):
20         # Call super's setUp().
21         TestBase.setUp(self)
22         # Find the line number to break at.
23         self.line = line_number('main.cpp', '// Set break point at this line.')
24
25     @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24764")
26     def test_with_run_command(self):
27         """Test that file and class static variables display correctly."""
28         self.build()
29         self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
30
31         lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
32
33         self.runCmd("run", RUN_SUCCEEDED)
34
35         # The stop reason of the thread should be breakpoint.
36         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
37             substrs = ['stopped',
38                        'stop reason = breakpoint'])
39
40         # global variables are no longer displayed with the "frame variable" command. 
41         self.expect('target variable A::g_points', VARIABLES_DISPLAYED_CORRECTLY,
42             patterns=['\(PointType \[[1-9]*\]\) A::g_points = {.*}'])
43         self.expect('target variable g_points', VARIABLES_DISPLAYED_CORRECTLY,
44             substrs = ['(PointType [2]) g_points'])
45
46         # On Mac OS X, gcc 4.2 emits the wrong debug info for A::g_points.
47         # A::g_points is an array of two elements.
48         if self.platformIsDarwin() or self.getPlatform() == "linux":
49             self.expect("target variable A::g_points[1].x", VARIABLES_DISPLAYED_CORRECTLY,
50                 startstr = "(int) A::g_points[1].x = 11")
51
52     @expectedFailureDarwin(9980907)
53     @expectedFailureAll(compiler=["clang", "gcc"], bugnumber="Compiler emits incomplete debug info")
54     @expectedFailureAll(oslist=['freebsd'], bugnumber='llvm.org/pr20550 failing on FreeBSD-11')
55     @add_test_categories(['pyapi'])
56     def test_with_python_api(self):
57         """Test Python APIs on file and class static variables."""
58         self.build()
59         exe = os.path.join(os.getcwd(), "a.out")
60
61         target = self.dbg.CreateTarget(exe)
62         self.assertTrue(target, VALID_TARGET)
63
64         breakpoint = target.BreakpointCreateByLocation("main.cpp", self.line)
65         self.assertTrue(breakpoint, VALID_BREAKPOINT)
66
67         # Now launch the process, and do not stop at entry point.
68         process = target.LaunchSimple (None, None, self.get_process_working_directory())
69         self.assertTrue(process, PROCESS_IS_VALID)
70
71         # The stop reason of the thread should be breakpoint.
72         thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
73         self.assertIsNotNone(thread)
74
75         # Get the SBValue of 'A::g_points' and 'g_points'.
76         frame = thread.GetFrameAtIndex(0)
77
78         # arguments =>     False
79         # locals =>        False
80         # statics =>       True
81         # in_scope_only => False
82         valList = frame.GetVariables(False, False, True, False)
83
84         for val in valList:
85             self.DebugSBValue(val)
86             name = val.GetName()
87             self.assertTrue(name in ['g_points', 'A::g_points'])
88             if name == 'g_points':
89                 self.assertTrue(val.GetValueType() == lldb.eValueTypeVariableStatic)
90                 self.assertTrue(val.GetNumChildren() == 2)
91             elif name == 'A::g_points':
92                 self.assertTrue(val.GetValueType() == lldb.eValueTypeVariableGlobal)
93                 self.assertTrue(val.GetNumChildren() == 2)
94                 child1 = val.GetChildAtIndex(1)
95                 self.DebugSBValue(child1)
96                 child1_x = child1.GetChildAtIndex(0)
97                 self.DebugSBValue(child1_x)
98                 self.assertTrue(child1_x.GetTypeName() == 'int' and
99                                 child1_x.GetValue() == '11')
100
101         # SBFrame.FindValue() should also work.
102         val = frame.FindValue("A::g_points", lldb.eValueTypeVariableGlobal)
103         self.DebugSBValue(val)
104         self.assertTrue(val.GetName() == 'A::g_points')
105
106         # Also exercise the "parameter" and "local" scopes while we are at it.
107         val = frame.FindValue("argc", lldb.eValueTypeVariableArgument)
108         self.DebugSBValue(val)
109         self.assertTrue(val.GetName() == 'argc')
110
111         val = frame.FindValue("argv", lldb.eValueTypeVariableArgument)
112         self.DebugSBValue(val)
113         self.assertTrue(val.GetName() == 'argv')
114
115         val = frame.FindValue("hello_world", lldb.eValueTypeVariableLocal)
116         self.DebugSBValue(val)
117         self.assertTrue(val.GetName() == 'hello_world')