Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:39

0001 //===- DebugStringTableSubsection.h - CodeView String Table -----*- 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 LLVM_DEBUGINFO_CODEVIEW_DEBUGSTRINGTABLESUBSECTION_H
0010 #define LLVM_DEBUGINFO_CODEVIEW_DEBUGSTRINGTABLESUBSECTION_H
0011 
0012 #include "llvm/ADT/DenseMap.h"
0013 #include "llvm/ADT/StringMap.h"
0014 #include "llvm/ADT/StringRef.h"
0015 #include "llvm/DebugInfo/CodeView/CodeView.h"
0016 #include "llvm/DebugInfo/CodeView/DebugSubsection.h"
0017 #include "llvm/Support/BinaryStreamRef.h"
0018 #include "llvm/Support/Error.h"
0019 #include <cstdint>
0020 
0021 namespace llvm {
0022 
0023 class BinaryStreamReader;
0024 
0025 namespace codeview {
0026 
0027 /// Represents a read-only view of a CodeView string table.  This is a very
0028 /// simple flat buffer consisting of null-terminated strings, where strings
0029 /// are retrieved by their offset in the buffer.  DebugStringTableSubsectionRef
0030 /// does not own the underlying storage for the buffer.
0031 class DebugStringTableSubsectionRef : public DebugSubsectionRef {
0032 public:
0033   DebugStringTableSubsectionRef();
0034 
0035   static bool classof(const DebugSubsectionRef *S) {
0036     return S->kind() == DebugSubsectionKind::StringTable;
0037   }
0038 
0039   Error initialize(BinaryStreamRef Contents);
0040   Error initialize(BinaryStreamReader &Reader);
0041 
0042   Expected<StringRef> getString(uint32_t Offset) const;
0043 
0044   bool valid() const { return Stream.valid(); }
0045 
0046   BinaryStreamRef getBuffer() const { return Stream; }
0047 
0048 private:
0049   BinaryStreamRef Stream;
0050 };
0051 
0052 /// Represents a read-write view of a CodeView string table.
0053 /// DebugStringTableSubsection owns the underlying storage for the table, and is
0054 /// capable of serializing the string table into a format understood by
0055 /// DebugStringTableSubsectionRef.
0056 class DebugStringTableSubsection : public DebugSubsection {
0057 public:
0058   DebugStringTableSubsection();
0059 
0060   static bool classof(const DebugSubsection *S) {
0061     return S->kind() == DebugSubsectionKind::StringTable;
0062   }
0063 
0064   // If string S does not exist in the string table, insert it.
0065   // Returns the ID for S.
0066   uint32_t insert(StringRef S);
0067 
0068   // Return the ID for string S.  Assumes S exists in the table.
0069   uint32_t getIdForString(StringRef S) const;
0070 
0071   StringRef getStringForId(uint32_t Id) const;
0072 
0073   uint32_t calculateSerializedSize() const override;
0074   Error commit(BinaryStreamWriter &Writer) const override;
0075 
0076   uint32_t size() const;
0077 
0078   StringMap<uint32_t>::const_iterator begin() const {
0079     return StringToId.begin();
0080   }
0081 
0082   StringMap<uint32_t>::const_iterator end() const { return StringToId.end(); }
0083 
0084   std::vector<uint32_t> sortedIds() const;
0085 
0086 private:
0087   DenseMap<uint32_t, StringRef> IdToString;
0088   StringMap<uint32_t> StringToId;
0089   uint32_t StringSize = 1;
0090 };
0091 
0092 } // end namespace codeview
0093 
0094 } // end namespace llvm
0095 
0096 #endif // LLVM_DEBUGINFO_CODEVIEW_DEBUGSTRINGTABLESUBSECTION_H