diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp index f666795c25860..e511c4e867022 100644 --- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp +++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp @@ -177,7 +177,8 @@ ModuleSP DynamicLoaderDarwin::FindTargetModuleForImageInfo( // added to the target, don't let it be called for every one. if (!module_sp || module_sp->GetObjectFile() == nullptr) { llvm::Expected module_sp_or_err = m_process->ReadModuleFromMemory( - image_info.file_spec, image_info.address); + image_info.file_spec, image_info.address, + image_info.mh_and_load_cmd_size); if (auto err = module_sp_or_err.takeError()) { LLDB_LOG_ERROR(GetLog(LLDBLog::DynamicLoader), std::move(err), "Failed to load module from memory: {0}"); @@ -445,6 +446,10 @@ bool DynamicLoaderDarwin::JSONImageInformationIntoImageInfo( mh->GetValueForKey("cpusubtype")->GetUnsignedIntegerValue(); image_infos[i].header.filetype = mh->GetValueForKey("filetype")->GetUnsignedIntegerValue(); + if (mh->HasKey("sizeof_h_and_loadcmds")) + image_infos[i].mh_and_load_cmd_size = + mh->GetValueForKey("sizeof_mh_and_loadcmds") + ->GetUnsignedIntegerValue(); if (image->HasKey("min_version_os_name")) { std::string os_name = diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.h b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.h index 2c049837cf5b4..4473866d79d09 100644 --- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.h +++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.h @@ -121,6 +121,12 @@ class DynamicLoaderDarwin : public lldb_private::DynamicLoader { llvm::Triple::EnvironmentType::UnknownEnvironment; /// LC_VERSION_MIN_... SDK. std::string min_version_os_sdk; + /// When we need to read a binary's mach header and load commands + /// out of memory, this specifies how much to read to get + /// everything in one read packet, if known. Increase the + /// default 512 bytes to 3192 which is enough to include most + /// mach header + load commands. + uint32_t mh_and_load_cmd_size = 3192; ImageInfo() = default; @@ -137,6 +143,7 @@ class DynamicLoaderDarwin : public lldb_private::DynamicLoader { os_type = llvm::Triple::OSType::UnknownOS; os_env = llvm::Triple::EnvironmentType::UnknownEnvironment; min_version_os_sdk.clear(); + mh_and_load_cmd_size = 3192; } bool operator==(const ImageInfo &rhs) const { @@ -144,7 +151,8 @@ class DynamicLoaderDarwin : public lldb_private::DynamicLoader { file_spec == rhs.file_spec && uuid == rhs.uuid && memcmp(&header, &rhs.header, sizeof(header)) == 0 && segments == rhs.segments && os_type == rhs.os_type && - os_env == rhs.os_env; + os_env == rhs.os_env && + mh_and_load_cmd_size == rhs.mh_and_load_cmd_size; } bool UUIDValid() const { return uuid.IsValid(); }