Johnny Chen | 3df7f94 | 2010-11-18 20:35:54 +0000 | [diff] [blame] | 1 | """ |
| 2 | Test display and Python APIs on file and class static variables. |
| 3 | """ |
| 4 | |
| 5 | import os, time |
| 6 | import unittest2 |
| 7 | import lldb |
| 8 | from lldbtest import * |
| 9 | |
| 10 | class StaticVariableTestCase(TestBase): |
| 11 | |
| 12 | mydir = "class_static" |
| 13 | |
| 14 | @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") |
| 15 | def test_with_dsym_and_run_command(self): |
| 16 | """Test that file and class static variables display correctly.""" |
| 17 | self.buildDsym() |
| 18 | self.static_variable_commands() |
| 19 | |
| 20 | def test_with_dwarf_and_run_command(self): |
| 21 | """Test that anonymous and named namespace variables display correctly.""" |
| 22 | self.buildDwarf() |
| 23 | self.static_variable_commands() |
| 24 | |
| 25 | def setUp(self): |
| 26 | # Call super's setUp(). |
| 27 | TestBase.setUp(self) |
| 28 | # Find the line number to break at. |
| 29 | self.line = line_number('main.cpp', '// Set break point at this line.') |
| 30 | |
| 31 | def static_variable_commands(self): |
| 32 | """Test that anonymous and named namespace variables display correctly.""" |
| 33 | self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) |
| 34 | |
| 35 | self.expect("breakpoint set -f main.cpp -l %d" % self.line, |
| 36 | BREAKPOINT_CREATED, |
| 37 | startstr = "Breakpoint created: 1: file ='main.cpp', line = %d, locations = 1" % |
| 38 | self.line) |
| 39 | |
| 40 | self.runCmd("run", RUN_SUCCEEDED) |
| 41 | |
| 42 | # The stop reason of the thread should be breakpoint. |
| 43 | self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, |
| 44 | substrs = ['state is stopped', |
| 45 | 'stop reason = breakpoint']) |
| 46 | |
| 47 | # On Mac OS X, gcc 4.2 emits the wrong debug info for A::g_points. |
| 48 | slist = ['(PointType [2]) g_points', 'A::g_points'] |
| 49 | |
| 50 | # 'frame variable -G' finds and displays global variable(s) by name. |
| 51 | self.expect('frame variable -G g_points', VARIABLES_DISPLAYED_CORRECTLY, |
| 52 | substrs = slist) |
| 53 | |
| 54 | # A::g_points is an array of two elements. |
| 55 | if sys.platform.startswith("darwin") and self.getCompiler() in ['clang', 'llvm-gcc']: |
| 56 | self.expect("frame variable A::g_points[1].x", VARIABLES_DISPLAYED_CORRECTLY, |
| 57 | startstr = "(int) A::g_points[1].x = 11") |
| 58 | |
| 59 | |
| 60 | if __name__ == '__main__': |
| 61 | import atexit |
| 62 | lldb.SBDebugger.Initialize() |
| 63 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 64 | unittest2.main() |