1 //===-- SBModuleSpec.cpp ----------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "lldb/API/SBModuleSpec.h" 11 #include "lldb/API/SBStream.h" 12 #include "lldb/Core/Module.h" 13 #include "lldb/Core/ModuleSpec.h" 14 #include "lldb/Host/Host.h" 15 #include "lldb/Symbol/ObjectFile.h" 16 #include "lldb/Utility/Stream.h" 17 18 using namespace lldb; 19 using namespace lldb_private; 20 SBModuleSpec()21SBModuleSpec::SBModuleSpec() : m_opaque_ap(new lldb_private::ModuleSpec()) {} 22 SBModuleSpec(const SBModuleSpec & rhs)23SBModuleSpec::SBModuleSpec(const SBModuleSpec &rhs) 24 : m_opaque_ap(new lldb_private::ModuleSpec(*rhs.m_opaque_ap)) {} 25 operator =(const SBModuleSpec & rhs)26const SBModuleSpec &SBModuleSpec::operator=(const SBModuleSpec &rhs) { 27 if (this != &rhs) 28 *m_opaque_ap = *(rhs.m_opaque_ap); 29 return *this; 30 } 31 ~SBModuleSpec()32SBModuleSpec::~SBModuleSpec() {} 33 IsValid() const34bool SBModuleSpec::IsValid() const { return m_opaque_ap->operator bool(); } 35 Clear()36void SBModuleSpec::Clear() { m_opaque_ap->Clear(); } 37 GetFileSpec()38SBFileSpec SBModuleSpec::GetFileSpec() { 39 SBFileSpec sb_spec(m_opaque_ap->GetFileSpec()); 40 return sb_spec; 41 } 42 SetFileSpec(const lldb::SBFileSpec & sb_spec)43void SBModuleSpec::SetFileSpec(const lldb::SBFileSpec &sb_spec) { 44 m_opaque_ap->GetFileSpec() = *sb_spec; 45 } 46 GetPlatformFileSpec()47lldb::SBFileSpec SBModuleSpec::GetPlatformFileSpec() { 48 return SBFileSpec(m_opaque_ap->GetPlatformFileSpec()); 49 } 50 SetPlatformFileSpec(const lldb::SBFileSpec & sb_spec)51void SBModuleSpec::SetPlatformFileSpec(const lldb::SBFileSpec &sb_spec) { 52 m_opaque_ap->GetPlatformFileSpec() = *sb_spec; 53 } 54 GetSymbolFileSpec()55lldb::SBFileSpec SBModuleSpec::GetSymbolFileSpec() { 56 return SBFileSpec(m_opaque_ap->GetSymbolFileSpec()); 57 } 58 SetSymbolFileSpec(const lldb::SBFileSpec & sb_spec)59void SBModuleSpec::SetSymbolFileSpec(const lldb::SBFileSpec &sb_spec) { 60 m_opaque_ap->GetSymbolFileSpec() = *sb_spec; 61 } 62 GetObjectName()63const char *SBModuleSpec::GetObjectName() { 64 return m_opaque_ap->GetObjectName().GetCString(); 65 } 66 SetObjectName(const char * name)67void SBModuleSpec::SetObjectName(const char *name) { 68 m_opaque_ap->GetObjectName().SetCString(name); 69 } 70 GetTriple()71const char *SBModuleSpec::GetTriple() { 72 std::string triple(m_opaque_ap->GetArchitecture().GetTriple().str()); 73 // Unique the string so we don't run into ownership issues since the const 74 // strings put the string into the string pool once and the strings never 75 // comes out 76 ConstString const_triple(triple.c_str()); 77 return const_triple.GetCString(); 78 } 79 SetTriple(const char * triple)80void SBModuleSpec::SetTriple(const char *triple) { 81 m_opaque_ap->GetArchitecture().SetTriple(triple); 82 } 83 GetUUIDBytes()84const uint8_t *SBModuleSpec::GetUUIDBytes() { 85 return m_opaque_ap->GetUUID().GetBytes().data(); 86 } 87 GetUUIDLength()88size_t SBModuleSpec::GetUUIDLength() { 89 return m_opaque_ap->GetUUID().GetBytes().size(); 90 } 91 SetUUIDBytes(const uint8_t * uuid,size_t uuid_len)92bool SBModuleSpec::SetUUIDBytes(const uint8_t *uuid, size_t uuid_len) { 93 m_opaque_ap->GetUUID() = UUID::fromOptionalData(uuid, uuid_len); 94 return m_opaque_ap->GetUUID().IsValid(); 95 } 96 GetDescription(lldb::SBStream & description)97bool SBModuleSpec::GetDescription(lldb::SBStream &description) { 98 m_opaque_ap->Dump(description.ref()); 99 return true; 100 } 101 SBModuleSpecList()102SBModuleSpecList::SBModuleSpecList() : m_opaque_ap(new ModuleSpecList()) {} 103 SBModuleSpecList(const SBModuleSpecList & rhs)104SBModuleSpecList::SBModuleSpecList(const SBModuleSpecList &rhs) 105 : m_opaque_ap(new ModuleSpecList(*rhs.m_opaque_ap)) {} 106 operator =(const SBModuleSpecList & rhs)107SBModuleSpecList &SBModuleSpecList::operator=(const SBModuleSpecList &rhs) { 108 if (this != &rhs) 109 *m_opaque_ap = *rhs.m_opaque_ap; 110 return *this; 111 } 112 ~SBModuleSpecList()113SBModuleSpecList::~SBModuleSpecList() {} 114 GetModuleSpecifications(const char * path)115SBModuleSpecList SBModuleSpecList::GetModuleSpecifications(const char *path) { 116 SBModuleSpecList specs; 117 FileSpec file_spec(path); 118 FileSystem::Instance().Resolve(file_spec); 119 Host::ResolveExecutableInBundle(file_spec); 120 ObjectFile::GetModuleSpecifications(file_spec, 0, 0, *specs.m_opaque_ap); 121 return specs; 122 } 123 Append(const SBModuleSpec & spec)124void SBModuleSpecList::Append(const SBModuleSpec &spec) { 125 m_opaque_ap->Append(*spec.m_opaque_ap); 126 } 127 Append(const SBModuleSpecList & spec_list)128void SBModuleSpecList::Append(const SBModuleSpecList &spec_list) { 129 m_opaque_ap->Append(*spec_list.m_opaque_ap); 130 } 131 GetSize()132size_t SBModuleSpecList::GetSize() { return m_opaque_ap->GetSize(); } 133 GetSpecAtIndex(size_t i)134SBModuleSpec SBModuleSpecList::GetSpecAtIndex(size_t i) { 135 SBModuleSpec sb_module_spec; 136 m_opaque_ap->GetModuleSpecAtIndex(i, *sb_module_spec.m_opaque_ap); 137 return sb_module_spec; 138 } 139 140 SBModuleSpec FindFirstMatchingSpec(const SBModuleSpec & match_spec)141SBModuleSpecList::FindFirstMatchingSpec(const SBModuleSpec &match_spec) { 142 SBModuleSpec sb_module_spec; 143 m_opaque_ap->FindMatchingModuleSpec(*match_spec.m_opaque_ap, 144 *sb_module_spec.m_opaque_ap); 145 return sb_module_spec; 146 } 147 148 SBModuleSpecList FindMatchingSpecs(const SBModuleSpec & match_spec)149SBModuleSpecList::FindMatchingSpecs(const SBModuleSpec &match_spec) { 150 SBModuleSpecList specs; 151 m_opaque_ap->FindMatchingModuleSpecs(*match_spec.m_opaque_ap, 152 *specs.m_opaque_ap); 153 return specs; 154 } 155 GetDescription(lldb::SBStream & description)156bool SBModuleSpecList::GetDescription(lldb::SBStream &description) { 157 m_opaque_ap->Dump(description.ref()); 158 return true; 159 } 160