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 | 1794184 | 2010-08-09 23:44:24 +0000 | [diff] [blame] | 8 | from lldbtest import * |
Johnny Chen | 377a8ed | 2010-07-28 21:24:31 +0000 | [diff] [blame] | 9 | |
Johnny Chen | cbb4be0 | 2010-09-01 19:59:58 +0000 | [diff] [blame] | 10 | class STLTestCase(TestBase): |
Johnny Chen | 377a8ed | 2010-07-28 21:24:31 +0000 | [diff] [blame] | 11 | |
Johnny Chen | 8d798eb | 2011-06-25 21:07:03 +0000 | [diff] [blame] | 12 | mydir = os.path.join("lang", "cpp", "stl") |
Johnny Chen | 377a8ed | 2010-07-28 21:24:31 +0000 | [diff] [blame] | 13 | |
Johnny Chen | 5fede4b | 2011-10-31 23:35:33 +0000 | [diff] [blame^] | 14 | @unittest2.expectedFailure |
Johnny Chen | 165a079 | 2010-09-07 18:27:35 +0000 | [diff] [blame] | 15 | @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") |
Johnny Chen | 165a079 | 2010-09-07 18:27:35 +0000 | [diff] [blame] | 16 | def test_with_dsym(self): |
Johnny Chen | 5fede4b | 2011-10-31 23:35:33 +0000 | [diff] [blame^] | 17 | """Test some expressions involving STL data types.""" |
Johnny Chen | 165a079 | 2010-09-07 18:27:35 +0000 | [diff] [blame] | 18 | self.buildDsym() |
Johnny Chen | 5fede4b | 2011-10-31 23:35:33 +0000 | [diff] [blame^] | 19 | self.step_stl_exprs() |
Johnny Chen | 165a079 | 2010-09-07 18:27:35 +0000 | [diff] [blame] | 20 | |
Johnny Chen | 5fede4b | 2011-10-31 23:35:33 +0000 | [diff] [blame^] | 21 | @unittest2.expectedFailure |
Johnny Chen | 165a079 | 2010-09-07 18:27:35 +0000 | [diff] [blame] | 22 | def test_with_dwarf(self): |
Johnny Chen | 5fede4b | 2011-10-31 23:35:33 +0000 | [diff] [blame^] | 23 | """Test some expressions involving STL data types.""" |
Johnny Chen | 165a079 | 2010-09-07 18:27:35 +0000 | [diff] [blame] | 24 | self.buildDwarf() |
Johnny Chen | 5fede4b | 2011-10-31 23:35:33 +0000 | [diff] [blame^] | 25 | self.step_stl_exprs() |
Johnny Chen | 165a079 | 2010-09-07 18:27:35 +0000 | [diff] [blame] | 26 | |
Johnny Chen | 77ca1a4 | 2010-10-12 22:53:02 +0000 | [diff] [blame] | 27 | def setUp(self): |
Johnny Chen | aadcef5 | 2010-10-14 17:31:24 +0000 | [diff] [blame] | 28 | # Call super's setUp(). |
| 29 | TestBase.setUp(self) |
Johnny Chen | 77ca1a4 | 2010-10-12 22:53:02 +0000 | [diff] [blame] | 30 | # Find the line number to break inside main(). |
| 31 | self.line = line_number('main.cpp', '// Set break point at this line.') |
| 32 | |
Johnny Chen | 5fede4b | 2011-10-31 23:35:33 +0000 | [diff] [blame^] | 33 | def step_stl_exprs(self): |
| 34 | """Test some expressions involving STL data types.""" |
Johnny Chen | 377a8ed | 2010-07-28 21:24:31 +0000 | [diff] [blame] | 35 | exe = os.path.join(os.getcwd(), "a.out") |
Johnny Chen | ff3d01d | 2010-08-20 21:03:09 +0000 | [diff] [blame] | 36 | |
Johnny Chen | 377a8ed | 2010-07-28 21:24:31 +0000 | [diff] [blame] | 37 | # The following two lines, if uncommented, will enable loggings. |
| 38 | #self.ci.HandleCommand("log enable -f /tmp/lldb.log lldb default", res) |
| 39 | #self.assertTrue(res.Succeeded()) |
Johnny Chen | ff3d01d | 2010-08-20 21:03:09 +0000 | [diff] [blame] | 40 | |
| 41 | self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) |
Johnny Chen | 377a8ed | 2010-07-28 21:24:31 +0000 | [diff] [blame] | 42 | |
Johnny Chen | 78c0aeb | 2010-10-12 23:01:50 +0000 | [diff] [blame] | 43 | # rdar://problem/8543077 |
| 44 | # test/stl: clang built binaries results in the breakpoint locations = 3, |
| 45 | # is this a problem with clang generated debug info? |
Johnny Chen | 77ca1a4 | 2010-10-12 22:53:02 +0000 | [diff] [blame] | 46 | self.expect("breakpoint set -f main.cpp -l %d" % self.line, |
| 47 | BREAKPOINT_CREATED, |
| 48 | startstr = "Breakpoint created: 1: file ='main.cpp', line = %d" % |
| 49 | self.line) |
Johnny Chen | 377a8ed | 2010-07-28 21:24:31 +0000 | [diff] [blame] | 50 | |
Johnny Chen | 5ee8819 | 2010-08-27 23:47:36 +0000 | [diff] [blame] | 51 | self.runCmd("run", RUN_SUCCEEDED) |
Johnny Chen | 377a8ed | 2010-07-28 21:24:31 +0000 | [diff] [blame] | 52 | |
| 53 | # Stop at 'std::string hello_world ("Hello World!");'. |
Johnny Chen | ff3d01d | 2010-08-20 21:03:09 +0000 | [diff] [blame] | 54 | self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, |
Johnny Chen | 77ca1a4 | 2010-10-12 22:53:02 +0000 | [diff] [blame] | 55 | substrs = ['main.cpp:%d' % self.line, |
Johnny Chen | ff3d01d | 2010-08-20 21:03:09 +0000 | [diff] [blame] | 56 | 'stop reason = breakpoint']) |
Johnny Chen | 377a8ed | 2010-07-28 21:24:31 +0000 | [diff] [blame] | 57 | |
| 58 | # The breakpoint should have a hit count of 1. |
Caroline Tice | 79042b3 | 2011-02-04 22:59:41 +0000 | [diff] [blame] | 59 | self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE, |
Johnny Chen | ff3d01d | 2010-08-20 21:03:09 +0000 | [diff] [blame] | 60 | substrs = [' resolved, hit count = 1']) |
Johnny Chen | 377a8ed | 2010-07-28 21:24:31 +0000 | [diff] [blame] | 61 | |
Johnny Chen | 9a1e9af | 2011-10-31 23:28:52 +0000 | [diff] [blame] | 62 | # Now try some expressions.... |
Johnny Chen | 377a8ed | 2010-07-28 21:24:31 +0000 | [diff] [blame] | 63 | |
Johnny Chen | 9a1e9af | 2011-10-31 23:28:52 +0000 | [diff] [blame] | 64 | self.runCmd('expr for (int i = 0; i < hello_world.length(); ++i) { (void)printf("%c\\n", hello_world[i]); }') |
| 65 | |
Johnny Chen | 5fede4b | 2011-10-31 23:35:33 +0000 | [diff] [blame^] | 66 | # rdar://problem/10373783 |
Johnny Chen | 9a1e9af | 2011-10-31 23:28:52 +0000 | [diff] [blame] | 67 | self.expect('expr associative_array.size()', |
| 68 | substrs = [' = 3']) |
| 69 | self.expect('expr associative_array.count(hello_world)', |
| 70 | substrs = [' = 1']) |
| 71 | self.expect('expr associative_array[hello_world]', |
| 72 | substrs = [' = 1']) |
| 73 | self.expect('expr associative_array["hello"]', |
| 74 | substrs = [' = 2']) |
Johnny Chen | 377a8ed | 2010-07-28 21:24:31 +0000 | [diff] [blame] | 75 | |
Johnny Chen | 377a8ed | 2010-07-28 21:24:31 +0000 | [diff] [blame] | 76 | |
| 77 | if __name__ == '__main__': |
Johnny Chen | a212495 | 2010-08-05 21:23:45 +0000 | [diff] [blame] | 78 | import atexit |
Johnny Chen | 377a8ed | 2010-07-28 21:24:31 +0000 | [diff] [blame] | 79 | lldb.SBDebugger.Initialize() |
Johnny Chen | a212495 | 2010-08-05 21:23:45 +0000 | [diff] [blame] | 80 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
Johnny Chen | 7325883 | 2010-08-05 23:42:46 +0000 | [diff] [blame] | 81 | unittest2.main() |