Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / test / API / lang / c / global_variables / TestGlobalVariables.py
blobcfed00b9327c12640d2732a70631f37652914bef
1 """Show global variables and check that they do indeed have global scopes."""
4 from lldbsuite.test.decorators import *
5 from lldbsuite.test.lldbtest import *
6 from lldbsuite.test import lldbutil
9 class GlobalVariablesTestCase(TestBase):
10 def setUp(self):
11 # Call super's setUp().
12 TestBase.setUp(self)
13 # Find the line number to break inside main().
14 self.source = "main.c"
15 self.line = line_number(self.source, "// Set break point at this line.")
16 self.shlib_names = ["a"]
18 @skipIfDarwin # Chained Fixups
19 @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24764")
20 def test_without_process(self):
21 """Test that static initialized variables can be inspected without
22 process."""
23 self.build()
25 # Create a target by the debugger.
26 target = self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
28 self.assertTrue(target, VALID_TARGET)
29 self.expect(
30 "target variable g_ptr", VARIABLES_DISPLAYED_CORRECTLY, substrs=["(int *)"]
32 self.expect(
33 "target variable *g_ptr", VARIABLES_DISPLAYED_CORRECTLY, substrs=["42"]
36 @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24764")
37 def test_c_global_variables(self):
38 """Test 'frame variable --scope --no-args' which omits args and shows scopes."""
39 self.build()
41 # Create a target by the debugger.
42 target = self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
43 self.assertTrue(target, VALID_TARGET)
45 # Break inside the main.
46 lldbutil.run_break_set_by_file_and_line(
47 self, self.source, self.line, num_expected_locations=1, loc_exact=True
50 # Register our shared libraries for remote targets so they get
51 # automatically uploaded
52 environment = self.registerSharedLibrariesWithTarget(target, self.shlib_names)
54 # Now launch the process, and do not stop at entry point.
55 process = target.LaunchSimple(
56 None, environment, self.get_process_working_directory()
58 self.assertTrue(process, PROCESS_IS_VALID)
60 # The stop reason of the thread should be breakpoint.
61 self.expect(
62 "thread list",
63 STOPPED_DUE_TO_BREAKPOINT,
64 substrs=["stopped", "stop reason = breakpoint"],
67 # The breakpoint should have a hit count of 1.
68 lldbutil.check_breakpoint(self, bpno=1, expected_hit_count=1)
70 # Test that the statically initialized variable can also be
71 # inspected *with* a process.
72 self.expect(
73 "target variable g_ptr", VARIABLES_DISPLAYED_CORRECTLY, substrs=["(int *)"]
75 self.expect(
76 "target variable *g_ptr", VARIABLES_DISPLAYED_CORRECTLY, substrs=["42"]
79 # Check that GLOBAL scopes are indicated for the variables.
80 self.expect(
81 "frame variable --show-types --scope --show-globals --no-args",
82 VARIABLES_DISPLAYED_CORRECTLY,
83 ordered=False,
84 substrs=[
85 "STATIC: (const char *) g_func_static_cstr",
86 '"g_func_static_cstr"',
87 "GLOBAL: (int *) g_ptr",
88 "STATIC: (const int) g_file_static_int = 2",
89 "GLOBAL: (int) g_common_1 = 21",
90 "GLOBAL: (int) g_file_global_int = 42",
91 "STATIC: (const char *) g_file_static_cstr",
92 '"g_file_static_cstr"',
93 "GLOBAL: (const char *) g_file_global_cstr",
94 '"g_file_global_cstr"',
98 # 'frame variable' should support address-of operator.
99 self.runCmd("frame variable &g_file_global_int")
101 # Exercise the 'target variable' command to display globals in a.c
102 # file.
103 self.expect(
104 "target variable g_a", VARIABLES_DISPLAYED_CORRECTLY, substrs=["g_a", "123"]
106 self.expect(
107 "target variable g_marked_spot.x",
108 VARIABLES_DISPLAYED_CORRECTLY,
109 substrs=["g_marked_spot.x", "20"],
112 self.expect(
113 "target variable g_marked_spot.y",
114 VARIABLES_DISPLAYED_CORRECTLY,
115 substrs=["g_marked_spot.y", "21"],
117 self.expect(
118 "target variable g_marked_spot.y",
119 VARIABLES_DISPLAYED_CORRECTLY,
120 matching=False,
121 substrs=["can't be resolved"],