TestGlobalVariables.py revision a1b9a90b7aef446302de9b845dc4f3b0e1473aa7
1"""Show global variables and check that they do indeed have global scopes.""" 2 3import os, time 4import unittest2 5import lldb 6from lldbtest import * 7 8class GlobalVariablesTestCase(TestBase): 9 10 mydir = os.path.join("lang", "c", "global_variables") 11 12 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") 13 def test_with_dsym(self): 14 """Test 'frame variable -s -a' which omits args and shows scopes.""" 15 self.buildDsym() 16 self.global_variables() 17 18 def test_with_dwarf(self): 19 """Test 'frame variable -s -a' which omits args and shows scopes.""" 20 self.buildDwarf() 21 self.global_variables() 22 23 def setUp(self): 24 # Call super's setUp(). 25 TestBase.setUp(self) 26 # Find the line number to break inside main(). 27 self.line = line_number('main.c', '// Set break point at this line.') 28 29 def global_variables(self): 30 """Test 'frame variable -s -a' which omits args and shows scopes.""" 31 exe = os.path.join(os.getcwd(), "a.out") 32 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) 33 34 # Break inside the main. 35 self.expect("breakpoint set -f main.c -l %d" % self.line, 36 BREAKPOINT_CREATED, 37 startstr = "Breakpoint created: 1: file ='main.c', line = %d, locations = 1" % 38 self.line) 39 40 self.runCmd("run", RUN_SUCCEEDED) 41 42 # The stop reason of the thread should be breakpoint. 43 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, 44 substrs = ['stopped', 45 'stop reason = breakpoint']) 46 47 # The breakpoint should have a hit count of 1. 48 self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE, 49 substrs = [' resolved, hit count = 1']) 50 51 # Check that GLOBAL scopes are indicated for the variables. 52 self.expect("frame variable -T -s -g -a", VARIABLES_DISPLAYED_CORRECTLY, 53 substrs = ['GLOBAL: (int) g_file_global_int = 42', 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"]) 77 78 79if __name__ == '__main__': 80 import atexit 81 lldb.SBDebugger.Initialize() 82 atexit.register(lambda: lldb.SBDebugger.Terminate()) 83 unittest2.main() 84