LLVM 20.0.0git
SymbolDeserializer.h
Go to the documentation of this file.
1//===- SymbolDeserializer.h -------------------------------------*- 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_SYMBOLDESERIALIZER_H
10#define LLVM_DEBUGINFO_CODEVIEW_SYMBOLDESERIALIZER_H
11
12#include "llvm/ADT/ArrayRef.h"
19#include "llvm/Support/Error.h"
20
21namespace llvm {
22namespace codeview {
23class SymbolVisitorDelegate;
25 struct MappingInfo {
26 MappingInfo(ArrayRef<uint8_t> RecordData, CodeViewContainer Container)
27 : Stream(RecordData, llvm::endianness::little), Reader(Stream),
28 Mapping(Reader, Container) {}
29
30 BinaryByteStream Stream;
31 BinaryStreamReader Reader;
32 SymbolRecordMapping Mapping;
33 };
34
35public:
36 template <typename T> static Error deserializeAs(CVSymbol Symbol, T &Record) {
37 // If we're just deserializing one record, then don't worry about alignment
38 // as there's nothing that comes after.
40 if (auto EC = S.visitSymbolBegin(Symbol))
41 return EC;
42 if (auto EC = S.visitKnownRecord(Symbol, Record))
43 return EC;
44 if (auto EC = S.visitSymbolEnd(Symbol))
45 return EC;
46 return Error::success();
47 }
48 template <typename T> static Expected<T> deserializeAs(CVSymbol Symbol) {
49 T Record(static_cast<SymbolRecordKind>(Symbol.kind()));
50 if (auto EC = deserializeAs<T>(Symbol, Record))
51 return std::move(EC);
52 return Record;
53 }
54
56 CodeViewContainer Container)
57 : Delegate(Delegate), Container(Container) {}
58
61 }
62
64 assert(!Mapping && "Already in a symbol mapping!");
65 Mapping = std::make_unique<MappingInfo>(Record.content(), Container);
66 return Mapping->Mapping.visitSymbolBegin(Record);
67 }
69 assert(Mapping && "Not in a symbol mapping!");
70 auto EC = Mapping->Mapping.visitSymbolEnd(Record);
71 Mapping.reset();
72 return EC;
73 }
74
75#define SYMBOL_RECORD(EnumName, EnumVal, Name) \
76 Error visitKnownRecord(CVSymbol &CVR, Name &Record) override { \
77 return visitKnownRecordImpl(CVR, Record); \
78 }
79#define SYMBOL_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
80#include "llvm/DebugInfo/CodeView/CodeViewSymbols.def"
81
82private:
83 template <typename T> Error visitKnownRecordImpl(CVSymbol &CVR, T &Record) {
84
85 Record.RecordOffset =
86 Delegate ? Delegate->getRecordOffset(Mapping->Reader) : 0;
87 if (auto EC = Mapping->Mapping.visitKnownRecord(CVR, Record))
88 return EC;
89 return Error::success();
90 }
91
92 SymbolVisitorDelegate *Delegate;
93 CodeViewContainer Container;
94 std::unique_ptr<MappingInfo> Mapping;
95};
96}
97}
98
99#endif
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
An implementation of BinaryStream which holds its entire data set in a single contiguous buffer.
Provides read only access to a subclass of BinaryStream.
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
static ErrorSuccess success()
Create a success value.
Definition: Error.h:337
Tagged union holding either a T or a Error.
Definition: Error.h:481
CVRecord is a fat pointer (base + size pair) to a symbol or type record.
Definition: CVRecord.h:29
Error visitSymbolBegin(CVSymbol &Record) override
static Error deserializeAs(CVSymbol Symbol, T &Record)
SymbolDeserializer(SymbolVisitorDelegate *Delegate, CodeViewContainer Container)
Error visitSymbolEnd(CVSymbol &Record) override
Error visitSymbolBegin(CVSymbol &Record, uint32_t Offset) override
Paired begin/end actions for all symbols.
static Expected< T > deserializeAs(CVSymbol Symbol)
virtual uint32_t getRecordOffset(BinaryStreamReader Reader)=0
SymbolRecordKind
Distinguishes individual records in the Symbols subsection of a .debug$S section.
Definition: CodeView.h:41
CVRecord< SymbolKind > CVSymbol
Definition: CVRecord.h:65
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:480