Skip to content

[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

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Comment on lines +1080 to +1082
Copy link
Collaborator

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; }

Copy link
Collaborator Author

@igorkudrin igorkudrin Aug 7, 2024

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.

Copy link
Collaborator

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; 
}

Copy link
Collaborator Author

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().

Copy link
Collaborator

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...

return DataExtractor(m_auxv);
}

bool ProcessElfCore::GetProcessInfo(ProcessInstanceInfo &info) {
Expand Down
Loading