194f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen"""
294f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny ChenTest breakpoint commands for a breakpoint ID with multiple locations.
394f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen"""
494f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen
594f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chenimport os, time
694f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chenimport unittest2
794f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chenimport lldb
894f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chenfrom lldbtest import *
9431d839a33e9a274e705f7a268a1c9de2ffc2da2Jim Inghamimport lldbutil
1094f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen
1194f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chenclass BreakpointLocationsTestCase(TestBase):
1294f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen
13083e4a9b6c13eb737ca6279bbd7359e674a729a4Johnny Chen    mydir = os.path.join("functionalities", "breakpoint", "breakpoint_locations")
1494f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen
1594f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
16a3ed7d834b0e0c6924ac95629e740682bbcd15baJohnny Chen    @dsym_test
1794f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen    def test_with_dsym(self):
1894f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen        """Test breakpoint enable/disable for a breakpoint ID with multiple locations."""
1994f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen        self.buildDsym()
2094f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen        self.breakpoint_locations_test()
2194f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen
22a3ed7d834b0e0c6924ac95629e740682bbcd15baJohnny Chen    @dwarf_test
2394f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen    def test_with_dwarf(self):
2494f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen        """Test breakpoint enable/disable for a breakpoint ID with multiple locations."""
2594f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen        self.buildDwarf()
2694f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen        self.breakpoint_locations_test()
2794f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen
2875be6166543b25f9fb0f7e65d2fdab832424958dJohnny Chen    def setUp(self):
290910eb32b94bd67b0357d34d0951aad197742569Johnny Chen        # Call super's setUp().
300910eb32b94bd67b0357d34d0951aad197742569Johnny Chen        TestBase.setUp(self)
3175be6166543b25f9fb0f7e65d2fdab832424958dJohnny Chen        # Find the line number to break inside main().
3275be6166543b25f9fb0f7e65d2fdab832424958dJohnny Chen        self.line = line_number('main.c', '// Set break point at this line.')
3375be6166543b25f9fb0f7e65d2fdab832424958dJohnny Chen
3494f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen    def breakpoint_locations_test(self):
3594f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen        """Test breakpoint enable/disable for a breakpoint ID with multiple locations."""
3694f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen        exe = os.path.join(os.getcwd(), "a.out")
3794f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
3894f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen
3994f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen        # This should create a breakpoint with 3 locations.
40431d839a33e9a274e705f7a268a1c9de2ffc2da2Jim Ingham        lldbutil.run_break_set_by_file_and_line (self, "main.c", self.line, num_expected_locations=3)
4194f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen
4294f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen        # The breakpoint list should show 3 locations.
4341950cc77813637e6c67b069e4ad2faf8c5f6fa7Caroline Tice        self.expect("breakpoint list -f", "Breakpoint locations shown correctly",
44025bcc0c90325b36dc3cbaf644bebc77ff758a7cMatt Kopec            substrs = ["1: file = 'main.c', line = %d, locations = 3" % self.line],
45c8f5e40431efad12d90c49a53498a59c40ddda09Johnny Chen            patterns = ["where = a.out`func_inlined .+unresolved, hit count = 0",
46c8f5e40431efad12d90c49a53498a59c40ddda09Johnny Chen                        "where = a.out`main .+\[inlined\].+unresolved, hit count = 0"])
4794f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen
4894f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen        # The 'breakpoint disable 3.*' command should fail gracefully.
4994f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen        self.expect("breakpoint disable 3.*",
5094f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen                    "Disabling an invalid breakpoint should fail gracefully",
5194f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen                    error=True,
5294f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen            startstr = "error: '3' is not a valid breakpoint ID.")
5394f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen
5494f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen        # The 'breakpoint disable 1.*' command should disable all 3 locations.
5594f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen        self.expect("breakpoint disable 1.*", "All 3 breakpoint locatons disabled correctly",
5694f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen            startstr = "3 breakpoints disabled.")
5794f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen
5894f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen        # Run the program.
5994f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen        self.runCmd("run", RUN_SUCCEEDED)
6094f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen
6194f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen        # We should not stopped on any breakpoint at all.
6294f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen        self.expect("process status", "No stopping on any disabled breakpoint",
6394f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen            patterns = ["^Process [0-9]+ exited with status = 0"])
6494f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen
6594f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen        # The 'breakpoint enable 1.*' command should enable all 3 breakpoints.
6694f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen        self.expect("breakpoint enable 1.*", "All 3 breakpoint locatons enabled correctly",
6794f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen            startstr = "3 breakpoints enabled.")
6894f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen
6994f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen        # The 'breakpoint disable 1.1' command should disable 1 location.
7094f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen        self.expect("breakpoint disable 1.1", "1 breakpoint locatons disabled correctly",
7194f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen            startstr = "1 breakpoints disabled.")
7294f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen
7394f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen        # Run the program againt.  We should stop on the two breakpoint locations.
7494f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen        self.runCmd("run", RUN_SUCCEEDED)
7594f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen
76c8f5e40431efad12d90c49a53498a59c40ddda09Johnny Chen        # Stopped once.
77c8f5e40431efad12d90c49a53498a59c40ddda09Johnny Chen        self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT,
78c8f5e40431efad12d90c49a53498a59c40ddda09Johnny Chen            substrs = ["stop reason = breakpoint 1."])
7994f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen
80c8f5e40431efad12d90c49a53498a59c40ddda09Johnny Chen        # Continue the program, there should be another stop.
8194f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen        self.runCmd("process continue")
8294f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen
83c8f5e40431efad12d90c49a53498a59c40ddda09Johnny Chen        # Stopped again.
84c8f5e40431efad12d90c49a53498a59c40ddda09Johnny Chen        self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT,
85c8f5e40431efad12d90c49a53498a59c40ddda09Johnny Chen            substrs = ["stop reason = breakpoint 1."])
8694f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen
87a720ff4065a51f2a2545634faaf8c90a71fe9d2aJohnny Chen        # At this point, 1.1 has a hit count of 0 and the other a hit count of 1".
8841950cc77813637e6c67b069e4ad2faf8c5f6fa7Caroline Tice        self.expect("breakpoint list -f", "The breakpoints should report correct hit counts",
89a720ff4065a51f2a2545634faaf8c90a71fe9d2aJohnny Chen            patterns = ["1\.1: .+ unresolved, hit count = 0 +Options: disabled",
90a720ff4065a51f2a2545634faaf8c90a71fe9d2aJohnny Chen                        "1\.2: .+ resolved, hit count = 1",
91a720ff4065a51f2a2545634faaf8c90a71fe9d2aJohnny Chen                        "1\.3: .+ resolved, hit count = 1"])
9294f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen
9394f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen
9494f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chenif __name__ == '__main__':
9594f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen    import atexit
9694f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen    lldb.SBDebugger.Initialize()
9794f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen    atexit.register(lambda: lldb.SBDebugger.Terminate())
9894f21c0a325b51a17f17186b91ad4e3d41c4f883Johnny Chen    unittest2.main()
99