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
19#include "llvm/Support/FileSystem.h"
20
21using namespace lldb;
22using namespace lldb_private;
23
25
26void ObjectFileMinidump::Initialize() {
28 GetPluginNameStatic(), GetPluginDescriptionStatic(), CreateInstance,
29 CreateMemoryInstance, GetModuleSpecifications, SaveCore);
30}
31
34}
35
37 const lldb::ModuleSP &module_sp, lldb::DataBufferSP data_sp,
38 lldb::offset_t data_offset, const lldb_private::FileSpec *file,
39 lldb::offset_t offset, lldb::offset_t length) {
40 return nullptr;
41}
42
44 const lldb::ModuleSP &module_sp, WritableDataBufferSP data_sp,
45 const ProcessSP &process_sp, lldb::addr_t header_addr) {
46 return nullptr;
47}
48
50 const lldb_private::FileSpec &file, lldb::DataBufferSP &data_sp,
51 lldb::offset_t data_offset, lldb::offset_t file_offset,
53 specs.Clear();
54 return 0;
55}
56
58 const lldb_private::FileSpec &outfile,
59 lldb::SaveCoreStyle &core_style,
61 // Set default core style if it isn't set.
62 if (core_style == SaveCoreStyle::eSaveCoreUnspecified)
63 core_style = SaveCoreStyle::eSaveCoreStackOnly;
64
65 if (!process_sp)
66 return false;
67
68 MinidumpFileBuilder builder;
69
70 Target &target = process_sp->GetTarget();
71
72 Log *log = GetLog(LLDBLog::Object);
73 error = builder.AddSystemInfo(target.GetArchitecture().GetTriple());
74 if (error.Fail()) {
75 LLDB_LOG(log, "AddSystemInfo failed: %s", error.AsCString());
76 return false;
77 }
78
79 error = builder.AddModuleList(target);
80 if (error.Fail()) {
81 LLDB_LOG(log, "AddModuleList failed: %s", error.AsCString());
82 return false;
83 }
84
85 builder.AddMiscInfo(process_sp);
86
87 error = builder.AddThreadList(process_sp);
88 if (error.Fail()) {
89 LLDB_LOG(log, "AddThreadList failed: %s", error.AsCString());
90 return false;
91 }
92
93 // Add any exceptions but only if there are any in any threads.
94 builder.AddExceptions(process_sp);
95
96 error = builder.AddMemoryList(process_sp, core_style);
97 if (error.Fail()) {
98 LLDB_LOG(log, "AddMemoryList failed: %s", error.AsCString());
99 return false;
100 }
101
102 if (target.GetArchitecture().GetTriple().getOS() ==
103 llvm::Triple::OSType::Linux) {
104 builder.AddLinuxFileStreams(process_sp);
105 }
106
107 llvm::Expected<lldb::FileUP> maybe_core_file = FileSystem::Instance().Open(
109 if (!maybe_core_file) {
110 error = maybe_core_file.takeError();
111 return false;
112 }
113 lldb::FileUP core_file = std::move(maybe_core_file.get());
114
115 error = builder.Dump(core_file);
116 if (error.Fail())
117 return false;
118
119 return true;
120}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition: Log.h:359
Structure holding data neccessary for minidump file creation.
Placeholder plugin for the save core functionality.
#define LLDB_PLUGIN_DEFINE(PluginName)
Definition: PluginManager.h:31
Minidump writer for Linux.
lldb_private::Status Dump(lldb::FileUP &core_file) const
lldb_private::Status AddModuleList(lldb_private::Target &target)
void AddExceptions(const lldb::ProcessSP &process_sp)
void AddLinuxFileStreams(const lldb::ProcessSP &process_sp)
void AddMiscInfo(const lldb::ProcessSP &process_sp)
lldb_private::Status AddSystemInfo(const llvm::Triple &target_triple)
lldb_private::Status AddMemoryList(const lldb::ProcessSP &process_sp, lldb::SaveCoreStyle core_style)
lldb_private::Status AddThreadList(const lldb::ProcessSP &process_sp)
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 bool SaveCore(const lldb::ProcessSP &process_sp, const lldb_private::FileSpec &outfile, lldb::SaveCoreStyle &core_style, lldb_private::Status &error)
static lldb_private::ObjectFile * CreateMemoryInstance(const lldb::ModuleSP &module_sp, lldb::WritableDataBufferSP data_sp, const lldb::ProcessSP &process_sp, lldb::addr_t header_addr)
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition: ArchSpec.h:450
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)
An error handling class.
Definition: Status.h:44
const ArchSpec & GetArchitecture() const
Definition: Target.h:1023
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
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
std::unique_ptr< lldb_private::File > FileUP
Definition: lldb-forward.h:344
uint64_t offset_t
Definition: lldb-types.h:85
std::shared_ptr< lldb_private::Process > ProcessSP
Definition: lldb-forward.h:381
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
Definition: lldb-forward.h:328
std::shared_ptr< lldb_private::WritableDataBuffer > WritableDataBufferSP
Definition: lldb-forward.h:329
uint64_t addr_t
Definition: lldb-types.h:80
std::shared_ptr< lldb_private::Module > ModuleSP
Definition: lldb-forward.h:365