Skip to content

Commit 1c24ddb

Browse files
committed
[lldb] Reimplement LineTable::FindLineEntryByAddress on top of lower_bound
I *think* this should be equivalent to the original implementation for all line tables occuring in practice. One difference I'm aware of is that the original implementation tried to return the first line entry out of multiple ones for the same address. However, this is not possible (anymore?) because of the check in LineTable::AppendLineEntryToSequence.
1 parent c6a907a commit 1c24ddb

File tree

1 file changed

+10
-62
lines changed

1 file changed

+10
-62
lines changed

lldb/source/Symbol/LineTable.cpp

Lines changed: 10 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -233,69 +233,17 @@ bool LineTable::FindLineEntryByAddress(const Address &so_addr,
233233
if (index_ptr != nullptr)
234234
*index_ptr = UINT32_MAX;
235235

236-
bool success = false;
237-
238-
if (so_addr.GetModule().get() == m_comp_unit->GetModule().get()) {
239-
Entry search_entry;
240-
search_entry.file_addr = so_addr.GetFileAddress();
241-
if (search_entry.file_addr != LLDB_INVALID_ADDRESS) {
242-
entry_collection::const_iterator begin_pos = m_entries.begin();
243-
entry_collection::const_iterator end_pos = m_entries.end();
244-
entry_collection::const_iterator pos = std::lower_bound(
245-
begin_pos, end_pos, search_entry, Entry::EntryAddressLessThan);
246-
if (pos != end_pos) {
247-
if (pos != begin_pos) {
248-
if (pos->file_addr != search_entry.file_addr)
249-
--pos;
250-
else if (pos->file_addr == search_entry.file_addr) {
251-
// If this is a termination entry, it shouldn't match since entries
252-
// with the "is_terminal_entry" member set to true are termination
253-
// entries that define the range for the previous entry.
254-
if (pos->is_terminal_entry) {
255-
// The matching entry is a terminal entry, so we skip ahead to
256-
// the next entry to see if there is another entry following this
257-
// one whose section/offset matches.
258-
++pos;
259-
if (pos != end_pos) {
260-
if (pos->file_addr != search_entry.file_addr)
261-
pos = end_pos;
262-
}
263-
}
264-
265-
if (pos != end_pos) {
266-
// While in the same section/offset backup to find the first line
267-
// entry that matches the address in case there are multiple
268-
while (pos != begin_pos) {
269-
entry_collection::const_iterator prev_pos = pos - 1;
270-
if (prev_pos->file_addr == search_entry.file_addr &&
271-
prev_pos->is_terminal_entry == false)
272-
--pos;
273-
else
274-
break;
275-
}
276-
}
277-
}
278-
}
279-
else
280-
{
281-
// There might be code in the containing objfile before the first
282-
// line table entry. Make sure that does not get considered part of
283-
// the first line table entry.
284-
if (pos->file_addr > so_addr.GetFileAddress())
285-
return false;
286-
}
236+
uint32_t idx = lower_bound(so_addr);
237+
if (idx >= GetSize())
238+
return false;
287239

288-
// Make sure we have a valid match and that the match isn't a
289-
// terminating entry for a previous line...
290-
if (pos != end_pos && pos->is_terminal_entry == false) {
291-
uint32_t match_idx = std::distance(begin_pos, pos);
292-
success = ConvertEntryAtIndexToLineEntry(match_idx, line_entry);
293-
if (index_ptr != nullptr && success)
294-
*index_ptr = match_idx;
295-
}
296-
}
297-
}
298-
}
240+
addr_t file_addr = so_addr.GetFileAddress();
241+
if (m_entries[idx].file_addr > file_addr)
242+
return false;
243+
244+
bool success = ConvertEntryAtIndexToLineEntry(idx, line_entry);
245+
if (index_ptr != nullptr && success)
246+
*index_ptr = idx;
299247
return success;
300248
}
301249

0 commit comments

Comments
 (0)