[MIPS GlobalISel] Select MSA vector generic and builtin add
[llvm-complete.git] / lib / DebugInfo / DWARF / DWARFDebugArangeSet.cpp
blob200b2d52a02b9cb7ef860c216357833e4c28d8bf
1 //===- DWARFDebugArangeSet.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 //===----------------------------------------------------------------------===//
9 #include "llvm/DebugInfo/DWARF/DWARFDebugArangeSet.h"
10 #include "llvm/Support/Format.h"
11 #include "llvm/Support/raw_ostream.h"
12 #include <cassert>
13 #include <cinttypes>
14 #include <cstdint>
15 #include <cstring>
17 using namespace llvm;
19 void DWARFDebugArangeSet::Descriptor::dump(raw_ostream &OS,
20 uint32_t AddressSize) const {
21 OS << format("[0x%*.*" PRIx64 ", ", AddressSize * 2, AddressSize * 2, Address)
22 << format(" 0x%*.*" PRIx64 ")", AddressSize * 2, AddressSize * 2,
23 getEndAddress());
26 void DWARFDebugArangeSet::clear() {
27 Offset = -1ULL;
28 std::memset(&HeaderData, 0, sizeof(Header));
29 ArangeDescriptors.clear();
32 bool
33 DWARFDebugArangeSet::extract(DataExtractor data, uint64_t *offset_ptr) {
34 if (data.isValidOffset(*offset_ptr)) {
35 ArangeDescriptors.clear();
36 Offset = *offset_ptr;
38 // 7.20 Address Range Table
40 // Each set of entries in the table of address ranges contained in
41 // the .debug_aranges section begins with a header consisting of: a
42 // 4-byte length containing the length of the set of entries for this
43 // compilation unit, not including the length field itself; a 2-byte
44 // version identifier containing the value 2 for DWARF Version 2; a
45 // 4-byte offset into the.debug_infosection; a 1-byte unsigned integer
46 // containing the size in bytes of an address (or the offset portion of
47 // an address for segmented addressing) on the target system; and a
48 // 1-byte unsigned integer containing the size in bytes of a segment
49 // descriptor on the target system. This header is followed by a series
50 // of tuples. Each tuple consists of an address and a length, each in
51 // the size appropriate for an address on the target architecture.
52 HeaderData.Length = data.getU32(offset_ptr);
53 HeaderData.Version = data.getU16(offset_ptr);
54 HeaderData.CuOffset = data.getU32(offset_ptr);
55 HeaderData.AddrSize = data.getU8(offset_ptr);
56 HeaderData.SegSize = data.getU8(offset_ptr);
58 // Perform basic validation of the header fields.
59 if (!data.isValidOffsetForDataOfSize(Offset, HeaderData.Length) ||
60 (HeaderData.AddrSize != 4 && HeaderData.AddrSize != 8)) {
61 clear();
62 return false;
65 // The first tuple following the header in each set begins at an offset
66 // that is a multiple of the size of a single tuple (that is, twice the
67 // size of an address). The header is padded, if necessary, to the
68 // appropriate boundary.
69 const uint32_t header_size = *offset_ptr - Offset;
70 const uint32_t tuple_size = HeaderData.AddrSize * 2;
71 uint32_t first_tuple_offset = 0;
72 while (first_tuple_offset < header_size)
73 first_tuple_offset += tuple_size;
75 *offset_ptr = Offset + first_tuple_offset;
77 Descriptor arangeDescriptor;
79 static_assert(sizeof(arangeDescriptor.Address) ==
80 sizeof(arangeDescriptor.Length),
81 "Different datatypes for addresses and sizes!");
82 assert(sizeof(arangeDescriptor.Address) >= HeaderData.AddrSize);
84 while (data.isValidOffset(*offset_ptr)) {
85 arangeDescriptor.Address = data.getUnsigned(offset_ptr, HeaderData.AddrSize);
86 arangeDescriptor.Length = data.getUnsigned(offset_ptr, HeaderData.AddrSize);
88 // Each set of tuples is terminated by a 0 for the address and 0
89 // for the length.
90 if (arangeDescriptor.Address || arangeDescriptor.Length)
91 ArangeDescriptors.push_back(arangeDescriptor);
92 else
93 break; // We are done if we get a zero address and length
96 return !ArangeDescriptors.empty();
98 return false;
101 void DWARFDebugArangeSet::dump(raw_ostream &OS) const {
102 OS << format("Address Range Header: length = 0x%8.8x, version = 0x%4.4x, ",
103 HeaderData.Length, HeaderData.Version)
104 << format("cu_offset = 0x%8.8x, addr_size = 0x%2.2x, seg_size = 0x%2.2x\n",
105 HeaderData.CuOffset, HeaderData.AddrSize, HeaderData.SegSize);
107 for (const auto &Desc : ArangeDescriptors) {
108 Desc.dump(OS, HeaderData.AddrSize);
109 OS << '\n';