1"""
2Test lldb breakpoint ids.
3"""
4
5import os, time
6import unittest2
7import lldb
8from lldbtest import *
9import lldbutil
10
11class BreakpointIDTestCase(TestBase):
12
13    mydir = os.path.join("functionalities", "breakpoint", "breakpoint_ids")
14
15    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
16    @dsym_test
17    def test_with_dsym (self):
18        self.buildDsym ()
19        self.breakpoint_id_tests ()
20
21    @dwarf_test
22    def test_with_dwarf (self):
23        self.buildDwarf ()
24        self.breakpoint_id_tests ()
25
26    def breakpoint_id_tests (self):
27        exe = os.path.join (os.getcwd(), "a.out")
28        self.expect("file " + exe,
29                    patterns = [ "Current executable set to .*a.out" ])
30
31
32        bpno = lldbutil.run_break_set_by_symbol (self, 'product', num_expected_locations=-1, sym_exact=False)
33        self.assertTrue (bpno == 1, "First breakpoint number is 1.")
34
35        bpno = lldbutil.run_break_set_by_symbol (self, 'sum', num_expected_locations=-1, sym_exact=False)
36        self.assertTrue (bpno == 2, "Second breakpoint number is 2.")
37
38        bpno = lldbutil.run_break_set_by_symbol (self, 'junk', num_expected_locations=0, sym_exact=False)
39        self.assertTrue (bpno == 3, "Third breakpoint number is 3.")
40
41        self.expect ("breakpoint disable 1.1 - 2.2 ",
42                     COMMAND_FAILED_AS_EXPECTED, error = True,
43                     startstr = "error: Invalid range: Ranges that specify particular breakpoint locations must be within the same major breakpoint; you specified two different major breakpoints, 1 and 2.")
44
45        self.expect ("breakpoint disable 2 - 2.2",
46                     COMMAND_FAILED_AS_EXPECTED, error = True,
47                     startstr = "error: Invalid breakpoint id range:  Either both ends of range must specify a breakpoint location, or neither can specify a breakpoint location.")
48
49        self.expect ("breakpoint disable 2.1 - 2",
50                     COMMAND_FAILED_AS_EXPECTED, error = True,
51                     startstr = "error: Invalid breakpoint id range:  Either both ends of range must specify a breakpoint location, or neither can specify a breakpoint location.")
52
53        self.expect ("breakpoint disable 2.1 - 2.2",
54                     startstr = "2 breakpoints disabled.")
55
56        self.expect ("breakpoint enable 2.*",
57                     patterns = [ ".* breakpoints enabled."] )
58
59if __name__ == '__main__':
60    import atexit
61    lldb.SBDebugger.Initialize()
62    atexit.register(lambda: lldb.SBDebugger.Terminate())
63    unittest2.main()
64
65