LLVM 24.0.0git
LVDWARFReader.h
Go to the documentation of this file.
1//===-- LVDWARFReader.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// This file defines the LVDWARFReader class, which is used to describe a
10// debug information (DWARF) reader.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_DEBUGINFO_LOGICALVIEW_READERS_LVDWARFREADER_H
15#define LLVM_DEBUGINFO_LOGICALVIEW_READERS_LVDWARFREADER_H
16
17#include "llvm/ADT/DenseMap.h"
22
23namespace llvm {
24namespace logicalview {
25
26class LVElement;
27
29
32
33 // Indicates if ranges data are available; in the case of split DWARF any
34 // reference to ranges is valid only if the skeleton DIE has been loaded.
35 bool RangesDataAvailable = false;
36 LVAddress CUBaseAddress = 0;
37 LVAddress CUHighAddress = 0;
38
39 LVOffset CurrentEndOffset = 0;
40
41 // In DWARF v4, the files are 1-indexed.
42 // In DWARF v5, the files are 0-indexed.
43 // The DWARF reader expects the indexes as 1-indexed.
44 bool IncrementFileIndex = false;
45
46 // Symbols with locations for current compile unit.
47 LVSymbols SymbolsWithLocations;
48
49 // Global Offsets (Offset, Element).
50 LVOffsetElementMap GlobalOffsets;
51
52 // Low PC and High PC values for DIE being processed.
53 LVAddress CurrentLowPC = 0;
54 LVAddress CurrentHighPC = 0;
55 bool FoundLowPC = false;
56 bool FoundHighPC = false;
57
58 // The value is updated for each Compile Unit that is processed.
59 std::optional<LVAddress> TombstoneAddress;
60
61 // Cross references (Elements).
62 using LVElementSet = SmallPtrSet<LVElement *, 0>;
63 struct LVElementEntry {
64 LVElement *Element;
65 LVElementSet References;
66 LVElementSet Types;
67 LVElementEntry(LVElement *Element = nullptr) : Element(Element) {}
68 };
69 using LVElementReference = DenseMap<LVOffset, LVElementEntry>;
70 LVElementReference ElementTable;
71
72 Error loadTargetInfo(const object::ObjectFile &Obj);
73
74 void mapRangeAddress(const object::ObjectFile &Obj) override;
75
76 void traverseDieAndChildren(DWARFDie &DIE, LVScope *Parent,
77 DWARFDie &SkeletonDie);
78 // Process the attributes for the given DIE.
79 LVScope *processOneDie(const DWARFDie &InputDIE, LVScope *Parent,
80 DWARFDie &SkeletonDie);
81 void processOneAttribute(const DWARFDie &Die, LVOffset *OffsetPtr,
82 const AttributeSpec &AttrSpec);
83 void createLineAndFileRecords(const DWARFDebugLine::LineTable *Lines);
84 void processLocationGaps();
85
86 // Add offset to global map.
87 void addGlobalOffset(LVOffset Offset) {
88 if (GlobalOffsets.find(Offset) == GlobalOffsets.end())
89 // Just associate the DIE offset with a null element, as we do not
90 // know if the referenced element has been created.
91 GlobalOffsets.emplace(Offset, nullptr);
92 }
93
94 // Remove offset from global map.
95 void removeGlobalOffset(LVOffset Offset) { GlobalOffsets.erase(Offset); }
96
97 // Get the location information for DW_AT_data_member_location.
98 void processLocationMember(dwarf::Attribute Attr,
99 const DWARFFormValue &FormValue,
100 const DWARFDie &Die, uint64_t OffsetOnEntry);
101 void processLocationList(dwarf::Attribute Attr,
102 const DWARFFormValue &FormValue, const DWARFDie &Die,
103 uint64_t OffsetOnEntry,
104 bool CallSiteLocation = false);
105 void updateReference(dwarf::Attribute Attr, const DWARFFormValue &FormValue);
106
107 // Get an element given the DIE offset.
108 LVElement *getElementForOffset(LVOffset offset, LVElement *Element,
109 bool IsType);
110
111protected:
112 Error createScopes() override;
113 void sortScopes() override;
114
115public:
116 LVDWARFReader() = delete;
121 LVDWARFReader(const LVDWARFReader &) = delete;
123 ~LVDWARFReader() override = default;
124
125 LVAddress getCUBaseAddress() const { return CUBaseAddress; }
126 void setCUBaseAddress(LVAddress Address) { CUBaseAddress = Address; }
127 LVAddress getCUHighAddress() const { return CUHighAddress; }
128 void setCUHighAddress(LVAddress Address) { CUHighAddress = Address; }
129
130 void setTombstoneAddress(LVAddress Address) { TombstoneAddress = Address; }
132 assert(TombstoneAddress && "Unset tombstone value");
133 return TombstoneAddress.value();
134 }
135
137 return SymbolsWithLocations;
138 }
139
140 std::string getRegisterName(LVSmall Opcode,
142
143 void print(raw_ostream &OS) const;
144
145#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
146 void dump() const { print(dbgs()); }
147#endif
148};
149
150} // end namespace logicalview
151} // end namespace llvm
152
153#endif // LLVM_DEBUGINFO_LOGICALVIEW_READERS_LVDWARFREADER_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
uint64_t uint64_t
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
#define LLVM_ABI
Definition Compiler.h:211
This file defines the DenseMap class.
static std::string getRegisterName(const TargetRegisterInfo *TRI, Register Reg)
SI Fold Operands
This file defines the SmallPtrSet class.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
A structured debug information entry.
Definition DIE.h:835
Utility class that carries the DWARF compile/type unit and the debug info entry in an object.
Definition DWARFDie.h:43
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
LVDWARFReader(const LVDWARFReader &)=delete
LVAddress getTombstoneAddress() const
void setCUHighAddress(LVAddress Address)
void setTombstoneAddress(LVAddress Address)
LVDWARFReader & operator=(const LVDWARFReader &)=delete
void setCUBaseAddress(LVAddress Address)
~LVDWARFReader() override=default
LVDWARFReader(StringRef Filename, StringRef FileFormatName, object::ObjectFile &Obj, ScopedPrinter &W)
const LVSymbols & GetSymbolsWithLocations() const
This class is the base class for all object file types.
Definition ObjectFile.h:231
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
Attribute
Attributes.
Definition Dwarf.h:125
uint64_t LVOffset
Definition LVObject.h:39
std::map< LVOffset, LVElement * > LVOffsetElementMap
Definition LVScope.h:68
SmallVector< LVSymbol *, 8 > LVSymbols
Definition LVObject.h:77
uint8_t LVSmall
Definition LVObject.h:42
DWARFAbbreviationDeclaration::AttributeSpec AttributeSpec
uint64_t LVAddress
Definition LVObject.h:36
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209