blob: 69e67866946ce348279c40fa0e701c5394d4926d [file] [log] [blame]
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001//===- DWARFDebugAddr.h -------------------------------------*- C++ -*-===//
2//
Andrew Walbran16937d02019-10-22 13:54:20 +01003// 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
Andrew Scullcdfcccc2018-10-05 20:58:37 +01006//
7//===------------------------------------------------------------------===//
8
9#ifndef LLVM_DEBUGINFO_DWARFDEBUGADDR_H
10#define LLVM_DEBUGINFO_DWARFDEBUGADDR_H
11
12#include "llvm/BinaryFormat/Dwarf.h"
13#include "llvm/DebugInfo/DIContext.h"
14#include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h"
15#include "llvm/Support/Errc.h"
16#include "llvm/Support/Error.h"
17#include <cstdint>
18#include <map>
19#include <vector>
20
21namespace llvm {
22
23class Error;
24class 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.
29class DWARFDebugAddrTable {
Andrew Scullcdfcccc2018-10-05 20:58:37 +010030 dwarf::DwarfFormat Format;
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020031 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;
Andrew Scullcdfcccc2018-10-05 20:58:37 +010044 std::vector<uint64_t> Addrs;
45
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020046 /// Invalidate Length field to stop further processing.
47 void invalidateLength() { Length = 0; }
Andrew Scullcdfcccc2018-10-05 20:58:37 +010048
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020049 Error extractAddresses(const DWARFDataExtractor &Data, uint64_t *OffsetPtr,
50 uint64_t EndOffset);
51
52public:
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,
Andrew Scullcdfcccc2018-10-05 20:58:37 +010057 std::function<void(Error)> WarnCallback);
58
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020059 /// 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
Andrew Scullcdfcccc2018-10-05 20:58:37 +010069 void dump(raw_ostream &OS, DIDumpOptions DumpOpts = {}) const;
70
71 /// Return the address based on a given index.
72 Expected<uint64_t> getAddrEntry(uint32_t Index) const;
73
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020074 /// Return the full length of this table, including the length field.
75 /// Return None if the length cannot be identified reliably.
76 Optional<uint64_t> getFullLength() const;
Andrew Scullcdfcccc2018-10-05 20:58:37 +010077
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020078 /// Return the DWARF format of this table.
79 dwarf::DwarfFormat getFormat() const { return Format; }
Andrew Scullcdfcccc2018-10-05 20:58:37 +010080
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020081 /// Return the length of this table.
82 uint64_t getLength() const { return Length; }
Andrew Scullcdfcccc2018-10-05 20:58:37 +010083
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020084 /// Return the version of this table.
85 uint16_t getVersion() const { return Version; }
Andrew Scullcdfcccc2018-10-05 20:58:37 +010086
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020087 /// 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; }
Andrew Scullcdfcccc2018-10-05 20:58:37 +010095};
96
97} // end namespace llvm
98
99#endif // LLVM_DEBUGINFO_DWARFDEBUGADDR_H