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" 10*baf5664fSJonas Devlieghere #include "SBReproducerPrivate.h" 11bd4bf82aSJonas Devlieghere #include "Utils.h" 12226cce25SGreg Clayton #include "lldb/API/SBStream.h" 13226cce25SGreg Clayton #include "lldb/Core/Module.h" 14226cce25SGreg Clayton #include "lldb/Core/ModuleSpec.h" 15226cce25SGreg Clayton #include "lldb/Host/Host.h" 16226cce25SGreg Clayton #include "lldb/Symbol/ObjectFile.h" 17bf9a7730SZachary Turner #include "lldb/Utility/Stream.h" 18226cce25SGreg Clayton 19226cce25SGreg Clayton using namespace lldb; 20226cce25SGreg Clayton using namespace lldb_private; 21226cce25SGreg Clayton 22*baf5664fSJonas Devlieghere SBModuleSpec::SBModuleSpec() : m_opaque_up(new lldb_private::ModuleSpec()) { 23*baf5664fSJonas Devlieghere LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBModuleSpec); 24*baf5664fSJonas Devlieghere } 25226cce25SGreg Clayton 26bd4bf82aSJonas Devlieghere SBModuleSpec::SBModuleSpec(const SBModuleSpec &rhs) : m_opaque_up() { 27*baf5664fSJonas Devlieghere LLDB_RECORD_CONSTRUCTOR(SBModuleSpec, (const lldb::SBModuleSpec &), rhs); 28*baf5664fSJonas Devlieghere 29bd4bf82aSJonas Devlieghere m_opaque_up = clone(rhs.m_opaque_up); 30bd4bf82aSJonas Devlieghere } 31226cce25SGreg Clayton 32b9c1b51eSKate Stone const SBModuleSpec &SBModuleSpec::operator=(const SBModuleSpec &rhs) { 33*baf5664fSJonas Devlieghere LLDB_RECORD_METHOD(const lldb::SBModuleSpec &, 34*baf5664fSJonas Devlieghere SBModuleSpec, operator=,(const lldb::SBModuleSpec &), rhs); 35*baf5664fSJonas Devlieghere 36226cce25SGreg Clayton if (this != &rhs) 37bd4bf82aSJonas Devlieghere m_opaque_up = clone(rhs.m_opaque_up); 38226cce25SGreg Clayton return *this; 39226cce25SGreg Clayton } 40226cce25SGreg Clayton 41b9c1b51eSKate Stone SBModuleSpec::~SBModuleSpec() {} 42226cce25SGreg Clayton 43*baf5664fSJonas Devlieghere bool SBModuleSpec::IsValid() const { 44*baf5664fSJonas Devlieghere LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBModuleSpec, IsValid); 45226cce25SGreg Clayton 46*baf5664fSJonas Devlieghere return m_opaque_up->operator bool(); 47*baf5664fSJonas Devlieghere } 48*baf5664fSJonas Devlieghere 49*baf5664fSJonas Devlieghere void SBModuleSpec::Clear() { 50*baf5664fSJonas Devlieghere LLDB_RECORD_METHOD_NO_ARGS(void, SBModuleSpec, Clear); 51*baf5664fSJonas Devlieghere 52*baf5664fSJonas Devlieghere m_opaque_up->Clear(); 53*baf5664fSJonas Devlieghere } 54226cce25SGreg Clayton 55b9c1b51eSKate Stone SBFileSpec SBModuleSpec::GetFileSpec() { 56*baf5664fSJonas Devlieghere LLDB_RECORD_METHOD_NO_ARGS(lldb::SBFileSpec, SBModuleSpec, GetFileSpec); 57*baf5664fSJonas Devlieghere 58d5b44036SJonas Devlieghere SBFileSpec sb_spec(m_opaque_up->GetFileSpec()); 59*baf5664fSJonas Devlieghere return LLDB_RECORD_RESULT(sb_spec); 60226cce25SGreg Clayton } 61226cce25SGreg Clayton 62b9c1b51eSKate Stone void SBModuleSpec::SetFileSpec(const lldb::SBFileSpec &sb_spec) { 63*baf5664fSJonas Devlieghere LLDB_RECORD_METHOD(void, SBModuleSpec, SetFileSpec, 64*baf5664fSJonas Devlieghere (const lldb::SBFileSpec &), sb_spec); 65*baf5664fSJonas Devlieghere 66d5b44036SJonas Devlieghere m_opaque_up->GetFileSpec() = *sb_spec; 67226cce25SGreg Clayton } 68226cce25SGreg Clayton 69b9c1b51eSKate Stone lldb::SBFileSpec SBModuleSpec::GetPlatformFileSpec() { 70*baf5664fSJonas Devlieghere LLDB_RECORD_METHOD_NO_ARGS(lldb::SBFileSpec, SBModuleSpec, 71*baf5664fSJonas Devlieghere GetPlatformFileSpec); 72*baf5664fSJonas Devlieghere 73*baf5664fSJonas Devlieghere return LLDB_RECORD_RESULT(SBFileSpec(m_opaque_up->GetPlatformFileSpec())); 74226cce25SGreg Clayton } 75226cce25SGreg Clayton 76b9c1b51eSKate Stone void SBModuleSpec::SetPlatformFileSpec(const lldb::SBFileSpec &sb_spec) { 77*baf5664fSJonas Devlieghere LLDB_RECORD_METHOD(void, SBModuleSpec, SetPlatformFileSpec, 78*baf5664fSJonas Devlieghere (const lldb::SBFileSpec &), sb_spec); 79*baf5664fSJonas Devlieghere 80d5b44036SJonas Devlieghere m_opaque_up->GetPlatformFileSpec() = *sb_spec; 81226cce25SGreg Clayton } 82226cce25SGreg Clayton 83b9c1b51eSKate Stone lldb::SBFileSpec SBModuleSpec::GetSymbolFileSpec() { 84*baf5664fSJonas Devlieghere LLDB_RECORD_METHOD_NO_ARGS(lldb::SBFileSpec, SBModuleSpec, GetSymbolFileSpec); 85*baf5664fSJonas Devlieghere 86*baf5664fSJonas Devlieghere return LLDB_RECORD_RESULT(SBFileSpec(m_opaque_up->GetSymbolFileSpec())); 87226cce25SGreg Clayton } 88226cce25SGreg Clayton 89b9c1b51eSKate Stone void SBModuleSpec::SetSymbolFileSpec(const lldb::SBFileSpec &sb_spec) { 90*baf5664fSJonas Devlieghere LLDB_RECORD_METHOD(void, SBModuleSpec, SetSymbolFileSpec, 91*baf5664fSJonas Devlieghere (const lldb::SBFileSpec &), sb_spec); 92*baf5664fSJonas Devlieghere 93d5b44036SJonas Devlieghere m_opaque_up->GetSymbolFileSpec() = *sb_spec; 94226cce25SGreg Clayton } 95226cce25SGreg Clayton 96b9c1b51eSKate Stone const char *SBModuleSpec::GetObjectName() { 97*baf5664fSJonas Devlieghere LLDB_RECORD_METHOD_NO_ARGS(const char *, SBModuleSpec, GetObjectName); 98*baf5664fSJonas Devlieghere 99d5b44036SJonas Devlieghere return m_opaque_up->GetObjectName().GetCString(); 100226cce25SGreg Clayton } 101226cce25SGreg Clayton 102b9c1b51eSKate Stone void SBModuleSpec::SetObjectName(const char *name) { 103*baf5664fSJonas Devlieghere LLDB_RECORD_METHOD(void, SBModuleSpec, SetObjectName, (const char *), name); 104*baf5664fSJonas Devlieghere 105d5b44036SJonas Devlieghere m_opaque_up->GetObjectName().SetCString(name); 106226cce25SGreg Clayton } 107226cce25SGreg Clayton 108b9c1b51eSKate Stone const char *SBModuleSpec::GetTriple() { 109*baf5664fSJonas Devlieghere LLDB_RECORD_METHOD_NO_ARGS(const char *, SBModuleSpec, GetTriple); 110*baf5664fSJonas Devlieghere 111d5b44036SJonas Devlieghere std::string triple(m_opaque_up->GetArchitecture().GetTriple().str()); 11205097246SAdrian Prantl // Unique the string so we don't run into ownership issues since the const 11305097246SAdrian Prantl // strings put the string into the string pool once and the strings never 11405097246SAdrian Prantl // comes out 115226cce25SGreg Clayton ConstString const_triple(triple.c_str()); 116226cce25SGreg Clayton return const_triple.GetCString(); 117226cce25SGreg Clayton } 118226cce25SGreg Clayton 119b9c1b51eSKate Stone void SBModuleSpec::SetTriple(const char *triple) { 120*baf5664fSJonas Devlieghere LLDB_RECORD_METHOD(void, SBModuleSpec, SetTriple, (const char *), triple); 121*baf5664fSJonas Devlieghere 122d5b44036SJonas Devlieghere m_opaque_up->GetArchitecture().SetTriple(triple); 123226cce25SGreg Clayton } 124226cce25SGreg Clayton 125b9c1b51eSKate Stone const uint8_t *SBModuleSpec::GetUUIDBytes() { 126d5b44036SJonas Devlieghere return m_opaque_up->GetUUID().GetBytes().data(); 127226cce25SGreg Clayton } 128226cce25SGreg Clayton 129b9c1b51eSKate Stone size_t SBModuleSpec::GetUUIDLength() { 130*baf5664fSJonas Devlieghere LLDB_RECORD_METHOD_NO_ARGS(size_t, SBModuleSpec, GetUUIDLength); 131*baf5664fSJonas Devlieghere 132d5b44036SJonas Devlieghere return m_opaque_up->GetUUID().GetBytes().size(); 133226cce25SGreg Clayton } 134226cce25SGreg Clayton 135b9c1b51eSKate Stone bool SBModuleSpec::SetUUIDBytes(const uint8_t *uuid, size_t uuid_len) { 136d5b44036SJonas Devlieghere m_opaque_up->GetUUID() = UUID::fromOptionalData(uuid, uuid_len); 137d5b44036SJonas Devlieghere return m_opaque_up->GetUUID().IsValid(); 138226cce25SGreg Clayton } 139226cce25SGreg Clayton 140b9c1b51eSKate Stone bool SBModuleSpec::GetDescription(lldb::SBStream &description) { 141*baf5664fSJonas Devlieghere LLDB_RECORD_METHOD(bool, SBModuleSpec, GetDescription, (lldb::SBStream &), 142*baf5664fSJonas Devlieghere description); 143*baf5664fSJonas Devlieghere 144d5b44036SJonas Devlieghere m_opaque_up->Dump(description.ref()); 145226cce25SGreg Clayton return true; 146226cce25SGreg Clayton } 147226cce25SGreg Clayton 148*baf5664fSJonas Devlieghere SBModuleSpecList::SBModuleSpecList() : m_opaque_up(new ModuleSpecList()) { 149*baf5664fSJonas Devlieghere LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBModuleSpecList); 150*baf5664fSJonas Devlieghere } 151226cce25SGreg Clayton 152b9c1b51eSKate Stone SBModuleSpecList::SBModuleSpecList(const SBModuleSpecList &rhs) 153*baf5664fSJonas Devlieghere : m_opaque_up(new ModuleSpecList(*rhs.m_opaque_up)) { 154*baf5664fSJonas Devlieghere LLDB_RECORD_CONSTRUCTOR(SBModuleSpecList, (const lldb::SBModuleSpecList &), 155*baf5664fSJonas Devlieghere rhs); 156*baf5664fSJonas Devlieghere } 157226cce25SGreg Clayton 158b9c1b51eSKate Stone SBModuleSpecList &SBModuleSpecList::operator=(const SBModuleSpecList &rhs) { 159*baf5664fSJonas Devlieghere LLDB_RECORD_METHOD( 160*baf5664fSJonas Devlieghere lldb::SBModuleSpecList &, 161*baf5664fSJonas Devlieghere SBModuleSpecList, operator=,(const lldb::SBModuleSpecList &), rhs); 162*baf5664fSJonas Devlieghere 163226cce25SGreg Clayton if (this != &rhs) 164d5b44036SJonas Devlieghere *m_opaque_up = *rhs.m_opaque_up; 165226cce25SGreg Clayton return *this; 166226cce25SGreg Clayton } 167226cce25SGreg Clayton 168b9c1b51eSKate Stone SBModuleSpecList::~SBModuleSpecList() {} 169226cce25SGreg Clayton 170b9c1b51eSKate Stone SBModuleSpecList SBModuleSpecList::GetModuleSpecifications(const char *path) { 171*baf5664fSJonas Devlieghere LLDB_RECORD_STATIC_METHOD(lldb::SBModuleSpecList, SBModuleSpecList, 172*baf5664fSJonas Devlieghere GetModuleSpecifications, (const char *), path); 173*baf5664fSJonas Devlieghere 174226cce25SGreg Clayton SBModuleSpecList specs; 1758f3be7a3SJonas Devlieghere FileSpec file_spec(path); 1768f3be7a3SJonas Devlieghere FileSystem::Instance().Resolve(file_spec); 177226cce25SGreg Clayton Host::ResolveExecutableInBundle(file_spec); 178d5b44036SJonas Devlieghere ObjectFile::GetModuleSpecifications(file_spec, 0, 0, *specs.m_opaque_up); 179*baf5664fSJonas Devlieghere return LLDB_RECORD_RESULT(specs); 180226cce25SGreg Clayton } 181226cce25SGreg Clayton 182b9c1b51eSKate Stone void SBModuleSpecList::Append(const SBModuleSpec &spec) { 183*baf5664fSJonas Devlieghere LLDB_RECORD_METHOD(void, SBModuleSpecList, Append, 184*baf5664fSJonas Devlieghere (const lldb::SBModuleSpec &), spec); 185*baf5664fSJonas Devlieghere 186d5b44036SJonas Devlieghere m_opaque_up->Append(*spec.m_opaque_up); 187226cce25SGreg Clayton } 188226cce25SGreg Clayton 189b9c1b51eSKate Stone void SBModuleSpecList::Append(const SBModuleSpecList &spec_list) { 190*baf5664fSJonas Devlieghere LLDB_RECORD_METHOD(void, SBModuleSpecList, Append, 191*baf5664fSJonas Devlieghere (const lldb::SBModuleSpecList &), spec_list); 192*baf5664fSJonas Devlieghere 193d5b44036SJonas Devlieghere m_opaque_up->Append(*spec_list.m_opaque_up); 194226cce25SGreg Clayton } 195226cce25SGreg Clayton 196*baf5664fSJonas Devlieghere size_t SBModuleSpecList::GetSize() { 197*baf5664fSJonas Devlieghere LLDB_RECORD_METHOD_NO_ARGS(size_t, SBModuleSpecList, GetSize); 198*baf5664fSJonas Devlieghere 199*baf5664fSJonas Devlieghere return m_opaque_up->GetSize(); 200*baf5664fSJonas Devlieghere } 201226cce25SGreg Clayton 202b9c1b51eSKate Stone SBModuleSpec SBModuleSpecList::GetSpecAtIndex(size_t i) { 203*baf5664fSJonas Devlieghere LLDB_RECORD_METHOD(lldb::SBModuleSpec, SBModuleSpecList, GetSpecAtIndex, 204*baf5664fSJonas Devlieghere (size_t), i); 205*baf5664fSJonas Devlieghere 206226cce25SGreg Clayton SBModuleSpec sb_module_spec; 207d5b44036SJonas Devlieghere m_opaque_up->GetModuleSpecAtIndex(i, *sb_module_spec.m_opaque_up); 208*baf5664fSJonas Devlieghere return LLDB_RECORD_RESULT(sb_module_spec); 209226cce25SGreg Clayton } 210226cce25SGreg Clayton 211226cce25SGreg Clayton SBModuleSpec 212b9c1b51eSKate Stone SBModuleSpecList::FindFirstMatchingSpec(const SBModuleSpec &match_spec) { 213*baf5664fSJonas Devlieghere LLDB_RECORD_METHOD(lldb::SBModuleSpec, SBModuleSpecList, 214*baf5664fSJonas Devlieghere FindFirstMatchingSpec, (const lldb::SBModuleSpec &), 215*baf5664fSJonas Devlieghere match_spec); 216*baf5664fSJonas Devlieghere 217226cce25SGreg Clayton SBModuleSpec sb_module_spec; 218d5b44036SJonas Devlieghere m_opaque_up->FindMatchingModuleSpec(*match_spec.m_opaque_up, 219d5b44036SJonas Devlieghere *sb_module_spec.m_opaque_up); 220*baf5664fSJonas Devlieghere return LLDB_RECORD_RESULT(sb_module_spec); 221226cce25SGreg Clayton } 222226cce25SGreg Clayton 223226cce25SGreg Clayton SBModuleSpecList 224b9c1b51eSKate Stone SBModuleSpecList::FindMatchingSpecs(const SBModuleSpec &match_spec) { 225*baf5664fSJonas Devlieghere LLDB_RECORD_METHOD(lldb::SBModuleSpecList, SBModuleSpecList, 226*baf5664fSJonas Devlieghere FindMatchingSpecs, (const lldb::SBModuleSpec &), 227*baf5664fSJonas Devlieghere match_spec); 228*baf5664fSJonas Devlieghere 229226cce25SGreg Clayton SBModuleSpecList specs; 230d5b44036SJonas Devlieghere m_opaque_up->FindMatchingModuleSpecs(*match_spec.m_opaque_up, 231d5b44036SJonas Devlieghere *specs.m_opaque_up); 232*baf5664fSJonas Devlieghere return LLDB_RECORD_RESULT(specs); 233226cce25SGreg Clayton } 234226cce25SGreg Clayton 235b9c1b51eSKate Stone bool SBModuleSpecList::GetDescription(lldb::SBStream &description) { 236*baf5664fSJonas Devlieghere LLDB_RECORD_METHOD(bool, SBModuleSpecList, GetDescription, (lldb::SBStream &), 237*baf5664fSJonas Devlieghere description); 238*baf5664fSJonas Devlieghere 239d5b44036SJonas Devlieghere m_opaque_up->Dump(description.ref()); 240226cce25SGreg Clayton return true; 241226cce25SGreg Clayton } 242