blob: 3b3009035f03e56606164a2189792bfe27512f32 [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 Chena1affab2010-07-03 03:41:59 +00008class TestClassTypes(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())
33 self.assertTrue(res.GetOutput().find('state is Stopped') and
34 res.GetOutput().find('stop reason = breakpoint'))
35
36 # The breakpoint should have a hit count of 1.
37 self.ci.HandleCommand("breakpoint list", res)
38 self.assertTrue(res.Succeeded())
39 self.assertTrue(res.GetOutput().find(' resolved, hit count = 1'))
40
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()
45 self.assertTrue(output.find('GLOBAL: g_file_static_cstr') and
46 output.find('g_file_static_cstr') and
47 output.find('GLOBAL: g_file_global_int') and
48 output.find('(int) 42') and
49 output.find('GLOBAL: g_file_global_cstr') and
50 output.find('g_file_global_cstr'))
Johnny Chenfc210782010-07-02 22:04:42 +000051
52 self.ci.HandleCommand("continue", res)
53 self.assertTrue(res.Succeeded())
54
55
56if __name__ == '__main__':
57 lldb.SBDebugger.Initialize()
Johnny Chenfc210782010-07-02 22:04:42 +000058 unittest.main()
59 lldb.SBDebugger.Terminate()