1226cce25SGreg Clayton //===-- SBModuleSpec.cpp ----------------------------------------*- C++ -*-===// 2226cce25SGreg Clayton // 32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6226cce25SGreg Clayton // 7226cce25SGreg Clayton //===----------------------------------------------------------------------===// 8226cce25SGreg Clayton 9226cce25SGreg Clayton #include "lldb/API/SBModuleSpec.h" 10226cce25SGreg Clayton #include "lldb/API/SBStream.h" 11226cce25SGreg Clayton #include "lldb/Core/Module.h" 12226cce25SGreg Clayton #include "lldb/Core/ModuleSpec.h" 13226cce25SGreg Clayton #include "lldb/Host/Host.h" 14226cce25SGreg Clayton #include "lldb/Symbol/ObjectFile.h" 15bf9a7730SZachary Turner #include "lldb/Utility/Stream.h" 16226cce25SGreg Clayton 17226cce25SGreg Clayton using namespace lldb; 18226cce25SGreg Clayton using namespace lldb_private; 19226cce25SGreg Clayton 20*d5b44036SJonas Devlieghere SBModuleSpec::SBModuleSpec() : m_opaque_up(new lldb_private::ModuleSpec()) {} 21226cce25SGreg Clayton 22b9c1b51eSKate Stone SBModuleSpec::SBModuleSpec(const SBModuleSpec &rhs) 23*d5b44036SJonas Devlieghere : m_opaque_up(new lldb_private::ModuleSpec(*rhs.m_opaque_up)) {} 24226cce25SGreg Clayton 25b9c1b51eSKate Stone const SBModuleSpec &SBModuleSpec::operator=(const SBModuleSpec &rhs) { 26226cce25SGreg Clayton if (this != &rhs) 27*d5b44036SJonas Devlieghere *m_opaque_up = *(rhs.m_opaque_up); 28226cce25SGreg Clayton return *this; 29226cce25SGreg Clayton } 30226cce25SGreg Clayton 31b9c1b51eSKate Stone SBModuleSpec::~SBModuleSpec() {} 32226cce25SGreg Clayton 33*d5b44036SJonas Devlieghere bool SBModuleSpec::IsValid() const { return m_opaque_up->operator bool(); } 34226cce25SGreg Clayton 35*d5b44036SJonas Devlieghere void SBModuleSpec::Clear() { m_opaque_up->Clear(); } 36226cce25SGreg Clayton 37b9c1b51eSKate Stone SBFileSpec SBModuleSpec::GetFileSpec() { 38*d5b44036SJonas Devlieghere SBFileSpec sb_spec(m_opaque_up->GetFileSpec()); 39226cce25SGreg Clayton return sb_spec; 40226cce25SGreg Clayton } 41226cce25SGreg Clayton 42b9c1b51eSKate Stone void SBModuleSpec::SetFileSpec(const lldb::SBFileSpec &sb_spec) { 43*d5b44036SJonas Devlieghere m_opaque_up->GetFileSpec() = *sb_spec; 44226cce25SGreg Clayton } 45226cce25SGreg Clayton 46b9c1b51eSKate Stone lldb::SBFileSpec SBModuleSpec::GetPlatformFileSpec() { 47*d5b44036SJonas Devlieghere return SBFileSpec(m_opaque_up->GetPlatformFileSpec()); 48226cce25SGreg Clayton } 49226cce25SGreg Clayton 50b9c1b51eSKate Stone void SBModuleSpec::SetPlatformFileSpec(const lldb::SBFileSpec &sb_spec) { 51*d5b44036SJonas Devlieghere m_opaque_up->GetPlatformFileSpec() = *sb_spec; 52226cce25SGreg Clayton } 53226cce25SGreg Clayton 54b9c1b51eSKate Stone lldb::SBFileSpec SBModuleSpec::GetSymbolFileSpec() { 55*d5b44036SJonas Devlieghere return SBFileSpec(m_opaque_up->GetSymbolFileSpec()); 56226cce25SGreg Clayton } 57226cce25SGreg Clayton 58b9c1b51eSKate Stone void SBModuleSpec::SetSymbolFileSpec(const lldb::SBFileSpec &sb_spec) { 59*d5b44036SJonas Devlieghere m_opaque_up->GetSymbolFileSpec() = *sb_spec; 60226cce25SGreg Clayton } 61226cce25SGreg Clayton 62b9c1b51eSKate Stone const char *SBModuleSpec::GetObjectName() { 63*d5b44036SJonas Devlieghere return m_opaque_up->GetObjectName().GetCString(); 64226cce25SGreg Clayton } 65226cce25SGreg Clayton 66b9c1b51eSKate Stone void SBModuleSpec::SetObjectName(const char *name) { 67*d5b44036SJonas Devlieghere m_opaque_up->GetObjectName().SetCString(name); 68226cce25SGreg Clayton } 69226cce25SGreg Clayton 70b9c1b51eSKate Stone const char *SBModuleSpec::GetTriple() { 71*d5b44036SJonas Devlieghere std::string triple(m_opaque_up->GetArchitecture().GetTriple().str()); 7205097246SAdrian Prantl // Unique the string so we don't run into ownership issues since the const 7305097246SAdrian Prantl // strings put the string into the string pool once and the strings never 7405097246SAdrian Prantl // comes out 75226cce25SGreg Clayton ConstString const_triple(triple.c_str()); 76226cce25SGreg Clayton return const_triple.GetCString(); 77226cce25SGreg Clayton } 78226cce25SGreg Clayton 79b9c1b51eSKate Stone void SBModuleSpec::SetTriple(const char *triple) { 80*d5b44036SJonas Devlieghere m_opaque_up->GetArchitecture().SetTriple(triple); 81226cce25SGreg Clayton } 82226cce25SGreg Clayton 83b9c1b51eSKate Stone const uint8_t *SBModuleSpec::GetUUIDBytes() { 84*d5b44036SJonas Devlieghere return m_opaque_up->GetUUID().GetBytes().data(); 85226cce25SGreg Clayton } 86226cce25SGreg Clayton 87b9c1b51eSKate Stone size_t SBModuleSpec::GetUUIDLength() { 88*d5b44036SJonas Devlieghere return m_opaque_up->GetUUID().GetBytes().size(); 89226cce25SGreg Clayton } 90226cce25SGreg Clayton 91b9c1b51eSKate Stone bool SBModuleSpec::SetUUIDBytes(const uint8_t *uuid, size_t uuid_len) { 92*d5b44036SJonas Devlieghere m_opaque_up->GetUUID() = UUID::fromOptionalData(uuid, uuid_len); 93*d5b44036SJonas Devlieghere return m_opaque_up->GetUUID().IsValid(); 94226cce25SGreg Clayton } 95226cce25SGreg Clayton 96b9c1b51eSKate Stone bool SBModuleSpec::GetDescription(lldb::SBStream &description) { 97*d5b44036SJonas Devlieghere m_opaque_up->Dump(description.ref()); 98226cce25SGreg Clayton return true; 99226cce25SGreg Clayton } 100226cce25SGreg Clayton 101*d5b44036SJonas Devlieghere SBModuleSpecList::SBModuleSpecList() : m_opaque_up(new ModuleSpecList()) {} 102226cce25SGreg Clayton 103b9c1b51eSKate Stone SBModuleSpecList::SBModuleSpecList(const SBModuleSpecList &rhs) 104*d5b44036SJonas Devlieghere : m_opaque_up(new ModuleSpecList(*rhs.m_opaque_up)) {} 105226cce25SGreg Clayton 106b9c1b51eSKate Stone SBModuleSpecList &SBModuleSpecList::operator=(const SBModuleSpecList &rhs) { 107226cce25SGreg Clayton if (this != &rhs) 108*d5b44036SJonas Devlieghere *m_opaque_up = *rhs.m_opaque_up; 109226cce25SGreg Clayton return *this; 110226cce25SGreg Clayton } 111226cce25SGreg Clayton 112b9c1b51eSKate Stone SBModuleSpecList::~SBModuleSpecList() {} 113226cce25SGreg Clayton 114b9c1b51eSKate Stone SBModuleSpecList SBModuleSpecList::GetModuleSpecifications(const char *path) { 115226cce25SGreg Clayton SBModuleSpecList specs; 1168f3be7a3SJonas Devlieghere FileSpec file_spec(path); 1178f3be7a3SJonas Devlieghere FileSystem::Instance().Resolve(file_spec); 118226cce25SGreg Clayton Host::ResolveExecutableInBundle(file_spec); 119*d5b44036SJonas Devlieghere ObjectFile::GetModuleSpecifications(file_spec, 0, 0, *specs.m_opaque_up); 120226cce25SGreg Clayton return specs; 121226cce25SGreg Clayton } 122226cce25SGreg Clayton 123b9c1b51eSKate Stone void SBModuleSpecList::Append(const SBModuleSpec &spec) { 124*d5b44036SJonas Devlieghere m_opaque_up->Append(*spec.m_opaque_up); 125226cce25SGreg Clayton } 126226cce25SGreg Clayton 127b9c1b51eSKate Stone void SBModuleSpecList::Append(const SBModuleSpecList &spec_list) { 128*d5b44036SJonas Devlieghere m_opaque_up->Append(*spec_list.m_opaque_up); 129226cce25SGreg Clayton } 130226cce25SGreg Clayton 131*d5b44036SJonas Devlieghere size_t SBModuleSpecList::GetSize() { return m_opaque_up->GetSize(); } 132226cce25SGreg Clayton 133b9c1b51eSKate Stone SBModuleSpec SBModuleSpecList::GetSpecAtIndex(size_t i) { 134226cce25SGreg Clayton SBModuleSpec sb_module_spec; 135*d5b44036SJonas Devlieghere m_opaque_up->GetModuleSpecAtIndex(i, *sb_module_spec.m_opaque_up); 136226cce25SGreg Clayton return sb_module_spec; 137226cce25SGreg Clayton } 138226cce25SGreg Clayton 139226cce25SGreg Clayton SBModuleSpec 140b9c1b51eSKate Stone SBModuleSpecList::FindFirstMatchingSpec(const SBModuleSpec &match_spec) { 141226cce25SGreg Clayton SBModuleSpec sb_module_spec; 142*d5b44036SJonas Devlieghere m_opaque_up->FindMatchingModuleSpec(*match_spec.m_opaque_up, 143*d5b44036SJonas Devlieghere *sb_module_spec.m_opaque_up); 144226cce25SGreg Clayton return sb_module_spec; 145226cce25SGreg Clayton } 146226cce25SGreg Clayton 147226cce25SGreg Clayton SBModuleSpecList 148b9c1b51eSKate Stone SBModuleSpecList::FindMatchingSpecs(const SBModuleSpec &match_spec) { 149226cce25SGreg Clayton SBModuleSpecList specs; 150*d5b44036SJonas Devlieghere m_opaque_up->FindMatchingModuleSpecs(*match_spec.m_opaque_up, 151*d5b44036SJonas Devlieghere *specs.m_opaque_up); 152226cce25SGreg Clayton return specs; 153226cce25SGreg Clayton } 154226cce25SGreg Clayton 155b9c1b51eSKate Stone bool SBModuleSpecList::GetDescription(lldb::SBStream &description) { 156*d5b44036SJonas Devlieghere m_opaque_up->Dump(description.ref()); 157226cce25SGreg Clayton return true; 158226cce25SGreg Clayton } 159