1"""Test breaking inside functions defined within a BSD archive file libfoo.a."""
2
3
4
5import lldb
6from lldbsuite.test.decorators import *
7from lldbsuite.test.lldbtest import *
8from lldbsuite.test import lldbutil
9
10
11class BSDArchivesTestCase(TestBase):
12
13    def setUp(self):
14        # Call super's setUp().
15        TestBase.setUp(self)
16        # Find the line number in a(int) to break at.
17        self.line = line_number(
18            'a.c', '// Set file and line breakpoint inside a().')
19
20    # Doesn't depend on any specific debug information.
21    @no_debug_info_test
22    @expectedFailureAll(
23        oslist=["windows"],
24        bugnumber="llvm.org/pr24527.  Makefile.rules doesn't know how to build static libs on Windows")
25    @expectedFailureAll(remote=True)
26    def test(self):
27        """Break inside a() and b() defined within libfoo.a."""
28        self.build()
29
30        exe = self.getBuildArtifact("a.out")
31        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
32
33        # Break inside a() by file and line first.
34        lldbutil.run_break_set_by_file_and_line(
35            self, "a.c", self.line, num_expected_locations=1, loc_exact=True)
36
37        self.runCmd("run", RUN_SUCCEEDED)
38
39        # The stop reason of the thread should be breakpoint.
40        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
41                    substrs=['stopped',
42                             'stop reason = breakpoint'])
43
44        # Break at a(int) first.
45        self.expect("frame variable", VARIABLES_DISPLAYED_CORRECTLY,
46                    substrs=['(int) arg = 1'])
47        self.expect_var_path("__a_global", type="int", value="1")
48
49        # Set breakpoint for b() next.
50        lldbutil.run_break_set_by_symbol(
51            self, "b", num_expected_locations=1, sym_exact=True)
52
53        # Continue the program, we should break at b(int) next.
54        self.runCmd("continue")
55        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
56                    substrs=['stopped',
57                             'stop reason = breakpoint'])
58        self.expect("frame variable", VARIABLES_DISPLAYED_CORRECTLY,
59                    substrs=['(int) arg = 2'])
60        self.expect_var_path("__b_global", type="int", value="2")
61
62        # Test loading thin archives
63        archive_path = self.getBuildArtifact("libbar.a")
64        module_specs = lldb.SBModuleSpecList.GetModuleSpecifications(archive_path)
65        num_specs = module_specs.GetSize()
66        self.assertEqual(num_specs, 1)
67        self.assertEqual(module_specs.GetSpecAtIndex(0).GetObjectName(), "c.o")
68