1 //===- DebugStringTableSubsection.h - CodeView String Table -----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_DEBUGINFO_CODEVIEW_DEBUGSTRINGTABLESUBSECTION_H
11 #define LLVM_DEBUGINFO_CODEVIEW_DEBUGSTRINGTABLESUBSECTION_H
13 #include "llvm/ADT/DenseMap.h"
14 #include "llvm/ADT/StringMap.h"
15 #include "llvm/ADT/StringRef.h"
16 #include "llvm/DebugInfo/CodeView/CodeView.h"
17 #include "llvm/DebugInfo/CodeView/DebugSubsection.h"
18 #include "llvm/Support/BinaryStreamRef.h"
19 #include "llvm/Support/Error.h"
24 class BinaryStreamReader;
28 /// Represents a read-only view of a CodeView string table. This is a very
29 /// simple flat buffer consisting of null-terminated strings, where strings
30 /// are retrieved by their offset in the buffer. DebugStringTableSubsectionRef
31 /// does not own the underlying storage for the buffer.
32 class DebugStringTableSubsectionRef : public DebugSubsectionRef {
34 DebugStringTableSubsectionRef();
36 static bool classof(const DebugSubsectionRef *S) {
37 return S->kind() == DebugSubsectionKind::StringTable;
40 Error initialize(BinaryStreamRef Contents);
41 Error initialize(BinaryStreamReader &Reader);
43 Expected<StringRef> getString(uint32_t Offset) const;
45 bool valid() const { return Stream.valid(); }
47 BinaryStreamRef getBuffer() const { return Stream; }
50 BinaryStreamRef Stream;
53 /// Represents a read-write view of a CodeView string table.
54 /// DebugStringTableSubsection owns the underlying storage for the table, and is
55 /// capable of serializing the string table into a format understood by
56 /// DebugStringTableSubsectionRef.
57 class DebugStringTableSubsection : public DebugSubsection {
59 DebugStringTableSubsection();
61 static bool classof(const DebugSubsection *S) {
62 return S->kind() == DebugSubsectionKind::StringTable;
65 // If string S does not exist in the string table, insert it.
66 // Returns the ID for S.
67 uint32_t insert(StringRef S);
69 // Return the ID for string S. Assumes S exists in the table.
70 uint32_t getIdForString(StringRef S) const;
72 StringRef getStringForId(uint32_t Id) const;
74 uint32_t calculateSerializedSize() const override;
75 Error commit(BinaryStreamWriter &Writer) const override;
77 uint32_t size() const;
79 StringMap<uint32_t>::const_iterator begin() const {
80 return StringToId.begin();
83 StringMap<uint32_t>::const_iterator end() const { return StringToId.end(); }
85 std::vector<uint32_t> sortedIds() const;
88 DenseMap<uint32_t, StringRef> IdToString;
89 StringMap<uint32_t> StringToId;
90 uint32_t StringSize = 1;
93 } // end namespace codeview
95 } // end namespace llvm
97 #endif // LLVM_DEBUGINFO_CODEVIEW_DEBUGSTRINGTABLESUBSECTION_H