LLVM 22.0.0git
SFrameParser.h
Go to the documentation of this file.
1//===- SFrameParser.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_OBJECT_SFRAME_H
10#define LLVM_OBJECT_SFRAME_H
11
12#include "llvm/ADT/ArrayRef.h"
16#include "llvm/Support/Error.h"
17#include <cstdint>
18
19namespace llvm {
20namespace object {
21
22template <endianness E> class SFrameParser {
24
25public:
27 uint64_t SectionAddress);
28
29 const sframe::Preamble<E> &getPreamble() const { return Header.Preamble; }
30 const sframe::Header<E> &getHeader() const { return Header; }
31
33
34 bool usesFixedRAOffset() const {
35 return getHeader().ABIArch == sframe::ABI::AMD64EndianLittle;
36 }
37 bool usesFixedFPOffset() const {
38 return false; // Not used in any currently defined ABI.
39 }
40
43
44 // Decodes the start address of the given FDE, which must be one of the
45 // objects returned by the `fdes()` function.
47
48 // Returns the offset (in the SFrame section) of the given FDE, which must be
49 // one of the objects returned by the `fdes()` function.
50 uint64_t offsetOf(typename FDERange::iterator FDE) const;
51
56 };
57
60 Error &Err) const;
61
62 std::optional<int32_t> getCFAOffset(const FrameRowEntry &FRE) const;
63 std::optional<int32_t> getRAOffset(const FrameRowEntry &FRE) const;
64 std::optional<int32_t> getFPOffset(const FrameRowEntry &FRE) const;
66
67private:
69 uint64_t SectionAddress;
70 const sframe::Header<E> &Header;
71
72 SFrameParser(ArrayRef<uint8_t> Data, uint64_t SectionAddress,
73 const sframe::Header<E> &Header)
74 : Data(Data), SectionAddress(SectionAddress), Header(Header) {}
75
76 uint64_t getFDEBase() const {
77 return sizeof(Header) + Header.AuxHdrLen + Header.FDEOff;
78 }
79
80 uint64_t getFREBase() const {
81 return getFDEBase() + Header.NumFDEs * sizeof(sframe::FuncDescEntry<E>);
82 }
83};
84
85template <endianness E> class SFrameParser<E>::FallibleFREIterator {
86public:
87 // NB: This iterator starts out in the before_begin() state. It must be
88 // ++'ed to reach the first element.
91 : Data(Data), FREType(FREType), Idx(Idx), Size(Size), Offset(Offset) {}
92
93 Error inc();
94 const FrameRowEntry &operator*() const { return FRE; }
95
97 const FallibleFREIterator &RHS) {
98 assert(LHS.Data.data() == RHS.Data.data());
99 assert(LHS.Data.size() == RHS.Data.size());
100 assert(LHS.FREType == RHS.FREType);
101 assert(LHS.Size == RHS.Size);
102 return LHS.Idx == RHS.Idx;
103 }
104
105private:
107 sframe::FREType FREType;
111 FrameRowEntry FRE;
112};
113
116
117} // end namespace object
118} // end namespace llvm
119
120#endif // LLVM_OBJECT_SFRAME_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_TEMPLATE_ABI
Definition: Compiler.h:214
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
uint64_t Size
This file contains data-structure definitions and constants to support unwinding based on ....
Value * RHS
Value * LHS
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
Lightweight error class with error context and mandatory checking.
Definition: Error.h:159
Tagged union holding either a T or a Error.
Definition: Error.h:485
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1197
A wrapper class for fallible iterators.
A range adaptor for a pair of iterators.
const FrameRowEntry & operator*() const
Definition: SFrameParser.h:94
FallibleFREIterator(ArrayRef< uint8_t > Data, sframe::FREType FREType, uint32_t Idx, uint32_t Size, uint64_t Offset)
Definition: SFrameParser.h:89
friend bool operator==(const FallibleFREIterator &LHS, const FallibleFREIterator &RHS)
Definition: SFrameParser.h:96
Expected< ArrayRef< uint8_t > > getAuxHeader() const
std::optional< int32_t > getRAOffset(const FrameRowEntry &FRE) const
static Expected< SFrameParser > create(ArrayRef< uint8_t > Contents, uint64_t SectionAddress)
bool usesFixedFPOffset() const
Definition: SFrameParser.h:37
bool usesFixedRAOffset() const
Definition: SFrameParser.h:34
const sframe::Preamble< E > & getPreamble() const
Definition: SFrameParser.h:29
std::optional< int32_t > getCFAOffset(const FrameRowEntry &FRE) const
iterator_range< fre_iterator > fres(const sframe::FuncDescEntry< E > &FDE, Error &Err) const
std::optional< int32_t > getFPOffset(const FrameRowEntry &FRE) const
const sframe::Header< E > & getHeader() const
Definition: SFrameParser.h:30
uint64_t offsetOf(typename FDERange::iterator FDE) const
ArrayRef< int32_t > getExtraOffsets(const FrameRowEntry &FRE) const
uint64_t getAbsoluteStartAddress(typename FDERange::iterator FDE) const
Expected< FDERange > fdes() const
FREType
SFrame FRE Types. Bits 0-3 of FuncDescEntry.Info.
Definition: SFrame.h:52
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:477
SmallVector< int32_t, 3 > Offsets
Definition: SFrameParser.h:55
sframe::FREInfo< endianness::native > Info
Definition: SFrameParser.h:54