Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 1 | //===- DWARFDebugLoc.h ------------------------------------------*- C++ -*-===// |
| 2 | // |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 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 |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef LLVM_DEBUGINFO_DWARF_DWARFDEBUGLOC_H |
| 10 | #define LLVM_DEBUGINFO_DWARF_DWARFDEBUGLOC_H |
| 11 | |
| 12 | #include "llvm/ADT/Optional.h" |
| 13 | #include "llvm/ADT/SmallVector.h" |
| 14 | #include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h" |
| 15 | #include "llvm/DebugInfo/DWARF/DWARFRelocMap.h" |
| 16 | #include <cstdint> |
| 17 | |
| 18 | namespace llvm { |
| 19 | class DWARFUnit; |
| 20 | class MCRegisterInfo; |
| 21 | class raw_ostream; |
| 22 | |
| 23 | class DWARFDebugLoc { |
| 24 | public: |
| 25 | /// A single location within a location list. |
| 26 | struct Entry { |
| 27 | /// The beginning address of the instruction range. |
| 28 | uint64_t Begin; |
| 29 | /// The ending address of the instruction range. |
| 30 | uint64_t End; |
| 31 | /// The location of the variable within the specified range. |
| 32 | SmallVector<char, 4> Loc; |
| 33 | }; |
| 34 | |
| 35 | /// A list of locations that contain one variable. |
| 36 | struct LocationList { |
| 37 | /// The beginning offset where this location list is stored in the debug_loc |
| 38 | /// section. |
| 39 | unsigned Offset; |
| 40 | /// All the locations in which the variable is stored. |
| 41 | SmallVector<Entry, 2> Entries; |
| 42 | /// Dump this list on OS. |
| 43 | void dump(raw_ostream &OS, bool IsLittleEndian, unsigned AddressSize, |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 44 | const MCRegisterInfo *MRI, DWARFUnit *U, uint64_t BaseAddress, |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 45 | unsigned Indent) const; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | private: |
| 49 | using LocationLists = SmallVector<LocationList, 4>; |
| 50 | |
| 51 | /// A list of all the variables in the debug_loc section, each one describing |
| 52 | /// the locations in which the variable is stored. |
| 53 | LocationLists Locations; |
| 54 | |
| 55 | unsigned AddressSize; |
| 56 | |
| 57 | bool IsLittleEndian; |
| 58 | |
| 59 | public: |
| 60 | /// Print the location lists found within the debug_loc section. |
| 61 | void dump(raw_ostream &OS, const MCRegisterInfo *RegInfo, |
| 62 | Optional<uint64_t> Offset) const; |
| 63 | |
| 64 | /// Parse the debug_loc section accessible via the 'data' parameter using the |
| 65 | /// address size also given in 'data' to interpret the address ranges. |
| 66 | void parse(const DWARFDataExtractor &data); |
| 67 | |
| 68 | /// Return the location list at the given offset or nullptr. |
| 69 | LocationList const *getLocationListAtOffset(uint64_t Offset) const; |
| 70 | |
| 71 | Optional<LocationList> parseOneLocationList(DWARFDataExtractor Data, |
| 72 | uint32_t *Offset); |
| 73 | }; |
| 74 | |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 75 | class DWARFDebugLoclists { |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 76 | public: |
| 77 | struct Entry { |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 78 | uint8_t Kind; |
| 79 | uint64_t Value0; |
| 80 | uint64_t Value1; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 81 | SmallVector<char, 4> Loc; |
| 82 | }; |
| 83 | |
| 84 | struct LocationList { |
| 85 | unsigned Offset; |
| 86 | SmallVector<Entry, 2> Entries; |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 87 | void dump(raw_ostream &OS, uint64_t BaseAddr, bool IsLittleEndian, |
| 88 | unsigned AddressSize, const MCRegisterInfo *RegInfo, |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 89 | DWARFUnit *U, unsigned Indent) const; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | private: |
| 93 | using LocationLists = SmallVector<LocationList, 4>; |
| 94 | |
| 95 | LocationLists Locations; |
| 96 | |
| 97 | unsigned AddressSize; |
| 98 | |
| 99 | bool IsLittleEndian; |
| 100 | |
| 101 | public: |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 102 | void parse(DataExtractor data, unsigned Version); |
| 103 | void dump(raw_ostream &OS, uint64_t BaseAddr, const MCRegisterInfo *RegInfo, |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 104 | Optional<uint64_t> Offset) const; |
| 105 | |
| 106 | /// Return the location list at the given offset or nullptr. |
| 107 | LocationList const *getLocationListAtOffset(uint64_t Offset) const; |
| 108 | |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 109 | static Optional<LocationList> |
| 110 | parseOneLocationList(DataExtractor Data, unsigned *Offset, unsigned Version); |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 111 | }; |
| 112 | |
| 113 | } // end namespace llvm |
| 114 | |
| 115 | #endif // LLVM_DEBUGINFO_DWARF_DWARFDEBUGLOC_H |