xref: /llvm-project-15.0.7/lldb/test/API/python_api/compile_unit/TestCompileUnitAPI.py (revision a7f9895c)
  • Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""
2Test SBCompileUnit APIs.
3"""
4
5import lldb
6from lldbsuite.test.decorators import *
7from lldbsuite.test.lldbtest import *
8from lldbsuite.test import lldbutil
9
10
11class CompileUnitAPITestCase(TestBase):
12
13    mydir = TestBase.compute_mydir(__file__)
14
15    def setUp(self):
16        TestBase.setUp(self)
17
18    def test(self):
19        """Exercise some SBCompileUnit APIs."""
20        self.build()
21
22        (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, 'break here', lldb.SBFileSpec('main.c'))
23        self.assertTrue(target, VALID_TARGET)
24        self.assertTrue(process, PROCESS_IS_VALID)
25        self.assertTrue(bkpt and bkpt.GetNumLocations() == 1,
26                        VALID_BREAKPOINT)
27
28        self.assertTrue(
29            thread.IsValid(),
30            "There should be a thread stopped due to breakpoint condition")
31        frame0 = thread.GetFrameAtIndex(0)
32        line_entry = frame0.GetLineEntry()
33
34        sc_list = target.FindCompileUnits(line_entry.GetFileSpec())
35        self.assertGreater(sc_list.GetSize(), 0)
36
37        main_cu = sc_list.compile_units[0]
38        self.assertTrue(main_cu.IsValid(), "Main executable CU is not valid")
39
40        self.assertEqual(main_cu.FindLineEntryIndex(line_entry, True),
41                         main_cu.FindLineEntryIndex(0, line_entry.GetLine(),
42                                   line_entry.GetFileSpec(), True))
43
44
45

served by {OpenGrok

Last Index Update: Tue Oct 21 18:42:31 GMT 2025