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