Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 1 | //===- llvm/CodeGen/DwarfDebug.h - Dwarf Debug Framework --------*- C++ -*-===// |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 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 | |
Benjamin Kramer | a7c40ef | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 14 | #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFDEBUG_H |
| 15 | #define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFDEBUG_H |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 16 | |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 17 | #include "AddressPool.h" |
Alexey Samsonov | 414b6fb | 2014-04-30 21:34:11 +0000 | [diff] [blame] | 18 | #include "DbgValueHistoryCalculator.h" |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 19 | #include "DebugHandlerBase.h" |
Duncan P. N. Exon Smith | 364a300 | 2015-04-17 21:34:47 +0000 | [diff] [blame] | 20 | #include "DebugLocStream.h" |
David Blaikie | 2406a062 | 2014-04-23 23:37:35 +0000 | [diff] [blame] | 21 | #include "DwarfAccelTable.h" |
Chandler Carruth | d990388 | 2015-01-14 11:23:27 +0000 | [diff] [blame] | 22 | #include "DwarfFile.h" |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/ArrayRef.h" |
Devang Patel | 018b29b | 2010-01-19 06:19:05 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/DenseMap.h" |
Duncan P. N. Exon Smith | 62e0f45 | 2015-04-15 22:29:27 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/DenseSet.h" |
Eric Christopher | acbe42b | 2014-03-18 20:58:35 +0000 | [diff] [blame] | 26 | #include "llvm/ADT/MapVector.h" |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 27 | #include "llvm/ADT/STLExtras.h" |
David Blaikie | 38b74bf | 2016-12-15 23:37:38 +0000 | [diff] [blame] | 28 | #include "llvm/ADT/SetVector.h" |
Eric Christopher | acbe42b | 2014-03-18 20:58:35 +0000 | [diff] [blame] | 29 | #include "llvm/ADT/SmallPtrSet.h" |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 30 | #include "llvm/ADT/SmallVector.h" |
Eric Christopher | acbe42b | 2014-03-18 20:58:35 +0000 | [diff] [blame] | 31 | #include "llvm/ADT/StringMap.h" |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 32 | #include "llvm/ADT/StringRef.h" |
| 33 | #include "llvm/BinaryFormat/Dwarf.h" |
Adrian Prantl | c119754 | 2014-05-30 21:10:13 +0000 | [diff] [blame] | 34 | #include "llvm/CodeGen/MachineInstr.h" |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 35 | #include "llvm/IR/DebugInfoMetadata.h" |
Eric Christopher | acbe42b | 2014-03-18 20:58:35 +0000 | [diff] [blame] | 36 | #include "llvm/IR/DebugLoc.h" |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 37 | #include "llvm/IR/Metadata.h" |
David Blaikie | 4a2f95f | 2014-03-18 01:17:26 +0000 | [diff] [blame] | 38 | #include "llvm/MC/MCDwarf.h" |
Chris Lattner | 3f3fb97 | 2010-04-05 05:24:55 +0000 | [diff] [blame] | 39 | #include "llvm/Support/Allocator.h" |
Paul Robinson | 6c27a2c | 2015-12-16 19:58:30 +0000 | [diff] [blame] | 40 | #include "llvm/Target/TargetOptions.h" |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 41 | #include <cassert> |
| 42 | #include <cstdint> |
| 43 | #include <limits> |
David Blaikie | f9b6a55 | 2014-04-22 22:39:41 +0000 | [diff] [blame] | 44 | #include <memory> |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 45 | #include <utility> |
| 46 | #include <vector> |
David Blaikie | f9b6a55 | 2014-04-22 22:39:41 +0000 | [diff] [blame] | 47 | |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 48 | namespace llvm { |
| 49 | |
Adrian Prantl | 702bf5a | 2014-03-18 02:34:52 +0000 | [diff] [blame] | 50 | class AsmPrinter; |
Eric Christopher | 29e874d | 2014-03-07 22:40:37 +0000 | [diff] [blame] | 51 | class ByteStreamer; |
Duncan P. N. Exon Smith | 364a300 | 2015-04-17 21:34:47 +0000 | [diff] [blame] | 52 | class DebugLocEntry; |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 53 | class DIE; |
Eric Christopher | ce4a944 | 2014-03-18 20:37:10 +0000 | [diff] [blame] | 54 | class DwarfCompileUnit; |
Eric Christopher | ce4a944 | 2014-03-18 20:37:10 +0000 | [diff] [blame] | 55 | class DwarfTypeUnit; |
| 56 | class DwarfUnit; |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 57 | class LexicalScope; |
| 58 | class MachineFunction; |
| 59 | class MCSection; |
| 60 | class MCSymbol; |
| 61 | class MDNode; |
| 62 | class Module; |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 63 | |
| 64 | //===----------------------------------------------------------------------===// |
Duncan P. N. Exon Smith | e6cc531 | 2015-06-21 16:50:43 +0000 | [diff] [blame] | 65 | /// This class is used to track local variable information. |
Adrian Prantl | ca7e470 | 2015-02-10 23:18:28 +0000 | [diff] [blame] | 66 | /// |
Duncan P. N. Exon Smith | e6cc531 | 2015-06-21 16:50:43 +0000 | [diff] [blame] | 67 | /// Variables can be created from allocas, in which case they're generated from |
| 68 | /// the MMI table. Such variables can have multiple expressions and frame |
Adrian Prantl | 67c2442 | 2017-02-17 19:42:32 +0000 | [diff] [blame] | 69 | /// indices. |
Adrian Prantl | ca7e470 | 2015-02-10 23:18:28 +0000 | [diff] [blame] | 70 | /// |
Duncan P. N. Exon Smith | e6cc531 | 2015-06-21 16:50:43 +0000 | [diff] [blame] | 71 | /// Variables can be created from \c DBG_VALUE instructions. Those whose |
| 72 | /// location changes over time use \a DebugLocListIndex, while those with a |
| 73 | /// single instruction use \a MInsn and (optionally) a single entry of \a Expr. |
| 74 | /// |
| 75 | /// Variables that have been optimized out use none of these fields. |
Benjamin Kramer | 079b96e | 2013-09-11 18:05:11 +0000 | [diff] [blame] | 76 | class DbgVariable { |
Duncan P. N. Exon Smith | e6cc531 | 2015-06-21 16:50:43 +0000 | [diff] [blame] | 77 | const DILocalVariable *Var; /// Variable Descriptor. |
| 78 | const DILocation *IA; /// Inlined at location. |
Duncan P. N. Exon Smith | e6cc531 | 2015-06-21 16:50:43 +0000 | [diff] [blame] | 79 | DIE *TheDIE = nullptr; /// Variable DIE. |
| 80 | unsigned DebugLocListIndex = ~0u; /// Offset in DebugLocs. |
| 81 | const MachineInstr *MInsn = nullptr; /// DBG_VALUE instruction. |
Adrian Prantl | 67c2442 | 2017-02-17 19:42:32 +0000 | [diff] [blame] | 82 | |
| 83 | struct FrameIndexExpr { |
| 84 | int FI; |
| 85 | const DIExpression *Expr; |
| 86 | }; |
| 87 | mutable SmallVector<FrameIndexExpr, 1> |
| 88 | FrameIndexExprs; /// Frame index + expression. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 89 | |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 90 | public: |
Duncan P. N. Exon Smith | e6cc531 | 2015-06-21 16:50:43 +0000 | [diff] [blame] | 91 | /// Construct a DbgVariable. |
| 92 | /// |
| 93 | /// Creates a variable without any DW_AT_location. Call \a initializeMMI() |
| 94 | /// for MMI entries, or \a initializeDbgValue() for DBG_VALUE instructions. |
Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 95 | DbgVariable(const DILocalVariable *V, const DILocation *IA) |
| 96 | : Var(V), IA(IA) {} |
Duncan P. N. Exon Smith | e6cc531 | 2015-06-21 16:50:43 +0000 | [diff] [blame] | 97 | |
| 98 | /// Initialize from the MMI table. |
| 99 | void initializeMMI(const DIExpression *E, int FI) { |
Adrian Prantl | 67c2442 | 2017-02-17 19:42:32 +0000 | [diff] [blame] | 100 | assert(FrameIndexExprs.empty() && "Already initialized?"); |
Duncan P. N. Exon Smith | e6cc531 | 2015-06-21 16:50:43 +0000 | [diff] [blame] | 101 | assert(!MInsn && "Already initialized?"); |
| 102 | |
| 103 | assert((!E || E->isValid()) && "Expected valid expression"); |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 104 | assert(FI != std::numeric_limits<int>::max() && "Expected valid index"); |
Duncan P. N. Exon Smith | e6cc531 | 2015-06-21 16:50:43 +0000 | [diff] [blame] | 105 | |
Adrian Prantl | 67c2442 | 2017-02-17 19:42:32 +0000 | [diff] [blame] | 106 | FrameIndexExprs.push_back({FI, E}); |
Adrian Prantl | 87b7eb9 | 2014-10-01 18:55:02 +0000 | [diff] [blame] | 107 | } |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 108 | |
Duncan P. N. Exon Smith | e6cc531 | 2015-06-21 16:50:43 +0000 | [diff] [blame] | 109 | /// Initialize from a DBG_VALUE instruction. |
| 110 | void initializeDbgValue(const MachineInstr *DbgValue) { |
Adrian Prantl | 67c2442 | 2017-02-17 19:42:32 +0000 | [diff] [blame] | 111 | assert(FrameIndexExprs.empty() && "Already initialized?"); |
Duncan P. N. Exon Smith | e6cc531 | 2015-06-21 16:50:43 +0000 | [diff] [blame] | 112 | assert(!MInsn && "Already initialized?"); |
| 113 | |
| 114 | assert(Var == DbgValue->getDebugVariable() && "Wrong variable"); |
| 115 | assert(IA == DbgValue->getDebugLoc()->getInlinedAt() && "Wrong inlined-at"); |
| 116 | |
| 117 | MInsn = DbgValue; |
| 118 | if (auto *E = DbgValue->getDebugExpression()) |
| 119 | if (E->getNumElements()) |
Adrian Prantl | 67c2442 | 2017-02-17 19:42:32 +0000 | [diff] [blame] | 120 | FrameIndexExprs.push_back({0, E}); |
Adrian Prantl | ca7e470 | 2015-02-10 23:18:28 +0000 | [diff] [blame] | 121 | } |
Adrian Prantl | c119754 | 2014-05-30 21:10:13 +0000 | [diff] [blame] | 122 | |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 123 | // Accessors. |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 124 | const DILocalVariable *getVariable() const { return Var; } |
| 125 | const DILocation *getInlinedAt() const { return IA; } |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 126 | |
Adrian Prantl | 6f4746b1 | 2016-02-17 22:19:59 +0000 | [diff] [blame] | 127 | const DIExpression *getSingleExpression() const { |
Adrian Prantl | 67c2442 | 2017-02-17 19:42:32 +0000 | [diff] [blame] | 128 | assert(MInsn && FrameIndexExprs.size() <= 1); |
| 129 | return FrameIndexExprs.size() ? FrameIndexExprs[0].Expr : nullptr; |
Adrian Prantl | 6f4746b1 | 2016-02-17 22:19:59 +0000 | [diff] [blame] | 130 | } |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 131 | |
David Blaikie | e071fc8 | 2014-04-25 17:32:19 +0000 | [diff] [blame] | 132 | void setDIE(DIE &D) { TheDIE = &D; } |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 133 | DIE *getDIE() const { return TheDIE; } |
Duncan P. N. Exon Smith | 364a300 | 2015-04-17 21:34:47 +0000 | [diff] [blame] | 134 | void setDebugLocListIndex(unsigned O) { DebugLocListIndex = O; } |
| 135 | unsigned getDebugLocListIndex() const { return DebugLocListIndex; } |
Duncan P. N. Exon Smith | 7348dda | 2015-04-14 02:22:36 +0000 | [diff] [blame] | 136 | StringRef getName() const { return Var->getName(); } |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 137 | const MachineInstr *getMInsn() const { return MInsn; } |
Adrian Prantl | 67c2442 | 2017-02-17 19:42:32 +0000 | [diff] [blame] | 138 | /// Get the FI entries, sorted by fragment offset. |
| 139 | ArrayRef<FrameIndexExpr> getFrameIndexExprs() const; |
| 140 | bool hasFrameIndexExprs() const { return !FrameIndexExprs.empty(); } |
Bjorn Steinbrink | d36bbe9 | 2017-10-10 07:46:17 +0000 | [diff] [blame] | 141 | void addMMIEntry(const DbgVariable &V); |
Adrian Prantl | ca7e470 | 2015-02-10 23:18:28 +0000 | [diff] [blame] | 142 | |
Eric Christopher | 27527b2 | 2012-11-21 00:03:28 +0000 | [diff] [blame] | 143 | // Translate tag to proper Dwarf tag. |
David Blaikie | efc403b | 2014-04-12 02:24:04 +0000 | [diff] [blame] | 144 | dwarf::Tag getTag() const { |
Duncan P. N. Exon Smith | ed013cd | 2015-07-31 18:58:39 +0000 | [diff] [blame] | 145 | // FIXME: Why don't we just infer this tag and store it all along? |
| 146 | if (Var->isParameter()) |
Devang Patel | 6e4d2c9 | 2011-08-15 18:35:42 +0000 | [diff] [blame] | 147 | return dwarf::DW_TAG_formal_parameter; |
Eric Christopher | 27527b2 | 2012-11-21 00:03:28 +0000 | [diff] [blame] | 148 | |
Devang Patel | 6e4d2c9 | 2011-08-15 18:35:42 +0000 | [diff] [blame] | 149 | return dwarf::DW_TAG_variable; |
| 150 | } |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 151 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 152 | /// Return true if DbgVariable is artificial. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 153 | bool isArtificial() const { |
Duncan P. N. Exon Smith | 7348dda | 2015-04-14 02:22:36 +0000 | [diff] [blame] | 154 | if (Var->isArtificial()) |
Devang Patel | d7d80aa | 2011-08-15 18:40:16 +0000 | [diff] [blame] | 155 | return true; |
Duncan P. N. Exon Smith | b105564 | 2015-04-16 01:01:28 +0000 | [diff] [blame] | 156 | if (getType()->isArtificial()) |
Devang Patel | d7d80aa | 2011-08-15 18:40:16 +0000 | [diff] [blame] | 157 | return true; |
| 158 | return false; |
| 159 | } |
Eric Christopher | e341776 | 2012-09-12 23:36:19 +0000 | [diff] [blame] | 160 | |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 161 | bool isObjectPointer() const { |
Duncan P. N. Exon Smith | 7348dda | 2015-04-14 02:22:36 +0000 | [diff] [blame] | 162 | if (Var->isObjectPointer()) |
Eric Christopher | e341776 | 2012-09-12 23:36:19 +0000 | [diff] [blame] | 163 | return true; |
Duncan P. N. Exon Smith | b105564 | 2015-04-16 01:01:28 +0000 | [diff] [blame] | 164 | if (getType()->isObjectPointer()) |
Eric Christopher | e341776 | 2012-09-12 23:36:19 +0000 | [diff] [blame] | 165 | return true; |
| 166 | return false; |
| 167 | } |
Eric Christopher | 27527b2 | 2012-11-21 00:03:28 +0000 | [diff] [blame] | 168 | |
Duncan P. N. Exon Smith | e6cc531 | 2015-06-21 16:50:43 +0000 | [diff] [blame] | 169 | bool hasComplexAddress() const { |
| 170 | assert(MInsn && "Expected DBG_VALUE, not MMI variable"); |
Adrian Prantl | 67c2442 | 2017-02-17 19:42:32 +0000 | [diff] [blame] | 171 | assert((FrameIndexExprs.empty() || |
| 172 | (FrameIndexExprs.size() == 1 && |
| 173 | FrameIndexExprs[0].Expr->getNumElements())) && |
| 174 | "Invalid Expr for DBG_VALUE"); |
| 175 | return !FrameIndexExprs.empty(); |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 176 | } |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 177 | |
Adrian Prantl | 1a1647c | 2014-03-18 02:34:58 +0000 | [diff] [blame] | 178 | bool isBlockByrefVariable() const; |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 179 | const DIType *getType() const; |
Manman Ren | be5576f | 2013-10-08 19:07:44 +0000 | [diff] [blame] | 180 | |
| 181 | private: |
Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 182 | template <typename T> T *resolve(TypedDINodeRef<T> Ref) const { |
| 183 | return Ref.resolve(); |
| 184 | } |
Devang Patel | f20c4f7 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 185 | }; |
| 186 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 187 | /// Helper used to pair up a symbol and its DWARF compile unit. |
Richard Mitton | 21101b3 | 2013-09-19 23:21:01 +0000 | [diff] [blame] | 188 | struct SymbolCU { |
Eric Christopher | 4287a49 | 2013-12-09 23:57:44 +0000 | [diff] [blame] | 189 | SymbolCU(DwarfCompileUnit *CU, const MCSymbol *Sym) : Sym(Sym), CU(CU) {} |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 190 | |
Richard Mitton | 21101b3 | 2013-09-19 23:21:01 +0000 | [diff] [blame] | 191 | const MCSymbol *Sym; |
Eric Christopher | 4287a49 | 2013-12-09 23:57:44 +0000 | [diff] [blame] | 192 | DwarfCompileUnit *CU; |
Richard Mitton | 21101b3 | 2013-09-19 23:21:01 +0000 | [diff] [blame] | 193 | }; |
| 194 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 195 | /// Collects and handles dwarf debug information. |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 196 | class DwarfDebug : public DebugHandlerBase { |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 197 | /// All DIEValues are allocated through this allocator. |
Benjamin Kramer | 0748008 | 2012-06-09 10:34:15 +0000 | [diff] [blame] | 198 | BumpPtrAllocator DIEValueAllocator; |
| 199 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 200 | /// Maps MDNode with its corresponding DwarfCompileUnit. |
Eric Christopher | 179fba1 | 2014-01-29 22:06:23 +0000 | [diff] [blame] | 201 | MapVector<const MDNode *, DwarfCompileUnit *> CUMap; |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 202 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 203 | /// Maps a CU DIE with its corresponding DwarfCompileUnit. |
Eric Christopher | 4287a49 | 2013-12-09 23:57:44 +0000 | [diff] [blame] | 204 | DenseMap<const DIE *, DwarfCompileUnit *> CUDieMap; |
Manman Ren | ce20d46 | 2013-10-29 22:57:10 +0000 | [diff] [blame] | 205 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 206 | /// List of all labels used in aranges generation. |
Alexey Samsonov | 4436bf0 | 2013-10-03 08:54:43 +0000 | [diff] [blame] | 207 | std::vector<SymbolCU> ArangeLabels; |
Richard Mitton | 21101b3 | 2013-09-19 23:21:01 +0000 | [diff] [blame] | 208 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 209 | /// Size of each symbol emitted (for those symbols that have a specific size). |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 210 | DenseMap<const MCSymbol *, uint64_t> SymSize; |
Richard Mitton | 089ed89 | 2013-09-23 17:56:20 +0000 | [diff] [blame] | 211 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 212 | /// Collection of abstract variables. |
David Blaikie | eb1a272 | 2014-06-13 22:18:23 +0000 | [diff] [blame] | 213 | SmallVector<std::unique_ptr<DbgVariable>, 64> ConcreteVariables; |
Devang Patel | f6eeaeb | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 214 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 215 | /// Collection of DebugLocEntry. Stored in a linked list so that DIELocLists |
| 216 | /// can refer to them in spite of insertions into this list. |
Duncan P. N. Exon Smith | 364a300 | 2015-04-17 21:34:47 +0000 | [diff] [blame] | 217 | DebugLocStream DebugLocs; |
Devang Patel | 9fc1170 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 218 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 219 | /// This is a collection of subprogram MDNodes that are processed to |
| 220 | /// create DIEs. |
David Blaikie | 38b74bf | 2016-12-15 23:37:38 +0000 | [diff] [blame] | 221 | SetVector<const DISubprogram *, SmallVector<const DISubprogram *, 16>, |
| 222 | SmallPtrSet<const DISubprogram *, 16>> |
| 223 | ProcessedSPNodes; |
Devang Patel | f3b2db6 | 2010-06-28 18:25:03 +0000 | [diff] [blame] | 224 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 225 | /// If nonnull, stores the current machine function we're processing. |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 226 | const MachineFunction *CurFn = nullptr; |
Timur Iskhodzhanov | 1cd1444 | 2013-12-03 15:10:23 +0000 | [diff] [blame] | 227 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 228 | /// If nonnull, stores the CU in which the previous subprogram was contained. |
Eric Christopher | 384f3fe | 2014-03-20 19:16:16 +0000 | [diff] [blame] | 229 | const DwarfCompileUnit *PrevCU; |
| 230 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 231 | /// As an optimization, there is no need to emit an entry in the directory |
| 232 | /// table for the same directory as DW_AT_comp_dir. |
Nick Lewycky | d1ee7f8 | 2011-11-02 20:55:33 +0000 | [diff] [blame] | 233 | StringRef CompilationDir; |
| 234 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 235 | /// Holder for the file specific debug information. |
Eric Christopher | f819485 | 2013-12-05 18:06:10 +0000 | [diff] [blame] | 236 | DwarfFile InfoHolder; |
Eric Christopher | c8a310e | 2012-12-10 23:34:43 +0000 | [diff] [blame] | 237 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 238 | /// Holders for the various debug information flags that we might need to |
| 239 | /// have exposed. See accessor functions below for description. |
David Blaikie | d51dea6 | 2015-07-01 18:07:16 +0000 | [diff] [blame] | 240 | |
Peter Collingbourne | 7c384cc | 2016-02-11 19:57:46 +0000 | [diff] [blame] | 241 | /// Map from MDNodes for user-defined types to their type signatures. Also |
| 242 | /// used to keep track of which types we have emitted type units for. |
| 243 | DenseMap<const MDNode *, uint64_t> TypeSignatures; |
Eric Christopher | 6764643 | 2013-07-26 17:02:41 +0000 | [diff] [blame] | 244 | |
Duncan P. N. Exon Smith | c624688 | 2015-04-20 21:17:32 +0000 | [diff] [blame] | 245 | SmallVector< |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 246 | std::pair<std::unique_ptr<DwarfTypeUnit>, const DICompositeType *>, 1> |
Eric Christopher | ffc5ff3 | 2015-02-17 20:02:28 +0000 | [diff] [blame] | 247 | TypeUnitsUnderConstruction; |
David Blaikie | e12b49a | 2014-04-26 17:27:38 +0000 | [diff] [blame] | 248 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 249 | /// Whether to use the GNU TLS opcode (instead of the standard opcode). |
Paul Robinson | 78cc082 | 2015-03-04 20:55:11 +0000 | [diff] [blame] | 250 | bool UseGNUTLSOpcode; |
| 251 | |
Adrian Prantl | 6323ddf | 2016-05-17 21:07:16 +0000 | [diff] [blame] | 252 | /// Whether to use DWARF 2 bitfields (instead of the DWARF 4 format). |
| 253 | bool UseDWARF2Bitfields; |
| 254 | |
Paul Robinson | 43d1e45 | 2016-04-18 22:41:41 +0000 | [diff] [blame] | 255 | /// Whether to emit all linkage names, or just abstract subprograms. |
| 256 | bool UseAllLinkageNames; |
Paul Robinson | 78046b4 | 2015-08-11 21:36:45 +0000 | [diff] [blame] | 257 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 258 | /// DWARF5 Experimental Options |
| 259 | /// @{ |
Eric Christopher | 7b30f2e4 | 2012-11-21 00:34:35 +0000 | [diff] [blame] | 260 | bool HasDwarfAccelTables; |
David Blaikie | c53e18d | 2016-05-24 21:19:28 +0000 | [diff] [blame] | 261 | bool HasAppleExtensionAttributes; |
Eric Christopher | cdf218d | 2012-12-10 19:51:21 +0000 | [diff] [blame] | 262 | bool HasSplitDwarf; |
Manman Ren | ac8062b | 2013-07-02 23:40:10 +0000 | [diff] [blame] | 263 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 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. |
Eric Christopher | d79f548 | 2012-12-10 19:51:13 +0000 | [diff] [blame] | 268 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 269 | /// Holder for the skeleton information. |
Eric Christopher | f819485 | 2013-12-05 18:06:10 +0000 | [diff] [blame] | 270 | DwarfFile SkeletonHolder; |
Eric Christopher | d79f548 | 2012-12-10 19:51:13 +0000 | [diff] [blame] | 271 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 272 | /// Store file names for type units under fission in a line table |
| 273 | /// header that will be emitted into debug_line.dwo. |
| 274 | // FIXME: replace this with a map from comp_dir to table so that we |
| 275 | // can emit multiple tables during LTO each of which uses directory |
| 276 | // 0, referencing the comp_dir of all the type units that use it. |
David Blaikie | 8287aff | 2014-03-18 02:13:23 +0000 | [diff] [blame] | 277 | MCDwarfDwoLineTable SplitTypeUnitFileTable; |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 278 | /// @} |
Jonas Devlieghere | 294e689 | 2017-11-15 10:57:05 +0000 | [diff] [blame] | 279 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 280 | /// True iff there are multiple CUs in this module. |
David Blaikie | 47f4b82 | 2014-03-19 00:11:28 +0000 | [diff] [blame] | 281 | bool SingleCU; |
David Blaikie | e1c7974 | 2014-09-30 21:28:32 +0000 | [diff] [blame] | 282 | bool IsDarwin; |
David Blaikie | 47f4b82 | 2014-03-19 00:11:28 +0000 | [diff] [blame] | 283 | |
David Blaikie | d75fb28 | 2014-04-23 21:20:10 +0000 | [diff] [blame] | 284 | AddressPool AddrPool; |
| 285 | |
David Blaikie | 2406a062 | 2014-04-23 23:37:35 +0000 | [diff] [blame] | 286 | DwarfAccelTable AccelNames; |
David Blaikie | 0ee82b9 | 2014-04-24 00:53:32 +0000 | [diff] [blame] | 287 | DwarfAccelTable AccelObjC; |
David Blaikie | ecf0415 | 2014-04-24 01:02:42 +0000 | [diff] [blame] | 288 | DwarfAccelTable AccelNamespace; |
David Blaikie | 18d3375 | 2014-04-24 01:23:49 +0000 | [diff] [blame] | 289 | DwarfAccelTable AccelTypes; |
David Blaikie | 2406a062 | 2014-04-23 23:37:35 +0000 | [diff] [blame] | 290 | |
Paul Robinson | b9de106 | 2015-07-15 22:04:54 +0000 | [diff] [blame] | 291 | // Identify a debugger for "tuning" the debug info. |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 292 | DebuggerKind DebuggerTuning = DebuggerKind::Default; |
Paul Robinson | b9de106 | 2015-07-15 22:04:54 +0000 | [diff] [blame] | 293 | |
David Blaikie | 47f4b82 | 2014-03-19 00:11:28 +0000 | [diff] [blame] | 294 | MCDwarfDwoLineTable *getDwoLineTable(const DwarfCompileUnit &); |
| 295 | |
Peter Collingbourne | 7c384cc | 2016-02-11 19:57:46 +0000 | [diff] [blame] | 296 | const SmallVectorImpl<std::unique_ptr<DwarfCompileUnit>> &getUnits() { |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 297 | return InfoHolder.getUnits(); |
| 298 | } |
David Blaikie | fd1eff5 | 2013-11-26 19:14:34 +0000 | [diff] [blame] | 299 | |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 300 | using InlinedVariable = DbgValueHistoryMap::InlinedVariable; |
Duncan P. N. Exon Smith | 62e0f45 | 2015-04-15 22:29:27 +0000 | [diff] [blame] | 301 | |
David Blaikie | 488393f | 2017-05-12 01:13:45 +0000 | [diff] [blame] | 302 | void ensureAbstractVariableIsCreated(DwarfCompileUnit &CU, InlinedVariable Var, |
David Blaikie | 6f9e867 | 2014-06-13 23:52:55 +0000 | [diff] [blame] | 303 | const MDNode *Scope); |
David Blaikie | 488393f | 2017-05-12 01:13:45 +0000 | [diff] [blame] | 304 | void ensureAbstractVariableIsCreatedIfScoped(DwarfCompileUnit &CU, InlinedVariable Var, |
David Blaikie | 6f9e867 | 2014-06-13 23:52:55 +0000 | [diff] [blame] | 305 | const MDNode *Scope); |
Devang Patel | f6eeaeb | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 306 | |
David Blaikie | 488393f | 2017-05-12 01:13:45 +0000 | [diff] [blame] | 307 | DbgVariable *createConcreteVariable(DwarfCompileUnit &TheCU, |
| 308 | LexicalScope &Scope, InlinedVariable IV); |
Duncan P. N. Exon Smith | e6cc531 | 2015-06-21 16:50:43 +0000 | [diff] [blame] | 309 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 310 | /// Construct a DIE for this abstract scope. |
David Blaikie | 488393f | 2017-05-12 01:13:45 +0000 | [diff] [blame] | 311 | void constructAbstractSubprogramScopeDIE(DwarfCompileUnit &SrcCU, LexicalScope *Scope); |
David Blaikie | 73cc705 | 2014-10-09 20:36:27 +0000 | [diff] [blame] | 312 | |
David Blaikie | eb1a272 | 2014-06-13 22:18:23 +0000 | [diff] [blame] | 313 | void finishVariableDefinitions(); |
| 314 | |
David Blaikie | f7221ad | 2014-05-27 18:37:43 +0000 | [diff] [blame] | 315 | void finishSubprogramDefinitions(); |
| 316 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 317 | /// Finish off debug information after all functions have been |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 318 | /// processed. |
Eric Christopher | 960ac37 | 2012-11-22 00:59:49 +0000 | [diff] [blame] | 319 | void finalizeModuleInfo(); |
| 320 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 321 | /// Emit the debug info section. |
Devang Patel | 930143b | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 322 | void emitDebugInfo(); |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 323 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 324 | /// Emit the abbreviation section. |
Eric Christopher | 3837195 | 2012-11-20 23:30:11 +0000 | [diff] [blame] | 325 | void emitAbbreviations(); |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 326 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 327 | /// Emit a specified accelerator table. |
Rafael Espindola | 0709a7b | 2015-05-21 19:20:38 +0000 | [diff] [blame] | 328 | void emitAccel(DwarfAccelTable &Accel, MCSection *Section, |
Rafael Espindola | 6b9998b | 2015-03-10 22:00:25 +0000 | [diff] [blame] | 329 | StringRef TableName); |
David Blaikie | 6741bb0 | 2014-09-11 21:12:48 +0000 | [diff] [blame] | 330 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 331 | /// Emit visible names into a hashed accelerator table section. |
Eric Christopher | 4996c70 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 332 | void emitAccelNames(); |
Eric Christopher | 27527b2 | 2012-11-21 00:03:28 +0000 | [diff] [blame] | 333 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 334 | /// Emit objective C classes and categories into a hashed |
Eric Christopher | 4996c70 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 335 | /// accelerator table section. |
| 336 | void emitAccelObjC(); |
| 337 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 338 | /// Emit namespace dies into a hashed accelerator table. |
Eric Christopher | 4996c70 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 339 | void emitAccelNamespaces(); |
| 340 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 341 | /// Emit type dies into a hashed accelerator table. |
Eric Christopher | 4996c70 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 342 | void emitAccelTypes(); |
Eric Christopher | 27527b2 | 2012-11-21 00:03:28 +0000 | [diff] [blame] | 343 | |
Peter Collingbourne | b52e236 | 2017-09-12 21:50:41 +0000 | [diff] [blame] | 344 | /// Emit visible names and types into debug pubnames and pubtypes sections. |
| 345 | void emitDebugPubSections(); |
Krzysztof Parzyszek | 228daa6 | 2013-02-12 18:00:14 +0000 | [diff] [blame] | 346 | |
Peter Collingbourne | b52e236 | 2017-09-12 21:50:41 +0000 | [diff] [blame] | 347 | void emitDebugPubSection(bool GnuStyle, StringRef Name, |
| 348 | DwarfCompileUnit *TheU, |
| 349 | const StringMap<const DIE *> &Globals); |
David Blaikie | 0f55e83 | 2014-03-11 23:18:15 +0000 | [diff] [blame] | 350 | |
Amjad Aboud | c077841 | 2016-01-24 08:18:55 +0000 | [diff] [blame] | 351 | /// Emit null-terminated strings into a debug str section. |
Devang Patel | 930143b | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 352 | void emitDebugStr(); |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 353 | |
Amjad Aboud | d7cfb48 | 2016-01-07 14:28:20 +0000 | [diff] [blame] | 354 | /// Emit variable locations into a debug loc section. |
Devang Patel | 930143b | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 355 | void emitDebugLoc(); |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 356 | |
Amjad Aboud | d7cfb48 | 2016-01-07 14:28:20 +0000 | [diff] [blame] | 357 | /// Emit variable locations into a debug loc dwo section. |
David Blaikie | 94c1d7f | 2014-04-02 01:50:20 +0000 | [diff] [blame] | 358 | void emitDebugLocDWO(); |
| 359 | |
Amjad Aboud | d7cfb48 | 2016-01-07 14:28:20 +0000 | [diff] [blame] | 360 | /// Emit address ranges into a debug aranges section. |
Eric Christopher | 7b30f2e4 | 2012-11-21 00:34:35 +0000 | [diff] [blame] | 361 | void emitDebugARanges(); |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 362 | |
Amjad Aboud | d7cfb48 | 2016-01-07 14:28:20 +0000 | [diff] [blame] | 363 | /// Emit address ranges into a debug ranges section. |
Devang Patel | 930143b | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 364 | void emitDebugRanges(); |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 365 | |
Amjad Aboud | d7cfb48 | 2016-01-07 14:28:20 +0000 | [diff] [blame] | 366 | /// Emit macros into a debug macinfo section. |
| 367 | void emitDebugMacinfo(); |
Amjad Aboud | 8bbce8a | 2016-02-01 14:09:41 +0000 | [diff] [blame] | 368 | void emitMacro(DIMacro &M); |
| 369 | void emitMacroFile(DIMacroFile &F, DwarfCompileUnit &U); |
| 370 | void handleMacroNodes(DIMacroNodeArray Nodes, DwarfCompileUnit &U); |
Amjad Aboud | d7cfb48 | 2016-01-07 14:28:20 +0000 | [diff] [blame] | 371 | |
Eric Christopher | cdf218d | 2012-12-10 19:51:21 +0000 | [diff] [blame] | 372 | /// DWARF 5 Experimental Split Dwarf Emitters |
Eric Christopher | 9c2ecd9 | 2012-11-30 23:59:06 +0000 | [diff] [blame] | 373 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 374 | /// Initialize common features of skeleton units. |
David Blaikie | 65a7466 | 2014-04-25 18:26:14 +0000 | [diff] [blame] | 375 | void initSkeletonUnit(const DwarfUnit &U, DIE &Die, |
Peter Collingbourne | 7c384cc | 2016-02-11 19:57:46 +0000 | [diff] [blame] | 376 | std::unique_ptr<DwarfCompileUnit> NewU); |
David Blaikie | 38fe634 | 2014-01-09 04:28:46 +0000 | [diff] [blame] | 377 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 378 | /// Construct the split debug info compile unit for the debug info |
Eric Christopher | cdf218d | 2012-12-10 19:51:21 +0000 | [diff] [blame] | 379 | /// section. |
David Blaikie | f9b6a55 | 2014-04-22 22:39:41 +0000 | [diff] [blame] | 380 | DwarfCompileUnit &constructSkeletonCU(const DwarfCompileUnit &CU); |
Eric Christopher | 9c2ecd9 | 2012-11-30 23:59:06 +0000 | [diff] [blame] | 381 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 382 | /// Emit the debug info dwo section. |
Eric Christopher | 9c2ecd9 | 2012-11-30 23:59:06 +0000 | [diff] [blame] | 383 | void emitDebugInfoDWO(); |
| 384 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 385 | /// Emit the debug abbrev dwo section. |
Eric Christopher | 3c5a191 | 2012-12-19 22:02:53 +0000 | [diff] [blame] | 386 | void emitDebugAbbrevDWO(); |
| 387 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 388 | /// Emit the debug line dwo section. |
David Blaikie | 4a2f95f | 2014-03-18 01:17:26 +0000 | [diff] [blame] | 389 | void emitDebugLineDWO(); |
| 390 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 391 | /// Emit the debug str dwo section. |
Eric Christopher | 3bf29fd | 2012-12-27 02:14:01 +0000 | [diff] [blame] | 392 | void emitDebugStrDWO(); |
| 393 | |
David Blaikie | 3c84262 | 2013-12-04 21:31:26 +0000 | [diff] [blame] | 394 | /// Flags to let the linker know we have emitted new style pubnames. Only |
| 395 | /// emit it here if we don't have a skeleton CU for split dwarf. |
David Blaikie | b3cee2f | 2017-05-25 18:50:28 +0000 | [diff] [blame] | 396 | void addGnuPubAttributes(DwarfCompileUnit &U, DIE &D) const; |
David Blaikie | 3c84262 | 2013-12-04 21:31:26 +0000 | [diff] [blame] | 397 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 398 | /// Create new DwarfCompileUnit for the given metadata node with tag |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 399 | /// DW_TAG_compile_unit. |
David Blaikie | 07963bd | 2017-05-26 18:52:56 +0000 | [diff] [blame] | 400 | DwarfCompileUnit &getOrCreateDwarfCompileUnit(const DICompileUnit *DIUnit); |
Devang Patel | 1a0df9a | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 401 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 402 | /// Construct imported_module or imported_declaration DIE. |
David Blaikie | 8912df1 | 2014-08-31 05:41:15 +0000 | [diff] [blame] | 403 | void constructAndAddImportedEntityDIE(DwarfCompileUnit &TheCU, |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 404 | const DIImportedEntity *N); |
David Blaikie | 684fc53 | 2013-05-06 23:33:07 +0000 | [diff] [blame] | 405 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 406 | /// Register a source line with debug info. Returns the unique |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 407 | /// label that was emitted and which provides correspondence to the |
| 408 | /// source line list. |
Devang Patel | 34a6620 | 2011-05-11 19:22:19 +0000 | [diff] [blame] | 409 | void recordSourceLine(unsigned Line, unsigned Col, const MDNode *Scope, |
| 410 | unsigned Flags); |
Eric Christopher | 27527b2 | 2012-11-21 00:03:28 +0000 | [diff] [blame] | 411 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 412 | /// Populate LexicalScope entries with variables' info. |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 413 | void collectVariableInfo(DwarfCompileUnit &TheCU, const DISubprogram *SP, |
Duncan P. N. Exon Smith | 62e0f45 | 2015-04-15 22:29:27 +0000 | [diff] [blame] | 414 | DenseSet<InlinedVariable> &ProcessedVars); |
Eric Christopher | 27527b2 | 2012-11-21 00:03:28 +0000 | [diff] [blame] | 415 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 416 | /// Build the location list for all DBG_VALUEs in the |
Adrian Prantl | b141683 | 2014-08-01 22:11:58 +0000 | [diff] [blame] | 417 | /// function that describe the same variable. |
| 418 | void buildLocationList(SmallVectorImpl<DebugLocEntry> &DebugLoc, |
David Blaikie | e1a26a6 | 2014-08-05 23:14:16 +0000 | [diff] [blame] | 419 | const DbgValueHistoryMap::InstrRanges &Ranges); |
Adrian Prantl | b141683 | 2014-08-01 22:11:58 +0000 | [diff] [blame] | 420 | |
Matthias Braun | ef331ef | 2016-11-30 23:48:50 +0000 | [diff] [blame] | 421 | /// Collect variable information from the side table maintained by MF. |
David Blaikie | 488393f | 2017-05-12 01:13:45 +0000 | [diff] [blame] | 422 | void collectVariableInfoFromMFTable(DwarfCompileUnit &TheCU, |
| 423 | DenseSet<InlinedVariable> &P); |
Jakob Stoklund Olesen | 9a624fa | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 424 | |
David Blaikie | b2fbb4b | 2017-02-16 18:48:33 +0000 | [diff] [blame] | 425 | protected: |
| 426 | /// Gather pre-function debug information. |
| 427 | void beginFunctionImpl(const MachineFunction *MF) override; |
| 428 | |
| 429 | /// Gather and emit post-function debug information. |
| 430 | void endFunctionImpl(const MachineFunction *MF) override; |
| 431 | |
| 432 | void skippedNonDebugFunction() override; |
| 433 | |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 434 | public: |
| 435 | //===--------------------------------------------------------------------===// |
| 436 | // Main entry points. |
| 437 | // |
Chris Lattner | f0d6bd3 | 2010-04-05 05:11:15 +0000 | [diff] [blame] | 438 | DwarfDebug(AsmPrinter *A, Module *M); |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 439 | |
Reid Kleckner | dd2647e | 2014-04-30 20:34:31 +0000 | [diff] [blame] | 440 | ~DwarfDebug() override; |
| 441 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 442 | /// Emit all Dwarf sections that should come prior to the |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 443 | /// content. |
Eric Christopher | 58f4195 | 2012-11-19 22:42:15 +0000 | [diff] [blame] | 444 | void beginModule(); |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 445 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 446 | /// Emit all Dwarf sections that should come after the content. |
Craig Topper | 7b883b3 | 2014-03-08 06:31:39 +0000 | [diff] [blame] | 447 | void endModule() override; |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 448 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 449 | /// Process beginning of an instruction. |
Craig Topper | 7b883b3 | 2014-03-08 06:31:39 +0000 | [diff] [blame] | 450 | void beginInstruction(const MachineInstr *MI) override; |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 451 | |
Adrian Prantl | ee5feaf | 2015-07-15 17:01:41 +0000 | [diff] [blame] | 452 | /// Perform an MD5 checksum of \p Identifier and return the lower 64 bits. |
| 453 | static uint64_t makeTypeSignature(StringRef Identifier); |
| 454 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 455 | /// Add a DIE to the set of types that we're going to pull into |
Eric Christopher | 6764643 | 2013-07-26 17:02:41 +0000 | [diff] [blame] | 456 | /// type units. |
David Blaikie | 15632ae | 2014-02-12 00:31:30 +0000 | [diff] [blame] | 457 | void addDwarfTypeUnitType(DwarfCompileUnit &CU, StringRef Identifier, |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 458 | DIE &Die, const DICompositeType *CTy); |
Eric Christopher | 6764643 | 2013-07-26 17:02:41 +0000 | [diff] [blame] | 459 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 460 | /// Add a label so that arange data can be generated for it. |
Alexey Samsonov | 4436bf0 | 2013-10-03 08:54:43 +0000 | [diff] [blame] | 461 | void addArangeLabel(SymbolCU SCU) { ArangeLabels.push_back(SCU); } |
Richard Mitton | 21101b3 | 2013-09-19 23:21:01 +0000 | [diff] [blame] | 462 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 463 | /// For symbols that have a size designated (e.g. common symbols), |
Richard Mitton | 089ed89 | 2013-09-23 17:56:20 +0000 | [diff] [blame] | 464 | /// this tracks that size. |
Craig Topper | 7b883b3 | 2014-03-08 06:31:39 +0000 | [diff] [blame] | 465 | void setSymbolSize(const MCSymbol *Sym, uint64_t Size) override { |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 466 | SymSize[Sym] = Size; |
| 467 | } |
Richard Mitton | 089ed89 | 2013-09-23 17:56:20 +0000 | [diff] [blame] | 468 | |
Paul Robinson | 43d1e45 | 2016-04-18 22:41:41 +0000 | [diff] [blame] | 469 | /// Returns whether we should emit all DW_AT_[MIPS_]linkage_name. |
| 470 | /// If not, we still might emit certain cases. |
| 471 | bool useAllLinkageNames() const { return UseAllLinkageNames; } |
Paul Robinson | 78046b4 | 2015-08-11 21:36:45 +0000 | [diff] [blame] | 472 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 473 | /// Returns whether to use DW_OP_GNU_push_tls_address, instead of the |
Paul Robinson | 78cc082 | 2015-03-04 20:55:11 +0000 | [diff] [blame] | 474 | /// standard DW_OP_form_tls_address opcode |
| 475 | bool useGNUTLSOpcode() const { return UseGNUTLSOpcode; } |
| 476 | |
Adrian Prantl | 6323ddf | 2016-05-17 21:07:16 +0000 | [diff] [blame] | 477 | /// Returns whether to use the DWARF2 format for bitfields instyead of the |
| 478 | /// DWARF4 format. |
| 479 | bool useDWARF2Bitfields() const { return UseDWARF2Bitfields; } |
| 480 | |
Eric Christopher | 55c5181 | 2012-11-21 00:03:31 +0000 | [diff] [blame] | 481 | // Experimental DWARF5 features. |
| 482 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 483 | /// Returns whether or not to emit tables that dwarf consumers can |
Eric Christopher | acdcbdb | 2012-11-27 22:43:45 +0000 | [diff] [blame] | 484 | /// use to accelerate lookup. |
Eric Christopher | 411bd59 | 2014-03-06 00:00:53 +0000 | [diff] [blame] | 485 | bool useDwarfAccelTables() const { return HasDwarfAccelTables; } |
Eric Christopher | 55c5181 | 2012-11-21 00:03:31 +0000 | [diff] [blame] | 486 | |
David Blaikie | c53e18d | 2016-05-24 21:19:28 +0000 | [diff] [blame] | 487 | bool useAppleExtensionAttributes() const { |
| 488 | return HasAppleExtensionAttributes; |
| 489 | } |
| 490 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 491 | /// Returns whether or not to change the current debug info for the |
Eric Christopher | cdf218d | 2012-12-10 19:51:21 +0000 | [diff] [blame] | 492 | /// split dwarf proposal support. |
Eric Christopher | 411bd59 | 2014-03-06 00:00:53 +0000 | [diff] [blame] | 493 | bool useSplitDwarf() const { return HasSplitDwarf; } |
Manman Ren | ac8062b | 2013-07-02 23:40:10 +0000 | [diff] [blame] | 494 | |
David Blaikie | 488393f | 2017-05-12 01:13:45 +0000 | [diff] [blame] | 495 | bool shareAcrossDWOCUs() const; |
| 496 | |
Manman Ren | ac8062b | 2013-07-02 23:40:10 +0000 | [diff] [blame] | 497 | /// Returns the Dwarf Version. |
Greg Clayton | e654397 | 2016-11-23 23:30:37 +0000 | [diff] [blame] | 498 | uint16_t getDwarfVersion() const; |
Manman Ren | 6035203 | 2013-09-05 18:48:31 +0000 | [diff] [blame] | 499 | |
Eric Christopher | 384f3fe | 2014-03-20 19:16:16 +0000 | [diff] [blame] | 500 | /// Returns the previous CU that was being updated |
| 501 | const DwarfCompileUnit *getPrevCU() const { return PrevCU; } |
David Blaikie | d0f1037 | 2014-09-09 23:13:01 +0000 | [diff] [blame] | 502 | void setPrevCU(const DwarfCompileUnit *PrevCU) { this->PrevCU = PrevCU; } |
Eric Christopher | 384f3fe | 2014-03-20 19:16:16 +0000 | [diff] [blame] | 503 | |
Eric Christopher | 4f17ee0 | 2014-03-08 00:29:41 +0000 | [diff] [blame] | 504 | /// Returns the entries for the .debug_loc section. |
Duncan P. N. Exon Smith | 364a300 | 2015-04-17 21:34:47 +0000 | [diff] [blame] | 505 | const DebugLocStream &getDebugLocs() const { return DebugLocs; } |
Eric Christopher | 4f17ee0 | 2014-03-08 00:29:41 +0000 | [diff] [blame] | 506 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 507 | /// Emit an entry for the debug loc section. This can be used to |
Eric Christopher | 4f17ee0 | 2014-03-08 00:29:41 +0000 | [diff] [blame] | 508 | /// handle an entry that's going to be emitted into the debug loc section. |
Adrian Prantl | 92da14b | 2015-03-02 22:02:33 +0000 | [diff] [blame] | 509 | void emitDebugLocEntry(ByteStreamer &Streamer, |
Duncan P. N. Exon Smith | 364a300 | 2015-04-17 21:34:47 +0000 | [diff] [blame] | 510 | const DebugLocStream::Entry &Entry); |
Eric Christopher | 4f17ee0 | 2014-03-08 00:29:41 +0000 | [diff] [blame] | 511 | |
David Blaikie | 0e84adc | 2014-04-01 16:17:41 +0000 | [diff] [blame] | 512 | /// Emit the location for a debug loc entry, including the size header. |
Duncan P. N. Exon Smith | 364a300 | 2015-04-17 21:34:47 +0000 | [diff] [blame] | 513 | void emitDebugLocEntryLocation(const DebugLocStream::Entry &Entry); |
David Blaikie | 0e84adc | 2014-04-01 16:17:41 +0000 | [diff] [blame] | 514 | |
Eric Christopher | 87b9c49 | 2013-10-05 00:32:34 +0000 | [diff] [blame] | 515 | /// Find the MDNode for the given reference. |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 516 | template <typename T> T *resolve(TypedDINodeRef<T> Ref) const { |
Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 517 | return Ref.resolve(); |
Adrian Prantl | 1a1647c | 2014-03-18 02:34:58 +0000 | [diff] [blame] | 518 | } |
| 519 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 520 | void addSubprogramNames(const DISubprogram *SP, DIE &Die); |
David Blaikie | 2406a062 | 2014-04-23 23:37:35 +0000 | [diff] [blame] | 521 | |
David Blaikie | d75fb28 | 2014-04-23 21:20:10 +0000 | [diff] [blame] | 522 | AddressPool &getAddressPool() { return AddrPool; } |
David Blaikie | 2406a062 | 2014-04-23 23:37:35 +0000 | [diff] [blame] | 523 | |
David Blaikie | b0b3fcf | 2014-04-25 18:52:29 +0000 | [diff] [blame] | 524 | void addAccelName(StringRef Name, const DIE &Die); |
David Blaikie | 0ee82b9 | 2014-04-24 00:53:32 +0000 | [diff] [blame] | 525 | |
David Blaikie | b0b3fcf | 2014-04-25 18:52:29 +0000 | [diff] [blame] | 526 | void addAccelObjC(StringRef Name, const DIE &Die); |
David Blaikie | ecf0415 | 2014-04-24 01:02:42 +0000 | [diff] [blame] | 527 | |
David Blaikie | b0b3fcf | 2014-04-25 18:52:29 +0000 | [diff] [blame] | 528 | void addAccelNamespace(StringRef Name, const DIE &Die); |
David Blaikie | 18d3375 | 2014-04-24 01:23:49 +0000 | [diff] [blame] | 529 | |
David Blaikie | b0b3fcf | 2014-04-25 18:52:29 +0000 | [diff] [blame] | 530 | void addAccelType(StringRef Name, const DIE &Die, char Flags); |
David Blaikie | cda2aa8 | 2014-10-04 16:24:00 +0000 | [diff] [blame] | 531 | |
| 532 | const MachineFunction *getCurrentFunction() const { return CurFn; } |
David Blaikie | 9c65b13 | 2014-10-08 22:20:02 +0000 | [diff] [blame] | 533 | |
Adrian Prantl | 857237e | 2015-07-13 18:25:29 +0000 | [diff] [blame] | 534 | /// A helper function to check whether the DIE for a given Scope is |
David Blaikie | 9c65b13 | 2014-10-08 22:20:02 +0000 | [diff] [blame] | 535 | /// going to be null. |
| 536 | bool isLexicalScopeDIENull(LexicalScope *Scope); |
David Blaikie | b3cee2f | 2017-05-25 18:50:28 +0000 | [diff] [blame] | 537 | |
Jonas Devlieghere | 294e689 | 2017-11-15 10:57:05 +0000 | [diff] [blame] | 538 | /// Find the matching DwarfCompileUnit for the given CU DIE. |
| 539 | DwarfCompileUnit *lookupCU(const DIE *Die) { return CUDieMap.lookup(Die); } |
| 540 | |
Peter Collingbourne | b52e236 | 2017-09-12 21:50:41 +0000 | [diff] [blame] | 541 | /// \defgroup DebuggerTuning Predicates to tune DWARF for a given debugger. |
| 542 | /// |
| 543 | /// Returns whether we are "tuning" for a given debugger. |
| 544 | /// @{ |
| 545 | bool tuneForGDB() const { return DebuggerTuning == DebuggerKind::GDB; } |
| 546 | bool tuneForLLDB() const { return DebuggerTuning == DebuggerKind::LLDB; } |
| 547 | bool tuneForSCE() const { return DebuggerTuning == DebuggerKind::SCE; } |
| 548 | /// @} |
Devang Patel | f6eeaeb | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 549 | }; |
Bill Wendling | 2f921f8 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 550 | |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 551 | } // end namespace llvm |
| 552 | |
| 553 | #endif // LLVM_LIB_CODEGEN_ASMPRINTER_DWARFDEBUG_H |