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/Core/Stream.h" 15ac7ddfbfSEd Maste #include "lldb/Host/Host.h" 16ac7ddfbfSEd Maste #include "lldb/Symbol/ObjectFile.h" 17ac7ddfbfSEd Maste 18ac7ddfbfSEd Maste using namespace lldb; 19ac7ddfbfSEd Maste using namespace lldb_private; 20ac7ddfbfSEd Maste 21ac7ddfbfSEd Maste 22ac7ddfbfSEd Maste SBModuleSpec::SBModuleSpec () : 23ac7ddfbfSEd Maste m_opaque_ap (new lldb_private::ModuleSpec()) 24ac7ddfbfSEd Maste { 25ac7ddfbfSEd Maste } 26ac7ddfbfSEd Maste 27ac7ddfbfSEd Maste SBModuleSpec::SBModuleSpec(const SBModuleSpec &rhs) : 28ac7ddfbfSEd Maste m_opaque_ap (new lldb_private::ModuleSpec(*rhs.m_opaque_ap)) 29ac7ddfbfSEd Maste { 30ac7ddfbfSEd Maste } 31ac7ddfbfSEd Maste 32ac7ddfbfSEd Maste const SBModuleSpec & 33ac7ddfbfSEd Maste SBModuleSpec::operator = (const SBModuleSpec &rhs) 34ac7ddfbfSEd Maste { 35ac7ddfbfSEd Maste if (this != &rhs) 36ac7ddfbfSEd Maste *m_opaque_ap = *(rhs.m_opaque_ap); 37ac7ddfbfSEd Maste return *this; 38ac7ddfbfSEd Maste } 39ac7ddfbfSEd Maste 40ac7ddfbfSEd Maste SBModuleSpec::~SBModuleSpec () 41ac7ddfbfSEd Maste { 42ac7ddfbfSEd Maste } 43ac7ddfbfSEd Maste 44ac7ddfbfSEd Maste bool 45ac7ddfbfSEd Maste SBModuleSpec::IsValid () const 46ac7ddfbfSEd Maste { 47ac7ddfbfSEd Maste return *m_opaque_ap; 48ac7ddfbfSEd Maste } 49ac7ddfbfSEd Maste 50ac7ddfbfSEd Maste void 51ac7ddfbfSEd Maste SBModuleSpec::Clear() 52ac7ddfbfSEd Maste { 53ac7ddfbfSEd Maste m_opaque_ap->Clear(); 54ac7ddfbfSEd Maste } 55ac7ddfbfSEd Maste 56ac7ddfbfSEd Maste SBFileSpec 57ac7ddfbfSEd Maste SBModuleSpec::GetFileSpec () 58ac7ddfbfSEd Maste { 59ac7ddfbfSEd Maste SBFileSpec sb_spec(m_opaque_ap->GetFileSpec()); 60ac7ddfbfSEd Maste return sb_spec; 61ac7ddfbfSEd Maste } 62ac7ddfbfSEd Maste 63ac7ddfbfSEd Maste void 64ac7ddfbfSEd Maste SBModuleSpec::SetFileSpec (const lldb::SBFileSpec &sb_spec) 65ac7ddfbfSEd Maste { 66ac7ddfbfSEd Maste m_opaque_ap->GetFileSpec() = *sb_spec; 67ac7ddfbfSEd Maste } 68ac7ddfbfSEd Maste 69ac7ddfbfSEd Maste lldb::SBFileSpec 70ac7ddfbfSEd Maste SBModuleSpec::GetPlatformFileSpec () 71ac7ddfbfSEd Maste { 72ac7ddfbfSEd Maste return SBFileSpec(m_opaque_ap->GetPlatformFileSpec()); 73ac7ddfbfSEd Maste } 74ac7ddfbfSEd Maste 75ac7ddfbfSEd Maste void 76ac7ddfbfSEd Maste SBModuleSpec::SetPlatformFileSpec (const lldb::SBFileSpec &sb_spec) 77ac7ddfbfSEd Maste { 78ac7ddfbfSEd Maste m_opaque_ap->GetPlatformFileSpec() = *sb_spec; 79ac7ddfbfSEd Maste } 80ac7ddfbfSEd Maste 81ac7ddfbfSEd Maste lldb::SBFileSpec 82ac7ddfbfSEd Maste SBModuleSpec::GetSymbolFileSpec () 83ac7ddfbfSEd Maste { 84ac7ddfbfSEd Maste return SBFileSpec(m_opaque_ap->GetSymbolFileSpec()); 85ac7ddfbfSEd Maste } 86ac7ddfbfSEd Maste 87ac7ddfbfSEd Maste void 88ac7ddfbfSEd Maste SBModuleSpec::SetSymbolFileSpec (const lldb::SBFileSpec &sb_spec) 89ac7ddfbfSEd Maste { 90ac7ddfbfSEd Maste m_opaque_ap->GetSymbolFileSpec() = *sb_spec; 91ac7ddfbfSEd Maste } 92ac7ddfbfSEd Maste 93ac7ddfbfSEd Maste const char * 94ac7ddfbfSEd Maste SBModuleSpec::GetObjectName () 95ac7ddfbfSEd Maste { 96ac7ddfbfSEd Maste return m_opaque_ap->GetObjectName().GetCString(); 97ac7ddfbfSEd Maste } 98ac7ddfbfSEd Maste 99ac7ddfbfSEd Maste void 100ac7ddfbfSEd Maste SBModuleSpec::SetObjectName (const char *name) 101ac7ddfbfSEd Maste { 102ac7ddfbfSEd Maste m_opaque_ap->GetObjectName().SetCString(name); 103ac7ddfbfSEd Maste } 104ac7ddfbfSEd Maste 105ac7ddfbfSEd Maste const char * 106ac7ddfbfSEd Maste SBModuleSpec::GetTriple () 107ac7ddfbfSEd Maste { 108ac7ddfbfSEd Maste std::string triple (m_opaque_ap->GetArchitecture().GetTriple().str()); 109ac7ddfbfSEd Maste // Unique the string so we don't run into ownership issues since 110ac7ddfbfSEd Maste // the const strings put the string into the string pool once and 111ac7ddfbfSEd Maste // the strings never comes out 112ac7ddfbfSEd Maste ConstString const_triple (triple.c_str()); 113ac7ddfbfSEd Maste return const_triple.GetCString(); 114ac7ddfbfSEd Maste } 115ac7ddfbfSEd Maste 116ac7ddfbfSEd Maste void 117ac7ddfbfSEd Maste SBModuleSpec::SetTriple (const char *triple) 118ac7ddfbfSEd Maste { 119ac7ddfbfSEd Maste m_opaque_ap->GetArchitecture().SetTriple(triple); 120ac7ddfbfSEd Maste } 121ac7ddfbfSEd Maste 122ac7ddfbfSEd Maste const uint8_t * 123ac7ddfbfSEd Maste SBModuleSpec::GetUUIDBytes () 124ac7ddfbfSEd Maste { 125ac7ddfbfSEd Maste return (const uint8_t *)m_opaque_ap->GetUUID().GetBytes(); 126ac7ddfbfSEd Maste } 127ac7ddfbfSEd Maste 128ac7ddfbfSEd Maste size_t 129ac7ddfbfSEd Maste SBModuleSpec::GetUUIDLength () 130ac7ddfbfSEd Maste { 131ac7ddfbfSEd Maste return m_opaque_ap->GetUUID().GetByteSize(); 132ac7ddfbfSEd Maste } 133ac7ddfbfSEd Maste 134ac7ddfbfSEd Maste bool 135ac7ddfbfSEd Maste SBModuleSpec::SetUUIDBytes (const uint8_t *uuid, size_t uuid_len) 136ac7ddfbfSEd Maste { 137ac7ddfbfSEd Maste return m_opaque_ap->GetUUID().SetBytes(uuid, uuid_len); 138ac7ddfbfSEd Maste } 139ac7ddfbfSEd Maste 140ac7ddfbfSEd Maste bool 141ac7ddfbfSEd Maste SBModuleSpec::GetDescription (lldb::SBStream &description) 142ac7ddfbfSEd Maste { 143ac7ddfbfSEd Maste m_opaque_ap->Dump (description.ref()); 144ac7ddfbfSEd Maste return true; 145ac7ddfbfSEd Maste } 146ac7ddfbfSEd Maste 147ac7ddfbfSEd Maste SBModuleSpecList::SBModuleSpecList() : 148ac7ddfbfSEd Maste m_opaque_ap(new ModuleSpecList()) 149ac7ddfbfSEd Maste { 150ac7ddfbfSEd Maste 151ac7ddfbfSEd Maste } 152ac7ddfbfSEd Maste 153ac7ddfbfSEd Maste SBModuleSpecList::SBModuleSpecList (const SBModuleSpecList &rhs) : 154ac7ddfbfSEd Maste m_opaque_ap(new ModuleSpecList(*rhs.m_opaque_ap)) 155ac7ddfbfSEd Maste { 156ac7ddfbfSEd Maste 157ac7ddfbfSEd Maste } 158ac7ddfbfSEd Maste 159ac7ddfbfSEd Maste SBModuleSpecList & 160ac7ddfbfSEd Maste SBModuleSpecList::operator = (const SBModuleSpecList &rhs) 161ac7ddfbfSEd Maste { 162ac7ddfbfSEd Maste if (this != &rhs) 163ac7ddfbfSEd Maste *m_opaque_ap = *rhs.m_opaque_ap; 164ac7ddfbfSEd Maste return *this; 165ac7ddfbfSEd Maste } 166ac7ddfbfSEd Maste 167ac7ddfbfSEd Maste SBModuleSpecList::~SBModuleSpecList() 168ac7ddfbfSEd Maste { 169ac7ddfbfSEd Maste 170ac7ddfbfSEd Maste } 171ac7ddfbfSEd Maste 172ac7ddfbfSEd Maste SBModuleSpecList 173ac7ddfbfSEd Maste SBModuleSpecList::GetModuleSpecifications (const char *path) 174ac7ddfbfSEd Maste { 175ac7ddfbfSEd Maste SBModuleSpecList specs; 176ac7ddfbfSEd Maste FileSpec file_spec(path, true); 177ac7ddfbfSEd Maste Host::ResolveExecutableInBundle(file_spec); 178ac7ddfbfSEd Maste ObjectFile::GetModuleSpecifications(file_spec, 0, 0, *specs.m_opaque_ap); 179ac7ddfbfSEd Maste return specs; 180ac7ddfbfSEd Maste } 181ac7ddfbfSEd Maste 182ac7ddfbfSEd Maste void 183ac7ddfbfSEd Maste SBModuleSpecList::Append (const SBModuleSpec &spec) 184ac7ddfbfSEd Maste { 185ac7ddfbfSEd Maste m_opaque_ap->Append (*spec.m_opaque_ap); 186ac7ddfbfSEd Maste } 187ac7ddfbfSEd Maste 188ac7ddfbfSEd Maste void 189ac7ddfbfSEd Maste SBModuleSpecList::Append (const SBModuleSpecList &spec_list) 190ac7ddfbfSEd Maste { 191ac7ddfbfSEd Maste m_opaque_ap->Append (*spec_list.m_opaque_ap); 192ac7ddfbfSEd Maste } 193ac7ddfbfSEd Maste 194ac7ddfbfSEd Maste size_t 195ac7ddfbfSEd Maste SBModuleSpecList::GetSize() 196ac7ddfbfSEd Maste { 197ac7ddfbfSEd Maste return m_opaque_ap->GetSize(); 198ac7ddfbfSEd Maste } 199ac7ddfbfSEd Maste 200ac7ddfbfSEd Maste SBModuleSpec 201ac7ddfbfSEd Maste SBModuleSpecList::GetSpecAtIndex (size_t i) 202ac7ddfbfSEd Maste { 203ac7ddfbfSEd Maste SBModuleSpec sb_module_spec; 204ac7ddfbfSEd Maste m_opaque_ap->GetModuleSpecAtIndex(i, *sb_module_spec.m_opaque_ap); 205ac7ddfbfSEd Maste return sb_module_spec; 206ac7ddfbfSEd Maste } 207ac7ddfbfSEd Maste 208ac7ddfbfSEd Maste SBModuleSpec 209ac7ddfbfSEd Maste SBModuleSpecList::FindFirstMatchingSpec (const SBModuleSpec &match_spec) 210ac7ddfbfSEd Maste { 211ac7ddfbfSEd Maste SBModuleSpec sb_module_spec; 212ac7ddfbfSEd Maste m_opaque_ap->FindMatchingModuleSpec(*match_spec.m_opaque_ap, *sb_module_spec.m_opaque_ap); 213ac7ddfbfSEd Maste return sb_module_spec; 214ac7ddfbfSEd Maste } 215ac7ddfbfSEd Maste 216ac7ddfbfSEd Maste SBModuleSpecList 217ac7ddfbfSEd Maste SBModuleSpecList::FindMatchingSpecs (const SBModuleSpec &match_spec) 218ac7ddfbfSEd Maste { 219ac7ddfbfSEd Maste SBModuleSpecList specs; 220ac7ddfbfSEd Maste m_opaque_ap->FindMatchingModuleSpecs(*match_spec.m_opaque_ap, *specs.m_opaque_ap); 221ac7ddfbfSEd Maste return specs; 222ac7ddfbfSEd Maste 223ac7ddfbfSEd Maste } 224ac7ddfbfSEd Maste 225ac7ddfbfSEd Maste bool 226ac7ddfbfSEd Maste SBModuleSpecList::GetDescription (lldb::SBStream &description) 227ac7ddfbfSEd Maste { 228ac7ddfbfSEd Maste m_opaque_ap->Dump (description.ref()); 229ac7ddfbfSEd Maste return true; 230ac7ddfbfSEd Maste } 231