Skip to content

[lldb] Store *signed* ranges in lldb_private::Block #120224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 9, 2025
Merged

Conversation

labath
Copy link
Collaborator

@labath labath commented Dec 17, 2024

This is to support functions whose entry points aren't their lowest address
(https://discourse.llvm.org/t/rfcish-support-for-discontinuous-functions/83244). The alternative is to keep blocks relative to the lowest address, but then introduce a separate concept for the function entry point, which I think would be more confusing.

This patch just changes the type signedness, it doesn't create any negative offsets yet. Since combining values with different signs can sometimes produce unexpected results, and since this is the first use of RangeVector with a signed type, I'm adding a test to verify that at least the core functionality works correctly.

This is to support functions whose entry points aren't their lowest
address
(https://discourse.llvm.org/t/rfcish-support-for-discontinuous-functions/83244).
The alternative is to keep blocks relative to the lowest address,
but then introduce a separate concept for the function entry point,
which I think would be more confusing.

This patch just changes the type signedness, it doesn't create any
negative offsets yet. Since combining values with different signs can
sometimes produce unexpected results, and since this is the first use of
RangeVector with a signed type, I'm adding a test to verify that at
least the core functionality works correctly.
@llvmbot
Copy link
Member

llvmbot commented Dec 17, 2024

@llvm/pr-subscribers-lldb

Author: Pavel Labath (labath)

Changes

This is to support functions whose entry points aren't their lowest address
(https://discourse.llvm.org/t/rfcish-support-for-discontinuous-functions/83244). The alternative is to keep blocks relative to the lowest address, but then introduce a separate concept for the function entry point, which I think would be more confusing.

This patch just changes the type signedness, it doesn't create any negative offsets yet. Since combining values with different signs can sometimes produce unexpected results, and since this is the first use of RangeVector with a signed type, I'm adding a test to verify that at least the core functionality works correctly.


Full diff: https://github.com/llvm/llvm-project/pull/120224.diff

2 Files Affected:

  • (modified) lldb/include/lldb/Symbol/Block.h (+1-1)
  • (modified) lldb/unittests/Utility/RangeMapTest.cpp (+23)
diff --git a/lldb/include/lldb/Symbol/Block.h b/lldb/include/lldb/Symbol/Block.h
index 7c7a66de831998..d0063f132cc0ff 100644
--- a/lldb/include/lldb/Symbol/Block.h
+++ b/lldb/include/lldb/Symbol/Block.h
@@ -40,7 +40,7 @@ namespace lldb_private {
 /// blocks.
 class Block : public UserID, public SymbolContextScope {
 public:
-  typedef RangeVector<uint32_t, uint32_t, 1> RangeList;
+  typedef RangeVector<int32_t, uint32_t, 1> RangeList;
   typedef RangeList::Entry Range;
 
   // Creates a block representing the whole function. Only meant to be used from
diff --git a/lldb/unittests/Utility/RangeMapTest.cpp b/lldb/unittests/Utility/RangeMapTest.cpp
index 0b4c236062f20b..981fa2a7d1c34e 100644
--- a/lldb/unittests/Utility/RangeMapTest.cpp
+++ b/lldb/unittests/Utility/RangeMapTest.cpp
@@ -12,6 +12,29 @@
 
 using namespace lldb_private;
 
+TEST(RangeVector, SignedBaseType) {
+  using RangeVector = RangeVector<int32_t, uint32_t>;
+  using Entry = RangeVector::Entry;
+
+  RangeVector V;
+  V.Append(10, 5);
+  V.Append(-3, 6);
+  V.Append(-10, 3);
+  V.Sort();
+  EXPECT_THAT(V,
+              testing::ElementsAre(Entry(-10, 3), Entry(-3, 6), Entry(10, 5)));
+  Entry e = *V.begin();
+  EXPECT_EQ(e.GetRangeBase(), -10);
+  EXPECT_EQ(e.GetByteSize(), 3u);
+  EXPECT_EQ(e.GetRangeEnd(), -7);
+  EXPECT_TRUE(e.Contains(-10));
+  EXPECT_TRUE(e.Contains(-8));
+  EXPECT_FALSE(e.Contains(-7));
+  EXPECT_TRUE(e.Union(Entry(-8, 2)));
+  EXPECT_EQ(e, Entry(-10, 4));
+  EXPECT_EQ(e.Intersect(Entry(-7, 3)), Entry(-7, 1));
+}
+
 TEST(RangeVector, CombineConsecutiveRanges) {
   using RangeVector = RangeVector<uint32_t, uint32_t>;
   using Entry = RangeVector::Entry;

Copy link
Collaborator

@DavidSpickett DavidSpickett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine assuming no one puts part of a function > 2GB before its entry point. Seems unlikely given that no one tried to put anything > 4GB after the entry point either.

LGTM.

@labath labath merged commit a261eee into llvm:main Jan 9, 2025
9 checks passed
@labath labath deleted the sigrange branch January 9, 2025 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants