//===- bolt/Core/DebugData.h - Debugging information handling ---*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file contains declaration of classes that represent and serialize // DWARF-related entities. // //===----------------------------------------------------------------------===// #ifndef BOLT_CORE_DEBUG_DATA_H #define BOLT_CORE_DEBUG_DATA_H #include "llvm/ADT/SmallVector.h" #include "llvm/CodeGen/DIE.h" #include "llvm/DebugInfo/DWARF/DWARFContext.h" #include "llvm/MC/MCDwarf.h" #include "llvm/Support/FormatVariadic.h" #include "llvm/Support/SMLoc.h" #include "llvm/Support/raw_ostream.h" #include <cstdint> #include <map> #include <memory> #include <mutex> #include <string> #include <unordered_map> #include <utility> #include <vector> #define DWARF2_FLAG_END_SEQUENCE … namespace llvm { namespace bolt { class DIEBuilder; struct AttrInfo { … }; /// Finds attributes FormValue and Offset. /// /// \param DIE die to look up in. /// \param AbbrevDecl abbrev declaration for the die. /// \param Index an index in Abbrev declaration entry. std::optional<AttrInfo> findAttributeInfo(const DWARFDie DIE, const DWARFAbbreviationDeclaration *AbbrevDecl, uint32_t Index); /// Finds attributes FormValue and Offset. /// /// \param DIE die to look up in. /// \param Attr the attribute to extract. /// \return an optional AttrInfo with DWARFFormValue and Offset. std::optional<AttrInfo> findAttributeInfo(const DWARFDie DIE, dwarf::Attribute Attr); // DWARF5 Header in order of encoding. // Types represent encoding sizes. UnitLengthType; VersionType; AddressSizeType; SegmentSelectorType; OffsetEntryCountType; /// Get DWARF5 Header size. /// Rangelists and Loclists have the same header. constexpr uint32_t getDWARF5RngListLocListHeaderSize() { … } class BinaryContext; /// Address range representation. Takes less space than DWARFAddressRange. struct DebugAddressRange { … }; static inline bool operator<(const DebugAddressRange &LHS, const DebugAddressRange &RHS) { … } inline raw_ostream &operator<<(raw_ostream &OS, const DebugAddressRange &Range) { … } /// DebugAddressRangesVector - represents a set of absolute address ranges. DebugAddressRangesVector; /// Address range with location used by .debug_loc section. /// More compact than DWARFLocationEntry and uses absolute addresses. struct DebugLocationEntry { … }; inline raw_ostream &operator<<(raw_ostream &OS, const DebugLocationEntry &Entry) { … } DebugLocationsVector; /// References a row in a DWARFDebugLine::LineTable by the DWARF /// Context index of the DWARF Compile Unit that owns the Line Table and the row /// index. This is tied to our IR during disassembly so that we can later update /// .debug_line information. RowIndex has a base of 1, which means a RowIndex /// of 1 maps to the first row of the line table and a RowIndex of 0 is invalid. struct DebugLineTableRowRef { … }; /// Common buffer vector used for debug info handling. DebugBufferVector; /// Map of old CU offset to new offset and length. struct CUInfo { … }; CUOffsetMap; enum class RangesWriterKind { … }; /// Serializes the .debug_ranges DWARF section. class DebugRangesSectionWriter { … }; class DebugAddrWriter; class DebugRangeListsSectionWriter : public DebugRangesSectionWriter { … }; /// Serializes the .debug_aranges DWARF section. class DebugARangesSectionWriter { … }; IndexAddressPair; AddressToIndexMap; IndexToAddressMap; AddressSectionBuffer; class DebugAddrWriter { … }; class DebugAddrWriterDwarf5 : public DebugAddrWriter { … }; /// This class is NOT thread safe. DebugStrOffsetsBufferVector; class DebugStrOffsetsWriter { … }; DebugStrBufferVector; class DebugStrWriter { … }; enum class LocWriterKind { … }; /// Serializes part of a .debug_loc DWARF section with LocationLists. class SimpleBinaryPatcher; class DebugLocWriter { … }; class DebugLoclistWriter : public DebugLocWriter { … }; /// Abstract interface for classes that apply modifications to a binary string. class BinaryPatcher { … }; /// Applies simple modifications to a binary string, such as directly replacing /// the contents of a certain portion with a string or an integer. class SimpleBinaryPatcher : public BinaryPatcher { … }; /// Similar to MCDwarfLineEntry, but identifies the location by its address /// instead of MCLabel. class BinaryDwarfLineEntry : public MCDwarfLoc { … }; /// Line number information for the output binary. One instance per CU. /// /// For any given CU, we may: /// 1. Generate new line table using: /// a) emitted code: getMCLineSections().addEntry() /// b) information from the input line table: addLineTableSequence() /// or /// 2. Copy line table from the input file: addRawContents(). class DwarfLineTable { … }; } // namespace bolt } // namespace llvm #endif