Skip to content

Commit

Permalink
[lldb] Store *signed* ranges in lldb_private::Block (llvm#120224)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
labath authored Jan 9, 2025
1 parent 6c06253 commit a261eee
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lldb/include/lldb/Symbol/Block.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions lldb/unittests/Utility/RangeMapTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a261eee

Please sign in to comment.