2 Test display and Python APIs on file and class static variables.
5 from __future__ import print_function
11 from lldbsuite.test.decorators import *
12 from lldbsuite.test.lldbtest import *
13 from lldbsuite.test import lldbutil
16 class StaticVariableTestCase(TestBase):
18 mydir = TestBase.compute_mydir(__file__)
21 # Call super's setUp().
23 # Find the line number to break at.
24 self.line = line_number('main.cpp', '// Set break point at this line.')
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."""
30 self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
32 lldbutil.run_break_set_by_file_and_line(
33 self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
35 self.runCmd("run", RUN_SUCCEEDED)
37 # The stop reason of the thread should be breakpoint.
38 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
40 'stop reason = breakpoint'])
42 # global variables are no longer displayed with the "frame variable"
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'])
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":
55 "target variable A::g_points[1].x",
56 VARIABLES_DISPLAYED_CORRECTLY,
57 startstr="(int) A::g_points[1].x = 11")
60 oslist=lldbplatformutil.getDarwinOSTriples(),
61 bugnumber="<rdar://problem/28706946>")
66 bugnumber="Compiler emits incomplete debug info")
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."""
74 exe = os.path.join(os.getcwd(), "a.out")
76 target = self.dbg.CreateTarget(exe)
77 self.assertTrue(target, VALID_TARGET)
79 breakpoint = target.BreakpointCreateByLocation("main.cpp", self.line)
80 self.assertTrue(breakpoint, VALID_BREAKPOINT)
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)
87 # The stop reason of the thread should be breakpoint.
88 thread = lldbutil.get_stopped_thread(
89 process, lldb.eStopReasonBreakpoint)
90 self.assertIsNotNone(thread)
92 # Get the SBValue of 'A::g_points' and 'g_points'.
93 frame = thread.GetFrameAtIndex(0)
98 # in_scope_only => False
99 valList = frame.GetVariables(False, False, True, False)
102 self.DebugSBValue(val)
104 self.assertTrue(name in ['g_points', 'A::g_points'])
105 if name == 'g_points':
107 val.GetValueType() == lldb.eValueTypeVariableStatic)
108 self.assertTrue(val.GetNumChildren() == 2)
109 elif name == 'A::g_points':
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')
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')
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')
130 val = frame.FindValue("argv", lldb.eValueTypeVariableArgument)
131 self.DebugSBValue(val)
132 self.assertTrue(val.GetName() == 'argv')
134 val = frame.FindValue("hello_world", lldb.eValueTypeVariableLocal)
135 self.DebugSBValue(val)
136 self.assertTrue(val.GetName() == 'hello_world')