Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 38 additions & 21 deletions lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,40 +308,57 @@ Status MinidumpFileBuilder::AddModuleList() {
// the llvm::minidump::Module's structures into helper data
size_t size_before = GetCurrentDataEndOffset();

// This is the size of the main part of the ModuleList stream.
// It consists of a module number and corresponding number of
// structs describing individual modules
size_t module_stream_size =
sizeof(llvm::support::ulittle32_t) + modules_count * minidump_module_size;

// Adding directory describing this stream.
error = AddDirectory(StreamType::ModuleList, module_stream_size);
if (error.Fail())
return error;

m_data.AppendData(&modules_count, sizeof(llvm::support::ulittle32_t));

// Temporary storage for the helper data (of variable length)
// as these cannot be dumped to m_data before dumping entire
// array of module structures.
DataBufferHeap helper_data;

// Struct to hold module information.
struct ValidModuleInfo {
ModuleSP module;
std::string module_name;
uint64_t module_size;
};

// Vector to store modules that pass validation.
std::vector<ValidModuleInfo> valid_modules;

// Track the count of successfully processed modules and log errors.
uint32_t successful_modules_count = 0;
for (size_t i = 0; i < modules_count; ++i) {
ModuleSP mod = modules.GetModuleAtIndex(i);
std::string module_name = mod->GetSpecificationDescription();
auto maybe_mod_size = getModuleFileSize(target, mod);
if (!maybe_mod_size) {
llvm::Error mod_size_err = maybe_mod_size.takeError();
llvm::handleAllErrors(std::move(mod_size_err),
[&](const llvm::ErrorInfoBase &E) {
error = Status::FromErrorStringWithFormat(
"Unable to get the size of module %s: %s.",
module_name.c_str(), E.message().c_str());
});
return error;
Log *log = GetLog(LLDBLog::Object);
llvm::handleAllErrors(
std::move(mod_size_err), [&](const llvm::ErrorInfoBase &E) {
if (log) {
LLDB_LOGF(log, "Unable to get the size of module %s: %s",
module_name.c_str(), E.message().c_str());
}
});
continue;
}
++successful_modules_count;
valid_modules.push_back({mod, module_name, *maybe_mod_size});
}

size_t module_stream_size = sizeof(llvm::support::ulittle32_t) +
successful_modules_count * minidump_module_size;

error = AddDirectory(StreamType::ModuleList, module_stream_size);
if (error.Fail())
return error;

m_data.AppendData(&successful_modules_count,
sizeof(llvm::support::ulittle32_t));

uint64_t mod_size = std::move(*maybe_mod_size);
for (const auto &valid_module : valid_modules) {
ModuleSP mod = valid_module.module;
std::string module_name = valid_module.module_name;
uint64_t mod_size = valid_module.module_size;

llvm::support::ulittle32_t signature =
static_cast<llvm::support::ulittle32_t>(
Expand Down
Loading