[lldb] Prevent object file plugins from changing the data buffer

The current design allows that the object file contents could be mapped
by one object file plugin and then used by another. Presumably the idea
here was to avoid mapping the same file twice.

This becomes an issue when one object file plugin wants to map the file
differently from the others. For example, ObjectFileELF needs to map its
memory as writable while others likeObjectFileMachO needs it to be
mapped read-only.

This patch prevents plugins from changing the buffer by passing them is
by value rather than by reference.

Differential revision: https://reviews.llvm.org/D122944
This commit is contained in:
Jonas Devlieghere
2022-04-04 09:17:01 -07:00
parent b08ede4374
commit c69307e5ee
17 changed files with 37 additions and 39 deletions

View File

@@ -77,12 +77,10 @@ llvm::StringRef ObjectFilePECOFF::GetPluginDescriptionStatic() {
"(32 and 64 bit)";
}
ObjectFile *ObjectFilePECOFF::CreateInstance(const lldb::ModuleSP &module_sp,
DataBufferSP &data_sp,
lldb::offset_t data_offset,
const lldb_private::FileSpec *file_p,
lldb::offset_t file_offset,
lldb::offset_t length) {
ObjectFile *ObjectFilePECOFF::CreateInstance(
const lldb::ModuleSP &module_sp, DataBufferSP data_sp,
lldb::offset_t data_offset, const lldb_private::FileSpec *file_p,
lldb::offset_t file_offset, lldb::offset_t length) {
FileSpec file = file_p ? *file_p : FileSpec();
if (!data_sp) {
data_sp = MapFileData(file, length, file_offset);
@@ -113,7 +111,7 @@ ObjectFile *ObjectFilePECOFF::CreateInstance(const lldb::ModuleSP &module_sp,
}
ObjectFile *ObjectFilePECOFF::CreateMemoryInstance(
const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
const lldb::ModuleSP &module_sp, lldb::DataBufferSP data_sp,
const lldb::ProcessSP &process_sp, lldb::addr_t header_addr) {
if (!data_sp || !ObjectFilePECOFF::MagicBytesMatch(data_sp))
return nullptr;