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
):
11 # Call super's setUp().
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
25 # Create a target by the debugger.
26 target
= self
.dbg
.CreateTarget(self
.getBuildArtifact("a.out"))
28 self
.assertTrue(target
, VALID_TARGET
)
30 "target variable g_ptr", VARIABLES_DISPLAYED_CORRECTLY
, substrs
=["(int *)"]
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."""
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.
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.
73 "target variable g_ptr", VARIABLES_DISPLAYED_CORRECTLY
, substrs
=["(int *)"]
76 "target variable *g_ptr", VARIABLES_DISPLAYED_CORRECTLY
, substrs
=["42"]
79 # Check that GLOBAL scopes are indicated for the variables.
81 "frame variable --show-types --scope --show-globals --no-args",
82 VARIABLES_DISPLAYED_CORRECTLY
,
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
104 "target variable g_a", VARIABLES_DISPLAYED_CORRECTLY
, substrs
=["g_a", "123"]
107 "target variable g_marked_spot.x",
108 VARIABLES_DISPLAYED_CORRECTLY
,
109 substrs
=["g_marked_spot.x", "20"],
113 "target variable g_marked_spot.y",
114 VARIABLES_DISPLAYED_CORRECTLY
,
115 substrs
=["g_marked_spot.y", "21"],
118 "target variable g_marked_spot.y",
119 VARIABLES_DISPLAYED_CORRECTLY
,
121 substrs
=["can't be resolved"],