| 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 | 75e28f9 | 2010-08-05 23:42:46 +0000 | [diff] [blame] | 4 | import unittest2 |
| Johnny Chen | a1affab | 2010-07-03 03:41:59 +0000 | [diff] [blame] | 5 | import lldb |
| Johnny Chen | d85dae5 | 2010-08-09 23:44:24 +0000 | [diff] [blame^] | 6 | from lldbtest import * |
| Johnny Chen | fc21078 | 2010-07-02 22:04:42 +0000 | [diff] [blame] | 7 | |
| Johnny Chen | d85dae5 | 2010-08-09 23:44:24 +0000 | [diff] [blame^] | 8 | class TestGlobalVariables(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) |
| Johnny Chen | d85dae5 | 2010-08-09 23:44:24 +0000 | [diff] [blame^] | 17 | self.assertTrue(res.Succeeded(), CURRENT_EXECUTABLE_SET) |
| Johnny Chen | fc21078 | 2010-07-02 22:04:42 +0000 | [diff] [blame] | 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( |
| Johnny Chen | d85dae5 | 2010-08-09 23:44:24 +0000 | [diff] [blame^] | 23 | "Breakpoint created: 1: file ='main.c', line = 20, locations = 1"), |
| 24 | BREAKPOINT_CREATED) |
| Johnny Chen | fc21078 | 2010-07-02 22:04:42 +0000 | [diff] [blame] | 25 | |
| 26 | self.ci.HandleCommand("run", res) |
| Johnny Chen | d85dae5 | 2010-08-09 23:44:24 +0000 | [diff] [blame^] | 27 | #time.sleep(0.1) |
| 28 | self.assertTrue(res.Succeeded(), RUN_STOPPED) |
| Johnny Chen | fc21078 | 2010-07-02 22:04:42 +0000 | [diff] [blame] | 29 | |
| 30 | # The stop reason of the thread should be breakpoint. |
| 31 | self.ci.HandleCommand("thread list", res) |
| Johnny Chen | d85dae5 | 2010-08-09 23:44:24 +0000 | [diff] [blame^] | 32 | #print "thread list ->", res.GetOutput() |
| 33 | self.assertTrue(res.Succeeded(), CMD_MSG('thread list')) |
| Johnny Chen | f8f1b0a | 2010-07-06 23:26:16 +0000 | [diff] [blame] | 34 | self.assertTrue(res.GetOutput().find('state is Stopped') > 0 and |
| Johnny Chen | d85dae5 | 2010-08-09 23:44:24 +0000 | [diff] [blame^] | 35 | res.GetOutput().find('stop reason = breakpoint') > 0, |
| 36 | STOPPED_DUE_TO_BREAKPOINT) |
| Johnny Chen | fc21078 | 2010-07-02 22:04:42 +0000 | [diff] [blame] | 37 | |
| 38 | # The breakpoint should have a hit count of 1. |
| 39 | self.ci.HandleCommand("breakpoint list", res) |
| 40 | self.assertTrue(res.Succeeded()) |
| Johnny Chen | d85dae5 | 2010-08-09 23:44:24 +0000 | [diff] [blame^] | 41 | self.assertTrue(res.GetOutput().find(' resolved, hit count = 1') > 0, |
| 42 | BREAKPOINT_HIT_ONCE) |
| Johnny Chen | fc21078 | 2010-07-02 22:04:42 +0000 | [diff] [blame] | 43 | |
| 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 Chen | 70b053b | 2010-07-02 22:12:25 +0000 | [diff] [blame] | 47 | output = res.GetOutput() |
| Johnny Chen | f8f1b0a | 2010-07-06 23:26:16 +0000 | [diff] [blame] | 48 | 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 Chen | d85dae5 | 2010-08-09 23:44:24 +0000 | [diff] [blame^] | 53 | output.find('g_file_global_cstr') > 0, |
| 54 | VARIABLES_DISPLAYED_CORRECTLY) |
| Johnny Chen | fc21078 | 2010-07-02 22:04:42 +0000 | [diff] [blame] | 55 | |
| 56 | self.ci.HandleCommand("continue", res) |
| 57 | self.assertTrue(res.Succeeded()) |
| 58 | |
| 59 | |
| 60 | if __name__ == '__main__': |
| Johnny Chen | 88f8304 | 2010-08-05 21:23:45 +0000 | [diff] [blame] | 61 | import atexit |
| Johnny Chen | fc21078 | 2010-07-02 22:04:42 +0000 | [diff] [blame] | 62 | lldb.SBDebugger.Initialize() |
| Johnny Chen | 88f8304 | 2010-08-05 21:23:45 +0000 | [diff] [blame] | 63 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| Johnny Chen | 75e28f9 | 2010-08-05 23:42:46 +0000 | [diff] [blame] | 64 | unittest2.main() |