blob: d062cce5389ca353ae2082a14a822f7112fdc771 [file] [log] [blame]
Johnny Chen377a8ed2010-07-28 21:24:31 +00001"""
2Test that we can successfully step into an STL function.
3"""
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
12 mydir = "stl"
13
Johnny Chen165a0792010-09-07 18:27:35 +000014 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
Johnny Chen165a0792010-09-07 18:27:35 +000015 def test_with_dsym(self):
16 """Test that we can successfully step into an STL function."""
17 self.buildDsym()
18 self.step_into_stl()
19
Johnny Chen165a0792010-09-07 18:27:35 +000020 def test_with_dwarf(self):
21 """Test that we can successfully step into an STL function."""
22 self.buildDwarf()
23 self.step_into_stl()
24
Johnny Chen77ca1a42010-10-12 22:53:02 +000025 def setUp(self):
26 super(STLTestCase, self).setUp()
27 # Find the line number to break inside main().
28 self.line = line_number('main.cpp', '// Set break point at this line.')
29
Johnny Chen165a0792010-09-07 18:27:35 +000030 def step_into_stl(self):
Johnny Chen377a8ed2010-07-28 21:24:31 +000031 """Test that we can successfully step into an STL function."""
Johnny Chen377a8ed2010-07-28 21:24:31 +000032 exe = os.path.join(os.getcwd(), "a.out")
Johnny Chenff3d01d2010-08-20 21:03:09 +000033
Johnny Chen377a8ed2010-07-28 21:24:31 +000034 # The following two lines, if uncommented, will enable loggings.
35 #self.ci.HandleCommand("log enable -f /tmp/lldb.log lldb default", res)
36 #self.assertTrue(res.Succeeded())
Johnny Chenff3d01d2010-08-20 21:03:09 +000037
38 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
Johnny Chen377a8ed2010-07-28 21:24:31 +000039
40 # Break on line 13 of main.cpp.
Johnny Chen77ca1a42010-10-12 22:53:02 +000041 self.expect("breakpoint set -f main.cpp -l %d" % self.line,
42 BREAKPOINT_CREATED,
43 startstr = "Breakpoint created: 1: file ='main.cpp', line = %d" %
44 self.line)
Johnny Chen377a8ed2010-07-28 21:24:31 +000045
Johnny Chen5ee88192010-08-27 23:47:36 +000046 self.runCmd("run", RUN_SUCCEEDED)
Johnny Chen377a8ed2010-07-28 21:24:31 +000047
48 # Stop at 'std::string hello_world ("Hello World!");'.
Johnny Chenff3d01d2010-08-20 21:03:09 +000049 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
Johnny Chen77ca1a42010-10-12 22:53:02 +000050 substrs = ['main.cpp:%d' % self.line,
Johnny Chenff3d01d2010-08-20 21:03:09 +000051 'stop reason = breakpoint'])
Johnny Chen377a8ed2010-07-28 21:24:31 +000052
53 # The breakpoint should have a hit count of 1.
Johnny Chenff3d01d2010-08-20 21:03:09 +000054 self.expect("breakpoint list", BREAKPOINT_HIT_ONCE,
55 substrs = [' resolved, hit count = 1'])
Johnny Chen377a8ed2010-07-28 21:24:31 +000056
57 # Now do 'thread step-in', we should stop on the basic_string template.
Johnny Chen377a8ed2010-07-28 21:24:31 +000058 #
59 # This assertion currently always fails.
Johnny Chen588ddc12010-07-28 22:00:42 +000060 # This might be related: rdar://problem/8247112.
Johnny Chen377a8ed2010-07-28 21:24:31 +000061 #
Johnny Chend0190a62010-08-23 17:10:44 +000062 #self.runCmd("thread step-in", trace=True)
Johnny Chenff3d01d2010-08-20 21:03:09 +000063 self.runCmd("thread step-in")
Johnny Chen377a8ed2010-07-28 21:24:31 +000064
Johnny Chenff3d01d2010-08-20 21:03:09 +000065 self.expect("thread backtrace", "We have stepped in STL",
66 substrs = ['[inlined]',
67 'basic_string.h'])
Johnny Chen377a8ed2010-07-28 21:24:31 +000068
Johnny Chen377a8ed2010-07-28 21:24:31 +000069
70if __name__ == '__main__':
Johnny Chena2124952010-08-05 21:23:45 +000071 import atexit
Johnny Chen377a8ed2010-07-28 21:24:31 +000072 lldb.SBDebugger.Initialize()
Johnny Chena2124952010-08-05 21:23:45 +000073 atexit.register(lambda: lldb.SBDebugger.Terminate())
Johnny Chen73258832010-08-05 23:42:46 +000074 unittest2.main()