Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 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" |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 14 | #include "lldb/Host/Host.h" |
| 15 | #include "lldb/Symbol/ObjectFile.h" |
Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 16 | #include "lldb/Utility/Stream.h" |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 17 | |
| 18 | using namespace lldb; |
| 19 | using namespace lldb_private; |
| 20 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 21 | SBModuleSpec::SBModuleSpec() : m_opaque_ap(new lldb_private::ModuleSpec()) {} |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 22 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 23 | SBModuleSpec::SBModuleSpec(const SBModuleSpec &rhs) |
| 24 | : m_opaque_ap(new lldb_private::ModuleSpec(*rhs.m_opaque_ap)) {} |
| 25 | |
| 26 | const SBModuleSpec &SBModuleSpec::operator=(const SBModuleSpec &rhs) { |
| 27 | if (this != &rhs) |
| 28 | *m_opaque_ap = *(rhs.m_opaque_ap); |
| 29 | return *this; |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 30 | } |
| 31 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 32 | SBModuleSpec::~SBModuleSpec() {} |
| 33 | |
| 34 | bool SBModuleSpec::IsValid() const { return m_opaque_ap->operator bool(); } |
| 35 | |
| 36 | void SBModuleSpec::Clear() { m_opaque_ap->Clear(); } |
| 37 | |
| 38 | SBFileSpec SBModuleSpec::GetFileSpec() { |
| 39 | SBFileSpec sb_spec(m_opaque_ap->GetFileSpec()); |
| 40 | return sb_spec; |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 41 | } |
| 42 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 43 | void SBModuleSpec::SetFileSpec(const lldb::SBFileSpec &sb_spec) { |
| 44 | m_opaque_ap->GetFileSpec() = *sb_spec; |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 45 | } |
| 46 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 47 | lldb::SBFileSpec SBModuleSpec::GetPlatformFileSpec() { |
| 48 | return SBFileSpec(m_opaque_ap->GetPlatformFileSpec()); |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 49 | } |
| 50 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 51 | void SBModuleSpec::SetPlatformFileSpec(const lldb::SBFileSpec &sb_spec) { |
| 52 | m_opaque_ap->GetPlatformFileSpec() = *sb_spec; |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 53 | } |
| 54 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 55 | lldb::SBFileSpec SBModuleSpec::GetSymbolFileSpec() { |
| 56 | return SBFileSpec(m_opaque_ap->GetSymbolFileSpec()); |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 57 | } |
| 58 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 59 | void SBModuleSpec::SetSymbolFileSpec(const lldb::SBFileSpec &sb_spec) { |
| 60 | m_opaque_ap->GetSymbolFileSpec() = *sb_spec; |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 63 | const char *SBModuleSpec::GetObjectName() { |
| 64 | return m_opaque_ap->GetObjectName().GetCString(); |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 65 | } |
| 66 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 67 | void SBModuleSpec::SetObjectName(const char *name) { |
| 68 | m_opaque_ap->GetObjectName().SetCString(name); |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 69 | } |
| 70 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 71 | const 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 |
| 74 | // the const strings put the string into the string pool once and |
| 75 | // the strings never comes out |
| 76 | ConstString const_triple(triple.c_str()); |
| 77 | return const_triple.GetCString(); |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 78 | } |
| 79 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 80 | void SBModuleSpec::SetTriple(const char *triple) { |
| 81 | m_opaque_ap->GetArchitecture().SetTriple(triple); |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 82 | } |
| 83 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 84 | const uint8_t *SBModuleSpec::GetUUIDBytes() { |
| 85 | return (const uint8_t *)m_opaque_ap->GetUUID().GetBytes(); |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 86 | } |
| 87 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 88 | size_t SBModuleSpec::GetUUIDLength() { |
| 89 | return m_opaque_ap->GetUUID().GetByteSize(); |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 90 | } |
| 91 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 92 | bool SBModuleSpec::SetUUIDBytes(const uint8_t *uuid, size_t uuid_len) { |
| 93 | return m_opaque_ap->GetUUID().SetBytes(uuid, uuid_len); |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 94 | } |
| 95 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 96 | bool SBModuleSpec::GetDescription(lldb::SBStream &description) { |
| 97 | m_opaque_ap->Dump(description.ref()); |
| 98 | return true; |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 99 | } |
| 100 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 101 | SBModuleSpecList::SBModuleSpecList() : m_opaque_ap(new ModuleSpecList()) {} |
| 102 | |
| 103 | SBModuleSpecList::SBModuleSpecList(const SBModuleSpecList &rhs) |
| 104 | : m_opaque_ap(new ModuleSpecList(*rhs.m_opaque_ap)) {} |
| 105 | |
| 106 | SBModuleSpecList &SBModuleSpecList::operator=(const SBModuleSpecList &rhs) { |
| 107 | if (this != &rhs) |
| 108 | *m_opaque_ap = *rhs.m_opaque_ap; |
| 109 | return *this; |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 110 | } |
| 111 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 112 | SBModuleSpecList::~SBModuleSpecList() {} |
| 113 | |
| 114 | SBModuleSpecList SBModuleSpecList::GetModuleSpecifications(const char *path) { |
| 115 | SBModuleSpecList specs; |
| 116 | FileSpec file_spec(path, true); |
| 117 | Host::ResolveExecutableInBundle(file_spec); |
| 118 | ObjectFile::GetModuleSpecifications(file_spec, 0, 0, *specs.m_opaque_ap); |
| 119 | return specs; |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 120 | } |
| 121 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 122 | void SBModuleSpecList::Append(const SBModuleSpec &spec) { |
| 123 | m_opaque_ap->Append(*spec.m_opaque_ap); |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 124 | } |
| 125 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 126 | void SBModuleSpecList::Append(const SBModuleSpecList &spec_list) { |
| 127 | m_opaque_ap->Append(*spec_list.m_opaque_ap); |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 128 | } |
| 129 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 130 | size_t SBModuleSpecList::GetSize() { return m_opaque_ap->GetSize(); } |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 131 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 132 | SBModuleSpec SBModuleSpecList::GetSpecAtIndex(size_t i) { |
| 133 | SBModuleSpec sb_module_spec; |
| 134 | m_opaque_ap->GetModuleSpecAtIndex(i, *sb_module_spec.m_opaque_ap); |
| 135 | return sb_module_spec; |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | SBModuleSpec |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 139 | SBModuleSpecList::FindFirstMatchingSpec(const SBModuleSpec &match_spec) { |
| 140 | SBModuleSpec sb_module_spec; |
| 141 | m_opaque_ap->FindMatchingModuleSpec(*match_spec.m_opaque_ap, |
| 142 | *sb_module_spec.m_opaque_ap); |
| 143 | return sb_module_spec; |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | SBModuleSpecList |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 147 | SBModuleSpecList::FindMatchingSpecs(const SBModuleSpec &match_spec) { |
| 148 | SBModuleSpecList specs; |
| 149 | m_opaque_ap->FindMatchingModuleSpecs(*match_spec.m_opaque_ap, |
| 150 | *specs.m_opaque_ap); |
| 151 | return specs; |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 152 | } |
| 153 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 154 | bool SBModuleSpecList::GetDescription(lldb::SBStream &description) { |
| 155 | m_opaque_ap->Dump(description.ref()); |
| 156 | return true; |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 157 | } |