LLVM 23.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;
27class LVLine;
29class LVSymbol;
30class LVType;
31
33
36
37 // Indicates if ranges data are available; in the case of split DWARF any
38 // reference to ranges is valid only if the skeleton DIE has been loaded.
39 bool RangesDataAvailable = false;
40 LVAddress CUBaseAddress = 0;
41 LVAddress CUHighAddress = 0;
42
43 LVOffset CurrentEndOffset = 0;
44
45 // In DWARF v4, the files are 1-indexed.
46 // In DWARF v5, the files are 0-indexed.
47 // The DWARF reader expects the indexes as 1-indexed.
48 bool IncrementFileIndex = false;
49
50 // Symbols with locations for current compile unit.
51 LVSymbols SymbolsWithLocations;
52
53 // Global Offsets (Offset, Element).
54 LVOffsetElementMap GlobalOffsets;
55
56 // Low PC and High PC values for DIE being processed.
57 LVAddress CurrentLowPC = 0;
58 LVAddress CurrentHighPC = 0;
59 bool FoundLowPC = false;
60 bool FoundHighPC = false;
61
62 // The value is updated for each Compile Unit that is processed.
63 std::optional<LVAddress> TombstoneAddress;
64
65 // Cross references (Elements).
66 using LVElementSet = SmallPtrSet<LVElement *, 0>;
67 struct LVElementEntry {
68 LVElement *Element;
69 LVElementSet References;
70 LVElementSet Types;
71 LVElementEntry(LVElement *Element = nullptr) : Element(Element) {}
72 };
73 using LVElementReference = DenseMap<LVOffset, LVElementEntry>;
74 LVElementReference ElementTable;
75
76 Error loadTargetInfo(const object::ObjectFile &Obj);
77
78 void mapRangeAddress(const object::ObjectFile &Obj) override;
79
80 void traverseDieAndChildren(DWARFDie &DIE, LVScope *Parent,
81 DWARFDie &SkeletonDie);
82 // Process the attributes for the given DIE.
83 LVScope *processOneDie(const DWARFDie &InputDIE, LVScope *Parent,
84 DWARFDie &SkeletonDie);
85 void processOneAttribute(const DWARFDie &Die, LVOffset *OffsetPtr,
86 const AttributeSpec &AttrSpec);
87 void createLineAndFileRecords(const DWARFDebugLine::LineTable *Lines);
88 void processLocationGaps();
89
90 // Add offset to global map.
91 void addGlobalOffset(LVOffset Offset) {
92 if (GlobalOffsets.find(Offset) == GlobalOffsets.end())
93 // Just associate the DIE offset with a null element, as we do not
94 // know if the referenced element has been created.
95 GlobalOffsets.emplace(Offset, nullptr);
96 }
97
98 // Remove offset from global map.
99 void removeGlobalOffset(LVOffset Offset) { GlobalOffsets.erase(Offset); }
100
101 // Get the location information for DW_AT_data_member_location.
102 void processLocationMember(dwarf::Attribute Attr,
103 const DWARFFormValue &FormValue,
104 const DWARFDie &Die, uint64_t OffsetOnEntry);
105 void processLocationList(dwarf::Attribute Attr,
106 const DWARFFormValue &FormValue, const DWARFDie &Die,
107 uint64_t OffsetOnEntry,
108 bool CallSiteLocation = false);
109 void updateReference(dwarf::Attribute Attr, const DWARFFormValue &FormValue);
110
111 // Get an element given the DIE offset.
112 LVElement *getElementForOffset(LVOffset offset, LVElement *Element,
113 bool IsType);
114
115protected:
116 Error createScopes() override;
117 void sortScopes() override;
118
119public:
120 LVDWARFReader() = delete;
125 LVDWARFReader(const LVDWARFReader &) = delete;
127 ~LVDWARFReader() override = default;
128
129 LVAddress getCUBaseAddress() const { return CUBaseAddress; }
130 void setCUBaseAddress(LVAddress Address) { CUBaseAddress = Address; }
131 LVAddress getCUHighAddress() const { return CUHighAddress; }
132 void setCUHighAddress(LVAddress Address) { CUHighAddress = Address; }
133
134 void setTombstoneAddress(LVAddress Address) { TombstoneAddress = Address; }
136 assert(TombstoneAddress && "Unset tombstone value");
137 return TombstoneAddress.value();
138 }
139
141 return SymbolsWithLocations;
142 }
143
144 std::string getRegisterName(LVSmall Opcode,
145 ArrayRef<uint64_t> Operands) override;
146
147 void print(raw_ostream &OS) const;
148
149#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
150 void dump() const { print(dbgs()); }
151#endif
152};
153
154} // end namespace logicalview
155} // end namespace llvm
156
157#endif // LLVM_DEBUGINFO_LOGICALVIEW_READERS_LVDWARFREADER_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
#define LLVM_ABI
Definition Compiler.h:215
This file defines the DenseMap class.
static std::string getRegisterName(const TargetRegisterInfo *TRI, Register Reg)
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:828
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:81
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