Johnny Chen | 377a8ed | 2010-07-28 21:24:31 +0000 | [diff] [blame] | 1 | """ |
Johnny Chen | 5fede4b | 2011-10-31 23:35:33 +0000 | [diff] [blame] | 2 | Test some expressions involving STL data types. |
Johnny Chen | 377a8ed | 2010-07-28 21:24:31 +0000 | [diff] [blame] | 3 | """ |
| 4 | |
| 5 | import os, time |
Johnny Chen | 7325883 | 2010-08-05 23:42:46 +0000 | [diff] [blame] | 6 | import unittest2 |
Johnny Chen | 377a8ed | 2010-07-28 21:24:31 +0000 | [diff] [blame] | 7 | import lldb |
Johnny Chen | 15f247a | 2012-02-03 20:43:00 +0000 | [diff] [blame] | 8 | import lldbutil |
Johnny Chen | 1794184 | 2010-08-09 23:44:24 +0000 | [diff] [blame] | 9 | from lldbtest import * |
Johnny Chen | 377a8ed | 2010-07-28 21:24:31 +0000 | [diff] [blame] | 10 | |
Johnny Chen | cbb4be0 | 2010-09-01 19:59:58 +0000 | [diff] [blame] | 11 | class STLTestCase(TestBase): |
Johnny Chen | 377a8ed | 2010-07-28 21:24:31 +0000 | [diff] [blame] | 12 | |
Johnny Chen | 8d798eb | 2011-06-25 21:07:03 +0000 | [diff] [blame] | 13 | mydir = os.path.join("lang", "cpp", "stl") |
Johnny Chen | 377a8ed | 2010-07-28 21:24:31 +0000 | [diff] [blame] | 14 | |
Johnny Chen | 9b54724 | 2011-11-14 18:33:39 +0000 | [diff] [blame] | 15 | # rdar://problem/10400981 |
Johnny Chen | 5fede4b | 2011-10-31 23:35:33 +0000 | [diff] [blame] | 16 | @unittest2.expectedFailure |
Johnny Chen | 165a079 | 2010-09-07 18:27:35 +0000 | [diff] [blame] | 17 | @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") |
Johnny Chen | 24086bc | 2012-04-06 19:54:10 +0000 | [diff] [blame] | 18 | @dsym_test |
Johnny Chen | 165a079 | 2010-09-07 18:27:35 +0000 | [diff] [blame] | 19 | def test_with_dsym(self): |
Johnny Chen | 5fede4b | 2011-10-31 23:35:33 +0000 | [diff] [blame] | 20 | """Test some expressions involving STL data types.""" |
Johnny Chen | 165a079 | 2010-09-07 18:27:35 +0000 | [diff] [blame] | 21 | self.buildDsym() |
Johnny Chen | 5fede4b | 2011-10-31 23:35:33 +0000 | [diff] [blame] | 22 | self.step_stl_exprs() |
Johnny Chen | 165a079 | 2010-09-07 18:27:35 +0000 | [diff] [blame] | 23 | |
Johnny Chen | 9b54724 | 2011-11-14 18:33:39 +0000 | [diff] [blame] | 24 | # rdar://problem/10400981 |
Johnny Chen | 5fede4b | 2011-10-31 23:35:33 +0000 | [diff] [blame] | 25 | @unittest2.expectedFailure |
Johnny Chen | 24086bc | 2012-04-06 19:54:10 +0000 | [diff] [blame] | 26 | @dwarf_test |
Johnny Chen | 165a079 | 2010-09-07 18:27:35 +0000 | [diff] [blame] | 27 | def test_with_dwarf(self): |
Johnny Chen | 5fede4b | 2011-10-31 23:35:33 +0000 | [diff] [blame] | 28 | """Test some expressions involving STL data types.""" |
Johnny Chen | 165a079 | 2010-09-07 18:27:35 +0000 | [diff] [blame] | 29 | self.buildDwarf() |
Johnny Chen | 5fede4b | 2011-10-31 23:35:33 +0000 | [diff] [blame] | 30 | self.step_stl_exprs() |
Johnny Chen | 165a079 | 2010-09-07 18:27:35 +0000 | [diff] [blame] | 31 | |
Johnny Chen | 15f247a | 2012-02-03 20:43:00 +0000 | [diff] [blame] | 32 | @python_api_test |
Johnny Chen | 24086bc | 2012-04-06 19:54:10 +0000 | [diff] [blame] | 33 | @dsym_test |
Johnny Chen | 15f247a | 2012-02-03 20:43:00 +0000 | [diff] [blame] | 34 | def test_SBType_template_aspects_with_dsym(self): |
Johnny Chen | 9dad8ae | 2012-02-03 20:50:56 +0000 | [diff] [blame] | 35 | """Test APIs for getting template arguments from an SBType.""" |
Johnny Chen | 15f247a | 2012-02-03 20:43:00 +0000 | [diff] [blame] | 36 | self.buildDsym() |
| 37 | self.sbtype_template_apis() |
| 38 | |
| 39 | @python_api_test |
Johnny Chen | 24086bc | 2012-04-06 19:54:10 +0000 | [diff] [blame] | 40 | @dwarf_test |
Johnny Chen | 15f247a | 2012-02-03 20:43:00 +0000 | [diff] [blame] | 41 | def test_SBType_template_aspects_with_dwarf(self): |
Johnny Chen | 9dad8ae | 2012-02-03 20:50:56 +0000 | [diff] [blame] | 42 | """Test APIs for getting template arguments from an SBType.""" |
Johnny Chen | 15f247a | 2012-02-03 20:43:00 +0000 | [diff] [blame] | 43 | self.buildDwarf() |
| 44 | self.sbtype_template_apis() |
| 45 | |
Johnny Chen | 77ca1a4 | 2010-10-12 22:53:02 +0000 | [diff] [blame] | 46 | def setUp(self): |
Johnny Chen | aadcef5 | 2010-10-14 17:31:24 +0000 | [diff] [blame] | 47 | # Call super's setUp(). |
| 48 | TestBase.setUp(self) |
Johnny Chen | 77ca1a4 | 2010-10-12 22:53:02 +0000 | [diff] [blame] | 49 | # Find the line number to break inside main(). |
Johnny Chen | 15f247a | 2012-02-03 20:43:00 +0000 | [diff] [blame] | 50 | self.source = 'main.cpp' |
| 51 | self.line = line_number(self.source, '// Set break point at this line.') |
Johnny Chen | 77ca1a4 | 2010-10-12 22:53:02 +0000 | [diff] [blame] | 52 | |
Johnny Chen | 5fede4b | 2011-10-31 23:35:33 +0000 | [diff] [blame] | 53 | def step_stl_exprs(self): |
| 54 | """Test some expressions involving STL data types.""" |
Johnny Chen | 377a8ed | 2010-07-28 21:24:31 +0000 | [diff] [blame] | 55 | exe = os.path.join(os.getcwd(), "a.out") |
Johnny Chen | ff3d01d | 2010-08-20 21:03:09 +0000 | [diff] [blame] | 56 | |
Johnny Chen | 377a8ed | 2010-07-28 21:24:31 +0000 | [diff] [blame] | 57 | # The following two lines, if uncommented, will enable loggings. |
| 58 | #self.ci.HandleCommand("log enable -f /tmp/lldb.log lldb default", res) |
| 59 | #self.assertTrue(res.Succeeded()) |
Johnny Chen | ff3d01d | 2010-08-20 21:03:09 +0000 | [diff] [blame] | 60 | |
| 61 | self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) |
Johnny Chen | 377a8ed | 2010-07-28 21:24:31 +0000 | [diff] [blame] | 62 | |
Johnny Chen | 78c0aeb | 2010-10-12 23:01:50 +0000 | [diff] [blame] | 63 | # rdar://problem/8543077 |
| 64 | # test/stl: clang built binaries results in the breakpoint locations = 3, |
| 65 | # is this a problem with clang generated debug info? |
Jim Ingham | 63dfc72 | 2012-09-22 00:05:11 +0000 | [diff] [blame^] | 66 | lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True) |
Johnny Chen | 377a8ed | 2010-07-28 21:24:31 +0000 | [diff] [blame] | 67 | |
Johnny Chen | 5ee8819 | 2010-08-27 23:47:36 +0000 | [diff] [blame] | 68 | self.runCmd("run", RUN_SUCCEEDED) |
Johnny Chen | 377a8ed | 2010-07-28 21:24:31 +0000 | [diff] [blame] | 69 | |
| 70 | # Stop at 'std::string hello_world ("Hello World!");'. |
Johnny Chen | ff3d01d | 2010-08-20 21:03:09 +0000 | [diff] [blame] | 71 | self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, |
Johnny Chen | 77ca1a4 | 2010-10-12 22:53:02 +0000 | [diff] [blame] | 72 | substrs = ['main.cpp:%d' % self.line, |
Johnny Chen | ff3d01d | 2010-08-20 21:03:09 +0000 | [diff] [blame] | 73 | 'stop reason = breakpoint']) |
Johnny Chen | 377a8ed | 2010-07-28 21:24:31 +0000 | [diff] [blame] | 74 | |
| 75 | # The breakpoint should have a hit count of 1. |
Caroline Tice | 79042b3 | 2011-02-04 22:59:41 +0000 | [diff] [blame] | 76 | self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE, |
Johnny Chen | ff3d01d | 2010-08-20 21:03:09 +0000 | [diff] [blame] | 77 | substrs = [' resolved, hit count = 1']) |
Johnny Chen | 377a8ed | 2010-07-28 21:24:31 +0000 | [diff] [blame] | 78 | |
Johnny Chen | 9a1e9af | 2011-10-31 23:28:52 +0000 | [diff] [blame] | 79 | # Now try some expressions.... |
Johnny Chen | 377a8ed | 2010-07-28 21:24:31 +0000 | [diff] [blame] | 80 | |
Johnny Chen | 9a1e9af | 2011-10-31 23:28:52 +0000 | [diff] [blame] | 81 | self.runCmd('expr for (int i = 0; i < hello_world.length(); ++i) { (void)printf("%c\\n", hello_world[i]); }') |
| 82 | |
Johnny Chen | 5fede4b | 2011-10-31 23:35:33 +0000 | [diff] [blame] | 83 | # rdar://problem/10373783 |
Johnny Chen | 9b54724 | 2011-11-14 18:33:39 +0000 | [diff] [blame] | 84 | # rdar://problem/10400981 |
Johnny Chen | 9a1e9af | 2011-10-31 23:28:52 +0000 | [diff] [blame] | 85 | self.expect('expr associative_array.size()', |
| 86 | substrs = [' = 3']) |
| 87 | self.expect('expr associative_array.count(hello_world)', |
| 88 | substrs = [' = 1']) |
| 89 | self.expect('expr associative_array[hello_world]', |
| 90 | substrs = [' = 1']) |
| 91 | self.expect('expr associative_array["hello"]', |
| 92 | substrs = [' = 2']) |
Johnny Chen | 377a8ed | 2010-07-28 21:24:31 +0000 | [diff] [blame] | 93 | |
Johnny Chen | 15f247a | 2012-02-03 20:43:00 +0000 | [diff] [blame] | 94 | def sbtype_template_apis(self): |
| 95 | """Test APIs for getting template arguments from an SBType.""" |
| 96 | exe = os.path.join(os.getcwd(), 'a.out') |
| 97 | |
| 98 | # Create a target by the debugger. |
| 99 | target = self.dbg.CreateTarget(exe) |
| 100 | self.assertTrue(target, VALID_TARGET) |
| 101 | |
| 102 | # Create the breakpoint inside function 'main'. |
| 103 | breakpoint = target.BreakpointCreateByLocation(self.source, self.line) |
| 104 | self.assertTrue(breakpoint, VALID_BREAKPOINT) |
| 105 | |
| 106 | # Now launch the process, and do not stop at entry point. |
| 107 | process = target.LaunchSimple(None, None, os.getcwd()) |
| 108 | self.assertTrue(process, PROCESS_IS_VALID) |
| 109 | |
| 110 | # Get Frame #0. |
| 111 | self.assertTrue(process.GetState() == lldb.eStateStopped) |
| 112 | thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) |
| 113 | self.assertTrue(thread != None, "There should be a thread stopped due to breakpoint condition") |
| 114 | frame0 = thread.GetFrameAtIndex(0) |
| 115 | |
| 116 | # Get the type for variable 'associative_array'. |
| 117 | associative_array = frame0.FindVariable('associative_array') |
| 118 | self.DebugSBValue(associative_array) |
| 119 | self.assertTrue(associative_array, VALID_VARIABLE) |
| 120 | map_type = associative_array.GetType() |
| 121 | self.DebugSBType(map_type) |
| 122 | self.assertTrue(map_type, VALID_TYPE) |
| 123 | num_template_args = map_type.GetNumberOfTemplateArguments() |
| 124 | self.assertTrue(num_template_args > 0) |
| 125 | |
| 126 | # We expect the template arguments to contain at least 'string' and 'int'. |
| 127 | expected_types = { 'string': False, 'int': False } |
| 128 | for i in range(num_template_args): |
| 129 | t = map_type.GetTemplateArgumentType(i) |
| 130 | self.DebugSBType(t) |
| 131 | self.assertTrue(t, VALID_TYPE) |
| 132 | name = t.GetName() |
| 133 | if 'string' in name: |
| 134 | expected_types['string'] = True |
| 135 | elif 'int' == name: |
| 136 | expected_types['int'] = True |
| 137 | |
| 138 | # Check that both entries of the dictionary have 'True' as the value. |
| 139 | self.assertTrue(all(expected_types.values())) |
| 140 | |
Johnny Chen | 377a8ed | 2010-07-28 21:24:31 +0000 | [diff] [blame] | 141 | |
| 142 | if __name__ == '__main__': |
Johnny Chen | a212495 | 2010-08-05 21:23:45 +0000 | [diff] [blame] | 143 | import atexit |
Johnny Chen | 377a8ed | 2010-07-28 21:24:31 +0000 | [diff] [blame] | 144 | lldb.SBDebugger.Initialize() |
Johnny Chen | a212495 | 2010-08-05 21:23:45 +0000 | [diff] [blame] | 145 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
Johnny Chen | 7325883 | 2010-08-05 23:42:46 +0000 | [diff] [blame] | 146 | unittest2.main() |