Path: blob/main/contrib/llvm-project/lldb/source/API/SBModuleSpec.cpp
39587 views
//===-- SBModuleSpec.cpp --------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "lldb/API/SBModuleSpec.h"9#include "Utils.h"10#include "lldb/API/SBStream.h"11#include "lldb/Core/Module.h"12#include "lldb/Core/ModuleSpec.h"13#include "lldb/Host/Host.h"14#include "lldb/Symbol/ObjectFile.h"15#include "lldb/Utility/Instrumentation.h"16#include "lldb/Utility/Stream.h"1718using namespace lldb;19using namespace lldb_private;2021SBModuleSpec::SBModuleSpec() : m_opaque_up(new lldb_private::ModuleSpec()) {22LLDB_INSTRUMENT_VA(this);23}2425SBModuleSpec::SBModuleSpec(const SBModuleSpec &rhs) {26LLDB_INSTRUMENT_VA(this, rhs);2728m_opaque_up = clone(rhs.m_opaque_up);29}3031SBModuleSpec::SBModuleSpec(const lldb_private::ModuleSpec &module_spec)32: m_opaque_up(new lldb_private::ModuleSpec(module_spec)) {33LLDB_INSTRUMENT_VA(this, module_spec);34}3536const SBModuleSpec &SBModuleSpec::operator=(const SBModuleSpec &rhs) {37LLDB_INSTRUMENT_VA(this, rhs);3839if (this != &rhs)40m_opaque_up = clone(rhs.m_opaque_up);41return *this;42}4344SBModuleSpec::~SBModuleSpec() = default;4546bool SBModuleSpec::IsValid() const {47LLDB_INSTRUMENT_VA(this);48return this->operator bool();49}50SBModuleSpec::operator bool() const {51LLDB_INSTRUMENT_VA(this);5253return m_opaque_up->operator bool();54}5556void SBModuleSpec::Clear() {57LLDB_INSTRUMENT_VA(this);5859m_opaque_up->Clear();60}6162SBFileSpec SBModuleSpec::GetFileSpec() {63LLDB_INSTRUMENT_VA(this);6465SBFileSpec sb_spec(m_opaque_up->GetFileSpec());66return sb_spec;67}6869void SBModuleSpec::SetFileSpec(const lldb::SBFileSpec &sb_spec) {70LLDB_INSTRUMENT_VA(this, sb_spec);7172m_opaque_up->GetFileSpec() = *sb_spec;73}7475lldb::SBFileSpec SBModuleSpec::GetPlatformFileSpec() {76LLDB_INSTRUMENT_VA(this);7778return SBFileSpec(m_opaque_up->GetPlatformFileSpec());79}8081void SBModuleSpec::SetPlatformFileSpec(const lldb::SBFileSpec &sb_spec) {82LLDB_INSTRUMENT_VA(this, sb_spec);8384m_opaque_up->GetPlatformFileSpec() = *sb_spec;85}8687lldb::SBFileSpec SBModuleSpec::GetSymbolFileSpec() {88LLDB_INSTRUMENT_VA(this);8990return SBFileSpec(m_opaque_up->GetSymbolFileSpec());91}9293void SBModuleSpec::SetSymbolFileSpec(const lldb::SBFileSpec &sb_spec) {94LLDB_INSTRUMENT_VA(this, sb_spec);9596m_opaque_up->GetSymbolFileSpec() = *sb_spec;97}9899const char *SBModuleSpec::GetObjectName() {100LLDB_INSTRUMENT_VA(this);101102return m_opaque_up->GetObjectName().GetCString();103}104105void SBModuleSpec::SetObjectName(const char *name) {106LLDB_INSTRUMENT_VA(this, name);107108m_opaque_up->GetObjectName().SetCString(name);109}110111const char *SBModuleSpec::GetTriple() {112LLDB_INSTRUMENT_VA(this);113114std::string triple(m_opaque_up->GetArchitecture().GetTriple().str());115// Unique the string so we don't run into ownership issues since the const116// strings put the string into the string pool once and the strings never117// comes out118ConstString const_triple(triple.c_str());119return const_triple.GetCString();120}121122void SBModuleSpec::SetTriple(const char *triple) {123LLDB_INSTRUMENT_VA(this, triple);124125m_opaque_up->GetArchitecture().SetTriple(triple);126}127128const uint8_t *SBModuleSpec::GetUUIDBytes() {129LLDB_INSTRUMENT_VA(this)130return m_opaque_up->GetUUID().GetBytes().data();131}132133size_t SBModuleSpec::GetUUIDLength() {134LLDB_INSTRUMENT_VA(this);135136return m_opaque_up->GetUUID().GetBytes().size();137}138139bool SBModuleSpec::SetUUIDBytes(const uint8_t *uuid, size_t uuid_len) {140LLDB_INSTRUMENT_VA(this, uuid, uuid_len)141m_opaque_up->GetUUID() = UUID(uuid, uuid_len);142return m_opaque_up->GetUUID().IsValid();143}144145bool SBModuleSpec::GetDescription(lldb::SBStream &description) {146LLDB_INSTRUMENT_VA(this, description);147148m_opaque_up->Dump(description.ref());149return true;150}151152uint64_t SBModuleSpec::GetObjectOffset() {153LLDB_INSTRUMENT_VA(this);154155return m_opaque_up->GetObjectOffset();156}157158void SBModuleSpec::SetObjectOffset(uint64_t object_offset) {159LLDB_INSTRUMENT_VA(this, object_offset);160161m_opaque_up->SetObjectOffset(object_offset);162}163164uint64_t SBModuleSpec::GetObjectSize() {165LLDB_INSTRUMENT_VA(this);166167return m_opaque_up->GetObjectSize();168}169170void SBModuleSpec::SetObjectSize(uint64_t object_size) {171LLDB_INSTRUMENT_VA(this, object_size);172173m_opaque_up->SetObjectSize(object_size);174}175176SBModuleSpecList::SBModuleSpecList() : m_opaque_up(new ModuleSpecList()) {177LLDB_INSTRUMENT_VA(this);178}179180SBModuleSpecList::SBModuleSpecList(const SBModuleSpecList &rhs)181: m_opaque_up(new ModuleSpecList(*rhs.m_opaque_up)) {182LLDB_INSTRUMENT_VA(this, rhs);183}184185SBModuleSpecList &SBModuleSpecList::operator=(const SBModuleSpecList &rhs) {186LLDB_INSTRUMENT_VA(this, rhs);187188if (this != &rhs)189*m_opaque_up = *rhs.m_opaque_up;190return *this;191}192193SBModuleSpecList::~SBModuleSpecList() = default;194195SBModuleSpecList SBModuleSpecList::GetModuleSpecifications(const char *path) {196LLDB_INSTRUMENT_VA(path);197198SBModuleSpecList specs;199FileSpec file_spec(path);200FileSystem::Instance().Resolve(file_spec);201Host::ResolveExecutableInBundle(file_spec);202ObjectFile::GetModuleSpecifications(file_spec, 0, 0, *specs.m_opaque_up);203return specs;204}205206void SBModuleSpecList::Append(const SBModuleSpec &spec) {207LLDB_INSTRUMENT_VA(this, spec);208209m_opaque_up->Append(*spec.m_opaque_up);210}211212void SBModuleSpecList::Append(const SBModuleSpecList &spec_list) {213LLDB_INSTRUMENT_VA(this, spec_list);214215m_opaque_up->Append(*spec_list.m_opaque_up);216}217218size_t SBModuleSpecList::GetSize() {219LLDB_INSTRUMENT_VA(this);220221return m_opaque_up->GetSize();222}223224SBModuleSpec SBModuleSpecList::GetSpecAtIndex(size_t i) {225LLDB_INSTRUMENT_VA(this, i);226227SBModuleSpec sb_module_spec;228m_opaque_up->GetModuleSpecAtIndex(i, *sb_module_spec.m_opaque_up);229return sb_module_spec;230}231232SBModuleSpec233SBModuleSpecList::FindFirstMatchingSpec(const SBModuleSpec &match_spec) {234LLDB_INSTRUMENT_VA(this, match_spec);235236SBModuleSpec sb_module_spec;237m_opaque_up->FindMatchingModuleSpec(*match_spec.m_opaque_up,238*sb_module_spec.m_opaque_up);239return sb_module_spec;240}241242SBModuleSpecList243SBModuleSpecList::FindMatchingSpecs(const SBModuleSpec &match_spec) {244LLDB_INSTRUMENT_VA(this, match_spec);245246SBModuleSpecList specs;247m_opaque_up->FindMatchingModuleSpecs(*match_spec.m_opaque_up,248*specs.m_opaque_up);249return specs;250}251252bool SBModuleSpecList::GetDescription(lldb::SBStream &description) {253LLDB_INSTRUMENT_VA(this, description);254255m_opaque_up->Dump(description.ref());256return true;257}258259260