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