2010-06-09 00:52:24 +08:00
|
|
|
//===-- UUID.cpp ------------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Core/UUID.h"
|
|
|
|
// C Includes
|
2010-06-10 03:36:54 +08:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
// C++ Includes
|
2013-05-04 07:56:12 +08:00
|
|
|
#include <string>
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
// Other libraries and framework includes
|
|
|
|
// Project includes
|
|
|
|
#include "lldb/Core/Stream.h"
|
|
|
|
|
2011-02-05 02:53:10 +08:00
|
|
|
namespace lldb_private {
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2013-05-24 04:57:03 +08:00
|
|
|
UUID::UUID() : m_num_uuid_bytes(16)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2011-02-05 05:13:05 +08:00
|
|
|
::memset (m_uuid, 0, sizeof(m_uuid));
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
UUID::UUID(const UUID& rhs)
|
|
|
|
{
|
2013-05-24 04:57:03 +08:00
|
|
|
m_num_uuid_bytes = rhs.m_num_uuid_bytes;
|
2010-06-09 00:52:24 +08:00
|
|
|
::memcpy (m_uuid, rhs.m_uuid, sizeof (m_uuid));
|
|
|
|
}
|
|
|
|
|
|
|
|
UUID::UUID (const void *uuid_bytes, uint32_t num_uuid_bytes)
|
|
|
|
{
|
2013-05-24 04:57:03 +08:00
|
|
|
SetBytes (uuid_bytes, num_uuid_bytes);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const UUID&
|
|
|
|
UUID::operator=(const UUID& rhs)
|
|
|
|
{
|
|
|
|
if (this != &rhs)
|
2013-05-24 04:57:03 +08:00
|
|
|
{
|
|
|
|
m_num_uuid_bytes = rhs.m_num_uuid_bytes;
|
2010-06-09 00:52:24 +08:00
|
|
|
::memcpy (m_uuid, rhs.m_uuid, sizeof (m_uuid));
|
2013-05-24 04:57:03 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
UUID::~UUID()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UUID::Clear()
|
|
|
|
{
|
2013-05-24 04:57:03 +08:00
|
|
|
m_num_uuid_bytes = 16;
|
2011-02-05 05:13:05 +08:00
|
|
|
::memset (m_uuid, 0, sizeof(m_uuid));
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const void *
|
|
|
|
UUID::GetBytes() const
|
|
|
|
{
|
|
|
|
return m_uuid;
|
|
|
|
}
|
|
|
|
|
2013-05-04 07:56:12 +08:00
|
|
|
std::string
|
2013-07-02 03:45:50 +08:00
|
|
|
UUID::GetAsString (const char *separator) const
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2013-05-04 07:56:12 +08:00
|
|
|
std::string result;
|
2013-07-02 03:45:50 +08:00
|
|
|
char buf[256];
|
|
|
|
if (!separator)
|
|
|
|
separator = "-";
|
2010-06-09 00:52:24 +08:00
|
|
|
const uint8_t *u = (const uint8_t *)GetBytes();
|
2013-05-24 04:57:03 +08:00
|
|
|
if (sizeof (buf) > (size_t)snprintf (buf,
|
2013-05-04 07:56:12 +08:00
|
|
|
sizeof (buf),
|
2013-07-02 03:45:50 +08:00
|
|
|
"%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%2.2X%2.2X%2.2X",
|
|
|
|
u[0],u[1],u[2],u[3],separator,
|
|
|
|
u[4],u[5],separator,
|
|
|
|
u[6],u[7],separator,
|
|
|
|
u[8],u[9],separator,
|
|
|
|
u[10],u[11],u[12],u[13],u[14],u[15]))
|
2013-05-04 07:56:12 +08:00
|
|
|
{
|
|
|
|
result.append (buf);
|
2013-05-24 04:57:03 +08:00
|
|
|
if (m_num_uuid_bytes == 20)
|
|
|
|
{
|
2013-07-02 03:45:50 +08:00
|
|
|
if (sizeof (buf) > (size_t)snprintf (buf, sizeof (buf), "%s%2.2X%2.2X%2.2X%2.2X", separator,u[16],u[17],u[18],u[19]))
|
2013-05-24 04:57:03 +08:00
|
|
|
result.append (buf);
|
|
|
|
}
|
2013-05-04 07:56:12 +08:00
|
|
|
}
|
|
|
|
return result;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UUID::Dump (Stream *s) const
|
|
|
|
{
|
|
|
|
const uint8_t *u = (const uint8_t *)GetBytes();
|
|
|
|
s->Printf ("%2.2X%2.2X%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X",
|
|
|
|
u[0],u[1],u[2],u[3],u[4],u[5],u[6],u[7],u[8],u[9],u[10],u[11],u[12],u[13],u[14],u[15]);
|
2013-05-24 04:57:03 +08:00
|
|
|
if (m_num_uuid_bytes == 20)
|
|
|
|
{
|
|
|
|
s->Printf ("-%2.2X%2.2X%2.2X%2.2X", u[16],u[17],u[18],u[19]);
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
Added a way to extract the module specifications from a file. A module specification is information that is required to describe a module (executable, shared library, object file, ect). This information includes host path, platform path (remote path), symbol file path, UUID, object name (for objects in .a files for example you could have an object name of "foo.o"), and target triple. Module specification can be used to create a module, or used to add a module to a target. A list of module specifications can be used to enumerate objects in container objects (like universal mach files and BSD archive files).
There are two new classes:
lldb::SBModuleSpec
lldb::SBModuleSpecList
The SBModuleSpec wraps up a lldb_private::ModuleSpec, and SBModuleSpecList wraps up a lldb_private::ModuleSpecList.
llvm-svn: 185877
2013-07-09 06:22:41 +08:00
|
|
|
bool
|
2013-05-24 04:57:03 +08:00
|
|
|
UUID::SetBytes (const void *uuid_bytes, uint32_t num_uuid_bytes)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
Added a way to extract the module specifications from a file. A module specification is information that is required to describe a module (executable, shared library, object file, ect). This information includes host path, platform path (remote path), symbol file path, UUID, object name (for objects in .a files for example you could have an object name of "foo.o"), and target triple. Module specification can be used to create a module, or used to add a module to a target. A list of module specifications can be used to enumerate objects in container objects (like universal mach files and BSD archive files).
There are two new classes:
lldb::SBModuleSpec
lldb::SBModuleSpecList
The SBModuleSpec wraps up a lldb_private::ModuleSpec, and SBModuleSpecList wraps up a lldb_private::ModuleSpecList.
llvm-svn: 185877
2013-07-09 06:22:41 +08:00
|
|
|
if (uuid_bytes)
|
2013-05-24 04:57:03 +08:00
|
|
|
{
|
Added a way to extract the module specifications from a file. A module specification is information that is required to describe a module (executable, shared library, object file, ect). This information includes host path, platform path (remote path), symbol file path, UUID, object name (for objects in .a files for example you could have an object name of "foo.o"), and target triple. Module specification can be used to create a module, or used to add a module to a target. A list of module specifications can be used to enumerate objects in container objects (like universal mach files and BSD archive files).
There are two new classes:
lldb::SBModuleSpec
lldb::SBModuleSpecList
The SBModuleSpec wraps up a lldb_private::ModuleSpec, and SBModuleSpecList wraps up a lldb_private::ModuleSpecList.
llvm-svn: 185877
2013-07-09 06:22:41 +08:00
|
|
|
switch (num_uuid_bytes)
|
|
|
|
{
|
|
|
|
case 20:
|
|
|
|
m_num_uuid_bytes = 20;
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
m_num_uuid_bytes = 16;
|
|
|
|
m_uuid[16] = m_uuid[17] = m_uuid[18] = m_uuid[19] = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// Unsupported UUID byte size
|
|
|
|
m_num_uuid_bytes = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_num_uuid_bytes > 0)
|
|
|
|
{
|
|
|
|
::memcpy (m_uuid, uuid_bytes, m_num_uuid_bytes);
|
|
|
|
return true;
|
|
|
|
}
|
2013-05-24 04:57:03 +08:00
|
|
|
}
|
Added a way to extract the module specifications from a file. A module specification is information that is required to describe a module (executable, shared library, object file, ect). This information includes host path, platform path (remote path), symbol file path, UUID, object name (for objects in .a files for example you could have an object name of "foo.o"), and target triple. Module specification can be used to create a module, or used to add a module to a target. A list of module specifications can be used to enumerate objects in container objects (like universal mach files and BSD archive files).
There are two new classes:
lldb::SBModuleSpec
lldb::SBModuleSpecList
The SBModuleSpec wraps up a lldb_private::ModuleSpec, and SBModuleSpecList wraps up a lldb_private::ModuleSpecList.
llvm-svn: 185877
2013-07-09 06:22:41 +08:00
|
|
|
::memset (m_uuid, 0, sizeof(m_uuid));
|
|
|
|
return false;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
UUID::GetByteSize()
|
|
|
|
{
|
2013-05-24 04:57:03 +08:00
|
|
|
return m_num_uuid_bytes;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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] ||
|
|
|
|
m_uuid[10] ||
|
|
|
|
m_uuid[11] ||
|
|
|
|
m_uuid[12] ||
|
|
|
|
m_uuid[13] ||
|
|
|
|
m_uuid[14] ||
|
2013-05-24 04:57:03 +08:00
|
|
|
m_uuid[15] ||
|
|
|
|
m_uuid[16] ||
|
|
|
|
m_uuid[17] ||
|
|
|
|
m_uuid[18] ||
|
|
|
|
m_uuid[19];
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
xdigit_to_int (char ch)
|
|
|
|
{
|
|
|
|
ch = tolower(ch);
|
|
|
|
if (ch >= 'a' && ch <= 'f')
|
|
|
|
return 10 + ch - 'a';
|
|
|
|
return ch - '0';
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
2013-05-24 04:57:03 +08:00
|
|
|
UUID::DecodeUUIDBytesFromCString (const char *p, ValueType &uuid_bytes, const char **end, uint32_t num_uuid_bytes)
|
2012-09-28 06:26:11 +08:00
|
|
|
{
|
|
|
|
size_t uuid_byte_idx = 0;
|
|
|
|
if (p)
|
|
|
|
{
|
|
|
|
while (*p)
|
|
|
|
{
|
|
|
|
if (isxdigit(p[0]) && isxdigit(p[1]))
|
|
|
|
{
|
|
|
|
int hi_nibble = xdigit_to_int(p[0]);
|
|
|
|
int lo_nibble = xdigit_to_int(p[1]);
|
|
|
|
// Translate the two hex nibble characters into a byte
|
|
|
|
uuid_bytes[uuid_byte_idx] = (hi_nibble << 4) + lo_nibble;
|
|
|
|
|
|
|
|
// Skip both hex digits
|
|
|
|
p += 2;
|
|
|
|
|
|
|
|
// Increment the byte that we are decoding within the UUID value
|
|
|
|
// and break out if we are done
|
2013-05-24 04:57:03 +08:00
|
|
|
if (++uuid_byte_idx == num_uuid_bytes)
|
2012-09-28 06:26:11 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (*p == '-')
|
|
|
|
{
|
|
|
|
// Skip dashes
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// UUID values can only consist of hex characters and '-' chars
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (end)
|
|
|
|
*end = p;
|
2013-05-24 04:57:03 +08:00
|
|
|
// Clear trailing bytes to 0.
|
|
|
|
for (uint32_t i = uuid_byte_idx; i < sizeof(ValueType); i++)
|
|
|
|
uuid_bytes[i] = 0;
|
2012-09-28 06:26:11 +08:00
|
|
|
return uuid_byte_idx;
|
|
|
|
}
|
|
|
|
size_t
|
2013-05-24 04:57:03 +08:00
|
|
|
UUID::SetFromCString (const char *cstr, uint32_t num_uuid_bytes)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
if (cstr == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
const char *p = cstr;
|
|
|
|
|
|
|
|
// Skip leading whitespace characters
|
|
|
|
while (isspace(*p))
|
|
|
|
++p;
|
2012-09-28 06:26:11 +08:00
|
|
|
|
2013-05-24 04:57:03 +08:00
|
|
|
const size_t uuid_byte_idx = UUID::DecodeUUIDBytesFromCString (p, m_uuid, &p, num_uuid_bytes);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
// If we successfully decoded a UUID, return the amount of characters that
|
|
|
|
// were consumed
|
2013-05-24 04:57:03 +08:00
|
|
|
if (uuid_byte_idx == num_uuid_bytes)
|
2015-03-10 09:15:28 +08:00
|
|
|
{
|
|
|
|
m_num_uuid_bytes = num_uuid_bytes;
|
2010-06-09 00:52:24 +08:00
|
|
|
return p - cstr;
|
2015-03-10 09:15:28 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
// Else return zero to indicate we were not able to parse a UUID value
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-02-05 02:53:10 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
bool
|
2011-02-05 02:53:10 +08:00
|
|
|
lldb_private::operator == (const lldb_private::UUID &lhs, const lldb_private::UUID &rhs)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2013-05-24 04:57:03 +08:00
|
|
|
return ::memcmp (lhs.GetBytes(), rhs.GetBytes(), sizeof (lldb_private::UUID::ValueType)) == 0;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2011-02-05 02:53:10 +08:00
|
|
|
lldb_private::operator != (const lldb_private::UUID &lhs, const lldb_private::UUID &rhs)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2013-05-24 04:57:03 +08:00
|
|
|
return ::memcmp (lhs.GetBytes(), rhs.GetBytes(), sizeof (lldb_private::UUID::ValueType)) != 0;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2011-02-05 02:53:10 +08:00
|
|
|
lldb_private::operator < (const lldb_private::UUID &lhs, const lldb_private::UUID &rhs)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2013-05-24 04:57:03 +08:00
|
|
|
return ::memcmp (lhs.GetBytes(), rhs.GetBytes(), sizeof (lldb_private::UUID::ValueType)) < 0;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2011-02-05 02:53:10 +08:00
|
|
|
lldb_private::operator <= (const lldb_private::UUID &lhs, const lldb_private::UUID &rhs)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2013-05-24 04:57:03 +08:00
|
|
|
return ::memcmp (lhs.GetBytes(), rhs.GetBytes(), sizeof (lldb_private::UUID::ValueType)) <= 0;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2011-02-05 02:53:10 +08:00
|
|
|
lldb_private::operator > (const lldb_private::UUID &lhs, const lldb_private::UUID &rhs)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2013-05-24 04:57:03 +08:00
|
|
|
return ::memcmp (lhs.GetBytes(), rhs.GetBytes(), sizeof (lldb_private::UUID::ValueType)) > 0;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2011-02-05 02:53:10 +08:00
|
|
|
lldb_private::operator >= (const lldb_private::UUID &lhs, const lldb_private::UUID &rhs)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2013-05-24 04:57:03 +08:00
|
|
|
return ::memcmp (lhs.GetBytes(), rhs.GetBytes(), sizeof (lldb_private::UUID::ValueType)) >= 0;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|