1"""
2Test that inlined breakpoints (breakpoint set on a file/line included from
3another source file) works correctly.
4"""
5
6import os, time
7import unittest2
8import lldb
9from lldbtest import *
10import lldbutil
11
12class InlinedBreakpointsTestCase(TestBase):
13    """Bug fixed: rdar://problem/8464339"""
14
15    mydir = os.path.join("functionalities", "breakpoint", "inlined_breakpoints")
16
17    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
18    @dsym_test
19    def test_with_dsym_and_run_command(self):
20        """Test 'b basic_types.cpp:176' does break (where int.cpp includes basic_type.cpp)."""
21        self.buildDsym()
22        self.inlined_breakpoints()
23
24    @dwarf_test
25    def test_with_dwarf_and_run_command(self):
26        """Test 'b basic_types.cpp:176' does break (where int.cpp includes basic_type.cpp)."""
27        self.buildDwarf()
28        self.inlined_breakpoints()
29
30    def setUp(self):
31        # Call super's setUp().
32        TestBase.setUp(self)
33        # Find the line number to break inside basic_type.cpp.
34        self.line = line_number('basic_type.cpp', '// Set break point at this line.')
35
36    def inlined_breakpoints(self):
37        """Test 'b basic_types.cpp:176' does break (where int.cpp includes basic_type.cpp)."""
38        exe = os.path.join(os.getcwd(), "a.out")
39        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
40
41        # Set a breakpoint and fail because it is in an inlined source implemenation file
42        lldbutil.run_break_set_by_file_and_line (self, "basic_type.cpp", self.line, num_expected_locations=0)
43
44        # Now enable breakpoints in implementation files and see the breakpoint set succeed
45        self.runCmd('settings set target.inline-breakpoint-strategy always')
46        # And add hooks to restore the settings during tearDown().
47        self.addTearDownHook(
48            lambda: self.runCmd("settings set target.inline-breakpoint-strategy headers"))
49
50        lldbutil.run_break_set_by_file_and_line (self, "basic_type.cpp", self.line, num_expected_locations=1, loc_exact=True)
51
52        self.runCmd("run", RUN_SUCCEEDED)
53
54        # The stop reason of the thread should be breakpoint.
55        # And it should break at basic_type.cpp:176.
56        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
57            substrs = ['stopped',
58                       'stop reason = breakpoint',
59                       'basic_type.cpp:%d' % self.line])
60
61
62if __name__ == '__main__':
63    import atexit
64    lldb.SBDebugger.Initialize()
65    atexit.register(lambda: lldb.SBDebugger.Terminate())
66    unittest2.main()
67