1 | //===- ExtractRanges.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_GSYM_EXTRACTRANGES_H |
10 | #define |
11 | |
12 | #include "llvm/ADT/AddressRanges.h" |
13 | #include "llvm/Support/Format.h" |
14 | #include "llvm/Support/raw_ostream.h" |
15 | #include <stdint.h> |
16 | |
17 | #define HEX8(v) llvm::format_hex(v, 4) |
18 | #define HEX16(v) llvm::format_hex(v, 6) |
19 | #define HEX32(v) llvm::format_hex(v, 10) |
20 | #define HEX64(v) llvm::format_hex(v, 18) |
21 | |
22 | namespace llvm { |
23 | class ; |
24 | class raw_ostream; |
25 | |
26 | namespace gsym { |
27 | |
28 | class FileWriter; |
29 | |
30 | /// AddressRange objects are encoded and decoded to be relative to a base |
31 | /// address. This will be the FunctionInfo's start address if the AddressRange |
32 | /// is directly contained in a FunctionInfo, or a base address of the |
33 | /// containing parent AddressRange or AddressRanges. This allows address |
34 | /// ranges to be efficiently encoded using ULEB128 encodings as we encode the |
35 | /// offset and size of each range instead of full addresses. This also makes |
36 | /// encoded addresses easy to relocate as we just need to relocate one base |
37 | /// address. |
38 | /// @{ |
39 | AddressRange (DataExtractor &Data, uint64_t BaseAddr, |
40 | uint64_t &Offset); |
41 | void encodeRange(const AddressRange &Range, FileWriter &O, uint64_t BaseAddr); |
42 | /// @} |
43 | |
44 | /// Skip an address range object in the specified data a the specified |
45 | /// offset. |
46 | /// |
47 | /// \param Data The binary stream to read the data from. |
48 | /// |
49 | /// \param Offset The byte offset within \a Data. |
50 | void (DataExtractor &Data, uint64_t &Offset); |
51 | |
52 | /// Address ranges are decoded and encoded to be relative to a base address. |
53 | /// See the AddressRange comment for the encode and decode methods for full |
54 | /// details. |
55 | /// @{ |
56 | void (AddressRanges &Ranges, DataExtractor &Data, uint64_t BaseAddr, |
57 | uint64_t &Offset); |
58 | void encodeRanges(const AddressRanges &Ranges, FileWriter &O, |
59 | uint64_t BaseAddr); |
60 | /// @} |
61 | |
62 | /// Skip an address range object in the specified data a the specified |
63 | /// offset. |
64 | /// |
65 | /// \param Data The binary stream to read the data from. |
66 | /// |
67 | /// \param Offset The byte offset within \a Data. |
68 | /// |
69 | /// \returns The number of address ranges that were skipped. |
70 | uint64_t (DataExtractor &Data, uint64_t &Offset); |
71 | |
72 | } // namespace gsym |
73 | |
74 | raw_ostream &operator<<(raw_ostream &OS, const AddressRange &R); |
75 | |
76 | raw_ostream &operator<<(raw_ostream &OS, const AddressRanges &AR); |
77 | |
78 | } // namespace llvm |
79 | |
80 | #endif // LLVM_DEBUGINFO_GSYM_EXTRACTRANGES_H |
81 | |