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