Skip to content

Commit a261eee

Browse files
authored
[lldb] Store *signed* ranges in lldb_private::Block (#120224)
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.
1 parent 6c06253 commit a261eee

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lldb/include/lldb/Symbol/Block.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace lldb_private {
4040
/// blocks.
4141
class Block : public UserID, public SymbolContextScope {
4242
public:
43-
typedef RangeVector<uint32_t, uint32_t, 1> RangeList;
43+
typedef RangeVector<int32_t, uint32_t, 1> RangeList;
4444
typedef RangeList::Entry Range;
4545

4646
// Creates a block representing the whole function. Only meant to be used from

lldb/unittests/Utility/RangeMapTest.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,29 @@
1212

1313
using namespace lldb_private;
1414

15+
TEST(RangeVector, SignedBaseType) {
16+
using RangeVector = RangeVector<int32_t, uint32_t>;
17+
using Entry = RangeVector::Entry;
18+
19+
RangeVector V;
20+
V.Append(10, 5);
21+
V.Append(-3, 6);
22+
V.Append(-10, 3);
23+
V.Sort();
24+
EXPECT_THAT(V,
25+
testing::ElementsAre(Entry(-10, 3), Entry(-3, 6), Entry(10, 5)));
26+
Entry e = *V.begin();
27+
EXPECT_EQ(e.GetRangeBase(), -10);
28+
EXPECT_EQ(e.GetByteSize(), 3u);
29+
EXPECT_EQ(e.GetRangeEnd(), -7);
30+
EXPECT_TRUE(e.Contains(-10));
31+
EXPECT_TRUE(e.Contains(-8));
32+
EXPECT_FALSE(e.Contains(-7));
33+
EXPECT_TRUE(e.Union(Entry(-8, 2)));
34+
EXPECT_EQ(e, Entry(-10, 4));
35+
EXPECT_EQ(e.Intersect(Entry(-7, 3)), Entry(-7, 1));
36+
}
37+
1538
TEST(RangeVector, CombineConsecutiveRanges) {
1639
using RangeVector = RangeVector<uint32_t, uint32_t>;
1740
using Entry = RangeVector::Entry;

0 commit comments

Comments
 (0)