#include <stddef.h>
#include <stdint.h>
#include <string>
+#include "llvm/ADT/ArrayRef.h"
namespace llvm {
class StringRef;
void Dump(Stream *s) const;
- const void *GetBytes() const;
-
- size_t GetByteSize() const;
+ llvm::ArrayRef<uint8_t> GetBytes() const {
+ return {m_uuid, m_num_uuid_bytes};
+ }
bool IsValid() 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) {
}
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) {
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());
}
}
}
::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%"
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] ||
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,
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,
TimeoutTest.cpp
TimerTest.cpp
UriParserTest.cpp
+ UUIDTest.cpp
VASprintfTest.cpp
LINK_LIBS
--- /dev/null
+//===-- UUIDTest.cpp --------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "gtest/gtest.h"
+
+#include "lldb/Utility/UUID.h"
+
+using namespace lldb_private;
+
+TEST(UUIDTest, RelationalOperators) {
+ UUID empty;
+ UUID a16("1234567890123456", 16);
+ UUID b16("1234567890123457", 16);
+ UUID a20("12345678901234567890", 20);
+ UUID b20("12345678900987654321", 20);
+
+ EXPECT_EQ(empty, empty);
+ EXPECT_EQ(a16, a16);
+ EXPECT_EQ(a20, a20);
+
+ EXPECT_NE(a16, b16);
+ EXPECT_NE(a20, b20);
+ EXPECT_NE(a16, a20);
+ EXPECT_NE(empty, a16);
+
+ EXPECT_LT(empty, a16);
+ EXPECT_LT(a16, a20);
+ EXPECT_LT(a16, b16);
+ EXPECT_GT(a20, b20);
+}