1 //===-- SBModuleSpec.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 9 #include "lldb/API/SBModuleSpec.h" 10 #include "Utils.h" 11 #include "lldb/API/SBStream.h" 12 #include "lldb/Core/Module.h" 13 #include "lldb/Core/ModuleSpec.h" 14 #include "lldb/Host/Host.h" 15 #include "lldb/Symbol/ObjectFile.h" 16 #include "lldb/Utility/Instrumentation.h" 17 #include "lldb/Utility/Stream.h" 18 19 using namespace lldb; 20 using namespace lldb_private; 21 22 SBModuleSpec::SBModuleSpec() : m_opaque_up(new lldb_private::ModuleSpec()) { 23 LLDB_INSTRUMENT_VA(this); 24 } 25 26 SBModuleSpec::SBModuleSpec(const SBModuleSpec &rhs) { 27 LLDB_INSTRUMENT_VA(this, rhs); 28 29 m_opaque_up = clone(rhs.m_opaque_up); 30 } 31 32 const SBModuleSpec &SBModuleSpec::operator=(const SBModuleSpec &rhs) { 33 LLDB_INSTRUMENT_VA(this, rhs); 34 35 if (this != &rhs) 36 m_opaque_up = clone(rhs.m_opaque_up); 37 return *this; 38 } 39 40 SBModuleSpec::~SBModuleSpec() = default; 41 42 bool SBModuleSpec::IsValid() const { 43 LLDB_INSTRUMENT_VA(this); 44 return this->operator bool(); 45 } 46 SBModuleSpec::operator bool() const { 47 LLDB_INSTRUMENT_VA(this); 48 49 return m_opaque_up->operator bool(); 50 } 51 52 void SBModuleSpec::Clear() { 53 LLDB_INSTRUMENT_VA(this); 54 55 m_opaque_up->Clear(); 56 } 57 58 SBFileSpec SBModuleSpec::GetFileSpec() { 59 LLDB_INSTRUMENT_VA(this); 60 61 SBFileSpec sb_spec(m_opaque_up->GetFileSpec()); 62 return sb_spec; 63 } 64 65 void SBModuleSpec::SetFileSpec(const lldb::SBFileSpec &sb_spec) { 66 LLDB_INSTRUMENT_VA(this, sb_spec); 67 68 m_opaque_up->GetFileSpec() = *sb_spec; 69 } 70 71 lldb::SBFileSpec SBModuleSpec::GetPlatformFileSpec() { 72 LLDB_INSTRUMENT_VA(this); 73 74 return SBFileSpec(m_opaque_up->GetPlatformFileSpec()); 75 } 76 77 void SBModuleSpec::SetPlatformFileSpec(const lldb::SBFileSpec &sb_spec) { 78 LLDB_INSTRUMENT_VA(this, sb_spec); 79 80 m_opaque_up->GetPlatformFileSpec() = *sb_spec; 81 } 82 83 lldb::SBFileSpec SBModuleSpec::GetSymbolFileSpec() { 84 LLDB_INSTRUMENT_VA(this); 85 86 return SBFileSpec(m_opaque_up->GetSymbolFileSpec()); 87 } 88 89 void SBModuleSpec::SetSymbolFileSpec(const lldb::SBFileSpec &sb_spec) { 90 LLDB_INSTRUMENT_VA(this, sb_spec); 91 92 m_opaque_up->GetSymbolFileSpec() = *sb_spec; 93 } 94 95 const char *SBModuleSpec::GetObjectName() { 96 LLDB_INSTRUMENT_VA(this); 97 98 return m_opaque_up->GetObjectName().GetCString(); 99 } 100 101 void SBModuleSpec::SetObjectName(const char *name) { 102 LLDB_INSTRUMENT_VA(this, name); 103 104 m_opaque_up->GetObjectName().SetCString(name); 105 } 106 107 const char *SBModuleSpec::GetTriple() { 108 LLDB_INSTRUMENT_VA(this); 109 110 std::string triple(m_opaque_up->GetArchitecture().GetTriple().str()); 111 // Unique the string so we don't run into ownership issues since the const 112 // strings put the string into the string pool once and the strings never 113 // comes out 114 ConstString const_triple(triple.c_str()); 115 return const_triple.GetCString(); 116 } 117 118 void SBModuleSpec::SetTriple(const char *triple) { 119 LLDB_INSTRUMENT_VA(this, triple); 120 121 m_opaque_up->GetArchitecture().SetTriple(triple); 122 } 123 124 const uint8_t *SBModuleSpec::GetUUIDBytes() { 125 LLDB_INSTRUMENT_VA(this) 126 return m_opaque_up->GetUUID().GetBytes().data(); 127 } 128 129 size_t SBModuleSpec::GetUUIDLength() { 130 LLDB_INSTRUMENT_VA(this); 131 132 return m_opaque_up->GetUUID().GetBytes().size(); 133 } 134 135 bool SBModuleSpec::SetUUIDBytes(const uint8_t *uuid, size_t uuid_len) { 136 LLDB_INSTRUMENT_VA(this, uuid, uuid_len) 137 m_opaque_up->GetUUID() = UUID::fromOptionalData(uuid, uuid_len); 138 return m_opaque_up->GetUUID().IsValid(); 139 } 140 141 bool SBModuleSpec::GetDescription(lldb::SBStream &description) { 142 LLDB_INSTRUMENT_VA(this, description); 143 144 m_opaque_up->Dump(description.ref()); 145 return true; 146 } 147 148 SBModuleSpecList::SBModuleSpecList() : m_opaque_up(new ModuleSpecList()) { 149 LLDB_INSTRUMENT_VA(this); 150 } 151 152 SBModuleSpecList::SBModuleSpecList(const SBModuleSpecList &rhs) 153 : m_opaque_up(new ModuleSpecList(*rhs.m_opaque_up)) { 154 LLDB_INSTRUMENT_VA(this, rhs); 155 } 156 157 SBModuleSpecList &SBModuleSpecList::operator=(const SBModuleSpecList &rhs) { 158 LLDB_INSTRUMENT_VA(this, rhs); 159 160 if (this != &rhs) 161 *m_opaque_up = *rhs.m_opaque_up; 162 return *this; 163 } 164 165 SBModuleSpecList::~SBModuleSpecList() = default; 166 167 SBModuleSpecList SBModuleSpecList::GetModuleSpecifications(const char *path) { 168 LLDB_INSTRUMENT_VA(path); 169 170 SBModuleSpecList specs; 171 FileSpec file_spec(path); 172 FileSystem::Instance().Resolve(file_spec); 173 Host::ResolveExecutableInBundle(file_spec); 174 ObjectFile::GetModuleSpecifications(file_spec, 0, 0, *specs.m_opaque_up); 175 return specs; 176 } 177 178 void SBModuleSpecList::Append(const SBModuleSpec &spec) { 179 LLDB_INSTRUMENT_VA(this, spec); 180 181 m_opaque_up->Append(*spec.m_opaque_up); 182 } 183 184 void SBModuleSpecList::Append(const SBModuleSpecList &spec_list) { 185 LLDB_INSTRUMENT_VA(this, spec_list); 186 187 m_opaque_up->Append(*spec_list.m_opaque_up); 188 } 189 190 size_t SBModuleSpecList::GetSize() { 191 LLDB_INSTRUMENT_VA(this); 192 193 return m_opaque_up->GetSize(); 194 } 195 196 SBModuleSpec SBModuleSpecList::GetSpecAtIndex(size_t i) { 197 LLDB_INSTRUMENT_VA(this, i); 198 199 SBModuleSpec sb_module_spec; 200 m_opaque_up->GetModuleSpecAtIndex(i, *sb_module_spec.m_opaque_up); 201 return sb_module_spec; 202 } 203 204 SBModuleSpec 205 SBModuleSpecList::FindFirstMatchingSpec(const SBModuleSpec &match_spec) { 206 LLDB_INSTRUMENT_VA(this, match_spec); 207 208 SBModuleSpec sb_module_spec; 209 m_opaque_up->FindMatchingModuleSpec(*match_spec.m_opaque_up, 210 *sb_module_spec.m_opaque_up); 211 return sb_module_spec; 212 } 213 214 SBModuleSpecList 215 SBModuleSpecList::FindMatchingSpecs(const SBModuleSpec &match_spec) { 216 LLDB_INSTRUMENT_VA(this, match_spec); 217 218 SBModuleSpecList specs; 219 m_opaque_up->FindMatchingModuleSpecs(*match_spec.m_opaque_up, 220 *specs.m_opaque_up); 221 return specs; 222 } 223 224 bool SBModuleSpecList::GetDescription(lldb::SBStream &description) { 225 LLDB_INSTRUMENT_VA(this, description); 226 227 m_opaque_up->Dump(description.ref()); 228 return true; 229 } 230