LLVM  14.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"
18 #include "llvm/Support/Error.h"
19 #include <cstdint>
20 
21 namespace llvm {
22 
23 class BinaryStreamReader;
24 
25 namespace codeview {
26 
27 /// Represents a read-only view of a CodeView string table. This is a very
28 /// simple flat buffer consisting of null-terminated strings, where strings
29 /// are retrieved by their offset in the buffer. DebugStringTableSubsectionRef
30 /// does not own the underlying storage for the buffer.
32 public:
34 
35  static bool classof(const DebugSubsectionRef *S) {
36  return S->kind() == DebugSubsectionKind::StringTable;
37  }
38 
41 
43 
44  bool valid() const { return Stream.valid(); }
45 
46  BinaryStreamRef getBuffer() const { return Stream; }
47 
48 private:
49  BinaryStreamRef Stream;
50 };
51 
52 /// Represents a read-write view of a CodeView string table.
53 /// DebugStringTableSubsection owns the underlying storage for the table, and is
54 /// capable of serializing the string table into a format understood by
55 /// DebugStringTableSubsectionRef.
57 public:
59 
60  static bool classof(const DebugSubsection *S) {
61  return S->kind() == DebugSubsectionKind::StringTable;
62  }
63 
64  // If string S does not exist in the string table, insert it.
65  // Returns the ID for S.
67 
68  // Return the ID for string S. Assumes S exists in the table.
70 
72 
73  uint32_t calculateSerializedSize() const override;
74  Error commit(BinaryStreamWriter &Writer) const override;
75 
76  uint32_t size() const;
77 
79  return StringToId.begin();
80  }
81 
82  StringMap<uint32_t>::const_iterator end() const { return StringToId.end(); }
83 
84  std::vector<uint32_t> sortedIds() const;
85 
86 private:
88  StringMap<uint32_t> StringToId;
89  uint32_t StringSize = 1;
90 };
91 
92 } // end namespace codeview
93 
94 } // end namespace llvm
95 
96 #endif // LLVM_DEBUGINFO_CODEVIEW_DEBUGSTRINGTABLESUBSECTION_H
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::codeview::DebugStringTableSubsection::calculateSerializedSize
uint32_t calculateSerializedSize() const override
Definition: DebugStringTableSubsection.cpp:60
StringRef.h
llvm::BinaryStreamWriter
Provides write only access to a subclass of WritableBinaryStream.
Definition: BinaryStreamWriter.h:31
llvm::codeview::DebugStringTableSubsection::insert
uint32_t insert(StringRef S)
Definition: DebugStringTableSubsection.cpp:47
Error.h
llvm::StringMap::end
iterator end()
Definition: StringMap.h:205
DenseMap.h
llvm::codeview::DebugStringTableSubsectionRef::DebugStringTableSubsectionRef
DebugStringTableSubsectionRef()
Definition: DebugStringTableSubsection.cpp:22
llvm::codeview::DebugStringTableSubsection::size
uint32_t size() const
Definition: DebugStringTableSubsection.cpp:86
llvm::codeview::DebugStringTableSubsection
Represents a read-write view of a CodeView string table.
Definition: DebugStringTableSubsection.h:56
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
llvm::codeview::DebugSubsectionKind::StringTable
@ StringTable
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
llvm::codeview::DebugStringTableSubsectionRef::getBuffer
BinaryStreamRef getBuffer() const
Definition: DebugStringTableSubsection.h:46
llvm::codeview::DebugStringTableSubsection::end
StringMap< uint32_t >::const_iterator end() const
Definition: DebugStringTableSubsection.h:82
llvm::codeview::DebugStringTableSubsectionRef::initialize
Error initialize(BinaryStreamRef Contents)
Definition: DebugStringTableSubsection.cpp:25
llvm::codeview::DebugSubsectionRef
Definition: DebugSubsection.h:19
llvm::codeview::DebugStringTableSubsectionRef::classof
static bool classof(const DebugSubsectionRef *S)
Definition: DebugStringTableSubsection.h:35
StringMap.h
llvm::codeview::DebugStringTableSubsection::classof
static bool classof(const DebugSubsection *S)
Definition: DebugStringTableSubsection.h:60
CodeView.h
llvm::StringMap
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:108
llvm::BinaryStreamReader
Provides read only access to a subclass of BinaryStream.
Definition: BinaryStreamReader.h:31
DebugSubsection.h
llvm::codeview::DebugStringTableSubsection::getStringForId
StringRef getStringForId(uint32_t Id) const
Definition: DebugStringTableSubsection.cpp:103
llvm::DenseMap
Definition: DenseMap.h:714
llvm::StringMap::begin
iterator begin()
Definition: StringMap.h:204
llvm::codeview::DebugStringTableSubsection::sortedIds
std::vector< uint32_t > sortedIds() const
Definition: DebugStringTableSubsection.cpp:88
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
BinaryStreamRef.h
uint32_t
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::codeview::DebugSubsection
Definition: DebugSubsection.h:32
llvm::codeview::DebugStringTableSubsection::begin
StringMap< uint32_t >::const_iterator begin() const
Definition: DebugStringTableSubsection.h:78
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::BinaryStreamRefBase::valid
bool valid() const
Definition: BinaryStreamRef.h:122
llvm::codeview::DebugStringTableSubsection::DebugStringTableSubsection
DebugStringTableSubsection()
Definition: DebugStringTableSubsection.cpp:44
llvm::codeview::DebugStringTableSubsection::commit
Error commit(BinaryStreamWriter &Writer) const override
Definition: DebugStringTableSubsection.cpp:64
llvm::codeview::DebugStringTableSubsectionRef
Represents a read-only view of a CodeView string table.
Definition: DebugStringTableSubsection.h:31
llvm::codeview::DebugStringTableSubsectionRef::getString
Expected< StringRef > getString(uint32_t Offset) const
Definition: DebugStringTableSubsection.cpp:35
llvm::codeview::DebugStringTableSubsection::getIdForString
uint32_t getIdForString(StringRef S) const
Definition: DebugStringTableSubsection.cpp:97
llvm::AMDGPU::VGPRIndexMode::Id
Id
Definition: SIDefines.h:221
llvm::codeview::DebugStringTableSubsectionRef::valid
bool valid() const
Definition: DebugStringTableSubsection.h:44
llvm::BinaryStreamRef
BinaryStreamRef is to BinaryStream what ArrayRef is to an Array.
Definition: BinaryStreamRef.h:156