1"""Test breaking inside functions defined within a BSD archive file libfoo.a."""
2
3import os, time
4import unittest2
5import lldb
6from lldbtest import *
7import lldbutil
8
9class BSDArchivesTestCase(TestBase):
10
11    mydir = os.path.join("functionalities", "archives")
12
13    def test_with_dwarf(self):
14        """Break inside a() and b() defined within libfoo.a."""
15        self.buildDwarf()
16        self.break_inside_bsd_archives()
17
18    def setUp(self):
19        # Call super's setUp().
20        TestBase.setUp(self)
21        # Find the line number in a(int) to break at.
22        self.line = line_number('a.c', '// Set file and line breakpoint inside a().')
23
24    def break_inside_bsd_archives(self):
25        """Break inside a() and b() defined within libfoo.a."""
26        exe = os.path.join(os.getcwd(), "a.out")
27        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
28
29        # Break inside a() by file and line first.
30        lldbutil.run_break_set_by_file_and_line (self, "a.c", self.line, num_expected_locations=1, loc_exact=True)
31
32        self.runCmd("run", RUN_SUCCEEDED)
33
34        # The stop reason of the thread should be breakpoint.
35        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
36            substrs = ['stopped',
37                       'stop reason = breakpoint'])
38
39        # Break at a(int) first.
40        self.expect("frame variable", VARIABLES_DISPLAYED_CORRECTLY,
41            substrs = ['(int) arg = 1'])
42        self.expect("frame variable __a_global", VARIABLES_DISPLAYED_CORRECTLY,
43            substrs = ['(int) __a_global = 1'])
44
45        # Set breakpoint for b() next.
46        lldbutil.run_break_set_by_symbol (self, "b", num_expected_locations=1, sym_exact=True)
47
48        # Continue the program, we should break at b(int) next.
49        self.runCmd("continue")
50        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
51            substrs = ['stopped',
52                       'stop reason = breakpoint'])
53        self.expect("frame variable", VARIABLES_DISPLAYED_CORRECTLY,
54            substrs = ['(int) arg = 2'])
55        self.expect("frame variable __b_global", VARIABLES_DISPLAYED_CORRECTLY,
56            substrs = ['(int) __b_global = 2'])
57
58
59if __name__ == '__main__':
60    import atexit
61    lldb.SBDebugger.Initialize()
62    atexit.register(lambda: lldb.SBDebugger.Terminate())
63    unittest2.main()
64