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 18 using namespace lldb; 19 20 SBSaveCoreOptions::SBSaveCoreOptions() { 21 LLDB_INSTRUMENT_VA(this) 22 23 m_opaque_up = std::make_unique<lldb_private::SaveCoreOptions>(); 24 } 25 26 SBSaveCoreOptions::SBSaveCoreOptions(const SBSaveCoreOptions &rhs) { 27 LLDB_INSTRUMENT_VA(this, rhs); 28 29 m_opaque_up = clone(rhs.m_opaque_up); 30 } 31 32 SBSaveCoreOptions::~SBSaveCoreOptions() = default; 33 34 const SBSaveCoreOptions & 35 SBSaveCoreOptions::operator=(const SBSaveCoreOptions &rhs) { 36 LLDB_INSTRUMENT_VA(this, rhs); 37 38 if (this != &rhs) 39 m_opaque_up = clone(rhs.m_opaque_up); 40 return *this; 41 } 42 43 SBError SBSaveCoreOptions::SetPluginName(const char *name) { 44 LLDB_INSTRUMENT_VA(this, name); 45 return SBError(m_opaque_up->SetPluginName(name)); 46 } 47 48 void SBSaveCoreOptions::SetStyle(lldb::SaveCoreStyle style) { 49 LLDB_INSTRUMENT_VA(this, style); 50 m_opaque_up->SetStyle(style); 51 } 52 53 void SBSaveCoreOptions::SetOutputFile(lldb::SBFileSpec file_spec) { 54 LLDB_INSTRUMENT_VA(this, file_spec); 55 m_opaque_up->SetOutputFile(file_spec.ref()); 56 } 57 58 const 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 66 SBFileSpec 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 74 lldb::SaveCoreStyle SBSaveCoreOptions::GetStyle() const { 75 LLDB_INSTRUMENT_VA(this); 76 return m_opaque_up->GetStyle(); 77 } 78 79 SBError SBSaveCoreOptions::SetProcess(lldb::SBProcess process) { 80 LLDB_INSTRUMENT_VA(this, process); 81 return m_opaque_up->SetProcess(process.GetSP()); 82 } 83 84 SBError SBSaveCoreOptions::AddThread(lldb::SBThread thread) { 85 LLDB_INSTRUMENT_VA(this, thread); 86 return m_opaque_up->AddThread(thread.GetSP()); 87 } 88 89 bool SBSaveCoreOptions::RemoveThread(lldb::SBThread thread) { 90 LLDB_INSTRUMENT_VA(this, thread); 91 return m_opaque_up->RemoveThread(thread.GetSP()); 92 } 93 94 lldb::SBError 95 SBSaveCoreOptions::AddMemoryRegionToSave(const SBMemoryRegionInfo ®ion) { 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.ref()); 101 return SBError(); 102 } 103 104 lldb::SBThreadCollection SBSaveCoreOptions::GetThreadsToSave() const { 105 LLDB_INSTRUMENT_VA(this); 106 lldb::ThreadCollectionSP threadcollection_sp = 107 std::make_shared<lldb_private::ThreadCollection>( 108 m_opaque_up->GetThreadsToSave()); 109 return SBThreadCollection(threadcollection_sp); 110 } 111 112 void SBSaveCoreOptions::Clear() { 113 LLDB_INSTRUMENT_VA(this); 114 m_opaque_up->Clear(); 115 } 116 117 lldb_private::SaveCoreOptions &SBSaveCoreOptions::ref() const { 118 return *m_opaque_up.get(); 119 } 120