blob: 36ddf652576f052ae6390a27fcdb4ce3b92d7846 [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 Chenfc210782010-07-02 22:04:42 +00004import unittest
Johnny Chena1affab2010-07-03 03:41:59 +00005import lldb
6import lldbtest
Johnny Chenfc210782010-07-02 22:04:42 +00007
Johnny Chen30974392010-07-27 20:59:06 +00008class TestGlobalVariables(lldbtest.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)
17 self.assertTrue(res.Succeeded())
18
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(
23 "Breakpoint created: 1: file ='main.c', line = 20, locations = 1"))
24
25 self.ci.HandleCommand("run", res)
26 time.sleep(0.1)
27 self.assertTrue(res.Succeeded())
28
29 # The stop reason of the thread should be breakpoint.
30 self.ci.HandleCommand("thread list", res)
31 print "thread list ->", res.GetOutput()
32 self.assertTrue(res.Succeeded())
Johnny Chenf8f1b0a2010-07-06 23:26:16 +000033 self.assertTrue(res.GetOutput().find('state is Stopped') > 0 and
34 res.GetOutput().find('stop reason = breakpoint') > 0)
Johnny Chenfc210782010-07-02 22:04:42 +000035
36 # The breakpoint should have a hit count of 1.
37 self.ci.HandleCommand("breakpoint list", res)
38 self.assertTrue(res.Succeeded())
Johnny Chenf8f1b0a2010-07-06 23:26:16 +000039 self.assertTrue(res.GetOutput().find(' resolved, hit count = 1') > 0)
Johnny Chenfc210782010-07-02 22:04:42 +000040
41 # Check that GLOBAL scopes are indicated for the variables.
42 self.ci.HandleCommand("variable list -s -a", res);
43 self.assertTrue(res.Succeeded())
Johnny Chen70b053b2010-07-02 22:12:25 +000044 output = res.GetOutput()
Johnny Chenf8f1b0a2010-07-06 23:26:16 +000045 self.assertTrue(output.find('GLOBAL: g_file_static_cstr') > 0 and
46 output.find('g_file_static_cstr') > 0 and
47 output.find('GLOBAL: g_file_global_int') > 0 and
48 output.find('(int) 42') > 0 and
49 output.find('GLOBAL: g_file_global_cstr') > 0 and
50 output.find('g_file_global_cstr') > 0)
Johnny Chenfc210782010-07-02 22:04:42 +000051
52 self.ci.HandleCommand("continue", res)
53 self.assertTrue(res.Succeeded())
54
55
56if __name__ == '__main__':
Johnny Chen88f83042010-08-05 21:23:45 +000057 import atexit
Johnny Chenfc210782010-07-02 22:04:42 +000058 lldb.SBDebugger.Initialize()
Johnny Chen88f83042010-08-05 21:23:45 +000059 atexit.register(lambda: lldb.SBDebugger.Terminate())
Johnny Chenfc210782010-07-02 22:04:42 +000060 unittest.main()