LLVM 22.0.0git
DebugStringTableSubsection.h
Go to the documentation of this file.
1//===- DebugStringTableSubsection.h - CodeView String Table -----*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_DEBUGINFO_CODEVIEW_DEBUGSTRINGTABLESUBSECTION_H
10#define LLVM_DEBUGINFO_CODEVIEW_DEBUGSTRINGTABLESUBSECTION_H
11
12#include "llvm/ADT/DenseMap.h"
13#include "llvm/ADT/StringMap.h"
14#include "llvm/ADT/StringRef.h"
19#include "llvm/Support/Error.h"
20#include <cstdint>
21
22namespace llvm {
23
24class BinaryStreamReader;
25
26namespace codeview {
27
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.
33public:
35
36 static bool classof(const DebugSubsectionRef *S) {
38 }
39
42
44
45 bool valid() const { return Stream.valid(); }
46
47 BinaryStreamRef getBuffer() const { return Stream; }
48
49private:
50 BinaryStreamRef Stream;
51};
52
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.
58public:
60
61 static bool classof(const DebugSubsection *S) {
62 return S->kind() == DebugSubsectionKind::StringTable;
63 }
64
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);
68
69 // Return the ID for string S. Assumes S exists in the table.
70 uint32_t getIdForString(StringRef S) const;
71
72 StringRef getStringForId(uint32_t Id) const;
73
74 uint32_t calculateSerializedSize() const override;
75 Error commit(BinaryStreamWriter &Writer) const override;
76
77 uint32_t size() const;
78
80 return StringToId.begin();
81 }
82
83 StringMap<uint32_t>::const_iterator end() const { return StringToId.end(); }
84
85 std::vector<uint32_t> sortedIds() const;
86
87private:
89 StringMap<uint32_t> StringToId;
90 uint32_t StringSize = 1;
91};
92
93} // end namespace codeview
94
95} // end namespace llvm
96
97#endif // LLVM_DEBUGINFO_CODEVIEW_DEBUGSTRINGTABLESUBSECTION_H
This file defines the StringMap class.
#define LLVM_ABI
Definition: Compiler.h:213
This file defines the DenseMap class.
Provides read only access to a subclass of BinaryStream.
BinaryStreamRef is to BinaryStream what ArrayRef is to an Array.
Provides write only access to a subclass of WritableBinaryStream.
Lightweight error class with error context and mandatory checking.
Definition: Error.h:159
Tagged union holding either a T or a Error.
Definition: Error.h:485
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:133
iterator end()
Definition: StringMap.h:224
iterator begin()
Definition: StringMap.h:223
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
Represents a read-only view of a CodeView string table.
static bool classof(const DebugSubsectionRef *S)
LLVM_ABI Expected< StringRef > getString(uint32_t Offset) const
LLVM_ABI Error initialize(BinaryStreamRef Contents)
Represents a read-write view of a CodeView string table.
StringMap< uint32_t >::const_iterator begin() const
StringMap< uint32_t >::const_iterator end() const
static bool classof(const DebugSubsection *S)
DebugSubsectionKind kind() const
DebugSubsectionKind kind() const
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:477
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Definition: STLExtras.h:1702