1ac7ddfbfSEd Maste //===-- SBModuleSpec.cpp ----------------------------------------*- C++ -*-===// 2ac7ddfbfSEd Maste // 3ac7ddfbfSEd Maste // The LLVM Compiler Infrastructure 4ac7ddfbfSEd Maste // 5ac7ddfbfSEd Maste // This file is distributed under the University of Illinois Open Source 6ac7ddfbfSEd Maste // License. See LICENSE.TXT for details. 7ac7ddfbfSEd Maste // 8ac7ddfbfSEd Maste //===----------------------------------------------------------------------===// 9ac7ddfbfSEd Maste 10ac7ddfbfSEd Maste #include "lldb/API/SBModuleSpec.h" 11ac7ddfbfSEd Maste #include "lldb/API/SBStream.h" 12ac7ddfbfSEd Maste #include "lldb/Core/Module.h" 13ac7ddfbfSEd Maste #include "lldb/Core/ModuleSpec.h" 14ac7ddfbfSEd Maste #include "lldb/Host/Host.h" 15ac7ddfbfSEd Maste #include "lldb/Symbol/ObjectFile.h" 16f678e45dSDimitry Andric #include "lldb/Utility/Stream.h" 17ac7ddfbfSEd Maste 18ac7ddfbfSEd Maste using namespace lldb; 19ac7ddfbfSEd Maste using namespace lldb_private; 20ac7ddfbfSEd Maste SBModuleSpec()21435933ddSDimitry AndricSBModuleSpec::SBModuleSpec() : m_opaque_ap(new lldb_private::ModuleSpec()) {} 22ac7ddfbfSEd Maste SBModuleSpec(const SBModuleSpec & rhs)23435933ddSDimitry AndricSBModuleSpec::SBModuleSpec(const SBModuleSpec &rhs) 24435933ddSDimitry Andric : m_opaque_ap(new lldb_private::ModuleSpec(*rhs.m_opaque_ap)) {} 25ac7ddfbfSEd Maste operator =(const SBModuleSpec & rhs)26435933ddSDimitry Andricconst SBModuleSpec &SBModuleSpec::operator=(const SBModuleSpec &rhs) { 27ac7ddfbfSEd Maste if (this != &rhs) 28ac7ddfbfSEd Maste *m_opaque_ap = *(rhs.m_opaque_ap); 29ac7ddfbfSEd Maste return *this; 30ac7ddfbfSEd Maste } 31ac7ddfbfSEd Maste ~SBModuleSpec()32435933ddSDimitry AndricSBModuleSpec::~SBModuleSpec() {} 33ac7ddfbfSEd Maste IsValid() const34435933ddSDimitry Andricbool SBModuleSpec::IsValid() const { return m_opaque_ap->operator bool(); } 35ac7ddfbfSEd Maste Clear()36435933ddSDimitry Andricvoid SBModuleSpec::Clear() { m_opaque_ap->Clear(); } 37ac7ddfbfSEd Maste GetFileSpec()38435933ddSDimitry AndricSBFileSpec SBModuleSpec::GetFileSpec() { 39ac7ddfbfSEd Maste SBFileSpec sb_spec(m_opaque_ap->GetFileSpec()); 40ac7ddfbfSEd Maste return sb_spec; 41ac7ddfbfSEd Maste } 42ac7ddfbfSEd Maste SetFileSpec(const lldb::SBFileSpec & sb_spec)43435933ddSDimitry Andricvoid SBModuleSpec::SetFileSpec(const lldb::SBFileSpec &sb_spec) { 44ac7ddfbfSEd Maste m_opaque_ap->GetFileSpec() = *sb_spec; 45ac7ddfbfSEd Maste } 46ac7ddfbfSEd Maste GetPlatformFileSpec()47435933ddSDimitry Andriclldb::SBFileSpec SBModuleSpec::GetPlatformFileSpec() { 48ac7ddfbfSEd Maste return SBFileSpec(m_opaque_ap->GetPlatformFileSpec()); 49ac7ddfbfSEd Maste } 50ac7ddfbfSEd Maste SetPlatformFileSpec(const lldb::SBFileSpec & sb_spec)51435933ddSDimitry Andricvoid SBModuleSpec::SetPlatformFileSpec(const lldb::SBFileSpec &sb_spec) { 52ac7ddfbfSEd Maste m_opaque_ap->GetPlatformFileSpec() = *sb_spec; 53ac7ddfbfSEd Maste } 54ac7ddfbfSEd Maste GetSymbolFileSpec()55435933ddSDimitry Andriclldb::SBFileSpec SBModuleSpec::GetSymbolFileSpec() { 56ac7ddfbfSEd Maste return SBFileSpec(m_opaque_ap->GetSymbolFileSpec()); 57ac7ddfbfSEd Maste } 58ac7ddfbfSEd Maste SetSymbolFileSpec(const lldb::SBFileSpec & sb_spec)59435933ddSDimitry Andricvoid SBModuleSpec::SetSymbolFileSpec(const lldb::SBFileSpec &sb_spec) { 60ac7ddfbfSEd Maste m_opaque_ap->GetSymbolFileSpec() = *sb_spec; 61ac7ddfbfSEd Maste } 62ac7ddfbfSEd Maste GetObjectName()63435933ddSDimitry Andricconst char *SBModuleSpec::GetObjectName() { 64ac7ddfbfSEd Maste return m_opaque_ap->GetObjectName().GetCString(); 65ac7ddfbfSEd Maste } 66ac7ddfbfSEd Maste SetObjectName(const char * name)67435933ddSDimitry Andricvoid SBModuleSpec::SetObjectName(const char *name) { 68ac7ddfbfSEd Maste m_opaque_ap->GetObjectName().SetCString(name); 69ac7ddfbfSEd Maste } 70ac7ddfbfSEd Maste GetTriple()71435933ddSDimitry Andricconst char *SBModuleSpec::GetTriple() { 72ac7ddfbfSEd Maste std::string triple(m_opaque_ap->GetArchitecture().GetTriple().str()); 734ba319b5SDimitry Andric // Unique the string so we don't run into ownership issues since the const 744ba319b5SDimitry Andric // strings put the string into the string pool once and the strings never 754ba319b5SDimitry Andric // comes out 76ac7ddfbfSEd Maste ConstString const_triple(triple.c_str()); 77ac7ddfbfSEd Maste return const_triple.GetCString(); 78ac7ddfbfSEd Maste } 79ac7ddfbfSEd Maste SetTriple(const char * triple)80435933ddSDimitry Andricvoid SBModuleSpec::SetTriple(const char *triple) { 81ac7ddfbfSEd Maste m_opaque_ap->GetArchitecture().SetTriple(triple); 82ac7ddfbfSEd Maste } 83ac7ddfbfSEd Maste GetUUIDBytes()84435933ddSDimitry Andricconst uint8_t *SBModuleSpec::GetUUIDBytes() { 854ba319b5SDimitry Andric return m_opaque_ap->GetUUID().GetBytes().data(); 86ac7ddfbfSEd Maste } 87ac7ddfbfSEd Maste GetUUIDLength()88435933ddSDimitry Andricsize_t SBModuleSpec::GetUUIDLength() { 894ba319b5SDimitry Andric return m_opaque_ap->GetUUID().GetBytes().size(); 90ac7ddfbfSEd Maste } 91ac7ddfbfSEd Maste SetUUIDBytes(const uint8_t * uuid,size_t uuid_len)92435933ddSDimitry Andricbool SBModuleSpec::SetUUIDBytes(const uint8_t *uuid, size_t uuid_len) { 934ba319b5SDimitry Andric m_opaque_ap->GetUUID() = UUID::fromOptionalData(uuid, uuid_len); 944ba319b5SDimitry Andric return m_opaque_ap->GetUUID().IsValid(); 95ac7ddfbfSEd Maste } 96ac7ddfbfSEd Maste GetDescription(lldb::SBStream & description)97435933ddSDimitry Andricbool SBModuleSpec::GetDescription(lldb::SBStream &description) { 98ac7ddfbfSEd Maste m_opaque_ap->Dump(description.ref()); 99ac7ddfbfSEd Maste return true; 100ac7ddfbfSEd Maste } 101ac7ddfbfSEd Maste SBModuleSpecList()102435933ddSDimitry AndricSBModuleSpecList::SBModuleSpecList() : m_opaque_ap(new ModuleSpecList()) {} 103ac7ddfbfSEd Maste SBModuleSpecList(const SBModuleSpecList & rhs)104435933ddSDimitry AndricSBModuleSpecList::SBModuleSpecList(const SBModuleSpecList &rhs) 105435933ddSDimitry Andric : m_opaque_ap(new ModuleSpecList(*rhs.m_opaque_ap)) {} 106ac7ddfbfSEd Maste operator =(const SBModuleSpecList & rhs)107435933ddSDimitry AndricSBModuleSpecList &SBModuleSpecList::operator=(const SBModuleSpecList &rhs) { 108ac7ddfbfSEd Maste if (this != &rhs) 109ac7ddfbfSEd Maste *m_opaque_ap = *rhs.m_opaque_ap; 110ac7ddfbfSEd Maste return *this; 111ac7ddfbfSEd Maste } 112ac7ddfbfSEd Maste ~SBModuleSpecList()113435933ddSDimitry AndricSBModuleSpecList::~SBModuleSpecList() {} 114ac7ddfbfSEd Maste GetModuleSpecifications(const char * path)115435933ddSDimitry AndricSBModuleSpecList SBModuleSpecList::GetModuleSpecifications(const char *path) { 116ac7ddfbfSEd Maste SBModuleSpecList specs; 117*b5893f02SDimitry Andric FileSpec file_spec(path); 118*b5893f02SDimitry Andric FileSystem::Instance().Resolve(file_spec); 119ac7ddfbfSEd Maste Host::ResolveExecutableInBundle(file_spec); 120ac7ddfbfSEd Maste ObjectFile::GetModuleSpecifications(file_spec, 0, 0, *specs.m_opaque_ap); 121ac7ddfbfSEd Maste return specs; 122ac7ddfbfSEd Maste } 123ac7ddfbfSEd Maste Append(const SBModuleSpec & spec)124435933ddSDimitry Andricvoid SBModuleSpecList::Append(const SBModuleSpec &spec) { 125ac7ddfbfSEd Maste m_opaque_ap->Append(*spec.m_opaque_ap); 126ac7ddfbfSEd Maste } 127ac7ddfbfSEd Maste Append(const SBModuleSpecList & spec_list)128435933ddSDimitry Andricvoid SBModuleSpecList::Append(const SBModuleSpecList &spec_list) { 129ac7ddfbfSEd Maste m_opaque_ap->Append(*spec_list.m_opaque_ap); 130ac7ddfbfSEd Maste } 131ac7ddfbfSEd Maste GetSize()132435933ddSDimitry Andricsize_t SBModuleSpecList::GetSize() { return m_opaque_ap->GetSize(); } 133ac7ddfbfSEd Maste GetSpecAtIndex(size_t i)134435933ddSDimitry AndricSBModuleSpec SBModuleSpecList::GetSpecAtIndex(size_t i) { 135ac7ddfbfSEd Maste SBModuleSpec sb_module_spec; 136ac7ddfbfSEd Maste m_opaque_ap->GetModuleSpecAtIndex(i, *sb_module_spec.m_opaque_ap); 137ac7ddfbfSEd Maste return sb_module_spec; 138ac7ddfbfSEd Maste } 139ac7ddfbfSEd Maste 140ac7ddfbfSEd Maste SBModuleSpec FindFirstMatchingSpec(const SBModuleSpec & match_spec)141435933ddSDimitry AndricSBModuleSpecList::FindFirstMatchingSpec(const SBModuleSpec &match_spec) { 142ac7ddfbfSEd Maste SBModuleSpec sb_module_spec; 143435933ddSDimitry Andric m_opaque_ap->FindMatchingModuleSpec(*match_spec.m_opaque_ap, 144435933ddSDimitry Andric *sb_module_spec.m_opaque_ap); 145ac7ddfbfSEd Maste return sb_module_spec; 146ac7ddfbfSEd Maste } 147ac7ddfbfSEd Maste 148ac7ddfbfSEd Maste SBModuleSpecList FindMatchingSpecs(const SBModuleSpec & match_spec)149435933ddSDimitry AndricSBModuleSpecList::FindMatchingSpecs(const SBModuleSpec &match_spec) { 150ac7ddfbfSEd Maste SBModuleSpecList specs; 151435933ddSDimitry Andric m_opaque_ap->FindMatchingModuleSpecs(*match_spec.m_opaque_ap, 152435933ddSDimitry Andric *specs.m_opaque_ap); 153ac7ddfbfSEd Maste return specs; 154ac7ddfbfSEd Maste } 155ac7ddfbfSEd Maste GetDescription(lldb::SBStream & description)156435933ddSDimitry Andricbool SBModuleSpecList::GetDescription(lldb::SBStream &description) { 157ac7ddfbfSEd Maste m_opaque_ap->Dump(description.ref()); 158ac7ddfbfSEd Maste return true; 159ac7ddfbfSEd Maste } 160