-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[lldb] Add DWARFExpressionEntry and GetExpressionEntryAtAddress() to … #144238
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
Changes from 9 commits
8ed8c54
1db5002
a26010b
72237b7
94e4951
e8142da
7e8741e
c4cd77f
62c02a9
d015971
60898ea
3462165
c01a747
ec3ac93
38baa90
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "lldb/Core/AddressRange.h" | ||
| #include "lldb/Expression/DWARFExpressionList.h" | ||
| #include "lldb/Symbol/Function.h" | ||
| #include "lldb/Target/RegisterContext.h" | ||
|
|
@@ -53,6 +54,30 @@ bool DWARFExpressionList::ContainsAddress(lldb::addr_t func_load_addr, | |
| return GetExpressionAtAddress(func_load_addr, addr) != nullptr; | ||
| } | ||
|
|
||
| std::optional<DWARFExpressionList::DWARFExpressionEntry> | ||
| DWARFExpressionList::GetExpressionEntryAtAddress(lldb::addr_t func_load_addr, | ||
| lldb::addr_t load_addr) const { | ||
| if (const DWARFExpression *always = GetAlwaysValidExpr()) { | ||
| AddressRange full_range(m_func_file_addr, /*size=*/LLDB_INVALID_ADDRESS); | ||
| return DWARFExpressionEntry{full_range, always}; | ||
| } | ||
|
|
||
| if (func_load_addr == LLDB_INVALID_ADDRESS) | ||
| func_load_addr = m_func_file_addr; | ||
|
|
||
| // translate to file-relative PC | ||
UltimateForce21 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| lldb::addr_t file_pc = load_addr - func_load_addr + m_func_file_addr; | ||
|
||
|
|
||
| if (const auto *entry = m_exprs.FindEntryThatContains(file_pc)) { | ||
| AddressRange range_in_file(entry->GetRangeBase(), | ||
| entry->GetRangeEnd() - entry->GetRangeBase()); | ||
| return DWARFExpressionEntry{range_in_file, &entry->data}; | ||
| } | ||
|
|
||
| // No entry covers this PC: | ||
| return std::nullopt; | ||
| } | ||
|
|
||
| const DWARFExpression * | ||
| DWARFExpressionList::GetExpressionAtAddress(lldb::addr_t func_load_addr, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Out of curiosity: Do we still need this API, or is it just a subset of the function above?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As you know the new function GetExpressionEntryAtAddress, does almost exact same thing as this one. I don't see this function being used anywhere else in the lldb code base, so maybe it can be removed, but to be safe I did not want to alter it. But from what I can tell, it should be okay to remove it. We can also choose to keep it and maybe refactor it to just call the GetExpressionEntryAtAddress and just return the
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it's completely unused, and there is no indication that was added in support of any downstream clients (either as a comment or in the commit message) we could consider deleting it in a separate PR. Not urgent. |
||
| lldb::addr_t load_addr) const { | ||
|
|
||
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.
The name of the argument is
byte_sizeso let's match that.I'm somewhat skeptical of
LLDB_INVALID_ADDRESSas the size. Is there precedent for using that to indicate we don't know the size? I'm worried about whether the existing code is resilient to that. Would it make sense to make the AddressRange optional in the struct for the always-valid-single-expression case?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.
I believe using an optional
AddressRangethe way you said is a safer option and probably more clear for users, I have committed the change.