LLVM 23.0.0git
DWARFDebugRangeList.cpp
Go to the documentation of this file.
1//===- DWARFDebugRangesList.cpp -------------------------------------------===//
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
11#include "llvm/Support/Errc.h"
12#include "llvm/Support/Format.h"
15#include <cinttypes>
16#include <cstdint>
17
18using namespace llvm;
19
25
27 Offset = -1ULL;
28 AddressSize = 0;
29 Entries.clear();
30}
31
33 uint64_t *offset_ptr) {
34 clear();
35 if (!data.isValidOffset(*offset_ptr))
37 "invalid range list offset 0x%" PRIx64, *offset_ptr);
38
39 AddressSize = data.getAddressSize();
41 AddressSize, errc::invalid_argument,
42 "range list at offset 0x%" PRIx64, *offset_ptr))
43 return SizeErr;
44 Offset = *offset_ptr;
45 while (true) {
46 RangeListEntry Entry;
47 Entry.SectionIndex = -1ULL;
48
49 uint64_t prev_offset = *offset_ptr;
50 Entry.StartAddress = data.getRelocatedAddress(offset_ptr);
51 Entry.EndAddress =
52 data.getRelocatedAddress(offset_ptr, &Entry.SectionIndex);
53
54 // Check that both values were extracted correctly.
55 if (*offset_ptr != prev_offset + 2 * AddressSize) {
56 clear();
58 "invalid range list entry at offset 0x%" PRIx64,
59 prev_offset);
60 }
61 if (Entry.isEndOfListEntry())
62 break;
63 Entries.push_back(Entry);
64 }
65 return Error::success();
66}
67
69 const char *AddrFmt;
70 switch (AddressSize) {
71 case 2:
72 AddrFmt = "{0:x-8} {1:x-4} {2:x-4}\n";
73 break;
74 case 4:
75 AddrFmt = "{0:x-8} {1:x-8} {2:x-8}\n";
76 break;
77 case 8:
78 AddrFmt = "{0:x-8} {1:x-16} {2:x-16}\n";
79 break;
80 default:
81 llvm_unreachable("unsupported address size");
82 }
83 for (const RangeListEntry &RLE : Entries)
84 OS << formatv(AddrFmt, Offset, RLE.StartAddress, RLE.EndAddress);
85 OS << formatv("{0:x-8} <End of list>\n", Offset);
86}
87
89 std::optional<object::SectionedAddress> BaseAddr) const {
91 // debug_addr can't use the max integer tombstone because that's used for the
92 // base address specifier entry - so use max-1.
94 for (const RangeListEntry &RLE : Entries) {
95 if (RLE.isBaseAddressSelectionEntry(AddressSize)) {
96 BaseAddr = {RLE.EndAddress, RLE.SectionIndex};
97 continue;
98 }
99
101 E.LowPC = RLE.StartAddress;
102 if (E.LowPC == Tombstone)
103 continue;
104 E.HighPC = RLE.EndAddress;
105 E.SectionIndex = RLE.SectionIndex;
106 // Base address of a range list entry is determined by the closest preceding
107 // base address selection entry in the same range list. It defaults to the
108 // base address of the compilation unit if there is no such entry.
109 if (BaseAddr) {
110 if (BaseAddr->Address == Tombstone)
111 continue;
112 E.LowPC += BaseAddr->Address;
113 E.HighPC += BaseAddr->Address;
114 if (E.SectionIndex == -1ULL)
115 E.SectionIndex = BaseAddr->SectionIndex;
116 }
117 Res.push_back(E);
118 }
119 return Res;
120}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static Split data
LocallyHashedType DenseMapInfo< LocallyHashedType >::Tombstone
static Error checkAddressSizeSupported(unsigned AddressSize, std::error_code EC, char const *Fmt, const Ts &...Vals)
static bool isAddressSizeSupported(unsigned AddressSize)
A DWARFDataExtractor (typically for an in-memory copy of an object-file section) plus a relocation ma...
LLVM_ABI Error extract(const DWARFDataExtractor &data, uint64_t *offset_ptr)
LLVM_ABI DWARFAddressRangesVector getAbsoluteRanges(std::optional< object::SectionedAddress > BaseAddr) const
getAbsoluteRanges - Returns absolute address ranges defined by this range list.
LLVM_ABI void dump(raw_ostream &OS) const
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
static ErrorSuccess success()
Create a success value.
Definition Error.h:336
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
uint64_t computeTombstoneAddress(uint8_t AddressByteSize)
Definition Dwarf.h:1242
This is an optimization pass for GlobalISel generic memory operations.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition Error.h:1321
@ invalid_argument
Definition Errc.h:56
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
std::vector< DWARFAddressRange > DWARFAddressRangesVector
DWARFAddressRangesVector - represents a set of absolute address ranges.
uint64_t SectionIndex
A section index this range belongs to.
LLVM_ABI bool isBaseAddressSelectionEntry(uint8_t AddressSize) const
A base address selection entry consists of:
uint64_t StartAddress
A beginning address offset.