shivammittal99 created this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

The FindEntryThatContains function does not return the correct entry in
the case when two non-consecutive entries contain the range.
Eg. Vector = [(0, 40, 0), (10, 10, 1)] and query = (25, 1). The function
currently returns nullptr, but it should return entry 0.

Signed-off-by: Shivam Mittal <shivammitta...@gmail.com>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77568

Files:
  lldb/include/lldb/Utility/RangeMap.h
  lldb/unittests/Utility/RangeMapTest.cpp


Index: lldb/unittests/Utility/RangeMapTest.cpp
===================================================================
--- lldb/unittests/Utility/RangeMapTest.cpp
+++ lldb/unittests/Utility/RangeMapTest.cpp
@@ -53,10 +53,7 @@
   // With overlapping intervals, the intention seems to be to return the first
   // interval which contains the address.
   EXPECT_THAT(Map.FindEntryThatContains(25), EntryIs(0));
-
-  // However, this does not always succeed.
-  // TODO: This should probably return the range (0, 40) as well.
-  EXPECT_THAT(Map.FindEntryThatContains(35), nullptr);
+  EXPECT_THAT(Map.FindEntryThatContains(35), EntryIs(0));
 }
 
 TEST(RangeDataVector, CustomSort) {
Index: lldb/include/lldb/Utility/RangeMap.h
===================================================================
--- lldb/include/lldb/Utility/RangeMap.h
+++ lldb/include/lldb/Utility/RangeMap.h
@@ -540,14 +540,13 @@
     if (!m_entries.empty()) {
       typename Collection::const_iterator begin = m_entries.begin();
       typename Collection::const_iterator end = m_entries.end();
-      typename Collection::const_iterator pos =
-          std::lower_bound(begin, end, range, BaseLessThan);
-
-      while (pos != begin && pos[-1].Contains(range))
-        --pos;
+      typename Collection::const_iterator limit =
+          std::upper_bound(begin, end, range, BaseLessThan);
 
-      if (pos != end && pos->Contains(range))
-        return &(*pos);
+      for (auto pos = begin; pos < limit; ++pos) {
+        if (pos->Contains(range))
+          return &(*pos);
+      }
     }
     return nullptr;
   }


Index: lldb/unittests/Utility/RangeMapTest.cpp
===================================================================
--- lldb/unittests/Utility/RangeMapTest.cpp
+++ lldb/unittests/Utility/RangeMapTest.cpp
@@ -53,10 +53,7 @@
   // With overlapping intervals, the intention seems to be to return the first
   // interval which contains the address.
   EXPECT_THAT(Map.FindEntryThatContains(25), EntryIs(0));
-
-  // However, this does not always succeed.
-  // TODO: This should probably return the range (0, 40) as well.
-  EXPECT_THAT(Map.FindEntryThatContains(35), nullptr);
+  EXPECT_THAT(Map.FindEntryThatContains(35), EntryIs(0));
 }
 
 TEST(RangeDataVector, CustomSort) {
Index: lldb/include/lldb/Utility/RangeMap.h
===================================================================
--- lldb/include/lldb/Utility/RangeMap.h
+++ lldb/include/lldb/Utility/RangeMap.h
@@ -540,14 +540,13 @@
     if (!m_entries.empty()) {
       typename Collection::const_iterator begin = m_entries.begin();
       typename Collection::const_iterator end = m_entries.end();
-      typename Collection::const_iterator pos =
-          std::lower_bound(begin, end, range, BaseLessThan);
-
-      while (pos != begin && pos[-1].Contains(range))
-        --pos;
+      typename Collection::const_iterator limit =
+          std::upper_bound(begin, end, range, BaseLessThan);
 
-      if (pos != end && pos->Contains(range))
-        return &(*pos);
+      for (auto pos = begin; pos < limit; ++pos) {
+        if (pos->Contains(range))
+          return &(*pos);
+      }
     }
     return nullptr;
   }
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
  • [Lldb-commits] [PATCH] D775... Shivam Mittal via Phabricator via lldb-commits

Reply via email to