blob: ceb7c4dfc34eee6137d1e17c36a1d7e232e276c2 [file] [log] [blame]
Johnny Chenfc210782010-07-02 22:04:42 +00001"""Show global variables and check that they do indeed have global scopes."""
2
3import os, time
Johnny Chen75e28f92010-08-05 23:42:46 +00004import unittest2
Johnny Chena1affab2010-07-03 03:41:59 +00005import lldb
Johnny Chend85dae52010-08-09 23:44:24 +00006from lldbtest import *
Johnny Chenfc210782010-07-02 22:04:42 +00007
Johnny Chend85dae52010-08-09 23:44:24 +00008class TestGlobalVariables(TestBase):
Johnny Chenfc210782010-07-02 22:04:42 +00009
Johnny Chena1affab2010-07-03 03:41:59 +000010 mydir = "global_variables"
Johnny Chenfc210782010-07-02 22:04:42 +000011
12 def test_global_variables(self):
13 """Test 'variable list -s -a' which omits args and shows scopes."""
Johnny Chena1affab2010-07-03 03:41:59 +000014 res = self.res
Johnny Chenfc210782010-07-02 22:04:42 +000015 exe = os.path.join(os.getcwd(), "a.out")
16 self.ci.HandleCommand("file " + exe, res)
Johnny Chend85dae52010-08-09 23:44:24 +000017 self.assertTrue(res.Succeeded(), CURRENT_EXECUTABLE_SET)
Johnny Chenfc210782010-07-02 22:04:42 +000018
19 # Break inside the main.
20 self.ci.HandleCommand("breakpoint set -f main.c -l 20", res)
21 self.assertTrue(res.Succeeded())
22 self.assertTrue(res.GetOutput().startswith(
Johnny Chend85dae52010-08-09 23:44:24 +000023 "Breakpoint created: 1: file ='main.c', line = 20, locations = 1"),
24 BREAKPOINT_CREATED)
Johnny Chenfc210782010-07-02 22:04:42 +000025
26 self.ci.HandleCommand("run", res)
Johnny Chenffde4fc2010-08-16 21:28:10 +000027 self.runStarted = True
Johnny Chend85dae52010-08-09 23:44:24 +000028 self.assertTrue(res.Succeeded(), RUN_STOPPED)
Johnny Chenfc210782010-07-02 22:04:42 +000029
30 # The stop reason of the thread should be breakpoint.
31 self.ci.HandleCommand("thread list", res)
Johnny Chend85dae52010-08-09 23:44:24 +000032 #print "thread list ->", res.GetOutput()
33 self.assertTrue(res.Succeeded(), CMD_MSG('thread list'))
Johnny Chenf8f1b0a2010-07-06 23:26:16 +000034 self.assertTrue(res.GetOutput().find('state is Stopped') > 0 and
Johnny Chend85dae52010-08-09 23:44:24 +000035 res.GetOutput().find('stop reason = breakpoint') > 0,
36 STOPPED_DUE_TO_BREAKPOINT)
Johnny Chenfc210782010-07-02 22:04:42 +000037
38 # The breakpoint should have a hit count of 1.
39 self.ci.HandleCommand("breakpoint list", res)
40 self.assertTrue(res.Succeeded())
Johnny Chend85dae52010-08-09 23:44:24 +000041 self.assertTrue(res.GetOutput().find(' resolved, hit count = 1') > 0,
42 BREAKPOINT_HIT_ONCE)
Johnny Chenfc210782010-07-02 22:04:42 +000043
44 # Check that GLOBAL scopes are indicated for the variables.
45 self.ci.HandleCommand("variable list -s -a", res);
46 self.assertTrue(res.Succeeded())
Johnny Chen70b053b2010-07-02 22:12:25 +000047 output = res.GetOutput()
Johnny Chenf8f1b0a2010-07-06 23:26:16 +000048 self.assertTrue(output.find('GLOBAL: g_file_static_cstr') > 0 and
49 output.find('g_file_static_cstr') > 0 and
50 output.find('GLOBAL: g_file_global_int') > 0 and
51 output.find('(int) 42') > 0 and
52 output.find('GLOBAL: g_file_global_cstr') > 0 and
Johnny Chend85dae52010-08-09 23:44:24 +000053 output.find('g_file_global_cstr') > 0,
54 VARIABLES_DISPLAYED_CORRECTLY)
Johnny Chenfc210782010-07-02 22:04:42 +000055
Johnny Chenfc210782010-07-02 22:04:42 +000056
57if __name__ == '__main__':
Johnny Chen88f83042010-08-05 21:23:45 +000058 import atexit
Johnny Chenfc210782010-07-02 22:04:42 +000059 lldb.SBDebugger.Initialize()
Johnny Chen88f83042010-08-05 21:23:45 +000060 atexit.register(lambda: lldb.SBDebugger.Terminate())
Johnny Chen75e28f92010-08-05 23:42:46 +000061 unittest2.main()