@@ -308,40 +308,49 @@ Status MinidumpFileBuilder::AddModuleList() {
308308 // the llvm::minidump::Module's structures into helper data
309309 size_t size_before = GetCurrentDataEndOffset ();
310310
311- // This is the size of the main part of the ModuleList stream.
312- // It consists of a module number and corresponding number of
313- // structs describing individual modules
314- size_t module_stream_size =
315- sizeof (llvm::support::ulittle32_t ) + modules_count * minidump_module_size;
316-
317- // Adding directory describing this stream.
318- error = AddDirectory (StreamType::ModuleList, module_stream_size);
319- if (error.Fail ())
320- return error;
321-
322- m_data.AppendData (&modules_count, sizeof (llvm::support::ulittle32_t ));
323-
324311 // Temporary storage for the helper data (of variable length)
325312 // as these cannot be dumped to m_data before dumping entire
326313 // array of module structures.
327314 DataBufferHeap helper_data;
328315
316+ // Vector to store modules that pass validation.
317+ std::vector<std::pair<ModuleSP, uint64_t >> valid_modules;
318+
329319 for (size_t i = 0 ; i < modules_count; ++i) {
330320 ModuleSP mod = modules.GetModuleAtIndex (i);
331321 std::string module_name = mod->GetSpecificationDescription ();
332322 auto maybe_mod_size = getModuleFileSize (target, mod);
333323 if (!maybe_mod_size) {
334324 llvm::Error mod_size_err = maybe_mod_size.takeError ();
335- llvm::handleAllErrors (std::move (mod_size_err),
336- [&](const llvm::ErrorInfoBase &E) {
337- error = Status::FromErrorStringWithFormat (
338- " Unable to get the size of module %s: %s." ,
339- module_name.c_str (), E.message ().c_str ());
340- });
341- return error;
325+ Log *log = GetLog (LLDBLog::Object);
326+ llvm::handleAllErrors (
327+ std::move (mod_size_err), [&](const llvm::ErrorInfoBase &E) {
328+ if (log) {
329+ LLDB_LOGF (log, " Unable to get the size of module %s: %s" ,
330+ module_name.c_str (), E.message ().c_str ());
331+ }
332+ });
333+ continue ;
342334 }
335+ valid_modules.emplace_back (mod, *maybe_mod_size);
336+ }
337+
338+ size_t module_stream_size = sizeof (llvm::support::ulittle32_t ) +
339+ valid_modules.size () * minidump_module_size;
340+
341+ error = AddDirectory (StreamType::ModuleList, module_stream_size);
342+ if (error.Fail ())
343+ return error;
343344
344- uint64_t mod_size = std::move (*maybe_mod_size);
345+ // Setting the header with the number of modules.
346+ llvm::support::ulittle32_t count =
347+ static_cast <llvm::support::ulittle32_t >(valid_modules.size ());
348+ m_data.AppendData (&count, sizeof (llvm::support::ulittle32_t ));
349+
350+ for (const auto &valid_module : valid_modules) {
351+ ModuleSP mod = valid_module.first ;
352+ uint64_t module_size = valid_module.second ;
353+ std::string module_name = mod->GetSpecificationDescription ();
345354
346355 llvm::support::ulittle32_t signature =
347356 static_cast <llvm::support::ulittle32_t >(
@@ -381,7 +390,7 @@ Status MinidumpFileBuilder::AddModuleList() {
381390 llvm::minidump::Module m{};
382391 m.BaseOfImage = static_cast <llvm::support::ulittle64_t >(
383392 mod->GetObjectFile ()->GetBaseAddress ().GetLoadAddress (&target));
384- m.SizeOfImage = static_cast <llvm::support::ulittle32_t >(mod_size );
393+ m.SizeOfImage = static_cast <llvm::support::ulittle32_t >(module_size );
385394 m.Checksum = static_cast <llvm::support::ulittle32_t >(0 );
386395 m.TimeDateStamp =
387396 static_cast <llvm::support::ulittle32_t >(std::time (nullptr ));
0 commit comments