LLDB mainline
ObjectFileMinidump.cpp
Go to the documentation of this file.
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//===----------------------------------------------------------------------===//
8
10
11#include "MinidumpFileBuilder.h"
12
15#include "lldb/Core/Section.h"
16#include "lldb/Target/Process.h"
18#include "lldb/Utility/Log.h"
19
20#include "llvm/Support/FileSystem.h"
21
22using namespace lldb;
23using namespace lldb_private;
24
26
27void ObjectFileMinidump::Initialize() {
29 GetPluginNameStatic(), GetPluginDescriptionStatic(), CreateInstance,
30 CreateMemoryInstance, GetModuleSpecifications, SaveCore);
31}
32
35}
36
38 const lldb::ModuleSP &module_sp, lldb::DataBufferSP data_sp,
39 lldb::offset_t data_offset, const lldb_private::FileSpec *file,
40 lldb::offset_t offset, lldb::offset_t length) {
41 return nullptr;
42}
43
45 const lldb::ModuleSP &module_sp, WritableDataBufferSP data_sp,
46 const ProcessSP &process_sp, lldb::addr_t header_addr) {
47 return nullptr;
48}
49
51 const lldb_private::FileSpec &file, lldb::DataBufferSP &data_sp,
52 lldb::offset_t data_offset, lldb::offset_t file_offset,
54 specs.Clear();
55 return 0;
56}
57
60
62 if (!m_success)
64 }
65
66 void SetSuccess() { m_success = true; }
67
68private:
70 bool m_success = false;
71};
72
76 // Output file and process_sp are both checked in PluginManager::SaveCore.
77 assert(options.GetOutputFile().has_value());
78 assert(process_sp);
79
80 // Minidump defaults to stacks only.
81 if (options.GetStyle() == SaveCoreStyle::eSaveCoreUnspecified)
82 options.SetStyle(SaveCoreStyle::eSaveCoreStackOnly);
83
84 llvm::Expected<lldb::FileUP> maybe_core_file = FileSystem::Instance().Open(
85 options.GetOutputFile().value(),
87 if (!maybe_core_file) {
88 error = Status::FromError(maybe_core_file.takeError());
89 return false;
90 }
91 MinidumpFileBuilder builder(std::move(maybe_core_file.get()), process_sp,
92 options);
93 DumpFailRemoveHolder request(builder);
94
95 Log *log = GetLog(LLDBLog::Object);
97 if (error.Fail()) {
98 LLDB_LOGF(log, "AddHeaderAndCalculateDirectories failed: %s",
99 error.AsCString());
100 return false;
101 };
102 error = builder.AddSystemInfo();
103 if (error.Fail()) {
104 LLDB_LOGF(log, "AddSystemInfo failed: %s", error.AsCString());
105 return false;
106 }
107
108 error = builder.AddModuleList();
109 if (error.Fail()) {
110 LLDB_LOGF(log, "AddModuleList failed: %s", error.AsCString());
111 return false;
112 }
113 error = builder.AddMiscInfo();
114 if (error.Fail()) {
115 LLDB_LOGF(log, "AddMiscInfo failed: %s", error.AsCString());
116 return false;
117 }
118
119 error = builder.AddThreadList();
120 if (error.Fail()) {
121 LLDB_LOGF(log, "AddThreadList failed: %s", error.AsCString());
122 return false;
123 }
124
125 error = builder.AddLinuxFileStreams();
126 if (error.Fail()) {
127 LLDB_LOGF(log, "AddLinuxFileStreams failed: %s", error.AsCString());
128 return false;
129 }
130
131 // Add any exceptions but only if there are any in any threads.
132 error = builder.AddExceptions();
133 if (error.Fail()) {
134 LLDB_LOGF(log, "AddExceptions failed: %s", error.AsCString());
135 return false;
136 }
137
138 // Note: add memory HAS to be the last thing we do. It can overflow into 64b
139 // land and many RVA's only support 32b
140 error = builder.AddMemoryList();
141 if (error.Fail()) {
142 LLDB_LOGF(log, "AddMemoryList failed: %s", error.AsCString());
143 return false;
144 }
145
146 error = builder.DumpFile();
147 if (error.Fail()) {
148 LLDB_LOGF(log, "DumpFile failed: %s", error.AsCString());
149 return false;
150 }
151
152 request.SetSuccess();
153
154 return true;
155}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOGF(log,...)
Definition: Log.h:376
Structure holding data neccessary for minidump file creation.
Placeholder plugin for the save core functionality.
#define LLDB_PLUGIN_DEFINE(PluginName)
Definition: PluginManager.h:32
Minidump writer for Linux.
lldb_private::Status AddExceptions()
lldb_private::Status AddThreadList()
lldb_private::Status AddHeaderAndCalculateDirectories()
lldb_private::Status AddSystemInfo()
lldb_private::Status AddMemoryList()
lldb_private::Status DumpFile()
lldb_private::Status AddLinuxFileStreams()
lldb_private::Status AddModuleList()
lldb_private::Status AddMiscInfo()
static lldb_private::ObjectFile * CreateInstance(const lldb::ModuleSP &module_sp, lldb::DataBufferSP data_sp, lldb::offset_t data_offset, const lldb_private::FileSpec *file, lldb::offset_t offset, lldb::offset_t length)
static size_t GetModuleSpecifications(const lldb_private::FileSpec &file, lldb::DataBufferSP &data_sp, lldb::offset_t data_offset, lldb::offset_t file_offset, lldb::offset_t length, lldb_private::ModuleSpecList &specs)
static lldb_private::ObjectFile * CreateMemoryInstance(const lldb::ModuleSP &module_sp, lldb::WritableDataBufferSP data_sp, const lldb::ProcessSP &process_sp, lldb::addr_t header_addr)
static bool SaveCore(const lldb::ProcessSP &process_sp, lldb_private::SaveCoreOptions &options, lldb_private::Status &error)
A file utility class.
Definition: FileSpec.h:56
int Open(const char *path, int flags, int mode=0600)
Wraps ::open in a platform-independent way.
static FileSystem & Instance()
@ eOpenOptionWriteOnly
Definition: File.h:52
@ eOpenOptionCanCreate
Definition: File.h:56
A plug-in interface definition class for object file parsers.
Definition: ObjectFile.h:44
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
const std::optional< lldb_private::FileSpec > GetOutputFile() const
lldb::SaveCoreStyle GetStyle() const
void SetStyle(lldb::SaveCoreStyle style)
An error handling class.
Definition: Status.h:115
static Status FromError(llvm::Error error)
Avoid using this in new code. Migrate APIs to llvm::Expected instead.
Definition: Status.cpp:137
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition: Log.h:332
Definition: SBAddress.h:15
uint64_t offset_t
Definition: lldb-types.h:85
std::shared_ptr< lldb_private::Process > ProcessSP
Definition: lldb-forward.h:389
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
Definition: lldb-forward.h:336
std::shared_ptr< lldb_private::WritableDataBuffer > WritableDataBufferSP
Definition: lldb-forward.h:337
uint64_t addr_t
Definition: lldb-types.h:80
std::shared_ptr< lldb_private::Module > ModuleSP
Definition: lldb-forward.h:373
DumpFailRemoveHolder(MinidumpFileBuilder &builder)
MinidumpFileBuilder & m_builder