DwarfDebug.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. //===-- llvm/CodeGen/DwarfDebug.h - Dwarf Debug Framework ------*- C++ -*--===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file contains support for writing dwarf debug info into asm files.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFDEBUG_H
  14. #define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFDEBUG_H
  15. #include "AsmPrinterHandler.h"
  16. #include "DbgValueHistoryCalculator.h"
  17. #include "DebugLocStream.h"
  18. #include "DwarfAccelTable.h"
  19. #include "DwarfFile.h"
  20. #include "llvm/ADT/DenseMap.h"
  21. #include "llvm/ADT/DenseSet.h"
  22. #include "llvm/ADT/FoldingSet.h"
  23. #include "llvm/ADT/MapVector.h"
  24. #include "llvm/ADT/SmallPtrSet.h"
  25. #include "llvm/ADT/StringMap.h"
  26. #include "llvm/CodeGen/DIE.h"
  27. #include "llvm/CodeGen/LexicalScopes.h"
  28. #include "llvm/CodeGen/MachineInstr.h"
  29. #include "llvm/IR/DebugInfo.h"
  30. #include "llvm/IR/DebugLoc.h"
  31. #include "llvm/MC/MCDwarf.h"
  32. #include "llvm/MC/MachineLocation.h"
  33. #include "llvm/Support/Allocator.h"
  34. #include <memory>
  35. namespace llvm {
  36. class AsmPrinter;
  37. class ByteStreamer;
  38. class ConstantInt;
  39. class ConstantFP;
  40. class DebugLocEntry;
  41. class DwarfCompileUnit;
  42. class DwarfDebug;
  43. class DwarfTypeUnit;
  44. class DwarfUnit;
  45. class MachineModuleInfo;
  46. //===----------------------------------------------------------------------===//
  47. /// This class is used to record source line correspondence.
  48. class SrcLineInfo {
  49. unsigned Line; // Source line number.
  50. unsigned Column; // Source column.
  51. unsigned SourceID; // Source ID number.
  52. MCSymbol *Label; // Label in code ID number.
  53. public:
  54. SrcLineInfo(unsigned L, unsigned C, unsigned S, MCSymbol *label)
  55. : Line(L), Column(C), SourceID(S), Label(label) {}
  56. // Accessors
  57. unsigned getLine() const { return Line; }
  58. unsigned getColumn() const { return Column; }
  59. unsigned getSourceID() const { return SourceID; }
  60. MCSymbol *getLabel() const { return Label; }
  61. };
  62. // //
  63. ///////////////////////////////////////////////////////////////////////////////
  64. /// This class is used to track local variable information.
  65. ///
  66. /// Variables can be created from allocas, in which case they're generated from
  67. /// the MMI table. Such variables can have multiple expressions and frame
  68. /// indices. The \a Expr and \a FrameIndices array must match.
  69. ///
  70. /// Variables can be created from \c DBG_VALUE instructions. Those whose
  71. /// location changes over time use \a DebugLocListIndex, while those with a
  72. /// single instruction use \a MInsn and (optionally) a single entry of \a Expr.
  73. ///
  74. /// Variables that have been optimized out use none of these fields.
  75. class DbgVariable {
  76. const DILocalVariable *Var; /// Variable Descriptor.
  77. const DILocation *IA; /// Inlined at location.
  78. SmallVector<const DIExpression *, 1> Expr; /// Complex address.
  79. DIE *TheDIE = nullptr; /// Variable DIE.
  80. unsigned DebugLocListIndex = ~0u; /// Offset in DebugLocs.
  81. const MachineInstr *MInsn = nullptr; /// DBG_VALUE instruction.
  82. SmallVector<int, 1> FrameIndex; /// Frame index.
  83. DwarfDebug *DD;
  84. public:
  85. /// Construct a DbgVariable.
  86. ///
  87. /// Creates a variable without any DW_AT_location. Call \a initializeMMI()
  88. /// for MMI entries, or \a initializeDbgValue() for DBG_VALUE instructions.
  89. DbgVariable(const DILocalVariable *V, const DILocation *IA, DwarfDebug *DD)
  90. : Var(V), IA(IA), DD(DD) {}
  91. /// Initialize from the MMI table.
  92. void initializeMMI(const DIExpression *E, int FI) {
  93. assert(Expr.empty() && "Already initialized?");
  94. assert(FrameIndex.empty() && "Already initialized?");
  95. assert(!MInsn && "Already initialized?");
  96. assert((!E || E->isValid()) && "Expected valid expression");
  97. assert(~FI && "Expected valid index");
  98. Expr.push_back(E);
  99. FrameIndex.push_back(FI);
  100. }
  101. /// Initialize from a DBG_VALUE instruction.
  102. void initializeDbgValue(const MachineInstr *DbgValue) {
  103. assert(Expr.empty() && "Already initialized?");
  104. assert(FrameIndex.empty() && "Already initialized?");
  105. assert(!MInsn && "Already initialized?");
  106. assert(Var == DbgValue->getDebugVariable() && "Wrong variable");
  107. assert(IA == DbgValue->getDebugLoc()->getInlinedAt() && "Wrong inlined-at");
  108. MInsn = DbgValue;
  109. if (auto *E = DbgValue->getDebugExpression())
  110. if (E->getNumElements())
  111. Expr.push_back(E);
  112. }
  113. // Accessors.
  114. const DILocalVariable *getVariable() const { return Var; }
  115. const DILocation *getInlinedAt() const { return IA; }
  116. const ArrayRef<const DIExpression *> getExpression() const { return Expr; }
  117. void setDIE(DIE &D) { TheDIE = &D; }
  118. DIE *getDIE() const { return TheDIE; }
  119. void setDebugLocListIndex(unsigned O) { DebugLocListIndex = O; }
  120. unsigned getDebugLocListIndex() const { return DebugLocListIndex; }
  121. StringRef getName() const { return Var->getName(); }
  122. const MachineInstr *getMInsn() const { return MInsn; }
  123. const ArrayRef<int> getFrameIndex() const { return FrameIndex; }
  124. void addMMIEntry(const DbgVariable &V) {
  125. assert(DebugLocListIndex == ~0U && !MInsn && "not an MMI entry");
  126. assert(V.DebugLocListIndex == ~0U && !V.MInsn && "not an MMI entry");
  127. assert(V.Var == Var && "conflicting variable");
  128. assert(V.IA == IA && "conflicting inlined-at location");
  129. assert(!FrameIndex.empty() && "Expected an MMI entry");
  130. assert(!V.FrameIndex.empty() && "Expected an MMI entry");
  131. assert(Expr.size() == FrameIndex.size() && "Mismatched expressions");
  132. assert(V.Expr.size() == V.FrameIndex.size() && "Mismatched expressions");
  133. Expr.append(V.Expr.begin(), V.Expr.end());
  134. FrameIndex.append(V.FrameIndex.begin(), V.FrameIndex.end());
  135. assert(std::all_of(Expr.begin(), Expr.end(), [](const DIExpression *E) {
  136. return E && E->isBitPiece();
  137. }) && "conflicting locations for variable");
  138. }
  139. // Translate tag to proper Dwarf tag.
  140. dwarf::Tag getTag() const {
  141. if (Var->getTag() == dwarf::DW_TAG_arg_variable)
  142. return dwarf::DW_TAG_formal_parameter;
  143. return dwarf::DW_TAG_variable;
  144. }
  145. /// Return true if DbgVariable is artificial.
  146. bool isArtificial() const {
  147. if (Var->isArtificial())
  148. return true;
  149. if (getType()->isArtificial())
  150. return true;
  151. return false;
  152. }
  153. bool isObjectPointer() const {
  154. if (Var->isObjectPointer())
  155. return true;
  156. if (getType()->isObjectPointer())
  157. return true;
  158. return false;
  159. }
  160. bool hasComplexAddress() const {
  161. assert(MInsn && "Expected DBG_VALUE, not MMI variable");
  162. assert(FrameIndex.empty() && "Expected DBG_VALUE, not MMI variable");
  163. assert(
  164. (Expr.empty() || (Expr.size() == 1 && Expr.back()->getNumElements())) &&
  165. "Invalid Expr for DBG_VALUE");
  166. return !Expr.empty();
  167. }
  168. bool isBlockByrefVariable() const;
  169. const DIType *getType() const;
  170. private:
  171. /// Look in the DwarfDebug map for the MDNode that
  172. /// corresponds to the reference.
  173. template <typename T> T *resolve(TypedDINodeRef<T> Ref) const;
  174. };
  175. /// Helper used to pair up a symbol and its DWARF compile unit.
  176. struct SymbolCU {
  177. SymbolCU(DwarfCompileUnit *CU, const MCSymbol *Sym) : Sym(Sym), CU(CU) {}
  178. const MCSymbol *Sym;
  179. DwarfCompileUnit *CU;
  180. };
  181. /// Collects and handles dwarf debug information.
  182. class DwarfDebug : public AsmPrinterHandler {
  183. /// Target of Dwarf emission.
  184. AsmPrinter *Asm;
  185. /// Collected machine module information.
  186. MachineModuleInfo *MMI;
  187. /// All DIEValues are allocated through this allocator.
  188. BumpPtrAllocator DIEValueAllocator;
  189. /// Maps MDNode with its corresponding DwarfCompileUnit.
  190. MapVector<const MDNode *, DwarfCompileUnit *> CUMap;
  191. /// Maps subprogram MDNode with its corresponding DwarfCompileUnit.
  192. MapVector<const MDNode *, DwarfCompileUnit *> SPMap;
  193. /// Maps a CU DIE with its corresponding DwarfCompileUnit.
  194. DenseMap<const DIE *, DwarfCompileUnit *> CUDieMap;
  195. /// List of all labels used in aranges generation.
  196. std::vector<SymbolCU> ArangeLabels;
  197. /// Size of each symbol emitted (for those symbols that have a specific size).
  198. DenseMap<const MCSymbol *, uint64_t> SymSize;
  199. LexicalScopes LScopes;
  200. /// Collection of abstract variables.
  201. DenseMap<const MDNode *, std::unique_ptr<DbgVariable>> AbstractVariables;
  202. SmallVector<std::unique_ptr<DbgVariable>, 64> ConcreteVariables;
  203. /// Collection of DebugLocEntry. Stored in a linked list so that DIELocLists
  204. /// can refer to them in spite of insertions into this list.
  205. DebugLocStream DebugLocs;
  206. /// This is a collection of subprogram MDNodes that are processed to
  207. /// create DIEs.
  208. SmallPtrSet<const MDNode *, 16> ProcessedSPNodes;
  209. /// Maps instruction with label emitted before instruction.
  210. DenseMap<const MachineInstr *, MCSymbol *> LabelsBeforeInsn;
  211. /// Maps instruction with label emitted after instruction.
  212. DenseMap<const MachineInstr *, MCSymbol *> LabelsAfterInsn;
  213. /// History of DBG_VALUE and clobber instructions for each user
  214. /// variable. Variables are listed in order of appearance.
  215. DbgValueHistoryMap DbgValues;
  216. /// Previous instruction's location information. This is used to
  217. /// determine label location to indicate scope boundries in dwarf
  218. /// debug info.
  219. DebugLoc PrevInstLoc;
  220. MCSymbol *PrevLabel;
  221. /// This location indicates end of function prologue and beginning of
  222. /// function body.
  223. DebugLoc PrologEndLoc;
  224. /// If nonnull, stores the current machine function we're processing.
  225. const MachineFunction *CurFn;
  226. /// If nonnull, stores the current machine instruction we're processing.
  227. const MachineInstr *CurMI;
  228. /// If nonnull, stores the CU in which the previous subprogram was contained.
  229. const DwarfCompileUnit *PrevCU;
  230. /// As an optimization, there is no need to emit an entry in the directory
  231. /// table for the same directory as DW_AT_comp_dir.
  232. StringRef CompilationDir;
  233. /// Holder for the file specific debug information.
  234. DwarfFile InfoHolder;
  235. /// Holders for the various debug information flags that we might need to
  236. /// have exposed. See accessor functions below for description.
  237. /// Holder for imported entities.
  238. typedef SmallVector<std::pair<const MDNode *, const MDNode *>, 32>
  239. ImportedEntityMap;
  240. ImportedEntityMap ScopesWithImportedEntities;
  241. /// Map from MDNodes for user-defined types to the type units that
  242. /// describe them.
  243. DenseMap<const MDNode *, const DwarfTypeUnit *> DwarfTypeUnits;
  244. SmallVector<
  245. std::pair<std::unique_ptr<DwarfTypeUnit>, const DICompositeType *>, 1>
  246. TypeUnitsUnderConstruction;
  247. /// Whether to emit the pubnames/pubtypes sections.
  248. bool HasDwarfPubSections;
  249. /// Whether or not to use AT_ranges for compilation units.
  250. bool HasCURanges;
  251. /// Whether we emitted a function into a section other than the
  252. /// default text.
  253. bool UsedNonDefaultText;
  254. /// Whether to use the GNU TLS opcode (instead of the standard opcode).
  255. bool UseGNUTLSOpcode;
  256. /// Version of dwarf we're emitting.
  257. unsigned DwarfVersion;
  258. /// Maps from a type identifier to the actual MDNode.
  259. DITypeIdentifierMap TypeIdentifierMap;
  260. /// DWARF5 Experimental Options
  261. /// @{
  262. bool HasDwarfAccelTables;
  263. bool HasSplitDwarf;
  264. /// Separated Dwarf Variables
  265. /// In general these will all be for bits that are left in the
  266. /// original object file, rather than things that are meant
  267. /// to be in the .dwo sections.
  268. /// Holder for the skeleton information.
  269. DwarfFile SkeletonHolder;
  270. /// Store file names for type units under fission in a line table
  271. /// header that will be emitted into debug_line.dwo.
  272. // FIXME: replace this with a map from comp_dir to table so that we
  273. // can emit multiple tables during LTO each of which uses directory
  274. // 0, referencing the comp_dir of all the type units that use it.
  275. MCDwarfDwoLineTable SplitTypeUnitFileTable;
  276. /// @}
  277. /// True iff there are multiple CUs in this module.
  278. bool SingleCU;
  279. bool IsDarwin;
  280. bool IsPS4;
  281. AddressPool AddrPool;
  282. DwarfAccelTable AccelNames;
  283. DwarfAccelTable AccelObjC;
  284. DwarfAccelTable AccelNamespace;
  285. DwarfAccelTable AccelTypes;
  286. DenseMap<const Function *, DISubprogram *> FunctionDIs;
  287. MCDwarfDwoLineTable *getDwoLineTable(const DwarfCompileUnit &);
  288. const SmallVectorImpl<std::unique_ptr<DwarfUnit>> &getUnits() {
  289. return InfoHolder.getUnits();
  290. }
  291. typedef DbgValueHistoryMap::InlinedVariable InlinedVariable;
  292. /// Find abstract variable associated with Var.
  293. DbgVariable *getExistingAbstractVariable(InlinedVariable IV,
  294. const DILocalVariable *&Cleansed);
  295. DbgVariable *getExistingAbstractVariable(InlinedVariable IV);
  296. void createAbstractVariable(const DILocalVariable *DV, LexicalScope *Scope);
  297. void ensureAbstractVariableIsCreated(InlinedVariable Var,
  298. const MDNode *Scope);
  299. void ensureAbstractVariableIsCreatedIfScoped(InlinedVariable Var,
  300. const MDNode *Scope);
  301. DbgVariable *createConcreteVariable(LexicalScope &Scope, InlinedVariable IV);
  302. /// Construct a DIE for this abstract scope.
  303. void constructAbstractSubprogramScopeDIE(LexicalScope *Scope);
  304. /// Compute the size and offset of a DIE given an incoming Offset.
  305. unsigned computeSizeAndOffset(DIE *Die, unsigned Offset);
  306. /// Compute the size and offset of all the DIEs.
  307. void computeSizeAndOffsets();
  308. /// Collect info for variables that were optimized out.
  309. void collectDeadVariables();
  310. void finishVariableDefinitions();
  311. void finishSubprogramDefinitions();
  312. /// Finish off debug information after all functions have been
  313. /// processed.
  314. void finalizeModuleInfo();
  315. /// Emit the debug info section.
  316. void emitDebugInfo();
  317. /// Emit the abbreviation section.
  318. void emitAbbreviations();
  319. /// Emit a specified accelerator table.
  320. void emitAccel(DwarfAccelTable &Accel, MCSection *Section,
  321. StringRef TableName);
  322. /// Emit visible names into a hashed accelerator table section.
  323. void emitAccelNames();
  324. /// Emit objective C classes and categories into a hashed
  325. /// accelerator table section.
  326. void emitAccelObjC();
  327. /// Emit namespace dies into a hashed accelerator table.
  328. void emitAccelNamespaces();
  329. /// Emit type dies into a hashed accelerator table.
  330. void emitAccelTypes();
  331. /// Emit visible names into a debug pubnames section.
  332. /// \param GnuStyle determines whether or not we want to emit
  333. /// additional information into the table ala newer gcc for gdb
  334. /// index.
  335. void emitDebugPubNames(bool GnuStyle = false);
  336. /// Emit visible types into a debug pubtypes section.
  337. /// \param GnuStyle determines whether or not we want to emit
  338. /// additional information into the table ala newer gcc for gdb
  339. /// index.
  340. void emitDebugPubTypes(bool GnuStyle = false);
  341. void emitDebugPubSection(
  342. bool GnuStyle, MCSection *PSec, StringRef Name,
  343. const StringMap<const DIE *> &(DwarfCompileUnit::*Accessor)() const);
  344. /// Emit visible names into a debug str section.
  345. void emitDebugStr();
  346. /// Emit visible names into a debug loc section.
  347. void emitDebugLoc();
  348. /// Emit visible names into a debug loc dwo section.
  349. void emitDebugLocDWO();
  350. /// Emit visible names into a debug aranges section.
  351. void emitDebugARanges();
  352. /// Emit visible names into a debug ranges section.
  353. void emitDebugRanges();
  354. /// Emit inline info using custom format.
  355. void emitDebugInlineInfo();
  356. /// DWARF 5 Experimental Split Dwarf Emitters
  357. /// Initialize common features of skeleton units.
  358. void initSkeletonUnit(const DwarfUnit &U, DIE &Die,
  359. std::unique_ptr<DwarfUnit> NewU);
  360. /// Construct the split debug info compile unit for the debug info
  361. /// section.
  362. DwarfCompileUnit &constructSkeletonCU(const DwarfCompileUnit &CU);
  363. /// Construct the split debug info compile unit for the debug info
  364. /// section.
  365. DwarfTypeUnit &constructSkeletonTU(DwarfTypeUnit &TU);
  366. /// Emit the debug info dwo section.
  367. void emitDebugInfoDWO();
  368. /// Emit the debug abbrev dwo section.
  369. void emitDebugAbbrevDWO();
  370. /// Emit the debug line dwo section.
  371. void emitDebugLineDWO();
  372. /// Emit the debug str dwo section.
  373. void emitDebugStrDWO();
  374. /// Flags to let the linker know we have emitted new style pubnames. Only
  375. /// emit it here if we don't have a skeleton CU for split dwarf.
  376. void addGnuPubAttributes(DwarfUnit &U, DIE &D) const;
  377. /// Create new DwarfCompileUnit for the given metadata node with tag
  378. /// DW_TAG_compile_unit.
  379. DwarfCompileUnit &constructDwarfCompileUnit(const DICompileUnit *DIUnit);
  380. /// Construct imported_module or imported_declaration DIE.
  381. void constructAndAddImportedEntityDIE(DwarfCompileUnit &TheCU,
  382. const DIImportedEntity *N);
  383. /// Register a source line with debug info. Returns the unique
  384. /// label that was emitted and which provides correspondence to the
  385. /// source line list.
  386. void recordSourceLine(unsigned Line, unsigned Col, const MDNode *Scope,
  387. unsigned Flags);
  388. /// Indentify instructions that are marking the beginning of or
  389. /// ending of a scope.
  390. void identifyScopeMarkers();
  391. /// Populate LexicalScope entries with variables' info.
  392. void collectVariableInfo(DwarfCompileUnit &TheCU, const DISubprogram *SP,
  393. DenseSet<InlinedVariable> &ProcessedVars);
  394. /// Build the location list for all DBG_VALUEs in the
  395. /// function that describe the same variable.
  396. void buildLocationList(SmallVectorImpl<DebugLocEntry> &DebugLoc,
  397. const DbgValueHistoryMap::InstrRanges &Ranges);
  398. /// Collect variable information from the side table maintained
  399. /// by MMI.
  400. void collectVariableInfoFromMMITable(DenseSet<InlinedVariable> &P);
  401. /// Ensure that a label will be emitted before MI.
  402. void requestLabelBeforeInsn(const MachineInstr *MI) {
  403. LabelsBeforeInsn.insert(std::make_pair(MI, nullptr));
  404. }
  405. /// Ensure that a label will be emitted after MI.
  406. void requestLabelAfterInsn(const MachineInstr *MI) {
  407. LabelsAfterInsn.insert(std::make_pair(MI, nullptr));
  408. }
  409. public:
  410. //===--------------------------------------------------------------------===//
  411. // Main entry points.
  412. //
  413. DwarfDebug(AsmPrinter *A, Module *M);
  414. ~DwarfDebug() override;
  415. /// Emit all Dwarf sections that should come prior to the
  416. /// content.
  417. void beginModule();
  418. /// Emit all Dwarf sections that should come after the content.
  419. void endModule() override;
  420. /// Gather pre-function debug information.
  421. void beginFunction(const MachineFunction *MF) override;
  422. /// Gather and emit post-function debug information.
  423. void endFunction(const MachineFunction *MF) override;
  424. /// Process beginning of an instruction.
  425. void beginInstruction(const MachineInstr *MI) override;
  426. /// Process end of an instruction.
  427. void endInstruction() override;
  428. /// Add a DIE to the set of types that we're going to pull into
  429. /// type units.
  430. void addDwarfTypeUnitType(DwarfCompileUnit &CU, StringRef Identifier,
  431. DIE &Die, const DICompositeType *CTy);
  432. /// Add a label so that arange data can be generated for it.
  433. void addArangeLabel(SymbolCU SCU) { ArangeLabels.push_back(SCU); }
  434. /// For symbols that have a size designated (e.g. common symbols),
  435. /// this tracks that size.
  436. void setSymbolSize(const MCSymbol *Sym, uint64_t Size) override {
  437. SymSize[Sym] = Size;
  438. }
  439. /// Returns whether to use DW_OP_GNU_push_tls_address, instead of the
  440. /// standard DW_OP_form_tls_address opcode
  441. bool useGNUTLSOpcode() const { return UseGNUTLSOpcode; }
  442. // Experimental DWARF5 features.
  443. /// Returns whether or not to emit tables that dwarf consumers can
  444. /// use to accelerate lookup.
  445. bool useDwarfAccelTables() const { return HasDwarfAccelTables; }
  446. /// Returns whether or not to change the current debug info for the
  447. /// split dwarf proposal support.
  448. bool useSplitDwarf() const { return HasSplitDwarf; }
  449. /// Returns the Dwarf Version.
  450. unsigned getDwarfVersion() const { return DwarfVersion; }
  451. /// Returns the previous CU that was being updated
  452. const DwarfCompileUnit *getPrevCU() const { return PrevCU; }
  453. void setPrevCU(const DwarfCompileUnit *PrevCU) { this->PrevCU = PrevCU; }
  454. /// Returns the entries for the .debug_loc section.
  455. const DebugLocStream &getDebugLocs() const { return DebugLocs; }
  456. /// Emit an entry for the debug loc section. This can be used to
  457. /// handle an entry that's going to be emitted into the debug loc section.
  458. void emitDebugLocEntry(ByteStreamer &Streamer,
  459. const DebugLocStream::Entry &Entry);
  460. /// Emit the location for a debug loc entry, including the size header.
  461. void emitDebugLocEntryLocation(const DebugLocStream::Entry &Entry);
  462. /// Find the MDNode for the given reference.
  463. template <typename T> T *resolve(TypedDINodeRef<T> Ref) const {
  464. return Ref.resolve(TypeIdentifierMap);
  465. }
  466. /// Return the TypeIdentifierMap.
  467. const DITypeIdentifierMap &getTypeIdentifierMap() const {
  468. return TypeIdentifierMap;
  469. }
  470. /// Find the DwarfCompileUnit for the given CU Die.
  471. DwarfCompileUnit *lookupUnit(const DIE *CU) const {
  472. return CUDieMap.lookup(CU);
  473. }
  474. /// isSubprogramContext - Return true if Context is either a subprogram
  475. /// or another context nested inside a subprogram.
  476. bool isSubprogramContext(const MDNode *Context);
  477. void addSubprogramNames(const DISubprogram *SP, DIE &Die);
  478. AddressPool &getAddressPool() { return AddrPool; }
  479. void addAccelName(StringRef Name, const DIE &Die);
  480. void addAccelObjC(StringRef Name, const DIE &Die);
  481. void addAccelNamespace(StringRef Name, const DIE &Die);
  482. void addAccelType(StringRef Name, const DIE &Die, char Flags);
  483. const MachineFunction *getCurrentFunction() const { return CurFn; }
  484. iterator_range<ImportedEntityMap::const_iterator>
  485. findImportedEntitiesForScope(const MDNode *Scope) const {
  486. return make_range(std::equal_range(
  487. ScopesWithImportedEntities.begin(), ScopesWithImportedEntities.end(),
  488. std::pair<const MDNode *, const MDNode *>(Scope, nullptr),
  489. less_first()));
  490. }
  491. /// A helper function to check whether the DIE for a given Scope is
  492. /// going to be null.
  493. bool isLexicalScopeDIENull(LexicalScope *Scope);
  494. /// Return Label preceding the instruction.
  495. MCSymbol *getLabelBeforeInsn(const MachineInstr *MI);
  496. /// Return Label immediately following the instruction.
  497. MCSymbol *getLabelAfterInsn(const MachineInstr *MI);
  498. // FIXME: Sink these functions down into DwarfFile/Dwarf*Unit.
  499. SmallPtrSet<const MDNode *, 16> &getProcessedSPNodes() {
  500. return ProcessedSPNodes;
  501. }
  502. };
  503. } // End of namespace llvm
  504. #endif