xref: /llvm-project/lldb/source/API/SBSaveCoreOptions.cpp (revision 06edefac10f4481bdd458c0362d9a305f6a1ce6a)
14120570dSJacob Lalonde //===-- SBSaveCoreOptions.cpp -----------------------------------*- C++ -*-===//
24120570dSJacob Lalonde //
34120570dSJacob Lalonde // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44120570dSJacob Lalonde // See https://llvm.org/LICENSE.txt for license information.
54120570dSJacob Lalonde // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
64120570dSJacob Lalonde //
74120570dSJacob Lalonde //===----------------------------------------------------------------------===//
84120570dSJacob Lalonde 
94120570dSJacob Lalonde #include "lldb/API/SBSaveCoreOptions.h"
1096b7c64bSJacob Lalonde #include "lldb/API/SBMemoryRegionInfo.h"
114120570dSJacob Lalonde #include "lldb/Host/FileSystem.h"
124120570dSJacob Lalonde #include "lldb/Symbol/SaveCoreOptions.h"
13*06edefacSJacob Lalonde #include "lldb/Target/ThreadCollection.h"
144120570dSJacob Lalonde #include "lldb/Utility/Instrumentation.h"
154120570dSJacob Lalonde 
164120570dSJacob Lalonde #include "Utils.h"
174120570dSJacob Lalonde 
184120570dSJacob Lalonde using namespace lldb;
194120570dSJacob Lalonde 
204120570dSJacob Lalonde SBSaveCoreOptions::SBSaveCoreOptions() {
214120570dSJacob Lalonde   LLDB_INSTRUMENT_VA(this)
224120570dSJacob Lalonde 
234120570dSJacob Lalonde   m_opaque_up = std::make_unique<lldb_private::SaveCoreOptions>();
244120570dSJacob Lalonde }
254120570dSJacob Lalonde 
264120570dSJacob Lalonde SBSaveCoreOptions::SBSaveCoreOptions(const SBSaveCoreOptions &rhs) {
274120570dSJacob Lalonde   LLDB_INSTRUMENT_VA(this, rhs);
284120570dSJacob Lalonde 
294120570dSJacob Lalonde   m_opaque_up = clone(rhs.m_opaque_up);
304120570dSJacob Lalonde }
314120570dSJacob Lalonde 
32101cf540SAlex Langford SBSaveCoreOptions::~SBSaveCoreOptions() = default;
33101cf540SAlex Langford 
344120570dSJacob Lalonde const SBSaveCoreOptions &
354120570dSJacob Lalonde SBSaveCoreOptions::operator=(const SBSaveCoreOptions &rhs) {
364120570dSJacob Lalonde   LLDB_INSTRUMENT_VA(this, rhs);
374120570dSJacob Lalonde 
384120570dSJacob Lalonde   if (this != &rhs)
394120570dSJacob Lalonde     m_opaque_up = clone(rhs.m_opaque_up);
404120570dSJacob Lalonde   return *this;
414120570dSJacob Lalonde }
424120570dSJacob Lalonde 
434120570dSJacob Lalonde SBError SBSaveCoreOptions::SetPluginName(const char *name) {
444120570dSJacob Lalonde   LLDB_INSTRUMENT_VA(this, name);
45b798f4bdSAdrian Prantl   return SBError(m_opaque_up->SetPluginName(name));
464120570dSJacob Lalonde }
474120570dSJacob Lalonde 
484120570dSJacob Lalonde void SBSaveCoreOptions::SetStyle(lldb::SaveCoreStyle style) {
494120570dSJacob Lalonde   LLDB_INSTRUMENT_VA(this, style);
504120570dSJacob Lalonde   m_opaque_up->SetStyle(style);
514120570dSJacob Lalonde }
524120570dSJacob Lalonde 
534120570dSJacob Lalonde void SBSaveCoreOptions::SetOutputFile(lldb::SBFileSpec file_spec) {
544120570dSJacob Lalonde   LLDB_INSTRUMENT_VA(this, file_spec);
554120570dSJacob Lalonde   m_opaque_up->SetOutputFile(file_spec.ref());
564120570dSJacob Lalonde }
574120570dSJacob Lalonde 
584120570dSJacob Lalonde const char *SBSaveCoreOptions::GetPluginName() const {
594120570dSJacob Lalonde   LLDB_INSTRUMENT_VA(this);
604120570dSJacob Lalonde   const auto name = m_opaque_up->GetPluginName();
614120570dSJacob Lalonde   if (!name)
624120570dSJacob Lalonde     return nullptr;
634120570dSJacob Lalonde   return lldb_private::ConstString(name.value()).GetCString();
644120570dSJacob Lalonde }
654120570dSJacob Lalonde 
664120570dSJacob Lalonde SBFileSpec SBSaveCoreOptions::GetOutputFile() const {
674120570dSJacob Lalonde   LLDB_INSTRUMENT_VA(this);
684120570dSJacob Lalonde   const auto file_spec = m_opaque_up->GetOutputFile();
694120570dSJacob Lalonde   if (file_spec)
704120570dSJacob Lalonde     return SBFileSpec(file_spec.value());
714120570dSJacob Lalonde   return SBFileSpec();
724120570dSJacob Lalonde }
734120570dSJacob Lalonde 
744120570dSJacob Lalonde lldb::SaveCoreStyle SBSaveCoreOptions::GetStyle() const {
754120570dSJacob Lalonde   LLDB_INSTRUMENT_VA(this);
764120570dSJacob Lalonde   return m_opaque_up->GetStyle();
774120570dSJacob Lalonde }
784120570dSJacob Lalonde 
79572943e7SJacob Lalonde SBError SBSaveCoreOptions::SetProcess(lldb::SBProcess process) {
80572943e7SJacob Lalonde   LLDB_INSTRUMENT_VA(this, process);
81572943e7SJacob Lalonde   return m_opaque_up->SetProcess(process.GetSP());
82572943e7SJacob Lalonde }
83572943e7SJacob Lalonde 
84572943e7SJacob Lalonde SBError SBSaveCoreOptions::AddThread(lldb::SBThread thread) {
85572943e7SJacob Lalonde   LLDB_INSTRUMENT_VA(this, thread);
86572943e7SJacob Lalonde   return m_opaque_up->AddThread(thread.GetSP());
87572943e7SJacob Lalonde }
88572943e7SJacob Lalonde 
89572943e7SJacob Lalonde bool SBSaveCoreOptions::RemoveThread(lldb::SBThread thread) {
90572943e7SJacob Lalonde   LLDB_INSTRUMENT_VA(this, thread);
91572943e7SJacob Lalonde   return m_opaque_up->RemoveThread(thread.GetSP());
92572943e7SJacob Lalonde }
93572943e7SJacob Lalonde 
9496b7c64bSJacob Lalonde lldb::SBError
9596b7c64bSJacob Lalonde SBSaveCoreOptions::AddMemoryRegionToSave(const SBMemoryRegionInfo &region) {
9696b7c64bSJacob Lalonde   LLDB_INSTRUMENT_VA(this, region);
9796b7c64bSJacob Lalonde   // Currently add memory region can't fail, so we always return a success
9896b7c64bSJacob Lalonde   // SBerror, but because these API's live forever, this is the most future
9996b7c64bSJacob Lalonde   // proof thing to do.
10096b7c64bSJacob Lalonde   m_opaque_up->AddMemoryRegionToSave(region.ref());
10196b7c64bSJacob Lalonde   return SBError();
10296b7c64bSJacob Lalonde }
10396b7c64bSJacob Lalonde 
104*06edefacSJacob Lalonde lldb::SBThreadCollection SBSaveCoreOptions::GetThreadsToSave() const {
105*06edefacSJacob Lalonde   LLDB_INSTRUMENT_VA(this);
106*06edefacSJacob Lalonde   lldb::ThreadCollectionSP threadcollection_sp =
107*06edefacSJacob Lalonde       std::make_shared<lldb_private::ThreadCollection>(
108*06edefacSJacob Lalonde           m_opaque_up->GetThreadsToSave());
109*06edefacSJacob Lalonde   return SBThreadCollection(threadcollection_sp);
110*06edefacSJacob Lalonde }
111*06edefacSJacob Lalonde 
1124120570dSJacob Lalonde void SBSaveCoreOptions::Clear() {
1134120570dSJacob Lalonde   LLDB_INSTRUMENT_VA(this);
1144120570dSJacob Lalonde   m_opaque_up->Clear();
1154120570dSJacob Lalonde }
1164120570dSJacob Lalonde 
1174120570dSJacob Lalonde lldb_private::SaveCoreOptions &SBSaveCoreOptions::ref() const {
1184120570dSJacob Lalonde   return *m_opaque_up.get();
1194120570dSJacob Lalonde }
120