LLVM  14.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 
21 namespace llvm {
22 namespace codeview {
23 class SymbolVisitorDelegate;
25  struct MappingInfo {
26  MappingInfo(ArrayRef<uint8_t> RecordData, CodeViewContainer Container)
27  : Stream(RecordData, llvm::support::little), Reader(Stream),
28  Mapping(Reader, Container) {}
29 
30  BinaryByteStream Stream;
31  BinaryStreamReader Reader;
32  SymbolRecordMapping Mapping;
33  };
34 
35 public:
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 
60  return visitSymbolBegin(Record);
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 
82 private:
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
BinaryStreamReader.h
SymbolRecordMapping.h
SymbolVisitorDelegate.h
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::codeview::SymbolVisitorDelegate
Definition: SymbolVisitorDelegate.h:23
BinaryByteStream.h
SymbolRecord.h
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:331
Error.h
T
#define T
Definition: Mips16ISelLowering.cpp:341
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
llvm::codeview::SymbolRecordMapping
Definition: SymbolRecordMapping.h:20
llvm::support::little
@ little
Definition: Endian.h:27
llvm::BinaryByteStream
An implementation of BinaryStream which holds its entire data set in a single contiguous buffer.
Definition: BinaryByteStream.h:31
llvm::codeview::CVSymbol
CVRecord< SymbolKind > CVSymbol
Definition: CVRecord.h:66
SymbolVisitorCallbacks.h
llvm::codeview::SymbolVisitorCallbacks
Definition: SymbolVisitorCallbacks.h:18
llvm::BinaryStreamReader
Provides read only access to a subclass of BinaryStream.
Definition: BinaryStreamReader.h:31
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
ArrayRef.h
llvm::codeview::SymbolDeserializer::visitSymbolBegin
Error visitSymbolBegin(CVSymbol &Record, uint32_t Offset) override
Paired begin/end actions for all symbols.
Definition: SymbolDeserializer.h:59
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::codeview::SymbolDeserializer::deserializeAs
static Error deserializeAs(CVSymbol Symbol, T &Record)
Definition: SymbolDeserializer.h:36
llvm::codeview::CompileSym2Flags::EC
@ EC
llvm::codeview::CodeViewContainer::ObjectFile
@ ObjectFile
llvm::Record
Definition: Record.h:1472
llvm::ArrayRef< uint8_t >
llvm::codeview::CVRecord
CVRecord is a fat pointer (base + size pair) to a symbol or type record.
Definition: CVRecord.h:30
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::SymbolDeserializer::deserializeAs
static Expected< T > deserializeAs(CVSymbol Symbol)
Definition: SymbolDeserializer.h:48
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::codeview::SymbolVisitorDelegate::getRecordOffset
virtual uint32_t getRecordOffset(BinaryStreamReader Reader)=0
llvm::codeview::SymbolRecordKind
SymbolRecordKind
Distinguishes individual records in the Symbols subsection of a .debug$S section.
Definition: CodeView.h:40
llvm::codeview::SymbolDeserializer::visitSymbolBegin
Error visitSymbolBegin(CVSymbol &Record) override
Definition: SymbolDeserializer.h:63
llvm::codeview::SymbolDeserializer::visitSymbolEnd
Error visitSymbolEnd(CVSymbol &Record) override
Definition: SymbolDeserializer.h:68
llvm::codeview::SymbolDeserializer
Definition: SymbolDeserializer.h:24
llvm::ARMBuildAttrs::Symbol
@ Symbol
Definition: ARMBuildAttributes.h:79
llvm::codeview::CodeViewContainer
CodeViewContainer
Definition: CodeView.h:607
llvm::codeview::SymbolDeserializer::SymbolDeserializer
SymbolDeserializer(SymbolVisitorDelegate *Delegate, CodeViewContainer Container)
Definition: SymbolDeserializer.h:55