1226cce25SGreg Clayton //===-- SBModuleSpec.cpp ----------------------------------------*- C++ -*-===// 2226cce25SGreg Clayton // 3226cce25SGreg Clayton // The LLVM Compiler Infrastructure 4226cce25SGreg Clayton // 5226cce25SGreg Clayton // This file is distributed under the University of Illinois Open Source 6226cce25SGreg Clayton // License. See LICENSE.TXT for details. 7226cce25SGreg Clayton // 8226cce25SGreg Clayton //===----------------------------------------------------------------------===// 9226cce25SGreg Clayton 10226cce25SGreg Clayton #include "lldb/API/SBModuleSpec.h" 11226cce25SGreg Clayton #include "lldb/API/SBStream.h" 12226cce25SGreg Clayton #include "lldb/Core/Module.h" 13226cce25SGreg Clayton #include "lldb/Core/ModuleSpec.h" 14226cce25SGreg Clayton #include "lldb/Core/Stream.h" 15226cce25SGreg Clayton #include "lldb/Host/Host.h" 16226cce25SGreg Clayton #include "lldb/Symbol/ObjectFile.h" 17226cce25SGreg Clayton 18226cce25SGreg Clayton using namespace lldb; 19226cce25SGreg Clayton using namespace lldb_private; 20226cce25SGreg Clayton 21226cce25SGreg Clayton 22226cce25SGreg Clayton SBModuleSpec::SBModuleSpec () : 23226cce25SGreg Clayton m_opaque_ap (new lldb_private::ModuleSpec()) 24226cce25SGreg Clayton { 25226cce25SGreg Clayton } 26226cce25SGreg Clayton 27226cce25SGreg Clayton SBModuleSpec::SBModuleSpec(const SBModuleSpec &rhs) : 28226cce25SGreg Clayton m_opaque_ap (new lldb_private::ModuleSpec(*rhs.m_opaque_ap)) 29226cce25SGreg Clayton { 30226cce25SGreg Clayton } 31226cce25SGreg Clayton 32226cce25SGreg Clayton const SBModuleSpec & 33226cce25SGreg Clayton SBModuleSpec::operator = (const SBModuleSpec &rhs) 34226cce25SGreg Clayton { 35226cce25SGreg Clayton if (this != &rhs) 36226cce25SGreg Clayton *m_opaque_ap = *(rhs.m_opaque_ap); 37226cce25SGreg Clayton return *this; 38226cce25SGreg Clayton } 39226cce25SGreg Clayton 40226cce25SGreg Clayton SBModuleSpec::~SBModuleSpec () 41226cce25SGreg Clayton { 42226cce25SGreg Clayton } 43226cce25SGreg Clayton 44226cce25SGreg Clayton bool 45226cce25SGreg Clayton SBModuleSpec::IsValid () const 46226cce25SGreg Clayton { 47226cce25SGreg Clayton return *m_opaque_ap; 48226cce25SGreg Clayton } 49226cce25SGreg Clayton 50226cce25SGreg Clayton void 51226cce25SGreg Clayton SBModuleSpec::Clear() 52226cce25SGreg Clayton { 53226cce25SGreg Clayton m_opaque_ap->Clear(); 54226cce25SGreg Clayton } 55226cce25SGreg Clayton 56226cce25SGreg Clayton SBFileSpec 57226cce25SGreg Clayton SBModuleSpec::GetFileSpec () 58226cce25SGreg Clayton { 59226cce25SGreg Clayton SBFileSpec sb_spec(m_opaque_ap->GetFileSpec()); 60226cce25SGreg Clayton return sb_spec; 61226cce25SGreg Clayton } 62226cce25SGreg Clayton 63226cce25SGreg Clayton void 64226cce25SGreg Clayton SBModuleSpec::SetFileSpec (const lldb::SBFileSpec &sb_spec) 65226cce25SGreg Clayton { 66226cce25SGreg Clayton m_opaque_ap->GetFileSpec() = *sb_spec; 67226cce25SGreg Clayton } 68226cce25SGreg Clayton 69226cce25SGreg Clayton lldb::SBFileSpec 70226cce25SGreg Clayton SBModuleSpec::GetPlatformFileSpec () 71226cce25SGreg Clayton { 72226cce25SGreg Clayton return SBFileSpec(m_opaque_ap->GetPlatformFileSpec()); 73226cce25SGreg Clayton } 74226cce25SGreg Clayton 75226cce25SGreg Clayton void 76226cce25SGreg Clayton SBModuleSpec::SetPlatformFileSpec (const lldb::SBFileSpec &sb_spec) 77226cce25SGreg Clayton { 78226cce25SGreg Clayton m_opaque_ap->GetPlatformFileSpec() = *sb_spec; 79226cce25SGreg Clayton } 80226cce25SGreg Clayton 81226cce25SGreg Clayton lldb::SBFileSpec 82226cce25SGreg Clayton SBModuleSpec::GetSymbolFileSpec () 83226cce25SGreg Clayton { 84226cce25SGreg Clayton return SBFileSpec(m_opaque_ap->GetSymbolFileSpec()); 85226cce25SGreg Clayton } 86226cce25SGreg Clayton 87226cce25SGreg Clayton void 88226cce25SGreg Clayton SBModuleSpec::SetSymbolFileSpec (const lldb::SBFileSpec &sb_spec) 89226cce25SGreg Clayton { 90226cce25SGreg Clayton m_opaque_ap->GetSymbolFileSpec() = *sb_spec; 91226cce25SGreg Clayton } 92226cce25SGreg Clayton 93226cce25SGreg Clayton const char * 94226cce25SGreg Clayton SBModuleSpec::GetObjectName () 95226cce25SGreg Clayton { 96226cce25SGreg Clayton return m_opaque_ap->GetObjectName().GetCString(); 97226cce25SGreg Clayton } 98226cce25SGreg Clayton 99226cce25SGreg Clayton void 100226cce25SGreg Clayton SBModuleSpec::SetObjectName (const char *name) 101226cce25SGreg Clayton { 102226cce25SGreg Clayton m_opaque_ap->GetObjectName().SetCString(name); 103226cce25SGreg Clayton } 104226cce25SGreg Clayton 105226cce25SGreg Clayton const char * 106226cce25SGreg Clayton SBModuleSpec::GetTriple () 107226cce25SGreg Clayton { 108226cce25SGreg Clayton std::string triple (m_opaque_ap->GetArchitecture().GetTriple().str()); 109226cce25SGreg Clayton // Unique the string so we don't run into ownership issues since 110226cce25SGreg Clayton // the const strings put the string into the string pool once and 111226cce25SGreg Clayton // the strings never comes out 112226cce25SGreg Clayton ConstString const_triple (triple.c_str()); 113226cce25SGreg Clayton return const_triple.GetCString(); 114226cce25SGreg Clayton } 115226cce25SGreg Clayton 116226cce25SGreg Clayton void 117226cce25SGreg Clayton SBModuleSpec::SetTriple (const char *triple) 118226cce25SGreg Clayton { 119226cce25SGreg Clayton m_opaque_ap->GetArchitecture().SetTriple(triple); 120226cce25SGreg Clayton } 121226cce25SGreg Clayton 122226cce25SGreg Clayton const uint8_t * 123226cce25SGreg Clayton SBModuleSpec::GetUUIDBytes () 124226cce25SGreg Clayton { 125226cce25SGreg Clayton return (const uint8_t *)m_opaque_ap->GetUUID().GetBytes(); 126226cce25SGreg Clayton } 127226cce25SGreg Clayton 128226cce25SGreg Clayton size_t 129226cce25SGreg Clayton SBModuleSpec::GetUUIDLength () 130226cce25SGreg Clayton { 131226cce25SGreg Clayton return m_opaque_ap->GetUUID().GetByteSize(); 132226cce25SGreg Clayton } 133226cce25SGreg Clayton 134226cce25SGreg Clayton bool 135226cce25SGreg Clayton SBModuleSpec::SetUUIDBytes (const uint8_t *uuid, size_t uuid_len) 136226cce25SGreg Clayton { 137226cce25SGreg Clayton return m_opaque_ap->GetUUID().SetBytes(uuid, uuid_len); 138226cce25SGreg Clayton } 139226cce25SGreg Clayton 140226cce25SGreg Clayton bool 141226cce25SGreg Clayton SBModuleSpec::GetDescription (lldb::SBStream &description) 142226cce25SGreg Clayton { 143226cce25SGreg Clayton m_opaque_ap->Dump (description.ref()); 144226cce25SGreg Clayton return true; 145226cce25SGreg Clayton } 146226cce25SGreg Clayton 147226cce25SGreg Clayton SBModuleSpecList::SBModuleSpecList() : 148226cce25SGreg Clayton m_opaque_ap(new ModuleSpecList()) 149226cce25SGreg Clayton { 150226cce25SGreg Clayton 151226cce25SGreg Clayton } 152226cce25SGreg Clayton 153226cce25SGreg Clayton SBModuleSpecList::SBModuleSpecList (const SBModuleSpecList &rhs) : 154226cce25SGreg Clayton m_opaque_ap(new ModuleSpecList(*rhs.m_opaque_ap)) 155226cce25SGreg Clayton { 156226cce25SGreg Clayton 157226cce25SGreg Clayton } 158226cce25SGreg Clayton 159226cce25SGreg Clayton SBModuleSpecList & 160226cce25SGreg Clayton SBModuleSpecList::operator = (const SBModuleSpecList &rhs) 161226cce25SGreg Clayton { 162226cce25SGreg Clayton if (this != &rhs) 163226cce25SGreg Clayton *m_opaque_ap = *rhs.m_opaque_ap; 164226cce25SGreg Clayton return *this; 165226cce25SGreg Clayton } 166226cce25SGreg Clayton 167226cce25SGreg Clayton SBModuleSpecList::~SBModuleSpecList() 168226cce25SGreg Clayton { 169226cce25SGreg Clayton 170226cce25SGreg Clayton } 171226cce25SGreg Clayton 172226cce25SGreg Clayton SBModuleSpecList 173226cce25SGreg Clayton SBModuleSpecList::GetModuleSpecifications (const char *path) 174226cce25SGreg Clayton { 175226cce25SGreg Clayton SBModuleSpecList specs; 176226cce25SGreg Clayton FileSpec file_spec(path, true); 177226cce25SGreg Clayton Host::ResolveExecutableInBundle(file_spec); 178*2540a8a7SGreg Clayton ObjectFile::GetModuleSpecifications(file_spec, 0, 0, *specs.m_opaque_ap); 179226cce25SGreg Clayton return specs; 180226cce25SGreg Clayton } 181226cce25SGreg Clayton 182226cce25SGreg Clayton void 183226cce25SGreg Clayton SBModuleSpecList::Append (const SBModuleSpec &spec) 184226cce25SGreg Clayton { 185226cce25SGreg Clayton m_opaque_ap->Append (*spec.m_opaque_ap); 186226cce25SGreg Clayton } 187226cce25SGreg Clayton 188226cce25SGreg Clayton void 189226cce25SGreg Clayton SBModuleSpecList::Append (const SBModuleSpecList &spec_list) 190226cce25SGreg Clayton { 191226cce25SGreg Clayton m_opaque_ap->Append (*spec_list.m_opaque_ap); 192226cce25SGreg Clayton } 193226cce25SGreg Clayton 194226cce25SGreg Clayton size_t 195226cce25SGreg Clayton SBModuleSpecList::GetSize() 196226cce25SGreg Clayton { 197226cce25SGreg Clayton return m_opaque_ap->GetSize(); 198226cce25SGreg Clayton } 199226cce25SGreg Clayton 200226cce25SGreg Clayton SBModuleSpec 201226cce25SGreg Clayton SBModuleSpecList::GetSpecAtIndex (size_t i) 202226cce25SGreg Clayton { 203226cce25SGreg Clayton SBModuleSpec sb_module_spec; 204226cce25SGreg Clayton m_opaque_ap->GetModuleSpecAtIndex(i, *sb_module_spec.m_opaque_ap); 205226cce25SGreg Clayton return sb_module_spec; 206226cce25SGreg Clayton } 207226cce25SGreg Clayton 208226cce25SGreg Clayton SBModuleSpec 209226cce25SGreg Clayton SBModuleSpecList::FindFirstMatchingSpec (const SBModuleSpec &match_spec) 210226cce25SGreg Clayton { 211226cce25SGreg Clayton SBModuleSpec sb_module_spec; 212226cce25SGreg Clayton m_opaque_ap->FindMatchingModuleSpec(*match_spec.m_opaque_ap, *sb_module_spec.m_opaque_ap); 213226cce25SGreg Clayton return sb_module_spec; 214226cce25SGreg Clayton } 215226cce25SGreg Clayton 216226cce25SGreg Clayton SBModuleSpecList 217226cce25SGreg Clayton SBModuleSpecList::FindMatchingSpecs (const SBModuleSpec &match_spec) 218226cce25SGreg Clayton { 219226cce25SGreg Clayton SBModuleSpecList specs; 220226cce25SGreg Clayton m_opaque_ap->FindMatchingModuleSpecs(*match_spec.m_opaque_ap, *specs.m_opaque_ap); 221226cce25SGreg Clayton return specs; 222226cce25SGreg Clayton 223226cce25SGreg Clayton } 224226cce25SGreg Clayton 225226cce25SGreg Clayton bool 226226cce25SGreg Clayton SBModuleSpecList::GetDescription (lldb::SBStream &description) 227226cce25SGreg Clayton { 228226cce25SGreg Clayton m_opaque_ap->Dump (description.ref()); 229226cce25SGreg Clayton return true; 230226cce25SGreg Clayton } 231