-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[lldb] Support negative function offsets in UnwindPlans #134662
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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-lldb Author: Pavel Labath (labath) ChangesThese are needed for functions whose entry point is not their lowest address. Full diff: https://github.com/llvm/llvm-project/pull/134662.diff 5 Files Affected:
diff --git a/lldb/include/lldb/Symbol/UnwindPlan.h b/lldb/include/lldb/Symbol/UnwindPlan.h
index 6640a23a3e868..410289851a879 100644
--- a/lldb/include/lldb/Symbol/UnwindPlan.h
+++ b/lldb/include/lldb/Symbol/UnwindPlan.h
@@ -356,11 +356,11 @@ class UnwindPlan {
void RemoveRegisterInfo(uint32_t reg_num);
- lldb::addr_t GetOffset() const { return m_offset; }
+ int64_t GetOffset() const { return m_offset; }
- void SetOffset(lldb::addr_t offset) { m_offset = offset; }
+ void SetOffset(int64_t offset) { m_offset = offset; }
- void SlideOffset(lldb::addr_t offset) { m_offset += offset; }
+ void SlideOffset(int64_t offset) { m_offset += offset; }
const FAValue &GetCFAValue() const { return m_cfa_value; }
FAValue &GetCFAValue() { return m_cfa_value; }
@@ -420,7 +420,7 @@ class UnwindPlan {
protected:
typedef std::map<uint32_t, AbstractRegisterLocation> collection;
- lldb::addr_t m_offset = 0; // Offset into the function for this row
+ int64_t m_offset = 0; // Offset into the function for this row
FAValue m_cfa_value;
FAValue m_afa_value;
@@ -472,7 +472,7 @@ class UnwindPlan {
// practice, the UnwindPlan for a function with no known start address will be
// the architectural default UnwindPlan which will only have one row.
const UnwindPlan::Row *
- GetRowForFunctionOffset(std::optional<int> offset) const;
+ GetRowForFunctionOffset(std::optional<int64_t> offset) const;
lldb::RegisterKind GetRegisterKind() const { return m_register_kind; }
diff --git a/lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp b/lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp
index 3eaa2f33fce3e..aaff278ca31e2 100644
--- a/lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp
+++ b/lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp
@@ -1390,11 +1390,12 @@ bool x86AssemblyInspectionEngine::AugmentUnwindPlanFromCallSite(
// If we already have one row for this instruction, we can continue.
while (row_id < unwind_plan.GetRowCount() &&
- unwind_plan.GetRowAtIndex(row_id)->GetOffset() <= offset) {
+ unwind_plan.GetRowAtIndex(row_id)->GetOffset() <=
+ static_cast<int64_t>(offset)) {
row_id++;
}
const UnwindPlan::Row *original_row = unwind_plan.GetRowAtIndex(row_id - 1);
- if (original_row->GetOffset() == offset) {
+ if (original_row->GetOffset() == static_cast<int64_t>(offset)) {
row = *original_row;
continue;
}
diff --git a/lldb/source/Symbol/DWARFCallFrameInfo.cpp b/lldb/source/Symbol/DWARFCallFrameInfo.cpp
index 957818e8d077f..dca3f665b0b80 100644
--- a/lldb/source/Symbol/DWARFCallFrameInfo.cpp
+++ b/lldb/source/Symbol/DWARFCallFrameInfo.cpp
@@ -765,7 +765,7 @@ bool DWARFCallFrameInfo::FDEToUnwindPlan(dw_offset_t dwarf_offset,
__FUNCTION__, dwarf_offset, startaddr.GetFileAddress());
break;
}
- lldb::addr_t offset = row.GetOffset();
+ int64_t offset = row.GetOffset();
row = std::move(stack.back());
stack.pop_back();
row.SetOffset(offset);
diff --git a/lldb/source/Symbol/UnwindPlan.cpp b/lldb/source/Symbol/UnwindPlan.cpp
index cfa8eefaa55bb..33aba0a859d5c 100644
--- a/lldb/source/Symbol/UnwindPlan.cpp
+++ b/lldb/source/Symbol/UnwindPlan.cpp
@@ -398,10 +398,10 @@ void UnwindPlan::AppendRow(Row row) {
}
struct RowLess {
- bool operator()(addr_t a, const UnwindPlan::RowSP &b) const {
+ bool operator()(int64_t a, const UnwindPlan::RowSP &b) const {
return a < b->GetOffset();
}
- bool operator()(const UnwindPlan::RowSP &a, addr_t b) const {
+ bool operator()(const UnwindPlan::RowSP &a, int64_t b) const {
return a->GetOffset() < b;
}
};
@@ -418,7 +418,7 @@ void UnwindPlan::InsertRow(Row row, bool replace_existing) {
}
const UnwindPlan::Row *
-UnwindPlan::GetRowForFunctionOffset(std::optional<int> offset) const {
+UnwindPlan::GetRowForFunctionOffset(std::optional<int64_t> offset) const {
auto it = offset ? llvm::upper_bound(m_row_list, *offset, RowLess())
: m_row_list.end();
if (it == m_row_list.begin())
diff --git a/lldb/unittests/Symbol/UnwindPlanTest.cpp b/lldb/unittests/Symbol/UnwindPlanTest.cpp
index fa8bb153e9247..08aa5b2dd84bb 100644
--- a/lldb/unittests/Symbol/UnwindPlanTest.cpp
+++ b/lldb/unittests/Symbol/UnwindPlanTest.cpp
@@ -24,6 +24,7 @@ static UnwindPlan::Row make_simple_row(addr_t offset, uint64_t cfa_value) {
TEST(UnwindPlan, InsertRow) {
UnwindPlan::Row row1 = make_simple_row(0, 42);
UnwindPlan::Row row2 = make_simple_row(0, 47);
+ UnwindPlan::Row row3 = make_simple_row(-1, 4242);
UnwindPlan plan(eRegisterKindGeneric);
plan.InsertRow(row1);
@@ -34,6 +35,10 @@ TEST(UnwindPlan, InsertRow) {
plan.InsertRow(row2, /*replace_existing=*/true);
EXPECT_THAT(plan.GetRowForFunctionOffset(0), testing::Pointee(row2));
+
+ EXPECT_THAT(plan.GetRowForFunctionOffset(-1), nullptr);
+ plan.InsertRow(row3);
+ EXPECT_THAT(plan.GetRowForFunctionOffset(-1), testing::Pointee(row3));
}
TEST(UnwindPlan, GetRowForFunctionOffset) {
|
jasonmolenda
approved these changes
Apr 9, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting OK.
These are needed for functions whose entry point is not their lowest address.
var-const
pushed a commit
to ldionne/llvm-project
that referenced
this pull request
Apr 17, 2025
These are needed for functions whose entry point is not their lowest address.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
These are needed for functions whose entry point is not their lowest address.