Movatterモバイル変換


[0]ホーム

URL:


LLVM 20.0.0git
DebugStringTableSubsection.cpp
Go to the documentation of this file.
1//===- DebugStringTableSubsection.cpp - CodeView String Table -------------===//
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#include "llvm/DebugInfo/CodeView/DebugStringTableSubsection.h"
10#include "llvm/ADT/StringRef.h"
11#include "llvm/DebugInfo/CodeView/CodeView.h"
12#include "llvm/Support/BinaryStreamReader.h"
13#include "llvm/Support/BinaryStreamWriter.h"
14#include "llvm/Support/Error.h"
15#include <cassert>
16#include <cstdint>
17
18using namespacellvm;
19using namespacellvm::codeview;
20
21DebugStringTableSubsectionRef::DebugStringTableSubsectionRef()
22 :DebugSubsectionRef(DebugSubsectionKind::StringTable) {}
23
24ErrorDebugStringTableSubsectionRef::initialize(BinaryStreamRef Contents) {
25 Stream = Contents;
26returnError::success();
27}
28
29ErrorDebugStringTableSubsectionRef::initialize(BinaryStreamReader &Reader) {
30return Reader.readStreamRef(Stream);
31}
32
33Expected<StringRef>
34DebugStringTableSubsectionRef::getString(uint32_tOffset) const{
35BinaryStreamReader Reader(Stream);
36 Reader.setOffset(Offset);
37StringRef Result;
38if (autoEC = Reader.readCString(Result))
39return std::move(EC);
40return Result;
41}
42
43DebugStringTableSubsection::DebugStringTableSubsection()
44 :DebugSubsection(DebugSubsectionKind::StringTable) {}
45
46uint32_tDebugStringTableSubsection::insert(StringRef S) {
47autoP = StringToId.insert({S, StringSize});
48
49// If a given string didn't exist in the string table, we want to increment
50// the string table size and insert it into the reverse lookup.
51if (P.second) {
52 IdToString.insert({P.first->getValue(),P.first->getKey()});
53 StringSize += S.size() + 1;// +1 for '\0'
54 }
55
56returnP.first->second;
57}
58
59uint32_tDebugStringTableSubsection::calculateSerializedSize() const{
60return StringSize;
61}
62
63ErrorDebugStringTableSubsection::commit(BinaryStreamWriter &Writer) const{
64uint32_t Begin = Writer.getOffset();
65uint32_tEnd = Begin + StringSize;
66
67// Write a null string at the beginning.
68if (autoEC = Writer.writeCString(StringRef()))
69returnEC;
70
71for (auto &Pair : StringToId) {
72StringRef S = Pair.getKey();
73uint32_tOffset = Begin + Pair.getValue();
74 Writer.setOffset(Offset);
75if (autoEC = Writer.writeCString(S))
76returnEC;
77assert(Writer.getOffset() <=End);
78 }
79
80 Writer.setOffset(End);
81assert((End - Begin) == StringSize);
82returnError::success();
83}
84
85uint32_tDebugStringTableSubsection::size() const{return StringToId.size(); }
86
87std::vector<uint32_t>DebugStringTableSubsection::sortedIds() const{
88 std::vector<uint32_t> Result;
89 Result.reserve(IdToString.size());
90for (constauto &Entry : IdToString)
91 Result.push_back(Entry.first);
92llvm::sort(Result);
93return Result;
94}
95
96uint32_tDebugStringTableSubsection::getIdForString(StringRef S) const{
97auto Iter = StringToId.find(S);
98assert(Iter != StringToId.end());
99return Iter->second;
100}
101
102StringRefDebugStringTableSubsection::getStringForId(uint32_t Id) const{
103auto Iter = IdToString.find(Id);
104assert(Iter != IdToString.end());
105return Iter->second;
106}
BinaryStreamReader.h
BinaryStreamWriter.h
CodeView.h
DebugStringTableSubsection.h
End
bool End
Definition:ELF_riscv.cpp:480
P
#define P(N)
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
StringRef.h
llvm::BinaryStreamReader
Provides read only access to a subclass of BinaryStream.
Definition:BinaryStreamReader.h:29
llvm::BinaryStreamReader::readStreamRef
Error readStreamRef(BinaryStreamRef &Ref)
Read the entire remainder of the underlying stream into Ref.
Definition:BinaryStreamReader.cpp:129
llvm::BinaryStreamReader::readCString
Error readCString(StringRef &Dest)
Read a null terminated string from Dest.
Definition:BinaryStreamReader.cpp:73
llvm::BinaryStreamReader::setOffset
void setOffset(uint64_t Off)
Definition:BinaryStreamReader.h:245
llvm::BinaryStreamRef
BinaryStreamRef is to BinaryStream what ArrayRef is to an Array.
Definition:BinaryStreamRef.h:154
llvm::BinaryStreamWriter
Provides write only access to a subclass of WritableBinaryStream.
Definition:BinaryStreamWriter.h:30
llvm::BinaryStreamWriter::writeCString
Error writeCString(StringRef Str)
Write the string Str to the underlying stream followed by a null terminator.
Definition:BinaryStreamWriter.cpp:47
llvm::BinaryStreamWriter::getOffset
uint64_t getOffset() const
Definition:BinaryStreamWriter.h:177
llvm::BinaryStreamWriter::setOffset
void setOffset(uint64_t Off)
Definition:BinaryStreamWriter.h:176
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition:Error.h:160
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition:Error.h:337
llvm::Expected
Tagged union holding either a T or a Error.
Definition:Error.h:481
llvm::StringMapImpl::size
unsigned size() const
Definition:StringMap.h:104
llvm::StringMap::end
iterator end()
Definition:StringMap.h:220
llvm::StringMap::find
iterator find(StringRef Key)
Definition:StringMap.h:233
llvm::StringMap::insert
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
Definition:StringMap.h:308
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition:StringRef.h:51
llvm::StringRef::size
constexpr size_t size() const
size - Get the string size.
Definition:StringRef.h:150
llvm::StringTable
A table of densely packed, null-terminated strings indexed by offset.
Definition:StringTable.h:33
llvm::codeview::DebugStringTableSubsectionRef::getString
Expected< StringRef > getString(uint32_t Offset) const
Definition:DebugStringTableSubsection.cpp:34
llvm::codeview::DebugStringTableSubsectionRef::DebugStringTableSubsectionRef
DebugStringTableSubsectionRef()
Definition:DebugStringTableSubsection.cpp:21
llvm::codeview::DebugStringTableSubsectionRef::initialize
Error initialize(BinaryStreamRef Contents)
Definition:DebugStringTableSubsection.cpp:24
llvm::codeview::DebugStringTableSubsection::DebugStringTableSubsection
DebugStringTableSubsection()
Definition:DebugStringTableSubsection.cpp:43
llvm::codeview::DebugStringTableSubsection::getStringForId
StringRef getStringForId(uint32_t Id) const
Definition:DebugStringTableSubsection.cpp:102
llvm::codeview::DebugStringTableSubsection::size
uint32_t size() const
Definition:DebugStringTableSubsection.cpp:85
llvm::codeview::DebugStringTableSubsection::calculateSerializedSize
uint32_t calculateSerializedSize() const override
Definition:DebugStringTableSubsection.cpp:59
llvm::codeview::DebugStringTableSubsection::getIdForString
uint32_t getIdForString(StringRef S) const
Definition:DebugStringTableSubsection.cpp:96
llvm::codeview::DebugStringTableSubsection::insert
uint32_t insert(StringRef S)
Definition:DebugStringTableSubsection.cpp:46
llvm::codeview::DebugStringTableSubsection::commit
Error commit(BinaryStreamWriter &Writer) const override
Definition:DebugStringTableSubsection.cpp:63
llvm::codeview::DebugStringTableSubsection::sortedIds
std::vector< uint32_t > sortedIds() const
Definition:DebugStringTableSubsection.cpp:87
llvm::codeview::DebugSubsectionRef
Definition:DebugSubsection.h:21
llvm::codeview::DebugSubsection
Definition:DebugSubsection.h:34
uint32_t
Error.h
llvm::codeview
Definition:AppendingTypeTableBuilder.h:22
llvm::codeview::DebugSubsectionKind
DebugSubsectionKind
Definition:CodeView.h:322
llvm::codeview::CompileSym2Flags::EC
@ EC
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:AddressRanges.h:18
llvm::Offset
@ Offset
Definition:DWP.cpp:480
llvm::sort
void sort(IteratorTy Start, IteratorTy End)
Definition:STLExtras.h:1664

Generated on Fri Jul 18 2025 11:08:40 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp