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