Path: blob/main/contrib/llvm-project/lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.cpp
39642 views
//===-- ObjectFileMinidump.cpp --------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "ObjectFileMinidump.h"910#include "MinidumpFileBuilder.h"1112#include "lldb/Core/ModuleSpec.h"13#include "lldb/Core/PluginManager.h"14#include "lldb/Core/Section.h"15#include "lldb/Target/Process.h"16#include "lldb/Utility/LLDBLog.h"17#include "lldb/Utility/Log.h"1819#include "llvm/Support/FileSystem.h"2021using namespace lldb;22using namespace lldb_private;2324LLDB_PLUGIN_DEFINE(ObjectFileMinidump)2526void ObjectFileMinidump::Initialize() {27PluginManager::RegisterPlugin(28GetPluginNameStatic(), GetPluginDescriptionStatic(), CreateInstance,29CreateMemoryInstance, GetModuleSpecifications, SaveCore);30}3132void ObjectFileMinidump::Terminate() {33PluginManager::UnregisterPlugin(CreateInstance);34}3536ObjectFile *ObjectFileMinidump::CreateInstance(37const lldb::ModuleSP &module_sp, lldb::DataBufferSP data_sp,38lldb::offset_t data_offset, const lldb_private::FileSpec *file,39lldb::offset_t offset, lldb::offset_t length) {40return nullptr;41}4243ObjectFile *ObjectFileMinidump::CreateMemoryInstance(44const lldb::ModuleSP &module_sp, WritableDataBufferSP data_sp,45const ProcessSP &process_sp, lldb::addr_t header_addr) {46return nullptr;47}4849size_t ObjectFileMinidump::GetModuleSpecifications(50const lldb_private::FileSpec &file, lldb::DataBufferSP &data_sp,51lldb::offset_t data_offset, lldb::offset_t file_offset,52lldb::offset_t length, lldb_private::ModuleSpecList &specs) {53specs.Clear();54return 0;55}5657bool ObjectFileMinidump::SaveCore(const lldb::ProcessSP &process_sp,58const lldb_private::SaveCoreOptions &options,59lldb_private::Status &error) {60// Output file and process_sp are both checked in PluginManager::SaveCore.61assert(options.GetOutputFile().has_value());62assert(process_sp);6364// Minidump defaults to stacks only.65SaveCoreStyle core_style = options.GetStyle();66if (core_style == SaveCoreStyle::eSaveCoreUnspecified)67core_style = SaveCoreStyle::eSaveCoreStackOnly;6869llvm::Expected<lldb::FileUP> maybe_core_file = FileSystem::Instance().Open(70options.GetOutputFile().value(),71File::eOpenOptionWriteOnly | File::eOpenOptionCanCreate);72if (!maybe_core_file) {73error = maybe_core_file.takeError();74return false;75}76MinidumpFileBuilder builder(std::move(maybe_core_file.get()), process_sp);7778Log *log = GetLog(LLDBLog::Object);79error = builder.AddHeaderAndCalculateDirectories();80if (error.Fail()) {81LLDB_LOGF(log, "AddHeaderAndCalculateDirectories failed: %s",82error.AsCString());83return false;84};85error = builder.AddSystemInfo();86if (error.Fail()) {87LLDB_LOGF(log, "AddSystemInfo failed: %s", error.AsCString());88return false;89}9091error = builder.AddModuleList();92if (error.Fail()) {93LLDB_LOGF(log, "AddModuleList failed: %s", error.AsCString());94return false;95}96error = builder.AddMiscInfo();97if (error.Fail()) {98LLDB_LOGF(log, "AddMiscInfo failed: %s", error.AsCString());99return false;100}101102error = builder.AddThreadList();103if (error.Fail()) {104LLDB_LOGF(log, "AddThreadList failed: %s", error.AsCString());105return false;106}107108error = builder.AddLinuxFileStreams();109if (error.Fail()) {110LLDB_LOGF(log, "AddLinuxFileStreams failed: %s", error.AsCString());111return false;112}113114// Add any exceptions but only if there are any in any threads.115error = builder.AddExceptions();116if (error.Fail()) {117LLDB_LOGF(log, "AddExceptions failed: %s", error.AsCString());118return false;119}120121// Note: add memory HAS to be the last thing we do. It can overflow into 64b122// land and many RVA's only support 32b123error = builder.AddMemoryList(core_style);124if (error.Fail()) {125LLDB_LOGF(log, "AddMemoryList failed: %s", error.AsCString());126return false;127}128129error = builder.DumpFile();130if (error.Fail()) {131LLDB_LOGF(log, "DumpFile failed: %s", error.AsCString());132return false;133}134135return true;136}137138139