1 //===- DebugStringTableSubsection.h - CodeView String Table -----*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef LLVM_DEBUGINFO_CODEVIEW_DEBUGSTRINGTABLESUBSECTION_H 11 #define LLVM_DEBUGINFO_CODEVIEW_DEBUGSTRINGTABLESUBSECTION_H 12 13 #include "llvm/ADT/StringMap.h" 14 #include "llvm/ADT/StringRef.h" 15 #include "llvm/DebugInfo/CodeView/DebugSubsection.h" 16 #include "llvm/Support/BinaryStreamRef.h" 17 #include "llvm/Support/Error.h" 18 19 #include <stdint.h> 20 21 namespace llvm { 22 23 class BinaryStreamReader; 24 class BinaryStreamRef; 25 class BinaryStreamWriter; 26 27 namespace codeview { 28 29 /// Represents a read-only view of a CodeView string table. This is a very 30 /// simple flat buffer consisting of null-terminated strings, where strings 31 /// are retrieved by their offset in the buffer. DebugStringTableSubsectionRef 32 /// does not own the underlying storage for the buffer. 33 class DebugStringTableSubsectionRef : public DebugSubsectionRef { 34 public: 35 DebugStringTableSubsectionRef(); 36 37 static bool classof(const DebugSubsectionRef *S) { 38 return S->kind() == DebugSubsectionKind::StringTable; 39 } 40 41 Error initialize(BinaryStreamRef Contents); 42 43 Expected<StringRef> getString(uint32_t Offset) const; 44 45 bool valid() const { return Stream.valid(); } 46 47 private: 48 BinaryStreamRef Stream; 49 }; 50 51 /// Represents a read-write view of a CodeView string table. 52 /// DebugStringTableSubsection owns the underlying storage for the table, and is 53 /// capable of serializing the string table into a format understood by 54 /// DebugStringTableSubsectionRef. 55 class DebugStringTableSubsection : public DebugSubsection { 56 public: 57 DebugStringTableSubsection(); 58 59 static bool classof(const DebugSubsection *S) { 60 return S->kind() == DebugSubsectionKind::StringTable; 61 } 62 63 // If string S does not exist in the string table, insert it. 64 // Returns the ID for S. 65 uint32_t insert(StringRef S); 66 67 // Return the ID for string S. Assumes S exists in the table. 68 uint32_t getStringId(StringRef S) const; 69 70 uint32_t calculateSerializedSize() const override; 71 Error commit(BinaryStreamWriter &Writer) const override; 72 73 uint32_t size() const; 74 75 StringMap<uint32_t>::const_iterator begin() const { return Strings.begin(); } 76 77 StringMap<uint32_t>::const_iterator end() const { return Strings.end(); } 78 79 private: 80 StringMap<uint32_t> Strings; 81 uint32_t StringSize = 1; 82 }; 83 } 84 } 85 86 #endif 87