xref: /llvm-project/lldb/test/API/functionalities/find-line-entry/TestFindLineEntry.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
1"""
2Test that SBCompileUnit::FindLineEntryIndex works correctly.
3"""
4
5import lldb
6import lldbsuite.test.lldbutil as lldbutil
7from lldbsuite.test.lldbtest import *
8
9
10class FindLineEntry(TestBase):
11    def test_compile_unit_find_line_entry_index(self):
12        """Test the CompileUnit LineEntryIndex lookup API"""
13        self.build()
14        exe = self.getBuildArtifact("a.out")
15        self.target = self.dbg.CreateTarget(exe)
16        self.assertTrue(self.target.IsValid(), "Target is not valid")
17
18        self.file = lldb.SBFileSpec("main.c")
19        sc_list = self.target.FindCompileUnits(self.file)
20        self.assertEqual(len(sc_list), 1)
21        cu = sc_list[0].GetCompileUnit()
22        self.assertTrue(cu.IsValid(), "CompileUnit is not valid")
23
24        # First look for valid line
25        self.line = line_number("main.c", "int change_me")
26        self.assertNotEqual(
27            cu.FindLineEntryIndex(0, self.line, self.file),
28            lldb.LLDB_INVALID_LINE_NUMBER,
29        )
30
31        # Then look for a line out of bound
32        self.assertEqual(
33            cu.FindLineEntryIndex(0, 42, self.file), lldb.LLDB_INVALID_LINE_NUMBER
34        )
35