-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[lldb][NFCI] Simplify ProcessElfCore::GetAuxvData() #102263
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
[lldb][NFCI] Simplify ProcessElfCore::GetAuxvData() #102263
Conversation
There is no need to create a new `DataExtractor` and clone the content, because `m_auxv` already has the required form.
@llvm/pr-subscribers-lldb Author: Igor Kudrin (igorkudrin) ChangesThere is no need to clone the content and set extraction properties because Full diff: https://github.com/llvm/llvm-project/pull/102263.diff 1 Files Affected:
diff --git a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
index 30af9345999c41..e73e31ca78d19f 100644
--- a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
+++ b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
@@ -1077,10 +1077,10 @@ ArchSpec ProcessElfCore::GetArchitecture() {
}
DataExtractor ProcessElfCore::GetAuxvData() {
- const uint8_t *start = m_auxv.GetDataStart();
- size_t len = m_auxv.GetByteSize();
- lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(start, len));
- return DataExtractor(buffer, GetByteOrder(), GetAddressByteSize());
+ assert(m_auxv.GetByteSize() == 0 ||
+ (m_auxv.GetByteOrder() == GetByteOrder() &&
+ m_auxv.GetAddressByteSize() == GetAddressByteSize()));
+ return DataExtractor(m_auxv);
}
bool ProcessElfCore::GetProcessInfo(ProcessInstanceInfo &info) {
|
assert(m_auxv.GetByteSize() == 0 || | ||
(m_auxv.GetByteOrder() == GetByteOrder() && | ||
m_auxv.GetAddressByteSize() == GetAddressByteSize())); |
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.
Do we need this assert? Can't we just change this to:
const DataExtractor &ProcessElfCore::GetAuxvData() { return m_auxv; }
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 added the assert
to be on the safe side. It shows that the change is eligible, and if I overlooked some exotic execution path, it will trigger and point directly to the problem. If you believe it's excessive, I'll remove it.
The copy constructor for DataExtractor
should be called explicitly, see the comment. And GetAuxvData()
cannot be changed to return a reference to a data member because in some classes it returns a temporary object.
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.
There is no need to copy the data extractor. It contains no modifiable state as the position curser is passed in as variables when acessing the data within. I would highly suggest changing to:
const DataExtractor &ProcessElfCore::GetAuxvData() {
// Feel free to add asserts here if you want them as long as the code functions correctly
// even if the asserts get triggered.
return m_auxv;
}
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'd also prefer to return a constant reference, but there are other implementations of this virtual function that can't do that, for example, ProcessGDBRemote::GetAuxvData()
.
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.
Sorry, I didn't realize this was a virtual function from Process.h...
There is no need to clone the content and set extraction properties because
m_auxv
is already in the required form.