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