LLVM  15.0.0git
DWARFDebugAddr.h
Go to the documentation of this file.
1 //===- DWARFDebugAddr.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_DWARF_DWARFDEBUGADDR_H
10 #define LLVM_DEBUGINFO_DWARF_DWARFDEBUGADDR_H
11 
14 #include "llvm/Support/Error.h"
15 #include <cstdint>
16 #include <vector>
17 
18 namespace llvm {
19 
20 class raw_ostream;
21 class DWARFDataExtractor;
22 
23 /// A class representing an address table as specified in DWARF v5.
24 /// The table consists of a header followed by an array of address values from
25 /// .debug_addr section.
27  dwarf::DwarfFormat Format;
28  uint64_t Offset;
29  /// The total length of the entries for this table, not including the length
30  /// field itself.
31  uint64_t Length = 0;
32  /// The DWARF version number.
33  uint16_t Version;
34  /// The size in bytes of an address on the target architecture. For
35  /// segmented addressing, this is the size of the offset portion of the
36  /// address.
37  uint8_t AddrSize;
38  /// The size in bytes of a segment selector on the target architecture.
39  /// If the target system uses a flat address space, this value is 0.
40  uint8_t SegSize;
41  std::vector<uint64_t> Addrs;
42 
43  /// Invalidate Length field to stop further processing.
44  void invalidateLength() { Length = 0; }
45 
46  Error extractAddresses(const DWARFDataExtractor &Data, uint64_t *OffsetPtr,
47  uint64_t EndOffset);
48 
49 public:
50 
51  /// Extract the entire table, including all addresses.
52  Error extract(const DWARFDataExtractor &Data, uint64_t *OffsetPtr,
53  uint16_t CUVersion, uint8_t CUAddrSize,
54  std::function<void(Error)> WarnCallback);
55 
56  /// Extract a DWARFv5 address table.
57  Error extractV5(const DWARFDataExtractor &Data, uint64_t *OffsetPtr,
58  uint8_t CUAddrSize, std::function<void(Error)> WarnCallback);
59 
60  /// Extract a pre-DWARFv5 address table. Such tables do not have a header
61  /// and consist only of a series of addresses.
62  /// See https://gcc.gnu.org/wiki/DebugFission for details.
64  uint16_t CUVersion, uint8_t CUAddrSize);
65 
66  void dump(raw_ostream &OS, DIDumpOptions DumpOpts = {}) const;
67 
68  /// Return the address based on a given index.
70 
71  /// Return the full length of this table, including the length field.
72  /// Return None if the length cannot be identified reliably.
74 
75  /// Return the DWARF format of this table.
76  dwarf::DwarfFormat getFormat() const { return Format; }
77 
78  /// Return the length of this table.
79  uint64_t getLength() const { return Length; }
80 
81  /// Return the version of this table.
82  uint16_t getVersion() const { return Version; }
83 
84  /// Return the address size of this table.
85  uint8_t getAddressSize() const { return AddrSize; }
86 
87  /// Return the segment selector size of this table.
88  uint8_t getSegmentSelectorSize() const { return SegSize; }
89 
90  /// Return the parsed addresses of this table.
91  ArrayRef<uint64_t> getAddressEntries() const { return Addrs; }
92 };
93 
94 } // end namespace llvm
95 
96 #endif // LLVM_DEBUGINFO_DWARF_DWARFDEBUGADDR_H
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::DWARFDebugAddrTable::getLength
uint64_t getLength() const
Return the length of this table.
Definition: DWARFDebugAddr.h:79
Error.h
llvm::Optional< uint64_t >
llvm::DWARFDebugAddrTable::extract
Error extract(const DWARFDataExtractor &Data, uint64_t *OffsetPtr, uint16_t CUVersion, uint8_t CUAddrSize, std::function< void(Error)> WarnCallback)
Extract the entire table, including all addresses.
Definition: DWARFDebugAddr.cpp:122
llvm::DWARFDebugAddrTable::getFullLength
Optional< uint64_t > getFullLength() const
Return the full length of this table, including the length field.
Definition: DWARFDebugAddr.cpp:180
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:41
llvm::DWARFDataExtractor
A DataExtractor (typically for an in-memory copy of an object-file section) plus a relocation map for...
Definition: DWARFDataExtractor.h:21
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
llvm::DWARFDebugAddrTable::extractPreStandard
Error extractPreStandard(const DWARFDataExtractor &Data, uint64_t *OffsetPtr, uint16_t CUVersion, uint8_t CUAddrSize)
Extract a pre-DWARFv5 address table.
Definition: DWARFDebugAddr.cpp:107
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:54
llvm::dwarf::DwarfFormat
DwarfFormat
Constants that define the DWARF format as 32 or 64 bit.
Definition: Dwarf.h:93
llvm::DWARFDebugAddrTable::getFormat
dwarf::DwarfFormat getFormat() const
Return the DWARF format of this table.
Definition: DWARFDebugAddr.h:76
uint64_t
llvm::DWARFDebugAddrTable
A class representing an address table as specified in DWARF v5.
Definition: DWARFDebugAddr.h:26
llvm::DWARFDebugAddrTable::getSegmentSelectorSize
uint8_t getSegmentSelectorSize() const
Return the segment selector size of this table.
Definition: DWARFDebugAddr.h:88
llvm::DWARFDebugAddrTable::getAddressSize
uint8_t getAddressSize() const
Return the address size of this table.
Definition: DWARFDebugAddr.h:85
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:82
llvm::ArrayRef< uint64_t >
Dwarf.h
uint32_t
DIContext.h
llvm::DWARFDebugAddrTable::dump
void dump(raw_ostream &OS, DIDumpOptions DumpOpts={}) const
Definition: DWARFDebugAddr.cpp:136
uint16_t
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
llvm::DWARFDebugAddrTable::getVersion
uint16_t getVersion() const
Return the version of this table.
Definition: DWARFDebugAddr.h:82
llvm::DWARFDebugAddrTable::getAddressEntries
ArrayRef< uint64_t > getAddressEntries() const
Return the parsed addresses of this table.
Definition: DWARFDebugAddr.h:91
llvm::DWARFDebugAddrTable::extractV5
Error extractV5(const DWARFDataExtractor &Data, uint64_t *OffsetPtr, uint8_t CUAddrSize, std::function< void(Error)> WarnCallback)
Extract a DWARFv5 address table.
Definition: DWARFDebugAddr.cpp:42
llvm::DWARFDebugAddrTable::getAddrEntry
Expected< uint64_t > getAddrEntry(uint32_t Index) const
Return the address based on a given index.
Definition: DWARFDebugAddr.cpp:171
llvm::DIDumpOptions
Container for dump options that control which debug information will be dumped.
Definition: DIContext.h:188