[Lldb-commits] [PATCH] D125437: [lldb/API] Add SBCompileUnit::GetIndexForLineEntry method to SB API

Med Ismail Bennani via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Wed May 11 17:15:30 PDT 2022


mib created this revision.
mib added reviewers: jingham, JDevlieghere.
mib added a project: LLDB.
Herald added a subscriber: arphaman.
Herald added a project: All.
mib requested review of this revision.
Herald added a subscriber: lldb-commits.

This patch adds a new `GetIndexForLineEntry` method to the `SBCompileUnit`
class. As the name suggests, given an `SBLineEntry` object, this will
return the line entry index within a specific compile unit.

This method can take a `exact` boolean that will make sure that the
provided line entry matches perfectly another line entry in the compile unit.

rdar://47450887

Signed-off-by: Med Ismail Bennani <medismail.bennani at gmail.com>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D125437

Files:
  lldb/bindings/interface/SBCompileUnit.i
  lldb/include/lldb/API/SBCompileUnit.h
  lldb/source/API/SBCompileUnit.cpp


Index: lldb/source/API/SBCompileUnit.cpp
===================================================================
--- lldb/source/API/SBCompileUnit.cpp
+++ lldb/source/API/SBCompileUnit.cpp
@@ -77,6 +77,28 @@
   return sb_line_entry;
 }
 
+uint32_t
+SBCompileUnit::GetIndexForLineEntry(const lldb::SBLineEntry &line_entry,
+                                    bool exact) const {
+  LLDB_INSTRUMENT_VA(this, line_entry, exact);
+
+  uint32_t index = UINT32_MAX;
+  if (m_opaque_ptr && line_entry.IsValid()) {
+
+    LineEntry found_line_entry;
+
+    uint32_t found_index = m_opaque_ptr->FindLineEntry(
+        0, line_entry.GetLine(), line_entry.GetFileSpec().get(), exact,
+        &found_line_entry);
+
+    if (!exact ||
+        (exact && !LineEntry::Compare(line_entry.ref(), found_line_entry)))
+      index = found_index;
+  }
+
+  return index;
+}
+
 uint32_t SBCompileUnit::FindLineEntryIndex(uint32_t start_idx, uint32_t line,
                                            SBFileSpec *inline_file_spec) const {
   LLDB_INSTRUMENT_VA(this, start_idx, line, inline_file_spec);
Index: lldb/include/lldb/API/SBCompileUnit.h
===================================================================
--- lldb/include/lldb/API/SBCompileUnit.h
+++ lldb/include/lldb/API/SBCompileUnit.h
@@ -34,6 +34,9 @@
 
   lldb::SBLineEntry GetLineEntryAtIndex(uint32_t idx) const;
 
+  uint32_t GetIndexForLineEntry(const lldb::SBLineEntry &line_entry,
+                                bool exact = false) const;
+
   uint32_t FindLineEntryIndex(uint32_t start_idx, uint32_t line,
                               lldb::SBFileSpec *inline_file_spec) const;
 
Index: lldb/bindings/interface/SBCompileUnit.i
===================================================================
--- lldb/bindings/interface/SBCompileUnit.i
+++ lldb/bindings/interface/SBCompileUnit.i
@@ -67,6 +67,9 @@
     lldb::SBLineEntry
     GetLineEntryAtIndex (uint32_t idx) const;
 
+    uint32_t
+    GetIndexForLineEntry (const lldb::SBLineEntry &line_entry, bool exact = false) const;
+
     uint32_t
     FindLineEntryIndex (uint32_t start_idx,
                         uint32_t line,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125437.428824.patch
Type: text/x-patch
Size: 2134 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220512/60515326/attachment.bin>


More information about the lldb-commits mailing list