summaryrefslogtreecommitdiffstats
path: root/lldb/source
diff options
context:
space:
mode:
authorPavel Labath <labath@google.com>2018-06-21 15:07:43 +0000
committerPavel Labath <labath@google.com>2018-06-21 15:07:43 +0000
commit470b286ee5669019a83b2e2ffae845ee44369fbf (patch)
tree6bb572eb8d9527ee580308d25363a284a0330efa /lldb/source
parent084d360f6984df29d0ea2bdf8fea1f1d97de2858 (diff)
downloadbcm5719-llvm-470b286ee5669019a83b2e2ffae845ee44369fbf.tar.gz
bcm5719-llvm-470b286ee5669019a83b2e2ffae845ee44369fbf.zip
Modernize UUID class
Instead of a separate GetBytes + GetByteSize methods I introduce a single GetBytes method returning an ArrayRef. This is NFC cleanup now, but it should make handling arbitrarily-sized UUIDs cleaner, should we choose to go that way. I also took the opportunity to add some unit tests for this class. llvm-svn: 335244
Diffstat (limited to 'lldb/source')
-rw-r--r--lldb/source/API/SBModule.cpp2
-rw-r--r--lldb/source/API/SBModuleSpec.cpp4
-rw-r--r--lldb/source/Interpreter/OptionValueUUID.cpp17
-rw-r--r--lldb/source/Utility/UUID.cpp16
4 files changed, 16 insertions, 23 deletions
diff --git a/lldb/source/API/SBModule.cpp b/lldb/source/API/SBModule.cpp
index 8866cf448a3..ed0c75c5c3e 100644
--- a/lldb/source/API/SBModule.cpp
+++ b/lldb/source/API/SBModule.cpp
@@ -144,7 +144,7 @@ const uint8_t *SBModule::GetUUIDBytes() const {
const uint8_t *uuid_bytes = NULL;
ModuleSP module_sp(GetSP());
if (module_sp)
- uuid_bytes = (const uint8_t *)module_sp->GetUUID().GetBytes();
+ uuid_bytes = module_sp->GetUUID().GetBytes().data();
if (log) {
if (uuid_bytes) {
diff --git a/lldb/source/API/SBModuleSpec.cpp b/lldb/source/API/SBModuleSpec.cpp
index 89e8bef91bf..0e6e7c9b0b9 100644
--- a/lldb/source/API/SBModuleSpec.cpp
+++ b/lldb/source/API/SBModuleSpec.cpp
@@ -82,11 +82,11 @@ void SBModuleSpec::SetTriple(const char *triple) {
}
const uint8_t *SBModuleSpec::GetUUIDBytes() {
- return (const uint8_t *)m_opaque_ap->GetUUID().GetBytes();
+ return m_opaque_ap->GetUUID().GetBytes().data();
}
size_t SBModuleSpec::GetUUIDLength() {
- return m_opaque_ap->GetUUID().GetByteSize();
+ return m_opaque_ap->GetUUID().GetBytes().size();
}
bool SBModuleSpec::SetUUIDBytes(const uint8_t *uuid, size_t uuid_len) {
diff --git a/lldb/source/Interpreter/OptionValueUUID.cpp b/lldb/source/Interpreter/OptionValueUUID.cpp
index bec04cba8c3..07c739db08a 100644
--- a/lldb/source/Interpreter/OptionValueUUID.cpp
+++ b/lldb/source/Interpreter/OptionValueUUID.cpp
@@ -86,17 +86,12 @@ size_t OptionValueUUID::AutoComplete(CommandInterpreter &interpreter,
if (module_sp) {
const UUID &module_uuid = module_sp->GetUUID();
if (module_uuid.IsValid()) {
- bool add_uuid = false;
- if (num_bytes_decoded == 0)
- add_uuid = true;
- else
- add_uuid = ::memcmp(module_uuid.GetBytes(), uuid_bytes,
- num_bytes_decoded) == 0;
- if (add_uuid) {
- std::string uuid_str;
- uuid_str = module_uuid.GetAsString();
- if (!uuid_str.empty())
- matches.AppendString(uuid_str.c_str());
+ llvm::ArrayRef<uint8_t> decoded_bytes(uuid_bytes,
+ num_bytes_decoded);
+ llvm::ArrayRef<uint8_t> module_bytes = module_uuid.GetBytes();
+ if (module_bytes.size() >= num_bytes_decoded &&
+ module_bytes.take_front(num_bytes_decoded) == decoded_bytes) {
+ matches.AppendString(module_uuid.GetAsString());
}
}
}
diff --git a/lldb/source/Utility/UUID.cpp b/lldb/source/Utility/UUID.cpp
index 097243219fa..864fb38eba1 100644
--- a/lldb/source/Utility/UUID.cpp
+++ b/lldb/source/Utility/UUID.cpp
@@ -46,14 +46,12 @@ void UUID::Clear() {
::memset(m_uuid, 0, sizeof(m_uuid));
}
-const void *UUID::GetBytes() const { return m_uuid; }
-
std::string UUID::GetAsString(const char *separator) const {
std::string result;
char buf[256];
if (!separator)
separator = "-";
- const uint8_t *u = (const uint8_t *)GetBytes();
+ const uint8_t *u = GetBytes().data();
if (sizeof(buf) >
(size_t)snprintf(buf, sizeof(buf), "%2.2X%2.2X%2.2X%2.2X%s%2.2X%2.2X%s%2."
"2X%2.2X%s%2.2X%2.2X%s%2.2X%2.2X%2.2X%"
@@ -101,8 +99,6 @@ bool UUID::SetBytes(const void *uuid_bytes, uint32_t num_uuid_bytes) {
return false;
}
-size_t UUID::GetByteSize() const { return m_num_uuid_bytes; }
-
bool UUID::IsValid() const {
return m_uuid[0] || m_uuid[1] || m_uuid[2] || m_uuid[3] || m_uuid[4] ||
m_uuid[5] || m_uuid[6] || m_uuid[7] || m_uuid[8] || m_uuid[9] ||
@@ -184,8 +180,7 @@ size_t UUID::SetFromCString(const char *cstr, uint32_t num_uuid_bytes) {
bool lldb_private::operator==(const lldb_private::UUID &lhs,
const lldb_private::UUID &rhs) {
- return ::memcmp(lhs.GetBytes(), rhs.GetBytes(),
- sizeof(lldb_private::UUID::ValueType)) == 0;
+ return lhs.GetBytes() == rhs.GetBytes();
}
bool lldb_private::operator!=(const lldb_private::UUID &lhs,
@@ -195,8 +190,11 @@ bool lldb_private::operator!=(const lldb_private::UUID &lhs,
bool lldb_private::operator<(const lldb_private::UUID &lhs,
const lldb_private::UUID &rhs) {
- return ::memcmp(lhs.GetBytes(), rhs.GetBytes(),
- sizeof(lldb_private::UUID::ValueType)) < 0;
+ if (lhs.GetBytes().size() != rhs.GetBytes().size())
+ return lhs.GetBytes().size() < rhs.GetBytes().size();
+
+ return std::memcmp(lhs.GetBytes().data(), rhs.GetBytes().data(),
+ lhs.GetBytes().size());
}
bool lldb_private::operator<=(const lldb_private::UUID &lhs,
OpenPOWER on IntegriCloud