LLDB mainline
SBSaveCoreOptions.cpp
Go to the documentation of this file.
1//===-- SBSaveCoreOptions.cpp -----------------------------------*- C++ -*-===//
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
17
18#include "Utils.h"
19
20using namespace lldb;
21
24
25 m_opaque_up = std::make_unique<lldb_private::SaveCoreOptions>();
26}
27
33
35
38 LLDB_INSTRUMENT_VA(this, rhs);
39
40 if (this != &rhs)
41 m_opaque_up = clone(rhs.m_opaque_up);
42 return *this;
43}
44
46 LLDB_INSTRUMENT_VA(this, name);
47 return SBError(m_opaque_up->SetPluginName(name));
48}
49
51 LLDB_INSTRUMENT_VA(this, style);
52 m_opaque_up->SetStyle(style);
53}
54
56 LLDB_INSTRUMENT_VA(this, file_spec);
57 m_opaque_up->SetOutputFile(file_spec.ref());
58}
59
62 const auto name = m_opaque_up->GetPluginName();
63 if (!name)
64 return nullptr;
66}
67
70 const auto file_spec = m_opaque_up->GetOutputFile();
71 if (file_spec)
72 return SBFileSpec(file_spec.value());
73 return SBFileSpec();
74}
75
80
82 LLDB_INSTRUMENT_VA(this, process);
83 return m_opaque_up->SetProcess(process.GetSP());
84}
85
88 return SBProcess(m_opaque_up->GetProcess());
89}
90
92 LLDB_INSTRUMENT_VA(this, thread);
93 return m_opaque_up->AddThread(thread.GetSP());
94}
95
97 LLDB_INSTRUMENT_VA(this, thread);
98 return m_opaque_up->RemoveThread(thread.GetSP());
99}
100
103 LLDB_INSTRUMENT_VA(this, region);
104 // Currently add memory region can't fail, so we always return a success
105 // SBerror, but because these API's live forever, this is the most future
106 // proof thing to do.
107 m_opaque_up->AddMemoryRegionToSave(region.ref());
108 return SBError();
109}
110
112 LLDB_INSTRUMENT_VA(this);
113 lldb::ThreadCollectionSP threadcollection_sp =
114 std::make_shared<lldb_private::ThreadCollection>(
115 m_opaque_up->GetThreadsToSave());
116 return SBThreadCollection(threadcollection_sp);
117}
118
120 LLDB_INSTRUMENT_VA(this);
121 m_opaque_up->Clear();
122}
123
126 llvm::Expected<uint64_t> expected_bytes =
127 m_opaque_up->GetCurrentSizeInBytes();
128 if (!expected_bytes) {
129 error =
130 SBError(lldb_private::Status::FromError(expected_bytes.takeError()));
131 return 0;
132 }
133 // Clear the error, so if the clearer uses it we set it to success.
134 error.Clear();
135 return *expected_bytes;
136}
137
139 LLDB_INSTRUMENT_VA(this);
140 llvm::Expected<lldb_private::CoreFileMemoryRanges> memory_ranges =
141 m_opaque_up->GetMemoryRegionsToSave();
142 if (!memory_ranges) {
143 llvm::consumeError(memory_ranges.takeError());
144 return SBMemoryRegionInfoList();
145 }
146
147 SBMemoryRegionInfoList memory_region_infos;
148 for (const auto &range : *memory_ranges) {
149 SBMemoryRegionInfo region_info(
150 nullptr, range.GetRangeBase(), range.GetRangeEnd(),
151 range.data.lldb_permissions, /*mapped=*/true);
152 memory_region_infos.Append(region_info);
153 }
154
155 return memory_region_infos;
156}
157
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_INSTRUMENT_VA(...)
const lldb_private::FileSpec & ref() const
void Append(lldb::SBMemoryRegionInfo &region)
lldb_private::MemoryRegionInfo & ref()
lldb::ProcessSP GetSP() const
SBThreadCollection GetThreadsToSave() const
Get an unsorted copy of all threads to save.
bool RemoveThread(lldb::SBThread thread)
Remove a thread from the list of threads to save.
void SetStyle(lldb::SaveCoreStyle style)
Set the Core dump style.
const SBSaveCoreOptions & operator=(const lldb::SBSaveCoreOptions &rhs)
void Clear()
Reset all options.
void SetOutputFile(SBFileSpec output_file)
Set the output file path.
lldb_private::SaveCoreOptions & ref() const
uint64_t GetCurrentSizeInBytes(SBError &error)
Get the current total number of bytes the core is expected to have excluding the overhead of the core...
SBError SetProcess(lldb::SBProcess process)
Set the process to save, or unset if supplied with a default constructed process.
SBError AddMemoryRegionToSave(const SBMemoryRegionInfo &region)
Add a memory region to save in the core file.
SBError AddThread(lldb::SBThread thread)
Add a thread to save in the core file.
const char * GetPluginName() const
Get the Core dump plugin name, if set.
lldb::SaveCoreStyle GetStyle() const
Get the Core dump style, if set.
SBError SetPluginName(const char *plugin)
Set the plugin name.
std::unique_ptr< lldb_private::SaveCoreOptions > m_opaque_up
SBMemoryRegionInfoList GetMemoryRegionsToSave() const
Get an unsorted copy of all memory regions to save.
SBProcess GetProcess() const
Get the process to save, if the process is not set an invalid SBProcess will be returned.
SBFileSpec GetOutputFile() const
Get the output file spec.
static Status FromError(llvm::Error error)
Avoid using this in new code. Migrate APIs to llvm::Expected instead.
Definition Status.cpp:136
const char * Intern(llvm::StringRef str) const
Definition StringPool.h:78
static StringPoolRef GetSystemPool()
The system pool. Only valid between Initialize and Terminate.
class LLDB_API SBFileSpec
Definition SBDefines.h:76
class LLDB_API SBMemoryRegionInfoList
Definition SBDefines.h:91
class LLDB_API SBError
Definition SBDefines.h:70
std::shared_ptr< lldb_private::ThreadCollection > ThreadCollectionSP