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
61 // Output file and process_sp are both checked in PluginManager::SaveCore.
62 assert(options.GetOutputFile().has_value());
63 assert(process_sp);
64
65 // Minidump defaults to stacks only.
66 if (options.GetStyle() == SaveCoreStyle::eSaveCoreUnspecified)
67 options.SetStyle(SaveCoreStyle::eSaveCoreStackOnly);
68
69 llvm::Expected<lldb::FileUP> maybe_core_file = FileSystem::Instance().Open(
70 options.GetOutputFile().value(),
72 if (!maybe_core_file) {
73 error = maybe_core_file.takeError();
74 return false;
75 }
76 MinidumpFileBuilder builder(std::move(maybe_core_file.get()), process_sp,
77 options);
78
79 Log *log = GetLog(LLDBLog::Object);
81 if (error.Fail()) {
82 LLDB_LOGF(log, "AddHeaderAndCalculateDirectories failed: %s",
83 error.AsCString());
84 return false;
85 };
86 error = builder.AddSystemInfo();
87 if (error.Fail()) {
88 LLDB_LOGF(log, "AddSystemInfo failed: %s", error.AsCString());
89 return false;
90 }
91
92 error = builder.AddModuleList();
93 if (error.Fail()) {
94 LLDB_LOGF(log, "AddModuleList failed: %s", error.AsCString());
95 return false;
96 }
97 error = builder.AddMiscInfo();
98 if (error.Fail()) {
99 LLDB_LOGF(log, "AddMiscInfo failed: %s", error.AsCString());
100 return false;
101 }
102
103 error = builder.AddThreadList();
104 if (error.Fail()) {
105 LLDB_LOGF(log, "AddThreadList failed: %s", error.AsCString());
106 return false;
107 }
108
109 error = builder.AddLinuxFileStreams();
110 if (error.Fail()) {
111 LLDB_LOGF(log, "AddLinuxFileStreams failed: %s", error.AsCString());
112 return false;
113 }
114
115 // Add any exceptions but only if there are any in any threads.
116 error = builder.AddExceptions();
117 if (error.Fail()) {
118 LLDB_LOGF(log, "AddExceptions failed: %s", error.AsCString());
119 return false;
120 }
121
122 // Note: add memory HAS to be the last thing we do. It can overflow into 64b
123 // land and many RVA's only support 32b
124 error = builder.AddMemoryList();
125 if (error.Fail()) {
126 LLDB_LOGF(log, "AddMemoryList failed: %s", error.AsCString());
127 return false;
128 }
129
130 error = builder.DumpFile();
131 if (error.Fail()) {
132 LLDB_LOGF(log, "DumpFile failed: %s", error.AsCString());
133 return false;
134 }
135
136 return true;
137}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOGF(log,...)
Definition: Log.h:366
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:44
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:331
Definition: SBAddress.h:15
uint64_t offset_t
Definition: lldb-types.h:85
std::shared_ptr< lldb_private::Process > ProcessSP
Definition: lldb-forward.h:387
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
Definition: lldb-forward.h:334
std::shared_ptr< lldb_private::WritableDataBuffer > WritableDataBufferSP
Definition: lldb-forward.h:335
uint64_t addr_t
Definition: lldb-types.h:80
std::shared_ptr< lldb_private::Module > ModuleSP
Definition: lldb-forward.h:371