[Lldb-commits] [PATCH] D102658: [lldb/API] Use a valid LineEntry object in SBCompileUnit::FindLineEntryIndex

Med Ismail Bennani via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon May 17 17:29:35 PDT 2021


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1b4d5b3bf306: [lldb/API] Use a valid LineEntry object in SBCompileUnit::FindLineEntryIndex (authored by mib).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D102658/new/

https://reviews.llvm.org/D102658

Files:
  lldb/source/API/SBCompileUnit.cpp
  lldb/test/API/functionalities/find-line-entry/Makefile
  lldb/test/API/functionalities/find-line-entry/TestFindLineEntry.py
  lldb/test/API/functionalities/find-line-entry/main.c


Index: lldb/test/API/functionalities/find-line-entry/main.c
===================================================================
--- /dev/null
+++ lldb/test/API/functionalities/find-line-entry/main.c
@@ -0,0 +1,7 @@
+int main() {
+  int change_me = 0;
+  for (int i = 0; i < 2; i++) {
+    change_me++;
+  }
+  return 0;
+}
Index: lldb/test/API/functionalities/find-line-entry/TestFindLineEntry.py
===================================================================
--- /dev/null
+++ lldb/test/API/functionalities/find-line-entry/TestFindLineEntry.py
@@ -0,0 +1,33 @@
+"""
+Test that SBCompileUnit::FindLineEntryIndex works correctly.
+"""
+
+import lldb
+import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test.lldbtest import *
+
+class FindLineEntry(TestBase):
+
+    mydir = TestBase.compute_mydir(__file__)
+
+    def test_compile_unit_find_line_entry_index(self):
+        """ Test the CompileUnit LineEntryIndex lookup API """
+        self.build()
+        exe = self.getBuildArtifact("a.out")
+        self.target = self.dbg.CreateTarget(exe)
+        self.assertTrue(self.target.IsValid(), "Target is not valid")
+
+        self.file = lldb.SBFileSpec("main.c")
+        sc_list = self.target.FindCompileUnits(self.file)
+        self.assertEqual(len(sc_list), 1)
+        cu = sc_list[0].GetCompileUnit()
+        self.assertTrue(cu.IsValid(), "CompileUnit is not valid")
+
+        # First look for valid line
+        self.line = line_number("main.c", "int change_me")
+        self.assertNotEqual(cu.FindLineEntryIndex(0, self.line, self.file),
+                            lldb.LLDB_INVALID_LINE_NUMBER)
+
+        # Then look for a line out of bound
+        self.assertEqual(cu.FindLineEntryIndex(0, 42, self.file),
+                            lldb.LLDB_INVALID_LINE_NUMBER)
Index: lldb/test/API/functionalities/find-line-entry/Makefile
===================================================================
--- /dev/null
+++ lldb/test/API/functionalities/find-line-entry/Makefile
@@ -0,0 +1,4 @@
+C_SOURCES := main.c
+CFLAGS_EXTRAS := -std=c99
+
+include Makefile.rules
Index: lldb/source/API/SBCompileUnit.cpp
===================================================================
--- lldb/source/API/SBCompileUnit.cpp
+++ lldb/source/API/SBCompileUnit.cpp
@@ -108,9 +108,10 @@
     else
       file_spec = m_opaque_ptr->GetPrimaryFile();
 
+    LineEntry line_entry;
     index = m_opaque_ptr->FindLineEntry(
         start_idx, line, inline_file_spec ? inline_file_spec->get() : nullptr,
-        exact, nullptr);
+        exact, &line_entry);
   }
 
   return index;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102658.346024.patch
Type: text/x-patch
Size: 2591 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20210518/6c1cb61d/attachment.bin>


More information about the lldb-commits mailing list