Skip to content

Commit 100dcf4

Browse files
authored
Merge pull request #2973 from medismailben/apple/stable/20210107
[lldb/API] Use a valid LineEntry object in SBCompileUnit::FindLineEntryIndex
2 parents 655a880 + ac84235 commit 100dcf4

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed

lldb/source/API/SBCompileUnit.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,10 @@ uint32_t SBCompileUnit::FindLineEntryIndex(uint32_t start_idx, uint32_t line,
108108
else
109109
file_spec = m_opaque_ptr->GetPrimaryFile();
110110

111+
LineEntry line_entry;
111112
index = m_opaque_ptr->FindLineEntry(
112113
start_idx, line, inline_file_spec ? inline_file_spec->get() : nullptr,
113-
exact, nullptr);
114+
exact, &line_entry);
114115
}
115116

116117
return index;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
C_SOURCES := main.c
2+
CFLAGS_EXTRAS := -std=c99
3+
4+
include Makefile.rules
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""
2+
Test that SBCompileUnit::FindLineEntryIndex works correctly.
3+
"""
4+
5+
import lldb
6+
import lldbsuite.test.lldbutil as lldbutil
7+
from lldbsuite.test.lldbtest import *
8+
9+
class FindLineEntry(TestBase):
10+
11+
mydir = TestBase.compute_mydir(__file__)
12+
13+
def test_compile_unit_find_line_entry_index(self):
14+
""" Test the CompileUnit LineEntryIndex lookup API """
15+
self.build()
16+
exe = self.getBuildArtifact("a.out")
17+
self.target = self.dbg.CreateTarget(exe)
18+
self.assertTrue(self.target.IsValid(), "Target is not valid")
19+
20+
self.file = lldb.SBFileSpec("main.c")
21+
sc_list = self.target.FindCompileUnits(self.file)
22+
self.assertEqual(len(sc_list), 1)
23+
cu = sc_list[0].GetCompileUnit()
24+
self.assertTrue(cu.IsValid(), "CompileUnit is not valid")
25+
26+
# First look for valid line
27+
self.line = line_number("main.c", "int change_me")
28+
self.assertNotEqual(cu.FindLineEntryIndex(0, self.line, self.file),
29+
lldb.LLDB_INVALID_LINE_NUMBER)
30+
31+
# Then look for a line out of bound
32+
self.assertEqual(cu.FindLineEntryIndex(0, 42, self.file),
33+
lldb.LLDB_INVALID_LINE_NUMBER)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
int main() {
2+
int change_me = 0;
3+
for (int i = 0; i < 2; i++) {
4+
change_me++;
5+
}
6+
return 0;
7+
}

0 commit comments

Comments
 (0)