Skip to content

Commit 26b46c0

Browse files
committed
[lldb] Support negative function offsets in UnwindPlans
These are needed for functions whose entry point is not their lowest address.
1 parent f04bfbc commit 26b46c0

File tree

5 files changed

+17
-11
lines changed

5 files changed

+17
-11
lines changed

lldb/include/lldb/Symbol/UnwindPlan.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -356,11 +356,11 @@ class UnwindPlan {
356356

357357
void RemoveRegisterInfo(uint32_t reg_num);
358358

359-
lldb::addr_t GetOffset() const { return m_offset; }
359+
int64_t GetOffset() const { return m_offset; }
360360

361-
void SetOffset(lldb::addr_t offset) { m_offset = offset; }
361+
void SetOffset(int64_t offset) { m_offset = offset; }
362362

363-
void SlideOffset(lldb::addr_t offset) { m_offset += offset; }
363+
void SlideOffset(int64_t offset) { m_offset += offset; }
364364

365365
const FAValue &GetCFAValue() const { return m_cfa_value; }
366366
FAValue &GetCFAValue() { return m_cfa_value; }
@@ -420,7 +420,7 @@ class UnwindPlan {
420420

421421
protected:
422422
typedef std::map<uint32_t, AbstractRegisterLocation> collection;
423-
lldb::addr_t m_offset = 0; // Offset into the function for this row
423+
int64_t m_offset = 0; // Offset into the function for this row
424424

425425
FAValue m_cfa_value;
426426
FAValue m_afa_value;
@@ -455,7 +455,7 @@ class UnwindPlan {
455455
// practice, the UnwindPlan for a function with no known start address will be
456456
// the architectural default UnwindPlan which will only have one row.
457457
const UnwindPlan::Row *
458-
GetRowForFunctionOffset(std::optional<int> offset) const;
458+
GetRowForFunctionOffset(std::optional<int64_t> offset) const;
459459

460460
lldb::RegisterKind GetRegisterKind() const { return m_register_kind; }
461461

lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,11 +1390,12 @@ bool x86AssemblyInspectionEngine::AugmentUnwindPlanFromCallSite(
13901390

13911391
// If we already have one row for this instruction, we can continue.
13921392
while (row_id < unwind_plan.GetRowCount() &&
1393-
unwind_plan.GetRowAtIndex(row_id)->GetOffset() <= offset) {
1393+
unwind_plan.GetRowAtIndex(row_id)->GetOffset() <=
1394+
static_cast<int64_t>(offset)) {
13941395
row_id++;
13951396
}
13961397
const UnwindPlan::Row *original_row = unwind_plan.GetRowAtIndex(row_id - 1);
1397-
if (original_row->GetOffset() == offset) {
1398+
if (original_row->GetOffset() == static_cast<int64_t>(offset)) {
13981399
row = *original_row;
13991400
continue;
14001401
}

lldb/source/Symbol/DWARFCallFrameInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ bool DWARFCallFrameInfo::FDEToUnwindPlan(dw_offset_t dwarf_offset,
765765
__FUNCTION__, dwarf_offset, startaddr.GetFileAddress());
766766
break;
767767
}
768-
lldb::addr_t offset = row.GetOffset();
768+
int64_t offset = row.GetOffset();
769769
row = std::move(stack.back());
770770
stack.pop_back();
771771
row.SetOffset(offset);

lldb/source/Symbol/UnwindPlan.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,10 +398,10 @@ void UnwindPlan::AppendRow(Row row) {
398398
}
399399

400400
struct RowLess {
401-
bool operator()(addr_t a, const UnwindPlan::Row &b) const {
401+
bool operator()(int64_t a, const UnwindPlan::Row &b) const {
402402
return a < b.GetOffset();
403403
}
404-
bool operator()(const UnwindPlan::Row &a, addr_t b) const {
404+
bool operator()(const UnwindPlan::Row &a, int64_t b) const {
405405
return a.GetOffset() < b;
406406
}
407407
};
@@ -418,7 +418,7 @@ void UnwindPlan::InsertRow(Row row, bool replace_existing) {
418418
}
419419

420420
const UnwindPlan::Row *
421-
UnwindPlan::GetRowForFunctionOffset(std::optional<int> offset) const {
421+
UnwindPlan::GetRowForFunctionOffset(std::optional<int64_t> offset) const {
422422
auto it = offset ? llvm::upper_bound(m_row_list, *offset, RowLess())
423423
: m_row_list.end();
424424
if (it == m_row_list.begin())

lldb/unittests/Symbol/UnwindPlanTest.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ static UnwindPlan::Row make_simple_row(addr_t offset, uint64_t cfa_value) {
2424
TEST(UnwindPlan, InsertRow) {
2525
UnwindPlan::Row row1 = make_simple_row(0, 42);
2626
UnwindPlan::Row row2 = make_simple_row(0, 47);
27+
UnwindPlan::Row row3 = make_simple_row(-1, 4242);
2728

2829
UnwindPlan plan(eRegisterKindGeneric);
2930
plan.InsertRow(row1);
@@ -34,6 +35,10 @@ TEST(UnwindPlan, InsertRow) {
3435

3536
plan.InsertRow(row2, /*replace_existing=*/true);
3637
EXPECT_THAT(plan.GetRowForFunctionOffset(0), testing::Pointee(row2));
38+
39+
EXPECT_THAT(plan.GetRowForFunctionOffset(-1), nullptr);
40+
plan.InsertRow(row3);
41+
EXPECT_THAT(plan.GetRowForFunctionOffset(-1), testing::Pointee(row3));
3742
}
3843

3944
TEST(UnwindPlan, GetRowForFunctionOffset) {

0 commit comments

Comments
 (0)