[Lldb-commits] [lldb] [lldb] Add LineTable::{upper, lower}_bound (PR #127519)

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Mon Feb 17 14:25:39 PST 2025


================
@@ -185,6 +185,48 @@ bool LineTable::GetLineEntryAtIndex(uint32_t idx, LineEntry &line_entry) {
   return false;
 }
 
+uint32_t LineTable::lower_bound(const Address &so_addr) const {
+  if (so_addr.GetModule() != m_comp_unit->GetModule())
+    return GetSize();
+
+  Entry search_entry;
+  search_entry.file_addr = so_addr.GetFileAddress();
+  if (search_entry.file_addr == LLDB_INVALID_ADDRESS)
+    return GetSize();
+
+  // This is not a typo. upper_bound returns the first entry which definitely
+  // does not contain this address, which means the entry before it *might*
+  // contain it -- if it is not a termination entry.
+  auto pos =
+      llvm::upper_bound(m_entries, search_entry, Entry::EntryAddressLessThan);
+
+  if (pos != m_entries.begin() && !std::prev(pos)->is_terminal_entry)
+    --pos;
+
+  return std::distance(m_entries.begin(), pos);
----------------
JDevlieghere wrote:

I assume you're returning the index rather than the iterator because that's easier to test in the unit test?

https://github.com/llvm/llvm-project/pull/127519


More information about the lldb-commits mailing list