[Lldb-commits] [lldb] [lldb][Darwin] Fetch detailed binary info in chunks (PR #190720)
Jason Molenda via lldb-commits
lldb-commits at lists.llvm.org
Wed Apr 8 16:28:29 PDT 2026
================
@@ -413,26 +440,43 @@ void DynamicLoaderMacOS::AddBinaries(
Log *log = GetLog(LLDBLog::DynamicLoader);
ImageInfo::collection image_infos;
- LLDB_LOGF(log, "Adding %" PRId64 " modules.",
- (uint64_t)load_addresses.size());
- StructuredData::ObjectSP binaries_info_sp =
- m_process->GetLoadedDynamicLibrariesInfos(load_addresses);
- if (binaries_info_sp.get() && binaries_info_sp->GetAsDictionary() &&
- binaries_info_sp->GetAsDictionary()->HasKey("images") &&
- binaries_info_sp->GetAsDictionary()
- ->GetValueForKey("images")
- ->GetAsArray() &&
- binaries_info_sp->GetAsDictionary()
- ->GetValueForKey("images")
- ->GetAsArray()
- ->GetSize() == load_addresses.size()) {
- if (JSONImageInformationIntoImageInfo(binaries_info_sp, image_infos)) {
- auto images = PreloadModulesFromImageInfos(image_infos);
- UpdateSpecialBinariesFromPreloadedModules(images);
- AddModulesUsingPreloadedModules(images);
+ const size_t image_fetch_max = 600;
+ std::vector<addr_t> fetch_binaries;
+ size_t fetched = 0;
+ size_t total_image_size = load_addresses.size();
+ fetch_binaries.reserve(std::min(image_fetch_max, total_image_size));
+ while (fetched < total_image_size) {
+ size_t this_fetch_amt =
+ std::min(image_fetch_max, total_image_size - fetched);
+ fetch_binaries.resize(this_fetch_amt);
+ // `addr_t* + num_elem` -- pointer math is addr_t sized.
+ const addr_t *this_chunk_start = load_addresses.data() + fetched;
+ memcpy(fetch_binaries.data(), this_chunk_start,
+ this_fetch_amt * sizeof(addr_t));
+
+ LLDB_LOGF(log, "Adding %" PRId64 " modules.",
+ (uint64_t)fetch_binaries.size());
+ image_infos.clear();
+ StructuredData::ObjectSP binaries_info_sp =
+ m_process->GetLoadedDynamicLibrariesInfos(fetch_binaries);
+ if (binaries_info_sp.get() && binaries_info_sp->GetAsDictionary() &&
+ binaries_info_sp->GetAsDictionary()->HasKey("images") &&
+ binaries_info_sp->GetAsDictionary()
+ ->GetValueForKey("images")
+ ->GetAsArray()) {
+ StructuredData::Array *images = binaries_info_sp->GetAsDictionary()
+ ->GetValueForKey("images")
+ ->GetAsArray();
+ if (images->GetSize() == fetch_binaries.size() &&
----------------
jasonmolenda wrote:
Yeah this is imagining a scenario where we asked for detailed information about 10 binaries, and debugserver only reported detailed information for 9 of them. This might happen if debugserver couldn't read the memory of the mach-o header/load commands, or couldn't parse the load commands, or dyld itself was inconsistent and told us a binary at addr x was loaded, but the libdyld SPI we use to find the filepath for binaries doesn't include anything at addr x. If that ever did happen, probably the best choice is to process the binaries we did get, instead of abandoning the entire batch.
https://github.com/llvm/llvm-project/pull/190720
More information about the lldb-commits
mailing list