Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:42:59

0001 //===-- UUID.h --------------------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLDB_UTILITY_UUID_H
0010 #define LLDB_UTILITY_UUID_H
0011 
0012 #include "llvm/ADT/ArrayRef.h"
0013 #include "llvm/ADT/StringRef.h"
0014 #include "llvm/Support/Endian.h"
0015 #include <cstddef>
0016 #include <cstdint>
0017 #include <string>
0018 
0019 namespace lldb_private {
0020 
0021   class Stream;
0022 
0023 class UUID {
0024   // Represents UUID's of various sizes.  In all cases, a uuid of all zeros is
0025   // treated as an "Invalid UUID" marker, and the UUID created from such data
0026   // will return false for IsValid.
0027 public:
0028   UUID() = default;
0029   
0030   /// Creates a uuid from the data pointed to by the bytes argument.
0031   UUID(llvm::ArrayRef<uint8_t> bytes) : m_bytes(bytes) {
0032     if (llvm::all_of(m_bytes, [](uint8_t b) { return b == 0; })) {
0033       Clear();
0034    }
0035   }
0036 
0037   // Reference:
0038   // https://crashpad.chromium.org/doxygen/structcrashpad_1_1CodeViewRecordPDB70.html
0039   struct CvRecordPdb70 {
0040     struct {
0041       llvm::support::ulittle32_t Data1;
0042       llvm::support::ulittle16_t Data2;
0043       llvm::support::ulittle16_t Data3;
0044       uint8_t Data4[8];
0045     } Uuid;
0046     llvm::support::ulittle32_t Age;
0047     // char PDBFileName[];
0048   };
0049 
0050   /// Create a UUID from CvRecordPdb70.
0051   UUID(CvRecordPdb70 debug_info);
0052 
0053   /// Creates a UUID from the data pointed to by the bytes argument. 
0054   UUID(const void *bytes, uint32_t num_bytes) {
0055     if (!bytes)
0056       return;
0057     *this 
0058         = UUID(llvm::ArrayRef<uint8_t>(reinterpret_cast<const uint8_t *>(bytes), 
0059                num_bytes));
0060   }
0061 
0062   void Clear() { m_bytes.clear(); }
0063 
0064   void Dump(Stream &s) const;
0065 
0066   llvm::ArrayRef<uint8_t> GetBytes() const { return m_bytes; }
0067 
0068   explicit operator bool() const { return IsValid(); }
0069   bool IsValid() const { return !m_bytes.empty(); }
0070   
0071   std::string GetAsString(llvm::StringRef separator = "-") const;
0072 
0073   bool SetFromStringRef(llvm::StringRef str);
0074 
0075   /// Decode as many UUID bytes as possible from the C string \a cstr.
0076   ///
0077   /// \param[in] str
0078   ///     An llvm::StringRef that points at a UUID string value (no leading
0079   ///     spaces). The string must contain only hex characters and optionally
0080   ///     can contain the '-' sepearators.
0081   ///
0082   /// \param[in] uuid_bytes
0083   ///     A buffer of bytes that will contain a full or partially decoded UUID.
0084   ///
0085   /// \return
0086   ///     The original string, with all decoded bytes removed.
0087   static llvm::StringRef
0088   DecodeUUIDBytesFromString(llvm::StringRef str,
0089                             llvm::SmallVectorImpl<uint8_t> &uuid_bytes);
0090 
0091 private:
0092   // GNU ld generates 20-byte build-ids. Size chosen to avoid heap allocations
0093   // for this case.
0094   llvm::SmallVector<uint8_t, 20> m_bytes;
0095 
0096   friend bool operator==(const UUID &LHS, const UUID &RHS) {
0097     return LHS.m_bytes == RHS.m_bytes;
0098   }
0099   friend bool operator!=(const UUID &LHS, const UUID &RHS) {
0100     return !(LHS == RHS);
0101   }
0102   friend bool operator<(const UUID &LHS, const UUID &RHS) {
0103     return LHS.m_bytes < RHS.m_bytes;
0104   }
0105   friend bool operator<=(const UUID &LHS, const UUID &RHS) {
0106     return !(RHS < LHS);
0107   }
0108   friend bool operator>(const UUID &LHS, const UUID &RHS) { return RHS < LHS; }
0109   friend bool operator>=(const UUID &LHS, const UUID &RHS) {
0110     return !(LHS < RHS);
0111   }
0112 };
0113 } // namespace lldb_private
0114 
0115 #endif // LLDB_UTILITY_UUID_H