| Johnny Chen | fc21078 | 2010-07-02 22:04:42 +0000 | [diff] [blame] | 1 | """Show global variables and check that they do indeed have global scopes.""" |
| 2 | |
| 3 | import os, time |
| Johnny Chen | fc21078 | 2010-07-02 22:04:42 +0000 | [diff] [blame] | 4 | import unittest |
| Johnny Chen | a1affab | 2010-07-03 03:41:59 +0000 | [diff] [blame^] | 5 | import lldb |
| 6 | import lldbtest |
| Johnny Chen | fc21078 | 2010-07-02 22:04:42 +0000 | [diff] [blame] | 7 | |
| Johnny Chen | a1affab | 2010-07-03 03:41:59 +0000 | [diff] [blame^] | 8 | class TestClassTypes(lldbtest.TestBase): |
| Johnny Chen | fc21078 | 2010-07-02 22:04:42 +0000 | [diff] [blame] | 9 | |
| Johnny Chen | a1affab | 2010-07-03 03:41:59 +0000 | [diff] [blame^] | 10 | mydir = "global_variables" |
| Johnny Chen | fc21078 | 2010-07-02 22:04:42 +0000 | [diff] [blame] | 11 | |
| 12 | def test_global_variables(self): |
| 13 | """Test 'variable list -s -a' which omits args and shows scopes.""" |
| Johnny Chen | a1affab | 2010-07-03 03:41:59 +0000 | [diff] [blame^] | 14 | res = self.res |
| Johnny Chen | fc21078 | 2010-07-02 22:04:42 +0000 | [diff] [blame] | 15 | 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 Chen | 70b053b | 2010-07-02 22:12:25 +0000 | [diff] [blame] | 44 | 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 Chen | fc21078 | 2010-07-02 22:04:42 +0000 | [diff] [blame] | 51 | |
| 52 | self.ci.HandleCommand("continue", res) |
| 53 | self.assertTrue(res.Succeeded()) |
| 54 | |
| 55 | |
| 56 | if __name__ == '__main__': |
| 57 | lldb.SBDebugger.Initialize() |
| Johnny Chen | fc21078 | 2010-07-02 22:04:42 +0000 | [diff] [blame] | 58 | unittest.main() |
| 59 | lldb.SBDebugger.Terminate() |