]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/lang/c/global_variables/TestGlobalVariables.py
Vendor import of lldb trunk r256945:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / lang / c / global_variables / TestGlobalVariables.py
1 """Show global variables and check that they do indeed have global scopes."""
2
3 from __future__ import print_function
4
5
6 from lldbsuite.test.lldbtest import *
7 import lldbsuite.test.lldbutil as lldbutil
8
9 class GlobalVariablesTestCase(TestBase):
10
11     mydir = TestBase.compute_mydir(__file__)
12
13     def setUp(self):
14         # Call super's setUp().
15         TestBase.setUp(self)
16         # Find the line number to break inside main().
17         self.source = 'main.c'
18         self.line = line_number(self.source, '// Set break point at this line.')
19         self.shlib_names = ["a"]
20
21     @expectedFailureWindows("llvm.org/pr24764")
22     @expectedFailureAll("llvm.org/pr25872", oslist=["macosx"], debug_info="dwarf")
23     def test_c_global_variables(self):
24         """Test 'frame variable --scope --no-args' which omits args and shows scopes."""
25         self.build()
26
27         # Create a target by the debugger.
28         target = self.dbg.CreateTarget("a.out")
29         self.assertTrue(target, VALID_TARGET)
30
31         # Break inside the main.
32         lldbutil.run_break_set_by_file_and_line (self, self.source, self.line, num_expected_locations=1, loc_exact=True)
33
34         # Register our shared libraries for remote targets so they get automatically uploaded
35         environment = self.registerSharedLibrariesWithTarget(target, self.shlib_names)
36
37         # Now launch the process, and do not stop at entry point.
38         process = target.LaunchSimple (None, environment, self.get_process_working_directory())
39         self.assertTrue(process, PROCESS_IS_VALID)
40
41         # The stop reason of the thread should be breakpoint.
42         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
43             substrs = ['stopped',
44                        'stop reason = breakpoint'])
45
46         # The breakpoint should have a hit count of 1.
47         self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
48             substrs = [' resolved, hit count = 1'])
49
50         # Check that GLOBAL scopes are indicated for the variables.
51         self.expect("frame variable --show-types --scope --show-globals --no-args", VARIABLES_DISPLAYED_CORRECTLY,
52             substrs = ['GLOBAL: (int) g_file_global_int = 42',
53                        'STATIC: (const int) g_file_static_int = 2',
54                        'GLOBAL: (const char *) g_file_global_cstr',
55                        '"g_file_global_cstr"',
56                        'STATIC: (const char *) g_file_static_cstr',
57                        '"g_file_static_cstr"',
58                        'GLOBAL: (int) g_common_1 = 21'])
59
60         # 'frame variable' should support address-of operator.
61         self.runCmd("frame variable &g_file_global_int")
62
63         # Exercise the 'target variable' command to display globals in a.c file.
64         self.expect("target variable g_a", VARIABLES_DISPLAYED_CORRECTLY,
65                     substrs = ['g_a', '123'])
66         self.expect("target variable g_marked_spot.x", VARIABLES_DISPLAYED_CORRECTLY,
67                     substrs = ['g_marked_spot.x', '20'])
68
69         # rdar://problem/9747668
70         # runCmd: target variable g_marked_spot.y
71         # output: (int) g_marked_spot.y = <a.o[0x214] can't be resolved,  in not currently loaded.
72         #         >
73         self.expect("target variable g_marked_spot.y", VARIABLES_DISPLAYED_CORRECTLY,
74                     substrs = ['g_marked_spot.y', '21'])
75         self.expect("target variable g_marked_spot.y", VARIABLES_DISPLAYED_CORRECTLY, matching=False,
76                     substrs = ["can't be resolved"])