Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / source / Plugins / ObjectFile / Minidump / ObjectFileMinidump.cpp
blob17b37afe557d91481c6a1932c97ef36ef4a96671
1 //===-- ObjectFileMinidump.cpp --------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "ObjectFileMinidump.h"
11 #include "MinidumpFileBuilder.h"
13 #include "lldb/Core/ModuleSpec.h"
14 #include "lldb/Core/PluginManager.h"
15 #include "lldb/Core/Section.h"
16 #include "lldb/Target/Process.h"
18 #include "llvm/Support/FileSystem.h"
20 using namespace lldb;
21 using namespace lldb_private;
23 LLDB_PLUGIN_DEFINE(ObjectFileMinidump)
25 void ObjectFileMinidump::Initialize() {
26 PluginManager::RegisterPlugin(
27 GetPluginNameStatic(), GetPluginDescriptionStatic(), CreateInstance,
28 CreateMemoryInstance, GetModuleSpecifications, SaveCore);
31 void ObjectFileMinidump::Terminate() {
32 PluginManager::UnregisterPlugin(CreateInstance);
35 ObjectFile *ObjectFileMinidump::CreateInstance(
36 const lldb::ModuleSP &module_sp, lldb::DataBufferSP data_sp,
37 lldb::offset_t data_offset, const lldb_private::FileSpec *file,
38 lldb::offset_t offset, lldb::offset_t length) {
39 return nullptr;
42 ObjectFile *ObjectFileMinidump::CreateMemoryInstance(
43 const lldb::ModuleSP &module_sp, WritableDataBufferSP data_sp,
44 const ProcessSP &process_sp, lldb::addr_t header_addr) {
45 return nullptr;
48 size_t ObjectFileMinidump::GetModuleSpecifications(
49 const lldb_private::FileSpec &file, lldb::DataBufferSP &data_sp,
50 lldb::offset_t data_offset, lldb::offset_t file_offset,
51 lldb::offset_t length, lldb_private::ModuleSpecList &specs) {
52 specs.Clear();
53 return 0;
56 bool ObjectFileMinidump::SaveCore(const lldb::ProcessSP &process_sp,
57 const lldb_private::FileSpec &outfile,
58 lldb::SaveCoreStyle &core_style,
59 lldb_private::Status &error) {
60 if (core_style != SaveCoreStyle::eSaveCoreStackOnly) {
61 error.SetErrorString("Only stack minidumps supported yet.");
62 return false;
65 if (!process_sp)
66 return false;
68 MinidumpFileBuilder builder;
70 Target &target = process_sp->GetTarget();
72 error = builder.AddSystemInfo(target.GetArchitecture().GetTriple());
73 if (error.Fail())
74 return false;
76 error = builder.AddModuleList(target);
77 if (error.Fail())
78 return false;
80 builder.AddMiscInfo(process_sp);
82 if (target.GetArchitecture().GetMachine() == llvm::Triple::ArchType::x86_64) {
83 error = builder.AddThreadList(process_sp);
84 if (error.Fail())
85 return false;
87 error = builder.AddException(process_sp);
88 if (error.Fail())
89 return false;
91 error = builder.AddMemoryList(process_sp);
92 if (error.Fail())
93 return false;
96 if (target.GetArchitecture().GetTriple().getOS() ==
97 llvm::Triple::OSType::Linux) {
98 builder.AddLinuxFileStreams(process_sp);
101 llvm::Expected<lldb::FileUP> maybe_core_file = FileSystem::Instance().Open(
102 outfile, File::eOpenOptionWriteOnly | File::eOpenOptionCanCreate);
103 if (!maybe_core_file) {
104 error = maybe_core_file.takeError();
105 return false;
107 lldb::FileUP core_file = std::move(maybe_core_file.get());
109 error = builder.Dump(core_file);
110 if (error.Fail())
111 return false;
113 return true;