Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1 | //===-- llvm/CodeGen/DwarfDebug.cpp - Dwarf Debug Framework ---------------===// |
| 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 | //===----------------------------------------------------------------------===// |
Chris Lattner | 6cde3e6 | 2010-03-09 00:39:24 +0000 | [diff] [blame] | 13 | |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 14 | #define DEBUG_TYPE "dwarfdebug" |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 15 | #include "DwarfDebug.h" |
Chris Lattner | 74e41f9 | 2010-04-05 05:24:55 +0000 | [diff] [blame] | 16 | #include "DIE.h" |
Devang Patel | 8b9df62 | 2011-04-12 17:40:32 +0000 | [diff] [blame] | 17 | #include "DwarfCompileUnit.h" |
Bill Wendling | 57fbba4 | 2010-04-05 22:59:21 +0000 | [diff] [blame] | 18 | #include "llvm/Constants.h" |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 19 | #include "llvm/Module.h" |
Devang Patel | e449d1f | 2011-01-20 00:02:16 +0000 | [diff] [blame] | 20 | #include "llvm/Instructions.h" |
David Greene | b2c66fc | 2009-08-19 21:52:55 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/MachineFunction.h" |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 22 | #include "llvm/CodeGen/MachineModuleInfo.h" |
Chris Lattner | b7db733 | 2010-03-09 01:58:53 +0000 | [diff] [blame] | 23 | #include "llvm/MC/MCAsmInfo.h" |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 24 | #include "llvm/MC/MCSection.h" |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 25 | #include "llvm/MC/MCStreamer.h" |
Chris Lattner | b7db733 | 2010-03-09 01:58:53 +0000 | [diff] [blame] | 26 | #include "llvm/MC/MCSymbol.h" |
Chris Lattner | 45111d1 | 2010-01-16 21:57:06 +0000 | [diff] [blame] | 27 | #include "llvm/Target/Mangler.h" |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 28 | #include "llvm/Target/TargetData.h" |
Anton Korobeynikov | 16c29b5 | 2011-01-10 12:39:04 +0000 | [diff] [blame] | 29 | #include "llvm/Target/TargetFrameLowering.h" |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 30 | #include "llvm/Target/TargetLoweringObjectFile.h" |
Chris Lattner | 9d1c1ad | 2010-04-04 18:06:11 +0000 | [diff] [blame] | 31 | #include "llvm/Target/TargetMachine.h" |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 32 | #include "llvm/Target/TargetRegisterInfo.h" |
Devang Patel | 2a4a3b7 | 2010-04-19 19:14:02 +0000 | [diff] [blame] | 33 | #include "llvm/Target/TargetOptions.h" |
Chris Lattner | 74e41f9 | 2010-04-05 05:24:55 +0000 | [diff] [blame] | 34 | #include "llvm/Analysis/DebugInfo.h" |
Devang Patel | 0eea95d | 2011-02-24 18:49:30 +0000 | [diff] [blame] | 35 | #include "llvm/Analysis/DIBuilder.h" |
Devang Patel | 9a31f0f | 2010-10-25 20:45:32 +0000 | [diff] [blame] | 36 | #include "llvm/ADT/Statistic.h" |
Jeffrey Yasskin | 5c213dc | 2010-03-12 17:45:06 +0000 | [diff] [blame] | 37 | #include "llvm/ADT/STLExtras.h" |
Chris Lattner | 23132b1 | 2009-08-24 03:52:50 +0000 | [diff] [blame] | 38 | #include "llvm/ADT/StringExtras.h" |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 39 | #include "llvm/Support/CommandLine.h" |
Daniel Dunbar | 6e4bdfc | 2009-10-13 06:47:08 +0000 | [diff] [blame] | 40 | #include "llvm/Support/Debug.h" |
| 41 | #include "llvm/Support/ErrorHandling.h" |
Devang Patel | 3139fcf | 2010-01-26 21:39:14 +0000 | [diff] [blame] | 42 | #include "llvm/Support/ValueHandle.h" |
Chris Lattner | 0ad9c91 | 2010-01-22 22:09:00 +0000 | [diff] [blame] | 43 | #include "llvm/Support/FormattedStream.h" |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 44 | #include "llvm/Support/Timer.h" |
Michael J. Spencer | 1f6efa3 | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 45 | #include "llvm/Support/Path.h" |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 46 | using namespace llvm; |
| 47 | |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 48 | static cl::opt<bool> PrintDbgScope("print-dbgscope", cl::Hidden, |
| 49 | cl::desc("Print DbgScope information for each machine instruction")); |
| 50 | |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 51 | static cl::opt<bool> DisableDebugInfoPrinting("disable-debug-info-print", |
Devang Patel | 6140962 | 2010-07-07 20:12:52 +0000 | [diff] [blame] | 52 | cl::Hidden, |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 53 | cl::desc("Disable debug info printing")); |
| 54 | |
Dan Gohman | 281d65d | 2010-05-07 01:08:53 +0000 | [diff] [blame] | 55 | static cl::opt<bool> UnknownLocations("use-unknown-locations", cl::Hidden, |
| 56 | cl::desc("Make an absense of debug location information explicit."), |
| 57 | cl::init(false)); |
| 58 | |
Nick Lewycky | a568d66 | 2010-10-26 00:51:57 +0000 | [diff] [blame] | 59 | #ifndef NDEBUG |
Devang Patel | 9a31f0f | 2010-10-25 20:45:32 +0000 | [diff] [blame] | 60 | STATISTIC(BlocksWithoutLineNo, "Number of blocks without any line number"); |
Nick Lewycky | a568d66 | 2010-10-26 00:51:57 +0000 | [diff] [blame] | 61 | #endif |
Devang Patel | 9a31f0f | 2010-10-25 20:45:32 +0000 | [diff] [blame] | 62 | |
Bill Wendling | 5f017e8 | 2010-04-07 09:28:04 +0000 | [diff] [blame] | 63 | namespace { |
| 64 | const char *DWARFGroupName = "DWARF Emission"; |
| 65 | const char *DbgTimerName = "DWARF Debug Writer"; |
| 66 | } // end anonymous namespace |
| 67 | |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 68 | //===----------------------------------------------------------------------===// |
| 69 | |
| 70 | /// Configuration values for initial hash set sizes (log2). |
| 71 | /// |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 72 | static const unsigned InitAbbreviationsSetSize = 9; // log2(512) |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 73 | |
| 74 | namespace llvm { |
| 75 | |
| 76 | //===----------------------------------------------------------------------===// |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 77 | /// DbgVariable - This class is used to track local variable information. |
| 78 | /// |
Devang Patel | f76a3d6 | 2009-11-16 21:53:40 +0000 | [diff] [blame] | 79 | class DbgVariable { |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 80 | DIVariable Var; // Variable Descriptor. |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 81 | DIE *TheDIE; // Variable DIE. |
| 82 | unsigned DotDebugLocOffset; // Offset in DotDebugLocEntries. |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 83 | public: |
Jeffrey Yasskin | 5c213dc | 2010-03-12 17:45:06 +0000 | [diff] [blame] | 84 | // AbsVar may be NULL. |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 85 | DbgVariable(DIVariable V) : Var(V), TheDIE(0), DotDebugLocOffset(~0U) {} |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 86 | |
| 87 | // Accessors. |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 88 | DIVariable getVariable() const { return Var; } |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 89 | void setDIE(DIE *D) { TheDIE = D; } |
| 90 | DIE *getDIE() const { return TheDIE; } |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 91 | void setDotDebugLocOffset(unsigned O) { DotDebugLocOffset = O; } |
| 92 | unsigned getDotDebugLocOffset() const { return DotDebugLocOffset; } |
Devang Patel | 8bd11de | 2010-08-09 21:01:39 +0000 | [diff] [blame] | 93 | StringRef getName() const { return Var.getName(); } |
| 94 | unsigned getTag() const { return Var.getTag(); } |
| 95 | bool variableHasComplexAddress() const { |
| 96 | assert(Var.Verify() && "Invalid complex DbgVariable!"); |
| 97 | return Var.hasComplexAddress(); |
| 98 | } |
| 99 | bool isBlockByrefVariable() const { |
| 100 | assert(Var.Verify() && "Invalid complex DbgVariable!"); |
| 101 | return Var.isBlockByrefVariable(); |
| 102 | } |
| 103 | unsigned getNumAddrElements() const { |
| 104 | assert(Var.Verify() && "Invalid complex DbgVariable!"); |
| 105 | return Var.getNumAddrElements(); |
| 106 | } |
| 107 | uint64_t getAddrElement(unsigned i) const { |
| 108 | return Var.getAddrElement(i); |
| 109 | } |
| 110 | DIType getType() const { |
| 111 | DIType Ty = Var.getType(); |
| 112 | // FIXME: isBlockByrefVariable should be reformulated in terms of complex |
| 113 | // addresses instead. |
| 114 | if (Var.isBlockByrefVariable()) { |
| 115 | /* Byref variables, in Blocks, are declared by the programmer as |
| 116 | "SomeType VarName;", but the compiler creates a |
| 117 | __Block_byref_x_VarName struct, and gives the variable VarName |
| 118 | either the struct, or a pointer to the struct, as its type. This |
| 119 | is necessary for various behind-the-scenes things the compiler |
| 120 | needs to do with by-reference variables in blocks. |
| 121 | |
| 122 | However, as far as the original *programmer* is concerned, the |
| 123 | variable should still have type 'SomeType', as originally declared. |
| 124 | |
| 125 | The following function dives into the __Block_byref_x_VarName |
| 126 | struct to find the original type of the variable. This will be |
| 127 | passed back to the code generating the type for the Debug |
| 128 | Information Entry for the variable 'VarName'. 'VarName' will then |
| 129 | have the original type 'SomeType' in its debug information. |
| 130 | |
| 131 | The original type 'SomeType' will be the type of the field named |
| 132 | 'VarName' inside the __Block_byref_x_VarName struct. |
| 133 | |
| 134 | NOTE: In order for this to not completely fail on the debugger |
| 135 | side, the Debug Information Entry for the variable VarName needs to |
| 136 | have a DW_AT_location that tells the debugger how to unwind through |
| 137 | the pointers and __Block_byref_x_VarName struct to find the actual |
| 138 | value of the variable. The function addBlockByrefType does this. */ |
| 139 | DIType subType = Ty; |
| 140 | unsigned tag = Ty.getTag(); |
| 141 | |
| 142 | if (tag == dwarf::DW_TAG_pointer_type) { |
| 143 | DIDerivedType DTy = DIDerivedType(Ty); |
| 144 | subType = DTy.getTypeDerivedFrom(); |
| 145 | } |
| 146 | |
| 147 | DICompositeType blockStruct = DICompositeType(subType); |
| 148 | DIArray Elements = blockStruct.getTypeArray(); |
| 149 | |
| 150 | for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) { |
| 151 | DIDescriptor Element = Elements.getElement(i); |
| 152 | DIDerivedType DT = DIDerivedType(Element); |
| 153 | if (getName() == DT.getName()) |
| 154 | return (DT.getTypeDerivedFrom()); |
| 155 | } |
| 156 | return Ty; |
| 157 | } |
| 158 | return Ty; |
| 159 | } |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 160 | }; |
| 161 | |
| 162 | //===----------------------------------------------------------------------===// |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 163 | /// DbgRange - This is used to track range of instructions with identical |
| 164 | /// debug info scope. |
| 165 | /// |
| 166 | typedef std::pair<const MachineInstr *, const MachineInstr *> DbgRange; |
| 167 | |
| 168 | //===----------------------------------------------------------------------===// |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 169 | /// DbgScope - This class is used to track scope information. |
| 170 | /// |
Devang Patel | f76a3d6 | 2009-11-16 21:53:40 +0000 | [diff] [blame] | 171 | class DbgScope { |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 172 | DbgScope *Parent; // Parent to this scope. |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 173 | DIDescriptor Desc; // Debug info descriptor for scope. |
Devang Patel | 3139fcf | 2010-01-26 21:39:14 +0000 | [diff] [blame] | 174 | // Location at which this scope is inlined. |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 175 | AssertingVH<const MDNode> InlinedAtLocation; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 176 | bool AbstractScope; // Abstract Scope |
Devang Patel | d38dd11 | 2009-10-01 18:25:23 +0000 | [diff] [blame] | 177 | const MachineInstr *LastInsn; // Last instruction of this scope. |
| 178 | const MachineInstr *FirstInsn; // First instruction of this scope. |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 179 | unsigned DFSIn, DFSOut; |
Jeffrey Yasskin | 5c213dc | 2010-03-12 17:45:06 +0000 | [diff] [blame] | 180 | // Scopes defined in scope. Contents not owned. |
| 181 | SmallVector<DbgScope *, 4> Scopes; |
| 182 | // Variables declared in scope. Contents owned. |
| 183 | SmallVector<DbgVariable *, 8> Variables; |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 184 | SmallVector<DbgRange, 4> Ranges; |
Owen Anderson | 04c05f7 | 2009-06-24 22:53:20 +0000 | [diff] [blame] | 185 | // Private state for dump() |
| 186 | mutable unsigned IndentLevel; |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 187 | public: |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 188 | DbgScope(DbgScope *P, DIDescriptor D, const MDNode *I = 0) |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 189 | : Parent(P), Desc(D), InlinedAtLocation(I), AbstractScope(false), |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 190 | LastInsn(0), FirstInsn(0), |
| 191 | DFSIn(0), DFSOut(0), IndentLevel(0) {} |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 192 | virtual ~DbgScope(); |
| 193 | |
| 194 | // Accessors. |
| 195 | DbgScope *getParent() const { return Parent; } |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 196 | void setParent(DbgScope *P) { Parent = P; } |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 197 | DIDescriptor getDesc() const { return Desc; } |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 198 | const MDNode *getInlinedAt() const { return InlinedAtLocation; } |
| 199 | const MDNode *getScopeNode() const { return Desc; } |
Jeffrey Yasskin | 5c213dc | 2010-03-12 17:45:06 +0000 | [diff] [blame] | 200 | const SmallVector<DbgScope *, 4> &getScopes() { return Scopes; } |
Devang Patel | e03161c | 2010-08-09 18:51:29 +0000 | [diff] [blame] | 201 | const SmallVector<DbgVariable *, 8> &getDbgVariables() { return Variables; } |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 202 | const SmallVector<DbgRange, 4> &getRanges() { return Ranges; } |
| 203 | |
| 204 | /// openInsnRange - This scope covers instruction range starting from MI. |
| 205 | void openInsnRange(const MachineInstr *MI) { |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 206 | if (!FirstInsn) |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 207 | FirstInsn = MI; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 208 | |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 209 | if (Parent) |
| 210 | Parent->openInsnRange(MI); |
| 211 | } |
| 212 | |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 213 | /// extendInsnRange - Extend the current instruction range covered by |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 214 | /// this scope. |
| 215 | void extendInsnRange(const MachineInstr *MI) { |
| 216 | assert (FirstInsn && "MI Range is not open!"); |
| 217 | LastInsn = MI; |
| 218 | if (Parent) |
| 219 | Parent->extendInsnRange(MI); |
| 220 | } |
| 221 | |
| 222 | /// closeInsnRange - Create a range based on FirstInsn and LastInsn collected |
| 223 | /// until now. This is used when a new scope is encountered while walking |
| 224 | /// machine instructions. |
| 225 | void closeInsnRange(DbgScope *NewScope = NULL) { |
| 226 | assert (LastInsn && "Last insn missing!"); |
| 227 | Ranges.push_back(DbgRange(FirstInsn, LastInsn)); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 228 | FirstInsn = NULL; |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 229 | LastInsn = NULL; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 230 | // If Parent dominates NewScope then do not close Parent's instruction |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 231 | // range. |
| 232 | if (Parent && (!NewScope || !Parent->dominates(NewScope))) |
| 233 | Parent->closeInsnRange(NewScope); |
| 234 | } |
| 235 | |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 236 | void setAbstractScope() { AbstractScope = true; } |
| 237 | bool isAbstractScope() const { return AbstractScope; } |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 238 | |
| 239 | // Depth First Search support to walk and mainpluate DbgScope hierarchy. |
| 240 | unsigned getDFSOut() const { return DFSOut; } |
| 241 | void setDFSOut(unsigned O) { DFSOut = O; } |
| 242 | unsigned getDFSIn() const { return DFSIn; } |
| 243 | void setDFSIn(unsigned I) { DFSIn = I; } |
| 244 | bool dominates(const DbgScope *S) { |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 245 | if (S == this) |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 246 | return true; |
| 247 | if (DFSIn < S->getDFSIn() && DFSOut > S->getDFSOut()) |
| 248 | return true; |
| 249 | return false; |
| 250 | } |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 251 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 252 | /// addScope - Add a scope to the scope. |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 253 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 254 | void addScope(DbgScope *S) { Scopes.push_back(S); } |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 255 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 256 | /// addVariable - Add a variable to the scope. |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 257 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 258 | void addVariable(DbgVariable *V) { Variables.push_back(V); } |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 259 | |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 260 | #ifndef NDEBUG |
| 261 | void dump() const; |
| 262 | #endif |
| 263 | }; |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 264 | |
Chris Lattner | ea76186 | 2010-04-05 04:09:20 +0000 | [diff] [blame] | 265 | } // end llvm namespace |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 266 | |
| 267 | #ifndef NDEBUG |
| 268 | void DbgScope::dump() const { |
David Greene | f83adbc | 2009-12-24 00:31:35 +0000 | [diff] [blame] | 269 | raw_ostream &err = dbgs(); |
Chris Lattner | c281de1 | 2009-08-23 00:51:00 +0000 | [diff] [blame] | 270 | err.indent(IndentLevel); |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 271 | const MDNode *N = Desc; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 272 | N->dump(); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 273 | if (AbstractScope) |
| 274 | err << "Abstract Scope\n"; |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 275 | |
| 276 | IndentLevel += 2; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 277 | if (!Scopes.empty()) |
| 278 | err << "Children ...\n"; |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 279 | for (unsigned i = 0, e = Scopes.size(); i != e; ++i) |
| 280 | if (Scopes[i] != this) |
| 281 | Scopes[i]->dump(); |
| 282 | |
| 283 | IndentLevel -= 2; |
| 284 | } |
| 285 | #endif |
| 286 | |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 287 | DbgScope::~DbgScope() { |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 288 | for (unsigned j = 0, M = Variables.size(); j < M; ++j) |
| 289 | delete Variables[j]; |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 290 | } |
| 291 | |
Chris Lattner | 49cd664 | 2010-04-05 05:11:15 +0000 | [diff] [blame] | 292 | DwarfDebug::DwarfDebug(AsmPrinter *A, Module *M) |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 293 | : Asm(A), MMI(Asm->MMI), FirstCU(0), |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 294 | AbbreviationsSet(InitAbbreviationsSetSize), |
Devang Patel | f2548ca | 2010-04-16 23:33:45 +0000 | [diff] [blame] | 295 | CurrentFnDbgScope(0), PrevLabel(NULL) { |
Chris Lattner | bc733f5 | 2010-03-13 02:17:42 +0000 | [diff] [blame] | 296 | NextStringPoolNumber = 0; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 297 | |
Chris Lattner | 4ad1efe | 2010-04-04 23:10:38 +0000 | [diff] [blame] | 298 | DwarfFrameSectionSym = DwarfInfoSectionSym = DwarfAbbrevSectionSym = 0; |
| 299 | DwarfStrSectionSym = TextSectionSym = 0; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 300 | DwarfDebugRangeSectionSym = DwarfDebugLocSectionSym = 0; |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 301 | FunctionBeginSym = FunctionEndSym = 0; |
Devang Patel | ca76f6f | 2010-07-08 20:10:35 +0000 | [diff] [blame] | 302 | DIEIntegerOne = new (DIEValueAllocator) DIEInteger(1); |
Dan Gohman | 03c3dc7 | 2010-06-18 15:56:31 +0000 | [diff] [blame] | 303 | { |
| 304 | NamedRegionTimer T(DbgTimerName, DWARFGroupName, TimePassesIsEnabled); |
| 305 | beginModule(M); |
Torok Edwin | 9c42107 | 2010-04-07 10:44:46 +0000 | [diff] [blame] | 306 | } |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 307 | } |
| 308 | DwarfDebug::~DwarfDebug() { |
Benjamin Kramer | 345ef34 | 2010-03-31 19:34:01 +0000 | [diff] [blame] | 309 | for (unsigned j = 0, M = DIEBlocks.size(); j < M; ++j) |
| 310 | DIEBlocks[j]->~DIEBlock(); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 311 | } |
| 312 | |
Chris Lattner | bc733f5 | 2010-03-13 02:17:42 +0000 | [diff] [blame] | 313 | MCSymbol *DwarfDebug::getStringPoolEntry(StringRef Str) { |
| 314 | std::pair<MCSymbol*, unsigned> &Entry = StringPool[Str]; |
| 315 | if (Entry.first) return Entry.first; |
| 316 | |
| 317 | Entry.second = NextStringPoolNumber++; |
Chris Lattner | c021572 | 2010-04-04 19:25:43 +0000 | [diff] [blame] | 318 | return Entry.first = Asm->GetTempSymbol("string", Entry.second); |
Chris Lattner | bc733f5 | 2010-03-13 02:17:42 +0000 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 322 | /// assignAbbrevNumber - Define a unique number for the abbreviation. |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 323 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 324 | void DwarfDebug::assignAbbrevNumber(DIEAbbrev &Abbrev) { |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 325 | // Profile the node so that we can make it unique. |
| 326 | FoldingSetNodeID ID; |
| 327 | Abbrev.Profile(ID); |
| 328 | |
| 329 | // Check the set for priors. |
| 330 | DIEAbbrev *InSet = AbbreviationsSet.GetOrInsertNode(&Abbrev); |
| 331 | |
| 332 | // If it's newly added. |
| 333 | if (InSet == &Abbrev) { |
| 334 | // Add to abbreviation list. |
| 335 | Abbreviations.push_back(&Abbrev); |
| 336 | |
| 337 | // Assign the vector position + 1 as its number. |
| 338 | Abbrev.setNumber(Abbreviations.size()); |
| 339 | } else { |
| 340 | // Assign existing abbreviation number. |
| 341 | Abbrev.setNumber(InSet->getNumber()); |
| 342 | } |
| 343 | } |
| 344 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 345 | /// createDIEEntry - Creates a new DIEEntry to be a proxy for a debug |
Bill Wendling | 995f80a | 2009-05-20 23:24:48 +0000 | [diff] [blame] | 346 | /// information entry. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 347 | DIEEntry *DwarfDebug::createDIEEntry(DIE *Entry) { |
Benjamin Kramer | 345ef34 | 2010-03-31 19:34:01 +0000 | [diff] [blame] | 348 | DIEEntry *Value = new (DIEValueAllocator) DIEEntry(Entry); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 349 | return Value; |
| 350 | } |
| 351 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 352 | /// addUInt - Add an unsigned integer attribute data and value. |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 353 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 354 | void DwarfDebug::addUInt(DIE *Die, unsigned Attribute, |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 355 | unsigned Form, uint64_t Integer) { |
| 356 | if (!Form) Form = DIEInteger::BestForm(false, Integer); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 357 | DIEValue *Value = Integer == 1 ? |
Devang Patel | ca76f6f | 2010-07-08 20:10:35 +0000 | [diff] [blame] | 358 | DIEIntegerOne : new (DIEValueAllocator) DIEInteger(Integer); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 359 | Die->addValue(Attribute, Form, Value); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 360 | } |
| 361 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 362 | /// addSInt - Add an signed integer attribute data and value. |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 363 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 364 | void DwarfDebug::addSInt(DIE *Die, unsigned Attribute, |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 365 | unsigned Form, int64_t Integer) { |
| 366 | if (!Form) Form = DIEInteger::BestForm(true, Integer); |
Benjamin Kramer | 345ef34 | 2010-03-31 19:34:01 +0000 | [diff] [blame] | 367 | DIEValue *Value = new (DIEValueAllocator) DIEInteger(Integer); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 368 | Die->addValue(Attribute, Form, Value); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 369 | } |
| 370 | |
Devang Patel | 69f57b1 | 2009-12-02 15:25:16 +0000 | [diff] [blame] | 371 | /// addString - Add a string attribute data and value. DIEString only |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 372 | /// keeps string reference. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 373 | void DwarfDebug::addString(DIE *Die, unsigned Attribute, unsigned Form, |
Chris Lattner | 4cf202b | 2010-01-23 03:11:46 +0000 | [diff] [blame] | 374 | StringRef String) { |
Benjamin Kramer | 345ef34 | 2010-03-31 19:34:01 +0000 | [diff] [blame] | 375 | DIEValue *Value = new (DIEValueAllocator) DIEString(String); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 376 | Die->addValue(Attribute, Form, Value); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 377 | } |
| 378 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 379 | /// addLabel - Add a Dwarf label attribute data and value. |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 380 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 381 | void DwarfDebug::addLabel(DIE *Die, unsigned Attribute, unsigned Form, |
Chris Lattner | b98b1bf | 2010-03-08 22:23:36 +0000 | [diff] [blame] | 382 | const MCSymbol *Label) { |
Benjamin Kramer | 345ef34 | 2010-03-31 19:34:01 +0000 | [diff] [blame] | 383 | DIEValue *Value = new (DIEValueAllocator) DIELabel(Label); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 384 | Die->addValue(Attribute, Form, Value); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 385 | } |
| 386 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 387 | /// addDelta - Add a label delta attribute data and value. |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 388 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 389 | void DwarfDebug::addDelta(DIE *Die, unsigned Attribute, unsigned Form, |
Chris Lattner | b98b1bf | 2010-03-08 22:23:36 +0000 | [diff] [blame] | 390 | const MCSymbol *Hi, const MCSymbol *Lo) { |
Benjamin Kramer | 345ef34 | 2010-03-31 19:34:01 +0000 | [diff] [blame] | 391 | DIEValue *Value = new (DIEValueAllocator) DIEDelta(Hi, Lo); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 392 | Die->addValue(Attribute, Form, Value); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 393 | } |
| 394 | |
Chris Lattner | 74e41f9 | 2010-04-05 05:24:55 +0000 | [diff] [blame] | 395 | /// addDIEEntry - Add a DIE attribute data and value. |
| 396 | /// |
| 397 | void DwarfDebug::addDIEEntry(DIE *Die, unsigned Attribute, unsigned Form, |
| 398 | DIE *Entry) { |
| 399 | Die->addValue(Attribute, Form, createDIEEntry(Entry)); |
| 400 | } |
| 401 | |
| 402 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 403 | /// addBlock - Add block data. |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 404 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 405 | void DwarfDebug::addBlock(DIE *Die, unsigned Attribute, unsigned Form, |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 406 | DIEBlock *Block) { |
Chris Lattner | a37d538 | 2010-04-05 00:18:22 +0000 | [diff] [blame] | 407 | Block->ComputeSize(Asm); |
Benjamin Kramer | 345ef34 | 2010-03-31 19:34:01 +0000 | [diff] [blame] | 408 | DIEBlocks.push_back(Block); // Memoize so we can call the destructor later on. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 409 | Die->addValue(Attribute, Block->BestForm(), Block); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 410 | } |
| 411 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 412 | /// addSourceLine - Add location information to specified debug information |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 413 | /// entry. |
Devang Patel | 85e9580 | 2010-08-10 04:09:06 +0000 | [diff] [blame] | 414 | void DwarfDebug::addSourceLine(DIE *Die, DIVariable V) { |
Devang Patel | c665a51 | 2010-05-07 23:33:41 +0000 | [diff] [blame] | 415 | // Verify variable. |
Devang Patel | 8162574 | 2010-08-09 20:20:05 +0000 | [diff] [blame] | 416 | if (!V.Verify()) |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 417 | return; |
| 418 | |
Devang Patel | 8162574 | 2010-08-09 20:20:05 +0000 | [diff] [blame] | 419 | unsigned Line = V.getLineNumber(); |
Devang Patel | b2bada3 | 2010-10-08 17:18:54 +0000 | [diff] [blame] | 420 | if (Line == 0) |
| 421 | return; |
Devang Patel | 23670e5 | 2011-03-24 20:30:50 +0000 | [diff] [blame] | 422 | unsigned FileID = GetOrCreateSourceID(V.getContext().getFilename(), |
| 423 | V.getContext().getDirectory()); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 424 | assert(FileID && "Invalid file id"); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 425 | addUInt(Die, dwarf::DW_AT_decl_file, 0, FileID); |
| 426 | addUInt(Die, dwarf::DW_AT_decl_line, 0, Line); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 427 | } |
| 428 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 429 | /// addSourceLine - Add location information to specified debug information |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 430 | /// entry. |
Devang Patel | 85e9580 | 2010-08-10 04:09:06 +0000 | [diff] [blame] | 431 | void DwarfDebug::addSourceLine(DIE *Die, DIGlobalVariable G) { |
Devang Patel | c665a51 | 2010-05-07 23:33:41 +0000 | [diff] [blame] | 432 | // Verify global variable. |
Devang Patel | 8162574 | 2010-08-09 20:20:05 +0000 | [diff] [blame] | 433 | if (!G.Verify()) |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 434 | return; |
| 435 | |
Devang Patel | 8162574 | 2010-08-09 20:20:05 +0000 | [diff] [blame] | 436 | unsigned Line = G.getLineNumber(); |
Devang Patel | b2bada3 | 2010-10-08 17:18:54 +0000 | [diff] [blame] | 437 | if (Line == 0) |
| 438 | return; |
Devang Patel | 23670e5 | 2011-03-24 20:30:50 +0000 | [diff] [blame] | 439 | unsigned FileID = GetOrCreateSourceID(G.getContext().getFilename(), |
| 440 | G.getContext().getDirectory()); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 441 | assert(FileID && "Invalid file id"); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 442 | addUInt(Die, dwarf::DW_AT_decl_file, 0, FileID); |
| 443 | addUInt(Die, dwarf::DW_AT_decl_line, 0, Line); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 444 | } |
Devang Patel | 82dfc0c | 2009-08-31 22:47:13 +0000 | [diff] [blame] | 445 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 446 | /// addSourceLine - Add location information to specified debug information |
Devang Patel | 82dfc0c | 2009-08-31 22:47:13 +0000 | [diff] [blame] | 447 | /// entry. |
Devang Patel | 85e9580 | 2010-08-10 04:09:06 +0000 | [diff] [blame] | 448 | void DwarfDebug::addSourceLine(DIE *Die, DISubprogram SP) { |
Devang Patel | c665a51 | 2010-05-07 23:33:41 +0000 | [diff] [blame] | 449 | // Verify subprogram. |
Devang Patel | 8162574 | 2010-08-09 20:20:05 +0000 | [diff] [blame] | 450 | if (!SP.Verify()) |
Devang Patel | 82dfc0c | 2009-08-31 22:47:13 +0000 | [diff] [blame] | 451 | return; |
Caroline Tice | c6f9d62 | 2009-09-11 18:25:54 +0000 | [diff] [blame] | 452 | // If the line number is 0, don't add it. |
Devang Patel | 8162574 | 2010-08-09 20:20:05 +0000 | [diff] [blame] | 453 | if (SP.getLineNumber() == 0) |
Caroline Tice | c6f9d62 | 2009-09-11 18:25:54 +0000 | [diff] [blame] | 454 | return; |
| 455 | |
Devang Patel | 8162574 | 2010-08-09 20:20:05 +0000 | [diff] [blame] | 456 | unsigned Line = SP.getLineNumber(); |
| 457 | if (!SP.getContext().Verify()) |
Devang Patel | 77bf295 | 2010-03-08 22:02:50 +0000 | [diff] [blame] | 458 | return; |
Devang Patel | 23670e5 | 2011-03-24 20:30:50 +0000 | [diff] [blame] | 459 | unsigned FileID = GetOrCreateSourceID(SP.getFilename(), SP.getDirectory()); |
Devang Patel | 82dfc0c | 2009-08-31 22:47:13 +0000 | [diff] [blame] | 460 | assert(FileID && "Invalid file id"); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 461 | addUInt(Die, dwarf::DW_AT_decl_file, 0, FileID); |
| 462 | addUInt(Die, dwarf::DW_AT_decl_line, 0, Line); |
Devang Patel | 82dfc0c | 2009-08-31 22:47:13 +0000 | [diff] [blame] | 463 | } |
| 464 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 465 | /// addSourceLine - Add location information to specified debug information |
Devang Patel | 82dfc0c | 2009-08-31 22:47:13 +0000 | [diff] [blame] | 466 | /// entry. |
Devang Patel | 85e9580 | 2010-08-10 04:09:06 +0000 | [diff] [blame] | 467 | void DwarfDebug::addSourceLine(DIE *Die, DIType Ty) { |
Devang Patel | c665a51 | 2010-05-07 23:33:41 +0000 | [diff] [blame] | 468 | // Verify type. |
Devang Patel | 8162574 | 2010-08-09 20:20:05 +0000 | [diff] [blame] | 469 | if (!Ty.Verify()) |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 470 | return; |
| 471 | |
Devang Patel | 8162574 | 2010-08-09 20:20:05 +0000 | [diff] [blame] | 472 | unsigned Line = Ty.getLineNumber(); |
Devang Patel | b2bada3 | 2010-10-08 17:18:54 +0000 | [diff] [blame] | 473 | if (Line == 0 || !Ty.getContext().Verify()) |
Devang Patel | 77bf295 | 2010-03-08 22:02:50 +0000 | [diff] [blame] | 474 | return; |
Devang Patel | 23670e5 | 2011-03-24 20:30:50 +0000 | [diff] [blame] | 475 | unsigned FileID = GetOrCreateSourceID(Ty.getFilename(), Ty.getDirectory()); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 476 | assert(FileID && "Invalid file id"); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 477 | addUInt(Die, dwarf::DW_AT_decl_file, 0, FileID); |
| 478 | addUInt(Die, dwarf::DW_AT_decl_line, 0, Line); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 479 | } |
| 480 | |
Devang Patel | 6404e4e | 2009-12-15 19:16:48 +0000 | [diff] [blame] | 481 | /// addSourceLine - Add location information to specified debug information |
| 482 | /// entry. |
Devang Patel | 85e9580 | 2010-08-10 04:09:06 +0000 | [diff] [blame] | 483 | void DwarfDebug::addSourceLine(DIE *Die, DINameSpace NS) { |
Devang Patel | c665a51 | 2010-05-07 23:33:41 +0000 | [diff] [blame] | 484 | // Verify namespace. |
Devang Patel | 8162574 | 2010-08-09 20:20:05 +0000 | [diff] [blame] | 485 | if (!NS.Verify()) |
Devang Patel | 6404e4e | 2009-12-15 19:16:48 +0000 | [diff] [blame] | 486 | return; |
| 487 | |
Devang Patel | 8162574 | 2010-08-09 20:20:05 +0000 | [diff] [blame] | 488 | unsigned Line = NS.getLineNumber(); |
Devang Patel | b2bada3 | 2010-10-08 17:18:54 +0000 | [diff] [blame] | 489 | if (Line == 0) |
| 490 | return; |
Devang Patel | 8162574 | 2010-08-09 20:20:05 +0000 | [diff] [blame] | 491 | StringRef FN = NS.getFilename(); |
Devang Patel | 6404e4e | 2009-12-15 19:16:48 +0000 | [diff] [blame] | 492 | |
Devang Patel | 23670e5 | 2011-03-24 20:30:50 +0000 | [diff] [blame] | 493 | unsigned FileID = GetOrCreateSourceID(FN, NS.getDirectory()); |
Devang Patel | 6404e4e | 2009-12-15 19:16:48 +0000 | [diff] [blame] | 494 | assert(FileID && "Invalid file id"); |
| 495 | addUInt(Die, dwarf::DW_AT_decl_file, 0, FileID); |
| 496 | addUInt(Die, dwarf::DW_AT_decl_line, 0, Line); |
| 497 | } |
| 498 | |
Devang Patel | 9e3bd2c | 2010-08-31 06:11:28 +0000 | [diff] [blame] | 499 | /// addVariableAddress - Add DW_AT_location attribute for a DbgVariable based |
| 500 | /// on provided frame index. |
| 501 | void DwarfDebug::addVariableAddress(DbgVariable *&DV, DIE *Die, int64_t FI) { |
| 502 | MachineLocation Location; |
| 503 | unsigned FrameReg; |
Anton Korobeynikov | 16c29b5 | 2011-01-10 12:39:04 +0000 | [diff] [blame] | 504 | const TargetFrameLowering *TFI = Asm->TM.getFrameLowering(); |
Anton Korobeynikov | 82f5874 | 2010-11-20 15:59:32 +0000 | [diff] [blame] | 505 | int Offset = TFI->getFrameIndexReference(*Asm->MF, FI, FrameReg); |
Devang Patel | 9e3bd2c | 2010-08-31 06:11:28 +0000 | [diff] [blame] | 506 | Location.set(FrameReg, Offset); |
| 507 | |
Devang Patel | 8bd11de | 2010-08-09 21:01:39 +0000 | [diff] [blame] | 508 | if (DV->variableHasComplexAddress()) |
| 509 | addComplexAddress(DV, Die, dwarf::DW_AT_location, Location); |
| 510 | else if (DV->isBlockByrefVariable()) |
| 511 | addBlockByrefAddress(DV, Die, dwarf::DW_AT_location, Location); |
| 512 | else |
| 513 | addAddress(Die, dwarf::DW_AT_location, Location); |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 514 | } |
| 515 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 516 | /// addComplexAddress - Start with the address based on the location provided, |
Mike Stump | 3e4c9bd | 2009-09-30 00:08:22 +0000 | [diff] [blame] | 517 | /// and generate the DWARF information necessary to find the actual variable |
| 518 | /// given the extra address information encoded in the DIVariable, starting from |
| 519 | /// the starting location. Add the DWARF information to the die. |
| 520 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 521 | void DwarfDebug::addComplexAddress(DbgVariable *&DV, DIE *Die, |
Mike Stump | 3e4c9bd | 2009-09-30 00:08:22 +0000 | [diff] [blame] | 522 | unsigned Attribute, |
| 523 | const MachineLocation &Location) { |
Devang Patel | 8bd11de | 2010-08-09 21:01:39 +0000 | [diff] [blame] | 524 | DIType Ty = DV->getType(); |
Mike Stump | 3e4c9bd | 2009-09-30 00:08:22 +0000 | [diff] [blame] | 525 | |
| 526 | // Decode the original location, and use that as the start of the byref |
| 527 | // variable's location. |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 528 | const TargetRegisterInfo *RI = Asm->TM.getRegisterInfo(); |
Mike Stump | 3e4c9bd | 2009-09-30 00:08:22 +0000 | [diff] [blame] | 529 | unsigned Reg = RI->getDwarfRegNum(Location.getReg(), false); |
Benjamin Kramer | 345ef34 | 2010-03-31 19:34:01 +0000 | [diff] [blame] | 530 | DIEBlock *Block = new (DIEValueAllocator) DIEBlock(); |
Mike Stump | 3e4c9bd | 2009-09-30 00:08:22 +0000 | [diff] [blame] | 531 | |
| 532 | if (Location.isReg()) { |
| 533 | if (Reg < 32) { |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 534 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_reg0 + Reg); |
Mike Stump | 3e4c9bd | 2009-09-30 00:08:22 +0000 | [diff] [blame] | 535 | } else { |
Devang Patel | dacde94 | 2011-01-19 23:04:47 +0000 | [diff] [blame] | 536 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_regx); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 537 | addUInt(Block, 0, dwarf::DW_FORM_udata, Reg); |
Mike Stump | 3e4c9bd | 2009-09-30 00:08:22 +0000 | [diff] [blame] | 538 | } |
| 539 | } else { |
| 540 | if (Reg < 32) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 541 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_breg0 + Reg); |
Mike Stump | 3e4c9bd | 2009-09-30 00:08:22 +0000 | [diff] [blame] | 542 | else { |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 543 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_bregx); |
| 544 | addUInt(Block, 0, dwarf::DW_FORM_udata, Reg); |
Mike Stump | 3e4c9bd | 2009-09-30 00:08:22 +0000 | [diff] [blame] | 545 | } |
| 546 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 547 | addUInt(Block, 0, dwarf::DW_FORM_sdata, Location.getOffset()); |
Mike Stump | 3e4c9bd | 2009-09-30 00:08:22 +0000 | [diff] [blame] | 548 | } |
| 549 | |
Devang Patel | 8bd11de | 2010-08-09 21:01:39 +0000 | [diff] [blame] | 550 | for (unsigned i = 0, N = DV->getNumAddrElements(); i < N; ++i) { |
| 551 | uint64_t Element = DV->getAddrElement(i); |
Mike Stump | 3e4c9bd | 2009-09-30 00:08:22 +0000 | [diff] [blame] | 552 | |
Devang Patel | 0eea95d | 2011-02-24 18:49:30 +0000 | [diff] [blame] | 553 | if (Element == DIBuilder::OpPlus) { |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 554 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst); |
Devang Patel | 8bd11de | 2010-08-09 21:01:39 +0000 | [diff] [blame] | 555 | addUInt(Block, 0, dwarf::DW_FORM_udata, DV->getAddrElement(++i)); |
Devang Patel | 0eea95d | 2011-02-24 18:49:30 +0000 | [diff] [blame] | 556 | } else if (Element == DIBuilder::OpDeref) { |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 557 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_deref); |
Devang Patel | 0eea95d | 2011-02-24 18:49:30 +0000 | [diff] [blame] | 558 | } else llvm_unreachable("unknown DIBuilder Opcode"); |
Mike Stump | 3e4c9bd | 2009-09-30 00:08:22 +0000 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | // Now attach the location information to the DIE. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 562 | addBlock(Die, Attribute, 0, Block); |
Mike Stump | 3e4c9bd | 2009-09-30 00:08:22 +0000 | [diff] [blame] | 563 | } |
| 564 | |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 565 | /* Byref variables, in Blocks, are declared by the programmer as "SomeType |
| 566 | VarName;", but the compiler creates a __Block_byref_x_VarName struct, and |
| 567 | gives the variable VarName either the struct, or a pointer to the struct, as |
| 568 | its type. This is necessary for various behind-the-scenes things the |
| 569 | compiler needs to do with by-reference variables in Blocks. |
| 570 | |
| 571 | However, as far as the original *programmer* is concerned, the variable |
| 572 | should still have type 'SomeType', as originally declared. |
| 573 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 574 | The function getBlockByrefType dives into the __Block_byref_x_VarName |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 575 | struct to find the original type of the variable, which is then assigned to |
| 576 | the variable's Debug Information Entry as its real type. So far, so good. |
| 577 | However now the debugger will expect the variable VarName to have the type |
| 578 | SomeType. So we need the location attribute for the variable to be an |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 579 | expression that explains to the debugger how to navigate through the |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 580 | pointers and struct to find the actual variable of type SomeType. |
| 581 | |
| 582 | The following function does just that. We start by getting |
| 583 | the "normal" location for the variable. This will be the location |
| 584 | of either the struct __Block_byref_x_VarName or the pointer to the |
| 585 | struct __Block_byref_x_VarName. |
| 586 | |
| 587 | The struct will look something like: |
| 588 | |
| 589 | struct __Block_byref_x_VarName { |
| 590 | ... <various fields> |
| 591 | struct __Block_byref_x_VarName *forwarding; |
| 592 | ... <various other fields> |
| 593 | SomeType VarName; |
| 594 | ... <maybe more fields> |
| 595 | }; |
| 596 | |
| 597 | If we are given the struct directly (as our starting point) we |
| 598 | need to tell the debugger to: |
| 599 | |
| 600 | 1). Add the offset of the forwarding field. |
| 601 | |
Dan Gohman | f451cb8 | 2010-02-10 16:03:48 +0000 | [diff] [blame] | 602 | 2). Follow that pointer to get the real __Block_byref_x_VarName |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 603 | struct to use (the real one may have been copied onto the heap). |
| 604 | |
| 605 | 3). Add the offset for the field VarName, to find the actual variable. |
| 606 | |
| 607 | If we started with a pointer to the struct, then we need to |
| 608 | dereference that pointer first, before the other steps. |
| 609 | Translating this into DWARF ops, we will need to append the following |
| 610 | to the current location description for the variable: |
| 611 | |
| 612 | DW_OP_deref -- optional, if we start with a pointer |
| 613 | DW_OP_plus_uconst <forward_fld_offset> |
| 614 | DW_OP_deref |
| 615 | DW_OP_plus_uconst <varName_fld_offset> |
| 616 | |
| 617 | That is what this function does. */ |
| 618 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 619 | /// addBlockByrefAddress - Start with the address based on the location |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 620 | /// provided, and generate the DWARF information necessary to find the |
| 621 | /// actual Block variable (navigating the Block struct) based on the |
| 622 | /// starting location. Add the DWARF information to the die. For |
| 623 | /// more information, read large comment just above here. |
| 624 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 625 | void DwarfDebug::addBlockByrefAddress(DbgVariable *&DV, DIE *Die, |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 626 | unsigned Attribute, |
| 627 | const MachineLocation &Location) { |
Devang Patel | 8bd11de | 2010-08-09 21:01:39 +0000 | [diff] [blame] | 628 | DIType Ty = DV->getType(); |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 629 | DIType TmpTy = Ty; |
| 630 | unsigned Tag = Ty.getTag(); |
| 631 | bool isPointer = false; |
| 632 | |
Devang Patel | 8bd11de | 2010-08-09 21:01:39 +0000 | [diff] [blame] | 633 | StringRef varName = DV->getName(); |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 634 | |
| 635 | if (Tag == dwarf::DW_TAG_pointer_type) { |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 636 | DIDerivedType DTy = DIDerivedType(Ty); |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 637 | TmpTy = DTy.getTypeDerivedFrom(); |
| 638 | isPointer = true; |
| 639 | } |
| 640 | |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 641 | DICompositeType blockStruct = DICompositeType(TmpTy); |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 642 | |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 643 | // Find the __forwarding field and the variable field in the __Block_byref |
| 644 | // struct. |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 645 | DIArray Fields = blockStruct.getTypeArray(); |
| 646 | DIDescriptor varField = DIDescriptor(); |
| 647 | DIDescriptor forwardingField = DIDescriptor(); |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 648 | |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 649 | for (unsigned i = 0, N = Fields.getNumElements(); i < N; ++i) { |
| 650 | DIDescriptor Element = Fields.getElement(i); |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 651 | DIDerivedType DT = DIDerivedType(Element); |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 652 | StringRef fieldName = DT.getName(); |
| 653 | if (fieldName == "__forwarding") |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 654 | forwardingField = Element; |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 655 | else if (fieldName == varName) |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 656 | varField = Element; |
| 657 | } |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 658 | |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 659 | // Get the offsets for the forwarding field and the variable field. |
Chris Lattner | 1d65ba7 | 2010-03-31 06:06:37 +0000 | [diff] [blame] | 660 | unsigned forwardingFieldOffset = |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 661 | DIDerivedType(forwardingField).getOffsetInBits() >> 3; |
Chris Lattner | 1d65ba7 | 2010-03-31 06:06:37 +0000 | [diff] [blame] | 662 | unsigned varFieldOffset = |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 663 | DIDerivedType(varField).getOffsetInBits() >> 3; |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 664 | |
Mike Stump | 7e3720d | 2009-09-24 23:21:26 +0000 | [diff] [blame] | 665 | // Decode the original location, and use that as the start of the byref |
| 666 | // variable's location. |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 667 | const TargetRegisterInfo *RI = Asm->TM.getRegisterInfo(); |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 668 | unsigned Reg = RI->getDwarfRegNum(Location.getReg(), false); |
Benjamin Kramer | 345ef34 | 2010-03-31 19:34:01 +0000 | [diff] [blame] | 669 | DIEBlock *Block = new (DIEValueAllocator) DIEBlock(); |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 670 | |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 671 | if (Location.isReg()) { |
| 672 | if (Reg < 32) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 673 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_reg0 + Reg); |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 674 | else { |
Devang Patel | dacde94 | 2011-01-19 23:04:47 +0000 | [diff] [blame] | 675 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_regx); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 676 | addUInt(Block, 0, dwarf::DW_FORM_udata, Reg); |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 677 | } |
| 678 | } else { |
| 679 | if (Reg < 32) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 680 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_breg0 + Reg); |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 681 | else { |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 682 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_bregx); |
| 683 | addUInt(Block, 0, dwarf::DW_FORM_udata, Reg); |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 684 | } |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 685 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 686 | addUInt(Block, 0, dwarf::DW_FORM_sdata, Location.getOffset()); |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 687 | } |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 688 | |
Mike Stump | 7e3720d | 2009-09-24 23:21:26 +0000 | [diff] [blame] | 689 | // If we started with a pointer to the __Block_byref... struct, then |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 690 | // the first thing we need to do is dereference the pointer (DW_OP_deref). |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 691 | if (isPointer) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 692 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_deref); |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 693 | |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 694 | // Next add the offset for the '__forwarding' field: |
| 695 | // DW_OP_plus_uconst ForwardingFieldOffset. Note there's no point in |
| 696 | // adding the offset if it's 0. |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 697 | if (forwardingFieldOffset > 0) { |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 698 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst); |
| 699 | addUInt(Block, 0, dwarf::DW_FORM_udata, forwardingFieldOffset); |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 700 | } |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 701 | |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 702 | // Now dereference the __forwarding field to get to the real __Block_byref |
| 703 | // struct: DW_OP_deref. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 704 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_deref); |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 705 | |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 706 | // Now that we've got the real __Block_byref... struct, add the offset |
| 707 | // for the variable's field to get to the location of the actual variable: |
| 708 | // DW_OP_plus_uconst varFieldOffset. Again, don't add if it's 0. |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 709 | if (varFieldOffset > 0) { |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 710 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst); |
| 711 | addUInt(Block, 0, dwarf::DW_FORM_udata, varFieldOffset); |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 712 | } |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 713 | |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 714 | // Now attach the location information to the DIE. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 715 | addBlock(Die, Attribute, 0, Block); |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 716 | } |
| 717 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 718 | /// addAddress - Add an address attribute to a die based on the location |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 719 | /// provided. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 720 | void DwarfDebug::addAddress(DIE *Die, unsigned Attribute, |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 721 | const MachineLocation &Location) { |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 722 | const TargetRegisterInfo *RI = Asm->TM.getRegisterInfo(); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 723 | unsigned Reg = RI->getDwarfRegNum(Location.getReg(), false); |
Benjamin Kramer | 345ef34 | 2010-03-31 19:34:01 +0000 | [diff] [blame] | 724 | DIEBlock *Block = new (DIEValueAllocator) DIEBlock(); |
Devang Patel | be90c3a | 2010-09-22 21:10:38 +0000 | [diff] [blame] | 725 | |
Devang Patel | c882104 | 2010-11-02 17:37:00 +0000 | [diff] [blame] | 726 | if (RI->getFrameRegister(*Asm->MF) == Location.getReg() |
Devang Patel | be90c3a | 2010-09-22 21:10:38 +0000 | [diff] [blame] | 727 | && Location.getOffset()) { |
| 728 | // If variable offset is based in frame register then use fbreg. |
| 729 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_fbreg); |
| 730 | addSInt(Block, 0, dwarf::DW_FORM_sdata, Location.getOffset()); |
| 731 | addBlock(Die, Attribute, 0, Block); |
| 732 | return; |
| 733 | } |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 734 | |
| 735 | if (Location.isReg()) { |
| 736 | if (Reg < 32) { |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 737 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_reg0 + Reg); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 738 | } else { |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 739 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_regx); |
| 740 | addUInt(Block, 0, dwarf::DW_FORM_udata, Reg); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 741 | } |
| 742 | } else { |
| 743 | if (Reg < 32) { |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 744 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_breg0 + Reg); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 745 | } else { |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 746 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_bregx); |
| 747 | addUInt(Block, 0, dwarf::DW_FORM_udata, Reg); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 748 | } |
| 749 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 750 | addUInt(Block, 0, dwarf::DW_FORM_sdata, Location.getOffset()); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 751 | } |
| 752 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 753 | addBlock(Die, Attribute, 0, Block); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 754 | } |
| 755 | |
Devang Patel | a43098d | 2010-04-28 01:03:09 +0000 | [diff] [blame] | 756 | /// addRegisterAddress - Add register location entry in variable DIE. |
Devang Patel | 522ad74 | 2010-11-12 23:20:42 +0000 | [diff] [blame] | 757 | bool DwarfDebug::addRegisterAddress(DIE *Die, const MachineOperand &MO) { |
Devang Patel | a43098d | 2010-04-28 01:03:09 +0000 | [diff] [blame] | 758 | assert (MO.isReg() && "Invalid machine operand!"); |
| 759 | if (!MO.getReg()) |
| 760 | return false; |
| 761 | MachineLocation Location; |
| 762 | Location.set(MO.getReg()); |
| 763 | addAddress(Die, dwarf::DW_AT_location, Location); |
Devang Patel | a43098d | 2010-04-28 01:03:09 +0000 | [diff] [blame] | 764 | return true; |
| 765 | } |
| 766 | |
| 767 | /// addConstantValue - Add constant value entry in variable DIE. |
Devang Patel | 522ad74 | 2010-11-12 23:20:42 +0000 | [diff] [blame] | 768 | bool DwarfDebug::addConstantValue(DIE *Die, const MachineOperand &MO) { |
Devang Patel | a43098d | 2010-04-28 01:03:09 +0000 | [diff] [blame] | 769 | assert (MO.isImm() && "Invalid machine operand!"); |
| 770 | DIEBlock *Block = new (DIEValueAllocator) DIEBlock(); |
| 771 | unsigned Imm = MO.getImm(); |
| 772 | addUInt(Block, 0, dwarf::DW_FORM_udata, Imm); |
| 773 | addBlock(Die, dwarf::DW_AT_const_value, 0, Block); |
Devang Patel | a43098d | 2010-04-28 01:03:09 +0000 | [diff] [blame] | 774 | return true; |
| 775 | } |
| 776 | |
| 777 | /// addConstantFPValue - Add constant value entry in variable DIE. |
Devang Patel | 522ad74 | 2010-11-12 23:20:42 +0000 | [diff] [blame] | 778 | bool DwarfDebug::addConstantFPValue(DIE *Die, const MachineOperand &MO) { |
Devang Patel | a43098d | 2010-04-28 01:03:09 +0000 | [diff] [blame] | 779 | assert (MO.isFPImm() && "Invalid machine operand!"); |
| 780 | DIEBlock *Block = new (DIEValueAllocator) DIEBlock(); |
| 781 | APFloat FPImm = MO.getFPImm()->getValueAPF(); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 782 | |
Devang Patel | a43098d | 2010-04-28 01:03:09 +0000 | [diff] [blame] | 783 | // Get the raw data form of the floating point. |
| 784 | const APInt FltVal = FPImm.bitcastToAPInt(); |
| 785 | const char *FltPtr = (const char*)FltVal.getRawData(); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 786 | |
Devang Patel | a43098d | 2010-04-28 01:03:09 +0000 | [diff] [blame] | 787 | int NumBytes = FltVal.getBitWidth() / 8; // 8 bits per byte. |
| 788 | bool LittleEndian = Asm->getTargetData().isLittleEndian(); |
| 789 | int Incr = (LittleEndian ? 1 : -1); |
| 790 | int Start = (LittleEndian ? 0 : NumBytes - 1); |
| 791 | int Stop = (LittleEndian ? NumBytes : -1); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 792 | |
Devang Patel | a43098d | 2010-04-28 01:03:09 +0000 | [diff] [blame] | 793 | // Output the constant to DWARF one byte at a time. |
| 794 | for (; Start != Stop; Start += Incr) |
| 795 | addUInt(Block, 0, dwarf::DW_FORM_data1, |
| 796 | (unsigned char)0xFF & FltPtr[Start]); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 797 | |
Devang Patel | a43098d | 2010-04-28 01:03:09 +0000 | [diff] [blame] | 798 | addBlock(Die, dwarf::DW_AT_const_value, 0, Block); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 799 | return true; |
Devang Patel | a43098d | 2010-04-28 01:03:09 +0000 | [diff] [blame] | 800 | } |
| 801 | |
Devang Patel | 76a788c | 2011-01-06 21:39:25 +0000 | [diff] [blame] | 802 | /// addConstantValue - Add constant value entry in variable DIE. |
| 803 | bool DwarfDebug::addConstantValue(DIE *Die, ConstantInt *CI, |
| 804 | bool Unsigned) { |
| 805 | if (CI->getBitWidth() <= 64) { |
| 806 | if (Unsigned) |
| 807 | addUInt(Die, dwarf::DW_AT_const_value, dwarf::DW_FORM_udata, |
| 808 | CI->getZExtValue()); |
| 809 | else |
| 810 | addSInt(Die, dwarf::DW_AT_const_value, dwarf::DW_FORM_sdata, |
| 811 | CI->getSExtValue()); |
| 812 | return true; |
| 813 | } |
| 814 | |
| 815 | DIEBlock *Block = new (DIEValueAllocator) DIEBlock(); |
| 816 | |
| 817 | // Get the raw data form of the large APInt. |
| 818 | const APInt Val = CI->getValue(); |
| 819 | const char *Ptr = (const char*)Val.getRawData(); |
| 820 | |
| 821 | int NumBytes = Val.getBitWidth() / 8; // 8 bits per byte. |
| 822 | bool LittleEndian = Asm->getTargetData().isLittleEndian(); |
| 823 | int Incr = (LittleEndian ? 1 : -1); |
| 824 | int Start = (LittleEndian ? 0 : NumBytes - 1); |
| 825 | int Stop = (LittleEndian ? NumBytes : -1); |
| 826 | |
| 827 | // Output the constant to DWARF one byte at a time. |
| 828 | for (; Start != Stop; Start += Incr) |
| 829 | addUInt(Block, 0, dwarf::DW_FORM_data1, |
| 830 | (unsigned char)0xFF & Ptr[Start]); |
| 831 | |
| 832 | addBlock(Die, dwarf::DW_AT_const_value, 0, Block); |
| 833 | return true; |
| 834 | } |
Devang Patel | a43098d | 2010-04-28 01:03:09 +0000 | [diff] [blame] | 835 | |
Devang Patel | b4c2bc25 | 2011-04-05 21:08:24 +0000 | [diff] [blame] | 836 | /// addTemplateParams - Add template parameters in buffer. |
| 837 | void DwarfDebug::addTemplateParams(DIE &Buffer, DIArray TParams) { |
| 838 | // Add template parameters. |
| 839 | for (unsigned i = 0, e = TParams.getNumElements(); i != e; ++i) { |
| 840 | DIDescriptor Element = TParams.getElement(i); |
| 841 | if (Element.isTemplateTypeParameter()) |
| 842 | Buffer.addChild(getOrCreateTemplateTypeParameterDIE( |
| 843 | DITemplateTypeParameter(Element))); |
| 844 | else if (Element.isTemplateValueParameter()) |
| 845 | Buffer.addChild(getOrCreateTemplateValueParameterDIE( |
| 846 | DITemplateValueParameter(Element))); |
| 847 | } |
| 848 | |
| 849 | } |
Devang Patel | c366f83 | 2009-12-10 19:14:49 +0000 | [diff] [blame] | 850 | /// addToContextOwner - Add Die into the list of its context owner's children. |
| 851 | void DwarfDebug::addToContextOwner(DIE *Die, DIDescriptor Context) { |
Devang Patel | 3c91b05 | 2010-03-08 20:52:55 +0000 | [diff] [blame] | 852 | if (Context.isType()) { |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 853 | DIE *ContextDIE = getOrCreateTypeDIE(DIType(Context)); |
Devang Patel | c366f83 | 2009-12-10 19:14:49 +0000 | [diff] [blame] | 854 | ContextDIE->addChild(Die); |
Devang Patel | 6404e4e | 2009-12-15 19:16:48 +0000 | [diff] [blame] | 855 | } else if (Context.isNameSpace()) { |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 856 | DIE *ContextDIE = getOrCreateNameSpace(DINameSpace(Context)); |
Devang Patel | 6404e4e | 2009-12-15 19:16:48 +0000 | [diff] [blame] | 857 | ContextDIE->addChild(Die); |
Stuart Hastings | 215aa15 | 2010-06-11 20:08:44 +0000 | [diff] [blame] | 858 | } else if (Context.isSubprogram()) { |
Devang Patel | ee70fa7 | 2010-09-27 23:15:27 +0000 | [diff] [blame] | 859 | DIE *ContextDIE = createSubprogramDIE(DISubprogram(Context)); |
Stuart Hastings | 215aa15 | 2010-06-11 20:08:44 +0000 | [diff] [blame] | 860 | ContextDIE->addChild(Die); |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 861 | } else if (DIE *ContextDIE = getCompileUnit(Context)->getDIE(Context)) |
Devang Patel | c366f83 | 2009-12-10 19:14:49 +0000 | [diff] [blame] | 862 | ContextDIE->addChild(Die); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 863 | else |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 864 | getCompileUnit(Context)->addDie(Die); |
Devang Patel | c366f83 | 2009-12-10 19:14:49 +0000 | [diff] [blame] | 865 | } |
| 866 | |
Devang Patel | 16ced73 | 2009-12-10 18:05:33 +0000 | [diff] [blame] | 867 | /// getOrCreateTypeDIE - Find existing DIE or create new DIE for the |
| 868 | /// given DIType. |
| 869 | DIE *DwarfDebug::getOrCreateTypeDIE(DIType Ty) { |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 870 | CompileUnit *TypeCU = getCompileUnit(Ty); |
| 871 | DIE *TyDIE = TypeCU->getDIE(Ty); |
Devang Patel | 16ced73 | 2009-12-10 18:05:33 +0000 | [diff] [blame] | 872 | if (TyDIE) |
| 873 | return TyDIE; |
| 874 | |
| 875 | // Create new type. |
| 876 | TyDIE = new DIE(dwarf::DW_TAG_base_type); |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 877 | TypeCU->insertDIE(Ty, TyDIE); |
Devang Patel | 16ced73 | 2009-12-10 18:05:33 +0000 | [diff] [blame] | 878 | if (Ty.isBasicType()) |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 879 | constructTypeDIE(*TyDIE, DIBasicType(Ty)); |
Devang Patel | 16ced73 | 2009-12-10 18:05:33 +0000 | [diff] [blame] | 880 | else if (Ty.isCompositeType()) |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 881 | constructTypeDIE(*TyDIE, DICompositeType(Ty)); |
Devang Patel | 16ced73 | 2009-12-10 18:05:33 +0000 | [diff] [blame] | 882 | else { |
| 883 | assert(Ty.isDerivedType() && "Unknown kind of DIType"); |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 884 | constructTypeDIE(*TyDIE, DIDerivedType(Ty)); |
Devang Patel | 16ced73 | 2009-12-10 18:05:33 +0000 | [diff] [blame] | 885 | } |
| 886 | |
Devang Patel | c366f83 | 2009-12-10 19:14:49 +0000 | [diff] [blame] | 887 | addToContextOwner(TyDIE, Ty.getContext()); |
Devang Patel | 16ced73 | 2009-12-10 18:05:33 +0000 | [diff] [blame] | 888 | return TyDIE; |
| 889 | } |
| 890 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 891 | /// addType - Add a new type attribute to the specified entity. |
Devang Patel | 8a24114 | 2009-12-09 18:24:21 +0000 | [diff] [blame] | 892 | void DwarfDebug::addType(DIE *Entity, DIType Ty) { |
Devang Patel | 9c00487 | 2010-05-07 21:45:47 +0000 | [diff] [blame] | 893 | if (!Ty.Verify()) |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 894 | return; |
| 895 | |
| 896 | // Check for pre-existence. |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 897 | CompileUnit *TypeCU = getCompileUnit(Ty); |
| 898 | DIEEntry *Entry = TypeCU->getDIEEntry(Ty); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 899 | // If it exists then use the existing value. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 900 | if (Entry) { |
| 901 | Entity->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, Entry); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 902 | return; |
| 903 | } |
| 904 | |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 905 | // Construct type. |
Devang Patel | 16ced73 | 2009-12-10 18:05:33 +0000 | [diff] [blame] | 906 | DIE *Buffer = getOrCreateTypeDIE(Ty); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 907 | |
Jeffrey Yasskin | 5c213dc | 2010-03-12 17:45:06 +0000 | [diff] [blame] | 908 | // Set up proxy. |
| 909 | Entry = createDIEEntry(Buffer); |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 910 | TypeCU->insertDIEEntry(Ty, Entry); |
Jeffrey Yasskin | 5c213dc | 2010-03-12 17:45:06 +0000 | [diff] [blame] | 911 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 912 | Entity->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, Entry); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 913 | } |
| 914 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 915 | /// constructTypeDIE - Construct basic type die from DIBasicType. |
Devang Patel | 8a24114 | 2009-12-09 18:24:21 +0000 | [diff] [blame] | 916 | void DwarfDebug::constructTypeDIE(DIE &Buffer, DIBasicType BTy) { |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 917 | // Get core information. |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 918 | StringRef Name = BTy.getName(); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 919 | Buffer.setTag(dwarf::DW_TAG_base_type); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 920 | addUInt(&Buffer, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 921 | BTy.getEncoding()); |
| 922 | |
| 923 | // Add name if not anonymous or intermediate type. |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 924 | if (!Name.empty()) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 925 | addString(&Buffer, dwarf::DW_AT_name, dwarf::DW_FORM_string, Name); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 926 | uint64_t Size = BTy.getSizeInBits() >> 3; |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 927 | addUInt(&Buffer, dwarf::DW_AT_byte_size, 0, Size); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 928 | } |
| 929 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 930 | /// constructTypeDIE - Construct derived type die from DIDerivedType. |
Devang Patel | 8a24114 | 2009-12-09 18:24:21 +0000 | [diff] [blame] | 931 | void DwarfDebug::constructTypeDIE(DIE &Buffer, DIDerivedType DTy) { |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 932 | // Get core information. |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 933 | StringRef Name = DTy.getName(); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 934 | uint64_t Size = DTy.getSizeInBits() >> 3; |
| 935 | unsigned Tag = DTy.getTag(); |
| 936 | |
| 937 | // FIXME - Workaround for templates. |
| 938 | if (Tag == dwarf::DW_TAG_inheritance) Tag = dwarf::DW_TAG_reference_type; |
| 939 | |
| 940 | Buffer.setTag(Tag); |
| 941 | |
| 942 | // Map to main type, void will not have a type. |
| 943 | DIType FromTy = DTy.getTypeDerivedFrom(); |
Devang Patel | 8a24114 | 2009-12-09 18:24:21 +0000 | [diff] [blame] | 944 | addType(&Buffer, FromTy); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 945 | |
| 946 | // Add name if not anonymous or intermediate type. |
Devang Patel | deea564 | 2009-11-30 23:56:56 +0000 | [diff] [blame] | 947 | if (!Name.empty()) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 948 | addString(&Buffer, dwarf::DW_AT_name, dwarf::DW_FORM_string, Name); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 949 | |
| 950 | // Add size if non-zero (derived types might be zero-sized.) |
| 951 | if (Size) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 952 | addUInt(&Buffer, dwarf::DW_AT_byte_size, 0, Size); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 953 | |
| 954 | // Add source line info if available and TyDesc is not a forward declaration. |
Devang Patel | 05f6fa8 | 2009-11-23 18:43:37 +0000 | [diff] [blame] | 955 | if (!DTy.isForwardDecl()) |
Devang Patel | 8162574 | 2010-08-09 20:20:05 +0000 | [diff] [blame] | 956 | addSourceLine(&Buffer, DTy); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 957 | } |
| 958 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 959 | /// constructTypeDIE - Construct type DIE from DICompositeType. |
Devang Patel | 8a24114 | 2009-12-09 18:24:21 +0000 | [diff] [blame] | 960 | void DwarfDebug::constructTypeDIE(DIE &Buffer, DICompositeType CTy) { |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 961 | // Get core information. |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 962 | StringRef Name = CTy.getName(); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 963 | |
| 964 | uint64_t Size = CTy.getSizeInBits() >> 3; |
| 965 | unsigned Tag = CTy.getTag(); |
| 966 | Buffer.setTag(Tag); |
| 967 | |
| 968 | switch (Tag) { |
| 969 | case dwarf::DW_TAG_vector_type: |
| 970 | case dwarf::DW_TAG_array_type: |
Devang Patel | 8a24114 | 2009-12-09 18:24:21 +0000 | [diff] [blame] | 971 | constructArrayTypeDIE(Buffer, &CTy); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 972 | break; |
| 973 | case dwarf::DW_TAG_enumeration_type: { |
| 974 | DIArray Elements = CTy.getTypeArray(); |
| 975 | |
| 976 | // Add enumerators to enumeration type. |
| 977 | for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) { |
| 978 | DIE *ElemDie = NULL; |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 979 | DIDescriptor Enum(Elements.getElement(i)); |
Devang Patel | 3c91b05 | 2010-03-08 20:52:55 +0000 | [diff] [blame] | 980 | if (Enum.isEnumerator()) { |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 981 | ElemDie = constructEnumTypeDIE(DIEnumerator(Enum)); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 982 | Buffer.addChild(ElemDie); |
Devang Patel | c525472 | 2009-10-09 17:51:49 +0000 | [diff] [blame] | 983 | } |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 984 | } |
| 985 | } |
| 986 | break; |
| 987 | case dwarf::DW_TAG_subroutine_type: { |
| 988 | // Add return type. |
| 989 | DIArray Elements = CTy.getTypeArray(); |
| 990 | DIDescriptor RTy = Elements.getElement(0); |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 991 | addType(&Buffer, DIType(RTy)); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 992 | |
Devang Patel | d6747df | 2010-10-06 20:50:40 +0000 | [diff] [blame] | 993 | bool isPrototyped = true; |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 994 | // Add arguments. |
| 995 | for (unsigned i = 1, N = Elements.getNumElements(); i < N; ++i) { |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 996 | DIDescriptor Ty = Elements.getElement(i); |
Devang Patel | d6747df | 2010-10-06 20:50:40 +0000 | [diff] [blame] | 997 | if (Ty.isUnspecifiedParameter()) { |
| 998 | DIE *Arg = new DIE(dwarf::DW_TAG_unspecified_parameters); |
| 999 | Buffer.addChild(Arg); |
| 1000 | isPrototyped = false; |
| 1001 | } else { |
| 1002 | DIE *Arg = new DIE(dwarf::DW_TAG_formal_parameter); |
| 1003 | addType(Arg, DIType(Ty)); |
| 1004 | Buffer.addChild(Arg); |
| 1005 | } |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1006 | } |
Devang Patel | d6747df | 2010-10-06 20:50:40 +0000 | [diff] [blame] | 1007 | // Add prototype flag. |
| 1008 | if (isPrototyped) |
| 1009 | addUInt(&Buffer, dwarf::DW_AT_prototyped, dwarf::DW_FORM_flag, 1); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1010 | } |
| 1011 | break; |
| 1012 | case dwarf::DW_TAG_structure_type: |
| 1013 | case dwarf::DW_TAG_union_type: |
| 1014 | case dwarf::DW_TAG_class_type: { |
| 1015 | // Add elements to structure type. |
| 1016 | DIArray Elements = CTy.getTypeArray(); |
| 1017 | |
| 1018 | // A forward struct declared type may not have elements available. |
Devang Patel | 3c91b05 | 2010-03-08 20:52:55 +0000 | [diff] [blame] | 1019 | unsigned N = Elements.getNumElements(); |
| 1020 | if (N == 0) |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1021 | break; |
| 1022 | |
| 1023 | // Add elements to structure type. |
Devang Patel | 3c91b05 | 2010-03-08 20:52:55 +0000 | [diff] [blame] | 1024 | for (unsigned i = 0; i < N; ++i) { |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1025 | DIDescriptor Element = Elements.getElement(i); |
| 1026 | DIE *ElemDie = NULL; |
Devang Patel | 1a30123 | 2010-09-29 21:44:16 +0000 | [diff] [blame] | 1027 | if (Element.isSubprogram()) { |
| 1028 | DISubprogram SP(Element); |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 1029 | ElemDie = createSubprogramDIE(DISubprogram(Element)); |
Devang Patel | 1a30123 | 2010-09-29 21:44:16 +0000 | [diff] [blame] | 1030 | if (SP.isProtected()) |
| 1031 | addUInt(ElemDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_flag, |
| 1032 | dwarf::DW_ACCESS_protected); |
| 1033 | else if (SP.isPrivate()) |
| 1034 | addUInt(ElemDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_flag, |
| 1035 | dwarf::DW_ACCESS_private); |
| 1036 | else |
| 1037 | addUInt(ElemDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_flag, |
| 1038 | dwarf::DW_ACCESS_public); |
Devang Patel | 21ea1d5 | 2010-10-01 23:31:40 +0000 | [diff] [blame] | 1039 | if (SP.isExplicit()) |
| 1040 | addUInt(ElemDie, dwarf::DW_AT_explicit, dwarf::DW_FORM_flag, 1); |
Devang Patel | 1a30123 | 2010-09-29 21:44:16 +0000 | [diff] [blame] | 1041 | } |
Devang Patel | 3c91b05 | 2010-03-08 20:52:55 +0000 | [diff] [blame] | 1042 | else if (Element.isVariable()) { |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 1043 | DIVariable DV(Element); |
Devang Patel | 1ee0cb9 | 2010-01-30 01:08:30 +0000 | [diff] [blame] | 1044 | ElemDie = new DIE(dwarf::DW_TAG_variable); |
| 1045 | addString(ElemDie, dwarf::DW_AT_name, dwarf::DW_FORM_string, |
| 1046 | DV.getName()); |
| 1047 | addType(ElemDie, DV.getType()); |
| 1048 | addUInt(ElemDie, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag, 1); |
| 1049 | addUInt(ElemDie, dwarf::DW_AT_external, dwarf::DW_FORM_flag, 1); |
Devang Patel | 8162574 | 2010-08-09 20:20:05 +0000 | [diff] [blame] | 1050 | addSourceLine(ElemDie, DV); |
Devang Patel | 3c91b05 | 2010-03-08 20:52:55 +0000 | [diff] [blame] | 1051 | } else if (Element.isDerivedType()) |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 1052 | ElemDie = createMemberDIE(DIDerivedType(Element)); |
Devang Patel | 3c91b05 | 2010-03-08 20:52:55 +0000 | [diff] [blame] | 1053 | else |
| 1054 | continue; |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1055 | Buffer.addChild(ElemDie); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1056 | } |
| 1057 | |
Devang Patel | a1ba269 | 2009-08-27 23:51:51 +0000 | [diff] [blame] | 1058 | if (CTy.isAppleBlockExtension()) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1059 | addUInt(&Buffer, dwarf::DW_AT_APPLE_block, dwarf::DW_FORM_flag, 1); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1060 | |
| 1061 | unsigned RLang = CTy.getRunTimeLang(); |
| 1062 | if (RLang) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1063 | addUInt(&Buffer, dwarf::DW_AT_APPLE_runtime_class, |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1064 | dwarf::DW_FORM_data1, RLang); |
Devang Patel | b554499 | 2010-01-26 21:16:06 +0000 | [diff] [blame] | 1065 | |
| 1066 | DICompositeType ContainingType = CTy.getContainingType(); |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 1067 | if (DIDescriptor(ContainingType).isCompositeType()) |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1068 | addDIEEntry(&Buffer, dwarf::DW_AT_containing_type, dwarf::DW_FORM_ref4, |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 1069 | getOrCreateTypeDIE(DIType(ContainingType))); |
Stuart Hastings | 215aa15 | 2010-06-11 20:08:44 +0000 | [diff] [blame] | 1070 | else { |
| 1071 | DIDescriptor Context = CTy.getContext(); |
| 1072 | addToContextOwner(&Buffer, Context); |
| 1073 | } |
Devang Patel | 7e2cb11 | 2011-02-02 21:38:25 +0000 | [diff] [blame] | 1074 | |
Devang Patel | b4c2bc25 | 2011-04-05 21:08:24 +0000 | [diff] [blame] | 1075 | if (Tag == dwarf::DW_TAG_class_type) |
| 1076 | addTemplateParams(Buffer, CTy.getTemplateParams()); |
| 1077 | |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1078 | break; |
| 1079 | } |
| 1080 | default: |
| 1081 | break; |
| 1082 | } |
| 1083 | |
| 1084 | // Add name if not anonymous or intermediate type. |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 1085 | if (!Name.empty()) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1086 | addString(&Buffer, dwarf::DW_AT_name, dwarf::DW_FORM_string, Name); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1087 | |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1088 | if (Tag == dwarf::DW_TAG_enumeration_type || Tag == dwarf::DW_TAG_class_type |
Devang Patel | 6140962 | 2010-07-07 20:12:52 +0000 | [diff] [blame] | 1089 | || Tag == dwarf::DW_TAG_structure_type || Tag == dwarf::DW_TAG_union_type) |
| 1090 | { |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1091 | // Add size if non-zero (derived types might be zero-sized.) |
| 1092 | if (Size) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1093 | addUInt(&Buffer, dwarf::DW_AT_byte_size, 0, Size); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1094 | else { |
| 1095 | // Add zero size if it is not a forward declaration. |
| 1096 | if (CTy.isForwardDecl()) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1097 | addUInt(&Buffer, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag, 1); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1098 | else |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1099 | addUInt(&Buffer, dwarf::DW_AT_byte_size, 0, 0); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1100 | } |
| 1101 | |
| 1102 | // Add source line info if available. |
| 1103 | if (!CTy.isForwardDecl()) |
Devang Patel | 8162574 | 2010-08-09 20:20:05 +0000 | [diff] [blame] | 1104 | addSourceLine(&Buffer, CTy); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1105 | } |
| 1106 | } |
| 1107 | |
Devang Patel | 7e2cb11 | 2011-02-02 21:38:25 +0000 | [diff] [blame] | 1108 | /// getOrCreateTemplateTypeParameterDIE - Find existing DIE or create new DIE |
| 1109 | /// for the given DITemplateTypeParameter. |
| 1110 | DIE * |
| 1111 | DwarfDebug::getOrCreateTemplateTypeParameterDIE(DITemplateTypeParameter TP) { |
| 1112 | CompileUnit *TypeCU = getCompileUnit(TP); |
| 1113 | DIE *ParamDIE = TypeCU->getDIE(TP); |
| 1114 | if (ParamDIE) |
| 1115 | return ParamDIE; |
| 1116 | |
| 1117 | ParamDIE = new DIE(dwarf::DW_TAG_template_type_parameter); |
| 1118 | addType(ParamDIE, TP.getType()); |
| 1119 | addString(ParamDIE, dwarf::DW_AT_name, dwarf::DW_FORM_string, TP.getName()); |
| 1120 | return ParamDIE; |
| 1121 | } |
| 1122 | |
Devang Patel | e7d9387 | 2011-02-02 22:35:53 +0000 | [diff] [blame] | 1123 | /// getOrCreateTemplateValueParameterDIE - Find existing DIE or create new DIE |
| 1124 | /// for the given DITemplateValueParameter. |
| 1125 | DIE * |
| 1126 | DwarfDebug::getOrCreateTemplateValueParameterDIE(DITemplateValueParameter TPV) { |
| 1127 | CompileUnit *TVCU = getCompileUnit(TPV); |
| 1128 | DIE *ParamDIE = TVCU->getDIE(TPV); |
| 1129 | if (ParamDIE) |
| 1130 | return ParamDIE; |
| 1131 | |
| 1132 | ParamDIE = new DIE(dwarf::DW_TAG_template_value_parameter); |
| 1133 | addType(ParamDIE, TPV.getType()); |
Devang Patel | e050f50 | 2011-04-05 20:14:13 +0000 | [diff] [blame] | 1134 | if (!TPV.getName().empty()) |
| 1135 | addString(ParamDIE, dwarf::DW_AT_name, dwarf::DW_FORM_string, TPV.getName()); |
Devang Patel | e7d9387 | 2011-02-02 22:35:53 +0000 | [diff] [blame] | 1136 | addUInt(ParamDIE, dwarf::DW_AT_const_value, dwarf::DW_FORM_udata, |
| 1137 | TPV.getValue()); |
| 1138 | return ParamDIE; |
| 1139 | } |
| 1140 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1141 | /// constructSubrangeDIE - Construct subrange DIE from DISubrange. |
| 1142 | void DwarfDebug::constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy){ |
Devang Patel | fb6e8d6 | 2011-04-08 21:55:10 +0000 | [diff] [blame] | 1143 | DIE *DW_Subrange = new DIE(dwarf::DW_TAG_subrange_type); |
| 1144 | addDIEEntry(DW_Subrange, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, IndexTy); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1145 | int64_t L = SR.getLo(); |
| 1146 | int64_t H = SR.getHi(); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1147 | |
Devang Patel | 3f932a7 | 2011-04-08 23:39:38 +0000 | [diff] [blame] | 1148 | // The L value defines the lower bounds which is typically zero for C/C++. The |
| 1149 | // H value is the upper bounds. Values are 64 bit. H - L + 1 is the size |
| 1150 | // of the array. If L > H then do not emit DW_AT_lower_bound and |
| 1151 | // DW_AT_upper_bound attributes. If L is zero and H is also zero then the |
| 1152 | // array has one element and in such case do not emit lower bound. |
Devang Patel | fb6e8d6 | 2011-04-08 21:55:10 +0000 | [diff] [blame] | 1153 | |
Devang Patel | 3f932a7 | 2011-04-08 23:39:38 +0000 | [diff] [blame] | 1154 | if (L > H) { |
Devang Patel | fb6e8d6 | 2011-04-08 21:55:10 +0000 | [diff] [blame] | 1155 | Buffer.addChild(DW_Subrange); |
| 1156 | return; |
| 1157 | } |
Devang Patel | 6325a53 | 2009-08-14 20:59:16 +0000 | [diff] [blame] | 1158 | if (L) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1159 | addSInt(DW_Subrange, dwarf::DW_AT_lower_bound, 0, L); |
Devang Patel | d55224c | 2009-12-04 23:10:24 +0000 | [diff] [blame] | 1160 | addSInt(DW_Subrange, dwarf::DW_AT_upper_bound, 0, H); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1161 | Buffer.addChild(DW_Subrange); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1162 | } |
| 1163 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1164 | /// constructArrayTypeDIE - Construct array type DIE from DICompositeType. |
Devang Patel | 8a24114 | 2009-12-09 18:24:21 +0000 | [diff] [blame] | 1165 | void DwarfDebug::constructArrayTypeDIE(DIE &Buffer, |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1166 | DICompositeType *CTy) { |
| 1167 | Buffer.setTag(dwarf::DW_TAG_array_type); |
| 1168 | if (CTy->getTag() == dwarf::DW_TAG_vector_type) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1169 | addUInt(&Buffer, dwarf::DW_AT_GNU_vector, dwarf::DW_FORM_flag, 1); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1170 | |
| 1171 | // Emit derived type. |
Devang Patel | 8a24114 | 2009-12-09 18:24:21 +0000 | [diff] [blame] | 1172 | addType(&Buffer, CTy->getTypeDerivedFrom()); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1173 | DIArray Elements = CTy->getTypeArray(); |
| 1174 | |
Devang Patel | 6f01d9c | 2009-11-21 00:31:03 +0000 | [diff] [blame] | 1175 | // Get an anonymous type for index type. |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1176 | CompileUnit *TheCU = getCompileUnit(*CTy); |
| 1177 | DIE *IdxTy = TheCU->getIndexTyDie(); |
Devang Patel | 6f01d9c | 2009-11-21 00:31:03 +0000 | [diff] [blame] | 1178 | if (!IdxTy) { |
| 1179 | // Construct an anonymous type for index type. |
| 1180 | IdxTy = new DIE(dwarf::DW_TAG_base_type); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1181 | addUInt(IdxTy, dwarf::DW_AT_byte_size, 0, sizeof(int32_t)); |
| 1182 | addUInt(IdxTy, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, |
Devang Patel | 6f01d9c | 2009-11-21 00:31:03 +0000 | [diff] [blame] | 1183 | dwarf::DW_ATE_signed); |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1184 | TheCU->addDie(IdxTy); |
| 1185 | TheCU->setIndexTyDie(IdxTy); |
Devang Patel | 6f01d9c | 2009-11-21 00:31:03 +0000 | [diff] [blame] | 1186 | } |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1187 | |
| 1188 | // Add subranges to array type. |
| 1189 | for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) { |
| 1190 | DIDescriptor Element = Elements.getElement(i); |
| 1191 | if (Element.getTag() == dwarf::DW_TAG_subrange_type) |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 1192 | constructSubrangeDIE(Buffer, DISubrange(Element), IdxTy); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1193 | } |
| 1194 | } |
| 1195 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1196 | /// constructEnumTypeDIE - Construct enum type DIE from DIEnumerator. |
Devang Patel | 3c91b05 | 2010-03-08 20:52:55 +0000 | [diff] [blame] | 1197 | DIE *DwarfDebug::constructEnumTypeDIE(DIEnumerator ETy) { |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1198 | DIE *Enumerator = new DIE(dwarf::DW_TAG_enumerator); |
Devang Patel | 3c91b05 | 2010-03-08 20:52:55 +0000 | [diff] [blame] | 1199 | StringRef Name = ETy.getName(); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1200 | addString(Enumerator, dwarf::DW_AT_name, dwarf::DW_FORM_string, Name); |
Devang Patel | 3c91b05 | 2010-03-08 20:52:55 +0000 | [diff] [blame] | 1201 | int64_t Value = ETy.getEnumValue(); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1202 | addSInt(Enumerator, dwarf::DW_AT_const_value, dwarf::DW_FORM_sdata, Value); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1203 | return Enumerator; |
| 1204 | } |
| 1205 | |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1206 | /// getRealLinkageName - If special LLVM prefix that is used to inform the asm |
Devang Patel | 351ca33 | 2010-01-05 01:46:14 +0000 | [diff] [blame] | 1207 | /// printer to not emit usual symbol prefix before the symbol name is used then |
| 1208 | /// return linkage name after skipping this special LLVM prefix. |
| 1209 | static StringRef getRealLinkageName(StringRef LinkageName) { |
| 1210 | char One = '\1'; |
| 1211 | if (LinkageName.startswith(StringRef(&One, 1))) |
| 1212 | return LinkageName.substr(1); |
| 1213 | return LinkageName; |
| 1214 | } |
| 1215 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1216 | /// createMemberDIE - Create new member DIE. |
Devang Patel | ecbd8e8 | 2010-08-10 04:12:17 +0000 | [diff] [blame] | 1217 | DIE *DwarfDebug::createMemberDIE(DIDerivedType DT) { |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1218 | DIE *MemberDie = new DIE(DT.getTag()); |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 1219 | StringRef Name = DT.getName(); |
| 1220 | if (!Name.empty()) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1221 | addString(MemberDie, dwarf::DW_AT_name, dwarf::DW_FORM_string, Name); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1222 | |
Devang Patel | 8a24114 | 2009-12-09 18:24:21 +0000 | [diff] [blame] | 1223 | addType(MemberDie, DT.getTypeDerivedFrom()); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1224 | |
Devang Patel | 8162574 | 2010-08-09 20:20:05 +0000 | [diff] [blame] | 1225 | addSourceLine(MemberDie, DT); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1226 | |
Benjamin Kramer | 345ef34 | 2010-03-31 19:34:01 +0000 | [diff] [blame] | 1227 | DIEBlock *MemLocationDie = new (DIEValueAllocator) DIEBlock(); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1228 | addUInt(MemLocationDie, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst); |
Devang Patel | 33db508 | 2009-11-04 22:06:12 +0000 | [diff] [blame] | 1229 | |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1230 | uint64_t Size = DT.getSizeInBits(); |
Devang Patel | 61ecbd1 | 2009-11-04 23:48:00 +0000 | [diff] [blame] | 1231 | uint64_t FieldSize = DT.getOriginalTypeSize(); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1232 | |
| 1233 | if (Size != FieldSize) { |
| 1234 | // Handle bitfield. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1235 | addUInt(MemberDie, dwarf::DW_AT_byte_size, 0, DT.getOriginalTypeSize()>>3); |
| 1236 | addUInt(MemberDie, dwarf::DW_AT_bit_size, 0, DT.getSizeInBits()); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1237 | |
| 1238 | uint64_t Offset = DT.getOffsetInBits(); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1239 | uint64_t AlignMask = ~(DT.getAlignInBits() - 1); |
| 1240 | uint64_t HiMark = (Offset + FieldSize) & AlignMask; |
Benjamin Kramer | 3d594fd | 2010-01-07 17:50:57 +0000 | [diff] [blame] | 1241 | uint64_t FieldOffset = (HiMark - FieldSize); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1242 | Offset -= FieldOffset; |
| 1243 | |
| 1244 | // Maybe we need to work from the other end. |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 1245 | if (Asm->getTargetData().isLittleEndian()) |
| 1246 | Offset = FieldSize - (Offset + Size); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1247 | addUInt(MemberDie, dwarf::DW_AT_bit_offset, 0, Offset); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1248 | |
Devang Patel | 33db508 | 2009-11-04 22:06:12 +0000 | [diff] [blame] | 1249 | // Here WD_AT_data_member_location points to the anonymous |
| 1250 | // field that includes this bit field. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1251 | addUInt(MemLocationDie, 0, dwarf::DW_FORM_udata, FieldOffset >> 3); |
Devang Patel | 33db508 | 2009-11-04 22:06:12 +0000 | [diff] [blame] | 1252 | |
| 1253 | } else |
| 1254 | // This is not a bitfield. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1255 | addUInt(MemLocationDie, 0, dwarf::DW_FORM_udata, DT.getOffsetInBits() >> 3); |
Devang Patel | 33db508 | 2009-11-04 22:06:12 +0000 | [diff] [blame] | 1256 | |
Devang Patel | c1dc8ff | 2010-02-03 20:08:48 +0000 | [diff] [blame] | 1257 | if (DT.getTag() == dwarf::DW_TAG_inheritance |
| 1258 | && DT.isVirtual()) { |
| 1259 | |
| 1260 | // For C++, virtual base classes are not at fixed offset. Use following |
| 1261 | // expression to extract appropriate offset from vtable. |
| 1262 | // BaseAddr = ObAddr + *((*ObAddr) - Offset) |
| 1263 | |
Benjamin Kramer | 345ef34 | 2010-03-31 19:34:01 +0000 | [diff] [blame] | 1264 | DIEBlock *VBaseLocationDie = new (DIEValueAllocator) DIEBlock(); |
Devang Patel | c1dc8ff | 2010-02-03 20:08:48 +0000 | [diff] [blame] | 1265 | addUInt(VBaseLocationDie, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_dup); |
| 1266 | addUInt(VBaseLocationDie, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_deref); |
| 1267 | addUInt(VBaseLocationDie, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_constu); |
| 1268 | addUInt(VBaseLocationDie, 0, dwarf::DW_FORM_udata, DT.getOffsetInBits()); |
| 1269 | addUInt(VBaseLocationDie, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_minus); |
| 1270 | addUInt(VBaseLocationDie, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_deref); |
| 1271 | addUInt(VBaseLocationDie, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_plus); |
| 1272 | |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1273 | addBlock(MemberDie, dwarf::DW_AT_data_member_location, 0, |
Devang Patel | c1dc8ff | 2010-02-03 20:08:48 +0000 | [diff] [blame] | 1274 | VBaseLocationDie); |
| 1275 | } else |
| 1276 | addBlock(MemberDie, dwarf::DW_AT_data_member_location, 0, MemLocationDie); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1277 | |
| 1278 | if (DT.isProtected()) |
Devang Patel | 5d11eb0 | 2009-12-03 19:11:07 +0000 | [diff] [blame] | 1279 | addUInt(MemberDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_flag, |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1280 | dwarf::DW_ACCESS_protected); |
| 1281 | else if (DT.isPrivate()) |
Devang Patel | 5d11eb0 | 2009-12-03 19:11:07 +0000 | [diff] [blame] | 1282 | addUInt(MemberDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_flag, |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1283 | dwarf::DW_ACCESS_private); |
Devang Patel | 2a36160 | 2010-09-29 19:08:08 +0000 | [diff] [blame] | 1284 | // Otherwise C++ member and base classes are considered public. |
| 1285 | else if (DT.getCompileUnit().getLanguage() == dwarf::DW_LANG_C_plus_plus) |
Devang Patel | 5d11eb0 | 2009-12-03 19:11:07 +0000 | [diff] [blame] | 1286 | addUInt(MemberDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_flag, |
| 1287 | dwarf::DW_ACCESS_public); |
| 1288 | if (DT.isVirtual()) |
| 1289 | addUInt(MemberDie, dwarf::DW_AT_virtuality, dwarf::DW_FORM_flag, |
| 1290 | dwarf::DW_VIRTUALITY_virtual); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1291 | return MemberDie; |
| 1292 | } |
| 1293 | |
Devang Patel | ffe966c | 2009-12-14 16:18:45 +0000 | [diff] [blame] | 1294 | /// createSubprogramDIE - Create new DIE using SP. |
Devang Patel | ee70fa7 | 2010-09-27 23:15:27 +0000 | [diff] [blame] | 1295 | DIE *DwarfDebug::createSubprogramDIE(DISubprogram SP) { |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1296 | CompileUnit *SPCU = getCompileUnit(SP); |
| 1297 | DIE *SPDie = SPCU->getDIE(SP); |
Devang Patel | ffe966c | 2009-12-14 16:18:45 +0000 | [diff] [blame] | 1298 | if (SPDie) |
| 1299 | return SPDie; |
| 1300 | |
| 1301 | SPDie = new DIE(dwarf::DW_TAG_subprogram); |
Devang Patel | 1eac3e7 | 2010-03-02 17:58:15 +0000 | [diff] [blame] | 1302 | // Constructors and operators for anonymous aggregates do not have names. |
Devang Patel | 6b506cb | 2010-03-02 01:26:20 +0000 | [diff] [blame] | 1303 | if (!SP.getName().empty()) |
| 1304 | addString(SPDie, dwarf::DW_AT_name, dwarf::DW_FORM_string, SP.getName()); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1305 | |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 1306 | StringRef LinkageName = SP.getLinkageName(); |
Devang Patel | 351ca33 | 2010-01-05 01:46:14 +0000 | [diff] [blame] | 1307 | if (!LinkageName.empty()) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1308 | addString(SPDie, dwarf::DW_AT_MIPS_linkage_name, dwarf::DW_FORM_string, |
Devang Patel | 351ca33 | 2010-01-05 01:46:14 +0000 | [diff] [blame] | 1309 | getRealLinkageName(LinkageName)); |
| 1310 | |
Devang Patel | 8162574 | 2010-08-09 20:20:05 +0000 | [diff] [blame] | 1311 | addSourceLine(SPDie, SP); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1312 | |
Devang Patel | 7b172c6 | 2010-10-07 22:03:01 +0000 | [diff] [blame] | 1313 | if (SP.isPrototyped()) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1314 | addUInt(SPDie, dwarf::DW_AT_prototyped, dwarf::DW_FORM_flag, 1); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1315 | |
| 1316 | // Add Return Type. |
Devang Patel | 1d5cc1d | 2009-12-03 01:25:38 +0000 | [diff] [blame] | 1317 | DICompositeType SPTy = SP.getType(); |
| 1318 | DIArray Args = SPTy.getTypeArray(); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1319 | unsigned SPTag = SPTy.getTag(); |
Devang Patel | 5d11eb0 | 2009-12-03 19:11:07 +0000 | [diff] [blame] | 1320 | |
Devang Patel | 3c91b05 | 2010-03-08 20:52:55 +0000 | [diff] [blame] | 1321 | if (Args.getNumElements() == 0 || SPTag != dwarf::DW_TAG_subroutine_type) |
Devang Patel | 8a24114 | 2009-12-09 18:24:21 +0000 | [diff] [blame] | 1322 | addType(SPDie, SPTy); |
Devang Patel | 1d5cc1d | 2009-12-03 01:25:38 +0000 | [diff] [blame] | 1323 | else |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 1324 | addType(SPDie, DIType(Args.getElement(0))); |
Devang Patel | 1d5cc1d | 2009-12-03 01:25:38 +0000 | [diff] [blame] | 1325 | |
Devang Patel | 5d11eb0 | 2009-12-03 19:11:07 +0000 | [diff] [blame] | 1326 | unsigned VK = SP.getVirtuality(); |
| 1327 | if (VK) { |
| 1328 | addUInt(SPDie, dwarf::DW_AT_virtuality, dwarf::DW_FORM_flag, VK); |
Benjamin Kramer | 345ef34 | 2010-03-31 19:34:01 +0000 | [diff] [blame] | 1329 | DIEBlock *Block = new (DIEValueAllocator) DIEBlock(); |
Devang Patel | 5d11eb0 | 2009-12-03 19:11:07 +0000 | [diff] [blame] | 1330 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_constu); |
Devang Patel | d639c7c | 2010-12-09 00:10:40 +0000 | [diff] [blame] | 1331 | addUInt(Block, 0, dwarf::DW_FORM_udata, SP.getVirtualIndex()); |
Devang Patel | 5d11eb0 | 2009-12-03 19:11:07 +0000 | [diff] [blame] | 1332 | addBlock(SPDie, dwarf::DW_AT_vtable_elem_location, 0, Block); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1333 | ContainingTypeMap.insert(std::make_pair(SPDie, |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 1334 | SP.getContainingType())); |
Devang Patel | 5d11eb0 | 2009-12-03 19:11:07 +0000 | [diff] [blame] | 1335 | } |
| 1336 | |
Devang Patel | ee70fa7 | 2010-09-27 23:15:27 +0000 | [diff] [blame] | 1337 | if (!SP.isDefinition()) { |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1338 | addUInt(SPDie, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag, 1); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1339 | |
| 1340 | // Add arguments. Do not add arguments for subprogram definition. They will |
Devang Patel | 1d5cc1d | 2009-12-03 01:25:38 +0000 | [diff] [blame] | 1341 | // be handled while processing variables. |
| 1342 | DICompositeType SPTy = SP.getType(); |
| 1343 | DIArray Args = SPTy.getTypeArray(); |
| 1344 | unsigned SPTag = SPTy.getTag(); |
| 1345 | |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1346 | if (SPTag == dwarf::DW_TAG_subroutine_type) |
| 1347 | for (unsigned i = 1, N = Args.getNumElements(); i < N; ++i) { |
| 1348 | DIE *Arg = new DIE(dwarf::DW_TAG_formal_parameter); |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 1349 | DIType ATy = DIType(DIType(Args.getElement(i))); |
Devang Patel | b464564 | 2010-02-06 01:02:37 +0000 | [diff] [blame] | 1350 | addType(Arg, ATy); |
| 1351 | if (ATy.isArtificial()) |
| 1352 | addUInt(Arg, dwarf::DW_AT_artificial, dwarf::DW_FORM_flag, 1); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1353 | SPDie->addChild(Arg); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1354 | } |
| 1355 | } |
| 1356 | |
Devang Patel | 4e0d19d | 2010-02-03 19:57:19 +0000 | [diff] [blame] | 1357 | if (SP.isArtificial()) |
| 1358 | addUInt(SPDie, dwarf::DW_AT_artificial, dwarf::DW_FORM_flag, 1); |
| 1359 | |
Devang Patel | ccff812 | 2010-04-30 19:38:23 +0000 | [diff] [blame] | 1360 | if (!SP.isLocalToUnit()) |
| 1361 | addUInt(SPDie, dwarf::DW_AT_external, dwarf::DW_FORM_flag, 1); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1362 | |
Devang Patel | ccff812 | 2010-04-30 19:38:23 +0000 | [diff] [blame] | 1363 | if (SP.isOptimized()) |
| 1364 | addUInt(SPDie, dwarf::DW_AT_APPLE_optimized, dwarf::DW_FORM_flag, 1); |
| 1365 | |
Jim Grosbach | 9172900 | 2010-07-21 23:03:52 +0000 | [diff] [blame] | 1366 | if (unsigned isa = Asm->getISAEncoding()) { |
| 1367 | addUInt(SPDie, dwarf::DW_AT_APPLE_isa, dwarf::DW_FORM_flag, isa); |
| 1368 | } |
| 1369 | |
Devang Patel | da19475 | 2011-04-05 22:52:06 +0000 | [diff] [blame] | 1370 | // Add function template parameters. |
| 1371 | addTemplateParams(*SPDie, SP.getTemplateParams()); |
| 1372 | |
Devang Patel | ccff812 | 2010-04-30 19:38:23 +0000 | [diff] [blame] | 1373 | // DW_TAG_inlined_subroutine may refer to this DIE. |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1374 | SPCU->insertDIE(SP, SPDie); |
Devang Patel | ccff812 | 2010-04-30 19:38:23 +0000 | [diff] [blame] | 1375 | |
Stuart Hastings | 215aa15 | 2010-06-11 20:08:44 +0000 | [diff] [blame] | 1376 | // Add to context owner. |
| 1377 | addToContextOwner(SPDie, SP.getContext()); |
| 1378 | |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1379 | return SPDie; |
| 1380 | } |
| 1381 | |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 1382 | DbgScope *DwarfDebug::getOrCreateAbstractScope(const MDNode *N) { |
Chris Lattner | ed7a77b | 2010-03-31 05:36:29 +0000 | [diff] [blame] | 1383 | assert(N && "Invalid Scope encoding!"); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1384 | |
| 1385 | DbgScope *AScope = AbstractScopes.lookup(N); |
| 1386 | if (AScope) |
| 1387 | return AScope; |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 1388 | |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1389 | DbgScope *Parent = NULL; |
| 1390 | |
| 1391 | DIDescriptor Scope(N); |
| 1392 | if (Scope.isLexicalBlock()) { |
| 1393 | DILexicalBlock DB(N); |
| 1394 | DIDescriptor ParentDesc = DB.getContext(); |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 1395 | Parent = getOrCreateAbstractScope(ParentDesc); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1396 | } |
| 1397 | |
| 1398 | AScope = new DbgScope(Parent, DIDescriptor(N), NULL); |
| 1399 | |
| 1400 | if (Parent) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1401 | Parent->addScope(AScope); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1402 | AScope->setAbstractScope(); |
| 1403 | AbstractScopes[N] = AScope; |
| 1404 | if (DIDescriptor(N).isSubprogram()) |
| 1405 | AbstractScopesList.push_back(AScope); |
| 1406 | return AScope; |
| 1407 | } |
Devang Patel | af9e847 | 2009-10-01 20:31:14 +0000 | [diff] [blame] | 1408 | |
Devang Patel | 5f09400 | 2010-04-06 23:53:48 +0000 | [diff] [blame] | 1409 | /// isSubprogramContext - Return true if Context is either a subprogram |
| 1410 | /// or another context nested inside a subprogram. |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 1411 | static bool isSubprogramContext(const MDNode *Context) { |
Devang Patel | 5f09400 | 2010-04-06 23:53:48 +0000 | [diff] [blame] | 1412 | if (!Context) |
| 1413 | return false; |
| 1414 | DIDescriptor D(Context); |
| 1415 | if (D.isSubprogram()) |
| 1416 | return true; |
| 1417 | if (D.isType()) |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 1418 | return isSubprogramContext(DIType(Context).getContext()); |
Devang Patel | 5f09400 | 2010-04-06 23:53:48 +0000 | [diff] [blame] | 1419 | return false; |
| 1420 | } |
| 1421 | |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 1422 | /// updateSubprogramScopeDIE - Find DIE for the given subprogram and |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1423 | /// attach appropriate DW_AT_low_pc and DW_AT_high_pc attributes. |
| 1424 | /// If there are global variables in this scope then create and insert |
| 1425 | /// DIEs for these variables. |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 1426 | DIE *DwarfDebug::updateSubprogramScopeDIE(const MDNode *SPNode) { |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1427 | CompileUnit *SPCU = getCompileUnit(SPNode); |
| 1428 | DIE *SPDie = SPCU->getDIE(SPNode); |
Devang Patel | 8aa6147 | 2010-07-07 22:20:57 +0000 | [diff] [blame] | 1429 | |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 1430 | assert(SPDie && "Unable to find subprogram DIE!"); |
| 1431 | DISubprogram SP(SPNode); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1432 | |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 1433 | // There is not any need to generate specification DIE for a function |
| 1434 | // defined at compile unit level. If a function is defined inside another |
| 1435 | // function then gdb prefers the definition at top level and but does not |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1436 | // expect specification DIE in parent function. So avoid creating |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 1437 | // specification DIE for a function defined inside a function. |
| 1438 | if (SP.isDefinition() && !SP.getContext().isCompileUnit() && |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1439 | !SP.getContext().isFile() && |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 1440 | !isSubprogramContext(SP.getContext())) { |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 1441 | addUInt(SPDie, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag, 1); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1442 | |
| 1443 | // Add arguments. |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 1444 | DICompositeType SPTy = SP.getType(); |
| 1445 | DIArray Args = SPTy.getTypeArray(); |
| 1446 | unsigned SPTag = SPTy.getTag(); |
| 1447 | if (SPTag == dwarf::DW_TAG_subroutine_type) |
| 1448 | for (unsigned i = 1, N = Args.getNumElements(); i < N; ++i) { |
| 1449 | DIE *Arg = new DIE(dwarf::DW_TAG_formal_parameter); |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 1450 | DIType ATy = DIType(DIType(Args.getElement(i))); |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 1451 | addType(Arg, ATy); |
| 1452 | if (ATy.isArtificial()) |
| 1453 | addUInt(Arg, dwarf::DW_AT_artificial, dwarf::DW_FORM_flag, 1); |
| 1454 | SPDie->addChild(Arg); |
| 1455 | } |
| 1456 | DIE *SPDeclDie = SPDie; |
| 1457 | SPDie = new DIE(dwarf::DW_TAG_subprogram); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1458 | addDIEEntry(SPDie, dwarf::DW_AT_specification, dwarf::DW_FORM_ref4, |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 1459 | SPDeclDie); |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1460 | SPCU->addDie(SPDie); |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 1461 | } |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1462 | |
Devang Patel | 8aa6147 | 2010-07-07 22:20:57 +0000 | [diff] [blame] | 1463 | // Pick up abstract subprogram DIE. |
| 1464 | if (DIE *AbsSPDIE = AbstractSPDies.lookup(SPNode)) { |
| 1465 | SPDie = new DIE(dwarf::DW_TAG_subprogram); |
| 1466 | addDIEEntry(SPDie, dwarf::DW_AT_abstract_origin, |
| 1467 | dwarf::DW_FORM_ref4, AbsSPDIE); |
| 1468 | SPCU->addDie(SPDie); |
| 1469 | } |
| 1470 | |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 1471 | addLabel(SPDie, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr, |
| 1472 | Asm->GetTempSymbol("func_begin", Asm->getFunctionNumber())); |
| 1473 | addLabel(SPDie, dwarf::DW_AT_high_pc, dwarf::DW_FORM_addr, |
| 1474 | Asm->GetTempSymbol("func_end", Asm->getFunctionNumber())); |
| 1475 | const TargetRegisterInfo *RI = Asm->TM.getRegisterInfo(); |
| 1476 | MachineLocation Location(RI->getFrameRegister(*Asm->MF)); |
| 1477 | addAddress(SPDie, dwarf::DW_AT_frame_base, Location); |
Devang Patel | b464564 | 2010-02-06 01:02:37 +0000 | [diff] [blame] | 1478 | |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 1479 | return SPDie; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1480 | } |
| 1481 | |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 1482 | /// constructLexicalScope - Construct new DW_TAG_lexical_block |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1483 | /// for this scope and attach DW_AT_low_pc/DW_AT_high_pc labels. |
| 1484 | DIE *DwarfDebug::constructLexicalScopeDIE(DbgScope *Scope) { |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1485 | |
| 1486 | DIE *ScopeDIE = new DIE(dwarf::DW_TAG_lexical_block); |
| 1487 | if (Scope->isAbstractScope()) |
| 1488 | return ScopeDIE; |
| 1489 | |
| 1490 | const SmallVector<DbgRange, 4> &Ranges = Scope->getRanges(); |
| 1491 | if (Ranges.empty()) |
| 1492 | return 0; |
| 1493 | |
| 1494 | SmallVector<DbgRange, 4>::const_iterator RI = Ranges.begin(); |
| 1495 | if (Ranges.size() > 1) { |
| 1496 | // .debug_range section has not been laid out yet. Emit offset in |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1497 | // .debug_range as a uint, size 4, for now. emitDIE will handle |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1498 | // DW_AT_ranges appropriately. |
| 1499 | addUInt(ScopeDIE, dwarf::DW_AT_ranges, dwarf::DW_FORM_data4, |
| 1500 | DebugRangeSymbols.size() * Asm->getTargetData().getPointerSize()); |
| 1501 | for (SmallVector<DbgRange, 4>::const_iterator RI = Ranges.begin(), |
| 1502 | RE = Ranges.end(); RI != RE; ++RI) { |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 1503 | DebugRangeSymbols.push_back(getLabelBeforeInsn(RI->first)); |
| 1504 | DebugRangeSymbols.push_back(getLabelAfterInsn(RI->second)); |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1505 | } |
| 1506 | DebugRangeSymbols.push_back(NULL); |
| 1507 | DebugRangeSymbols.push_back(NULL); |
| 1508 | return ScopeDIE; |
| 1509 | } |
| 1510 | |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 1511 | const MCSymbol *Start = getLabelBeforeInsn(RI->first); |
| 1512 | const MCSymbol *End = getLabelAfterInsn(RI->second); |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1513 | |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 1514 | if (End == 0) return 0; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1515 | |
Chris Lattner | b7db733 | 2010-03-09 01:58:53 +0000 | [diff] [blame] | 1516 | assert(Start->isDefined() && "Invalid starting label for an inlined scope!"); |
| 1517 | assert(End->isDefined() && "Invalid end label for an inlined scope!"); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1518 | |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1519 | addLabel(ScopeDIE, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr, Start); |
| 1520 | addLabel(ScopeDIE, dwarf::DW_AT_high_pc, dwarf::DW_FORM_addr, End); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1521 | |
| 1522 | return ScopeDIE; |
| 1523 | } |
| 1524 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1525 | /// constructInlinedScopeDIE - This scope represents inlined body of |
| 1526 | /// a function. Construct DIE to represent this concrete inlined copy |
| 1527 | /// of the function. |
| 1528 | DIE *DwarfDebug::constructInlinedScopeDIE(DbgScope *Scope) { |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1529 | |
| 1530 | const SmallVector<DbgRange, 4> &Ranges = Scope->getRanges(); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1531 | assert (Ranges.empty() == false |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1532 | && "DbgScope does not have instruction markers!"); |
| 1533 | |
| 1534 | // FIXME : .debug_inlined section specification does not clearly state how |
| 1535 | // to emit inlined scope that is split into multiple instruction ranges. |
| 1536 | // For now, use first instruction range and emit low_pc/high_pc pair and |
| 1537 | // corresponding .debug_inlined section entry for this pair. |
| 1538 | SmallVector<DbgRange, 4>::const_iterator RI = Ranges.begin(); |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 1539 | const MCSymbol *StartLabel = getLabelBeforeInsn(RI->first); |
| 1540 | const MCSymbol *EndLabel = getLabelAfterInsn(RI->second); |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1541 | |
Devang Patel | 0afbf23 | 2010-07-08 22:39:20 +0000 | [diff] [blame] | 1542 | if (StartLabel == 0 || EndLabel == 0) { |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1543 | assert (0 && "Unexpected Start and End labels for a inlined scope!"); |
| 1544 | return 0; |
| 1545 | } |
Chris Lattner | b7db733 | 2010-03-09 01:58:53 +0000 | [diff] [blame] | 1546 | assert(StartLabel->isDefined() && |
Chris Lattner | a34ec229 | 2010-03-09 01:51:43 +0000 | [diff] [blame] | 1547 | "Invalid starting label for an inlined scope!"); |
Chris Lattner | b7db733 | 2010-03-09 01:58:53 +0000 | [diff] [blame] | 1548 | assert(EndLabel->isDefined() && |
Chris Lattner | a34ec229 | 2010-03-09 01:51:43 +0000 | [diff] [blame] | 1549 | "Invalid end label for an inlined scope!"); |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1550 | |
Devang Patel | 3c91b05 | 2010-03-08 20:52:55 +0000 | [diff] [blame] | 1551 | if (!Scope->getScopeNode()) |
Devang Patel | 0ef3fa6 | 2010-03-08 19:20:38 +0000 | [diff] [blame] | 1552 | return NULL; |
Devang Patel | 3c91b05 | 2010-03-08 20:52:55 +0000 | [diff] [blame] | 1553 | DIScope DS(Scope->getScopeNode()); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1554 | DIE *ScopeDIE = new DIE(dwarf::DW_TAG_inlined_subroutine); |
| 1555 | |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 1556 | DISubprogram InlinedSP = getDISubprogram(DS); |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1557 | CompileUnit *TheCU = getCompileUnit(InlinedSP); |
| 1558 | DIE *OriginDIE = TheCU->getDIE(InlinedSP); |
Chris Lattner | ed7a77b | 2010-03-31 05:36:29 +0000 | [diff] [blame] | 1559 | assert(OriginDIE && "Unable to find Origin DIE!"); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1560 | addDIEEntry(ScopeDIE, dwarf::DW_AT_abstract_origin, |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1561 | dwarf::DW_FORM_ref4, OriginDIE); |
| 1562 | |
Chris Lattner | 6ed0f90 | 2010-03-09 00:31:02 +0000 | [diff] [blame] | 1563 | addLabel(ScopeDIE, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr, StartLabel); |
Chris Lattner | b7db733 | 2010-03-09 01:58:53 +0000 | [diff] [blame] | 1564 | addLabel(ScopeDIE, dwarf::DW_AT_high_pc, dwarf::DW_FORM_addr, EndLabel); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1565 | |
| 1566 | InlinedSubprogramDIEs.insert(OriginDIE); |
| 1567 | |
| 1568 | // Track the start label for this inlined function. |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 1569 | DenseMap<const MDNode *, SmallVector<InlineInfoLabels, 4> >::iterator |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 1570 | I = InlineInfo.find(InlinedSP); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1571 | |
| 1572 | if (I == InlineInfo.end()) { |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 1573 | InlineInfo[InlinedSP].push_back(std::make_pair(StartLabel, |
Jim Grosbach | 7ab38df | 2009-11-22 19:20:36 +0000 | [diff] [blame] | 1574 | ScopeDIE)); |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 1575 | InlinedSPNodes.push_back(InlinedSP); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1576 | } else |
Chris Lattner | 6ed0f90 | 2010-03-09 00:31:02 +0000 | [diff] [blame] | 1577 | I->second.push_back(std::make_pair(StartLabel, ScopeDIE)); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1578 | |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1579 | DILocation DL(Scope->getInlinedAt()); |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1580 | addUInt(ScopeDIE, dwarf::DW_AT_call_file, 0, TheCU->getID()); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1581 | addUInt(ScopeDIE, dwarf::DW_AT_call_line, 0, DL.getLineNumber()); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1582 | |
| 1583 | return ScopeDIE; |
| 1584 | } |
| 1585 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1586 | |
| 1587 | /// constructVariableDIE - Construct a DIE for the given DbgVariable. |
Devang Patel | 8a24114 | 2009-12-09 18:24:21 +0000 | [diff] [blame] | 1588 | DIE *DwarfDebug::constructVariableDIE(DbgVariable *DV, DbgScope *Scope) { |
Devang Patel | 8bd11de | 2010-08-09 21:01:39 +0000 | [diff] [blame] | 1589 | StringRef Name = DV->getName(); |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 1590 | if (Name.empty()) |
Devang Patel | 3fb6bd6 | 2009-11-13 02:25:26 +0000 | [diff] [blame] | 1591 | return NULL; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1592 | |
| 1593 | // Translate tag to proper Dwarf tag. The result variable is dropped for |
| 1594 | // now. |
| 1595 | unsigned Tag; |
Devang Patel | 8bd11de | 2010-08-09 21:01:39 +0000 | [diff] [blame] | 1596 | switch (DV->getTag()) { |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1597 | case dwarf::DW_TAG_return_variable: |
| 1598 | return NULL; |
| 1599 | case dwarf::DW_TAG_arg_variable: |
| 1600 | Tag = dwarf::DW_TAG_formal_parameter; |
| 1601 | break; |
| 1602 | case dwarf::DW_TAG_auto_variable: // fall thru |
| 1603 | default: |
| 1604 | Tag = dwarf::DW_TAG_variable; |
| 1605 | break; |
| 1606 | } |
| 1607 | |
| 1608 | // Define variable debug information entry. |
| 1609 | DIE *VariableDie = new DIE(Tag); |
| 1610 | |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1611 | DIE *AbsDIE = NULL; |
Devang Patel | 26c1e56 | 2010-05-20 16:36:41 +0000 | [diff] [blame] | 1612 | DenseMap<const DbgVariable *, const DbgVariable *>::iterator |
| 1613 | V2AVI = VarToAbstractVarMap.find(DV); |
| 1614 | if (V2AVI != VarToAbstractVarMap.end()) |
| 1615 | AbsDIE = V2AVI->second->getDIE(); |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 1616 | |
Devang Patel | 26c1e56 | 2010-05-20 16:36:41 +0000 | [diff] [blame] | 1617 | if (AbsDIE) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1618 | addDIEEntry(VariableDie, dwarf::DW_AT_abstract_origin, |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1619 | dwarf::DW_FORM_ref4, AbsDIE); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1620 | else { |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1621 | addString(VariableDie, dwarf::DW_AT_name, dwarf::DW_FORM_string, Name); |
Devang Patel | 8bd11de | 2010-08-09 21:01:39 +0000 | [diff] [blame] | 1622 | addSourceLine(VariableDie, DV->getVariable()); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1623 | |
| 1624 | // Add variable type. |
Devang Patel | 8bd11de | 2010-08-09 21:01:39 +0000 | [diff] [blame] | 1625 | addType(VariableDie, DV->getType()); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1626 | } |
| 1627 | |
Devang Patel | 8bd11de | 2010-08-09 21:01:39 +0000 | [diff] [blame] | 1628 | if (Tag == dwarf::DW_TAG_formal_parameter && DV->getType().isArtificial()) |
Devang Patel | b464564 | 2010-02-06 01:02:37 +0000 | [diff] [blame] | 1629 | addUInt(VariableDie, dwarf::DW_AT_artificial, dwarf::DW_FORM_flag, 1); |
Devang Patel | 3cf763d | 2010-09-29 23:07:21 +0000 | [diff] [blame] | 1630 | else if (DIVariable(DV->getVariable()).isArtificial()) |
| 1631 | addUInt(VariableDie, dwarf::DW_AT_artificial, dwarf::DW_FORM_flag, 1); |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 1632 | |
| 1633 | if (Scope->isAbstractScope()) { |
| 1634 | DV->setDIE(VariableDie); |
| 1635 | return VariableDie; |
| 1636 | } |
| 1637 | |
| 1638 | // Add variable address. |
| 1639 | |
| 1640 | unsigned Offset = DV->getDotDebugLocOffset(); |
| 1641 | if (Offset != ~0U) { |
| 1642 | addLabel(VariableDie, dwarf::DW_AT_location, dwarf::DW_FORM_data4, |
| 1643 | Asm->GetTempSymbol("debug_loc", Offset)); |
| 1644 | DV->setDIE(VariableDie); |
| 1645 | UseDotDebugLocEntry.insert(VariableDie); |
| 1646 | return VariableDie; |
| 1647 | } |
| 1648 | |
| 1649 | // Check if variable is described by a DBG_VALUE instruction. |
| 1650 | DenseMap<const DbgVariable *, const MachineInstr *>::iterator DVI = |
| 1651 | DbgVariableToDbgInstMap.find(DV); |
| 1652 | if (DVI != DbgVariableToDbgInstMap.end()) { |
| 1653 | const MachineInstr *DVInsn = DVI->second; |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 1654 | bool updated = false; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1655 | // FIXME : Handle getNumOperands != 3 |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 1656 | if (DVInsn->getNumOperands() == 3) { |
Devang Patel | 0b48ead | 2010-08-31 22:22:42 +0000 | [diff] [blame] | 1657 | if (DVInsn->getOperand(0).isReg()) { |
| 1658 | const MachineOperand RegOp = DVInsn->getOperand(0); |
| 1659 | const TargetRegisterInfo *TRI = Asm->TM.getRegisterInfo(); |
| 1660 | if (DVInsn->getOperand(1).isImm() && |
| 1661 | TRI->getFrameRegister(*Asm->MF) == RegOp.getReg()) { |
| 1662 | addVariableAddress(DV, VariableDie, DVInsn->getOperand(1).getImm()); |
| 1663 | updated = true; |
| 1664 | } else |
Devang Patel | 522ad74 | 2010-11-12 23:20:42 +0000 | [diff] [blame] | 1665 | updated = addRegisterAddress(VariableDie, RegOp); |
Devang Patel | 0b48ead | 2010-08-31 22:22:42 +0000 | [diff] [blame] | 1666 | } |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 1667 | else if (DVInsn->getOperand(0).isImm()) |
Devang Patel | 522ad74 | 2010-11-12 23:20:42 +0000 | [diff] [blame] | 1668 | updated = addConstantValue(VariableDie, DVInsn->getOperand(0)); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1669 | else if (DVInsn->getOperand(0).isFPImm()) |
| 1670 | updated = |
Devang Patel | 522ad74 | 2010-11-12 23:20:42 +0000 | [diff] [blame] | 1671 | addConstantFPValue(VariableDie, DVInsn->getOperand(0)); |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 1672 | } else { |
| 1673 | MachineLocation Location = Asm->getDebugValueLocation(DVInsn); |
| 1674 | if (Location.getReg()) { |
| 1675 | addAddress(VariableDie, dwarf::DW_AT_location, Location); |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 1676 | updated = true; |
| 1677 | } |
| 1678 | } |
| 1679 | if (!updated) { |
| 1680 | // If variableDie is not updated then DBG_VALUE instruction does not |
| 1681 | // have valid variable info. |
| 1682 | delete VariableDie; |
| 1683 | return NULL; |
| 1684 | } |
| 1685 | DV->setDIE(VariableDie); |
| 1686 | return VariableDie; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1687 | } |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 1688 | |
| 1689 | // .. else use frame index, if available. |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 1690 | int FI = 0; |
Devang Patel | 9e3bd2c | 2010-08-31 06:11:28 +0000 | [diff] [blame] | 1691 | if (findVariableFrameIndex(DV, &FI)) |
| 1692 | addVariableAddress(DV, VariableDie, FI); |
| 1693 | |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1694 | DV->setDIE(VariableDie); |
| 1695 | return VariableDie; |
| 1696 | |
| 1697 | } |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1698 | |
Devang Patel | 193f720 | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 1699 | void DwarfDebug::addPubTypes(DISubprogram SP) { |
| 1700 | DICompositeType SPTy = SP.getType(); |
| 1701 | unsigned SPTag = SPTy.getTag(); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1702 | if (SPTag != dwarf::DW_TAG_subroutine_type) |
Devang Patel | 193f720 | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 1703 | return; |
| 1704 | |
| 1705 | DIArray Args = SPTy.getTypeArray(); |
Devang Patel | 193f720 | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 1706 | for (unsigned i = 0, e = Args.getNumElements(); i != e; ++i) { |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 1707 | DIType ATy(Args.getElement(i)); |
Devang Patel | 9c00487 | 2010-05-07 21:45:47 +0000 | [diff] [blame] | 1708 | if (!ATy.Verify()) |
Devang Patel | 193f720 | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 1709 | continue; |
| 1710 | DICompositeType CATy = getDICompositeType(ATy); |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 1711 | if (DIDescriptor(CATy).Verify() && !CATy.getName().empty() |
Devang Patel | 50d80e3 | 2010-04-13 20:35:04 +0000 | [diff] [blame] | 1712 | && !CATy.isForwardDecl()) { |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1713 | CompileUnit *TheCU = getCompileUnit(CATy); |
| 1714 | if (DIEEntry *Entry = TheCU->getDIEEntry(CATy)) |
| 1715 | TheCU->addGlobalType(CATy.getName(), Entry->getEntry()); |
Devang Patel | 193f720 | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 1716 | } |
| 1717 | } |
| 1718 | } |
| 1719 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1720 | /// constructScopeDIE - Construct a DIE for this scope. |
| 1721 | DIE *DwarfDebug::constructScopeDIE(DbgScope *Scope) { |
Devang Patel | 3c91b05 | 2010-03-08 20:52:55 +0000 | [diff] [blame] | 1722 | if (!Scope || !Scope->getScopeNode()) |
| 1723 | return NULL; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1724 | |
Devang Patel | 5bc9fec | 2011-02-19 01:31:27 +0000 | [diff] [blame] | 1725 | SmallVector <DIE *, 8> Children; |
Devang Patel | 0478c15 | 2011-03-01 22:58:55 +0000 | [diff] [blame] | 1726 | |
| 1727 | // Collect arguments for current function. |
| 1728 | if (Scope == CurrentFnDbgScope) |
| 1729 | for (unsigned i = 0, N = CurrentFnArguments.size(); i < N; ++i) |
| 1730 | if (DbgVariable *ArgDV = CurrentFnArguments[i]) |
| 1731 | if (DIE *Arg = constructVariableDIE(ArgDV, Scope)) |
| 1732 | Children.push_back(Arg); |
| 1733 | |
Devang Patel | 5bc9fec | 2011-02-19 01:31:27 +0000 | [diff] [blame] | 1734 | // Collect lexical scope childrens first. |
| 1735 | const SmallVector<DbgVariable *, 8> &Variables = Scope->getDbgVariables(); |
| 1736 | for (unsigned i = 0, N = Variables.size(); i < N; ++i) |
| 1737 | if (DIE *Variable = constructVariableDIE(Variables[i], Scope)) |
| 1738 | Children.push_back(Variable); |
| 1739 | const SmallVector<DbgScope *, 4> &Scopes = Scope->getScopes(); |
| 1740 | for (unsigned j = 0, M = Scopes.size(); j < M; ++j) |
| 1741 | if (DIE *Nested = constructScopeDIE(Scopes[j])) |
| 1742 | Children.push_back(Nested); |
Devang Patel | 3c91b05 | 2010-03-08 20:52:55 +0000 | [diff] [blame] | 1743 | DIScope DS(Scope->getScopeNode()); |
| 1744 | DIE *ScopeDIE = NULL; |
| 1745 | if (Scope->getInlinedAt()) |
| 1746 | ScopeDIE = constructInlinedScopeDIE(Scope); |
| 1747 | else if (DS.isSubprogram()) { |
Devang Patel | 0dd4558 | 2010-06-28 20:53:04 +0000 | [diff] [blame] | 1748 | ProcessedSPNodes.insert(DS); |
Devang Patel | 8aa6147 | 2010-07-07 22:20:57 +0000 | [diff] [blame] | 1749 | if (Scope->isAbstractScope()) { |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1750 | ScopeDIE = getCompileUnit(DS)->getDIE(DS); |
Devang Patel | 8aa6147 | 2010-07-07 22:20:57 +0000 | [diff] [blame] | 1751 | // Note down abstract DIE. |
| 1752 | if (ScopeDIE) |
| 1753 | AbstractSPDies.insert(std::make_pair(DS, ScopeDIE)); |
| 1754 | } |
Devang Patel | 3c91b05 | 2010-03-08 20:52:55 +0000 | [diff] [blame] | 1755 | else |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 1756 | ScopeDIE = updateSubprogramScopeDIE(DS); |
Devang Patel | 3c91b05 | 2010-03-08 20:52:55 +0000 | [diff] [blame] | 1757 | } |
Devang Patel | 5bc9fec | 2011-02-19 01:31:27 +0000 | [diff] [blame] | 1758 | else { |
| 1759 | // There is no need to emit empty lexical block DIE. |
| 1760 | if (Children.empty()) |
| 1761 | return NULL; |
Devang Patel | 3c91b05 | 2010-03-08 20:52:55 +0000 | [diff] [blame] | 1762 | ScopeDIE = constructLexicalScopeDIE(Scope); |
Devang Patel | 5bc9fec | 2011-02-19 01:31:27 +0000 | [diff] [blame] | 1763 | } |
| 1764 | |
Devang Patel | aead63c | 2010-03-29 22:59:58 +0000 | [diff] [blame] | 1765 | if (!ScopeDIE) return NULL; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1766 | |
Devang Patel | 5bc9fec | 2011-02-19 01:31:27 +0000 | [diff] [blame] | 1767 | // Add children |
| 1768 | for (SmallVector<DIE *, 8>::iterator I = Children.begin(), |
| 1769 | E = Children.end(); I != E; ++I) |
| 1770 | ScopeDIE->addChild(*I); |
Devang Patel | 193f720 | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 1771 | |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1772 | if (DS.isSubprogram()) |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 1773 | addPubTypes(DISubprogram(DS)); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1774 | |
Devang Patel | 193f720 | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 1775 | return ScopeDIE; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1776 | } |
| 1777 | |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1778 | /// GetOrCreateSourceID - Look up the source id with the given directory and |
| 1779 | /// source file names. If none currently exists, create a new id and insert it |
| 1780 | /// in the SourceIds map. This can update DirectoryNames and SourceFileNames |
| 1781 | /// maps as well. |
Devang Patel | 2f58485 | 2010-07-24 00:53:22 +0000 | [diff] [blame] | 1782 | |
Devang Patel | 23670e5 | 2011-03-24 20:30:50 +0000 | [diff] [blame] | 1783 | unsigned DwarfDebug::GetOrCreateSourceID(StringRef FileName, |
| 1784 | StringRef DirName) { |
Devang Patel | 1905a18 | 2010-09-16 20:57:49 +0000 | [diff] [blame] | 1785 | // If FE did not provide a file name, then assume stdin. |
| 1786 | if (FileName.empty()) |
Devang Patel | 23670e5 | 2011-03-24 20:30:50 +0000 | [diff] [blame] | 1787 | return GetOrCreateSourceID("<stdin>", StringRef()); |
| 1788 | |
| 1789 | // MCStream expects full path name as filename. |
| 1790 | if (!DirName.empty() && !FileName.startswith("/")) { |
| 1791 | std::string FullPathName(DirName.data()); |
| 1792 | if (!DirName.endswith("/")) |
| 1793 | FullPathName += "/"; |
| 1794 | FullPathName += FileName.data(); |
| 1795 | // Here FullPathName will be copied into StringMap by GetOrCreateSourceID. |
| 1796 | return GetOrCreateSourceID(StringRef(FullPathName), StringRef()); |
| 1797 | } |
Devang Patel | 1905a18 | 2010-09-16 20:57:49 +0000 | [diff] [blame] | 1798 | |
Rafael Espindola | 5c05563 | 2010-11-18 02:04:25 +0000 | [diff] [blame] | 1799 | StringMapEntry<unsigned> &Entry = SourceIdMap.GetOrCreateValue(FileName); |
| 1800 | if (Entry.getValue()) |
| 1801 | return Entry.getValue(); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1802 | |
Rafael Espindola | 5c05563 | 2010-11-18 02:04:25 +0000 | [diff] [blame] | 1803 | unsigned SrcId = SourceIdMap.size(); |
| 1804 | Entry.setValue(SrcId); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1805 | |
Rafael Espindola | 5c05563 | 2010-11-18 02:04:25 +0000 | [diff] [blame] | 1806 | // Print out a .file directive to specify files for .loc directives. |
Devang Patel | 23670e5 | 2011-03-24 20:30:50 +0000 | [diff] [blame] | 1807 | Asm->OutStreamer.EmitDwarfFileDirective(SrcId, Entry.getKey()); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1808 | |
| 1809 | return SrcId; |
| 1810 | } |
| 1811 | |
Devang Patel | 6404e4e | 2009-12-15 19:16:48 +0000 | [diff] [blame] | 1812 | /// getOrCreateNameSpace - Create a DIE for DINameSpace. |
| 1813 | DIE *DwarfDebug::getOrCreateNameSpace(DINameSpace NS) { |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1814 | CompileUnit *TheCU = getCompileUnit(NS); |
| 1815 | DIE *NDie = TheCU->getDIE(NS); |
Devang Patel | 6404e4e | 2009-12-15 19:16:48 +0000 | [diff] [blame] | 1816 | if (NDie) |
| 1817 | return NDie; |
| 1818 | NDie = new DIE(dwarf::DW_TAG_namespace); |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1819 | TheCU->insertDIE(NS, NDie); |
Devang Patel | 6404e4e | 2009-12-15 19:16:48 +0000 | [diff] [blame] | 1820 | if (!NS.getName().empty()) |
| 1821 | addString(NDie, dwarf::DW_AT_name, dwarf::DW_FORM_string, NS.getName()); |
Devang Patel | 8162574 | 2010-08-09 20:20:05 +0000 | [diff] [blame] | 1822 | addSourceLine(NDie, NS); |
Devang Patel | 6404e4e | 2009-12-15 19:16:48 +0000 | [diff] [blame] | 1823 | addToContextOwner(NDie, NS.getContext()); |
| 1824 | return NDie; |
| 1825 | } |
| 1826 | |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1827 | /// constructCompileUnit - Create new CompileUnit for the given |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1828 | /// metadata node with tag DW_TAG_compile_unit. |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 1829 | void DwarfDebug::constructCompileUnit(const MDNode *N) { |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1830 | DICompileUnit DIUnit(N); |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 1831 | StringRef FN = DIUnit.getFilename(); |
| 1832 | StringRef Dir = DIUnit.getDirectory(); |
Devang Patel | 23670e5 | 2011-03-24 20:30:50 +0000 | [diff] [blame] | 1833 | unsigned ID = GetOrCreateSourceID(FN, Dir); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1834 | |
| 1835 | DIE *Die = new DIE(dwarf::DW_TAG_compile_unit); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1836 | addString(Die, dwarf::DW_AT_producer, dwarf::DW_FORM_string, |
Devang Patel | 5ccdd10 | 2009-09-29 18:40:58 +0000 | [diff] [blame] | 1837 | DIUnit.getProducer()); |
Devang Patel | 3a4ae32 | 2011-02-23 22:37:04 +0000 | [diff] [blame] | 1838 | addUInt(Die, dwarf::DW_AT_language, dwarf::DW_FORM_data2, |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1839 | DIUnit.getLanguage()); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1840 | addString(Die, dwarf::DW_AT_name, dwarf::DW_FORM_string, FN); |
Devang Patel | 5098da0 | 2010-04-26 22:54:28 +0000 | [diff] [blame] | 1841 | // Use DW_AT_entry_pc instead of DW_AT_low_pc/DW_AT_high_pc pair. This |
| 1842 | // simplifies debug range entries. |
Devang Patel | 9b93b6b | 2010-06-28 22:22:47 +0000 | [diff] [blame] | 1843 | addUInt(Die, dwarf::DW_AT_entry_pc, dwarf::DW_FORM_addr, 0); |
Devang Patel | 4a602ca | 2010-03-22 23:11:36 +0000 | [diff] [blame] | 1844 | // DW_AT_stmt_list is a offset of line number information for this |
Devang Patel | af608bd | 2010-08-24 00:06:12 +0000 | [diff] [blame] | 1845 | // compile unit in debug_line section. |
Devang Patel | ae84d5b | 2010-08-31 23:50:19 +0000 | [diff] [blame] | 1846 | if (Asm->MAI->doesDwarfUsesAbsoluteLabelForStmtList()) |
Cameron Zwarich | f754f50 | 2011-02-25 16:30:32 +0000 | [diff] [blame] | 1847 | addLabel(Die, dwarf::DW_AT_stmt_list, dwarf::DW_FORM_addr, |
| 1848 | Asm->GetTempSymbol("section_line")); |
Devang Patel | ae84d5b | 2010-08-31 23:50:19 +0000 | [diff] [blame] | 1849 | else |
| 1850 | addUInt(Die, dwarf::DW_AT_stmt_list, dwarf::DW_FORM_data4, 0); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1851 | |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 1852 | if (!Dir.empty()) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1853 | addString(Die, dwarf::DW_AT_comp_dir, dwarf::DW_FORM_string, Dir); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1854 | if (DIUnit.isOptimized()) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1855 | addUInt(Die, dwarf::DW_AT_APPLE_optimized, dwarf::DW_FORM_flag, 1); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1856 | |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 1857 | StringRef Flags = DIUnit.getFlags(); |
| 1858 | if (!Flags.empty()) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1859 | addString(Die, dwarf::DW_AT_APPLE_flags, dwarf::DW_FORM_string, Flags); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1860 | |
| 1861 | unsigned RVer = DIUnit.getRunTimeVersion(); |
| 1862 | if (RVer) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1863 | addUInt(Die, dwarf::DW_AT_APPLE_major_runtime_vers, |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1864 | dwarf::DW_FORM_data1, RVer); |
| 1865 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1866 | CompileUnit *NewCU = new CompileUnit(ID, Die); |
| 1867 | if (!FirstCU) |
| 1868 | FirstCU = NewCU; |
| 1869 | CUMap.insert(std::make_pair(N, NewCU)); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1870 | } |
| 1871 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1872 | /// getCompielUnit - Get CompileUnit DIE. |
| 1873 | CompileUnit *DwarfDebug::getCompileUnit(const MDNode *N) const { |
| 1874 | assert (N && "Invalid DwarfDebug::getCompileUnit argument!"); |
| 1875 | DIDescriptor D(N); |
| 1876 | const MDNode *CUNode = NULL; |
| 1877 | if (D.isCompileUnit()) |
| 1878 | CUNode = N; |
| 1879 | else if (D.isSubprogram()) |
| 1880 | CUNode = DISubprogram(N).getCompileUnit(); |
| 1881 | else if (D.isType()) |
| 1882 | CUNode = DIType(N).getCompileUnit(); |
| 1883 | else if (D.isGlobalVariable()) |
| 1884 | CUNode = DIGlobalVariable(N).getCompileUnit(); |
| 1885 | else if (D.isVariable()) |
| 1886 | CUNode = DIVariable(N).getCompileUnit(); |
| 1887 | else if (D.isNameSpace()) |
| 1888 | CUNode = DINameSpace(N).getCompileUnit(); |
| 1889 | else if (D.isFile()) |
| 1890 | CUNode = DIFile(N).getCompileUnit(); |
| 1891 | else |
| 1892 | return FirstCU; |
| 1893 | |
| 1894 | DenseMap<const MDNode *, CompileUnit *>::const_iterator I |
| 1895 | = CUMap.find(CUNode); |
| 1896 | if (I == CUMap.end()) |
| 1897 | return FirstCU; |
| 1898 | return I->second; |
| 1899 | } |
| 1900 | |
Devang Patel | 0c4720c | 2010-08-23 18:25:56 +0000 | [diff] [blame] | 1901 | /// isUnsignedDIType - Return true if type encoding is unsigned. |
| 1902 | static bool isUnsignedDIType(DIType Ty) { |
| 1903 | DIDerivedType DTy(Ty); |
| 1904 | if (DTy.Verify()) |
| 1905 | return isUnsignedDIType(DTy.getTypeDerivedFrom()); |
| 1906 | |
| 1907 | DIBasicType BTy(Ty); |
| 1908 | if (BTy.Verify()) { |
| 1909 | unsigned Encoding = BTy.getEncoding(); |
| 1910 | if (Encoding == dwarf::DW_ATE_unsigned || |
| 1911 | Encoding == dwarf::DW_ATE_unsigned_char) |
| 1912 | return true; |
| 1913 | } |
| 1914 | return false; |
| 1915 | } |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1916 | |
Devang Patel | e449d1f | 2011-01-20 00:02:16 +0000 | [diff] [blame] | 1917 | // Return const exprssion if value is a GEP to access merged global |
| 1918 | // constant. e.g. |
| 1919 | // i8* getelementptr ({ i8, i8, i8, i8 }* @_MergedGlobals, i32 0, i32 0) |
| 1920 | static const ConstantExpr *getMergedGlobalExpr(const Value *V) { |
| 1921 | const ConstantExpr *CE = dyn_cast_or_null<ConstantExpr>(V); |
| 1922 | if (!CE || CE->getNumOperands() != 3 || |
| 1923 | CE->getOpcode() != Instruction::GetElementPtr) |
| 1924 | return NULL; |
| 1925 | |
| 1926 | // First operand points to a global value. |
| 1927 | if (!isa<GlobalValue>(CE->getOperand(0))) |
| 1928 | return NULL; |
| 1929 | |
| 1930 | // Second operand is zero. |
| 1931 | const ConstantInt *CI = |
| 1932 | dyn_cast_or_null<ConstantInt>(CE->getOperand(1)); |
| 1933 | if (!CI || !CI->isZero()) |
| 1934 | return NULL; |
| 1935 | |
| 1936 | // Third operand is offset. |
| 1937 | if (!isa<ConstantInt>(CE->getOperand(2))) |
| 1938 | return NULL; |
| 1939 | |
| 1940 | return CE; |
| 1941 | } |
| 1942 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1943 | /// constructGlobalVariableDIE - Construct global variable DIE. |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 1944 | void DwarfDebug::constructGlobalVariableDIE(const MDNode *N) { |
Devang Patel | 9fa539c | 2010-08-10 01:37:23 +0000 | [diff] [blame] | 1945 | DIGlobalVariable GV(N); |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 1946 | |
Devang Patel | 905cf5e | 2009-09-04 23:59:07 +0000 | [diff] [blame] | 1947 | // If debug information is malformed then ignore it. |
Devang Patel | 9fa539c | 2010-08-10 01:37:23 +0000 | [diff] [blame] | 1948 | if (GV.Verify() == false) |
Devang Patel | 905cf5e | 2009-09-04 23:59:07 +0000 | [diff] [blame] | 1949 | return; |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1950 | |
| 1951 | // Check for pre-existence. |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1952 | CompileUnit *TheCU = getCompileUnit(N); |
Devang Patel | 9fa539c | 2010-08-10 01:37:23 +0000 | [diff] [blame] | 1953 | if (TheCU->getDIE(GV)) |
Devang Patel | 13e16b6 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 1954 | return; |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1955 | |
Devang Patel | 9fa539c | 2010-08-10 01:37:23 +0000 | [diff] [blame] | 1956 | DIType GTy = GV.getType(); |
Devang Patel | 2936807 | 2010-08-10 07:11:13 +0000 | [diff] [blame] | 1957 | DIE *VariableDIE = new DIE(GV.getTag()); |
| 1958 | |
| 1959 | bool isGlobalVariable = GV.getGlobal() != NULL; |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1960 | |
Devang Patel | 9fa539c | 2010-08-10 01:37:23 +0000 | [diff] [blame] | 1961 | // Add name. |
| 1962 | addString(VariableDIE, dwarf::DW_AT_name, dwarf::DW_FORM_string, |
| 1963 | GV.getDisplayName()); |
| 1964 | StringRef LinkageName = GV.getLinkageName(); |
Devang Patel | 2936807 | 2010-08-10 07:11:13 +0000 | [diff] [blame] | 1965 | if (!LinkageName.empty() && isGlobalVariable) |
Devang Patel | 9fa539c | 2010-08-10 01:37:23 +0000 | [diff] [blame] | 1966 | addString(VariableDIE, dwarf::DW_AT_MIPS_linkage_name, dwarf::DW_FORM_string, |
| 1967 | getRealLinkageName(LinkageName)); |
| 1968 | // Add type. |
| 1969 | addType(VariableDIE, GTy); |
Devang Patel | 50d80e3 | 2010-04-13 20:35:04 +0000 | [diff] [blame] | 1970 | if (GTy.isCompositeType() && !GTy.getName().empty() |
| 1971 | && !GTy.isForwardDecl()) { |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1972 | DIEEntry *Entry = TheCU->getDIEEntry(GTy); |
Chris Lattner | ed7a77b | 2010-03-31 05:36:29 +0000 | [diff] [blame] | 1973 | assert(Entry && "Missing global type!"); |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1974 | TheCU->addGlobalType(GTy.getName(), Entry->getEntry()); |
Devang Patel | 193f720 | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 1975 | } |
Devang Patel | 9fa539c | 2010-08-10 01:37:23 +0000 | [diff] [blame] | 1976 | // Add scoping info. |
| 1977 | if (!GV.isLocalToUnit()) { |
| 1978 | addUInt(VariableDIE, dwarf::DW_AT_external, dwarf::DW_FORM_flag, 1); |
| 1979 | // Expose as global. |
| 1980 | TheCU->addGlobal(GV.getName(), VariableDIE); |
| 1981 | } |
| 1982 | // Add line number info. |
| 1983 | addSourceLine(VariableDIE, GV); |
| 1984 | // Add to map. |
| 1985 | TheCU->insertDIE(N, VariableDIE); |
| 1986 | // Add to context owner. |
| 1987 | DIDescriptor GVContext = GV.getContext(); |
| 1988 | addToContextOwner(VariableDIE, GVContext); |
| 1989 | // Add location. |
Devang Patel | 2936807 | 2010-08-10 07:11:13 +0000 | [diff] [blame] | 1990 | if (isGlobalVariable) { |
| 1991 | DIEBlock *Block = new (DIEValueAllocator) DIEBlock(); |
| 1992 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_addr); |
| 1993 | addLabel(Block, 0, dwarf::DW_FORM_udata, |
| 1994 | Asm->Mang->getSymbol(GV.getGlobal())); |
| 1995 | // Do not create specification DIE if context is either compile unit |
| 1996 | // or a subprogram. |
| 1997 | if (GV.isDefinition() && !GVContext.isCompileUnit() && |
| 1998 | !GVContext.isFile() && !isSubprogramContext(GVContext)) { |
| 1999 | // Create specification DIE. |
| 2000 | DIE *VariableSpecDIE = new DIE(dwarf::DW_TAG_variable); |
| 2001 | addDIEEntry(VariableSpecDIE, dwarf::DW_AT_specification, |
| 2002 | dwarf::DW_FORM_ref4, VariableDIE); |
| 2003 | addBlock(VariableSpecDIE, dwarf::DW_AT_location, 0, Block); |
| 2004 | addUInt(VariableDIE, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag, 1); |
| 2005 | TheCU->addDie(VariableSpecDIE); |
| 2006 | } else { |
| 2007 | addBlock(VariableDIE, dwarf::DW_AT_location, 0, Block); |
| 2008 | } |
Devang Patel | 76a788c | 2011-01-06 21:39:25 +0000 | [diff] [blame] | 2009 | } else if (ConstantInt *CI = |
| 2010 | dyn_cast_or_null<ConstantInt>(GV.getConstant())) |
| 2011 | addConstantValue(VariableDIE, CI, isUnsignedDIType(GTy)); |
Devang Patel | e449d1f | 2011-01-20 00:02:16 +0000 | [diff] [blame] | 2012 | else if (const ConstantExpr *CE = getMergedGlobalExpr(N->getOperand(11))) { |
| 2013 | // GV is a merged global. |
| 2014 | DIEBlock *Block = new (DIEValueAllocator) DIEBlock(); |
| 2015 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_addr); |
| 2016 | addLabel(Block, 0, dwarf::DW_FORM_udata, |
| 2017 | Asm->Mang->getSymbol(cast<GlobalValue>(CE->getOperand(0)))); |
| 2018 | ConstantInt *CII = cast<ConstantInt>(CE->getOperand(2)); |
| 2019 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_constu); |
| 2020 | addUInt(Block, 0, dwarf::DW_FORM_udata, CII->getZExtValue()); |
| 2021 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_plus); |
| 2022 | addBlock(VariableDIE, dwarf::DW_AT_location, 0, Block); |
| 2023 | } |
Devang Patel | 76a788c | 2011-01-06 21:39:25 +0000 | [diff] [blame] | 2024 | |
Devang Patel | 13e16b6 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 2025 | return; |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2026 | } |
| 2027 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2028 | /// construct SubprogramDIE - Construct subprogram DIE. |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 2029 | void DwarfDebug::constructSubprogramDIE(const MDNode *N) { |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 2030 | DISubprogram SP(N); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2031 | |
Stuart Hastings | 639336e | 2010-04-06 21:38:29 +0000 | [diff] [blame] | 2032 | // Check for pre-existence. |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2033 | CompileUnit *TheCU = getCompileUnit(N); |
| 2034 | if (TheCU->getDIE(N)) |
Stuart Hastings | 639336e | 2010-04-06 21:38:29 +0000 | [diff] [blame] | 2035 | return; |
| 2036 | |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2037 | if (!SP.isDefinition()) |
| 2038 | // This is a method declaration which will be handled while constructing |
| 2039 | // class type. |
Devang Patel | 13e16b6 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 2040 | return; |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2041 | |
Stuart Hastings | 639336e | 2010-04-06 21:38:29 +0000 | [diff] [blame] | 2042 | DIE *SubprogramDie = createSubprogramDIE(SP); |
| 2043 | |
| 2044 | // Add to map. |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2045 | TheCU->insertDIE(N, SubprogramDie); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2046 | |
| 2047 | // Add to context owner. |
Devang Patel | 6404e4e | 2009-12-15 19:16:48 +0000 | [diff] [blame] | 2048 | addToContextOwner(SubprogramDie, SP.getContext()); |
Devang Patel | 0000fad | 2009-12-08 23:21:45 +0000 | [diff] [blame] | 2049 | |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2050 | // Expose as global. |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2051 | TheCU->addGlobal(SP.getName(), SubprogramDie); |
Devang Patel | 193f720 | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 2052 | |
Devang Patel | 13e16b6 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 2053 | return; |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2054 | } |
| 2055 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2056 | /// beginModule - Emit all Dwarf sections that should come prior to the |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 2057 | /// content. Create global DIEs and emit initial debug info sections. |
| 2058 | /// This is inovked by the target AsmPrinter. |
Chris Lattner | 75f5072 | 2010-04-04 07:48:20 +0000 | [diff] [blame] | 2059 | void DwarfDebug::beginModule(Module *M) { |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 2060 | if (DisableDebugInfoPrinting) |
| 2061 | return; |
| 2062 | |
Devang Patel | 78ab9e2 | 2009-07-30 18:56:46 +0000 | [diff] [blame] | 2063 | DebugInfoFinder DbgFinder; |
| 2064 | DbgFinder.processModule(*M); |
Devang Patel | 13e16b6 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 2065 | |
Chris Lattner | d850ac7 | 2010-04-05 02:19:28 +0000 | [diff] [blame] | 2066 | bool HasDebugInfo = false; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2067 | |
Chris Lattner | d850ac7 | 2010-04-05 02:19:28 +0000 | [diff] [blame] | 2068 | // Scan all the compile-units to see if there are any marked as the main unit. |
| 2069 | // if not, we do not generate debug info. |
| 2070 | for (DebugInfoFinder::iterator I = DbgFinder.compile_unit_begin(), |
| 2071 | E = DbgFinder.compile_unit_end(); I != E; ++I) { |
| 2072 | if (DICompileUnit(*I).isMain()) { |
| 2073 | HasDebugInfo = true; |
| 2074 | break; |
| 2075 | } |
| 2076 | } |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2077 | |
Chris Lattner | d850ac7 | 2010-04-05 02:19:28 +0000 | [diff] [blame] | 2078 | if (!HasDebugInfo) return; |
| 2079 | |
| 2080 | // Tell MMI that we have debug info. |
| 2081 | MMI->setDebugInfoAvailability(true); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2082 | |
Chris Lattner | be15beb | 2010-04-04 23:17:54 +0000 | [diff] [blame] | 2083 | // Emit initial sections. |
Chris Lattner | d850ac7 | 2010-04-05 02:19:28 +0000 | [diff] [blame] | 2084 | EmitSectionLabels(); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2085 | |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2086 | // Create all the compile unit DIEs. |
Devang Patel | 78ab9e2 | 2009-07-30 18:56:46 +0000 | [diff] [blame] | 2087 | for (DebugInfoFinder::iterator I = DbgFinder.compile_unit_begin(), |
| 2088 | E = DbgFinder.compile_unit_end(); I != E; ++I) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2089 | constructCompileUnit(*I); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2090 | |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 2091 | // Create DIEs for each subprogram. |
Devang Patel | 78ab9e2 | 2009-07-30 18:56:46 +0000 | [diff] [blame] | 2092 | for (DebugInfoFinder::iterator I = DbgFinder.subprogram_begin(), |
| 2093 | E = DbgFinder.subprogram_end(); I != E; ++I) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2094 | constructSubprogramDIE(*I); |
Devang Patel | 13e16b6 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 2095 | |
Devang Patel | c366f83 | 2009-12-10 19:14:49 +0000 | [diff] [blame] | 2096 | // Create DIEs for each global variable. |
| 2097 | for (DebugInfoFinder::iterator I = DbgFinder.global_variable_begin(), |
| 2098 | E = DbgFinder.global_variable_end(); I != E; ++I) |
| 2099 | constructGlobalVariableDIE(*I); |
| 2100 | |
Devang Patel | e7e5a0f | 2010-08-10 20:01:20 +0000 | [diff] [blame] | 2101 | //getOrCreateTypeDIE |
| 2102 | if (NamedMDNode *NMD = M->getNamedMetadata("llvm.dbg.enum")) |
| 2103 | for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) |
| 2104 | getOrCreateTypeDIE(DIType(NMD->getOperand(i))); |
| 2105 | |
Devang Patel | 1a7ca03 | 2010-09-28 18:08:20 +0000 | [diff] [blame] | 2106 | if (NamedMDNode *NMD = M->getNamedMetadata("llvm.dbg.ty")) |
| 2107 | for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) |
| 2108 | getOrCreateTypeDIE(DIType(NMD->getOperand(i))); |
| 2109 | |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2110 | // Prime section data. |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 2111 | SectionMap.insert(Asm->getObjFileLowering().getTextSection()); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2112 | } |
| 2113 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2114 | /// endModule - Emit all Dwarf sections that should come after the content. |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2115 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2116 | void DwarfDebug::endModule() { |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2117 | if (!FirstCU) return; |
Devang Patel | 4a1cad6 | 2010-06-28 18:25:03 +0000 | [diff] [blame] | 2118 | const Module *M = MMI->getModule(); |
Devang Patel | e9a1cca | 2010-08-02 17:32:15 +0000 | [diff] [blame] | 2119 | DenseMap<const MDNode *, DbgScope *> DeadFnScopeMap; |
Devang Patel | 4a1cad6 | 2010-06-28 18:25:03 +0000 | [diff] [blame] | 2120 | if (NamedMDNode *AllSPs = M->getNamedMetadata("llvm.dbg.sp")) { |
| 2121 | for (unsigned SI = 0, SE = AllSPs->getNumOperands(); SI != SE; ++SI) { |
| 2122 | if (ProcessedSPNodes.count(AllSPs->getOperand(SI)) != 0) continue; |
| 2123 | DISubprogram SP(AllSPs->getOperand(SI)); |
| 2124 | if (!SP.Verify()) continue; |
| 2125 | |
| 2126 | // Collect info for variables that were optimized out. |
Devang Patel | 8b3a6b6 | 2010-07-19 17:53:55 +0000 | [diff] [blame] | 2127 | if (!SP.isDefinition()) continue; |
Devang Patel | 4a1cad6 | 2010-06-28 18:25:03 +0000 | [diff] [blame] | 2128 | StringRef FName = SP.getLinkageName(); |
| 2129 | if (FName.empty()) |
| 2130 | FName = SP.getName(); |
Devang Patel | 6236704 | 2010-11-10 22:19:21 +0000 | [diff] [blame] | 2131 | NamedMDNode *NMD = getFnSpecificMDNode(*(MMI->getModule()), FName); |
Devang Patel | 4a1cad6 | 2010-06-28 18:25:03 +0000 | [diff] [blame] | 2132 | if (!NMD) continue; |
| 2133 | unsigned E = NMD->getNumOperands(); |
| 2134 | if (!E) continue; |
| 2135 | DbgScope *Scope = new DbgScope(NULL, DIDescriptor(SP), NULL); |
Devang Patel | e9a1cca | 2010-08-02 17:32:15 +0000 | [diff] [blame] | 2136 | DeadFnScopeMap[SP] = Scope; |
Devang Patel | 4a1cad6 | 2010-06-28 18:25:03 +0000 | [diff] [blame] | 2137 | for (unsigned I = 0; I != E; ++I) { |
| 2138 | DIVariable DV(NMD->getOperand(I)); |
| 2139 | if (!DV.Verify()) continue; |
| 2140 | Scope->addVariable(new DbgVariable(DV)); |
| 2141 | } |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2142 | |
Devang Patel | 4a1cad6 | 2010-06-28 18:25:03 +0000 | [diff] [blame] | 2143 | // Construct subprogram DIE and add variables DIEs. |
| 2144 | constructSubprogramDIE(SP); |
| 2145 | DIE *ScopeDIE = getCompileUnit(SP)->getDIE(SP); |
Devang Patel | e03161c | 2010-08-09 18:51:29 +0000 | [diff] [blame] | 2146 | const SmallVector<DbgVariable *, 8> &Variables = Scope->getDbgVariables(); |
Devang Patel | 4a1cad6 | 2010-06-28 18:25:03 +0000 | [diff] [blame] | 2147 | for (unsigned i = 0, N = Variables.size(); i < N; ++i) { |
| 2148 | DIE *VariableDIE = constructVariableDIE(Variables[i], Scope); |
| 2149 | if (VariableDIE) |
| 2150 | ScopeDIE->addChild(VariableDIE); |
| 2151 | } |
| 2152 | } |
| 2153 | } |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2154 | |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 2155 | // Attach DW_AT_inline attribute with inlined subprogram DIEs. |
| 2156 | for (SmallPtrSet<DIE *, 4>::iterator AI = InlinedSubprogramDIEs.begin(), |
| 2157 | AE = InlinedSubprogramDIEs.end(); AI != AE; ++AI) { |
| 2158 | DIE *ISP = *AI; |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2159 | addUInt(ISP, dwarf::DW_AT_inline, 0, dwarf::DW_INL_inlined); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 2160 | } |
| 2161 | |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 2162 | for (DenseMap<DIE *, const MDNode *>::iterator CI = ContainingTypeMap.begin(), |
Devang Patel | 5d11eb0 | 2009-12-03 19:11:07 +0000 | [diff] [blame] | 2163 | CE = ContainingTypeMap.end(); CI != CE; ++CI) { |
| 2164 | DIE *SPDie = CI->first; |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 2165 | const MDNode *N = dyn_cast_or_null<MDNode>(CI->second); |
Devang Patel | 5d11eb0 | 2009-12-03 19:11:07 +0000 | [diff] [blame] | 2166 | if (!N) continue; |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2167 | DIE *NDie = getCompileUnit(N)->getDIE(N); |
Devang Patel | 5d11eb0 | 2009-12-03 19:11:07 +0000 | [diff] [blame] | 2168 | if (!NDie) continue; |
| 2169 | addDIEEntry(SPDie, dwarf::DW_AT_containing_type, dwarf::DW_FORM_ref4, NDie); |
Devang Patel | 5d11eb0 | 2009-12-03 19:11:07 +0000 | [diff] [blame] | 2170 | } |
| 2171 | |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2172 | // Standard sections final addresses. |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 2173 | Asm->OutStreamer.SwitchSection(Asm->getObjFileLowering().getTextSection()); |
Chris Lattner | c021572 | 2010-04-04 19:25:43 +0000 | [diff] [blame] | 2174 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("text_end")); |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 2175 | Asm->OutStreamer.SwitchSection(Asm->getObjFileLowering().getDataSection()); |
Chris Lattner | c021572 | 2010-04-04 19:25:43 +0000 | [diff] [blame] | 2176 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("data_end")); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2177 | |
| 2178 | // End text sections. |
| 2179 | for (unsigned i = 1, N = SectionMap.size(); i <= N; ++i) { |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 2180 | Asm->OutStreamer.SwitchSection(SectionMap[i]); |
Chris Lattner | c021572 | 2010-04-04 19:25:43 +0000 | [diff] [blame] | 2181 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("section_end", i)); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2182 | } |
| 2183 | |
| 2184 | // Emit common frame information. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2185 | emitCommonDebugFrame(); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2186 | |
| 2187 | // Emit function debug frame information |
| 2188 | for (std::vector<FunctionDebugFrameInfo>::iterator I = DebugFrames.begin(), |
| 2189 | E = DebugFrames.end(); I != E; ++I) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2190 | emitFunctionDebugFrame(*I); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2191 | |
| 2192 | // Compute DIE offsets and sizes. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2193 | computeSizeAndOffsets(); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2194 | |
| 2195 | // Emit all the DIEs into a debug info section |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2196 | emitDebugInfo(); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2197 | |
| 2198 | // Corresponding abbreviations into a abbrev section. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2199 | emitAbbreviations(); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2200 | |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2201 | // Emit info into a debug pubnames section. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2202 | emitDebugPubNames(); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2203 | |
Devang Patel | 193f720 | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 2204 | // Emit info into a debug pubtypes section. |
| 2205 | emitDebugPubTypes(); |
| 2206 | |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2207 | // Emit info into a debug loc section. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2208 | emitDebugLoc(); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2209 | |
| 2210 | // Emit info into a debug aranges section. |
| 2211 | EmitDebugARanges(); |
| 2212 | |
| 2213 | // Emit info into a debug ranges section. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2214 | emitDebugRanges(); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2215 | |
| 2216 | // Emit info into a debug macinfo section. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2217 | emitDebugMacInfo(); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2218 | |
| 2219 | // Emit inline info. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2220 | emitDebugInlineInfo(); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2221 | |
Chris Lattner | bc733f5 | 2010-03-13 02:17:42 +0000 | [diff] [blame] | 2222 | // Emit info into a debug str section. |
| 2223 | emitDebugStr(); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2224 | |
Devang Patel | e9a1cca | 2010-08-02 17:32:15 +0000 | [diff] [blame] | 2225 | // clean up. |
| 2226 | DeleteContainerSeconds(DeadFnScopeMap); |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2227 | for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(), |
| 2228 | E = CUMap.end(); I != E; ++I) |
| 2229 | delete I->second; |
| 2230 | FirstCU = NULL; // Reset for the next Module, if any. |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2231 | } |
| 2232 | |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 2233 | /// findAbstractVariable - Find abstract variable, if any, associated with Var. |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2234 | DbgVariable *DwarfDebug::findAbstractVariable(DIVariable &Var, |
Chris Lattner | de4845c | 2010-04-02 19:42:39 +0000 | [diff] [blame] | 2235 | DebugLoc ScopeLoc) { |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 2236 | |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 2237 | DbgVariable *AbsDbgVariable = AbstractVariables.lookup(Var); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 2238 | if (AbsDbgVariable) |
| 2239 | return AbsDbgVariable; |
| 2240 | |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 2241 | LLVMContext &Ctx = Var->getContext(); |
Chris Lattner | de4845c | 2010-04-02 19:42:39 +0000 | [diff] [blame] | 2242 | DbgScope *Scope = AbstractScopes.lookup(ScopeLoc.getScope(Ctx)); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 2243 | if (!Scope) |
| 2244 | return NULL; |
| 2245 | |
Devang Patel | 26c1e56 | 2010-05-20 16:36:41 +0000 | [diff] [blame] | 2246 | AbsDbgVariable = new DbgVariable(Var); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2247 | Scope->addVariable(AbsDbgVariable); |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 2248 | AbstractVariables[Var] = AbsDbgVariable; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 2249 | return AbsDbgVariable; |
| 2250 | } |
| 2251 | |
Devang Patel | 0478c15 | 2011-03-01 22:58:55 +0000 | [diff] [blame] | 2252 | /// addCurrentFnArgument - If Var is an current function argument that add |
| 2253 | /// it in CurrentFnArguments list. |
| 2254 | bool DwarfDebug::addCurrentFnArgument(const MachineFunction *MF, |
| 2255 | DbgVariable *Var, DbgScope *Scope) { |
| 2256 | if (Scope != CurrentFnDbgScope) |
| 2257 | return false; |
| 2258 | DIVariable DV = Var->getVariable(); |
| 2259 | if (DV.getTag() != dwarf::DW_TAG_arg_variable) |
| 2260 | return false; |
| 2261 | unsigned ArgNo = DV.getArgNumber(); |
| 2262 | if (ArgNo == 0) |
| 2263 | return false; |
| 2264 | |
Devang Patel | cb3a657 | 2011-03-03 20:02:02 +0000 | [diff] [blame] | 2265 | size_t Size = CurrentFnArguments.size(); |
| 2266 | if (Size == 0) |
Devang Patel | 0478c15 | 2011-03-01 22:58:55 +0000 | [diff] [blame] | 2267 | CurrentFnArguments.resize(MF->getFunction()->arg_size()); |
Devang Patel | bbd0f45 | 2011-03-03 21:49:41 +0000 | [diff] [blame] | 2268 | // llvm::Function argument size is not good indicator of how many |
Devang Patel | 6f676be | 2011-03-03 20:08:10 +0000 | [diff] [blame] | 2269 | // arguments does the function have at source level. |
| 2270 | if (ArgNo > Size) |
Devang Patel | cb3a657 | 2011-03-03 20:02:02 +0000 | [diff] [blame] | 2271 | CurrentFnArguments.resize(ArgNo * 2); |
Devang Patel | 0478c15 | 2011-03-01 22:58:55 +0000 | [diff] [blame] | 2272 | CurrentFnArguments[ArgNo - 1] = Var; |
| 2273 | return true; |
| 2274 | } |
| 2275 | |
Devang Patel | ee43286 | 2010-05-20 19:57:06 +0000 | [diff] [blame] | 2276 | /// collectVariableInfoFromMMITable - Collect variable information from |
| 2277 | /// side table maintained by MMI. |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2278 | void |
Devang Patel | ee43286 | 2010-05-20 19:57:06 +0000 | [diff] [blame] | 2279 | DwarfDebug::collectVariableInfoFromMMITable(const MachineFunction * MF, |
| 2280 | SmallPtrSet<const MDNode *, 16> &Processed) { |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 2281 | const LLVMContext &Ctx = Asm->MF->getFunction()->getContext(); |
Devang Patel | e717faa | 2009-10-06 01:26:37 +0000 | [diff] [blame] | 2282 | MachineModuleInfo::VariableDbgInfoMapTy &VMap = MMI->getVariableDbgInfo(); |
| 2283 | for (MachineModuleInfo::VariableDbgInfoMapTy::iterator VI = VMap.begin(), |
| 2284 | VE = VMap.end(); VI != VE; ++VI) { |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 2285 | const MDNode *Var = VI->first; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 2286 | if (!Var) continue; |
Devang Patel | 98e1cac | 2010-05-14 21:01:35 +0000 | [diff] [blame] | 2287 | Processed.insert(Var); |
Chris Lattner | de4845c | 2010-04-02 19:42:39 +0000 | [diff] [blame] | 2288 | DIVariable DV(Var); |
| 2289 | const std::pair<unsigned, DebugLoc> &VP = VI->second; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 2290 | |
Chris Lattner | de4845c | 2010-04-02 19:42:39 +0000 | [diff] [blame] | 2291 | DbgScope *Scope = 0; |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 2292 | if (const MDNode *IA = VP.second.getInlinedAt(Ctx)) |
Chris Lattner | de4845c | 2010-04-02 19:42:39 +0000 | [diff] [blame] | 2293 | Scope = ConcreteScopes.lookup(IA); |
| 2294 | if (Scope == 0) |
| 2295 | Scope = DbgScopeMap.lookup(VP.second.getScope(Ctx)); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2296 | |
Devang Patel | fb0ee43 | 2009-11-10 23:20:04 +0000 | [diff] [blame] | 2297 | // If variable scope is not found then skip this variable. |
Chris Lattner | de4845c | 2010-04-02 19:42:39 +0000 | [diff] [blame] | 2298 | if (Scope == 0) |
Devang Patel | fb0ee43 | 2009-11-10 23:20:04 +0000 | [diff] [blame] | 2299 | continue; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 2300 | |
Devang Patel | 26c1e56 | 2010-05-20 16:36:41 +0000 | [diff] [blame] | 2301 | DbgVariable *AbsDbgVariable = findAbstractVariable(DV, VP.second); |
| 2302 | DbgVariable *RegVar = new DbgVariable(DV); |
| 2303 | recordVariableFrameIndex(RegVar, VP.first); |
Devang Patel | 0478c15 | 2011-03-01 22:58:55 +0000 | [diff] [blame] | 2304 | if (!addCurrentFnArgument(MF, RegVar, Scope)) |
| 2305 | Scope->addVariable(RegVar); |
Devang Patel | 26c1e56 | 2010-05-20 16:36:41 +0000 | [diff] [blame] | 2306 | if (AbsDbgVariable) { |
| 2307 | recordVariableFrameIndex(AbsDbgVariable, VP.first); |
| 2308 | VarToAbstractVarMap[RegVar] = AbsDbgVariable; |
| 2309 | } |
Devang Patel | e717faa | 2009-10-06 01:26:37 +0000 | [diff] [blame] | 2310 | } |
Devang Patel | ee43286 | 2010-05-20 19:57:06 +0000 | [diff] [blame] | 2311 | } |
Devang Patel | 90a48ad | 2010-03-15 18:33:46 +0000 | [diff] [blame] | 2312 | |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2313 | /// isDbgValueInDefinedReg - Return true if debug value, encoded by |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 2314 | /// DBG_VALUE instruction, is in a defined reg. |
| 2315 | static bool isDbgValueInDefinedReg(const MachineInstr *MI) { |
| 2316 | assert (MI->isDebugValue() && "Invalid DBG_VALUE machine instruction!"); |
Jakob Stoklund Olesen | 28cf115 | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 2317 | return MI->getNumOperands() == 3 && |
| 2318 | MI->getOperand(0).isReg() && MI->getOperand(0).getReg() && |
| 2319 | MI->getOperand(1).isImm() && MI->getOperand(1).getImm() == 0; |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 2320 | } |
| 2321 | |
Devang Patel | ee43286 | 2010-05-20 19:57:06 +0000 | [diff] [blame] | 2322 | /// collectVariableInfo - Populate DbgScope entries with variables' info. |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2323 | void |
Devang Patel | 78e127d | 2010-06-25 22:07:34 +0000 | [diff] [blame] | 2324 | DwarfDebug::collectVariableInfo(const MachineFunction *MF, |
| 2325 | SmallPtrSet<const MDNode *, 16> &Processed) { |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2326 | |
Devang Patel | ee43286 | 2010-05-20 19:57:06 +0000 | [diff] [blame] | 2327 | /// collection info from MMI table. |
| 2328 | collectVariableInfoFromMMITable(MF, Processed); |
| 2329 | |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 2330 | for (SmallVectorImpl<const MDNode*>::const_iterator |
| 2331 | UVI = UserVariables.begin(), UVE = UserVariables.end(); UVI != UVE; |
| 2332 | ++UVI) { |
| 2333 | const MDNode *Var = *UVI; |
| 2334 | if (Processed.count(Var)) |
Devang Patel | ee43286 | 2010-05-20 19:57:06 +0000 | [diff] [blame] | 2335 | continue; |
| 2336 | |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 2337 | // History contains relevant DBG_VALUE instructions for Var and instructions |
| 2338 | // clobbering it. |
| 2339 | SmallVectorImpl<const MachineInstr*> &History = DbgValues[Var]; |
| 2340 | if (History.empty()) |
| 2341 | continue; |
| 2342 | const MachineInstr *MInsn = History.front(); |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 2343 | |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 2344 | DIVariable DV(Var); |
Devang Patel | a36478f | 2011-01-11 21:42:10 +0000 | [diff] [blame] | 2345 | DbgScope *Scope = NULL; |
Devang Patel | d8720f4 | 2010-05-27 20:25:04 +0000 | [diff] [blame] | 2346 | if (DV.getTag() == dwarf::DW_TAG_arg_variable && |
| 2347 | DISubprogram(DV.getContext()).describes(MF->getFunction())) |
Devang Patel | c0c5a26 | 2010-05-21 00:10:20 +0000 | [diff] [blame] | 2348 | Scope = CurrentFnDbgScope; |
Devang Patel | a36478f | 2011-01-11 21:42:10 +0000 | [diff] [blame] | 2349 | else |
| 2350 | Scope = findDbgScope(MInsn); |
Devang Patel | ee43286 | 2010-05-20 19:57:06 +0000 | [diff] [blame] | 2351 | // If variable scope is not found then skip this variable. |
Devang Patel | c0c5a26 | 2010-05-21 00:10:20 +0000 | [diff] [blame] | 2352 | if (!Scope) |
Devang Patel | ee43286 | 2010-05-20 19:57:06 +0000 | [diff] [blame] | 2353 | continue; |
| 2354 | |
| 2355 | Processed.insert(DV); |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 2356 | assert(MInsn->isDebugValue() && "History must begin with debug value"); |
Devang Patel | ee43286 | 2010-05-20 19:57:06 +0000 | [diff] [blame] | 2357 | DbgVariable *RegVar = new DbgVariable(DV); |
Devang Patel | 0478c15 | 2011-03-01 22:58:55 +0000 | [diff] [blame] | 2358 | if (!addCurrentFnArgument(MF, RegVar, Scope)) |
| 2359 | Scope->addVariable(RegVar); |
Devang Patel | c0c5a26 | 2010-05-21 00:10:20 +0000 | [diff] [blame] | 2360 | if (DbgVariable *AbsVar = findAbstractVariable(DV, MInsn->getDebugLoc())) { |
| 2361 | DbgVariableToDbgInstMap[AbsVar] = MInsn; |
| 2362 | VarToAbstractVarMap[RegVar] = AbsVar; |
Devang Patel | 90a48ad | 2010-03-15 18:33:46 +0000 | [diff] [blame] | 2363 | } |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 2364 | |
| 2365 | // Simple ranges that are fully coalesced. |
| 2366 | if (History.size() <= 1 || (History.size() == 2 && |
| 2367 | MInsn->isIdenticalTo(History.back()))) { |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 2368 | DbgVariableToDbgInstMap[RegVar] = MInsn; |
| 2369 | continue; |
| 2370 | } |
| 2371 | |
| 2372 | // handle multiple DBG_VALUE instructions describing one variable. |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 2373 | RegVar->setDotDebugLocOffset(DotDebugLocEntries.size()); |
Jakob Stoklund Olesen | 28cf115 | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 2374 | |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 2375 | for (SmallVectorImpl<const MachineInstr*>::const_iterator |
| 2376 | HI = History.begin(), HE = History.end(); HI != HE; ++HI) { |
| 2377 | const MachineInstr *Begin = *HI; |
| 2378 | assert(Begin->isDebugValue() && "Invalid History entry"); |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 2379 | MachineLocation MLoc; |
Devang Patel | b2cf581 | 2010-08-04 18:40:52 +0000 | [diff] [blame] | 2380 | if (Begin->getNumOperands() == 3) { |
| 2381 | if (Begin->getOperand(0).isReg() && Begin->getOperand(1).isImm()) |
| 2382 | MLoc.set(Begin->getOperand(0).getReg(), Begin->getOperand(1).getImm()); |
| 2383 | } else |
| 2384 | MLoc = Asm->getDebugValueLocation(Begin); |
| 2385 | |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 2386 | // FIXME: emitDebugLoc only understands registers. |
Jakob Stoklund Olesen | 28cf115 | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 2387 | if (!MLoc.getReg()) |
| 2388 | continue; |
Jakob Stoklund Olesen | e17232e | 2011-03-22 00:21:41 +0000 | [diff] [blame] | 2389 | |
Jakob Stoklund Olesen | 28cf115 | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 2390 | // Compute the range for a register location. |
| 2391 | const MCSymbol *FLabel = getLabelBeforeInsn(Begin); |
| 2392 | const MCSymbol *SLabel = 0; |
| 2393 | |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 2394 | if (HI + 1 == HE) |
| 2395 | // If Begin is the last instruction in History then its value is valid |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 2396 | // until the end of the funtion. |
Jakob Stoklund Olesen | 28cf115 | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 2397 | SLabel = FunctionEndSym; |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 2398 | else { |
| 2399 | const MachineInstr *End = HI[1]; |
| 2400 | if (End->isDebugValue()) |
| 2401 | SLabel = getLabelBeforeInsn(End); |
| 2402 | else { |
| 2403 | // End is a normal instruction clobbering the range. |
| 2404 | SLabel = getLabelAfterInsn(End); |
| 2405 | assert(SLabel && "Forgot label after clobber instruction"); |
| 2406 | ++HI; |
| 2407 | } |
| 2408 | } |
Jakob Stoklund Olesen | 28cf115 | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 2409 | |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 2410 | // The value is valid until the next DBG_VALUE or clobber. |
Jakob Stoklund Olesen | 28cf115 | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 2411 | DotDebugLocEntries.push_back(DotDebugLocEntry(FLabel, SLabel, MLoc)); |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 2412 | } |
| 2413 | DotDebugLocEntries.push_back(DotDebugLocEntry()); |
Devang Patel | 90a48ad | 2010-03-15 18:33:46 +0000 | [diff] [blame] | 2414 | } |
Devang Patel | 98e1cac | 2010-05-14 21:01:35 +0000 | [diff] [blame] | 2415 | |
| 2416 | // Collect info for variables that were optimized out. |
Devang Patel | d1bbc6b | 2010-06-22 01:01:58 +0000 | [diff] [blame] | 2417 | const Function *F = MF->getFunction(); |
Devang Patel | 6236704 | 2010-11-10 22:19:21 +0000 | [diff] [blame] | 2418 | if (NamedMDNode *NMD = getFnSpecificMDNode(*(F->getParent()), F->getName())) { |
Devang Patel | 98e1cac | 2010-05-14 21:01:35 +0000 | [diff] [blame] | 2419 | for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) { |
Dan Gohman | 872814a | 2010-07-21 18:54:18 +0000 | [diff] [blame] | 2420 | DIVariable DV(cast<MDNode>(NMD->getOperand(i))); |
Devang Patel | ee43286 | 2010-05-20 19:57:06 +0000 | [diff] [blame] | 2421 | if (!DV || !Processed.insert(DV)) |
Devang Patel | 98e1cac | 2010-05-14 21:01:35 +0000 | [diff] [blame] | 2422 | continue; |
| 2423 | DbgScope *Scope = DbgScopeMap.lookup(DV.getContext()); |
| 2424 | if (Scope) |
Devang Patel | 26c1e56 | 2010-05-20 16:36:41 +0000 | [diff] [blame] | 2425 | Scope->addVariable(new DbgVariable(DV)); |
Devang Patel | 98e1cac | 2010-05-14 21:01:35 +0000 | [diff] [blame] | 2426 | } |
| 2427 | } |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 2428 | } |
Devang Patel | 98e1cac | 2010-05-14 21:01:35 +0000 | [diff] [blame] | 2429 | |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 2430 | /// getLabelBeforeInsn - Return Label preceding the instruction. |
| 2431 | const MCSymbol *DwarfDebug::getLabelBeforeInsn(const MachineInstr *MI) { |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 2432 | MCSymbol *Label = LabelsBeforeInsn.lookup(MI); |
| 2433 | assert(Label && "Didn't insert label before instruction"); |
| 2434 | return Label; |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 2435 | } |
| 2436 | |
| 2437 | /// getLabelAfterInsn - Return Label immediately following the instruction. |
| 2438 | const MCSymbol *DwarfDebug::getLabelAfterInsn(const MachineInstr *MI) { |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 2439 | return LabelsAfterInsn.lookup(MI); |
Devang Patel | e717faa | 2009-10-06 01:26:37 +0000 | [diff] [blame] | 2440 | } |
| 2441 | |
Devang Patel | cbbe287 | 2010-10-26 17:49:02 +0000 | [diff] [blame] | 2442 | /// beginInstruction - Process beginning of an instruction. |
| 2443 | void DwarfDebug::beginInstruction(const MachineInstr *MI) { |
Jakob Stoklund Olesen | 15a3ea0 | 2011-03-25 17:20:59 +0000 | [diff] [blame] | 2444 | // Check if source location changes, but ignore DBG_VALUE locations. |
| 2445 | if (!MI->isDebugValue()) { |
| 2446 | DebugLoc DL = MI->getDebugLoc(); |
| 2447 | if (DL != PrevInstLoc && (!DL.isUnknown() || UnknownLocations)) { |
| 2448 | PrevInstLoc = DL; |
| 2449 | if (!DL.isUnknown()) { |
| 2450 | const MDNode *Scope = DL.getScope(Asm->MF->getFunction()->getContext()); |
| 2451 | recordSourceLine(DL.getLine(), DL.getCol(), Scope); |
| 2452 | } else |
| 2453 | recordSourceLine(0, 0, 0); |
| 2454 | } |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 2455 | } |
Devang Patel | aead63c | 2010-03-29 22:59:58 +0000 | [diff] [blame] | 2456 | |
Jakob Stoklund Olesen | 15a3ea0 | 2011-03-25 17:20:59 +0000 | [diff] [blame] | 2457 | // Insert labels where requested. |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 2458 | DenseMap<const MachineInstr*, MCSymbol*>::iterator I = |
| 2459 | LabelsBeforeInsn.find(MI); |
| 2460 | |
| 2461 | // No label needed. |
| 2462 | if (I == LabelsBeforeInsn.end()) |
| 2463 | return; |
| 2464 | |
| 2465 | // Label already assigned. |
| 2466 | if (I->second) |
Devang Patel | b2b31a6 | 2010-05-26 19:37:24 +0000 | [diff] [blame] | 2467 | return; |
Devang Patel | 553881b | 2010-03-29 17:20:31 +0000 | [diff] [blame] | 2468 | |
Jakob Stoklund Olesen | 15a3ea0 | 2011-03-25 17:20:59 +0000 | [diff] [blame] | 2469 | if (!PrevLabel) { |
Devang Patel | 77051f5 | 2010-05-26 21:23:46 +0000 | [diff] [blame] | 2470 | PrevLabel = MMI->getContext().CreateTempSymbol(); |
| 2471 | Asm->OutStreamer.EmitLabel(PrevLabel); |
Devang Patel | b2b31a6 | 2010-05-26 19:37:24 +0000 | [diff] [blame] | 2472 | } |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 2473 | I->second = PrevLabel; |
Devang Patel | 0d20ac8 | 2009-10-06 01:50:42 +0000 | [diff] [blame] | 2474 | } |
| 2475 | |
Devang Patel | cbbe287 | 2010-10-26 17:49:02 +0000 | [diff] [blame] | 2476 | /// endInstruction - Process end of an instruction. |
| 2477 | void DwarfDebug::endInstruction(const MachineInstr *MI) { |
Jakob Stoklund Olesen | 15a3ea0 | 2011-03-25 17:20:59 +0000 | [diff] [blame] | 2478 | // Don't create a new label after DBG_VALUE instructions. |
| 2479 | // They don't generate code. |
| 2480 | if (!MI->isDebugValue()) |
| 2481 | PrevLabel = 0; |
| 2482 | |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 2483 | DenseMap<const MachineInstr*, MCSymbol*>::iterator I = |
| 2484 | LabelsAfterInsn.find(MI); |
| 2485 | |
| 2486 | // No label needed. |
| 2487 | if (I == LabelsAfterInsn.end()) |
| 2488 | return; |
| 2489 | |
| 2490 | // Label already assigned. |
| 2491 | if (I->second) |
Jakob Stoklund Olesen | 15a3ea0 | 2011-03-25 17:20:59 +0000 | [diff] [blame] | 2492 | return; |
| 2493 | |
| 2494 | // We need a label after this instruction. |
| 2495 | if (!PrevLabel) { |
| 2496 | PrevLabel = MMI->getContext().CreateTempSymbol(); |
| 2497 | Asm->OutStreamer.EmitLabel(PrevLabel); |
Devang Patel | 1c24635 | 2010-04-08 16:50:29 +0000 | [diff] [blame] | 2498 | } |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 2499 | I->second = PrevLabel; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 2500 | } |
| 2501 | |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 2502 | /// getOrCreateDbgScope - Create DbgScope for the scope. |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2503 | DbgScope *DwarfDebug::getOrCreateDbgScope(const MDNode *Scope, |
Devang Patel | 6140962 | 2010-07-07 20:12:52 +0000 | [diff] [blame] | 2504 | const MDNode *InlinedAt) { |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 2505 | if (!InlinedAt) { |
| 2506 | DbgScope *WScope = DbgScopeMap.lookup(Scope); |
| 2507 | if (WScope) |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 2508 | return WScope; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 2509 | WScope = new DbgScope(NULL, DIDescriptor(Scope), NULL); |
| 2510 | DbgScopeMap.insert(std::make_pair(Scope, WScope)); |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 2511 | if (DIDescriptor(Scope).isLexicalBlock()) { |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2512 | DbgScope *Parent = |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 2513 | getOrCreateDbgScope(DILexicalBlock(Scope).getContext(), NULL); |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 2514 | WScope->setParent(Parent); |
| 2515 | Parent->addScope(WScope); |
| 2516 | } |
| 2517 | |
| 2518 | if (!WScope->getParent()) { |
| 2519 | StringRef SPName = DISubprogram(Scope).getLinkageName(); |
Stuart Hastings | cad22ad | 2010-06-15 23:06:30 +0000 | [diff] [blame] | 2520 | // We used to check only for a linkage name, but that fails |
| 2521 | // since we began omitting the linkage name for private |
| 2522 | // functions. The new way is to check for the name in metadata, |
| 2523 | // but that's not supported in old .ll test cases. Ergo, we |
| 2524 | // check both. |
Stuart Hastings | 215aa15 | 2010-06-11 20:08:44 +0000 | [diff] [blame] | 2525 | if (SPName == Asm->MF->getFunction()->getName() || |
| 2526 | DISubprogram(Scope).getFunction() == Asm->MF->getFunction()) |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 2527 | CurrentFnDbgScope = WScope; |
| 2528 | } |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2529 | |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 2530 | return WScope; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 2531 | } |
| 2532 | |
Devang Patel | 78e127d | 2010-06-25 22:07:34 +0000 | [diff] [blame] | 2533 | getOrCreateAbstractScope(Scope); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 2534 | DbgScope *WScope = DbgScopeMap.lookup(InlinedAt); |
| 2535 | if (WScope) |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 2536 | return WScope; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 2537 | |
| 2538 | WScope = new DbgScope(NULL, DIDescriptor(Scope), InlinedAt); |
| 2539 | DbgScopeMap.insert(std::make_pair(InlinedAt, WScope)); |
| 2540 | DILocation DL(InlinedAt); |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 2541 | DbgScope *Parent = |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 2542 | getOrCreateDbgScope(DL.getScope(), DL.getOrigLocation()); |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 2543 | WScope->setParent(Parent); |
| 2544 | Parent->addScope(WScope); |
| 2545 | |
| 2546 | ConcreteScopes[InlinedAt] = WScope; |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 2547 | |
| 2548 | return WScope; |
Devang Patel | 0d20ac8 | 2009-10-06 01:50:42 +0000 | [diff] [blame] | 2549 | } |
| 2550 | |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 2551 | /// hasValidLocation - Return true if debug location entry attached with |
| 2552 | /// machine instruction encodes valid location info. |
| 2553 | static bool hasValidLocation(LLVMContext &Ctx, |
| 2554 | const MachineInstr *MInsn, |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 2555 | const MDNode *&Scope, const MDNode *&InlinedAt) { |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 2556 | DebugLoc DL = MInsn->getDebugLoc(); |
| 2557 | if (DL.isUnknown()) return false; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2558 | |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 2559 | const MDNode *S = DL.getScope(Ctx); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2560 | |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 2561 | // There is no need to create another DIE for compile unit. For all |
| 2562 | // other scopes, create one DbgScope now. This will be translated |
| 2563 | // into a scope DIE at the end. |
| 2564 | if (DIScope(S).isCompileUnit()) return false; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2565 | |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 2566 | Scope = S; |
| 2567 | InlinedAt = DL.getInlinedAt(Ctx); |
| 2568 | return true; |
| 2569 | } |
| 2570 | |
| 2571 | /// calculateDominanceGraph - Calculate dominance graph for DbgScope |
| 2572 | /// hierarchy. |
| 2573 | static void calculateDominanceGraph(DbgScope *Scope) { |
| 2574 | assert (Scope && "Unable to calculate scop edominance graph!"); |
| 2575 | SmallVector<DbgScope *, 4> WorkStack; |
| 2576 | WorkStack.push_back(Scope); |
| 2577 | unsigned Counter = 0; |
| 2578 | while (!WorkStack.empty()) { |
| 2579 | DbgScope *WS = WorkStack.back(); |
| 2580 | const SmallVector<DbgScope *, 4> &Children = WS->getScopes(); |
| 2581 | bool visitedChildren = false; |
| 2582 | for (SmallVector<DbgScope *, 4>::const_iterator SI = Children.begin(), |
| 2583 | SE = Children.end(); SI != SE; ++SI) { |
| 2584 | DbgScope *ChildScope = *SI; |
| 2585 | if (!ChildScope->getDFSOut()) { |
| 2586 | WorkStack.push_back(ChildScope); |
| 2587 | visitedChildren = true; |
| 2588 | ChildScope->setDFSIn(++Counter); |
| 2589 | break; |
| 2590 | } |
| 2591 | } |
| 2592 | if (!visitedChildren) { |
| 2593 | WorkStack.pop_back(); |
| 2594 | WS->setDFSOut(++Counter); |
| 2595 | } |
| 2596 | } |
| 2597 | } |
| 2598 | |
| 2599 | /// printDbgScopeInfo - Print DbgScope info for each machine instruction. |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2600 | static |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 2601 | void printDbgScopeInfo(LLVMContext &Ctx, const MachineFunction *MF, |
| 2602 | DenseMap<const MachineInstr *, DbgScope *> &MI2ScopeMap) |
| 2603 | { |
| 2604 | #ifndef NDEBUG |
| 2605 | unsigned PrevDFSIn = 0; |
| 2606 | for (MachineFunction::const_iterator I = MF->begin(), E = MF->end(); |
| 2607 | I != E; ++I) { |
| 2608 | for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end(); |
| 2609 | II != IE; ++II) { |
| 2610 | const MachineInstr *MInsn = II; |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 2611 | const MDNode *Scope = NULL; |
| 2612 | const MDNode *InlinedAt = NULL; |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 2613 | |
| 2614 | // Check if instruction has valid location information. |
| 2615 | if (hasValidLocation(Ctx, MInsn, Scope, InlinedAt)) { |
| 2616 | dbgs() << " [ "; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2617 | if (InlinedAt) |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 2618 | dbgs() << "*"; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2619 | DenseMap<const MachineInstr *, DbgScope *>::iterator DI = |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 2620 | MI2ScopeMap.find(MInsn); |
| 2621 | if (DI != MI2ScopeMap.end()) { |
| 2622 | DbgScope *S = DI->second; |
| 2623 | dbgs() << S->getDFSIn(); |
| 2624 | PrevDFSIn = S->getDFSIn(); |
| 2625 | } else |
| 2626 | dbgs() << PrevDFSIn; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2627 | } else |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 2628 | dbgs() << " [ x" << PrevDFSIn; |
| 2629 | dbgs() << " ]"; |
| 2630 | MInsn->dump(); |
| 2631 | } |
| 2632 | dbgs() << "\n"; |
| 2633 | } |
| 2634 | #endif |
| 2635 | } |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2636 | /// extractScopeInformation - Scan machine instructions in this function |
Chris Lattner | 14d750d | 2010-03-31 05:39:57 +0000 | [diff] [blame] | 2637 | /// and collect DbgScopes. Return true, if at least one scope was found. |
Chris Lattner | eec791a | 2010-01-26 23:18:02 +0000 | [diff] [blame] | 2638 | bool DwarfDebug::extractScopeInformation() { |
Devang Patel | af9e847 | 2009-10-01 20:31:14 +0000 | [diff] [blame] | 2639 | // If scope information was extracted using .dbg intrinsics then there is not |
| 2640 | // any need to extract these information by scanning each instruction. |
| 2641 | if (!DbgScopeMap.empty()) |
| 2642 | return false; |
| 2643 | |
Dan Gohman | 314bf7c | 2010-04-23 01:18:53 +0000 | [diff] [blame] | 2644 | // Scan each instruction and create scopes. First build working set of scopes. |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 2645 | LLVMContext &Ctx = Asm->MF->getFunction()->getContext(); |
| 2646 | SmallVector<DbgRange, 4> MIRanges; |
| 2647 | DenseMap<const MachineInstr *, DbgScope *> MI2ScopeMap; |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 2648 | const MDNode *PrevScope = NULL; |
| 2649 | const MDNode *PrevInlinedAt = NULL; |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 2650 | const MachineInstr *RangeBeginMI = NULL; |
| 2651 | const MachineInstr *PrevMI = NULL; |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 2652 | for (MachineFunction::const_iterator I = Asm->MF->begin(), E = Asm->MF->end(); |
Devang Patel | af9e847 | 2009-10-01 20:31:14 +0000 | [diff] [blame] | 2653 | I != E; ++I) { |
| 2654 | for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end(); |
| 2655 | II != IE; ++II) { |
| 2656 | const MachineInstr *MInsn = II; |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 2657 | const MDNode *Scope = NULL; |
| 2658 | const MDNode *InlinedAt = NULL; |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 2659 | |
| 2660 | // Check if instruction has valid location information. |
| 2661 | if (!hasValidLocation(Ctx, MInsn, Scope, InlinedAt)) { |
| 2662 | PrevMI = MInsn; |
| 2663 | continue; |
| 2664 | } |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2665 | |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 2666 | // If scope has not changed then skip this instruction. |
| 2667 | if (Scope == PrevScope && PrevInlinedAt == InlinedAt) { |
| 2668 | PrevMI = MInsn; |
| 2669 | continue; |
| 2670 | } |
| 2671 | |
Devang Patel | d3526ea | 2011-02-15 17:56:09 +0000 | [diff] [blame] | 2672 | // Ignore DBG_VALUE. It does not contribute any instruction in output. |
| 2673 | if (MInsn->isDebugValue()) |
| 2674 | continue; |
| 2675 | |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2676 | if (RangeBeginMI) { |
| 2677 | // If we have alread seen a beginning of a instruction range and |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 2678 | // current instruction scope does not match scope of first instruction |
| 2679 | // in this range then create a new instruction range. |
| 2680 | DbgRange R(RangeBeginMI, PrevMI); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2681 | MI2ScopeMap[RangeBeginMI] = getOrCreateDbgScope(PrevScope, |
Devang Patel | 6140962 | 2010-07-07 20:12:52 +0000 | [diff] [blame] | 2682 | PrevInlinedAt); |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 2683 | MIRanges.push_back(R); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2684 | } |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 2685 | |
| 2686 | // This is a beginning of a new instruction range. |
| 2687 | RangeBeginMI = MInsn; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2688 | |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 2689 | // Reset previous markers. |
| 2690 | PrevMI = MInsn; |
| 2691 | PrevScope = Scope; |
| 2692 | PrevInlinedAt = InlinedAt; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 2693 | } |
| 2694 | } |
| 2695 | |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 2696 | // Create last instruction range. |
| 2697 | if (RangeBeginMI && PrevMI && PrevScope) { |
| 2698 | DbgRange R(RangeBeginMI, PrevMI); |
| 2699 | MIRanges.push_back(R); |
| 2700 | MI2ScopeMap[RangeBeginMI] = getOrCreateDbgScope(PrevScope, PrevInlinedAt); |
Devang Patel | af9e847 | 2009-10-01 20:31:14 +0000 | [diff] [blame] | 2701 | } |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2702 | |
Devang Patel | 344130e | 2010-01-04 20:44:00 +0000 | [diff] [blame] | 2703 | if (!CurrentFnDbgScope) |
| 2704 | return false; |
| 2705 | |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 2706 | calculateDominanceGraph(CurrentFnDbgScope); |
| 2707 | if (PrintDbgScope) |
| 2708 | printDbgScopeInfo(Ctx, Asm->MF, MI2ScopeMap); |
| 2709 | |
| 2710 | // Find ranges of instructions covered by each DbgScope; |
| 2711 | DbgScope *PrevDbgScope = NULL; |
| 2712 | for (SmallVector<DbgRange, 4>::const_iterator RI = MIRanges.begin(), |
| 2713 | RE = MIRanges.end(); RI != RE; ++RI) { |
| 2714 | const DbgRange &R = *RI; |
| 2715 | DbgScope *S = MI2ScopeMap.lookup(R.first); |
| 2716 | assert (S && "Lost DbgScope for a machine instruction!"); |
| 2717 | if (PrevDbgScope && !PrevDbgScope->dominates(S)) |
| 2718 | PrevDbgScope->closeInsnRange(S); |
| 2719 | S->openInsnRange(R.first); |
| 2720 | S->extendInsnRange(R.second); |
| 2721 | PrevDbgScope = S; |
| 2722 | } |
| 2723 | |
| 2724 | if (PrevDbgScope) |
| 2725 | PrevDbgScope->closeInsnRange(); |
Devang Patel | af9e847 | 2009-10-01 20:31:14 +0000 | [diff] [blame] | 2726 | |
Devang Patel | e37b0c6 | 2010-04-08 18:43:56 +0000 | [diff] [blame] | 2727 | identifyScopeMarkers(); |
Devang Patel | 6122a4d | 2010-04-08 15:37:09 +0000 | [diff] [blame] | 2728 | |
| 2729 | return !DbgScopeMap.empty(); |
| 2730 | } |
| 2731 | |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2732 | /// identifyScopeMarkers() - |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 2733 | /// Each DbgScope has first instruction and last instruction to mark beginning |
| 2734 | /// and end of a scope respectively. Create an inverse map that list scopes |
| 2735 | /// starts (and ends) with an instruction. One instruction may start (or end) |
| 2736 | /// multiple scopes. Ignore scopes that are not reachable. |
Devang Patel | e37b0c6 | 2010-04-08 18:43:56 +0000 | [diff] [blame] | 2737 | void DwarfDebug::identifyScopeMarkers() { |
Devang Patel | 42aafd7 | 2010-01-20 02:05:23 +0000 | [diff] [blame] | 2738 | SmallVector<DbgScope *, 4> WorkList; |
| 2739 | WorkList.push_back(CurrentFnDbgScope); |
| 2740 | while (!WorkList.empty()) { |
Chris Lattner | 14d750d | 2010-03-31 05:39:57 +0000 | [diff] [blame] | 2741 | DbgScope *S = WorkList.pop_back_val(); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2742 | |
Jeffrey Yasskin | 5c213dc | 2010-03-12 17:45:06 +0000 | [diff] [blame] | 2743 | const SmallVector<DbgScope *, 4> &Children = S->getScopes(); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2744 | if (!Children.empty()) |
Jeffrey Yasskin | 5c213dc | 2010-03-12 17:45:06 +0000 | [diff] [blame] | 2745 | for (SmallVector<DbgScope *, 4>::const_iterator SI = Children.begin(), |
Devang Patel | 42aafd7 | 2010-01-20 02:05:23 +0000 | [diff] [blame] | 2746 | SE = Children.end(); SI != SE; ++SI) |
| 2747 | WorkList.push_back(*SI); |
| 2748 | |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 2749 | if (S->isAbstractScope()) |
| 2750 | continue; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2751 | |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 2752 | const SmallVector<DbgRange, 4> &Ranges = S->getRanges(); |
| 2753 | if (Ranges.empty()) |
| 2754 | continue; |
| 2755 | for (SmallVector<DbgRange, 4>::const_iterator RI = Ranges.begin(), |
| 2756 | RE = Ranges.end(); RI != RE; ++RI) { |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2757 | assert(RI->first && "DbgRange does not have first instruction!"); |
| 2758 | assert(RI->second && "DbgRange does not have second instruction!"); |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 2759 | requestLabelBeforeInsn(RI->first); |
| 2760 | requestLabelAfterInsn(RI->second); |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 2761 | } |
Devang Patel | af9e847 | 2009-10-01 20:31:14 +0000 | [diff] [blame] | 2762 | } |
Devang Patel | af9e847 | 2009-10-01 20:31:14 +0000 | [diff] [blame] | 2763 | } |
| 2764 | |
Dan Gohman | 084751c | 2010-04-20 00:37:27 +0000 | [diff] [blame] | 2765 | /// FindFirstDebugLoc - Find the first debug location in the function. This |
| 2766 | /// is intended to be an approximation for the source position of the |
| 2767 | /// beginning of the function. |
| 2768 | static DebugLoc FindFirstDebugLoc(const MachineFunction *MF) { |
| 2769 | for (MachineFunction::const_iterator I = MF->begin(), E = MF->end(); |
| 2770 | I != E; ++I) |
| 2771 | for (MachineBasicBlock::const_iterator MBBI = I->begin(), MBBE = I->end(); |
| 2772 | MBBI != MBBE; ++MBBI) { |
| 2773 | DebugLoc DL = MBBI->getDebugLoc(); |
| 2774 | if (!DL.isUnknown()) |
| 2775 | return DL; |
| 2776 | } |
| 2777 | return DebugLoc(); |
| 2778 | } |
| 2779 | |
Devang Patel | 9a31f0f | 2010-10-25 20:45:32 +0000 | [diff] [blame] | 2780 | #ifndef NDEBUG |
| 2781 | /// CheckLineNumbers - Count basicblocks whose instructions do not have any |
| 2782 | /// line number information. |
| 2783 | static void CheckLineNumbers(const MachineFunction *MF) { |
| 2784 | for (MachineFunction::const_iterator I = MF->begin(), E = MF->end(); |
| 2785 | I != E; ++I) { |
| 2786 | bool FoundLineNo = false; |
| 2787 | for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end(); |
| 2788 | II != IE; ++II) { |
| 2789 | const MachineInstr *MI = II; |
| 2790 | if (!MI->getDebugLoc().isUnknown()) { |
| 2791 | FoundLineNo = true; |
| 2792 | break; |
| 2793 | } |
| 2794 | } |
Devang Patel | 4d7f9a0 | 2010-10-28 22:11:59 +0000 | [diff] [blame] | 2795 | if (!FoundLineNo && I->size()) |
Devang Patel | 9a31f0f | 2010-10-25 20:45:32 +0000 | [diff] [blame] | 2796 | ++BlocksWithoutLineNo; |
| 2797 | } |
| 2798 | } |
| 2799 | #endif |
| 2800 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2801 | /// beginFunction - Gather pre-function debug information. Assumes being |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2802 | /// emitted immediately after the function entry point. |
Chris Lattner | eec791a | 2010-01-26 23:18:02 +0000 | [diff] [blame] | 2803 | void DwarfDebug::beginFunction(const MachineFunction *MF) { |
Chris Lattner | 994cb12 | 2010-04-05 03:52:55 +0000 | [diff] [blame] | 2804 | if (!MMI->hasDebugInfo()) return; |
Bill Wendling | 5f017e8 | 2010-04-07 09:28:04 +0000 | [diff] [blame] | 2805 | if (!extractScopeInformation()) return; |
Devang Patel | 60b35bd | 2009-10-06 18:37:31 +0000 | [diff] [blame] | 2806 | |
Devang Patel | 9a31f0f | 2010-10-25 20:45:32 +0000 | [diff] [blame] | 2807 | #ifndef NDEBUG |
| 2808 | CheckLineNumbers(MF); |
| 2809 | #endif |
| 2810 | |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 2811 | FunctionBeginSym = Asm->GetTempSymbol("func_begin", |
| 2812 | Asm->getFunctionNumber()); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2813 | // Assumes in correct section after the entry point. |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 2814 | Asm->OutStreamer.EmitLabel(FunctionBeginSym); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2815 | |
| 2816 | // Emit label for the implicitly defined dbg.stoppoint at the start of the |
| 2817 | // function. |
Dan Gohman | 084751c | 2010-04-20 00:37:27 +0000 | [diff] [blame] | 2818 | DebugLoc FDL = FindFirstDebugLoc(MF); |
Chris Lattner | de4845c | 2010-04-02 19:42:39 +0000 | [diff] [blame] | 2819 | if (FDL.isUnknown()) return; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2820 | |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 2821 | const MDNode *Scope = FDL.getScope(MF->getFunction()->getContext()); |
Stuart Hastings | 0db4271 | 2010-07-19 23:56:30 +0000 | [diff] [blame] | 2822 | const MDNode *TheScope = 0; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2823 | |
Chris Lattner | de4845c | 2010-04-02 19:42:39 +0000 | [diff] [blame] | 2824 | DISubprogram SP = getDISubprogram(Scope); |
| 2825 | unsigned Line, Col; |
| 2826 | if (SP.Verify()) { |
| 2827 | Line = SP.getLineNumber(); |
| 2828 | Col = 0; |
Stuart Hastings | 0db4271 | 2010-07-19 23:56:30 +0000 | [diff] [blame] | 2829 | TheScope = SP; |
Chris Lattner | de4845c | 2010-04-02 19:42:39 +0000 | [diff] [blame] | 2830 | } else { |
| 2831 | Line = FDL.getLine(); |
| 2832 | Col = FDL.getCol(); |
Stuart Hastings | 0db4271 | 2010-07-19 23:56:30 +0000 | [diff] [blame] | 2833 | TheScope = Scope; |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2834 | } |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2835 | |
Stuart Hastings | 0db4271 | 2010-07-19 23:56:30 +0000 | [diff] [blame] | 2836 | recordSourceLine(Line, Col, TheScope); |
Devang Patel | b2b31a6 | 2010-05-26 19:37:24 +0000 | [diff] [blame] | 2837 | |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 2838 | assert(UserVariables.empty() && DbgValues.empty() && "Maps weren't cleaned"); |
| 2839 | |
Devang Patel | b9abe9f | 2010-06-02 16:42:51 +0000 | [diff] [blame] | 2840 | /// ProcessedArgs - Collection of arguments already processed. |
| 2841 | SmallPtrSet<const MDNode *, 8> ProcessedArgs; |
| 2842 | |
Jakob Stoklund Olesen | 28cf115 | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 2843 | const TargetRegisterInfo *TRI = Asm->TM.getRegisterInfo(); |
| 2844 | |
| 2845 | /// LiveUserVar - Map physreg numbers to the MDNode they contain. |
| 2846 | std::vector<const MDNode*> LiveUserVar(TRI->getNumRegs()); |
| 2847 | |
Devang Patel | b2b31a6 | 2010-05-26 19:37:24 +0000 | [diff] [blame] | 2848 | for (MachineFunction::const_iterator I = MF->begin(), E = MF->end(); |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 2849 | I != E; ++I) { |
| 2850 | bool AtBlockEntry = true; |
Devang Patel | b2b31a6 | 2010-05-26 19:37:24 +0000 | [diff] [blame] | 2851 | for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end(); |
| 2852 | II != IE; ++II) { |
| 2853 | const MachineInstr *MI = II; |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 2854 | |
Devang Patel | b2b31a6 | 2010-05-26 19:37:24 +0000 | [diff] [blame] | 2855 | if (MI->isDebugValue()) { |
Devang Patel | b2b31a6 | 2010-05-26 19:37:24 +0000 | [diff] [blame] | 2856 | assert (MI->getNumOperands() > 1 && "Invalid machine instruction!"); |
Jakob Stoklund Olesen | 28cf115 | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 2857 | |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 2858 | // Keep track of user variables. |
Jakob Stoklund Olesen | 28cf115 | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 2859 | const MDNode *Var = |
| 2860 | MI->getOperand(MI->getNumOperands() - 1).getMetadata(); |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 2861 | |
| 2862 | // Variable is in a register, we need to check for clobbers. |
Jakob Stoklund Olesen | 28cf115 | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 2863 | if (isDbgValueInDefinedReg(MI)) |
| 2864 | LiveUserVar[MI->getOperand(0).getReg()] = Var; |
| 2865 | |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 2866 | // Check the history of this variable. |
| 2867 | SmallVectorImpl<const MachineInstr*> &History = DbgValues[Var]; |
| 2868 | if (History.empty()) { |
| 2869 | UserVariables.push_back(Var); |
| 2870 | // The first mention of a function argument gets the FunctionBeginSym |
| 2871 | // label, so arguments are visible when breaking at function entry. |
| 2872 | DIVariable DV(Var); |
| 2873 | if (DV.Verify() && DV.getTag() == dwarf::DW_TAG_arg_variable && |
| 2874 | DISubprogram(getDISubprogram(DV.getContext())) |
| 2875 | .describes(MF->getFunction())) |
| 2876 | LabelsBeforeInsn[MI] = FunctionBeginSym; |
| 2877 | } else { |
| 2878 | // We have seen this variable before. Try to coalesce DBG_VALUEs. |
| 2879 | const MachineInstr *Prev = History.back(); |
| 2880 | if (Prev->isDebugValue()) { |
| 2881 | // Coalesce identical entries at the end of History. |
| 2882 | if (History.size() >= 2 && |
| 2883 | Prev->isIdenticalTo(History[History.size() - 2])) |
| 2884 | History.pop_back(); |
| 2885 | |
| 2886 | // Terminate old register assignments that don't reach MI; |
| 2887 | MachineFunction::const_iterator PrevMBB = Prev->getParent(); |
| 2888 | if (PrevMBB != I && (!AtBlockEntry || llvm::next(PrevMBB) != I) && |
| 2889 | isDbgValueInDefinedReg(Prev)) { |
| 2890 | // Previous register assignment needs to terminate at the end of |
| 2891 | // its basic block. |
| 2892 | MachineBasicBlock::const_iterator LastMI = |
| 2893 | PrevMBB->getLastNonDebugInstr(); |
| 2894 | if (LastMI == PrevMBB->end()) |
| 2895 | // Drop DBG_VALUE for empty range. |
| 2896 | History.pop_back(); |
| 2897 | else { |
| 2898 | // Terminate after LastMI. |
| 2899 | History.push_back(LastMI); |
| 2900 | } |
| 2901 | } |
| 2902 | } |
| 2903 | } |
| 2904 | History.push_back(MI); |
Devang Patel | b2b31a6 | 2010-05-26 19:37:24 +0000 | [diff] [blame] | 2905 | } else { |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 2906 | // Not a DBG_VALUE instruction. |
| 2907 | if (!MI->isLabel()) |
| 2908 | AtBlockEntry = false; |
| 2909 | |
Jakob Stoklund Olesen | 28cf115 | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 2910 | // Check if the instruction clobbers any registers with debug vars. |
| 2911 | for (MachineInstr::const_mop_iterator MOI = MI->operands_begin(), |
| 2912 | MOE = MI->operands_end(); MOI != MOE; ++MOI) { |
| 2913 | if (!MOI->isReg() || !MOI->isDef() || !MOI->getReg()) |
| 2914 | continue; |
| 2915 | for (const unsigned *AI = TRI->getOverlaps(MOI->getReg()); |
| 2916 | unsigned Reg = *AI; ++AI) { |
| 2917 | const MDNode *Var = LiveUserVar[Reg]; |
| 2918 | if (!Var) |
| 2919 | continue; |
| 2920 | // Reg is now clobbered. |
| 2921 | LiveUserVar[Reg] = 0; |
| 2922 | |
| 2923 | // Was MD last defined by a DBG_VALUE referring to Reg? |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 2924 | DbgValueHistoryMap::iterator HistI = DbgValues.find(Var); |
| 2925 | if (HistI == DbgValues.end()) |
Jakob Stoklund Olesen | 28cf115 | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 2926 | continue; |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 2927 | SmallVectorImpl<const MachineInstr*> &History = HistI->second; |
| 2928 | if (History.empty()) |
Jakob Stoklund Olesen | 28cf115 | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 2929 | continue; |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 2930 | const MachineInstr *Prev = History.back(); |
| 2931 | // Sanity-check: Register assignments are terminated at the end of |
| 2932 | // their block. |
| 2933 | if (!Prev->isDebugValue() || Prev->getParent() != MI->getParent()) |
| 2934 | continue; |
| 2935 | // Is the variable still in Reg? |
| 2936 | if (!isDbgValueInDefinedReg(Prev) || |
| 2937 | Prev->getOperand(0).getReg() != Reg) |
| 2938 | continue; |
| 2939 | // Var is clobbered. Make sure the next instruction gets a label. |
| 2940 | History.push_back(MI); |
Jakob Stoklund Olesen | 28cf115 | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 2941 | } |
| 2942 | } |
Devang Patel | b2b31a6 | 2010-05-26 19:37:24 +0000 | [diff] [blame] | 2943 | } |
Devang Patel | b2b31a6 | 2010-05-26 19:37:24 +0000 | [diff] [blame] | 2944 | } |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 2945 | } |
| 2946 | |
| 2947 | for (DbgValueHistoryMap::iterator I = DbgValues.begin(), E = DbgValues.end(); |
| 2948 | I != E; ++I) { |
| 2949 | SmallVectorImpl<const MachineInstr*> &History = I->second; |
| 2950 | if (History.empty()) |
| 2951 | continue; |
| 2952 | |
| 2953 | // Make sure the final register assignments are terminated. |
| 2954 | const MachineInstr *Prev = History.back(); |
| 2955 | if (Prev->isDebugValue() && isDbgValueInDefinedReg(Prev)) { |
| 2956 | const MachineBasicBlock *PrevMBB = Prev->getParent(); |
| 2957 | MachineBasicBlock::const_iterator LastMI = PrevMBB->getLastNonDebugInstr(); |
| 2958 | if (LastMI == PrevMBB->end()) |
| 2959 | // Drop DBG_VALUE for empty range. |
| 2960 | History.pop_back(); |
| 2961 | else { |
| 2962 | // Terminate after LastMI. |
| 2963 | History.push_back(LastMI); |
| 2964 | } |
| 2965 | } |
| 2966 | // Request labels for the full history. |
| 2967 | for (unsigned i = 0, e = History.size(); i != e; ++i) { |
| 2968 | const MachineInstr *MI = History[i]; |
| 2969 | if (MI->isDebugValue()) |
| 2970 | requestLabelBeforeInsn(MI); |
| 2971 | else |
| 2972 | requestLabelAfterInsn(MI); |
| 2973 | } |
| 2974 | } |
Devang Patel | b2b31a6 | 2010-05-26 19:37:24 +0000 | [diff] [blame] | 2975 | |
Jakob Stoklund Olesen | 15a3ea0 | 2011-03-25 17:20:59 +0000 | [diff] [blame] | 2976 | PrevInstLoc = DebugLoc(); |
Devang Patel | b2b31a6 | 2010-05-26 19:37:24 +0000 | [diff] [blame] | 2977 | PrevLabel = FunctionBeginSym; |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2978 | } |
| 2979 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2980 | /// endFunction - Gather and emit post-function debug information. |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2981 | /// |
Chris Lattner | eec791a | 2010-01-26 23:18:02 +0000 | [diff] [blame] | 2982 | void DwarfDebug::endFunction(const MachineFunction *MF) { |
Bill Wendling | 5f017e8 | 2010-04-07 09:28:04 +0000 | [diff] [blame] | 2983 | if (!MMI->hasDebugInfo() || DbgScopeMap.empty()) return; |
Devang Patel | 70d75ca | 2009-11-12 19:02:56 +0000 | [diff] [blame] | 2984 | |
Devang Patel | 344130e | 2010-01-04 20:44:00 +0000 | [diff] [blame] | 2985 | if (CurrentFnDbgScope) { |
Devang Patel | 65eb482 | 2010-05-22 00:04:14 +0000 | [diff] [blame] | 2986 | |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 2987 | // Define end label for subprogram. |
| 2988 | FunctionEndSym = Asm->GetTempSymbol("func_end", |
| 2989 | Asm->getFunctionNumber()); |
| 2990 | // Assumes in correct section after the entry point. |
| 2991 | Asm->OutStreamer.EmitLabel(FunctionEndSym); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2992 | |
Devang Patel | 78e127d | 2010-06-25 22:07:34 +0000 | [diff] [blame] | 2993 | SmallPtrSet<const MDNode *, 16> ProcessedVars; |
| 2994 | collectVariableInfo(MF, ProcessedVars); |
Devang Patel | 65eb482 | 2010-05-22 00:04:14 +0000 | [diff] [blame] | 2995 | |
Devang Patel | 344130e | 2010-01-04 20:44:00 +0000 | [diff] [blame] | 2996 | // Construct abstract scopes. |
| 2997 | for (SmallVector<DbgScope *, 4>::iterator AI = AbstractScopesList.begin(), |
Devang Patel | 78e127d | 2010-06-25 22:07:34 +0000 | [diff] [blame] | 2998 | AE = AbstractScopesList.end(); AI != AE; ++AI) { |
Devang Patel | 78e127d | 2010-06-25 22:07:34 +0000 | [diff] [blame] | 2999 | DISubprogram SP((*AI)->getScopeNode()); |
| 3000 | if (SP.Verify()) { |
| 3001 | // Collect info for variables that were optimized out. |
| 3002 | StringRef FName = SP.getLinkageName(); |
| 3003 | if (FName.empty()) |
| 3004 | FName = SP.getName(); |
Devang Patel | 6236704 | 2010-11-10 22:19:21 +0000 | [diff] [blame] | 3005 | if (NamedMDNode *NMD = |
| 3006 | getFnSpecificMDNode(*(MF->getFunction()->getParent()), FName)) { |
Devang Patel | 78e127d | 2010-06-25 22:07:34 +0000 | [diff] [blame] | 3007 | for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) { |
Dan Gohman | 872814a | 2010-07-21 18:54:18 +0000 | [diff] [blame] | 3008 | DIVariable DV(cast<MDNode>(NMD->getOperand(i))); |
Devang Patel | 78e127d | 2010-06-25 22:07:34 +0000 | [diff] [blame] | 3009 | if (!DV || !ProcessedVars.insert(DV)) |
| 3010 | continue; |
Devang Patel | 1d68d21 | 2010-06-30 00:11:08 +0000 | [diff] [blame] | 3011 | DbgScope *Scope = AbstractScopes.lookup(DV.getContext()); |
Devang Patel | 78e127d | 2010-06-25 22:07:34 +0000 | [diff] [blame] | 3012 | if (Scope) |
| 3013 | Scope->addVariable(new DbgVariable(DV)); |
| 3014 | } |
| 3015 | } |
| 3016 | } |
Devang Patel | 90e19aa | 2010-06-30 01:40:11 +0000 | [diff] [blame] | 3017 | if (ProcessedSPNodes.count((*AI)->getScopeNode()) == 0) |
| 3018 | constructScopeDIE(*AI); |
Devang Patel | 78e127d | 2010-06-25 22:07:34 +0000 | [diff] [blame] | 3019 | } |
Devang Patel | 6140962 | 2010-07-07 20:12:52 +0000 | [diff] [blame] | 3020 | |
Devang Patel | 9c48837 | 2010-05-04 06:15:30 +0000 | [diff] [blame] | 3021 | DIE *CurFnDIE = constructScopeDIE(CurrentFnDbgScope); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3022 | |
Devang Patel | 9c48837 | 2010-05-04 06:15:30 +0000 | [diff] [blame] | 3023 | if (!DisableFramePointerElim(*MF)) |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3024 | addUInt(CurFnDIE, dwarf::DW_AT_APPLE_omit_frame_ptr, |
Devang Patel | 9c48837 | 2010-05-04 06:15:30 +0000 | [diff] [blame] | 3025 | dwarf::DW_FORM_flag, 1); |
| 3026 | |
| 3027 | |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 3028 | DebugFrames.push_back(FunctionDebugFrameInfo(Asm->getFunctionNumber(), |
Devang Patel | 344130e | 2010-01-04 20:44:00 +0000 | [diff] [blame] | 3029 | MMI->getFrameMoves())); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 3030 | } |
| 3031 | |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 3032 | // Clear debug info |
Devang Patel | f54b852 | 2010-01-19 01:26:02 +0000 | [diff] [blame] | 3033 | CurrentFnDbgScope = NULL; |
Devang Patel | 0478c15 | 2011-03-01 22:58:55 +0000 | [diff] [blame] | 3034 | CurrentFnArguments.clear(); |
Devang Patel | 26c1e56 | 2010-05-20 16:36:41 +0000 | [diff] [blame] | 3035 | DbgVariableToFrameIndexMap.clear(); |
| 3036 | VarToAbstractVarMap.clear(); |
| 3037 | DbgVariableToDbgInstMap.clear(); |
Jeffrey Yasskin | 5c213dc | 2010-03-12 17:45:06 +0000 | [diff] [blame] | 3038 | DeleteContainerSeconds(DbgScopeMap); |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 3039 | UserVariables.clear(); |
| 3040 | DbgValues.clear(); |
Devang Patel | f54b852 | 2010-01-19 01:26:02 +0000 | [diff] [blame] | 3041 | ConcreteScopes.clear(); |
Jeffrey Yasskin | 5c213dc | 2010-03-12 17:45:06 +0000 | [diff] [blame] | 3042 | DeleteContainerSeconds(AbstractScopes); |
Devang Patel | f54b852 | 2010-01-19 01:26:02 +0000 | [diff] [blame] | 3043 | AbstractScopesList.clear(); |
Jeffrey Yasskin | 5c213dc | 2010-03-12 17:45:06 +0000 | [diff] [blame] | 3044 | AbstractVariables.clear(); |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 3045 | LabelsBeforeInsn.clear(); |
| 3046 | LabelsAfterInsn.clear(); |
Devang Patel | f2548ca | 2010-04-16 23:33:45 +0000 | [diff] [blame] | 3047 | PrevLabel = NULL; |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 3048 | } |
| 3049 | |
Devang Patel | 26c1e56 | 2010-05-20 16:36:41 +0000 | [diff] [blame] | 3050 | /// recordVariableFrameIndex - Record a variable's index. |
| 3051 | void DwarfDebug::recordVariableFrameIndex(const DbgVariable *V, int Index) { |
| 3052 | assert (V && "Invalid DbgVariable!"); |
| 3053 | DbgVariableToFrameIndexMap[V] = Index; |
| 3054 | } |
| 3055 | |
| 3056 | /// findVariableFrameIndex - Return true if frame index for the variable |
| 3057 | /// is found. Update FI to hold value of the index. |
| 3058 | bool DwarfDebug::findVariableFrameIndex(const DbgVariable *V, int *FI) { |
| 3059 | assert (V && "Invalid DbgVariable!"); |
| 3060 | DenseMap<const DbgVariable *, int>::iterator I = |
| 3061 | DbgVariableToFrameIndexMap.find(V); |
| 3062 | if (I == DbgVariableToFrameIndexMap.end()) |
| 3063 | return false; |
| 3064 | *FI = I->second; |
| 3065 | return true; |
| 3066 | } |
| 3067 | |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3068 | /// findDbgScope - Find DbgScope for the debug loc attached with an |
Devang Patel | ee43286 | 2010-05-20 19:57:06 +0000 | [diff] [blame] | 3069 | /// instruction. |
| 3070 | DbgScope *DwarfDebug::findDbgScope(const MachineInstr *MInsn) { |
| 3071 | DbgScope *Scope = NULL; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3072 | LLVMContext &Ctx = |
Devang Patel | ee43286 | 2010-05-20 19:57:06 +0000 | [diff] [blame] | 3073 | MInsn->getParent()->getParent()->getFunction()->getContext(); |
| 3074 | DebugLoc DL = MInsn->getDebugLoc(); |
| 3075 | |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3076 | if (DL.isUnknown()) |
Devang Patel | ee43286 | 2010-05-20 19:57:06 +0000 | [diff] [blame] | 3077 | return Scope; |
| 3078 | |
| 3079 | if (const MDNode *IA = DL.getInlinedAt(Ctx)) |
| 3080 | Scope = ConcreteScopes.lookup(IA); |
| 3081 | if (Scope == 0) |
| 3082 | Scope = DbgScopeMap.lookup(DL.getScope(Ctx)); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3083 | |
Devang Patel | ee43286 | 2010-05-20 19:57:06 +0000 | [diff] [blame] | 3084 | return Scope; |
| 3085 | } |
| 3086 | |
| 3087 | |
Chris Lattner | c608784 | 2010-03-09 04:54:43 +0000 | [diff] [blame] | 3088 | /// recordSourceLine - Register a source line with debug info. Returns the |
| 3089 | /// unique label that was emitted and which provides correspondence to |
| 3090 | /// the source line list. |
Jakob Stoklund Olesen | 15a3ea0 | 2011-03-25 17:20:59 +0000 | [diff] [blame] | 3091 | void DwarfDebug::recordSourceLine(unsigned Line, unsigned Col, const MDNode *S){ |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 3092 | StringRef Fn; |
Devang Patel | 23670e5 | 2011-03-24 20:30:50 +0000 | [diff] [blame] | 3093 | StringRef Dir; |
Dan Gohman | 1cc0d62 | 2010-05-05 23:41:32 +0000 | [diff] [blame] | 3094 | unsigned Src = 1; |
| 3095 | if (S) { |
| 3096 | DIDescriptor Scope(S); |
Devang Patel | f84548d | 2009-10-05 18:03:19 +0000 | [diff] [blame] | 3097 | |
Dan Gohman | 1cc0d62 | 2010-05-05 23:41:32 +0000 | [diff] [blame] | 3098 | if (Scope.isCompileUnit()) { |
| 3099 | DICompileUnit CU(S); |
Dan Gohman | 1cc0d62 | 2010-05-05 23:41:32 +0000 | [diff] [blame] | 3100 | Fn = CU.getFilename(); |
Devang Patel | 23670e5 | 2011-03-24 20:30:50 +0000 | [diff] [blame] | 3101 | Dir = CU.getDirectory(); |
Devang Patel | 3cabc9d | 2010-10-28 17:30:52 +0000 | [diff] [blame] | 3102 | } else if (Scope.isFile()) { |
| 3103 | DIFile F(S); |
Devang Patel | 3cabc9d | 2010-10-28 17:30:52 +0000 | [diff] [blame] | 3104 | Fn = F.getFilename(); |
Devang Patel | 23670e5 | 2011-03-24 20:30:50 +0000 | [diff] [blame] | 3105 | Dir = F.getDirectory(); |
Dan Gohman | 1cc0d62 | 2010-05-05 23:41:32 +0000 | [diff] [blame] | 3106 | } else if (Scope.isSubprogram()) { |
| 3107 | DISubprogram SP(S); |
Dan Gohman | 1cc0d62 | 2010-05-05 23:41:32 +0000 | [diff] [blame] | 3108 | Fn = SP.getFilename(); |
Devang Patel | 23670e5 | 2011-03-24 20:30:50 +0000 | [diff] [blame] | 3109 | Dir = SP.getDirectory(); |
Dan Gohman | 1cc0d62 | 2010-05-05 23:41:32 +0000 | [diff] [blame] | 3110 | } else if (Scope.isLexicalBlock()) { |
| 3111 | DILexicalBlock DB(S); |
Dan Gohman | 1cc0d62 | 2010-05-05 23:41:32 +0000 | [diff] [blame] | 3112 | Fn = DB.getFilename(); |
Devang Patel | 23670e5 | 2011-03-24 20:30:50 +0000 | [diff] [blame] | 3113 | Dir = DB.getDirectory(); |
Dan Gohman | 1cc0d62 | 2010-05-05 23:41:32 +0000 | [diff] [blame] | 3114 | } else |
| 3115 | assert(0 && "Unexpected scope info"); |
| 3116 | |
Devang Patel | 23670e5 | 2011-03-24 20:30:50 +0000 | [diff] [blame] | 3117 | Src = GetOrCreateSourceID(Fn, Dir); |
Dan Gohman | 1cc0d62 | 2010-05-05 23:41:32 +0000 | [diff] [blame] | 3118 | } |
| 3119 | |
Rafael Espindola | 5c05563 | 2010-11-18 02:04:25 +0000 | [diff] [blame] | 3120 | Asm->OutStreamer.EmitDwarfLocDirective(Src, Line, Col, DWARF2_FLAG_IS_STMT, |
| 3121 | 0, 0); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 3122 | } |
| 3123 | |
Bill Wendling | 829e67b | 2009-05-20 23:22:40 +0000 | [diff] [blame] | 3124 | //===----------------------------------------------------------------------===// |
| 3125 | // Emit Methods |
| 3126 | //===----------------------------------------------------------------------===// |
| 3127 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 3128 | /// computeSizeAndOffset - Compute the size and offset of a DIE. |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3129 | /// |
Jim Grosbach | 7ab38df | 2009-11-22 19:20:36 +0000 | [diff] [blame] | 3130 | unsigned |
| 3131 | DwarfDebug::computeSizeAndOffset(DIE *Die, unsigned Offset, bool Last) { |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3132 | // Get the children. |
| 3133 | const std::vector<DIE *> &Children = Die->getChildren(); |
| 3134 | |
| 3135 | // If not last sibling and has children then add sibling offset attribute. |
Jeffrey Yasskin | 638fe8d | 2010-03-22 18:47:14 +0000 | [diff] [blame] | 3136 | if (!Last && !Children.empty()) |
Benjamin Kramer | 345ef34 | 2010-03-31 19:34:01 +0000 | [diff] [blame] | 3137 | Die->addSiblingOffset(DIEValueAllocator); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3138 | |
| 3139 | // Record the abbreviation. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 3140 | assignAbbrevNumber(Die->getAbbrev()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3141 | |
| 3142 | // Get the abbreviation for this DIE. |
| 3143 | unsigned AbbrevNumber = Die->getAbbrevNumber(); |
| 3144 | const DIEAbbrev *Abbrev = Abbreviations[AbbrevNumber - 1]; |
| 3145 | |
| 3146 | // Set DIE offset |
| 3147 | Die->setOffset(Offset); |
| 3148 | |
| 3149 | // Start the size with the size of abbreviation code. |
Chris Lattner | af76e59 | 2009-08-22 20:48:53 +0000 | [diff] [blame] | 3150 | Offset += MCAsmInfo::getULEB128Size(AbbrevNumber); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3151 | |
| 3152 | const SmallVector<DIEValue*, 32> &Values = Die->getValues(); |
| 3153 | const SmallVector<DIEAbbrevData, 8> &AbbrevData = Abbrev->getData(); |
| 3154 | |
| 3155 | // Size the DIE attribute values. |
| 3156 | for (unsigned i = 0, N = Values.size(); i < N; ++i) |
| 3157 | // Size attribute value. |
Chris Lattner | a37d538 | 2010-04-05 00:18:22 +0000 | [diff] [blame] | 3158 | Offset += Values[i]->SizeOf(Asm, AbbrevData[i].getForm()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3159 | |
| 3160 | // Size the DIE children if any. |
| 3161 | if (!Children.empty()) { |
| 3162 | assert(Abbrev->getChildrenFlag() == dwarf::DW_CHILDREN_yes && |
| 3163 | "Children flag not set"); |
| 3164 | |
| 3165 | for (unsigned j = 0, M = Children.size(); j < M; ++j) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 3166 | Offset = computeSizeAndOffset(Children[j], Offset, (j + 1) == M); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3167 | |
| 3168 | // End of children marker. |
| 3169 | Offset += sizeof(int8_t); |
| 3170 | } |
| 3171 | |
| 3172 | Die->setSize(Offset - Die->getOffset()); |
| 3173 | return Offset; |
| 3174 | } |
| 3175 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 3176 | /// computeSizeAndOffsets - Compute the size and offset of all the DIEs. |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3177 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 3178 | void DwarfDebug::computeSizeAndOffsets() { |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 3179 | unsigned PrevOffset = 0; |
| 3180 | for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(), |
| 3181 | E = CUMap.end(); I != E; ++I) { |
| 3182 | // Compute size of compile unit header. |
| 3183 | static unsigned Offset = PrevOffset + |
| 3184 | sizeof(int32_t) + // Length of Compilation Unit Info |
| 3185 | sizeof(int16_t) + // DWARF version number |
| 3186 | sizeof(int32_t) + // Offset Into Abbrev. Section |
| 3187 | sizeof(int8_t); // Pointer Size (in bytes) |
| 3188 | computeSizeAndOffset(I->second->getCUDie(), Offset, true); |
| 3189 | PrevOffset = Offset; |
| 3190 | } |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3191 | } |
| 3192 | |
Chris Lattner | 11b8f30 | 2010-04-04 23:02:02 +0000 | [diff] [blame] | 3193 | /// EmitSectionSym - Switch to the specified MCSection and emit an assembler |
| 3194 | /// temporary label to it if SymbolStem is specified. |
Chris Lattner | 9c69e28553 | 2010-04-04 22:59:04 +0000 | [diff] [blame] | 3195 | static MCSymbol *EmitSectionSym(AsmPrinter *Asm, const MCSection *Section, |
Chris Lattner | 11b8f30 | 2010-04-04 23:02:02 +0000 | [diff] [blame] | 3196 | const char *SymbolStem = 0) { |
Chris Lattner | 9c69e28553 | 2010-04-04 22:59:04 +0000 | [diff] [blame] | 3197 | Asm->OutStreamer.SwitchSection(Section); |
Chris Lattner | 11b8f30 | 2010-04-04 23:02:02 +0000 | [diff] [blame] | 3198 | if (!SymbolStem) return 0; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3199 | |
Chris Lattner | 9c69e28553 | 2010-04-04 22:59:04 +0000 | [diff] [blame] | 3200 | MCSymbol *TmpSym = Asm->GetTempSymbol(SymbolStem); |
| 3201 | Asm->OutStreamer.EmitLabel(TmpSym); |
| 3202 | return TmpSym; |
| 3203 | } |
| 3204 | |
| 3205 | /// EmitSectionLabels - Emit initial Dwarf sections with a label at |
| 3206 | /// the start of each one. |
Chris Lattner | fa070b0 | 2010-04-04 22:33:59 +0000 | [diff] [blame] | 3207 | void DwarfDebug::EmitSectionLabels() { |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 3208 | const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering(); |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 3209 | |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3210 | // Dwarf sections base addresses. |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 3211 | if (Asm->MAI->doesDwarfRequireFrameSection()) { |
Chris Lattner | 9c69e28553 | 2010-04-04 22:59:04 +0000 | [diff] [blame] | 3212 | DwarfFrameSectionSym = |
| 3213 | EmitSectionSym(Asm, TLOF.getDwarfFrameSection(), "section_debug_frame"); |
| 3214 | } |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3215 | |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3216 | DwarfInfoSectionSym = |
Chris Lattner | 9c69e28553 | 2010-04-04 22:59:04 +0000 | [diff] [blame] | 3217 | EmitSectionSym(Asm, TLOF.getDwarfInfoSection(), "section_info"); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3218 | DwarfAbbrevSectionSym = |
Chris Lattner | 9c69e28553 | 2010-04-04 22:59:04 +0000 | [diff] [blame] | 3219 | EmitSectionSym(Asm, TLOF.getDwarfAbbrevSection(), "section_abbrev"); |
Chris Lattner | 11b8f30 | 2010-04-04 23:02:02 +0000 | [diff] [blame] | 3220 | EmitSectionSym(Asm, TLOF.getDwarfARangesSection()); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3221 | |
Chris Lattner | 9c69e28553 | 2010-04-04 22:59:04 +0000 | [diff] [blame] | 3222 | if (const MCSection *MacroInfo = TLOF.getDwarfMacroInfoSection()) |
Chris Lattner | 11b8f30 | 2010-04-04 23:02:02 +0000 | [diff] [blame] | 3223 | EmitSectionSym(Asm, MacroInfo); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3224 | |
Devang Patel | af608bd | 2010-08-24 00:06:12 +0000 | [diff] [blame] | 3225 | EmitSectionSym(Asm, TLOF.getDwarfLineSection(), "section_line"); |
Chris Lattner | 11b8f30 | 2010-04-04 23:02:02 +0000 | [diff] [blame] | 3226 | EmitSectionSym(Asm, TLOF.getDwarfLocSection()); |
| 3227 | EmitSectionSym(Asm, TLOF.getDwarfPubNamesSection()); |
| 3228 | EmitSectionSym(Asm, TLOF.getDwarfPubTypesSection()); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3229 | DwarfStrSectionSym = |
Chris Lattner | 9c69e28553 | 2010-04-04 22:59:04 +0000 | [diff] [blame] | 3230 | EmitSectionSym(Asm, TLOF.getDwarfStrSection(), "section_str"); |
Devang Patel | f2548ca | 2010-04-16 23:33:45 +0000 | [diff] [blame] | 3231 | DwarfDebugRangeSectionSym = EmitSectionSym(Asm, TLOF.getDwarfRangesSection(), |
| 3232 | "debug_range"); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3233 | |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 3234 | DwarfDebugLocSectionSym = EmitSectionSym(Asm, TLOF.getDwarfLocSection(), |
| 3235 | "section_debug_loc"); |
| 3236 | |
Chris Lattner | 9c69e28553 | 2010-04-04 22:59:04 +0000 | [diff] [blame] | 3237 | TextSectionSym = EmitSectionSym(Asm, TLOF.getTextSection(), "text_begin"); |
Chris Lattner | 4ad1efe | 2010-04-04 23:10:38 +0000 | [diff] [blame] | 3238 | EmitSectionSym(Asm, TLOF.getDataSection()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3239 | } |
| 3240 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 3241 | /// emitDIE - Recusively Emits a debug information entry. |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3242 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 3243 | void DwarfDebug::emitDIE(DIE *Die) { |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3244 | // Get the abbreviation for this DIE. |
| 3245 | unsigned AbbrevNumber = Die->getAbbrevNumber(); |
| 3246 | const DIEAbbrev *Abbrev = Abbreviations[AbbrevNumber - 1]; |
| 3247 | |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3248 | // Emit the code (index) for the abbreviation. |
Chris Lattner | 3f53c83 | 2010-04-04 18:52:31 +0000 | [diff] [blame] | 3249 | if (Asm->isVerbose()) |
Chris Lattner | 894d75a | 2010-01-22 23:18:42 +0000 | [diff] [blame] | 3250 | Asm->OutStreamer.AddComment("Abbrev [" + Twine(AbbrevNumber) + "] 0x" + |
| 3251 | Twine::utohexstr(Die->getOffset()) + ":0x" + |
| 3252 | Twine::utohexstr(Die->getSize()) + " " + |
| 3253 | dwarf::TagString(Abbrev->getTag())); |
Chris Lattner | 7e1a8f8 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 3254 | Asm->EmitULEB128(AbbrevNumber); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3255 | |
Jeffrey Yasskin | 638fe8d | 2010-03-22 18:47:14 +0000 | [diff] [blame] | 3256 | const SmallVector<DIEValue*, 32> &Values = Die->getValues(); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3257 | const SmallVector<DIEAbbrevData, 8> &AbbrevData = Abbrev->getData(); |
| 3258 | |
| 3259 | // Emit the DIE attribute values. |
| 3260 | for (unsigned i = 0, N = Values.size(); i < N; ++i) { |
| 3261 | unsigned Attr = AbbrevData[i].getAttribute(); |
| 3262 | unsigned Form = AbbrevData[i].getForm(); |
| 3263 | assert(Form && "Too many attributes for DIE (check abbreviation)"); |
| 3264 | |
Chris Lattner | 3f53c83 | 2010-04-04 18:52:31 +0000 | [diff] [blame] | 3265 | if (Asm->isVerbose()) |
Chris Lattner | a801362 | 2010-01-24 18:54:17 +0000 | [diff] [blame] | 3266 | Asm->OutStreamer.AddComment(dwarf::AttributeString(Attr)); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3267 | |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3268 | switch (Attr) { |
| 3269 | case dwarf::DW_AT_sibling: |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 3270 | Asm->EmitInt32(Die->getSiblingOffset()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3271 | break; |
| 3272 | case dwarf::DW_AT_abstract_origin: { |
| 3273 | DIEEntry *E = cast<DIEEntry>(Values[i]); |
| 3274 | DIE *Origin = E->getEntry(); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 3275 | unsigned Addr = Origin->getOffset(); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3276 | Asm->EmitInt32(Addr); |
| 3277 | break; |
| 3278 | } |
Devang Patel | f2548ca | 2010-04-16 23:33:45 +0000 | [diff] [blame] | 3279 | case dwarf::DW_AT_ranges: { |
| 3280 | // DW_AT_range Value encodes offset in debug_range section. |
| 3281 | DIEInteger *V = cast<DIEInteger>(Values[i]); |
Devang Patel | b1fcfbe | 2010-09-02 16:43:44 +0000 | [diff] [blame] | 3282 | |
| 3283 | if (Asm->MAI->doesDwarfUsesLabelOffsetForRanges()) { |
| 3284 | Asm->EmitLabelPlusOffset(DwarfDebugRangeSectionSym, |
| 3285 | V->getValue(), |
| 3286 | 4); |
| 3287 | } else { |
| 3288 | Asm->EmitLabelOffsetDifference(DwarfDebugRangeSectionSym, |
| 3289 | V->getValue(), |
| 3290 | DwarfDebugRangeSectionSym, |
| 3291 | 4); |
| 3292 | } |
Devang Patel | f2548ca | 2010-04-16 23:33:45 +0000 | [diff] [blame] | 3293 | break; |
| 3294 | } |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 3295 | case dwarf::DW_AT_location: { |
| 3296 | if (UseDotDebugLocEntry.count(Die) != 0) { |
| 3297 | DIELabel *L = cast<DIELabel>(Values[i]); |
Daniel Dunbar | 83320a0 | 2011-03-16 22:16:39 +0000 | [diff] [blame] | 3298 | Asm->EmitLabelDifference(L->getValue(), DwarfDebugLocSectionSym, 4); |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 3299 | } else |
| 3300 | Values[i]->EmitValue(Asm, Form); |
| 3301 | break; |
| 3302 | } |
Devang Patel | 2a36160 | 2010-09-29 19:08:08 +0000 | [diff] [blame] | 3303 | case dwarf::DW_AT_accessibility: { |
| 3304 | if (Asm->isVerbose()) { |
| 3305 | DIEInteger *V = cast<DIEInteger>(Values[i]); |
| 3306 | Asm->OutStreamer.AddComment(dwarf::AccessibilityString(V->getValue())); |
| 3307 | } |
| 3308 | Values[i]->EmitValue(Asm, Form); |
| 3309 | break; |
| 3310 | } |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3311 | default: |
| 3312 | // Emit an attribute using the defined form. |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 3313 | Values[i]->EmitValue(Asm, Form); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3314 | break; |
| 3315 | } |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3316 | } |
| 3317 | |
| 3318 | // Emit the DIE children if any. |
| 3319 | if (Abbrev->getChildrenFlag() == dwarf::DW_CHILDREN_yes) { |
| 3320 | const std::vector<DIE *> &Children = Die->getChildren(); |
| 3321 | |
| 3322 | for (unsigned j = 0, M = Children.size(); j < M; ++j) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 3323 | emitDIE(Children[j]); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3324 | |
Chris Lattner | 3f53c83 | 2010-04-04 18:52:31 +0000 | [diff] [blame] | 3325 | if (Asm->isVerbose()) |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 3326 | Asm->OutStreamer.AddComment("End Of Children Mark"); |
| 3327 | Asm->EmitInt8(0); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3328 | } |
| 3329 | } |
| 3330 | |
Devang Patel | 8a24114 | 2009-12-09 18:24:21 +0000 | [diff] [blame] | 3331 | /// emitDebugInfo - Emit the debug info section. |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3332 | /// |
Devang Patel | 8a24114 | 2009-12-09 18:24:21 +0000 | [diff] [blame] | 3333 | void DwarfDebug::emitDebugInfo() { |
| 3334 | // Start debug info section. |
| 3335 | Asm->OutStreamer.SwitchSection( |
| 3336 | Asm->getObjFileLowering().getDwarfInfoSection()); |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 3337 | for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(), |
| 3338 | E = CUMap.end(); I != E; ++I) { |
| 3339 | CompileUnit *TheCU = I->second; |
| 3340 | DIE *Die = TheCU->getCUDie(); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3341 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 3342 | // Emit the compile units header. |
| 3343 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("info_begin", |
| 3344 | TheCU->getID())); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3345 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 3346 | // Emit size of content not including length itself |
| 3347 | unsigned ContentSize = Die->getSize() + |
| 3348 | sizeof(int16_t) + // DWARF version number |
| 3349 | sizeof(int32_t) + // Offset Into Abbrev. Section |
| 3350 | sizeof(int8_t) + // Pointer Size (in bytes) |
| 3351 | sizeof(int32_t); // FIXME - extra pad for gdb bug. |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3352 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 3353 | Asm->OutStreamer.AddComment("Length of Compilation Unit Info"); |
| 3354 | Asm->EmitInt32(ContentSize); |
| 3355 | Asm->OutStreamer.AddComment("DWARF version number"); |
| 3356 | Asm->EmitInt16(dwarf::DWARF_VERSION); |
| 3357 | Asm->OutStreamer.AddComment("Offset Into Abbrev. Section"); |
| 3358 | Asm->EmitSectionOffset(Asm->GetTempSymbol("abbrev_begin"), |
| 3359 | DwarfAbbrevSectionSym); |
| 3360 | Asm->OutStreamer.AddComment("Address Size (in bytes)"); |
| 3361 | Asm->EmitInt8(Asm->getTargetData().getPointerSize()); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3362 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 3363 | emitDIE(Die); |
| 3364 | // FIXME - extra padding for gdb bug. |
| 3365 | Asm->OutStreamer.AddComment("4 extra padding bytes for GDB"); |
| 3366 | Asm->EmitInt8(0); |
| 3367 | Asm->EmitInt8(0); |
| 3368 | Asm->EmitInt8(0); |
| 3369 | Asm->EmitInt8(0); |
| 3370 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("info_end", TheCU->getID())); |
| 3371 | } |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3372 | } |
| 3373 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 3374 | /// emitAbbreviations - Emit the abbreviation section. |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3375 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 3376 | void DwarfDebug::emitAbbreviations() const { |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3377 | // Check to see if it is worth the effort. |
| 3378 | if (!Abbreviations.empty()) { |
| 3379 | // Start the debug abbrev section. |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 3380 | Asm->OutStreamer.SwitchSection( |
| 3381 | Asm->getObjFileLowering().getDwarfAbbrevSection()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3382 | |
Chris Lattner | c021572 | 2010-04-04 19:25:43 +0000 | [diff] [blame] | 3383 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("abbrev_begin")); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3384 | |
| 3385 | // For each abbrevation. |
| 3386 | for (unsigned i = 0, N = Abbreviations.size(); i < N; ++i) { |
| 3387 | // Get abbreviation data |
| 3388 | const DIEAbbrev *Abbrev = Abbreviations[i]; |
| 3389 | |
| 3390 | // Emit the abbrevations code (base 1 index.) |
Chris Lattner | 7e1a8f8 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 3391 | Asm->EmitULEB128(Abbrev->getNumber(), "Abbreviation Code"); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3392 | |
| 3393 | // Emit the abbreviations data. |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 3394 | Abbrev->Emit(Asm); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3395 | } |
| 3396 | |
| 3397 | // Mark end of abbreviations. |
Chris Lattner | 7e1a8f8 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 3398 | Asm->EmitULEB128(0, "EOM(3)"); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3399 | |
Chris Lattner | c021572 | 2010-04-04 19:25:43 +0000 | [diff] [blame] | 3400 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("abbrev_end")); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3401 | } |
| 3402 | } |
| 3403 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 3404 | /// emitEndOfLineMatrix - Emit the last address of the section and the end of |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3405 | /// the line matrix. |
| 3406 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 3407 | void DwarfDebug::emitEndOfLineMatrix(unsigned SectionEnd) { |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3408 | // Define last address of section. |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 3409 | Asm->OutStreamer.AddComment("Extended Op"); |
| 3410 | Asm->EmitInt8(0); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3411 | |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 3412 | Asm->OutStreamer.AddComment("Op size"); |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 3413 | Asm->EmitInt8(Asm->getTargetData().getPointerSize() + 1); |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 3414 | Asm->OutStreamer.AddComment("DW_LNE_set_address"); |
| 3415 | Asm->EmitInt8(dwarf::DW_LNE_set_address); |
| 3416 | |
| 3417 | Asm->OutStreamer.AddComment("Section end label"); |
Chris Lattner | d85fc6e | 2010-03-10 01:17:49 +0000 | [diff] [blame] | 3418 | |
Chris Lattner | c021572 | 2010-04-04 19:25:43 +0000 | [diff] [blame] | 3419 | Asm->OutStreamer.EmitSymbolValue(Asm->GetTempSymbol("section_end",SectionEnd), |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 3420 | Asm->getTargetData().getPointerSize(), |
| 3421 | 0/*AddrSpace*/); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3422 | |
| 3423 | // Mark end of matrix. |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 3424 | Asm->OutStreamer.AddComment("DW_LNE_end_sequence"); |
| 3425 | Asm->EmitInt8(0); |
Chris Lattner | 0ad9c91 | 2010-01-22 22:09:00 +0000 | [diff] [blame] | 3426 | Asm->EmitInt8(1); |
Chris Lattner | 894d75a | 2010-01-22 23:18:42 +0000 | [diff] [blame] | 3427 | Asm->EmitInt8(1); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3428 | } |
| 3429 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 3430 | /// emitCommonDebugFrame - Emit common frame info into a debug frame section. |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3431 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 3432 | void DwarfDebug::emitCommonDebugFrame() { |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 3433 | if (!Asm->MAI->doesDwarfRequireFrameSection()) |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3434 | return; |
| 3435 | |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 3436 | int stackGrowth = Asm->getTargetData().getPointerSize(); |
Anton Korobeynikov | 16c29b5 | 2011-01-10 12:39:04 +0000 | [diff] [blame] | 3437 | if (Asm->TM.getFrameLowering()->getStackGrowthDirection() == |
| 3438 | TargetFrameLowering::StackGrowsDown) |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 3439 | stackGrowth *= -1; |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3440 | |
| 3441 | // Start the dwarf frame section. |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 3442 | Asm->OutStreamer.SwitchSection( |
| 3443 | Asm->getObjFileLowering().getDwarfFrameSection()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3444 | |
Chris Lattner | c021572 | 2010-04-04 19:25:43 +0000 | [diff] [blame] | 3445 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("debug_frame_common")); |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 3446 | Asm->OutStreamer.AddComment("Length of Common Information Entry"); |
Chris Lattner | a643718 | 2010-04-04 19:58:12 +0000 | [diff] [blame] | 3447 | Asm->EmitLabelDifference(Asm->GetTempSymbol("debug_frame_common_end"), |
| 3448 | Asm->GetTempSymbol("debug_frame_common_begin"), 4); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3449 | |
Chris Lattner | c021572 | 2010-04-04 19:25:43 +0000 | [diff] [blame] | 3450 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("debug_frame_common_begin")); |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 3451 | Asm->OutStreamer.AddComment("CIE Identifier Tag"); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3452 | Asm->EmitInt32((int)dwarf::DW_CIE_ID); |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 3453 | Asm->OutStreamer.AddComment("CIE Version"); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3454 | Asm->EmitInt8(dwarf::DW_CIE_VERSION); |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 3455 | Asm->OutStreamer.AddComment("CIE Augmentation"); |
Chris Lattner | 4cf202b | 2010-01-23 03:11:46 +0000 | [diff] [blame] | 3456 | Asm->OutStreamer.EmitIntValue(0, 1, /*addrspace*/0); // nul terminator. |
Chris Lattner | 7e1a8f8 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 3457 | Asm->EmitULEB128(1, "CIE Code Alignment Factor"); |
| 3458 | Asm->EmitSLEB128(stackGrowth, "CIE Data Alignment Factor"); |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 3459 | Asm->OutStreamer.AddComment("CIE RA Column"); |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 3460 | const TargetRegisterInfo *RI = Asm->TM.getRegisterInfo(); |
Anton Korobeynikov | 16c29b5 | 2011-01-10 12:39:04 +0000 | [diff] [blame] | 3461 | const TargetFrameLowering *TFI = Asm->TM.getFrameLowering(); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3462 | Asm->EmitInt8(RI->getDwarfRegNum(RI->getRARegister(), false)); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3463 | |
| 3464 | std::vector<MachineMove> Moves; |
Anton Korobeynikov | d9e3385 | 2010-11-18 23:25:52 +0000 | [diff] [blame] | 3465 | TFI->getInitialFrameState(Moves); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3466 | |
Chris Lattner | 02b86b9 | 2010-04-04 23:41:46 +0000 | [diff] [blame] | 3467 | Asm->EmitFrameMoves(Moves, 0, false); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3468 | |
Chris Lattner | 059ea13 | 2010-04-28 01:05:45 +0000 | [diff] [blame] | 3469 | Asm->EmitAlignment(2); |
Chris Lattner | c021572 | 2010-04-04 19:25:43 +0000 | [diff] [blame] | 3470 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("debug_frame_common_end")); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3471 | } |
| 3472 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 3473 | /// emitFunctionDebugFrame - Emit per function frame info into a debug frame |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3474 | /// section. |
Chris Lattner | 206d61e | 2010-03-13 07:26:18 +0000 | [diff] [blame] | 3475 | void DwarfDebug:: |
| 3476 | emitFunctionDebugFrame(const FunctionDebugFrameInfo &DebugFrameInfo) { |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 3477 | if (!Asm->MAI->doesDwarfRequireFrameSection()) |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3478 | return; |
| 3479 | |
| 3480 | // Start the dwarf frame section. |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 3481 | Asm->OutStreamer.SwitchSection( |
| 3482 | Asm->getObjFileLowering().getDwarfFrameSection()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3483 | |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 3484 | Asm->OutStreamer.AddComment("Length of Frame Information Entry"); |
Chris Lattner | 206d61e | 2010-03-13 07:26:18 +0000 | [diff] [blame] | 3485 | MCSymbol *DebugFrameBegin = |
Chris Lattner | c021572 | 2010-04-04 19:25:43 +0000 | [diff] [blame] | 3486 | Asm->GetTempSymbol("debug_frame_begin", DebugFrameInfo.Number); |
Chris Lattner | 206d61e | 2010-03-13 07:26:18 +0000 | [diff] [blame] | 3487 | MCSymbol *DebugFrameEnd = |
Chris Lattner | c021572 | 2010-04-04 19:25:43 +0000 | [diff] [blame] | 3488 | Asm->GetTempSymbol("debug_frame_end", DebugFrameInfo.Number); |
Chris Lattner | a643718 | 2010-04-04 19:58:12 +0000 | [diff] [blame] | 3489 | Asm->EmitLabelDifference(DebugFrameEnd, DebugFrameBegin, 4); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3490 | |
Chris Lattner | 206d61e | 2010-03-13 07:26:18 +0000 | [diff] [blame] | 3491 | Asm->OutStreamer.EmitLabel(DebugFrameBegin); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3492 | |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 3493 | Asm->OutStreamer.AddComment("FDE CIE offset"); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3494 | Asm->EmitSectionOffset(Asm->GetTempSymbol("debug_frame_common"), |
Chris Lattner | 6189ed1 | 2010-04-04 23:25:33 +0000 | [diff] [blame] | 3495 | DwarfFrameSectionSym); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3496 | |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 3497 | Asm->OutStreamer.AddComment("FDE initial location"); |
Chris Lattner | c021572 | 2010-04-04 19:25:43 +0000 | [diff] [blame] | 3498 | MCSymbol *FuncBeginSym = |
| 3499 | Asm->GetTempSymbol("func_begin", DebugFrameInfo.Number); |
Chris Lattner | fb65807 | 2010-03-13 07:40:56 +0000 | [diff] [blame] | 3500 | Asm->OutStreamer.EmitSymbolValue(FuncBeginSym, |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 3501 | Asm->getTargetData().getPointerSize(), |
| 3502 | 0/*AddrSpace*/); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3503 | |
| 3504 | |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 3505 | Asm->OutStreamer.AddComment("FDE address range"); |
Chris Lattner | a643718 | 2010-04-04 19:58:12 +0000 | [diff] [blame] | 3506 | Asm->EmitLabelDifference(Asm->GetTempSymbol("func_end",DebugFrameInfo.Number), |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 3507 | FuncBeginSym, Asm->getTargetData().getPointerSize()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3508 | |
Chris Lattner | 02b86b9 | 2010-04-04 23:41:46 +0000 | [diff] [blame] | 3509 | Asm->EmitFrameMoves(DebugFrameInfo.Moves, FuncBeginSym, false); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3510 | |
Chris Lattner | 059ea13 | 2010-04-28 01:05:45 +0000 | [diff] [blame] | 3511 | Asm->EmitAlignment(2); |
Chris Lattner | 206d61e | 2010-03-13 07:26:18 +0000 | [diff] [blame] | 3512 | Asm->OutStreamer.EmitLabel(DebugFrameEnd); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3513 | } |
| 3514 | |
Devang Patel | 8a24114 | 2009-12-09 18:24:21 +0000 | [diff] [blame] | 3515 | /// emitDebugPubNames - Emit visible names into a debug pubnames section. |
| 3516 | /// |
| 3517 | void DwarfDebug::emitDebugPubNames() { |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 3518 | for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(), |
| 3519 | E = CUMap.end(); I != E; ++I) { |
| 3520 | CompileUnit *TheCU = I->second; |
| 3521 | // Start the dwarf pubnames section. |
| 3522 | Asm->OutStreamer.SwitchSection( |
| 3523 | Asm->getObjFileLowering().getDwarfPubNamesSection()); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3524 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 3525 | Asm->OutStreamer.AddComment("Length of Public Names Info"); |
| 3526 | Asm->EmitLabelDifference( |
| 3527 | Asm->GetTempSymbol("pubnames_end", TheCU->getID()), |
| 3528 | Asm->GetTempSymbol("pubnames_begin", TheCU->getID()), 4); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3529 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 3530 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("pubnames_begin", |
| 3531 | TheCU->getID())); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3532 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 3533 | Asm->OutStreamer.AddComment("DWARF Version"); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3534 | Asm->EmitInt16(dwarf::DWARF_VERSION); |
| 3535 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 3536 | Asm->OutStreamer.AddComment("Offset of Compilation Unit Info"); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3537 | Asm->EmitSectionOffset(Asm->GetTempSymbol("info_begin", TheCU->getID()), |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 3538 | DwarfInfoSectionSym); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3539 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 3540 | Asm->OutStreamer.AddComment("Compilation Unit Length"); |
| 3541 | Asm->EmitLabelDifference(Asm->GetTempSymbol("info_end", TheCU->getID()), |
| 3542 | Asm->GetTempSymbol("info_begin", TheCU->getID()), |
| 3543 | 4); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3544 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 3545 | const StringMap<DIE*> &Globals = TheCU->getGlobals(); |
| 3546 | for (StringMap<DIE*>::const_iterator |
| 3547 | GI = Globals.begin(), GE = Globals.end(); GI != GE; ++GI) { |
| 3548 | const char *Name = GI->getKeyData(); |
| 3549 | DIE *Entity = GI->second; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3550 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 3551 | Asm->OutStreamer.AddComment("DIE offset"); |
| 3552 | Asm->EmitInt32(Entity->getOffset()); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3553 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 3554 | if (Asm->isVerbose()) |
| 3555 | Asm->OutStreamer.AddComment("External Name"); |
| 3556 | Asm->OutStreamer.EmitBytes(StringRef(Name, strlen(Name)+1), 0); |
| 3557 | } |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3558 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 3559 | Asm->OutStreamer.AddComment("End Mark"); |
| 3560 | Asm->EmitInt32(0); |
| 3561 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("pubnames_end", |
| 3562 | TheCU->getID())); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3563 | } |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3564 | } |
| 3565 | |
Devang Patel | 193f720 | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 3566 | void DwarfDebug::emitDebugPubTypes() { |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 3567 | for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(), |
| 3568 | E = CUMap.end(); I != E; ++I) { |
| 3569 | CompileUnit *TheCU = I->second; |
| 3570 | // Start the dwarf pubnames section. |
| 3571 | Asm->OutStreamer.SwitchSection( |
| 3572 | Asm->getObjFileLowering().getDwarfPubTypesSection()); |
| 3573 | Asm->OutStreamer.AddComment("Length of Public Types Info"); |
| 3574 | Asm->EmitLabelDifference( |
| 3575 | Asm->GetTempSymbol("pubtypes_end", TheCU->getID()), |
| 3576 | Asm->GetTempSymbol("pubtypes_begin", TheCU->getID()), 4); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3577 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 3578 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("pubtypes_begin", |
| 3579 | TheCU->getID())); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3580 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 3581 | if (Asm->isVerbose()) Asm->OutStreamer.AddComment("DWARF Version"); |
| 3582 | Asm->EmitInt16(dwarf::DWARF_VERSION); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3583 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 3584 | Asm->OutStreamer.AddComment("Offset of Compilation Unit Info"); |
| 3585 | Asm->EmitSectionOffset(Asm->GetTempSymbol("info_begin", TheCU->getID()), |
| 3586 | DwarfInfoSectionSym); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3587 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 3588 | Asm->OutStreamer.AddComment("Compilation Unit Length"); |
| 3589 | Asm->EmitLabelDifference(Asm->GetTempSymbol("info_end", TheCU->getID()), |
| 3590 | Asm->GetTempSymbol("info_begin", TheCU->getID()), |
| 3591 | 4); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3592 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 3593 | const StringMap<DIE*> &Globals = TheCU->getGlobalTypes(); |
| 3594 | for (StringMap<DIE*>::const_iterator |
| 3595 | GI = Globals.begin(), GE = Globals.end(); GI != GE; ++GI) { |
| 3596 | const char *Name = GI->getKeyData(); |
| 3597 | DIE * Entity = GI->second; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3598 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 3599 | if (Asm->isVerbose()) Asm->OutStreamer.AddComment("DIE offset"); |
| 3600 | Asm->EmitInt32(Entity->getOffset()); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3601 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 3602 | if (Asm->isVerbose()) Asm->OutStreamer.AddComment("External Name"); |
| 3603 | Asm->OutStreamer.EmitBytes(StringRef(Name, GI->getKeyLength()+1), 0); |
| 3604 | } |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3605 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 3606 | Asm->OutStreamer.AddComment("End Mark"); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3607 | Asm->EmitInt32(0); |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 3608 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("pubtypes_end", |
| 3609 | TheCU->getID())); |
Devang Patel | 193f720 | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 3610 | } |
Devang Patel | 193f720 | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 3611 | } |
| 3612 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 3613 | /// emitDebugStr - Emit visible names into a debug str section. |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3614 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 3615 | void DwarfDebug::emitDebugStr() { |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3616 | // Check to see if it is worth the effort. |
Chris Lattner | 0d9d70f | 2010-03-09 23:38:23 +0000 | [diff] [blame] | 3617 | if (StringPool.empty()) return; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3618 | |
Chris Lattner | 0d9d70f | 2010-03-09 23:38:23 +0000 | [diff] [blame] | 3619 | // Start the dwarf str section. |
| 3620 | Asm->OutStreamer.SwitchSection( |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 3621 | Asm->getObjFileLowering().getDwarfStrSection()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3622 | |
Chris Lattner | bc733f5 | 2010-03-13 02:17:42 +0000 | [diff] [blame] | 3623 | // Get all of the string pool entries and put them in an array by their ID so |
| 3624 | // we can sort them. |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3625 | SmallVector<std::pair<unsigned, |
Chris Lattner | bc733f5 | 2010-03-13 02:17:42 +0000 | [diff] [blame] | 3626 | StringMapEntry<std::pair<MCSymbol*, unsigned> >*>, 64> Entries; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3627 | |
Chris Lattner | bc733f5 | 2010-03-13 02:17:42 +0000 | [diff] [blame] | 3628 | for (StringMap<std::pair<MCSymbol*, unsigned> >::iterator |
| 3629 | I = StringPool.begin(), E = StringPool.end(); I != E; ++I) |
| 3630 | Entries.push_back(std::make_pair(I->second.second, &*I)); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3631 | |
Chris Lattner | bc733f5 | 2010-03-13 02:17:42 +0000 | [diff] [blame] | 3632 | array_pod_sort(Entries.begin(), Entries.end()); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3633 | |
Chris Lattner | bc733f5 | 2010-03-13 02:17:42 +0000 | [diff] [blame] | 3634 | for (unsigned i = 0, e = Entries.size(); i != e; ++i) { |
Chris Lattner | 0d9d70f | 2010-03-09 23:38:23 +0000 | [diff] [blame] | 3635 | // Emit a label for reference from debug information entries. |
Chris Lattner | bc733f5 | 2010-03-13 02:17:42 +0000 | [diff] [blame] | 3636 | Asm->OutStreamer.EmitLabel(Entries[i].second->getValue().first); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3637 | |
Chris Lattner | 0d9d70f | 2010-03-09 23:38:23 +0000 | [diff] [blame] | 3638 | // Emit the string itself. |
Chris Lattner | bc733f5 | 2010-03-13 02:17:42 +0000 | [diff] [blame] | 3639 | Asm->OutStreamer.EmitBytes(Entries[i].second->getKey(), 0/*addrspace*/); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3640 | } |
| 3641 | } |
| 3642 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 3643 | /// emitDebugLoc - Emit visible names into a debug loc section. |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3644 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 3645 | void DwarfDebug::emitDebugLoc() { |
Devang Patel | 8025068 | 2010-05-26 23:55:23 +0000 | [diff] [blame] | 3646 | if (DotDebugLocEntries.empty()) |
| 3647 | return; |
| 3648 | |
Devang Patel | 6c3ea90 | 2011-02-04 22:57:18 +0000 | [diff] [blame] | 3649 | for (SmallVector<DotDebugLocEntry, 4>::iterator |
| 3650 | I = DotDebugLocEntries.begin(), E = DotDebugLocEntries.end(); |
| 3651 | I != E; ++I) { |
| 3652 | DotDebugLocEntry &Entry = *I; |
| 3653 | if (I + 1 != DotDebugLocEntries.end()) |
| 3654 | Entry.Merge(I+1); |
| 3655 | } |
| 3656 | |
Daniel Dunbar | 83320a0 | 2011-03-16 22:16:39 +0000 | [diff] [blame] | 3657 | // Start the dwarf loc section. |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 3658 | Asm->OutStreamer.SwitchSection( |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 3659 | Asm->getObjFileLowering().getDwarfLocSection()); |
| 3660 | unsigned char Size = Asm->getTargetData().getPointerSize(); |
Devang Patel | 8025068 | 2010-05-26 23:55:23 +0000 | [diff] [blame] | 3661 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("debug_loc", 0)); |
| 3662 | unsigned index = 1; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3663 | for (SmallVector<DotDebugLocEntry, 4>::iterator |
| 3664 | I = DotDebugLocEntries.begin(), E = DotDebugLocEntries.end(); |
Devang Patel | 6140962 | 2010-07-07 20:12:52 +0000 | [diff] [blame] | 3665 | I != E; ++I, ++index) { |
Devang Patel | 6c3ea90 | 2011-02-04 22:57:18 +0000 | [diff] [blame] | 3666 | DotDebugLocEntry &Entry = *I; |
| 3667 | if (Entry.isMerged()) continue; |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 3668 | if (Entry.isEmpty()) { |
| 3669 | Asm->OutStreamer.EmitIntValue(0, Size, /*addrspace*/0); |
| 3670 | Asm->OutStreamer.EmitIntValue(0, Size, /*addrspace*/0); |
Devang Patel | 8025068 | 2010-05-26 23:55:23 +0000 | [diff] [blame] | 3671 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("debug_loc", index)); |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 3672 | } else { |
| 3673 | Asm->OutStreamer.EmitSymbolValue(Entry.Begin, Size, 0); |
| 3674 | Asm->OutStreamer.EmitSymbolValue(Entry.End, Size, 0); |
| 3675 | const TargetRegisterInfo *RI = Asm->TM.getRegisterInfo(); |
| 3676 | unsigned Reg = RI->getDwarfRegNum(Entry.Loc.getReg(), false); |
Devang Patel | b2cf581 | 2010-08-04 18:40:52 +0000 | [diff] [blame] | 3677 | if (int Offset = Entry.Loc.getOffset()) { |
| 3678 | // If the value is at a certain offset from frame register then |
| 3679 | // use DW_OP_fbreg. |
| 3680 | unsigned OffsetSize = Offset ? MCAsmInfo::getSLEB128Size(Offset) : 1; |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 3681 | Asm->OutStreamer.AddComment("Loc expr size"); |
Devang Patel | b2cf581 | 2010-08-04 18:40:52 +0000 | [diff] [blame] | 3682 | Asm->EmitInt16(1 + OffsetSize); |
| 3683 | Asm->OutStreamer.AddComment( |
| 3684 | dwarf::OperationEncodingString(dwarf::DW_OP_fbreg)); |
| 3685 | Asm->EmitInt8(dwarf::DW_OP_fbreg); |
| 3686 | Asm->OutStreamer.AddComment("Offset"); |
| 3687 | Asm->EmitSLEB128(Offset); |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 3688 | } else { |
Devang Patel | b2cf581 | 2010-08-04 18:40:52 +0000 | [diff] [blame] | 3689 | if (Reg < 32) { |
| 3690 | Asm->OutStreamer.AddComment("Loc expr size"); |
| 3691 | Asm->EmitInt16(1); |
| 3692 | Asm->OutStreamer.AddComment( |
Devang Patel | a54e0cc | 2010-08-04 20:32:36 +0000 | [diff] [blame] | 3693 | dwarf::OperationEncodingString(dwarf::DW_OP_reg0 + Reg)); |
Devang Patel | b2cf581 | 2010-08-04 18:40:52 +0000 | [diff] [blame] | 3694 | Asm->EmitInt8(dwarf::DW_OP_reg0 + Reg); |
| 3695 | } else { |
| 3696 | Asm->OutStreamer.AddComment("Loc expr size"); |
| 3697 | Asm->EmitInt16(1 + MCAsmInfo::getULEB128Size(Reg)); |
| 3698 | Asm->EmitInt8(dwarf::DW_OP_regx); |
| 3699 | Asm->EmitULEB128(Reg); |
| 3700 | } |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 3701 | } |
| 3702 | } |
| 3703 | } |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3704 | } |
| 3705 | |
| 3706 | /// EmitDebugARanges - Emit visible names into a debug aranges section. |
| 3707 | /// |
| 3708 | void DwarfDebug::EmitDebugARanges() { |
| 3709 | // Start the dwarf aranges section. |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 3710 | Asm->OutStreamer.SwitchSection( |
| 3711 | Asm->getObjFileLowering().getDwarfARangesSection()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3712 | } |
| 3713 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 3714 | /// emitDebugRanges - Emit visible names into a debug ranges section. |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3715 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 3716 | void DwarfDebug::emitDebugRanges() { |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3717 | // Start the dwarf ranges section. |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 3718 | Asm->OutStreamer.SwitchSection( |
Devang Patel | f2548ca | 2010-04-16 23:33:45 +0000 | [diff] [blame] | 3719 | Asm->getObjFileLowering().getDwarfRangesSection()); |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 3720 | unsigned char Size = Asm->getTargetData().getPointerSize(); |
| 3721 | for (SmallVector<const MCSymbol *, 8>::iterator |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3722 | I = DebugRangeSymbols.begin(), E = DebugRangeSymbols.end(); |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 3723 | I != E; ++I) { |
| 3724 | if (*I) |
| 3725 | Asm->OutStreamer.EmitSymbolValue(const_cast<MCSymbol*>(*I), Size, 0); |
Devang Patel | f2548ca | 2010-04-16 23:33:45 +0000 | [diff] [blame] | 3726 | else |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 3727 | Asm->OutStreamer.EmitIntValue(0, Size, /*addrspace*/0); |
Devang Patel | f2548ca | 2010-04-16 23:33:45 +0000 | [diff] [blame] | 3728 | } |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3729 | } |
| 3730 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 3731 | /// emitDebugMacInfo - Emit visible names into a debug macinfo section. |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3732 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 3733 | void DwarfDebug::emitDebugMacInfo() { |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 3734 | if (const MCSection *LineInfo = |
Chris Lattner | 18a4c16 | 2009-08-02 07:24:22 +0000 | [diff] [blame] | 3735 | Asm->getObjFileLowering().getDwarfMacroInfoSection()) { |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3736 | // Start the dwarf macinfo section. |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 3737 | Asm->OutStreamer.SwitchSection(LineInfo); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3738 | } |
| 3739 | } |
| 3740 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 3741 | /// emitDebugInlineInfo - Emit inline info using following format. |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3742 | /// Section Header: |
| 3743 | /// 1. length of section |
| 3744 | /// 2. Dwarf version number |
| 3745 | /// 3. address size. |
| 3746 | /// |
| 3747 | /// Entries (one "entry" for each function that was inlined): |
| 3748 | /// |
| 3749 | /// 1. offset into __debug_str section for MIPS linkage name, if exists; |
| 3750 | /// otherwise offset into __debug_str for regular function name. |
| 3751 | /// 2. offset into __debug_str section for regular function name. |
| 3752 | /// 3. an unsigned LEB128 number indicating the number of distinct inlining |
| 3753 | /// instances for the function. |
| 3754 | /// |
| 3755 | /// The rest of the entry consists of a {die_offset, low_pc} pair for each |
| 3756 | /// inlined instance; the die_offset points to the inlined_subroutine die in the |
| 3757 | /// __debug_info section, and the low_pc is the starting address for the |
| 3758 | /// inlining instance. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 3759 | void DwarfDebug::emitDebugInlineInfo() { |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 3760 | if (!Asm->MAI->doesDwarfUsesInlineInfoSection()) |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3761 | return; |
| 3762 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 3763 | if (!FirstCU) |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3764 | return; |
| 3765 | |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 3766 | Asm->OutStreamer.SwitchSection( |
| 3767 | Asm->getObjFileLowering().getDwarfDebugInlineSection()); |
Chris Lattner | 0ad9c91 | 2010-01-22 22:09:00 +0000 | [diff] [blame] | 3768 | |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 3769 | Asm->OutStreamer.AddComment("Length of Debug Inlined Information Entry"); |
Chris Lattner | a643718 | 2010-04-04 19:58:12 +0000 | [diff] [blame] | 3770 | Asm->EmitLabelDifference(Asm->GetTempSymbol("debug_inlined_end", 1), |
| 3771 | Asm->GetTempSymbol("debug_inlined_begin", 1), 4); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3772 | |
Chris Lattner | c021572 | 2010-04-04 19:25:43 +0000 | [diff] [blame] | 3773 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("debug_inlined_begin", 1)); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3774 | |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 3775 | Asm->OutStreamer.AddComment("Dwarf Version"); |
| 3776 | Asm->EmitInt16(dwarf::DWARF_VERSION); |
| 3777 | Asm->OutStreamer.AddComment("Address Size (in bytes)"); |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 3778 | Asm->EmitInt8(Asm->getTargetData().getPointerSize()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3779 | |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 3780 | for (SmallVector<const MDNode *, 4>::iterator I = InlinedSPNodes.begin(), |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 3781 | E = InlinedSPNodes.end(); I != E; ++I) { |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 3782 | |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 3783 | const MDNode *Node = *I; |
| 3784 | DenseMap<const MDNode *, SmallVector<InlineInfoLabels, 4> >::iterator II |
Jim Grosbach | 7ab38df | 2009-11-22 19:20:36 +0000 | [diff] [blame] | 3785 | = InlineInfo.find(Node); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 3786 | SmallVector<InlineInfoLabels, 4> &Labels = II->second; |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 3787 | DISubprogram SP(Node); |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 3788 | StringRef LName = SP.getLinkageName(); |
| 3789 | StringRef Name = SP.getName(); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3790 | |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 3791 | Asm->OutStreamer.AddComment("MIPS linkage name"); |
Chris Lattner | 4cf202b | 2010-01-23 03:11:46 +0000 | [diff] [blame] | 3792 | if (LName.empty()) { |
| 3793 | Asm->OutStreamer.EmitBytes(Name, 0); |
| 3794 | Asm->OutStreamer.EmitIntValue(0, 1, 0); // nul terminator. |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 3795 | } else |
Chris Lattner | 6189ed1 | 2010-04-04 23:25:33 +0000 | [diff] [blame] | 3796 | Asm->EmitSectionOffset(getStringPoolEntry(getRealLinkageName(LName)), |
| 3797 | DwarfStrSectionSym); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 3798 | |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 3799 | Asm->OutStreamer.AddComment("Function name"); |
Chris Lattner | 6189ed1 | 2010-04-04 23:25:33 +0000 | [diff] [blame] | 3800 | Asm->EmitSectionOffset(getStringPoolEntry(Name), DwarfStrSectionSym); |
Chris Lattner | 7e1a8f8 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 3801 | Asm->EmitULEB128(Labels.size(), "Inline count"); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3802 | |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 3803 | for (SmallVector<InlineInfoLabels, 4>::iterator LI = Labels.begin(), |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3804 | LE = Labels.end(); LI != LE; ++LI) { |
Chris Lattner | 3f53c83 | 2010-04-04 18:52:31 +0000 | [diff] [blame] | 3805 | if (Asm->isVerbose()) Asm->OutStreamer.AddComment("DIE offset"); |
Chris Lattner | 6ed0f90 | 2010-03-09 00:31:02 +0000 | [diff] [blame] | 3806 | Asm->EmitInt32(LI->second->getOffset()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3807 | |
Chris Lattner | 3f53c83 | 2010-04-04 18:52:31 +0000 | [diff] [blame] | 3808 | if (Asm->isVerbose()) Asm->OutStreamer.AddComment("low_pc"); |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 3809 | Asm->OutStreamer.EmitSymbolValue(LI->first, |
| 3810 | Asm->getTargetData().getPointerSize(),0); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3811 | } |
| 3812 | } |
| 3813 | |
Chris Lattner | c021572 | 2010-04-04 19:25:43 +0000 | [diff] [blame] | 3814 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("debug_inlined_end", 1)); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 3815 | } |