-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[LLDB][NFC] Calculate the region size of an in memory image if size isn't specified #123148
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -2544,6 +2544,26 @@ ModuleSP Process::ReadModuleFromMemory(const FileSpec &file_spec, | |
| progress_up = std::make_unique<Progress>( | ||
| "Reading binary from memory", file_spec.GetFilename().GetString()); | ||
|
|
||
| if (size_to_read == 0) { | ||
| // No size was provided, figure out the size of the memory region that | ||
| // contains "header_addr" | ||
| MemoryRegionInfo header_region_info; | ||
| Status error(GetMemoryRegionInfo(header_addr, header_region_info)); | ||
| // Default to 512 in case we can't find a memory region. | ||
| size_to_read = 512; | ||
| if (error.Success()) { | ||
| // We found a memory region, set the range of bytes ro read to read to | ||
| // the end of the memory region. This should be enough to contain the | ||
| // file header and important bits. | ||
| const auto &range = header_region_info.GetRange(); | ||
|
Contributor
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. Echoing what Pavel said a little bit, I do think an upper bound makes sense. I think we can be pretty heavy handed with that upper-bound. I'm not an expert on ELF files by any means, but I suspect something like 10MB or even 100 MB, will be a sane expectation for even the largest set of ELF headers. |
||
| const addr_t end = range.GetRangeBase() + range.GetByteSize(); | ||
|
Contributor
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. Should this be an error? The end should always be greater than the addr correct? |
||
| if (end > header_addr) { | ||
| const addr_t new_size = end - header_addr; | ||
| if (new_size > size_to_read) | ||
| size_to_read = new_size; | ||
| } | ||
| } | ||
| } | ||
| ObjectFile *objfile = module_sp->GetMemoryObjectFile( | ||
| shared_from_this(), header_addr, error, size_to_read); | ||
| if (objfile) | ||
|
|
||
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.
Typo plus maybe rephrase to