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
15 class StaticVariableTestCase(TestBase):
17 mydir = TestBase.compute_mydir(__file__)
20 # Call super's setUp().
22 # Find the line number to break at.
23 self.line = line_number('main.cpp', '// Set break point at this line.')
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."""
29 self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
31 lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
33 self.runCmd("run", RUN_SUCCEEDED)
35 # The stop reason of the thread should be breakpoint.
36 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
38 'stop reason = breakpoint'])
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'])
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")
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."""
59 exe = os.path.join(os.getcwd(), "a.out")
61 target = self.dbg.CreateTarget(exe)
62 self.assertTrue(target, VALID_TARGET)
64 breakpoint = target.BreakpointCreateByLocation("main.cpp", self.line)
65 self.assertTrue(breakpoint, VALID_BREAKPOINT)
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)
71 # The stop reason of the thread should be breakpoint.
72 thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
73 self.assertIsNotNone(thread)
75 # Get the SBValue of 'A::g_points' and 'g_points'.
76 frame = thread.GetFrameAtIndex(0)
81 # in_scope_only => False
82 valList = frame.GetVariables(False, False, True, False)
85 self.DebugSBValue(val)
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')
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')
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')
111 val = frame.FindValue("argv", lldb.eValueTypeVariableArgument)
112 self.DebugSBValue(val)
113 self.assertTrue(val.GetName() == 'argv')
115 val = frame.FindValue("hello_world", lldb.eValueTypeVariableLocal)
116 self.DebugSBValue(val)
117 self.assertTrue(val.GetName() == 'hello_world')