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 | |
Zachary Turner | 77db4a8 | 2015-10-22 20:06:20 +0000 | [diff] [blame] | 5 | import lldb_shared |
| 6 | |
Johnny Chen | 3df7f94 | 2010-11-18 20:35:54 +0000 | [diff] [blame] | 7 | import os, time |
Johnny Chen | 3df7f94 | 2010-11-18 20:35:54 +0000 | [diff] [blame] | 8 | import lldb |
| 9 | from lldbtest import * |
Jim Ingham | 63dfc72 | 2012-09-22 00:05:11 +0000 | [diff] [blame] | 10 | import lldbutil |
Johnny Chen | 3df7f94 | 2010-11-18 20:35:54 +0000 | [diff] [blame] | 11 | |
| 12 | class StaticVariableTestCase(TestBase): |
| 13 | |
Greg Clayton | 4570d3e | 2013-12-10 23:19:29 +0000 | [diff] [blame] | 14 | mydir = TestBase.compute_mydir(__file__) |
Johnny Chen | 835a88c | 2010-11-18 23:33:43 +0000 | [diff] [blame] | 15 | |
Johnny Chen | 3df7f94 | 2010-11-18 20:35:54 +0000 | [diff] [blame] | 16 | def setUp(self): |
| 17 | # Call super's setUp(). |
| 18 | TestBase.setUp(self) |
| 19 | # Find the line number to break at. |
| 20 | self.line = line_number('main.cpp', '// Set break point at this line.') |
| 21 | |
Tamas Berghammer | c8fd130 | 2015-09-30 10:12:40 +0000 | [diff] [blame] | 22 | @expectedFailureWindows("llvm.org/pr24764") |
| 23 | def test_with_run_command(self): |
| 24 | """Test that file and class static variables display correctly.""" |
| 25 | self.build() |
Johnny Chen | 3df7f94 | 2010-11-18 20:35:54 +0000 | [diff] [blame] | 26 | self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) |
| 27 | |
Jim Ingham | 63dfc72 | 2012-09-22 00:05:11 +0000 | [diff] [blame] | 28 | 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] | 29 | |
Sean Callanan | 05834cd | 2015-07-01 23:56:30 +0000 | [diff] [blame] | 30 | self.runCmd("run", RUN_SUCCEEDED) |
Johnny Chen | 3df7f94 | 2010-11-18 20:35:54 +0000 | [diff] [blame] | 31 | |
| 32 | # The stop reason of the thread should be breakpoint. |
| 33 | self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 34 | substrs = ['stopped', |
Johnny Chen | 3df7f94 | 2010-11-18 20:35:54 +0000 | [diff] [blame] | 35 | 'stop reason = breakpoint']) |
| 36 | |
Johnny Chen | 1dc9a20 | 2011-08-22 17:58:14 +0000 | [diff] [blame] | 37 | # global variables are no longer displayed with the "frame variable" command. |
| 38 | self.expect('target variable A::g_points', VARIABLES_DISPLAYED_CORRECTLY, |
Siva Chandra | 89ce955 | 2015-01-05 23:06:14 +0000 | [diff] [blame] | 39 | patterns=['\(PointType \[[1-9]*\]\) A::g_points = {.*}']) |
Johnny Chen | 1dc9a20 | 2011-08-22 17:58:14 +0000 | [diff] [blame] | 40 | self.expect('target variable g_points', VARIABLES_DISPLAYED_CORRECTLY, |
| 41 | substrs = ['(PointType [2]) g_points']) |
| 42 | |
Johnny Chen | 3df7f94 | 2010-11-18 20:35:54 +0000 | [diff] [blame] | 43 | # 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] | 44 | # A::g_points is an array of two elements. |
Greg Clayton | e0d0a76 | 2015-04-02 18:24:03 +0000 | [diff] [blame] | 45 | if self.platformIsDarwin() or self.getPlatform() == "linux": |
Johnny Chen | 1dc9a20 | 2011-08-22 17:58:14 +0000 | [diff] [blame] | 46 | self.expect("target variable A::g_points[1].x", VARIABLES_DISPLAYED_CORRECTLY, |
Johnny Chen | 3df7f94 | 2010-11-18 20:35:54 +0000 | [diff] [blame] | 47 | startstr = "(int) A::g_points[1].x = 11") |
| 48 | |
Tamas Berghammer | c8fd130 | 2015-09-30 10:12:40 +0000 | [diff] [blame] | 49 | @expectedFailureDarwin(9980907) |
| 50 | @expectedFailureClang('Clang emits incomplete debug info.') |
| 51 | @expectedFailureFreeBSD('llvm.org/pr20550 failing on FreeBSD-11') |
| 52 | @expectedFailureGcc('GCC emits incomplete debug info.') |
| 53 | @python_api_test |
| 54 | def test_with_python_api(self): |
Johnny Chen | 835a88c | 2010-11-18 23:33:43 +0000 | [diff] [blame] | 55 | """Test Python APIs on file and class static variables.""" |
Tamas Berghammer | c8fd130 | 2015-09-30 10:12:40 +0000 | [diff] [blame] | 56 | self.build() |
Johnny Chen | 835a88c | 2010-11-18 23:33:43 +0000 | [diff] [blame] | 57 | exe = os.path.join(os.getcwd(), "a.out") |
| 58 | |
| 59 | target = self.dbg.CreateTarget(exe) |
Johnny Chen | 4ebd019 | 2011-05-24 18:22:45 +0000 | [diff] [blame] | 60 | self.assertTrue(target, VALID_TARGET) |
Johnny Chen | 835a88c | 2010-11-18 23:33:43 +0000 | [diff] [blame] | 61 | |
| 62 | breakpoint = target.BreakpointCreateByLocation("main.cpp", self.line) |
Johnny Chen | 4ebd019 | 2011-05-24 18:22:45 +0000 | [diff] [blame] | 63 | self.assertTrue(breakpoint, VALID_BREAKPOINT) |
Johnny Chen | 835a88c | 2010-11-18 23:33:43 +0000 | [diff] [blame] | 64 | |
| 65 | # Now launch the process, and do not stop at entry point. |
Greg Clayton | c694751 | 2013-12-13 19:18:59 +0000 | [diff] [blame] | 66 | process = target.LaunchSimple (None, None, self.get_process_working_directory()) |
Johnny Chen | 5a0bee7 | 2011-06-15 22:14:12 +0000 | [diff] [blame] | 67 | self.assertTrue(process, PROCESS_IS_VALID) |
Johnny Chen | 835a88c | 2010-11-18 23:33:43 +0000 | [diff] [blame] | 68 | |
| 69 | # The stop reason of the thread should be breakpoint. |
Johnny Chen | 5a0bee7 | 2011-06-15 22:14:12 +0000 | [diff] [blame] | 70 | thread = process.GetThreadAtIndex(0) |
Johnny Chen | 835a88c | 2010-11-18 23:33:43 +0000 | [diff] [blame] | 71 | if thread.GetStopReason() != lldb.eStopReasonBreakpoint: |
Johnny Chen | de90f1d | 2011-04-27 17:43:07 +0000 | [diff] [blame] | 72 | from lldbutil import stop_reason_to_str |
Johnny Chen | 835a88c | 2010-11-18 23:33:43 +0000 | [diff] [blame] | 73 | self.fail(STOPPED_DUE_TO_BREAKPOINT_WITH_STOP_REASON_AS % |
Johnny Chen | de90f1d | 2011-04-27 17:43:07 +0000 | [diff] [blame] | 74 | stop_reason_to_str(thread.GetStopReason())) |
Johnny Chen | 835a88c | 2010-11-18 23:33:43 +0000 | [diff] [blame] | 75 | |
| 76 | # Get the SBValue of 'A::g_points' and 'g_points'. |
| 77 | frame = thread.GetFrameAtIndex(0) |
| 78 | |
| 79 | # arguments => False |
| 80 | # locals => False |
| 81 | # statics => True |
| 82 | # in_scope_only => False |
| 83 | valList = frame.GetVariables(False, False, True, False) |
| 84 | |
Johnny Chen | e69c748 | 2011-04-28 22:57:01 +0000 | [diff] [blame] | 85 | for val in valList: |
Johnny Chen | 9a07aba | 2011-07-11 20:06:28 +0000 | [diff] [blame] | 86 | self.DebugSBValue(val) |
Johnny Chen | 835a88c | 2010-11-18 23:33:43 +0000 | [diff] [blame] | 87 | name = val.GetName() |
| 88 | self.assertTrue(name in ['g_points', 'A::g_points']) |
| 89 | if name == 'g_points': |
Greg Clayton | bc8d239 | 2013-05-14 22:17:29 +0000 | [diff] [blame] | 90 | self.assertTrue(val.GetValueType() == lldb.eValueTypeVariableStatic) |
Johnny Chen | 835a88c | 2010-11-18 23:33:43 +0000 | [diff] [blame] | 91 | self.assertTrue(val.GetNumChildren() == 2) |
Siva Chandra | 5ab2e07 | 2014-12-19 22:40:05 +0000 | [diff] [blame] | 92 | elif name == 'A::g_points': |
Greg Clayton | bc8d239 | 2013-05-14 22:17:29 +0000 | [diff] [blame] | 93 | self.assertTrue(val.GetValueType() == lldb.eValueTypeVariableGlobal) |
Johnny Chen | 835a88c | 2010-11-18 23:33:43 +0000 | [diff] [blame] | 94 | self.assertTrue(val.GetNumChildren() == 2) |
| 95 | child1 = val.GetChildAtIndex(1) |
Johnny Chen | 9a07aba | 2011-07-11 20:06:28 +0000 | [diff] [blame] | 96 | self.DebugSBValue(child1) |
Johnny Chen | 835a88c | 2010-11-18 23:33:43 +0000 | [diff] [blame] | 97 | child1_x = child1.GetChildAtIndex(0) |
Johnny Chen | 9a07aba | 2011-07-11 20:06:28 +0000 | [diff] [blame] | 98 | self.DebugSBValue(child1_x) |
Johnny Chen | 835a88c | 2010-11-18 23:33:43 +0000 | [diff] [blame] | 99 | self.assertTrue(child1_x.GetTypeName() == 'int' and |
Greg Clayton | fe42ac4 | 2011-08-03 22:57:10 +0000 | [diff] [blame] | 100 | child1_x.GetValue() == '11') |
Johnny Chen | 835a88c | 2010-11-18 23:33:43 +0000 | [diff] [blame] | 101 | |
Johnny Chen | 94f928b | 2010-12-14 18:59:15 +0000 | [diff] [blame] | 102 | # SBFrame.FindValue() should also work. |
| 103 | val = frame.FindValue("A::g_points", lldb.eValueTypeVariableGlobal) |
Johnny Chen | 9a07aba | 2011-07-11 20:06:28 +0000 | [diff] [blame] | 104 | self.DebugSBValue(val) |
Johnny Chen | beae523 | 2010-11-19 18:07:14 +0000 | [diff] [blame] | 105 | self.assertTrue(val.GetName() == 'A::g_points') |
| 106 | |
| 107 | # Also exercise the "parameter" and "local" scopes while we are at it. |
Johnny Chen | 94f928b | 2010-12-14 18:59:15 +0000 | [diff] [blame] | 108 | val = frame.FindValue("argc", lldb.eValueTypeVariableArgument) |
Johnny Chen | 9a07aba | 2011-07-11 20:06:28 +0000 | [diff] [blame] | 109 | self.DebugSBValue(val) |
Johnny Chen | beae523 | 2010-11-19 18:07:14 +0000 | [diff] [blame] | 110 | self.assertTrue(val.GetName() == 'argc') |
| 111 | |
Johnny Chen | 94f928b | 2010-12-14 18:59:15 +0000 | [diff] [blame] | 112 | val = frame.FindValue("argv", lldb.eValueTypeVariableArgument) |
Johnny Chen | 9a07aba | 2011-07-11 20:06:28 +0000 | [diff] [blame] | 113 | self.DebugSBValue(val) |
Johnny Chen | beae523 | 2010-11-19 18:07:14 +0000 | [diff] [blame] | 114 | self.assertTrue(val.GetName() == 'argv') |
| 115 | |
Johnny Chen | 94f928b | 2010-12-14 18:59:15 +0000 | [diff] [blame] | 116 | val = frame.FindValue("hello_world", lldb.eValueTypeVariableLocal) |
Johnny Chen | 9a07aba | 2011-07-11 20:06:28 +0000 | [diff] [blame] | 117 | self.DebugSBValue(val) |
Johnny Chen | beae523 | 2010-11-19 18:07:14 +0000 | [diff] [blame] | 118 | self.assertTrue(val.GetName() == 'hello_world') |