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
9#include "lldb/API/SBSaveCoreOptions.h"
10#include "lldb/API/SBMemoryRegionInfo.h"
11#include "lldb/Host/FileSystem.h"
12#include "lldb/Symbol/SaveCoreOptions.h"
13#include "lldb/Target/ThreadCollection.h"
14#include "lldb/Utility/Instrumentation.h"
15
16#include "Utils.h"
17
18using namespace lldb;
19
20SBSaveCoreOptions::SBSaveCoreOptions() {
21 LLDB_INSTRUMENT_VA(this)
22
23 m_opaque_up = std::make_unique<lldb_private::SaveCoreOptions>();
24}
25
26SBSaveCoreOptions::SBSaveCoreOptions(const SBSaveCoreOptions &rhs) {
27 LLDB_INSTRUMENT_VA(this, rhs);
28
29 m_opaque_up = clone(src: rhs.m_opaque_up);
30}
31
32SBSaveCoreOptions::~SBSaveCoreOptions() = default;
33
34const SBSaveCoreOptions &
35SBSaveCoreOptions::operator=(const SBSaveCoreOptions &rhs) {
36 LLDB_INSTRUMENT_VA(this, rhs);
37
38 if (this != &rhs)
39 m_opaque_up = clone(src: rhs.m_opaque_up);
40 return *this;
41}
42
43SBError SBSaveCoreOptions::SetPluginName(const char *name) {
44 LLDB_INSTRUMENT_VA(this, name);
45 return SBError(m_opaque_up->SetPluginName(name));
46}
47
48void SBSaveCoreOptions::SetStyle(lldb::SaveCoreStyle style) {
49 LLDB_INSTRUMENT_VA(this, style);
50 m_opaque_up->SetStyle(style);
51}
52
53void SBSaveCoreOptions::SetOutputFile(lldb::SBFileSpec file_spec) {
54 LLDB_INSTRUMENT_VA(this, file_spec);
55 m_opaque_up->SetOutputFile(file_spec.ref());
56}
57
58const char *SBSaveCoreOptions::GetPluginName() const {
59 LLDB_INSTRUMENT_VA(this);
60 const auto name = m_opaque_up->GetPluginName();
61 if (!name)
62 return nullptr;
63 return lldb_private::ConstString(name.value()).GetCString();
64}
65
66SBFileSpec SBSaveCoreOptions::GetOutputFile() const {
67 LLDB_INSTRUMENT_VA(this);
68 const auto file_spec = m_opaque_up->GetOutputFile();
69 if (file_spec)
70 return SBFileSpec(file_spec.value());
71 return SBFileSpec();
72}
73
74lldb::SaveCoreStyle SBSaveCoreOptions::GetStyle() const {
75 LLDB_INSTRUMENT_VA(this);
76 return m_opaque_up->GetStyle();
77}
78
79SBError SBSaveCoreOptions::SetProcess(lldb::SBProcess process) {
80 LLDB_INSTRUMENT_VA(this, process);
81 return m_opaque_up->SetProcess(process.GetSP());
82}
83
84SBError SBSaveCoreOptions::AddThread(lldb::SBThread thread) {
85 LLDB_INSTRUMENT_VA(this, thread);
86 return m_opaque_up->AddThread(thread_sp: thread.GetSP());
87}
88
89bool SBSaveCoreOptions::RemoveThread(lldb::SBThread thread) {
90 LLDB_INSTRUMENT_VA(this, thread);
91 return m_opaque_up->RemoveThread(thread_sp: thread.GetSP());
92}
93
94lldb::SBError
95SBSaveCoreOptions::AddMemoryRegionToSave(const SBMemoryRegionInfo &region) {
96 LLDB_INSTRUMENT_VA(this, region);
97 // Currently add memory region can't fail, so we always return a success
98 // SBerror, but because these API's live forever, this is the most future
99 // proof thing to do.
100 m_opaque_up->AddMemoryRegionToSave(region: region.ref());
101 return SBError();
102}
103
104lldb::SBThreadCollection SBSaveCoreOptions::GetThreadsToSave() const {
105 LLDB_INSTRUMENT_VA(this);
106 lldb::ThreadCollectionSP threadcollection_sp =
107 std::make_shared<lldb_private::ThreadCollection>(
108 args: m_opaque_up->GetThreadsToSave());
109 return SBThreadCollection(threadcollection_sp);
110}
111
112void SBSaveCoreOptions::Clear() {
113 LLDB_INSTRUMENT_VA(this);
114 m_opaque_up->Clear();
115}
116
117uint64_t SBSaveCoreOptions::GetCurrentSizeInBytes(SBError &error) {
118 LLDB_INSTRUMENT_VA(this, error);
119 llvm::Expected<uint64_t> expected_bytes =
120 m_opaque_up->GetCurrentSizeInBytes();
121 if (!expected_bytes) {
122 error =
123 SBError(lldb_private::Status::FromError(error: expected_bytes.takeError()));
124 return 0;
125 }
126 // Clear the error, so if the clearer uses it we set it to success.
127 error.Clear();
128 return *expected_bytes;
129}
130
131lldb_private::SaveCoreOptions &SBSaveCoreOptions::ref() const {
132 return *m_opaque_up;
133}
134

source code of lldb/source/API/SBSaveCoreOptions.cpp