LLVM 20.0.0git
DebugChecksumsSubsection.cpp
Go to the documentation of this file.
1//===- DebugChecksumsSubsection.cpp ---------------------------------------===//
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
10#include "llvm/ADT/ArrayRef.h"
15#include "llvm/Support/Endian.h"
16#include "llvm/Support/Error.h"
18#include <cassert>
19#include <cstdint>
20#include <cstring>
21
22using namespace llvm;
23using namespace llvm::codeview;
24
27
28 ulittle32_t FileNameOffset; // Byte offset of filename in global string table.
29 uint8_t ChecksumSize; // Number of bytes of checksum.
30 uint8_t ChecksumKind; // FileChecksumKind
31 // Checksum bytes follow.
32};
33
36 BinaryStreamReader Reader(Stream);
37
38 const FileChecksumEntryHeader *Header;
39 if (auto EC = Reader.readObject(Header))
40 return EC;
41
42 Item.FileNameOffset = Header->FileNameOffset;
43 Item.Kind = static_cast<FileChecksumKind>(Header->ChecksumKind);
44 if (auto EC = Reader.readBytes(Item.Checksum, Header->ChecksumSize))
45 return EC;
46
47 Len = alignTo(Header->ChecksumSize + sizeof(FileChecksumEntryHeader), 4);
48 return Error::success();
49}
52 if (auto EC = Reader.readArray(Checksums, Reader.bytesRemaining()))
53 return EC;
54
55 return Error::success();
56}
57
59 BinaryStreamReader Reader(Section);
60 return initialize(Reader);
61}
62
66
69 ArrayRef<uint8_t> Bytes) {
71 if (!Bytes.empty()) {
72 uint8_t *Copy = Storage.Allocate<uint8_t>(Bytes.size());
73 ::memcpy(Copy, Bytes.data(), Bytes.size());
74 Entry.Checksum = ArrayRef(Copy, Bytes.size());
75 }
76
77 Entry.FileNameOffset = Strings.insert(FileName);
78 Entry.Kind = Kind;
79 Checksums.push_back(Entry);
80
81 // This maps the offset of this string in the string table to the offset
82 // of this checksum entry in the checksum buffer.
83 OffsetMap[Entry.FileNameOffset] = SerializedSize;
84 assert(SerializedSize % 4 == 0);
85
86 uint32_t Len = alignTo(sizeof(FileChecksumEntryHeader) + Bytes.size(), 4);
87 SerializedSize += Len;
88}
89
91 return SerializedSize;
92}
93
95 for (const auto &FC : Checksums) {
97 Header.ChecksumKind = uint8_t(FC.Kind);
98 Header.ChecksumSize = FC.Checksum.size();
99 Header.FileNameOffset = FC.FileNameOffset;
100 if (auto EC = Writer.writeObject(Header))
101 return EC;
102 if (auto EC = Writer.writeArray(ArrayRef(FC.Checksum)))
103 return EC;
104 if (auto EC = Writer.padToAlignment(4))
105 return EC;
106 }
107 return Error::success();
108}
109
111 uint32_t Offset = Strings.getIdForString(FileName);
112 auto Iter = OffsetMap.find(Offset);
113 assert(Iter != OffsetMap.end());
114 return Iter->second;
115}
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:165
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:160
const T * data() const
Definition: ArrayRef.h:162
Provides read only access to a subclass of BinaryStream.
Error readObject(const T *&Dest)
Get a pointer to an object of type T from the underlying stream, as if by memcpy, and store the resul...
Error readBytes(ArrayRef< uint8_t > &Buffer, uint32_t Size)
Read Size bytes from the underlying stream at the current offset and and set Buffer to the resulting ...
uint64_t bytesRemaining() const
Error readArray(ArrayRef< T > &Array, uint32_t NumElements)
Get a reference to a NumElements element array of objects of type T from the underlying stream as if ...
BinaryStreamRef is to BinaryStream what ArrayRef is to an Array.
Provides write only access to a subclass of WritableBinaryStream.
Error writeArray(ArrayRef< T > Array)
Writes an array of objects of type T to the underlying stream, as if by using memcpy.
Error writeObject(const T &Obj)
Writes the object Obj to the underlying stream, as if by using memcpy.
Error padToAlignment(uint32_t Align)
LLVM_ATTRIBUTE_RETURNS_NONNULL void * Allocate(size_t Size, Align Alignment)
Allocate space at the specified alignment.
Definition: Allocator.h:148
iterator find(const_arg_type_t< KeyT > Val)
Definition: DenseMap.h:155
iterator end()
Definition: DenseMap.h:84
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
static ErrorSuccess success()
Create a success value.
Definition: Error.h:337
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
Error commit(BinaryStreamWriter &Writer) const override
uint32_t mapChecksumOffset(StringRef FileName) const
void addChecksum(StringRef FileName, FileChecksumKind Kind, ArrayRef< uint8_t > Bytes)
DebugChecksumsSubsection(DebugStringTableSubsection &Strings)
Represents a read-write view of a CodeView string table.
detail::packed_endian_specific_integral< uint32_t, llvm::endianness::little, unaligned > ulittle32_t
Definition: Endian.h:285
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:480
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition: Alignment.h:155
Error operator()(BinaryStreamRef Stream, uint32_t &Len, T &Item) const =delete