blob: 161080a1f9696f040d494ced681c36d87ee12a37 [file] [log] [blame]
Johnny Chen377a8ed2010-07-28 21:24:31 +00001"""
Johnny Chen5fede4b2011-10-31 23:35:33 +00002Test some expressions involving STL data types.
Johnny Chen377a8ed2010-07-28 21:24:31 +00003"""
4
5import os, time
Johnny Chen73258832010-08-05 23:42:46 +00006import unittest2
Johnny Chen377a8ed2010-07-28 21:24:31 +00007import lldb
Johnny Chen17941842010-08-09 23:44:24 +00008from lldbtest import *
Johnny Chen377a8ed2010-07-28 21:24:31 +00009
Johnny Chencbb4be02010-09-01 19:59:58 +000010class STLTestCase(TestBase):
Johnny Chen377a8ed2010-07-28 21:24:31 +000011
Johnny Chen8d798eb2011-06-25 21:07:03 +000012 mydir = os.path.join("lang", "cpp", "stl")
Johnny Chen377a8ed2010-07-28 21:24:31 +000013
Johnny Chen5fede4b2011-10-31 23:35:33 +000014 @unittest2.expectedFailure
Johnny Chen165a0792010-09-07 18:27:35 +000015 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
Johnny Chen165a0792010-09-07 18:27:35 +000016 def test_with_dsym(self):
Johnny Chen5fede4b2011-10-31 23:35:33 +000017 """Test some expressions involving STL data types."""
Johnny Chen165a0792010-09-07 18:27:35 +000018 self.buildDsym()
Johnny Chen5fede4b2011-10-31 23:35:33 +000019 self.step_stl_exprs()
Johnny Chen165a0792010-09-07 18:27:35 +000020
Johnny Chen5fede4b2011-10-31 23:35:33 +000021 @unittest2.expectedFailure
Johnny Chen165a0792010-09-07 18:27:35 +000022 def test_with_dwarf(self):
Johnny Chen5fede4b2011-10-31 23:35:33 +000023 """Test some expressions involving STL data types."""
Johnny Chen165a0792010-09-07 18:27:35 +000024 self.buildDwarf()
Johnny Chen5fede4b2011-10-31 23:35:33 +000025 self.step_stl_exprs()
Johnny Chen165a0792010-09-07 18:27:35 +000026
Johnny Chen77ca1a42010-10-12 22:53:02 +000027 def setUp(self):
Johnny Chenaadcef52010-10-14 17:31:24 +000028 # Call super's setUp().
29 TestBase.setUp(self)
Johnny Chen77ca1a42010-10-12 22:53:02 +000030 # Find the line number to break inside main().
31 self.line = line_number('main.cpp', '// Set break point at this line.')
32
Johnny Chen5fede4b2011-10-31 23:35:33 +000033 def step_stl_exprs(self):
34 """Test some expressions involving STL data types."""
Johnny Chen377a8ed2010-07-28 21:24:31 +000035 exe = os.path.join(os.getcwd(), "a.out")
Johnny Chenff3d01d2010-08-20 21:03:09 +000036
Johnny Chen377a8ed2010-07-28 21:24:31 +000037 # 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 Chenff3d01d2010-08-20 21:03:09 +000040
41 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
Johnny Chen377a8ed2010-07-28 21:24:31 +000042
Johnny Chen78c0aeb2010-10-12 23:01:50 +000043 # 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 Chen77ca1a42010-10-12 22:53:02 +000046 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 Chen377a8ed2010-07-28 21:24:31 +000050
Johnny Chen5ee88192010-08-27 23:47:36 +000051 self.runCmd("run", RUN_SUCCEEDED)
Johnny Chen377a8ed2010-07-28 21:24:31 +000052
53 # Stop at 'std::string hello_world ("Hello World!");'.
Johnny Chenff3d01d2010-08-20 21:03:09 +000054 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
Johnny Chen77ca1a42010-10-12 22:53:02 +000055 substrs = ['main.cpp:%d' % self.line,
Johnny Chenff3d01d2010-08-20 21:03:09 +000056 'stop reason = breakpoint'])
Johnny Chen377a8ed2010-07-28 21:24:31 +000057
58 # The breakpoint should have a hit count of 1.
Caroline Tice79042b32011-02-04 22:59:41 +000059 self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
Johnny Chenff3d01d2010-08-20 21:03:09 +000060 substrs = [' resolved, hit count = 1'])
Johnny Chen377a8ed2010-07-28 21:24:31 +000061
Johnny Chen9a1e9af2011-10-31 23:28:52 +000062 # Now try some expressions....
Johnny Chen377a8ed2010-07-28 21:24:31 +000063
Johnny Chen9a1e9af2011-10-31 23:28:52 +000064 self.runCmd('expr for (int i = 0; i < hello_world.length(); ++i) { (void)printf("%c\\n", hello_world[i]); }')
65
Johnny Chen5fede4b2011-10-31 23:35:33 +000066 # rdar://problem/10373783
Johnny Chen9a1e9af2011-10-31 23:28:52 +000067 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 Chen377a8ed2010-07-28 21:24:31 +000075
Johnny Chen377a8ed2010-07-28 21:24:31 +000076
77if __name__ == '__main__':
Johnny Chena2124952010-08-05 21:23:45 +000078 import atexit
Johnny Chen377a8ed2010-07-28 21:24:31 +000079 lldb.SBDebugger.Initialize()
Johnny Chena2124952010-08-05 21:23:45 +000080 atexit.register(lambda: lldb.SBDebugger.Terminate())
Johnny Chen73258832010-08-05 23:42:46 +000081 unittest2.main()