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"
17
18#include "llvm/Support/FileSystem.h"
19
20using namespace lldb;
21using namespace lldb_private;
22
24
25void ObjectFileMinidump::Initialize() {
27 GetPluginNameStatic(), GetPluginDescriptionStatic(), CreateInstance,
28 CreateMemoryInstance, GetModuleSpecifications, SaveCore);
29}
30
33}
34
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;
40}
41
43 const lldb::ModuleSP &module_sp, WritableDataBufferSP data_sp,
44 const ProcessSP &process_sp, lldb::addr_t header_addr) {
45 return nullptr;
46}
47
49 const lldb_private::FileSpec &file, lldb::DataBufferSP &data_sp,
50 lldb::offset_t data_offset, lldb::offset_t file_offset,
52 specs.Clear();
53 return 0;
54}
55
57 const lldb_private::FileSpec &outfile,
58 lldb::SaveCoreStyle &core_style,
60 // Set default core style if it isn't set.
61 if (core_style == SaveCoreStyle::eSaveCoreUnspecified)
62 core_style = SaveCoreStyle::eSaveCoreStackOnly;
63
64 if (!process_sp)
65 return false;
66
67 MinidumpFileBuilder builder;
68
69 Target &target = process_sp->GetTarget();
70
71 error = builder.AddSystemInfo(target.GetArchitecture().GetTriple());
72 if (error.Fail())
73 return false;
74
75 error = builder.AddModuleList(target);
76 if (error.Fail())
77 return false;
78
79 builder.AddMiscInfo(process_sp);
80
81 error = builder.AddThreadList(process_sp);
82 if (error.Fail())
83 return false;
84
85 // Add any exceptions but only if there are any in any threads.
86 builder.AddExceptions(process_sp);
87
88 error = builder.AddMemoryList(process_sp, core_style);
89 if (error.Fail())
90 return false;
91
92 if (target.GetArchitecture().GetTriple().getOS() ==
93 llvm::Triple::OSType::Linux) {
94 builder.AddLinuxFileStreams(process_sp);
95 }
96
97 llvm::Expected<lldb::FileUP> maybe_core_file = FileSystem::Instance().Open(
99 if (!maybe_core_file) {
100 error = maybe_core_file.takeError();
101 return false;
102 }
103 lldb::FileUP core_file = std::move(maybe_core_file.get());
104
105 error = builder.Dump(core_file);
106 if (error.Fail())
107 return false;
108
109 return true;
110}
static llvm::raw_ostream & error(Stream &strm)
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:57
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:1012
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
Definition: SBAddress.h:15
std::unique_ptr< lldb_private::File > FileUP
Definition: lldb-forward.h:340
uint64_t offset_t
Definition: lldb-types.h:83
std::shared_ptr< lldb_private::Process > ProcessSP
Definition: lldb-forward.h:377
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
Definition: lldb-forward.h:324
std::shared_ptr< lldb_private::WritableDataBuffer > WritableDataBufferSP
Definition: lldb-forward.h:325
uint64_t addr_t
Definition: lldb-types.h:79
std::shared_ptr< lldb_private::Module > ModuleSP
Definition: lldb-forward.h:361