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 * |
Jim Ingham | 63dfc72 | 2012-09-22 00:05:11 +0000 | [diff] [blame] | 9 | import lldbutil |
Johnny Chen | 3df7f94 | 2010-11-18 20:35:54 +0000 | [diff] [blame] | 10 | |
| 11 | class StaticVariableTestCase(TestBase): |
| 12 | |
Greg Clayton | 4570d3e | 2013-12-10 23:19:29 +0000 | [diff] [blame] | 13 | mydir = TestBase.compute_mydir(__file__) |
Matt Kopec | 5d4bc2a | 2013-08-01 17:22:24 +0000 | [diff] [blame] | 14 | failing_compilers = ['clang', 'gcc'] |
Johnny Chen | 3df7f94 | 2010-11-18 20:35:54 +0000 | [diff] [blame] | 15 | |
| 16 | @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") |
Johnny Chen | 24086bc | 2012-04-06 19:54:10 +0000 | [diff] [blame] | 17 | @dsym_test |
Johnny Chen | 3df7f94 | 2010-11-18 20:35:54 +0000 | [diff] [blame] | 18 | def test_with_dsym_and_run_command(self): |
| 19 | """Test that file and class static variables display correctly.""" |
| 20 | self.buildDsym() |
| 21 | self.static_variable_commands() |
| 22 | |
Johnny Chen | 24086bc | 2012-04-06 19:54:10 +0000 | [diff] [blame] | 23 | @dwarf_test |
Johnny Chen | 3df7f94 | 2010-11-18 20:35:54 +0000 | [diff] [blame] | 24 | def test_with_dwarf_and_run_command(self): |
Johnny Chen | 835a88c | 2010-11-18 23:33:43 +0000 | [diff] [blame] | 25 | """Test that file and class static variables display correctly.""" |
Johnny Chen | 3df7f94 | 2010-11-18 20:35:54 +0000 | [diff] [blame] | 26 | self.buildDwarf() |
| 27 | self.static_variable_commands() |
| 28 | |
Johnny Chen | 835a88c | 2010-11-18 23:33:43 +0000 | [diff] [blame] | 29 | @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") |
Greg Clayton | 609a433 | 2013-05-14 23:21:47 +0000 | [diff] [blame] | 30 | @expectedFailureClang(9980907) |
Enrico Granata | 43f6213 | 2013-02-23 01:28:30 +0000 | [diff] [blame] | 31 | @expectedFailureGcc(9980907) |
Johnny Chen | a47d7cb | 2010-12-10 01:21:27 +0000 | [diff] [blame] | 32 | @python_api_test |
Johnny Chen | 24086bc | 2012-04-06 19:54:10 +0000 | [diff] [blame] | 33 | @dsym_test |
Johnny Chen | 835a88c | 2010-11-18 23:33:43 +0000 | [diff] [blame] | 34 | def test_with_dsym_and_python_api(self): |
| 35 | """Test Python APIs on file and class static variables.""" |
| 36 | self.buildDsym() |
| 37 | self.static_variable_python() |
| 38 | |
Ed Maste | ec4f47e | 2014-04-22 13:42:05 +0000 | [diff] [blame] | 39 | @expectedFailureDarwin(9980907) |
Siva Chandra | 5ab2e07 | 2014-12-19 22:40:05 +0000 | [diff] [blame] | 40 | @expectedFailureClang('Clang emits incomplete debug info.') |
| 41 | @expectedFailureGcc('GCC emits incomplete debug info.') |
Johnny Chen | a47d7cb | 2010-12-10 01:21:27 +0000 | [diff] [blame] | 42 | @python_api_test |
Johnny Chen | 24086bc | 2012-04-06 19:54:10 +0000 | [diff] [blame] | 43 | @dwarf_test |
Johnny Chen | 835a88c | 2010-11-18 23:33:43 +0000 | [diff] [blame] | 44 | def test_with_dwarf_and_python_api(self): |
| 45 | """Test Python APIs on file and class static variables.""" |
| 46 | self.buildDwarf() |
| 47 | self.static_variable_python() |
| 48 | |
Johnny Chen | 3df7f94 | 2010-11-18 20:35:54 +0000 | [diff] [blame] | 49 | def setUp(self): |
| 50 | # Call super's setUp(). |
| 51 | TestBase.setUp(self) |
| 52 | # Find the line number to break at. |
| 53 | self.line = line_number('main.cpp', '// Set break point at this line.') |
| 54 | |
| 55 | def static_variable_commands(self): |
Johnny Chen | 835a88c | 2010-11-18 23:33:43 +0000 | [diff] [blame] | 56 | """Test that that file and class static variables display correctly.""" |
Johnny Chen | 3df7f94 | 2010-11-18 20:35:54 +0000 | [diff] [blame] | 57 | self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) |
| 58 | |
Jim Ingham | 63dfc72 | 2012-09-22 00:05:11 +0000 | [diff] [blame] | 59 | lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True) |
Johnny Chen | 3df7f94 | 2010-11-18 20:35:54 +0000 | [diff] [blame] | 60 | |
| 61 | self.runCmd("run", RUN_SUCCEEDED) |
| 62 | |
| 63 | # The stop reason of the thread should be breakpoint. |
| 64 | self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 65 | substrs = ['stopped', |
Johnny Chen | 3df7f94 | 2010-11-18 20:35:54 +0000 | [diff] [blame] | 66 | 'stop reason = breakpoint']) |
| 67 | |
Johnny Chen | 1dc9a20 | 2011-08-22 17:58:14 +0000 | [diff] [blame] | 68 | # global variables are no longer displayed with the "frame variable" command. |
| 69 | self.expect('target variable A::g_points', VARIABLES_DISPLAYED_CORRECTLY, |
Siva Chandra | 89ce955 | 2015-01-05 23:06:14 +0000 | [diff] [blame^] | 70 | patterns=['\(PointType \[[1-9]*\]\) A::g_points = {.*}']) |
Johnny Chen | 1dc9a20 | 2011-08-22 17:58:14 +0000 | [diff] [blame] | 71 | self.expect('target variable g_points', VARIABLES_DISPLAYED_CORRECTLY, |
| 72 | substrs = ['(PointType [2]) g_points']) |
| 73 | |
Johnny Chen | 3df7f94 | 2010-11-18 20:35:54 +0000 | [diff] [blame] | 74 | # On Mac OS X, gcc 4.2 emits the wrong debug info for A::g_points. |
Johnny Chen | 3df7f94 | 2010-11-18 20:35:54 +0000 | [diff] [blame] | 75 | # A::g_points is an array of two elements. |
Siva Chandra | 89ce955 | 2015-01-05 23:06:14 +0000 | [diff] [blame^] | 76 | if sys.platform.startswith("darwin") or sys.platform.startswith("linux"): |
Johnny Chen | 1dc9a20 | 2011-08-22 17:58:14 +0000 | [diff] [blame] | 77 | self.expect("target variable A::g_points[1].x", VARIABLES_DISPLAYED_CORRECTLY, |
Johnny Chen | 3df7f94 | 2010-11-18 20:35:54 +0000 | [diff] [blame] | 78 | startstr = "(int) A::g_points[1].x = 11") |
| 79 | |
Johnny Chen | 835a88c | 2010-11-18 23:33:43 +0000 | [diff] [blame] | 80 | def static_variable_python(self): |
| 81 | """Test Python APIs on file and class static variables.""" |
| 82 | exe = os.path.join(os.getcwd(), "a.out") |
| 83 | |
| 84 | target = self.dbg.CreateTarget(exe) |
Johnny Chen | 4ebd019 | 2011-05-24 18:22:45 +0000 | [diff] [blame] | 85 | self.assertTrue(target, VALID_TARGET) |
Johnny Chen | 835a88c | 2010-11-18 23:33:43 +0000 | [diff] [blame] | 86 | |
| 87 | breakpoint = target.BreakpointCreateByLocation("main.cpp", self.line) |
Johnny Chen | 4ebd019 | 2011-05-24 18:22:45 +0000 | [diff] [blame] | 88 | self.assertTrue(breakpoint, VALID_BREAKPOINT) |
Johnny Chen | 835a88c | 2010-11-18 23:33:43 +0000 | [diff] [blame] | 89 | |
| 90 | # Now launch the process, and do not stop at entry point. |
Greg Clayton | c694751 | 2013-12-13 19:18:59 +0000 | [diff] [blame] | 91 | process = target.LaunchSimple (None, None, self.get_process_working_directory()) |
Johnny Chen | 5a0bee7 | 2011-06-15 22:14:12 +0000 | [diff] [blame] | 92 | self.assertTrue(process, PROCESS_IS_VALID) |
Johnny Chen | 835a88c | 2010-11-18 23:33:43 +0000 | [diff] [blame] | 93 | |
| 94 | # The stop reason of the thread should be breakpoint. |
Johnny Chen | 5a0bee7 | 2011-06-15 22:14:12 +0000 | [diff] [blame] | 95 | thread = process.GetThreadAtIndex(0) |
Johnny Chen | 835a88c | 2010-11-18 23:33:43 +0000 | [diff] [blame] | 96 | if thread.GetStopReason() != lldb.eStopReasonBreakpoint: |
Johnny Chen | de90f1d | 2011-04-27 17:43:07 +0000 | [diff] [blame] | 97 | from lldbutil import stop_reason_to_str |
Johnny Chen | 835a88c | 2010-11-18 23:33:43 +0000 | [diff] [blame] | 98 | self.fail(STOPPED_DUE_TO_BREAKPOINT_WITH_STOP_REASON_AS % |
Johnny Chen | de90f1d | 2011-04-27 17:43:07 +0000 | [diff] [blame] | 99 | stop_reason_to_str(thread.GetStopReason())) |
Johnny Chen | 835a88c | 2010-11-18 23:33:43 +0000 | [diff] [blame] | 100 | |
| 101 | # Get the SBValue of 'A::g_points' and 'g_points'. |
| 102 | frame = thread.GetFrameAtIndex(0) |
| 103 | |
| 104 | # arguments => False |
| 105 | # locals => False |
| 106 | # statics => True |
| 107 | # in_scope_only => False |
| 108 | valList = frame.GetVariables(False, False, True, False) |
| 109 | |
Johnny Chen | e69c748 | 2011-04-28 22:57:01 +0000 | [diff] [blame] | 110 | for val in valList: |
Johnny Chen | 9a07aba | 2011-07-11 20:06:28 +0000 | [diff] [blame] | 111 | self.DebugSBValue(val) |
Johnny Chen | 835a88c | 2010-11-18 23:33:43 +0000 | [diff] [blame] | 112 | name = val.GetName() |
| 113 | self.assertTrue(name in ['g_points', 'A::g_points']) |
| 114 | if name == 'g_points': |
Greg Clayton | bc8d239 | 2013-05-14 22:17:29 +0000 | [diff] [blame] | 115 | self.assertTrue(val.GetValueType() == lldb.eValueTypeVariableStatic) |
Johnny Chen | 835a88c | 2010-11-18 23:33:43 +0000 | [diff] [blame] | 116 | self.assertTrue(val.GetNumChildren() == 2) |
Siva Chandra | 5ab2e07 | 2014-12-19 22:40:05 +0000 | [diff] [blame] | 117 | elif name == 'A::g_points': |
Greg Clayton | bc8d239 | 2013-05-14 22:17:29 +0000 | [diff] [blame] | 118 | self.assertTrue(val.GetValueType() == lldb.eValueTypeVariableGlobal) |
Johnny Chen | 835a88c | 2010-11-18 23:33:43 +0000 | [diff] [blame] | 119 | self.assertTrue(val.GetNumChildren() == 2) |
| 120 | child1 = val.GetChildAtIndex(1) |
Johnny Chen | 9a07aba | 2011-07-11 20:06:28 +0000 | [diff] [blame] | 121 | self.DebugSBValue(child1) |
Johnny Chen | 835a88c | 2010-11-18 23:33:43 +0000 | [diff] [blame] | 122 | child1_x = child1.GetChildAtIndex(0) |
Johnny Chen | 9a07aba | 2011-07-11 20:06:28 +0000 | [diff] [blame] | 123 | self.DebugSBValue(child1_x) |
Johnny Chen | 835a88c | 2010-11-18 23:33:43 +0000 | [diff] [blame] | 124 | self.assertTrue(child1_x.GetTypeName() == 'int' and |
Greg Clayton | fe42ac4 | 2011-08-03 22:57:10 +0000 | [diff] [blame] | 125 | child1_x.GetValue() == '11') |
Johnny Chen | 835a88c | 2010-11-18 23:33:43 +0000 | [diff] [blame] | 126 | |
Johnny Chen | 94f928b | 2010-12-14 18:59:15 +0000 | [diff] [blame] | 127 | # SBFrame.FindValue() should also work. |
| 128 | val = frame.FindValue("A::g_points", lldb.eValueTypeVariableGlobal) |
Johnny Chen | 9a07aba | 2011-07-11 20:06:28 +0000 | [diff] [blame] | 129 | self.DebugSBValue(val) |
Johnny Chen | beae523 | 2010-11-19 18:07:14 +0000 | [diff] [blame] | 130 | self.assertTrue(val.GetName() == 'A::g_points') |
| 131 | |
| 132 | # Also exercise the "parameter" and "local" scopes while we are at it. |
Johnny Chen | 94f928b | 2010-12-14 18:59:15 +0000 | [diff] [blame] | 133 | val = frame.FindValue("argc", lldb.eValueTypeVariableArgument) |
Johnny Chen | 9a07aba | 2011-07-11 20:06:28 +0000 | [diff] [blame] | 134 | self.DebugSBValue(val) |
Johnny Chen | beae523 | 2010-11-19 18:07:14 +0000 | [diff] [blame] | 135 | self.assertTrue(val.GetName() == 'argc') |
| 136 | |
Johnny Chen | 94f928b | 2010-12-14 18:59:15 +0000 | [diff] [blame] | 137 | val = frame.FindValue("argv", lldb.eValueTypeVariableArgument) |
Johnny Chen | 9a07aba | 2011-07-11 20:06:28 +0000 | [diff] [blame] | 138 | self.DebugSBValue(val) |
Johnny Chen | beae523 | 2010-11-19 18:07:14 +0000 | [diff] [blame] | 139 | self.assertTrue(val.GetName() == 'argv') |
| 140 | |
Johnny Chen | 94f928b | 2010-12-14 18:59:15 +0000 | [diff] [blame] | 141 | val = frame.FindValue("hello_world", lldb.eValueTypeVariableLocal) |
Johnny Chen | 9a07aba | 2011-07-11 20:06:28 +0000 | [diff] [blame] | 142 | self.DebugSBValue(val) |
Johnny Chen | beae523 | 2010-11-19 18:07:14 +0000 | [diff] [blame] | 143 | self.assertTrue(val.GetName() == 'hello_world') |
Johnny Chen | 835a88c | 2010-11-18 23:33:43 +0000 | [diff] [blame] | 144 | |
Johnny Chen | 3df7f94 | 2010-11-18 20:35:54 +0000 | [diff] [blame] | 145 | |
| 146 | if __name__ == '__main__': |
| 147 | import atexit |
| 148 | lldb.SBDebugger.Initialize() |
| 149 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 150 | unittest2.main() |