LLVM  14.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"
14 #include <cinttypes>
15 #include <cstdint>
16 
17 using namespace llvm;
18 
20  Offset = -1ULL;
21  AddressSize = 0;
22  Entries.clear();
23 }
24 
26  uint64_t *offset_ptr) {
27  clear();
28  if (!data.isValidOffset(*offset_ptr))
30  "invalid range list offset 0x%" PRIx64, *offset_ptr);
31 
32  AddressSize = data.getAddressSize();
33  if (AddressSize != 4 && AddressSize != 8)
35  "invalid address size: %" PRIu8, AddressSize);
36  Offset = *offset_ptr;
37  while (true) {
38  RangeListEntry Entry;
39  Entry.SectionIndex = -1ULL;
40 
41  uint64_t prev_offset = *offset_ptr;
42  Entry.StartAddress = data.getRelocatedAddress(offset_ptr);
43  Entry.EndAddress =
44  data.getRelocatedAddress(offset_ptr, &Entry.SectionIndex);
45 
46  // Check that both values were extracted correctly.
47  if (*offset_ptr != prev_offset + 2 * AddressSize) {
48  clear();
50  "invalid range list entry at offset 0x%" PRIx64,
51  prev_offset);
52  }
53  if (Entry.isEndOfListEntry())
54  break;
55  Entries.push_back(Entry);
56  }
57  return Error::success();
58 }
59 
61  for (const RangeListEntry &RLE : Entries) {
62  const char *format_str =
63  (AddressSize == 4 ? "%08" PRIx64 " %08" PRIx64 " %08" PRIx64 "\n"
64  : "%08" PRIx64 " %016" PRIx64 " %016" PRIx64 "\n");
65  OS << format(format_str, Offset, RLE.StartAddress, RLE.EndAddress);
66  }
67  OS << format("%08" PRIx64 " <End of list>\n", Offset);
68 }
69 
73  // debug_addr can't use the max integer tombstone because that's used for the
74  // base address specifier entry - so use max-1.
75  uint64_t Tombstone = dwarf::computeTombstoneAddress(AddressSize) - 1;
76  for (const RangeListEntry &RLE : Entries) {
77  if (RLE.isBaseAddressSelectionEntry(AddressSize)) {
78  BaseAddr = {RLE.EndAddress, RLE.SectionIndex};
79  continue;
80  }
81 
83  E.LowPC = RLE.StartAddress;
84  if (E.LowPC == Tombstone)
85  continue;
86  E.HighPC = RLE.EndAddress;
87  E.SectionIndex = RLE.SectionIndex;
88  // Base address of a range list entry is determined by the closest preceding
89  // base address selection entry in the same range list. It defaults to the
90  // base address of the compilation unit if there is no such entry.
91  if (BaseAddr) {
92  if (BaseAddr->Address == Tombstone)
93  continue;
94  E.LowPC += BaseAddr->Address;
95  E.HighPC += BaseAddr->Address;
96  if (E.SectionIndex == -1ULL)
97  E.SectionIndex = BaseAddr->SectionIndex;
98  }
99  Res.push_back(E);
100  }
101  return Res;
102 }
llvm::errc::invalid_argument
@ invalid_argument
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::DWARFDebugRangeList::clear
void clear()
Definition: DWARFDebugRangeList.cpp:19
llvm::object::SectionedAddress::Address
uint64_t Address
Definition: ObjectFile.h:147
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:331
DWARFContext.h
Errc.h
llvm::Optional
Definition: APInt.h:33
llvm::DWARFDataExtractor
A DataExtractor (typically for an in-memory copy of an object-file section) plus a relocation map for...
Definition: DWARFDataExtractor.h:21
Format.h
llvm::object::SectionedAddress::SectionIndex
uint64_t SectionIndex
Definition: ObjectFile.h:148
llvm::DWARFDataExtractor::getRelocatedAddress
uint64_t getRelocatedAddress(uint64_t *Off, uint64_t *SecIx=nullptr) const
Extracts an address-sized value and applies a relocation to the result if one exists for the given of...
Definition: DWARFDataExtractor.h:72
DWARFDebugRangeList.h
llvm::dwarf::computeTombstoneAddress
uint64_t computeTombstoneAddress(uint8_t AddressByteSize)
Definition: Dwarf.h:772
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::DataExtractor::getAddressSize
uint8_t getAddressSize() const
Get the address size for this extractor.
Definition: DataExtractor.h:96
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::DWARFDebugRangeList::extract
Error extract(const DWARFDataExtractor &data, uint64_t *offset_ptr)
Definition: DWARFDebugRangeList.cpp:25
uint64_t
llvm::DWARFDebugRangeList::RangeListEntry
Definition: DWARFDebugRangeList.h:24
llvm::DataExtractor::isValidOffset
bool isValidOffset(uint64_t offset) const
Test the validity of offset.
Definition: DataExtractor.h:662
llvm::DWARFDebugRangeList::getAbsoluteRanges
DWARFAddressRangesVector getAbsoluteRanges(llvm::Optional< object::SectionedAddress > BaseAddr) const
getAbsoluteRanges - Returns absolute address ranges defined by this range list.
Definition: DWARFDebugRangeList.cpp:70
llvm::format
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:124
llvm::DWARFAddressRangesVector
std::vector< DWARFAddressRange > DWARFAddressRangesVector
DWARFAddressRangesVector - represents a set of absolute address ranges.
Definition: DWARFAddressRange.h:83
llvm::createStringError
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition: Error.h:1231
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::DWARFAddressRange
Definition: DWARFAddressRange.h:22
raw_ostream.h
llvm::DWARFDebugRangeList::dump
void dump(raw_ostream &OS) const
Definition: DWARFDebugRangeList.cpp:60