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, |
Chris Lattner | 7a2bdde | 2011-04-15 05:18:47 +0000 | [diff] [blame] | 56 | cl::desc("Make an absence of debug location information explicit."), |
Dan Gohman | 281d65d | 2010-05-07 01:08:53 +0000 | [diff] [blame] | 57 | cl::init(false)); |
| 58 | |
Bill Wendling | 5f017e8 | 2010-04-07 09:28:04 +0000 | [diff] [blame] | 59 | namespace { |
| 60 | const char *DWARFGroupName = "DWARF Emission"; |
| 61 | const char *DbgTimerName = "DWARF Debug Writer"; |
| 62 | } // end anonymous namespace |
| 63 | |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 64 | //===----------------------------------------------------------------------===// |
| 65 | |
| 66 | /// Configuration values for initial hash set sizes (log2). |
| 67 | /// |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 68 | static const unsigned InitAbbreviationsSetSize = 9; // log2(512) |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 69 | |
| 70 | namespace llvm { |
| 71 | |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 72 | DIType DbgVariable::getType() const { |
| 73 | DIType Ty = Var.getType(); |
| 74 | // FIXME: isBlockByrefVariable should be reformulated in terms of complex |
| 75 | // addresses instead. |
| 76 | if (Var.isBlockByrefVariable()) { |
| 77 | /* Byref variables, in Blocks, are declared by the programmer as |
| 78 | "SomeType VarName;", but the compiler creates a |
| 79 | __Block_byref_x_VarName struct, and gives the variable VarName |
| 80 | either the struct, or a pointer to the struct, as its type. This |
| 81 | is necessary for various behind-the-scenes things the compiler |
| 82 | needs to do with by-reference variables in blocks. |
| 83 | |
| 84 | However, as far as the original *programmer* is concerned, the |
| 85 | variable should still have type 'SomeType', as originally declared. |
| 86 | |
| 87 | The following function dives into the __Block_byref_x_VarName |
| 88 | struct to find the original type of the variable. This will be |
| 89 | passed back to the code generating the type for the Debug |
| 90 | Information Entry for the variable 'VarName'. 'VarName' will then |
| 91 | have the original type 'SomeType' in its debug information. |
| 92 | |
| 93 | The original type 'SomeType' will be the type of the field named |
| 94 | 'VarName' inside the __Block_byref_x_VarName struct. |
| 95 | |
| 96 | NOTE: In order for this to not completely fail on the debugger |
| 97 | side, the Debug Information Entry for the variable VarName needs to |
| 98 | have a DW_AT_location that tells the debugger how to unwind through |
| 99 | the pointers and __Block_byref_x_VarName struct to find the actual |
| 100 | value of the variable. The function addBlockByrefType does this. */ |
| 101 | DIType subType = Ty; |
| 102 | unsigned tag = Ty.getTag(); |
| 103 | |
| 104 | if (tag == dwarf::DW_TAG_pointer_type) { |
| 105 | DIDerivedType DTy = DIDerivedType(Ty); |
| 106 | subType = DTy.getTypeDerivedFrom(); |
| 107 | } |
| 108 | |
| 109 | DICompositeType blockStruct = DICompositeType(subType); |
| 110 | DIArray Elements = blockStruct.getTypeArray(); |
| 111 | |
| 112 | for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) { |
| 113 | DIDescriptor Element = Elements.getElement(i); |
| 114 | DIDerivedType DT = DIDerivedType(Element); |
| 115 | if (getName() == DT.getName()) |
| 116 | return (DT.getTypeDerivedFrom()); |
Devang Patel | 8bd11de | 2010-08-09 21:01:39 +0000 | [diff] [blame] | 117 | } |
| 118 | return Ty; |
| 119 | } |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 120 | return Ty; |
| 121 | } |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 122 | |
| 123 | //===----------------------------------------------------------------------===// |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 124 | /// DbgRange - This is used to track range of instructions with identical |
| 125 | /// debug info scope. |
| 126 | /// |
| 127 | typedef std::pair<const MachineInstr *, const MachineInstr *> DbgRange; |
| 128 | |
| 129 | //===----------------------------------------------------------------------===// |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 130 | /// DbgScope - This class is used to track scope information. |
| 131 | /// |
Devang Patel | f76a3d6 | 2009-11-16 21:53:40 +0000 | [diff] [blame] | 132 | class DbgScope { |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 133 | DbgScope *Parent; // Parent to this scope. |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 134 | DIDescriptor Desc; // Debug info descriptor for scope. |
Devang Patel | 3139fcf | 2010-01-26 21:39:14 +0000 | [diff] [blame] | 135 | // Location at which this scope is inlined. |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 136 | AssertingVH<const MDNode> InlinedAtLocation; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 137 | bool AbstractScope; // Abstract Scope |
Devang Patel | d38dd11 | 2009-10-01 18:25:23 +0000 | [diff] [blame] | 138 | const MachineInstr *LastInsn; // Last instruction of this scope. |
| 139 | const MachineInstr *FirstInsn; // First instruction of this scope. |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 140 | unsigned DFSIn, DFSOut; |
Jeffrey Yasskin | 5c213dc | 2010-03-12 17:45:06 +0000 | [diff] [blame] | 141 | // Scopes defined in scope. Contents not owned. |
| 142 | SmallVector<DbgScope *, 4> Scopes; |
| 143 | // Variables declared in scope. Contents owned. |
| 144 | SmallVector<DbgVariable *, 8> Variables; |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 145 | SmallVector<DbgRange, 4> Ranges; |
Owen Anderson | 04c05f7 | 2009-06-24 22:53:20 +0000 | [diff] [blame] | 146 | // Private state for dump() |
| 147 | mutable unsigned IndentLevel; |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 148 | public: |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 149 | DbgScope(DbgScope *P, DIDescriptor D, const MDNode *I = 0) |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 150 | : Parent(P), Desc(D), InlinedAtLocation(I), AbstractScope(false), |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 151 | LastInsn(0), FirstInsn(0), |
| 152 | DFSIn(0), DFSOut(0), IndentLevel(0) {} |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 153 | virtual ~DbgScope(); |
| 154 | |
| 155 | // Accessors. |
| 156 | DbgScope *getParent() const { return Parent; } |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 157 | void setParent(DbgScope *P) { Parent = P; } |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 158 | DIDescriptor getDesc() const { return Desc; } |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 159 | const MDNode *getInlinedAt() const { return InlinedAtLocation; } |
| 160 | const MDNode *getScopeNode() const { return Desc; } |
Jeffrey Yasskin | 5c213dc | 2010-03-12 17:45:06 +0000 | [diff] [blame] | 161 | const SmallVector<DbgScope *, 4> &getScopes() { return Scopes; } |
Devang Patel | e03161c | 2010-08-09 18:51:29 +0000 | [diff] [blame] | 162 | const SmallVector<DbgVariable *, 8> &getDbgVariables() { return Variables; } |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 163 | const SmallVector<DbgRange, 4> &getRanges() { return Ranges; } |
| 164 | |
| 165 | /// openInsnRange - This scope covers instruction range starting from MI. |
| 166 | void openInsnRange(const MachineInstr *MI) { |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 167 | if (!FirstInsn) |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 168 | FirstInsn = MI; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 169 | |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 170 | if (Parent) |
| 171 | Parent->openInsnRange(MI); |
| 172 | } |
| 173 | |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 174 | /// extendInsnRange - Extend the current instruction range covered by |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 175 | /// this scope. |
| 176 | void extendInsnRange(const MachineInstr *MI) { |
| 177 | assert (FirstInsn && "MI Range is not open!"); |
| 178 | LastInsn = MI; |
| 179 | if (Parent) |
| 180 | Parent->extendInsnRange(MI); |
| 181 | } |
| 182 | |
| 183 | /// closeInsnRange - Create a range based on FirstInsn and LastInsn collected |
| 184 | /// until now. This is used when a new scope is encountered while walking |
| 185 | /// machine instructions. |
| 186 | void closeInsnRange(DbgScope *NewScope = NULL) { |
| 187 | assert (LastInsn && "Last insn missing!"); |
| 188 | Ranges.push_back(DbgRange(FirstInsn, LastInsn)); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 189 | FirstInsn = NULL; |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 190 | LastInsn = NULL; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 191 | // If Parent dominates NewScope then do not close Parent's instruction |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 192 | // range. |
| 193 | if (Parent && (!NewScope || !Parent->dominates(NewScope))) |
| 194 | Parent->closeInsnRange(NewScope); |
| 195 | } |
| 196 | |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 197 | void setAbstractScope() { AbstractScope = true; } |
| 198 | bool isAbstractScope() const { return AbstractScope; } |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 199 | |
| 200 | // Depth First Search support to walk and mainpluate DbgScope hierarchy. |
| 201 | unsigned getDFSOut() const { return DFSOut; } |
| 202 | void setDFSOut(unsigned O) { DFSOut = O; } |
| 203 | unsigned getDFSIn() const { return DFSIn; } |
| 204 | void setDFSIn(unsigned I) { DFSIn = I; } |
| 205 | bool dominates(const DbgScope *S) { |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 206 | if (S == this) |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 207 | return true; |
| 208 | if (DFSIn < S->getDFSIn() && DFSOut > S->getDFSOut()) |
| 209 | return true; |
| 210 | return false; |
| 211 | } |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 212 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 213 | /// addScope - Add a scope to the scope. |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 214 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 215 | void addScope(DbgScope *S) { Scopes.push_back(S); } |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 216 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 217 | /// addVariable - Add a variable to the scope. |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 218 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 219 | void addVariable(DbgVariable *V) { Variables.push_back(V); } |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 220 | |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 221 | #ifndef NDEBUG |
| 222 | void dump() const; |
| 223 | #endif |
| 224 | }; |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 225 | |
Chris Lattner | ea76186 | 2010-04-05 04:09:20 +0000 | [diff] [blame] | 226 | } // end llvm namespace |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 227 | |
| 228 | #ifndef NDEBUG |
| 229 | void DbgScope::dump() const { |
David Greene | f83adbc | 2009-12-24 00:31:35 +0000 | [diff] [blame] | 230 | raw_ostream &err = dbgs(); |
Chris Lattner | c281de1 | 2009-08-23 00:51:00 +0000 | [diff] [blame] | 231 | err.indent(IndentLevel); |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 232 | const MDNode *N = Desc; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 233 | N->dump(); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 234 | if (AbstractScope) |
| 235 | err << "Abstract Scope\n"; |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 236 | |
| 237 | IndentLevel += 2; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 238 | if (!Scopes.empty()) |
| 239 | err << "Children ...\n"; |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 240 | for (unsigned i = 0, e = Scopes.size(); i != e; ++i) |
| 241 | if (Scopes[i] != this) |
| 242 | Scopes[i]->dump(); |
| 243 | |
| 244 | IndentLevel -= 2; |
| 245 | } |
| 246 | #endif |
| 247 | |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 248 | DbgScope::~DbgScope() { |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 249 | for (unsigned j = 0, M = Variables.size(); j < M; ++j) |
| 250 | delete Variables[j]; |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 251 | } |
| 252 | |
Chris Lattner | 49cd664 | 2010-04-05 05:11:15 +0000 | [diff] [blame] | 253 | DwarfDebug::DwarfDebug(AsmPrinter *A, Module *M) |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 254 | : Asm(A), MMI(Asm->MMI), FirstCU(0), |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 255 | AbbreviationsSet(InitAbbreviationsSetSize), |
Devang Patel | f2548ca | 2010-04-16 23:33:45 +0000 | [diff] [blame] | 256 | CurrentFnDbgScope(0), PrevLabel(NULL) { |
Chris Lattner | bc733f5 | 2010-03-13 02:17:42 +0000 | [diff] [blame] | 257 | NextStringPoolNumber = 0; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 258 | |
Rafael Espindola | f2b0423 | 2011-05-06 14:56:22 +0000 | [diff] [blame] | 259 | DwarfInfoSectionSym = DwarfAbbrevSectionSym = 0; |
Chris Lattner | 4ad1efe | 2010-04-04 23:10:38 +0000 | [diff] [blame] | 260 | DwarfStrSectionSym = TextSectionSym = 0; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 261 | DwarfDebugRangeSectionSym = DwarfDebugLocSectionSym = 0; |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 262 | FunctionBeginSym = FunctionEndSym = 0; |
Dan Gohman | 03c3dc7 | 2010-06-18 15:56:31 +0000 | [diff] [blame] | 263 | { |
| 264 | NamedRegionTimer T(DbgTimerName, DWARFGroupName, TimePassesIsEnabled); |
| 265 | beginModule(M); |
Torok Edwin | 9c42107 | 2010-04-07 10:44:46 +0000 | [diff] [blame] | 266 | } |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 267 | } |
| 268 | DwarfDebug::~DwarfDebug() { |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 269 | } |
| 270 | |
Chris Lattner | bc733f5 | 2010-03-13 02:17:42 +0000 | [diff] [blame] | 271 | MCSymbol *DwarfDebug::getStringPoolEntry(StringRef Str) { |
| 272 | std::pair<MCSymbol*, unsigned> &Entry = StringPool[Str]; |
| 273 | if (Entry.first) return Entry.first; |
| 274 | |
| 275 | Entry.second = NextStringPoolNumber++; |
Chris Lattner | c021572 | 2010-04-04 19:25:43 +0000 | [diff] [blame] | 276 | return Entry.first = Asm->GetTempSymbol("string", Entry.second); |
Chris Lattner | bc733f5 | 2010-03-13 02:17:42 +0000 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 280 | /// assignAbbrevNumber - Define a unique number for the abbreviation. |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 281 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 282 | void DwarfDebug::assignAbbrevNumber(DIEAbbrev &Abbrev) { |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 283 | // Profile the node so that we can make it unique. |
| 284 | FoldingSetNodeID ID; |
| 285 | Abbrev.Profile(ID); |
| 286 | |
| 287 | // Check the set for priors. |
| 288 | DIEAbbrev *InSet = AbbreviationsSet.GetOrInsertNode(&Abbrev); |
| 289 | |
| 290 | // If it's newly added. |
| 291 | if (InSet == &Abbrev) { |
| 292 | // Add to abbreviation list. |
| 293 | Abbreviations.push_back(&Abbrev); |
| 294 | |
| 295 | // Assign the vector position + 1 as its number. |
| 296 | Abbrev.setNumber(Abbreviations.size()); |
| 297 | } else { |
| 298 | // Assign existing abbreviation number. |
| 299 | Abbrev.setNumber(InSet->getNumber()); |
| 300 | } |
| 301 | } |
| 302 | |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 303 | /// getRealLinkageName - If special LLVM prefix that is used to inform the asm |
Devang Patel | 351ca33 | 2010-01-05 01:46:14 +0000 | [diff] [blame] | 304 | /// printer to not emit usual symbol prefix before the symbol name is used then |
| 305 | /// return linkage name after skipping this special LLVM prefix. |
| 306 | static StringRef getRealLinkageName(StringRef LinkageName) { |
| 307 | char One = '\1'; |
| 308 | if (LinkageName.startswith(StringRef(&One, 1))) |
| 309 | return LinkageName.substr(1); |
| 310 | return LinkageName; |
| 311 | } |
| 312 | |
Devang Patel | ffe966c | 2009-12-14 16:18:45 +0000 | [diff] [blame] | 313 | /// createSubprogramDIE - Create new DIE using SP. |
Devang Patel | ee70fa7 | 2010-09-27 23:15:27 +0000 | [diff] [blame] | 314 | DIE *DwarfDebug::createSubprogramDIE(DISubprogram SP) { |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 315 | CompileUnit *SPCU = getCompileUnit(SP); |
| 316 | DIE *SPDie = SPCU->getDIE(SP); |
Devang Patel | ffe966c | 2009-12-14 16:18:45 +0000 | [diff] [blame] | 317 | if (SPDie) |
| 318 | return SPDie; |
| 319 | |
| 320 | SPDie = new DIE(dwarf::DW_TAG_subprogram); |
Devang Patel | 5e06bb8 | 2011-04-22 23:10:17 +0000 | [diff] [blame] | 321 | |
| 322 | // DW_TAG_inlined_subroutine may refer to this DIE. |
| 323 | SPCU->insertDIE(SP, SPDie); |
| 324 | |
| 325 | // Add to context owner. |
| 326 | SPCU->addToContextOwner(SPDie, SP.getContext()); |
| 327 | |
| 328 | // Add function template parameters. |
| 329 | SPCU->addTemplateParams(*SPDie, SP.getTemplateParams()); |
| 330 | |
Devang Patel | ee4a3ab | 2011-05-03 21:50:34 +0000 | [diff] [blame] | 331 | StringRef LinkageName = SP.getLinkageName(); |
| 332 | if (!LinkageName.empty()) |
| 333 | SPCU->addString(SPDie, dwarf::DW_AT_MIPS_linkage_name, dwarf::DW_FORM_string, |
| 334 | getRealLinkageName(LinkageName)); |
| 335 | |
Devang Patel | 5e06bb8 | 2011-04-22 23:10:17 +0000 | [diff] [blame] | 336 | // If this DIE is going to refer declaration info using AT_specification |
| 337 | // then there is no need to add other attributes. |
| 338 | if (SP.getFunctionDeclaration().isSubprogram()) |
| 339 | return SPDie; |
| 340 | |
Devang Patel | 1eac3e7 | 2010-03-02 17:58:15 +0000 | [diff] [blame] | 341 | // Constructors and operators for anonymous aggregates do not have names. |
Devang Patel | 6b506cb | 2010-03-02 01:26:20 +0000 | [diff] [blame] | 342 | if (!SP.getName().empty()) |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 343 | SPCU->addString(SPDie, dwarf::DW_AT_name, dwarf::DW_FORM_string, |
| 344 | SP.getName()); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 345 | |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 346 | SPCU->addSourceLine(SPDie, SP); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 347 | |
Devang Patel | 7b172c6 | 2010-10-07 22:03:01 +0000 | [diff] [blame] | 348 | if (SP.isPrototyped()) |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 349 | SPCU->addUInt(SPDie, dwarf::DW_AT_prototyped, dwarf::DW_FORM_flag, 1); |
Devang Patel | 5e06bb8 | 2011-04-22 23:10:17 +0000 | [diff] [blame] | 350 | |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 351 | // Add Return Type. |
Devang Patel | 1d5cc1d | 2009-12-03 01:25:38 +0000 | [diff] [blame] | 352 | DICompositeType SPTy = SP.getType(); |
| 353 | DIArray Args = SPTy.getTypeArray(); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 354 | unsigned SPTag = SPTy.getTag(); |
Devang Patel | 5d11eb0 | 2009-12-03 19:11:07 +0000 | [diff] [blame] | 355 | |
Devang Patel | 3c91b05 | 2010-03-08 20:52:55 +0000 | [diff] [blame] | 356 | if (Args.getNumElements() == 0 || SPTag != dwarf::DW_TAG_subroutine_type) |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 357 | SPCU->addType(SPDie, SPTy); |
Devang Patel | 1d5cc1d | 2009-12-03 01:25:38 +0000 | [diff] [blame] | 358 | else |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 359 | SPCU->addType(SPDie, DIType(Args.getElement(0))); |
Devang Patel | 1d5cc1d | 2009-12-03 01:25:38 +0000 | [diff] [blame] | 360 | |
Devang Patel | 5d11eb0 | 2009-12-03 19:11:07 +0000 | [diff] [blame] | 361 | unsigned VK = SP.getVirtuality(); |
| 362 | if (VK) { |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 363 | SPCU->addUInt(SPDie, dwarf::DW_AT_virtuality, dwarf::DW_FORM_flag, VK); |
| 364 | DIEBlock *Block = SPCU->getDIEBlock(); |
| 365 | SPCU->addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_constu); |
| 366 | SPCU->addUInt(Block, 0, dwarf::DW_FORM_udata, SP.getVirtualIndex()); |
| 367 | SPCU->addBlock(SPDie, dwarf::DW_AT_vtable_elem_location, 0, Block); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 368 | ContainingTypeMap.insert(std::make_pair(SPDie, |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 369 | SP.getContainingType())); |
Devang Patel | 5d11eb0 | 2009-12-03 19:11:07 +0000 | [diff] [blame] | 370 | } |
| 371 | |
Devang Patel | ee70fa7 | 2010-09-27 23:15:27 +0000 | [diff] [blame] | 372 | if (!SP.isDefinition()) { |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 373 | SPCU->addUInt(SPDie, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag, 1); |
| 374 | |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 375 | // Add arguments. Do not add arguments for subprogram definition. They will |
Devang Patel | 1d5cc1d | 2009-12-03 01:25:38 +0000 | [diff] [blame] | 376 | // be handled while processing variables. |
| 377 | DICompositeType SPTy = SP.getType(); |
| 378 | DIArray Args = SPTy.getTypeArray(); |
| 379 | unsigned SPTag = SPTy.getTag(); |
| 380 | |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 381 | if (SPTag == dwarf::DW_TAG_subroutine_type) |
| 382 | for (unsigned i = 1, N = Args.getNumElements(); i < N; ++i) { |
| 383 | DIE *Arg = new DIE(dwarf::DW_TAG_formal_parameter); |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 384 | DIType ATy = DIType(DIType(Args.getElement(i))); |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 385 | SPCU->addType(Arg, ATy); |
Devang Patel | b464564 | 2010-02-06 01:02:37 +0000 | [diff] [blame] | 386 | if (ATy.isArtificial()) |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 387 | SPCU->addUInt(Arg, dwarf::DW_AT_artificial, dwarf::DW_FORM_flag, 1); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 388 | SPDie->addChild(Arg); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 389 | } |
| 390 | } |
| 391 | |
Devang Patel | 4e0d19d | 2010-02-03 19:57:19 +0000 | [diff] [blame] | 392 | if (SP.isArtificial()) |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 393 | SPCU->addUInt(SPDie, dwarf::DW_AT_artificial, dwarf::DW_FORM_flag, 1); |
Devang Patel | 4e0d19d | 2010-02-03 19:57:19 +0000 | [diff] [blame] | 394 | |
Devang Patel | ccff812 | 2010-04-30 19:38:23 +0000 | [diff] [blame] | 395 | if (!SP.isLocalToUnit()) |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 396 | SPCU->addUInt(SPDie, dwarf::DW_AT_external, dwarf::DW_FORM_flag, 1); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 397 | |
Devang Patel | ccff812 | 2010-04-30 19:38:23 +0000 | [diff] [blame] | 398 | if (SP.isOptimized()) |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 399 | SPCU->addUInt(SPDie, dwarf::DW_AT_APPLE_optimized, dwarf::DW_FORM_flag, 1); |
Devang Patel | ccff812 | 2010-04-30 19:38:23 +0000 | [diff] [blame] | 400 | |
Jim Grosbach | 9172900 | 2010-07-21 23:03:52 +0000 | [diff] [blame] | 401 | if (unsigned isa = Asm->getISAEncoding()) { |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 402 | SPCU->addUInt(SPDie, dwarf::DW_AT_APPLE_isa, dwarf::DW_FORM_flag, isa); |
Jim Grosbach | 9172900 | 2010-07-21 23:03:52 +0000 | [diff] [blame] | 403 | } |
| 404 | |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 405 | return SPDie; |
| 406 | } |
| 407 | |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 408 | DbgScope *DwarfDebug::getOrCreateAbstractScope(const MDNode *N) { |
Chris Lattner | ed7a77b | 2010-03-31 05:36:29 +0000 | [diff] [blame] | 409 | assert(N && "Invalid Scope encoding!"); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 410 | |
| 411 | DbgScope *AScope = AbstractScopes.lookup(N); |
| 412 | if (AScope) |
| 413 | return AScope; |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 414 | |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 415 | DbgScope *Parent = NULL; |
| 416 | |
| 417 | DIDescriptor Scope(N); |
| 418 | if (Scope.isLexicalBlock()) { |
| 419 | DILexicalBlock DB(N); |
| 420 | DIDescriptor ParentDesc = DB.getContext(); |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 421 | Parent = getOrCreateAbstractScope(ParentDesc); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | AScope = new DbgScope(Parent, DIDescriptor(N), NULL); |
| 425 | |
| 426 | if (Parent) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 427 | Parent->addScope(AScope); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 428 | AScope->setAbstractScope(); |
| 429 | AbstractScopes[N] = AScope; |
| 430 | if (DIDescriptor(N).isSubprogram()) |
| 431 | AbstractScopesList.push_back(AScope); |
| 432 | return AScope; |
| 433 | } |
Devang Patel | af9e847 | 2009-10-01 20:31:14 +0000 | [diff] [blame] | 434 | |
Devang Patel | 5f09400 | 2010-04-06 23:53:48 +0000 | [diff] [blame] | 435 | /// isSubprogramContext - Return true if Context is either a subprogram |
| 436 | /// or another context nested inside a subprogram. |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 437 | static bool isSubprogramContext(const MDNode *Context) { |
Devang Patel | 5f09400 | 2010-04-06 23:53:48 +0000 | [diff] [blame] | 438 | if (!Context) |
| 439 | return false; |
| 440 | DIDescriptor D(Context); |
| 441 | if (D.isSubprogram()) |
| 442 | return true; |
| 443 | if (D.isType()) |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 444 | return isSubprogramContext(DIType(Context).getContext()); |
Devang Patel | 5f09400 | 2010-04-06 23:53:48 +0000 | [diff] [blame] | 445 | return false; |
| 446 | } |
| 447 | |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 448 | /// updateSubprogramScopeDIE - Find DIE for the given subprogram and |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 449 | /// attach appropriate DW_AT_low_pc and DW_AT_high_pc attributes. |
| 450 | /// If there are global variables in this scope then create and insert |
| 451 | /// DIEs for these variables. |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 452 | DIE *DwarfDebug::updateSubprogramScopeDIE(const MDNode *SPNode) { |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 453 | CompileUnit *SPCU = getCompileUnit(SPNode); |
| 454 | DIE *SPDie = SPCU->getDIE(SPNode); |
Devang Patel | 8aa6147 | 2010-07-07 22:20:57 +0000 | [diff] [blame] | 455 | |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 456 | assert(SPDie && "Unable to find subprogram DIE!"); |
| 457 | DISubprogram SP(SPNode); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 458 | |
Devang Patel | 5e06bb8 | 2011-04-22 23:10:17 +0000 | [diff] [blame] | 459 | DISubprogram SPDecl = SP.getFunctionDeclaration(); |
| 460 | if (SPDecl.isSubprogram()) |
| 461 | // Refer function declaration directly. |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 462 | SPCU->addDIEEntry(SPDie, dwarf::DW_AT_specification, dwarf::DW_FORM_ref4, |
Devang Patel | 5e06bb8 | 2011-04-22 23:10:17 +0000 | [diff] [blame] | 463 | createSubprogramDIE(SPDecl)); |
| 464 | else { |
| 465 | // There is not any need to generate specification DIE for a function |
| 466 | // defined at compile unit level. If a function is defined inside another |
| 467 | // function then gdb prefers the definition at top level and but does not |
| 468 | // expect specification DIE in parent function. So avoid creating |
| 469 | // specification DIE for a function defined inside a function. |
| 470 | if (SP.isDefinition() && !SP.getContext().isCompileUnit() && |
| 471 | !SP.getContext().isFile() && |
| 472 | !isSubprogramContext(SP.getContext())) { |
| 473 | SPCU-> addUInt(SPDie, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag, 1); |
| 474 | |
| 475 | // Add arguments. |
| 476 | DICompositeType SPTy = SP.getType(); |
| 477 | DIArray Args = SPTy.getTypeArray(); |
| 478 | unsigned SPTag = SPTy.getTag(); |
| 479 | if (SPTag == dwarf::DW_TAG_subroutine_type) |
| 480 | for (unsigned i = 1, N = Args.getNumElements(); i < N; ++i) { |
| 481 | DIE *Arg = new DIE(dwarf::DW_TAG_formal_parameter); |
| 482 | DIType ATy = DIType(DIType(Args.getElement(i))); |
| 483 | SPCU->addType(Arg, ATy); |
| 484 | if (ATy.isArtificial()) |
| 485 | SPCU->addUInt(Arg, dwarf::DW_AT_artificial, dwarf::DW_FORM_flag, 1); |
| 486 | SPDie->addChild(Arg); |
| 487 | } |
| 488 | DIE *SPDeclDie = SPDie; |
| 489 | SPDie = new DIE(dwarf::DW_TAG_subprogram); |
| 490 | SPCU->addDIEEntry(SPDie, dwarf::DW_AT_specification, dwarf::DW_FORM_ref4, |
| 491 | SPDeclDie); |
| 492 | SPCU->addDie(SPDie); |
| 493 | } |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 494 | } |
Devang Patel | 8aa6147 | 2010-07-07 22:20:57 +0000 | [diff] [blame] | 495 | // Pick up abstract subprogram DIE. |
| 496 | if (DIE *AbsSPDIE = AbstractSPDies.lookup(SPNode)) { |
| 497 | SPDie = new DIE(dwarf::DW_TAG_subprogram); |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 498 | SPCU->addDIEEntry(SPDie, dwarf::DW_AT_abstract_origin, |
| 499 | dwarf::DW_FORM_ref4, AbsSPDIE); |
Devang Patel | 8aa6147 | 2010-07-07 22:20:57 +0000 | [diff] [blame] | 500 | SPCU->addDie(SPDie); |
| 501 | } |
| 502 | |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 503 | SPCU->addLabel(SPDie, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr, |
| 504 | Asm->GetTempSymbol("func_begin", Asm->getFunctionNumber())); |
| 505 | SPCU->addLabel(SPDie, dwarf::DW_AT_high_pc, dwarf::DW_FORM_addr, |
| 506 | Asm->GetTempSymbol("func_end", Asm->getFunctionNumber())); |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 507 | const TargetRegisterInfo *RI = Asm->TM.getRegisterInfo(); |
| 508 | MachineLocation Location(RI->getFrameRegister(*Asm->MF)); |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 509 | SPCU->addAddress(SPDie, dwarf::DW_AT_frame_base, Location); |
Devang Patel | b464564 | 2010-02-06 01:02:37 +0000 | [diff] [blame] | 510 | |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 511 | return SPDie; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 512 | } |
| 513 | |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 514 | /// constructLexicalScope - Construct new DW_TAG_lexical_block |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 515 | /// for this scope and attach DW_AT_low_pc/DW_AT_high_pc labels. |
| 516 | DIE *DwarfDebug::constructLexicalScopeDIE(DbgScope *Scope) { |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 517 | |
| 518 | DIE *ScopeDIE = new DIE(dwarf::DW_TAG_lexical_block); |
| 519 | if (Scope->isAbstractScope()) |
| 520 | return ScopeDIE; |
| 521 | |
| 522 | const SmallVector<DbgRange, 4> &Ranges = Scope->getRanges(); |
| 523 | if (Ranges.empty()) |
| 524 | return 0; |
| 525 | |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 526 | CompileUnit *TheCU = getCompileUnit(Scope->getScopeNode()); |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 527 | SmallVector<DbgRange, 4>::const_iterator RI = Ranges.begin(); |
| 528 | if (Ranges.size() > 1) { |
| 529 | // .debug_range section has not been laid out yet. Emit offset in |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 530 | // .debug_range as a uint, size 4, for now. emitDIE will handle |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 531 | // DW_AT_ranges appropriately. |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 532 | TheCU->addUInt(ScopeDIE, dwarf::DW_AT_ranges, dwarf::DW_FORM_data4, |
| 533 | DebugRangeSymbols.size() * Asm->getTargetData().getPointerSize()); |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 534 | for (SmallVector<DbgRange, 4>::const_iterator RI = Ranges.begin(), |
| 535 | RE = Ranges.end(); RI != RE; ++RI) { |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 536 | DebugRangeSymbols.push_back(getLabelBeforeInsn(RI->first)); |
| 537 | DebugRangeSymbols.push_back(getLabelAfterInsn(RI->second)); |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 538 | } |
| 539 | DebugRangeSymbols.push_back(NULL); |
| 540 | DebugRangeSymbols.push_back(NULL); |
| 541 | return ScopeDIE; |
| 542 | } |
| 543 | |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 544 | const MCSymbol *Start = getLabelBeforeInsn(RI->first); |
| 545 | const MCSymbol *End = getLabelAfterInsn(RI->second); |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 546 | |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 547 | if (End == 0) return 0; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 548 | |
Chris Lattner | b7db733 | 2010-03-09 01:58:53 +0000 | [diff] [blame] | 549 | assert(Start->isDefined() && "Invalid starting label for an inlined scope!"); |
| 550 | assert(End->isDefined() && "Invalid end label for an inlined scope!"); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 551 | |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 552 | TheCU->addLabel(ScopeDIE, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr, Start); |
| 553 | TheCU->addLabel(ScopeDIE, dwarf::DW_AT_high_pc, dwarf::DW_FORM_addr, End); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 554 | |
| 555 | return ScopeDIE; |
| 556 | } |
| 557 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 558 | /// constructInlinedScopeDIE - This scope represents inlined body of |
| 559 | /// a function. Construct DIE to represent this concrete inlined copy |
| 560 | /// of the function. |
| 561 | DIE *DwarfDebug::constructInlinedScopeDIE(DbgScope *Scope) { |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 562 | |
| 563 | const SmallVector<DbgRange, 4> &Ranges = Scope->getRanges(); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 564 | assert (Ranges.empty() == false |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 565 | && "DbgScope does not have instruction markers!"); |
| 566 | |
| 567 | // FIXME : .debug_inlined section specification does not clearly state how |
| 568 | // to emit inlined scope that is split into multiple instruction ranges. |
| 569 | // For now, use first instruction range and emit low_pc/high_pc pair and |
| 570 | // corresponding .debug_inlined section entry for this pair. |
| 571 | SmallVector<DbgRange, 4>::const_iterator RI = Ranges.begin(); |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 572 | const MCSymbol *StartLabel = getLabelBeforeInsn(RI->first); |
| 573 | const MCSymbol *EndLabel = getLabelAfterInsn(RI->second); |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 574 | |
Devang Patel | 0afbf23 | 2010-07-08 22:39:20 +0000 | [diff] [blame] | 575 | if (StartLabel == 0 || EndLabel == 0) { |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 576 | assert (0 && "Unexpected Start and End labels for a inlined scope!"); |
| 577 | return 0; |
| 578 | } |
Chris Lattner | b7db733 | 2010-03-09 01:58:53 +0000 | [diff] [blame] | 579 | assert(StartLabel->isDefined() && |
Chris Lattner | a34ec229 | 2010-03-09 01:51:43 +0000 | [diff] [blame] | 580 | "Invalid starting label for an inlined scope!"); |
Chris Lattner | b7db733 | 2010-03-09 01:58:53 +0000 | [diff] [blame] | 581 | assert(EndLabel->isDefined() && |
Chris Lattner | a34ec229 | 2010-03-09 01:51:43 +0000 | [diff] [blame] | 582 | "Invalid end label for an inlined scope!"); |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 583 | |
Devang Patel | 3c91b05 | 2010-03-08 20:52:55 +0000 | [diff] [blame] | 584 | if (!Scope->getScopeNode()) |
Devang Patel | 0ef3fa6 | 2010-03-08 19:20:38 +0000 | [diff] [blame] | 585 | return NULL; |
Devang Patel | 3c91b05 | 2010-03-08 20:52:55 +0000 | [diff] [blame] | 586 | DIScope DS(Scope->getScopeNode()); |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 587 | DISubprogram InlinedSP = getDISubprogram(DS); |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 588 | CompileUnit *TheCU = getCompileUnit(InlinedSP); |
| 589 | DIE *OriginDIE = TheCU->getDIE(InlinedSP); |
Devang Patel | d96efb8 | 2011-05-05 17:54:26 +0000 | [diff] [blame] | 590 | if (!OriginDIE) { |
| 591 | DEBUG(dbgs() << "Unable to find original DIE for inlined subprogram."); |
| 592 | return NULL; |
| 593 | } |
| 594 | DIE *ScopeDIE = new DIE(dwarf::DW_TAG_inlined_subroutine); |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 595 | TheCU->addDIEEntry(ScopeDIE, dwarf::DW_AT_abstract_origin, |
| 596 | dwarf::DW_FORM_ref4, OriginDIE); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 597 | |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 598 | TheCU->addLabel(ScopeDIE, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr, StartLabel); |
| 599 | TheCU->addLabel(ScopeDIE, dwarf::DW_AT_high_pc, dwarf::DW_FORM_addr, EndLabel); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 600 | |
| 601 | InlinedSubprogramDIEs.insert(OriginDIE); |
| 602 | |
| 603 | // Track the start label for this inlined function. |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 604 | DenseMap<const MDNode *, SmallVector<InlineInfoLabels, 4> >::iterator |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 605 | I = InlineInfo.find(InlinedSP); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 606 | |
| 607 | if (I == InlineInfo.end()) { |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 608 | InlineInfo[InlinedSP].push_back(std::make_pair(StartLabel, |
Jim Grosbach | 7ab38df | 2009-11-22 19:20:36 +0000 | [diff] [blame] | 609 | ScopeDIE)); |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 610 | InlinedSPNodes.push_back(InlinedSP); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 611 | } else |
Chris Lattner | 6ed0f90 | 2010-03-09 00:31:02 +0000 | [diff] [blame] | 612 | I->second.push_back(std::make_pair(StartLabel, ScopeDIE)); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 613 | |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 614 | DILocation DL(Scope->getInlinedAt()); |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 615 | TheCU->addUInt(ScopeDIE, dwarf::DW_AT_call_file, 0, TheCU->getID()); |
| 616 | TheCU->addUInt(ScopeDIE, dwarf::DW_AT_call_line, 0, DL.getLineNumber()); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 617 | |
| 618 | return ScopeDIE; |
| 619 | } |
| 620 | |
Devang Patel | 8594d42 | 2011-06-24 20:46:11 +0000 | [diff] [blame^] | 621 | /// isUnsignedDIType - Return true if type encoding is unsigned. |
| 622 | static bool isUnsignedDIType(DIType Ty) { |
| 623 | DIDerivedType DTy(Ty); |
| 624 | if (DTy.Verify()) |
| 625 | return isUnsignedDIType(DTy.getTypeDerivedFrom()); |
| 626 | |
| 627 | DIBasicType BTy(Ty); |
| 628 | if (BTy.Verify()) { |
| 629 | unsigned Encoding = BTy.getEncoding(); |
| 630 | if (Encoding == dwarf::DW_ATE_unsigned || |
| 631 | Encoding == dwarf::DW_ATE_unsigned_char) |
| 632 | return true; |
| 633 | } |
| 634 | return false; |
| 635 | } |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 636 | |
| 637 | /// constructVariableDIE - Construct a DIE for the given DbgVariable. |
Devang Patel | 8a24114 | 2009-12-09 18:24:21 +0000 | [diff] [blame] | 638 | DIE *DwarfDebug::constructVariableDIE(DbgVariable *DV, DbgScope *Scope) { |
Devang Patel | 8bd11de | 2010-08-09 21:01:39 +0000 | [diff] [blame] | 639 | StringRef Name = DV->getName(); |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 640 | if (Name.empty()) |
Devang Patel | 3fb6bd6 | 2009-11-13 02:25:26 +0000 | [diff] [blame] | 641 | return NULL; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 642 | |
| 643 | // Translate tag to proper Dwarf tag. The result variable is dropped for |
| 644 | // now. |
| 645 | unsigned Tag; |
Devang Patel | 8bd11de | 2010-08-09 21:01:39 +0000 | [diff] [blame] | 646 | switch (DV->getTag()) { |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 647 | case dwarf::DW_TAG_return_variable: |
| 648 | return NULL; |
| 649 | case dwarf::DW_TAG_arg_variable: |
| 650 | Tag = dwarf::DW_TAG_formal_parameter; |
| 651 | break; |
| 652 | case dwarf::DW_TAG_auto_variable: // fall thru |
| 653 | default: |
| 654 | Tag = dwarf::DW_TAG_variable; |
| 655 | break; |
| 656 | } |
| 657 | |
| 658 | // Define variable debug information entry. |
| 659 | DIE *VariableDie = new DIE(Tag); |
Devang Patel | 9341d10 | 2011-04-25 23:05:21 +0000 | [diff] [blame] | 660 | CompileUnit *VariableCU = getCompileUnit(DV->getVariable()); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 661 | DIE *AbsDIE = NULL; |
Devang Patel | 26c1e56 | 2010-05-20 16:36:41 +0000 | [diff] [blame] | 662 | DenseMap<const DbgVariable *, const DbgVariable *>::iterator |
| 663 | V2AVI = VarToAbstractVarMap.find(DV); |
| 664 | if (V2AVI != VarToAbstractVarMap.end()) |
| 665 | AbsDIE = V2AVI->second->getDIE(); |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 666 | |
Devang Patel | 26c1e56 | 2010-05-20 16:36:41 +0000 | [diff] [blame] | 667 | if (AbsDIE) |
Devang Patel | 9341d10 | 2011-04-25 23:05:21 +0000 | [diff] [blame] | 668 | VariableCU->addDIEEntry(VariableDie, dwarf::DW_AT_abstract_origin, |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 669 | dwarf::DW_FORM_ref4, AbsDIE); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 670 | else { |
Devang Patel | 9341d10 | 2011-04-25 23:05:21 +0000 | [diff] [blame] | 671 | VariableCU->addString(VariableDie, dwarf::DW_AT_name, dwarf::DW_FORM_string, |
| 672 | Name); |
| 673 | VariableCU->addSourceLine(VariableDie, DV->getVariable()); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 674 | |
| 675 | // Add variable type. |
Devang Patel | 9341d10 | 2011-04-25 23:05:21 +0000 | [diff] [blame] | 676 | VariableCU->addType(VariableDie, DV->getType()); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 677 | } |
| 678 | |
Devang Patel | 8bd11de | 2010-08-09 21:01:39 +0000 | [diff] [blame] | 679 | if (Tag == dwarf::DW_TAG_formal_parameter && DV->getType().isArtificial()) |
Devang Patel | 9341d10 | 2011-04-25 23:05:21 +0000 | [diff] [blame] | 680 | VariableCU->addUInt(VariableDie, dwarf::DW_AT_artificial, |
| 681 | dwarf::DW_FORM_flag, 1); |
Devang Patel | 3cf763d | 2010-09-29 23:07:21 +0000 | [diff] [blame] | 682 | else if (DIVariable(DV->getVariable()).isArtificial()) |
Devang Patel | 9341d10 | 2011-04-25 23:05:21 +0000 | [diff] [blame] | 683 | VariableCU->addUInt(VariableDie, dwarf::DW_AT_artificial, |
| 684 | dwarf::DW_FORM_flag, 1); |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 685 | |
| 686 | if (Scope->isAbstractScope()) { |
| 687 | DV->setDIE(VariableDie); |
| 688 | return VariableDie; |
| 689 | } |
| 690 | |
| 691 | // Add variable address. |
| 692 | |
| 693 | unsigned Offset = DV->getDotDebugLocOffset(); |
| 694 | if (Offset != ~0U) { |
Devang Patel | 9341d10 | 2011-04-25 23:05:21 +0000 | [diff] [blame] | 695 | VariableCU->addLabel(VariableDie, dwarf::DW_AT_location, dwarf::DW_FORM_data4, |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 696 | Asm->GetTempSymbol("debug_loc", Offset)); |
| 697 | DV->setDIE(VariableDie); |
| 698 | UseDotDebugLocEntry.insert(VariableDie); |
| 699 | return VariableDie; |
| 700 | } |
| 701 | |
| 702 | // Check if variable is described by a DBG_VALUE instruction. |
| 703 | DenseMap<const DbgVariable *, const MachineInstr *>::iterator DVI = |
| 704 | DbgVariableToDbgInstMap.find(DV); |
| 705 | if (DVI != DbgVariableToDbgInstMap.end()) { |
| 706 | const MachineInstr *DVInsn = DVI->second; |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 707 | bool updated = false; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 708 | // FIXME : Handle getNumOperands != 3 |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 709 | if (DVInsn->getNumOperands() == 3) { |
Devang Patel | 0b48ead | 2010-08-31 22:22:42 +0000 | [diff] [blame] | 710 | if (DVInsn->getOperand(0).isReg()) { |
| 711 | const MachineOperand RegOp = DVInsn->getOperand(0); |
| 712 | const TargetRegisterInfo *TRI = Asm->TM.getRegisterInfo(); |
| 713 | if (DVInsn->getOperand(1).isImm() && |
| 714 | TRI->getFrameRegister(*Asm->MF) == RegOp.getReg()) { |
Devang Patel | e1cdf84 | 2011-04-27 22:45:24 +0000 | [diff] [blame] | 715 | unsigned FrameReg = 0; |
| 716 | const TargetFrameLowering *TFI = Asm->TM.getFrameLowering(); |
| 717 | int Offset = |
| 718 | TFI->getFrameIndexReference(*Asm->MF, |
| 719 | DVInsn->getOperand(1).getImm(), |
| 720 | FrameReg); |
| 721 | MachineLocation Location(FrameReg, Offset); |
| 722 | VariableCU->addVariableAddress(DV, VariableDie, Location); |
| 723 | |
| 724 | } else if (RegOp.getReg()) |
| 725 | VariableCU->addVariableAddress(DV, VariableDie, |
| 726 | MachineLocation(RegOp.getReg())); |
| 727 | updated = true; |
Devang Patel | 0b48ead | 2010-08-31 22:22:42 +0000 | [diff] [blame] | 728 | } |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 729 | else if (DVInsn->getOperand(0).isImm()) |
Devang Patel | b58128e | 2011-05-27 16:45:18 +0000 | [diff] [blame] | 730 | updated = |
| 731 | VariableCU->addConstantValue(VariableDie, DVInsn->getOperand(0), |
| 732 | DV->getType()); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 733 | else if (DVInsn->getOperand(0).isFPImm()) |
| 734 | updated = |
Devang Patel | 9341d10 | 2011-04-25 23:05:21 +0000 | [diff] [blame] | 735 | VariableCU->addConstantFPValue(VariableDie, DVInsn->getOperand(0)); |
Devang Patel | 8594d42 | 2011-06-24 20:46:11 +0000 | [diff] [blame^] | 736 | else if (DVInsn->getOperand(0).isCImm()) |
| 737 | updated = |
| 738 | VariableCU->addConstantValue(VariableDie, |
| 739 | DVInsn->getOperand(0).getCImm(), |
| 740 | isUnsignedDIType(DV->getType())); |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 741 | } else { |
Devang Patel | e1cdf84 | 2011-04-27 22:45:24 +0000 | [diff] [blame] | 742 | VariableCU->addVariableAddress(DV, VariableDie, |
| 743 | Asm->getDebugValueLocation(DVInsn)); |
| 744 | updated = true; |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 745 | } |
| 746 | if (!updated) { |
| 747 | // If variableDie is not updated then DBG_VALUE instruction does not |
| 748 | // have valid variable info. |
| 749 | delete VariableDie; |
| 750 | return NULL; |
| 751 | } |
| 752 | DV->setDIE(VariableDie); |
| 753 | return VariableDie; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 754 | } |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 755 | |
| 756 | // .. else use frame index, if available. |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 757 | int FI = 0; |
Devang Patel | e1cdf84 | 2011-04-27 22:45:24 +0000 | [diff] [blame] | 758 | if (findVariableFrameIndex(DV, &FI)) { |
| 759 | unsigned FrameReg = 0; |
| 760 | const TargetFrameLowering *TFI = Asm->TM.getFrameLowering(); |
| 761 | int Offset = |
| 762 | TFI->getFrameIndexReference(*Asm->MF, FI, FrameReg); |
| 763 | MachineLocation Location(FrameReg, Offset); |
| 764 | VariableCU->addVariableAddress(DV, VariableDie, Location); |
| 765 | } |
| 766 | |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 767 | DV->setDIE(VariableDie); |
| 768 | return VariableDie; |
| 769 | |
| 770 | } |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 771 | |
| 772 | /// constructScopeDIE - Construct a DIE for this scope. |
| 773 | DIE *DwarfDebug::constructScopeDIE(DbgScope *Scope) { |
Devang Patel | 3c91b05 | 2010-03-08 20:52:55 +0000 | [diff] [blame] | 774 | if (!Scope || !Scope->getScopeNode()) |
| 775 | return NULL; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 776 | |
Devang Patel | 5bc9fec | 2011-02-19 01:31:27 +0000 | [diff] [blame] | 777 | SmallVector <DIE *, 8> Children; |
Devang Patel | 0478c15 | 2011-03-01 22:58:55 +0000 | [diff] [blame] | 778 | |
| 779 | // Collect arguments for current function. |
| 780 | if (Scope == CurrentFnDbgScope) |
| 781 | for (unsigned i = 0, N = CurrentFnArguments.size(); i < N; ++i) |
| 782 | if (DbgVariable *ArgDV = CurrentFnArguments[i]) |
| 783 | if (DIE *Arg = constructVariableDIE(ArgDV, Scope)) |
| 784 | Children.push_back(Arg); |
| 785 | |
Devang Patel | 5bc9fec | 2011-02-19 01:31:27 +0000 | [diff] [blame] | 786 | // Collect lexical scope childrens first. |
| 787 | const SmallVector<DbgVariable *, 8> &Variables = Scope->getDbgVariables(); |
| 788 | for (unsigned i = 0, N = Variables.size(); i < N; ++i) |
| 789 | if (DIE *Variable = constructVariableDIE(Variables[i], Scope)) |
| 790 | Children.push_back(Variable); |
| 791 | const SmallVector<DbgScope *, 4> &Scopes = Scope->getScopes(); |
| 792 | for (unsigned j = 0, M = Scopes.size(); j < M; ++j) |
| 793 | if (DIE *Nested = constructScopeDIE(Scopes[j])) |
| 794 | Children.push_back(Nested); |
Devang Patel | 3c91b05 | 2010-03-08 20:52:55 +0000 | [diff] [blame] | 795 | DIScope DS(Scope->getScopeNode()); |
| 796 | DIE *ScopeDIE = NULL; |
| 797 | if (Scope->getInlinedAt()) |
| 798 | ScopeDIE = constructInlinedScopeDIE(Scope); |
| 799 | else if (DS.isSubprogram()) { |
Devang Patel | 0dd4558 | 2010-06-28 20:53:04 +0000 | [diff] [blame] | 800 | ProcessedSPNodes.insert(DS); |
Devang Patel | 8aa6147 | 2010-07-07 22:20:57 +0000 | [diff] [blame] | 801 | if (Scope->isAbstractScope()) { |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 802 | ScopeDIE = getCompileUnit(DS)->getDIE(DS); |
Devang Patel | 8aa6147 | 2010-07-07 22:20:57 +0000 | [diff] [blame] | 803 | // Note down abstract DIE. |
| 804 | if (ScopeDIE) |
| 805 | AbstractSPDies.insert(std::make_pair(DS, ScopeDIE)); |
| 806 | } |
Devang Patel | 3c91b05 | 2010-03-08 20:52:55 +0000 | [diff] [blame] | 807 | else |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 808 | ScopeDIE = updateSubprogramScopeDIE(DS); |
Devang Patel | 3c91b05 | 2010-03-08 20:52:55 +0000 | [diff] [blame] | 809 | } |
Devang Patel | 5bc9fec | 2011-02-19 01:31:27 +0000 | [diff] [blame] | 810 | else { |
| 811 | // There is no need to emit empty lexical block DIE. |
| 812 | if (Children.empty()) |
| 813 | return NULL; |
Devang Patel | 3c91b05 | 2010-03-08 20:52:55 +0000 | [diff] [blame] | 814 | ScopeDIE = constructLexicalScopeDIE(Scope); |
Devang Patel | 5bc9fec | 2011-02-19 01:31:27 +0000 | [diff] [blame] | 815 | } |
| 816 | |
Devang Patel | aead63c | 2010-03-29 22:59:58 +0000 | [diff] [blame] | 817 | if (!ScopeDIE) return NULL; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 818 | |
Devang Patel | 5bc9fec | 2011-02-19 01:31:27 +0000 | [diff] [blame] | 819 | // Add children |
| 820 | for (SmallVector<DIE *, 8>::iterator I = Children.begin(), |
| 821 | E = Children.end(); I != E; ++I) |
| 822 | ScopeDIE->addChild(*I); |
Devang Patel | 193f720 | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 823 | |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 824 | if (DS.isSubprogram()) |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 825 | getCompileUnit(DS)->addPubTypes(DISubprogram(DS)); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 826 | |
Devang Patel | 193f720 | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 827 | return ScopeDIE; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 828 | } |
| 829 | |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 830 | /// GetOrCreateSourceID - Look up the source id with the given directory and |
| 831 | /// source file names. If none currently exists, create a new id and insert it |
| 832 | /// in the SourceIds map. This can update DirectoryNames and SourceFileNames |
| 833 | /// maps as well. |
Devang Patel | 2f58485 | 2010-07-24 00:53:22 +0000 | [diff] [blame] | 834 | |
Devang Patel | 23670e5 | 2011-03-24 20:30:50 +0000 | [diff] [blame] | 835 | unsigned DwarfDebug::GetOrCreateSourceID(StringRef FileName, |
| 836 | StringRef DirName) { |
Devang Patel | 1905a18 | 2010-09-16 20:57:49 +0000 | [diff] [blame] | 837 | // If FE did not provide a file name, then assume stdin. |
| 838 | if (FileName.empty()) |
Devang Patel | 23670e5 | 2011-03-24 20:30:50 +0000 | [diff] [blame] | 839 | return GetOrCreateSourceID("<stdin>", StringRef()); |
| 840 | |
| 841 | // MCStream expects full path name as filename. |
Benjamin Kramer | ab5f788 | 2011-06-05 14:36:47 +0000 | [diff] [blame] | 842 | if (!DirName.empty() && !sys::path::is_absolute(FileName)) { |
| 843 | SmallString<128> FullPathName = DirName; |
| 844 | sys::path::append(FullPathName, FileName); |
Devang Patel | 23670e5 | 2011-03-24 20:30:50 +0000 | [diff] [blame] | 845 | // Here FullPathName will be copied into StringMap by GetOrCreateSourceID. |
| 846 | return GetOrCreateSourceID(StringRef(FullPathName), StringRef()); |
| 847 | } |
Devang Patel | 1905a18 | 2010-09-16 20:57:49 +0000 | [diff] [blame] | 848 | |
Rafael Espindola | 5c05563 | 2010-11-18 02:04:25 +0000 | [diff] [blame] | 849 | StringMapEntry<unsigned> &Entry = SourceIdMap.GetOrCreateValue(FileName); |
| 850 | if (Entry.getValue()) |
| 851 | return Entry.getValue(); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 852 | |
Rafael Espindola | 5c05563 | 2010-11-18 02:04:25 +0000 | [diff] [blame] | 853 | unsigned SrcId = SourceIdMap.size(); |
| 854 | Entry.setValue(SrcId); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 855 | |
Rafael Espindola | 5c05563 | 2010-11-18 02:04:25 +0000 | [diff] [blame] | 856 | // Print out a .file directive to specify files for .loc directives. |
Devang Patel | 23670e5 | 2011-03-24 20:30:50 +0000 | [diff] [blame] | 857 | Asm->OutStreamer.EmitDwarfFileDirective(SrcId, Entry.getKey()); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 858 | |
| 859 | return SrcId; |
| 860 | } |
| 861 | |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 862 | /// constructCompileUnit - Create new CompileUnit for the given |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 863 | /// metadata node with tag DW_TAG_compile_unit. |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 864 | void DwarfDebug::constructCompileUnit(const MDNode *N) { |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 865 | DICompileUnit DIUnit(N); |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 866 | StringRef FN = DIUnit.getFilename(); |
| 867 | StringRef Dir = DIUnit.getDirectory(); |
Devang Patel | 23670e5 | 2011-03-24 20:30:50 +0000 | [diff] [blame] | 868 | unsigned ID = GetOrCreateSourceID(FN, Dir); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 869 | |
| 870 | DIE *Die = new DIE(dwarf::DW_TAG_compile_unit); |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 871 | CompileUnit *NewCU = new CompileUnit(ID, Die, Asm, this); |
| 872 | NewCU->addString(Die, dwarf::DW_AT_producer, dwarf::DW_FORM_string, |
| 873 | DIUnit.getProducer()); |
| 874 | NewCU->addUInt(Die, dwarf::DW_AT_language, dwarf::DW_FORM_data2, |
| 875 | DIUnit.getLanguage()); |
| 876 | NewCU->addString(Die, dwarf::DW_AT_name, dwarf::DW_FORM_string, FN); |
Devang Patel | 5098da0 | 2010-04-26 22:54:28 +0000 | [diff] [blame] | 877 | // Use DW_AT_entry_pc instead of DW_AT_low_pc/DW_AT_high_pc pair. This |
| 878 | // simplifies debug range entries. |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 879 | NewCU->addUInt(Die, dwarf::DW_AT_entry_pc, dwarf::DW_FORM_addr, 0); |
Devang Patel | 4a602ca | 2010-03-22 23:11:36 +0000 | [diff] [blame] | 880 | // 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] | 881 | // compile unit in debug_line section. |
Rafael Espindola | dc52ecf | 2011-05-10 20:35:05 +0000 | [diff] [blame] | 882 | if(Asm->MAI->doesDwarfRequireRelocationForSectionOffset()) |
Rafael Espindola | 597a766 | 2011-05-04 17:44:06 +0000 | [diff] [blame] | 883 | NewCU->addLabel(Die, dwarf::DW_AT_stmt_list, dwarf::DW_FORM_data4, |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 884 | Asm->GetTempSymbol("section_line")); |
Devang Patel | ae84d5b | 2010-08-31 23:50:19 +0000 | [diff] [blame] | 885 | else |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 886 | NewCU->addUInt(Die, dwarf::DW_AT_stmt_list, dwarf::DW_FORM_data4, 0); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 887 | |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 888 | if (!Dir.empty()) |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 889 | NewCU->addString(Die, dwarf::DW_AT_comp_dir, dwarf::DW_FORM_string, Dir); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 890 | if (DIUnit.isOptimized()) |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 891 | NewCU->addUInt(Die, dwarf::DW_AT_APPLE_optimized, dwarf::DW_FORM_flag, 1); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 892 | |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 893 | StringRef Flags = DIUnit.getFlags(); |
| 894 | if (!Flags.empty()) |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 895 | NewCU->addString(Die, dwarf::DW_AT_APPLE_flags, dwarf::DW_FORM_string, Flags); |
| 896 | |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 897 | unsigned RVer = DIUnit.getRunTimeVersion(); |
| 898 | if (RVer) |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 899 | NewCU->addUInt(Die, dwarf::DW_AT_APPLE_major_runtime_vers, |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 900 | dwarf::DW_FORM_data1, RVer); |
| 901 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 902 | if (!FirstCU) |
| 903 | FirstCU = NewCU; |
| 904 | CUMap.insert(std::make_pair(N, NewCU)); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 905 | } |
| 906 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 907 | /// getCompielUnit - Get CompileUnit DIE. |
| 908 | CompileUnit *DwarfDebug::getCompileUnit(const MDNode *N) const { |
| 909 | assert (N && "Invalid DwarfDebug::getCompileUnit argument!"); |
| 910 | DIDescriptor D(N); |
| 911 | const MDNode *CUNode = NULL; |
| 912 | if (D.isCompileUnit()) |
| 913 | CUNode = N; |
| 914 | else if (D.isSubprogram()) |
| 915 | CUNode = DISubprogram(N).getCompileUnit(); |
| 916 | else if (D.isType()) |
| 917 | CUNode = DIType(N).getCompileUnit(); |
| 918 | else if (D.isGlobalVariable()) |
| 919 | CUNode = DIGlobalVariable(N).getCompileUnit(); |
| 920 | else if (D.isVariable()) |
| 921 | CUNode = DIVariable(N).getCompileUnit(); |
| 922 | else if (D.isNameSpace()) |
| 923 | CUNode = DINameSpace(N).getCompileUnit(); |
| 924 | else if (D.isFile()) |
| 925 | CUNode = DIFile(N).getCompileUnit(); |
| 926 | else |
| 927 | return FirstCU; |
| 928 | |
| 929 | DenseMap<const MDNode *, CompileUnit *>::const_iterator I |
| 930 | = CUMap.find(CUNode); |
| 931 | if (I == CUMap.end()) |
| 932 | return FirstCU; |
| 933 | return I->second; |
| 934 | } |
| 935 | |
Devang Patel | e449d1f | 2011-01-20 00:02:16 +0000 | [diff] [blame] | 936 | // Return const exprssion if value is a GEP to access merged global |
| 937 | // constant. e.g. |
| 938 | // i8* getelementptr ({ i8, i8, i8, i8 }* @_MergedGlobals, i32 0, i32 0) |
| 939 | static const ConstantExpr *getMergedGlobalExpr(const Value *V) { |
| 940 | const ConstantExpr *CE = dyn_cast_or_null<ConstantExpr>(V); |
| 941 | if (!CE || CE->getNumOperands() != 3 || |
| 942 | CE->getOpcode() != Instruction::GetElementPtr) |
| 943 | return NULL; |
| 944 | |
| 945 | // First operand points to a global value. |
| 946 | if (!isa<GlobalValue>(CE->getOperand(0))) |
| 947 | return NULL; |
| 948 | |
| 949 | // Second operand is zero. |
| 950 | const ConstantInt *CI = |
| 951 | dyn_cast_or_null<ConstantInt>(CE->getOperand(1)); |
| 952 | if (!CI || !CI->isZero()) |
| 953 | return NULL; |
| 954 | |
| 955 | // Third operand is offset. |
| 956 | if (!isa<ConstantInt>(CE->getOperand(2))) |
| 957 | return NULL; |
| 958 | |
| 959 | return CE; |
| 960 | } |
| 961 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 962 | /// constructGlobalVariableDIE - Construct global variable DIE. |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 963 | void DwarfDebug::constructGlobalVariableDIE(const MDNode *N) { |
Devang Patel | 9fa539c | 2010-08-10 01:37:23 +0000 | [diff] [blame] | 964 | DIGlobalVariable GV(N); |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 965 | |
Devang Patel | 905cf5e | 2009-09-04 23:59:07 +0000 | [diff] [blame] | 966 | // If debug information is malformed then ignore it. |
Devang Patel | 9fa539c | 2010-08-10 01:37:23 +0000 | [diff] [blame] | 967 | if (GV.Verify() == false) |
Devang Patel | 905cf5e | 2009-09-04 23:59:07 +0000 | [diff] [blame] | 968 | return; |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 969 | |
| 970 | // Check for pre-existence. |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 971 | CompileUnit *TheCU = getCompileUnit(N); |
Devang Patel | 9fa539c | 2010-08-10 01:37:23 +0000 | [diff] [blame] | 972 | if (TheCU->getDIE(GV)) |
Devang Patel | 13e16b6 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 973 | return; |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 974 | |
Devang Patel | 9fa539c | 2010-08-10 01:37:23 +0000 | [diff] [blame] | 975 | DIType GTy = GV.getType(); |
Devang Patel | 2936807 | 2010-08-10 07:11:13 +0000 | [diff] [blame] | 976 | DIE *VariableDIE = new DIE(GV.getTag()); |
| 977 | |
| 978 | bool isGlobalVariable = GV.getGlobal() != NULL; |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 979 | |
Devang Patel | 9fa539c | 2010-08-10 01:37:23 +0000 | [diff] [blame] | 980 | // Add name. |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 981 | TheCU->addString(VariableDIE, dwarf::DW_AT_name, dwarf::DW_FORM_string, |
| 982 | GV.getDisplayName()); |
Devang Patel | 9fa539c | 2010-08-10 01:37:23 +0000 | [diff] [blame] | 983 | StringRef LinkageName = GV.getLinkageName(); |
Devang Patel | 2936807 | 2010-08-10 07:11:13 +0000 | [diff] [blame] | 984 | if (!LinkageName.empty() && isGlobalVariable) |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 985 | TheCU->addString(VariableDIE, dwarf::DW_AT_MIPS_linkage_name, |
| 986 | dwarf::DW_FORM_string, |
| 987 | getRealLinkageName(LinkageName)); |
Devang Patel | 9fa539c | 2010-08-10 01:37:23 +0000 | [diff] [blame] | 988 | // Add type. |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 989 | TheCU->addType(VariableDIE, GTy); |
Devang Patel | e9ae06c | 2011-05-31 22:56:51 +0000 | [diff] [blame] | 990 | |
Devang Patel | 9fa539c | 2010-08-10 01:37:23 +0000 | [diff] [blame] | 991 | // Add scoping info. |
| 992 | if (!GV.isLocalToUnit()) { |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 993 | TheCU->addUInt(VariableDIE, dwarf::DW_AT_external, dwarf::DW_FORM_flag, 1); |
Devang Patel | 9fa539c | 2010-08-10 01:37:23 +0000 | [diff] [blame] | 994 | // Expose as global. |
| 995 | TheCU->addGlobal(GV.getName(), VariableDIE); |
| 996 | } |
| 997 | // Add line number info. |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 998 | TheCU->addSourceLine(VariableDIE, GV); |
Devang Patel | 9fa539c | 2010-08-10 01:37:23 +0000 | [diff] [blame] | 999 | // Add to map. |
| 1000 | TheCU->insertDIE(N, VariableDIE); |
| 1001 | // Add to context owner. |
| 1002 | DIDescriptor GVContext = GV.getContext(); |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 1003 | TheCU->addToContextOwner(VariableDIE, GVContext); |
Devang Patel | 9fa539c | 2010-08-10 01:37:23 +0000 | [diff] [blame] | 1004 | // Add location. |
Devang Patel | 2936807 | 2010-08-10 07:11:13 +0000 | [diff] [blame] | 1005 | if (isGlobalVariable) { |
| 1006 | DIEBlock *Block = new (DIEValueAllocator) DIEBlock(); |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 1007 | TheCU->addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_addr); |
| 1008 | TheCU->addLabel(Block, 0, dwarf::DW_FORM_udata, |
Devang Patel | 2936807 | 2010-08-10 07:11:13 +0000 | [diff] [blame] | 1009 | Asm->Mang->getSymbol(GV.getGlobal())); |
| 1010 | // Do not create specification DIE if context is either compile unit |
| 1011 | // or a subprogram. |
| 1012 | if (GV.isDefinition() && !GVContext.isCompileUnit() && |
| 1013 | !GVContext.isFile() && !isSubprogramContext(GVContext)) { |
| 1014 | // Create specification DIE. |
| 1015 | DIE *VariableSpecDIE = new DIE(dwarf::DW_TAG_variable); |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 1016 | TheCU->addDIEEntry(VariableSpecDIE, dwarf::DW_AT_specification, |
Devang Patel | 2936807 | 2010-08-10 07:11:13 +0000 | [diff] [blame] | 1017 | dwarf::DW_FORM_ref4, VariableDIE); |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 1018 | TheCU->addBlock(VariableSpecDIE, dwarf::DW_AT_location, 0, Block); |
| 1019 | TheCU->addUInt(VariableDIE, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag, 1); |
Devang Patel | 2936807 | 2010-08-10 07:11:13 +0000 | [diff] [blame] | 1020 | TheCU->addDie(VariableSpecDIE); |
| 1021 | } else { |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 1022 | TheCU->addBlock(VariableDIE, dwarf::DW_AT_location, 0, Block); |
Devang Patel | 2936807 | 2010-08-10 07:11:13 +0000 | [diff] [blame] | 1023 | } |
Devang Patel | 8594d42 | 2011-06-24 20:46:11 +0000 | [diff] [blame^] | 1024 | } else if (const ConstantInt *CI = |
Devang Patel | 76a788c | 2011-01-06 21:39:25 +0000 | [diff] [blame] | 1025 | dyn_cast_or_null<ConstantInt>(GV.getConstant())) |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 1026 | TheCU->addConstantValue(VariableDIE, CI, isUnsignedDIType(GTy)); |
Devang Patel | e449d1f | 2011-01-20 00:02:16 +0000 | [diff] [blame] | 1027 | else if (const ConstantExpr *CE = getMergedGlobalExpr(N->getOperand(11))) { |
| 1028 | // GV is a merged global. |
| 1029 | DIEBlock *Block = new (DIEValueAllocator) DIEBlock(); |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 1030 | TheCU->addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_addr); |
| 1031 | TheCU->addLabel(Block, 0, dwarf::DW_FORM_udata, |
| 1032 | Asm->Mang->getSymbol(cast<GlobalValue>(CE->getOperand(0)))); |
Devang Patel | e449d1f | 2011-01-20 00:02:16 +0000 | [diff] [blame] | 1033 | ConstantInt *CII = cast<ConstantInt>(CE->getOperand(2)); |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 1034 | TheCU->addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_constu); |
| 1035 | TheCU->addUInt(Block, 0, dwarf::DW_FORM_udata, CII->getZExtValue()); |
| 1036 | TheCU->addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_plus); |
| 1037 | TheCU->addBlock(VariableDIE, dwarf::DW_AT_location, 0, Block); |
Devang Patel | e449d1f | 2011-01-20 00:02:16 +0000 | [diff] [blame] | 1038 | } |
Devang Patel | 76a788c | 2011-01-06 21:39:25 +0000 | [diff] [blame] | 1039 | |
Devang Patel | 13e16b6 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 1040 | return; |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1041 | } |
| 1042 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1043 | /// construct SubprogramDIE - Construct subprogram DIE. |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 1044 | void DwarfDebug::constructSubprogramDIE(const MDNode *N) { |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1045 | DISubprogram SP(N); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1046 | |
Stuart Hastings | 639336e | 2010-04-06 21:38:29 +0000 | [diff] [blame] | 1047 | // Check for pre-existence. |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1048 | CompileUnit *TheCU = getCompileUnit(N); |
| 1049 | if (TheCU->getDIE(N)) |
Stuart Hastings | 639336e | 2010-04-06 21:38:29 +0000 | [diff] [blame] | 1050 | return; |
| 1051 | |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1052 | if (!SP.isDefinition()) |
| 1053 | // This is a method declaration which will be handled while constructing |
| 1054 | // class type. |
Devang Patel | 13e16b6 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 1055 | return; |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1056 | |
Stuart Hastings | 639336e | 2010-04-06 21:38:29 +0000 | [diff] [blame] | 1057 | DIE *SubprogramDie = createSubprogramDIE(SP); |
| 1058 | |
| 1059 | // Add to map. |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1060 | TheCU->insertDIE(N, SubprogramDie); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1061 | |
| 1062 | // Add to context owner. |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 1063 | TheCU->addToContextOwner(SubprogramDie, SP.getContext()); |
Devang Patel | 0000fad | 2009-12-08 23:21:45 +0000 | [diff] [blame] | 1064 | |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1065 | // Expose as global. |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1066 | TheCU->addGlobal(SP.getName(), SubprogramDie); |
Devang Patel | 193f720 | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 1067 | |
Devang Patel | 13e16b6 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 1068 | return; |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1069 | } |
| 1070 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1071 | /// beginModule - Emit all Dwarf sections that should come prior to the |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 1072 | /// content. Create global DIEs and emit initial debug info sections. |
| 1073 | /// This is inovked by the target AsmPrinter. |
Chris Lattner | 75f5072 | 2010-04-04 07:48:20 +0000 | [diff] [blame] | 1074 | void DwarfDebug::beginModule(Module *M) { |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1075 | if (DisableDebugInfoPrinting) |
| 1076 | return; |
| 1077 | |
Devang Patel | 30692ab | 2011-05-03 16:45:22 +0000 | [diff] [blame] | 1078 | // If module has named metadata anchors then use them, otherwise scan the module |
| 1079 | // using debug info finder to collect debug info. |
| 1080 | NamedMDNode *CU_Nodes = M->getNamedMetadata("llvm.dbg.cu"); |
| 1081 | if (CU_Nodes) { |
Devang Patel | a938dd0 | 2011-05-04 16:34:02 +0000 | [diff] [blame] | 1082 | |
| 1083 | NamedMDNode *GV_Nodes = M->getNamedMetadata("llvm.dbg.gv"); |
| 1084 | NamedMDNode *SP_Nodes = M->getNamedMetadata("llvm.dbg.sp"); |
| 1085 | if (!GV_Nodes && !SP_Nodes) |
| 1086 | // If there are not any global variables or any functions then |
| 1087 | // there is not any debug info in this module. |
Devang Patel | 30692ab | 2011-05-03 16:45:22 +0000 | [diff] [blame] | 1088 | return; |
| 1089 | |
Devang Patel | a938dd0 | 2011-05-04 16:34:02 +0000 | [diff] [blame] | 1090 | for (unsigned i = 0, e = CU_Nodes->getNumOperands(); i != e; ++i) |
| 1091 | constructCompileUnit(CU_Nodes->getOperand(i)); |
Devang Patel | 30692ab | 2011-05-03 16:45:22 +0000 | [diff] [blame] | 1092 | |
Devang Patel | a938dd0 | 2011-05-04 16:34:02 +0000 | [diff] [blame] | 1093 | if (GV_Nodes) |
| 1094 | for (unsigned i = 0, e = GV_Nodes->getNumOperands(); i != e; ++i) |
| 1095 | constructGlobalVariableDIE(GV_Nodes->getOperand(i)); |
| 1096 | |
| 1097 | if (SP_Nodes) |
| 1098 | for (unsigned i = 0, e = SP_Nodes->getNumOperands(); i != e; ++i) |
| 1099 | constructSubprogramDIE(SP_Nodes->getOperand(i)); |
Devang Patel | 30692ab | 2011-05-03 16:45:22 +0000 | [diff] [blame] | 1100 | |
| 1101 | } else { |
| 1102 | |
| 1103 | DebugInfoFinder DbgFinder; |
| 1104 | DbgFinder.processModule(*M); |
| 1105 | |
Devang Patel | a938dd0 | 2011-05-04 16:34:02 +0000 | [diff] [blame] | 1106 | bool HasDebugInfo = false; |
Devang Patel | 30692ab | 2011-05-03 16:45:22 +0000 | [diff] [blame] | 1107 | // Scan all the compile-units to see if there are any marked as the main unit. |
| 1108 | // if not, we do not generate debug info. |
| 1109 | for (DebugInfoFinder::iterator I = DbgFinder.compile_unit_begin(), |
| 1110 | E = DbgFinder.compile_unit_end(); I != E; ++I) { |
| 1111 | if (DICompileUnit(*I).isMain()) { |
| 1112 | HasDebugInfo = true; |
| 1113 | break; |
| 1114 | } |
| 1115 | } |
Devang Patel | a938dd0 | 2011-05-04 16:34:02 +0000 | [diff] [blame] | 1116 | if (!HasDebugInfo) return; |
Devang Patel | 30692ab | 2011-05-03 16:45:22 +0000 | [diff] [blame] | 1117 | |
| 1118 | // Create all the compile unit DIEs. |
| 1119 | for (DebugInfoFinder::iterator I = DbgFinder.compile_unit_begin(), |
| 1120 | E = DbgFinder.compile_unit_end(); I != E; ++I) |
| 1121 | constructCompileUnit(*I); |
| 1122 | |
| 1123 | // Create DIEs for each global variable. |
| 1124 | for (DebugInfoFinder::iterator I = DbgFinder.global_variable_begin(), |
| 1125 | E = DbgFinder.global_variable_end(); I != E; ++I) |
| 1126 | constructGlobalVariableDIE(*I); |
| 1127 | |
| 1128 | // Create DIEs for each subprogram. |
| 1129 | for (DebugInfoFinder::iterator I = DbgFinder.subprogram_begin(), |
| 1130 | E = DbgFinder.subprogram_end(); I != E; ++I) |
| 1131 | constructSubprogramDIE(*I); |
Chris Lattner | d850ac7 | 2010-04-05 02:19:28 +0000 | [diff] [blame] | 1132 | } |
Devang Patel | 30692ab | 2011-05-03 16:45:22 +0000 | [diff] [blame] | 1133 | |
Chris Lattner | d850ac7 | 2010-04-05 02:19:28 +0000 | [diff] [blame] | 1134 | // Tell MMI that we have debug info. |
| 1135 | MMI->setDebugInfoAvailability(true); |
Devang Patel | 30692ab | 2011-05-03 16:45:22 +0000 | [diff] [blame] | 1136 | |
Chris Lattner | be15beb | 2010-04-04 23:17:54 +0000 | [diff] [blame] | 1137 | // Emit initial sections. |
Chris Lattner | d850ac7 | 2010-04-05 02:19:28 +0000 | [diff] [blame] | 1138 | EmitSectionLabels(); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1139 | |
Devang Patel | e7e5a0f | 2010-08-10 20:01:20 +0000 | [diff] [blame] | 1140 | //getOrCreateTypeDIE |
| 1141 | if (NamedMDNode *NMD = M->getNamedMetadata("llvm.dbg.enum")) |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 1142 | for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) { |
| 1143 | DIType Ty(NMD->getOperand(i)); |
| 1144 | getCompileUnit(Ty)->getOrCreateTypeDIE(Ty); |
| 1145 | } |
Devang Patel | e7e5a0f | 2010-08-10 20:01:20 +0000 | [diff] [blame] | 1146 | |
Devang Patel | 1a7ca03 | 2010-09-28 18:08:20 +0000 | [diff] [blame] | 1147 | if (NamedMDNode *NMD = M->getNamedMetadata("llvm.dbg.ty")) |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 1148 | for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) { |
| 1149 | DIType Ty(NMD->getOperand(i)); |
| 1150 | getCompileUnit(Ty)->getOrCreateTypeDIE(Ty); |
| 1151 | } |
Devang Patel | 1a7ca03 | 2010-09-28 18:08:20 +0000 | [diff] [blame] | 1152 | |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1153 | // Prime section data. |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 1154 | SectionMap.insert(Asm->getObjFileLowering().getTextSection()); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1155 | } |
| 1156 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1157 | /// endModule - Emit all Dwarf sections that should come after the content. |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1158 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1159 | void DwarfDebug::endModule() { |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1160 | if (!FirstCU) return; |
Devang Patel | 4a1cad6 | 2010-06-28 18:25:03 +0000 | [diff] [blame] | 1161 | const Module *M = MMI->getModule(); |
Devang Patel | e9a1cca | 2010-08-02 17:32:15 +0000 | [diff] [blame] | 1162 | DenseMap<const MDNode *, DbgScope *> DeadFnScopeMap; |
Devang Patel | 4a1cad6 | 2010-06-28 18:25:03 +0000 | [diff] [blame] | 1163 | if (NamedMDNode *AllSPs = M->getNamedMetadata("llvm.dbg.sp")) { |
| 1164 | for (unsigned SI = 0, SE = AllSPs->getNumOperands(); SI != SE; ++SI) { |
| 1165 | if (ProcessedSPNodes.count(AllSPs->getOperand(SI)) != 0) continue; |
| 1166 | DISubprogram SP(AllSPs->getOperand(SI)); |
| 1167 | if (!SP.Verify()) continue; |
| 1168 | |
| 1169 | // Collect info for variables that were optimized out. |
Devang Patel | 8b3a6b6 | 2010-07-19 17:53:55 +0000 | [diff] [blame] | 1170 | if (!SP.isDefinition()) continue; |
Devang Patel | 4a1cad6 | 2010-06-28 18:25:03 +0000 | [diff] [blame] | 1171 | StringRef FName = SP.getLinkageName(); |
| 1172 | if (FName.empty()) |
| 1173 | FName = SP.getName(); |
Devang Patel | 6236704 | 2010-11-10 22:19:21 +0000 | [diff] [blame] | 1174 | NamedMDNode *NMD = getFnSpecificMDNode(*(MMI->getModule()), FName); |
Devang Patel | 4a1cad6 | 2010-06-28 18:25:03 +0000 | [diff] [blame] | 1175 | if (!NMD) continue; |
| 1176 | unsigned E = NMD->getNumOperands(); |
| 1177 | if (!E) continue; |
| 1178 | DbgScope *Scope = new DbgScope(NULL, DIDescriptor(SP), NULL); |
Devang Patel | e9a1cca | 2010-08-02 17:32:15 +0000 | [diff] [blame] | 1179 | DeadFnScopeMap[SP] = Scope; |
Devang Patel | 4a1cad6 | 2010-06-28 18:25:03 +0000 | [diff] [blame] | 1180 | for (unsigned I = 0; I != E; ++I) { |
| 1181 | DIVariable DV(NMD->getOperand(I)); |
| 1182 | if (!DV.Verify()) continue; |
| 1183 | Scope->addVariable(new DbgVariable(DV)); |
| 1184 | } |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1185 | |
Devang Patel | 4a1cad6 | 2010-06-28 18:25:03 +0000 | [diff] [blame] | 1186 | // Construct subprogram DIE and add variables DIEs. |
| 1187 | constructSubprogramDIE(SP); |
| 1188 | DIE *ScopeDIE = getCompileUnit(SP)->getDIE(SP); |
Devang Patel | e03161c | 2010-08-09 18:51:29 +0000 | [diff] [blame] | 1189 | const SmallVector<DbgVariable *, 8> &Variables = Scope->getDbgVariables(); |
Devang Patel | 4a1cad6 | 2010-06-28 18:25:03 +0000 | [diff] [blame] | 1190 | for (unsigned i = 0, N = Variables.size(); i < N; ++i) { |
| 1191 | DIE *VariableDIE = constructVariableDIE(Variables[i], Scope); |
| 1192 | if (VariableDIE) |
| 1193 | ScopeDIE->addChild(VariableDIE); |
| 1194 | } |
| 1195 | } |
| 1196 | } |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1197 | |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1198 | // Attach DW_AT_inline attribute with inlined subprogram DIEs. |
| 1199 | for (SmallPtrSet<DIE *, 4>::iterator AI = InlinedSubprogramDIEs.begin(), |
| 1200 | AE = InlinedSubprogramDIEs.end(); AI != AE; ++AI) { |
| 1201 | DIE *ISP = *AI; |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 1202 | FirstCU->addUInt(ISP, dwarf::DW_AT_inline, 0, dwarf::DW_INL_inlined); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1203 | } |
| 1204 | |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 1205 | for (DenseMap<DIE *, const MDNode *>::iterator CI = ContainingTypeMap.begin(), |
Devang Patel | 5d11eb0 | 2009-12-03 19:11:07 +0000 | [diff] [blame] | 1206 | CE = ContainingTypeMap.end(); CI != CE; ++CI) { |
| 1207 | DIE *SPDie = CI->first; |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 1208 | const MDNode *N = dyn_cast_or_null<MDNode>(CI->second); |
Devang Patel | 5d11eb0 | 2009-12-03 19:11:07 +0000 | [diff] [blame] | 1209 | if (!N) continue; |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1210 | DIE *NDie = getCompileUnit(N)->getDIE(N); |
Devang Patel | 5d11eb0 | 2009-12-03 19:11:07 +0000 | [diff] [blame] | 1211 | if (!NDie) continue; |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 1212 | getCompileUnit(N)->addDIEEntry(SPDie, dwarf::DW_AT_containing_type, |
| 1213 | dwarf::DW_FORM_ref4, NDie); |
Devang Patel | 5d11eb0 | 2009-12-03 19:11:07 +0000 | [diff] [blame] | 1214 | } |
| 1215 | |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1216 | // Standard sections final addresses. |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 1217 | Asm->OutStreamer.SwitchSection(Asm->getObjFileLowering().getTextSection()); |
Chris Lattner | c021572 | 2010-04-04 19:25:43 +0000 | [diff] [blame] | 1218 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("text_end")); |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 1219 | Asm->OutStreamer.SwitchSection(Asm->getObjFileLowering().getDataSection()); |
Chris Lattner | c021572 | 2010-04-04 19:25:43 +0000 | [diff] [blame] | 1220 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("data_end")); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1221 | |
| 1222 | // End text sections. |
| 1223 | for (unsigned i = 1, N = SectionMap.size(); i <= N; ++i) { |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 1224 | Asm->OutStreamer.SwitchSection(SectionMap[i]); |
Chris Lattner | c021572 | 2010-04-04 19:25:43 +0000 | [diff] [blame] | 1225 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("section_end", i)); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1226 | } |
| 1227 | |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1228 | // Compute DIE offsets and sizes. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1229 | computeSizeAndOffsets(); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1230 | |
| 1231 | // Emit all the DIEs into a debug info section |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1232 | emitDebugInfo(); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1233 | |
| 1234 | // Corresponding abbreviations into a abbrev section. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1235 | emitAbbreviations(); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1236 | |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1237 | // Emit info into a debug pubnames section. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1238 | emitDebugPubNames(); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1239 | |
Devang Patel | 193f720 | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 1240 | // Emit info into a debug pubtypes section. |
| 1241 | emitDebugPubTypes(); |
| 1242 | |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1243 | // Emit info into a debug loc section. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1244 | emitDebugLoc(); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1245 | |
| 1246 | // Emit info into a debug aranges section. |
| 1247 | EmitDebugARanges(); |
| 1248 | |
| 1249 | // Emit info into a debug ranges section. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1250 | emitDebugRanges(); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1251 | |
| 1252 | // Emit info into a debug macinfo section. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1253 | emitDebugMacInfo(); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1254 | |
| 1255 | // Emit inline info. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1256 | emitDebugInlineInfo(); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1257 | |
Chris Lattner | bc733f5 | 2010-03-13 02:17:42 +0000 | [diff] [blame] | 1258 | // Emit info into a debug str section. |
| 1259 | emitDebugStr(); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1260 | |
Devang Patel | e9a1cca | 2010-08-02 17:32:15 +0000 | [diff] [blame] | 1261 | // clean up. |
| 1262 | DeleteContainerSeconds(DeadFnScopeMap); |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 1263 | for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(), |
| 1264 | E = CUMap.end(); I != E; ++I) |
| 1265 | delete I->second; |
| 1266 | FirstCU = NULL; // Reset for the next Module, if any. |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1267 | } |
| 1268 | |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1269 | /// findAbstractVariable - Find abstract variable, if any, associated with Var. |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1270 | DbgVariable *DwarfDebug::findAbstractVariable(DIVariable &Var, |
Chris Lattner | de4845c | 2010-04-02 19:42:39 +0000 | [diff] [blame] | 1271 | DebugLoc ScopeLoc) { |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1272 | |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 1273 | DbgVariable *AbsDbgVariable = AbstractVariables.lookup(Var); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1274 | if (AbsDbgVariable) |
| 1275 | return AbsDbgVariable; |
| 1276 | |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 1277 | LLVMContext &Ctx = Var->getContext(); |
Chris Lattner | de4845c | 2010-04-02 19:42:39 +0000 | [diff] [blame] | 1278 | DbgScope *Scope = AbstractScopes.lookup(ScopeLoc.getScope(Ctx)); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1279 | if (!Scope) |
| 1280 | return NULL; |
| 1281 | |
Devang Patel | 26c1e56 | 2010-05-20 16:36:41 +0000 | [diff] [blame] | 1282 | AbsDbgVariable = new DbgVariable(Var); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1283 | Scope->addVariable(AbsDbgVariable); |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 1284 | AbstractVariables[Var] = AbsDbgVariable; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1285 | return AbsDbgVariable; |
| 1286 | } |
| 1287 | |
Devang Patel | 0478c15 | 2011-03-01 22:58:55 +0000 | [diff] [blame] | 1288 | /// addCurrentFnArgument - If Var is an current function argument that add |
| 1289 | /// it in CurrentFnArguments list. |
| 1290 | bool DwarfDebug::addCurrentFnArgument(const MachineFunction *MF, |
| 1291 | DbgVariable *Var, DbgScope *Scope) { |
| 1292 | if (Scope != CurrentFnDbgScope) |
| 1293 | return false; |
| 1294 | DIVariable DV = Var->getVariable(); |
| 1295 | if (DV.getTag() != dwarf::DW_TAG_arg_variable) |
| 1296 | return false; |
| 1297 | unsigned ArgNo = DV.getArgNumber(); |
| 1298 | if (ArgNo == 0) |
| 1299 | return false; |
| 1300 | |
Devang Patel | cb3a657 | 2011-03-03 20:02:02 +0000 | [diff] [blame] | 1301 | size_t Size = CurrentFnArguments.size(); |
| 1302 | if (Size == 0) |
Devang Patel | 0478c15 | 2011-03-01 22:58:55 +0000 | [diff] [blame] | 1303 | CurrentFnArguments.resize(MF->getFunction()->arg_size()); |
Devang Patel | bbd0f45 | 2011-03-03 21:49:41 +0000 | [diff] [blame] | 1304 | // llvm::Function argument size is not good indicator of how many |
Devang Patel | 6f676be | 2011-03-03 20:08:10 +0000 | [diff] [blame] | 1305 | // arguments does the function have at source level. |
| 1306 | if (ArgNo > Size) |
Devang Patel | cb3a657 | 2011-03-03 20:02:02 +0000 | [diff] [blame] | 1307 | CurrentFnArguments.resize(ArgNo * 2); |
Devang Patel | 0478c15 | 2011-03-01 22:58:55 +0000 | [diff] [blame] | 1308 | CurrentFnArguments[ArgNo - 1] = Var; |
| 1309 | return true; |
| 1310 | } |
| 1311 | |
Devang Patel | ee43286 | 2010-05-20 19:57:06 +0000 | [diff] [blame] | 1312 | /// collectVariableInfoFromMMITable - Collect variable information from |
| 1313 | /// side table maintained by MMI. |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1314 | void |
Devang Patel | ee43286 | 2010-05-20 19:57:06 +0000 | [diff] [blame] | 1315 | DwarfDebug::collectVariableInfoFromMMITable(const MachineFunction * MF, |
| 1316 | SmallPtrSet<const MDNode *, 16> &Processed) { |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 1317 | const LLVMContext &Ctx = Asm->MF->getFunction()->getContext(); |
Devang Patel | e717faa | 2009-10-06 01:26:37 +0000 | [diff] [blame] | 1318 | MachineModuleInfo::VariableDbgInfoMapTy &VMap = MMI->getVariableDbgInfo(); |
| 1319 | for (MachineModuleInfo::VariableDbgInfoMapTy::iterator VI = VMap.begin(), |
| 1320 | VE = VMap.end(); VI != VE; ++VI) { |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 1321 | const MDNode *Var = VI->first; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1322 | if (!Var) continue; |
Devang Patel | 98e1cac | 2010-05-14 21:01:35 +0000 | [diff] [blame] | 1323 | Processed.insert(Var); |
Chris Lattner | de4845c | 2010-04-02 19:42:39 +0000 | [diff] [blame] | 1324 | DIVariable DV(Var); |
| 1325 | const std::pair<unsigned, DebugLoc> &VP = VI->second; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1326 | |
Chris Lattner | de4845c | 2010-04-02 19:42:39 +0000 | [diff] [blame] | 1327 | DbgScope *Scope = 0; |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 1328 | if (const MDNode *IA = VP.second.getInlinedAt(Ctx)) |
Chris Lattner | de4845c | 2010-04-02 19:42:39 +0000 | [diff] [blame] | 1329 | Scope = ConcreteScopes.lookup(IA); |
| 1330 | if (Scope == 0) |
| 1331 | Scope = DbgScopeMap.lookup(VP.second.getScope(Ctx)); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1332 | |
Devang Patel | fb0ee43 | 2009-11-10 23:20:04 +0000 | [diff] [blame] | 1333 | // If variable scope is not found then skip this variable. |
Chris Lattner | de4845c | 2010-04-02 19:42:39 +0000 | [diff] [blame] | 1334 | if (Scope == 0) |
Devang Patel | fb0ee43 | 2009-11-10 23:20:04 +0000 | [diff] [blame] | 1335 | continue; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1336 | |
Devang Patel | 26c1e56 | 2010-05-20 16:36:41 +0000 | [diff] [blame] | 1337 | DbgVariable *AbsDbgVariable = findAbstractVariable(DV, VP.second); |
| 1338 | DbgVariable *RegVar = new DbgVariable(DV); |
| 1339 | recordVariableFrameIndex(RegVar, VP.first); |
Devang Patel | 0478c15 | 2011-03-01 22:58:55 +0000 | [diff] [blame] | 1340 | if (!addCurrentFnArgument(MF, RegVar, Scope)) |
| 1341 | Scope->addVariable(RegVar); |
Devang Patel | 26c1e56 | 2010-05-20 16:36:41 +0000 | [diff] [blame] | 1342 | if (AbsDbgVariable) { |
| 1343 | recordVariableFrameIndex(AbsDbgVariable, VP.first); |
| 1344 | VarToAbstractVarMap[RegVar] = AbsDbgVariable; |
| 1345 | } |
Devang Patel | e717faa | 2009-10-06 01:26:37 +0000 | [diff] [blame] | 1346 | } |
Devang Patel | ee43286 | 2010-05-20 19:57:06 +0000 | [diff] [blame] | 1347 | } |
Devang Patel | 90a48ad | 2010-03-15 18:33:46 +0000 | [diff] [blame] | 1348 | |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1349 | /// isDbgValueInDefinedReg - Return true if debug value, encoded by |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 1350 | /// DBG_VALUE instruction, is in a defined reg. |
| 1351 | static bool isDbgValueInDefinedReg(const MachineInstr *MI) { |
| 1352 | assert (MI->isDebugValue() && "Invalid DBG_VALUE machine instruction!"); |
Jakob Stoklund Olesen | 28cf115 | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 1353 | return MI->getNumOperands() == 3 && |
| 1354 | MI->getOperand(0).isReg() && MI->getOperand(0).getReg() && |
| 1355 | MI->getOperand(1).isImm() && MI->getOperand(1).getImm() == 0; |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 1356 | } |
| 1357 | |
Devang Patel | ee43286 | 2010-05-20 19:57:06 +0000 | [diff] [blame] | 1358 | /// collectVariableInfo - Populate DbgScope entries with variables' info. |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1359 | void |
Devang Patel | 78e127d | 2010-06-25 22:07:34 +0000 | [diff] [blame] | 1360 | DwarfDebug::collectVariableInfo(const MachineFunction *MF, |
| 1361 | SmallPtrSet<const MDNode *, 16> &Processed) { |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1362 | |
Devang Patel | ee43286 | 2010-05-20 19:57:06 +0000 | [diff] [blame] | 1363 | /// collection info from MMI table. |
| 1364 | collectVariableInfoFromMMITable(MF, Processed); |
| 1365 | |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1366 | for (SmallVectorImpl<const MDNode*>::const_iterator |
| 1367 | UVI = UserVariables.begin(), UVE = UserVariables.end(); UVI != UVE; |
| 1368 | ++UVI) { |
| 1369 | const MDNode *Var = *UVI; |
| 1370 | if (Processed.count(Var)) |
Devang Patel | ee43286 | 2010-05-20 19:57:06 +0000 | [diff] [blame] | 1371 | continue; |
| 1372 | |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1373 | // History contains relevant DBG_VALUE instructions for Var and instructions |
| 1374 | // clobbering it. |
| 1375 | SmallVectorImpl<const MachineInstr*> &History = DbgValues[Var]; |
| 1376 | if (History.empty()) |
| 1377 | continue; |
| 1378 | const MachineInstr *MInsn = History.front(); |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 1379 | |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1380 | DIVariable DV(Var); |
Devang Patel | a36478f | 2011-01-11 21:42:10 +0000 | [diff] [blame] | 1381 | DbgScope *Scope = NULL; |
Devang Patel | d8720f4 | 2010-05-27 20:25:04 +0000 | [diff] [blame] | 1382 | if (DV.getTag() == dwarf::DW_TAG_arg_variable && |
| 1383 | DISubprogram(DV.getContext()).describes(MF->getFunction())) |
Devang Patel | c0c5a26 | 2010-05-21 00:10:20 +0000 | [diff] [blame] | 1384 | Scope = CurrentFnDbgScope; |
Devang Patel | a36478f | 2011-01-11 21:42:10 +0000 | [diff] [blame] | 1385 | else |
| 1386 | Scope = findDbgScope(MInsn); |
Devang Patel | ee43286 | 2010-05-20 19:57:06 +0000 | [diff] [blame] | 1387 | // If variable scope is not found then skip this variable. |
Devang Patel | c0c5a26 | 2010-05-21 00:10:20 +0000 | [diff] [blame] | 1388 | if (!Scope) |
Devang Patel | ee43286 | 2010-05-20 19:57:06 +0000 | [diff] [blame] | 1389 | continue; |
| 1390 | |
| 1391 | Processed.insert(DV); |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1392 | assert(MInsn->isDebugValue() && "History must begin with debug value"); |
Devang Patel | ee43286 | 2010-05-20 19:57:06 +0000 | [diff] [blame] | 1393 | DbgVariable *RegVar = new DbgVariable(DV); |
Devang Patel | 0478c15 | 2011-03-01 22:58:55 +0000 | [diff] [blame] | 1394 | if (!addCurrentFnArgument(MF, RegVar, Scope)) |
| 1395 | Scope->addVariable(RegVar); |
Devang Patel | c0c5a26 | 2010-05-21 00:10:20 +0000 | [diff] [blame] | 1396 | if (DbgVariable *AbsVar = findAbstractVariable(DV, MInsn->getDebugLoc())) { |
| 1397 | DbgVariableToDbgInstMap[AbsVar] = MInsn; |
| 1398 | VarToAbstractVarMap[RegVar] = AbsVar; |
Devang Patel | 90a48ad | 2010-03-15 18:33:46 +0000 | [diff] [blame] | 1399 | } |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1400 | |
| 1401 | // Simple ranges that are fully coalesced. |
| 1402 | if (History.size() <= 1 || (History.size() == 2 && |
| 1403 | MInsn->isIdenticalTo(History.back()))) { |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 1404 | DbgVariableToDbgInstMap[RegVar] = MInsn; |
| 1405 | continue; |
| 1406 | } |
| 1407 | |
| 1408 | // handle multiple DBG_VALUE instructions describing one variable. |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1409 | RegVar->setDotDebugLocOffset(DotDebugLocEntries.size()); |
Jakob Stoklund Olesen | 28cf115 | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 1410 | |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1411 | for (SmallVectorImpl<const MachineInstr*>::const_iterator |
| 1412 | HI = History.begin(), HE = History.end(); HI != HE; ++HI) { |
| 1413 | const MachineInstr *Begin = *HI; |
| 1414 | assert(Begin->isDebugValue() && "Invalid History entry"); |
Jakob Stoklund Olesen | e17232e | 2011-03-22 00:21:41 +0000 | [diff] [blame] | 1415 | |
Devang Patel | 4ada1d7 | 2011-06-01 23:00:17 +0000 | [diff] [blame] | 1416 | // Check if DBG_VALUE is truncating a range. |
| 1417 | if (Begin->getNumOperands() > 1 && Begin->getOperand(0).isReg() |
| 1418 | && !Begin->getOperand(0).getReg()) |
| 1419 | continue; |
| 1420 | |
Jakob Stoklund Olesen | 28cf115 | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 1421 | // Compute the range for a register location. |
| 1422 | const MCSymbol *FLabel = getLabelBeforeInsn(Begin); |
| 1423 | const MCSymbol *SLabel = 0; |
| 1424 | |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1425 | if (HI + 1 == HE) |
| 1426 | // If Begin is the last instruction in History then its value is valid |
Chris Lattner | 7a2bdde | 2011-04-15 05:18:47 +0000 | [diff] [blame] | 1427 | // until the end of the function. |
Jakob Stoklund Olesen | 28cf115 | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 1428 | SLabel = FunctionEndSym; |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1429 | else { |
| 1430 | const MachineInstr *End = HI[1]; |
| 1431 | if (End->isDebugValue()) |
| 1432 | SLabel = getLabelBeforeInsn(End); |
| 1433 | else { |
| 1434 | // End is a normal instruction clobbering the range. |
| 1435 | SLabel = getLabelAfterInsn(End); |
| 1436 | assert(SLabel && "Forgot label after clobber instruction"); |
| 1437 | ++HI; |
| 1438 | } |
| 1439 | } |
Jakob Stoklund Olesen | 28cf115 | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 1440 | |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1441 | // The value is valid until the next DBG_VALUE or clobber. |
Devang Patel | c432907 | 2011-06-01 22:03:25 +0000 | [diff] [blame] | 1442 | MachineLocation MLoc; |
| 1443 | if (Begin->getNumOperands() == 3) { |
| 1444 | if (Begin->getOperand(0).isReg() && Begin->getOperand(1).isImm()) { |
| 1445 | MLoc.set(Begin->getOperand(0).getReg(), |
| 1446 | Begin->getOperand(1).getImm()); |
| 1447 | DotDebugLocEntries. |
| 1448 | push_back(DotDebugLocEntry(FLabel, SLabel, MLoc, Var)); |
| 1449 | } |
| 1450 | // FIXME: Handle isFPImm also. |
| 1451 | else if (Begin->getOperand(0).isImm()) { |
| 1452 | DotDebugLocEntries. |
| 1453 | push_back(DotDebugLocEntry(FLabel, SLabel, |
| 1454 | Begin->getOperand(0).getImm())); |
| 1455 | } |
| 1456 | } else { |
| 1457 | MLoc = Asm->getDebugValueLocation(Begin); |
| 1458 | DotDebugLocEntries. |
| 1459 | push_back(DotDebugLocEntry(FLabel, SLabel, MLoc, Var)); |
| 1460 | } |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 1461 | } |
| 1462 | DotDebugLocEntries.push_back(DotDebugLocEntry()); |
Devang Patel | 90a48ad | 2010-03-15 18:33:46 +0000 | [diff] [blame] | 1463 | } |
Devang Patel | 98e1cac | 2010-05-14 21:01:35 +0000 | [diff] [blame] | 1464 | |
| 1465 | // Collect info for variables that were optimized out. |
Devang Patel | d1bbc6b | 2010-06-22 01:01:58 +0000 | [diff] [blame] | 1466 | const Function *F = MF->getFunction(); |
Devang Patel | 6236704 | 2010-11-10 22:19:21 +0000 | [diff] [blame] | 1467 | if (NamedMDNode *NMD = getFnSpecificMDNode(*(F->getParent()), F->getName())) { |
Devang Patel | 98e1cac | 2010-05-14 21:01:35 +0000 | [diff] [blame] | 1468 | for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) { |
Dan Gohman | 872814a | 2010-07-21 18:54:18 +0000 | [diff] [blame] | 1469 | DIVariable DV(cast<MDNode>(NMD->getOperand(i))); |
Devang Patel | ee43286 | 2010-05-20 19:57:06 +0000 | [diff] [blame] | 1470 | if (!DV || !Processed.insert(DV)) |
Devang Patel | 98e1cac | 2010-05-14 21:01:35 +0000 | [diff] [blame] | 1471 | continue; |
| 1472 | DbgScope *Scope = DbgScopeMap.lookup(DV.getContext()); |
| 1473 | if (Scope) |
Devang Patel | 26c1e56 | 2010-05-20 16:36:41 +0000 | [diff] [blame] | 1474 | Scope->addVariable(new DbgVariable(DV)); |
Devang Patel | 98e1cac | 2010-05-14 21:01:35 +0000 | [diff] [blame] | 1475 | } |
| 1476 | } |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 1477 | } |
Devang Patel | 98e1cac | 2010-05-14 21:01:35 +0000 | [diff] [blame] | 1478 | |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 1479 | /// getLabelBeforeInsn - Return Label preceding the instruction. |
| 1480 | const MCSymbol *DwarfDebug::getLabelBeforeInsn(const MachineInstr *MI) { |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1481 | MCSymbol *Label = LabelsBeforeInsn.lookup(MI); |
| 1482 | assert(Label && "Didn't insert label before instruction"); |
| 1483 | return Label; |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 1484 | } |
| 1485 | |
| 1486 | /// getLabelAfterInsn - Return Label immediately following the instruction. |
| 1487 | const MCSymbol *DwarfDebug::getLabelAfterInsn(const MachineInstr *MI) { |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1488 | return LabelsAfterInsn.lookup(MI); |
Devang Patel | e717faa | 2009-10-06 01:26:37 +0000 | [diff] [blame] | 1489 | } |
| 1490 | |
Devang Patel | cbbe287 | 2010-10-26 17:49:02 +0000 | [diff] [blame] | 1491 | /// beginInstruction - Process beginning of an instruction. |
| 1492 | void DwarfDebug::beginInstruction(const MachineInstr *MI) { |
Jakob Stoklund Olesen | 15a3ea0 | 2011-03-25 17:20:59 +0000 | [diff] [blame] | 1493 | // Check if source location changes, but ignore DBG_VALUE locations. |
| 1494 | if (!MI->isDebugValue()) { |
| 1495 | DebugLoc DL = MI->getDebugLoc(); |
| 1496 | if (DL != PrevInstLoc && (!DL.isUnknown() || UnknownLocations)) { |
Devang Patel | 4243e67 | 2011-05-11 19:22:19 +0000 | [diff] [blame] | 1497 | unsigned Flags = DWARF2_FLAG_IS_STMT; |
Jakob Stoklund Olesen | 15a3ea0 | 2011-03-25 17:20:59 +0000 | [diff] [blame] | 1498 | PrevInstLoc = DL; |
Devang Patel | 4243e67 | 2011-05-11 19:22:19 +0000 | [diff] [blame] | 1499 | if (DL == PrologEndLoc) { |
| 1500 | Flags |= DWARF2_FLAG_PROLOGUE_END; |
| 1501 | PrologEndLoc = DebugLoc(); |
| 1502 | } |
Jakob Stoklund Olesen | 15a3ea0 | 2011-03-25 17:20:59 +0000 | [diff] [blame] | 1503 | if (!DL.isUnknown()) { |
| 1504 | const MDNode *Scope = DL.getScope(Asm->MF->getFunction()->getContext()); |
Devang Patel | 4243e67 | 2011-05-11 19:22:19 +0000 | [diff] [blame] | 1505 | recordSourceLine(DL.getLine(), DL.getCol(), Scope, Flags); |
Jakob Stoklund Olesen | 15a3ea0 | 2011-03-25 17:20:59 +0000 | [diff] [blame] | 1506 | } else |
Devang Patel | 4243e67 | 2011-05-11 19:22:19 +0000 | [diff] [blame] | 1507 | recordSourceLine(0, 0, 0, 0); |
Jakob Stoklund Olesen | 15a3ea0 | 2011-03-25 17:20:59 +0000 | [diff] [blame] | 1508 | } |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 1509 | } |
Devang Patel | aead63c | 2010-03-29 22:59:58 +0000 | [diff] [blame] | 1510 | |
Jakob Stoklund Olesen | 15a3ea0 | 2011-03-25 17:20:59 +0000 | [diff] [blame] | 1511 | // Insert labels where requested. |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1512 | DenseMap<const MachineInstr*, MCSymbol*>::iterator I = |
| 1513 | LabelsBeforeInsn.find(MI); |
| 1514 | |
| 1515 | // No label needed. |
| 1516 | if (I == LabelsBeforeInsn.end()) |
| 1517 | return; |
| 1518 | |
| 1519 | // Label already assigned. |
| 1520 | if (I->second) |
Devang Patel | b2b31a6 | 2010-05-26 19:37:24 +0000 | [diff] [blame] | 1521 | return; |
Devang Patel | 553881b | 2010-03-29 17:20:31 +0000 | [diff] [blame] | 1522 | |
Jakob Stoklund Olesen | 15a3ea0 | 2011-03-25 17:20:59 +0000 | [diff] [blame] | 1523 | if (!PrevLabel) { |
Devang Patel | 77051f5 | 2010-05-26 21:23:46 +0000 | [diff] [blame] | 1524 | PrevLabel = MMI->getContext().CreateTempSymbol(); |
| 1525 | Asm->OutStreamer.EmitLabel(PrevLabel); |
Devang Patel | b2b31a6 | 2010-05-26 19:37:24 +0000 | [diff] [blame] | 1526 | } |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1527 | I->second = PrevLabel; |
Devang Patel | 0d20ac8 | 2009-10-06 01:50:42 +0000 | [diff] [blame] | 1528 | } |
| 1529 | |
Devang Patel | cbbe287 | 2010-10-26 17:49:02 +0000 | [diff] [blame] | 1530 | /// endInstruction - Process end of an instruction. |
| 1531 | void DwarfDebug::endInstruction(const MachineInstr *MI) { |
Jakob Stoklund Olesen | 15a3ea0 | 2011-03-25 17:20:59 +0000 | [diff] [blame] | 1532 | // Don't create a new label after DBG_VALUE instructions. |
| 1533 | // They don't generate code. |
| 1534 | if (!MI->isDebugValue()) |
| 1535 | PrevLabel = 0; |
| 1536 | |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1537 | DenseMap<const MachineInstr*, MCSymbol*>::iterator I = |
| 1538 | LabelsAfterInsn.find(MI); |
| 1539 | |
| 1540 | // No label needed. |
| 1541 | if (I == LabelsAfterInsn.end()) |
| 1542 | return; |
| 1543 | |
| 1544 | // Label already assigned. |
| 1545 | if (I->second) |
Jakob Stoklund Olesen | 15a3ea0 | 2011-03-25 17:20:59 +0000 | [diff] [blame] | 1546 | return; |
| 1547 | |
| 1548 | // We need a label after this instruction. |
| 1549 | if (!PrevLabel) { |
| 1550 | PrevLabel = MMI->getContext().CreateTempSymbol(); |
| 1551 | Asm->OutStreamer.EmitLabel(PrevLabel); |
Devang Patel | 1c24635 | 2010-04-08 16:50:29 +0000 | [diff] [blame] | 1552 | } |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1553 | I->second = PrevLabel; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1554 | } |
| 1555 | |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1556 | /// getOrCreateDbgScope - Create DbgScope for the scope. |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1557 | DbgScope *DwarfDebug::getOrCreateDbgScope(const MDNode *Scope, |
Devang Patel | 6140962 | 2010-07-07 20:12:52 +0000 | [diff] [blame] | 1558 | const MDNode *InlinedAt) { |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1559 | if (!InlinedAt) { |
| 1560 | DbgScope *WScope = DbgScopeMap.lookup(Scope); |
| 1561 | if (WScope) |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1562 | return WScope; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1563 | WScope = new DbgScope(NULL, DIDescriptor(Scope), NULL); |
| 1564 | DbgScopeMap.insert(std::make_pair(Scope, WScope)); |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1565 | if (DIDescriptor(Scope).isLexicalBlock()) { |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1566 | DbgScope *Parent = |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 1567 | getOrCreateDbgScope(DILexicalBlock(Scope).getContext(), NULL); |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1568 | WScope->setParent(Parent); |
| 1569 | Parent->addScope(WScope); |
| 1570 | } |
| 1571 | |
| 1572 | if (!WScope->getParent()) { |
| 1573 | StringRef SPName = DISubprogram(Scope).getLinkageName(); |
Stuart Hastings | cad22ad | 2010-06-15 23:06:30 +0000 | [diff] [blame] | 1574 | // We used to check only for a linkage name, but that fails |
| 1575 | // since we began omitting the linkage name for private |
| 1576 | // functions. The new way is to check for the name in metadata, |
| 1577 | // but that's not supported in old .ll test cases. Ergo, we |
| 1578 | // check both. |
Stuart Hastings | 215aa15 | 2010-06-11 20:08:44 +0000 | [diff] [blame] | 1579 | if (SPName == Asm->MF->getFunction()->getName() || |
| 1580 | DISubprogram(Scope).getFunction() == Asm->MF->getFunction()) |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1581 | CurrentFnDbgScope = WScope; |
| 1582 | } |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1583 | |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1584 | return WScope; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1585 | } |
| 1586 | |
Devang Patel | 78e127d | 2010-06-25 22:07:34 +0000 | [diff] [blame] | 1587 | getOrCreateAbstractScope(Scope); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1588 | DbgScope *WScope = DbgScopeMap.lookup(InlinedAt); |
| 1589 | if (WScope) |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1590 | return WScope; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1591 | |
| 1592 | WScope = new DbgScope(NULL, DIDescriptor(Scope), InlinedAt); |
| 1593 | DbgScopeMap.insert(std::make_pair(InlinedAt, WScope)); |
| 1594 | DILocation DL(InlinedAt); |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1595 | DbgScope *Parent = |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 1596 | getOrCreateDbgScope(DL.getScope(), DL.getOrigLocation()); |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1597 | WScope->setParent(Parent); |
| 1598 | Parent->addScope(WScope); |
| 1599 | |
| 1600 | ConcreteScopes[InlinedAt] = WScope; |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1601 | |
| 1602 | return WScope; |
Devang Patel | 0d20ac8 | 2009-10-06 01:50:42 +0000 | [diff] [blame] | 1603 | } |
| 1604 | |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1605 | /// hasValidLocation - Return true if debug location entry attached with |
| 1606 | /// machine instruction encodes valid location info. |
| 1607 | static bool hasValidLocation(LLVMContext &Ctx, |
| 1608 | const MachineInstr *MInsn, |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 1609 | const MDNode *&Scope, const MDNode *&InlinedAt) { |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1610 | DebugLoc DL = MInsn->getDebugLoc(); |
| 1611 | if (DL.isUnknown()) return false; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1612 | |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 1613 | const MDNode *S = DL.getScope(Ctx); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1614 | |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1615 | // There is no need to create another DIE for compile unit. For all |
| 1616 | // other scopes, create one DbgScope now. This will be translated |
| 1617 | // into a scope DIE at the end. |
| 1618 | if (DIScope(S).isCompileUnit()) return false; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1619 | |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1620 | Scope = S; |
| 1621 | InlinedAt = DL.getInlinedAt(Ctx); |
| 1622 | return true; |
| 1623 | } |
| 1624 | |
| 1625 | /// calculateDominanceGraph - Calculate dominance graph for DbgScope |
| 1626 | /// hierarchy. |
| 1627 | static void calculateDominanceGraph(DbgScope *Scope) { |
| 1628 | assert (Scope && "Unable to calculate scop edominance graph!"); |
| 1629 | SmallVector<DbgScope *, 4> WorkStack; |
| 1630 | WorkStack.push_back(Scope); |
| 1631 | unsigned Counter = 0; |
| 1632 | while (!WorkStack.empty()) { |
| 1633 | DbgScope *WS = WorkStack.back(); |
| 1634 | const SmallVector<DbgScope *, 4> &Children = WS->getScopes(); |
| 1635 | bool visitedChildren = false; |
| 1636 | for (SmallVector<DbgScope *, 4>::const_iterator SI = Children.begin(), |
| 1637 | SE = Children.end(); SI != SE; ++SI) { |
| 1638 | DbgScope *ChildScope = *SI; |
| 1639 | if (!ChildScope->getDFSOut()) { |
| 1640 | WorkStack.push_back(ChildScope); |
| 1641 | visitedChildren = true; |
| 1642 | ChildScope->setDFSIn(++Counter); |
| 1643 | break; |
| 1644 | } |
| 1645 | } |
| 1646 | if (!visitedChildren) { |
| 1647 | WorkStack.pop_back(); |
| 1648 | WS->setDFSOut(++Counter); |
| 1649 | } |
| 1650 | } |
| 1651 | } |
| 1652 | |
| 1653 | /// printDbgScopeInfo - Print DbgScope info for each machine instruction. |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1654 | static |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1655 | void printDbgScopeInfo(LLVMContext &Ctx, const MachineFunction *MF, |
| 1656 | DenseMap<const MachineInstr *, DbgScope *> &MI2ScopeMap) |
| 1657 | { |
| 1658 | #ifndef NDEBUG |
| 1659 | unsigned PrevDFSIn = 0; |
| 1660 | for (MachineFunction::const_iterator I = MF->begin(), E = MF->end(); |
| 1661 | I != E; ++I) { |
| 1662 | for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end(); |
| 1663 | II != IE; ++II) { |
| 1664 | const MachineInstr *MInsn = II; |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 1665 | const MDNode *Scope = NULL; |
| 1666 | const MDNode *InlinedAt = NULL; |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1667 | |
| 1668 | // Check if instruction has valid location information. |
| 1669 | if (hasValidLocation(Ctx, MInsn, Scope, InlinedAt)) { |
| 1670 | dbgs() << " [ "; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1671 | if (InlinedAt) |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1672 | dbgs() << "*"; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1673 | DenseMap<const MachineInstr *, DbgScope *>::iterator DI = |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1674 | MI2ScopeMap.find(MInsn); |
| 1675 | if (DI != MI2ScopeMap.end()) { |
| 1676 | DbgScope *S = DI->second; |
| 1677 | dbgs() << S->getDFSIn(); |
| 1678 | PrevDFSIn = S->getDFSIn(); |
| 1679 | } else |
| 1680 | dbgs() << PrevDFSIn; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1681 | } else |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1682 | dbgs() << " [ x" << PrevDFSIn; |
| 1683 | dbgs() << " ]"; |
| 1684 | MInsn->dump(); |
| 1685 | } |
| 1686 | dbgs() << "\n"; |
| 1687 | } |
| 1688 | #endif |
| 1689 | } |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1690 | /// extractScopeInformation - Scan machine instructions in this function |
Chris Lattner | 14d750d | 2010-03-31 05:39:57 +0000 | [diff] [blame] | 1691 | /// and collect DbgScopes. Return true, if at least one scope was found. |
Chris Lattner | eec791a | 2010-01-26 23:18:02 +0000 | [diff] [blame] | 1692 | bool DwarfDebug::extractScopeInformation() { |
Devang Patel | af9e847 | 2009-10-01 20:31:14 +0000 | [diff] [blame] | 1693 | // If scope information was extracted using .dbg intrinsics then there is not |
| 1694 | // any need to extract these information by scanning each instruction. |
| 1695 | if (!DbgScopeMap.empty()) |
| 1696 | return false; |
| 1697 | |
Dan Gohman | 314bf7c | 2010-04-23 01:18:53 +0000 | [diff] [blame] | 1698 | // Scan each instruction and create scopes. First build working set of scopes. |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1699 | LLVMContext &Ctx = Asm->MF->getFunction()->getContext(); |
| 1700 | SmallVector<DbgRange, 4> MIRanges; |
| 1701 | DenseMap<const MachineInstr *, DbgScope *> MI2ScopeMap; |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 1702 | const MDNode *PrevScope = NULL; |
| 1703 | const MDNode *PrevInlinedAt = NULL; |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1704 | const MachineInstr *RangeBeginMI = NULL; |
| 1705 | const MachineInstr *PrevMI = NULL; |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 1706 | for (MachineFunction::const_iterator I = Asm->MF->begin(), E = Asm->MF->end(); |
Devang Patel | af9e847 | 2009-10-01 20:31:14 +0000 | [diff] [blame] | 1707 | I != E; ++I) { |
| 1708 | for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end(); |
| 1709 | II != IE; ++II) { |
| 1710 | const MachineInstr *MInsn = II; |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 1711 | const MDNode *Scope = NULL; |
| 1712 | const MDNode *InlinedAt = NULL; |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1713 | |
| 1714 | // Check if instruction has valid location information. |
| 1715 | if (!hasValidLocation(Ctx, MInsn, Scope, InlinedAt)) { |
| 1716 | PrevMI = MInsn; |
| 1717 | continue; |
| 1718 | } |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1719 | |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1720 | // If scope has not changed then skip this instruction. |
| 1721 | if (Scope == PrevScope && PrevInlinedAt == InlinedAt) { |
| 1722 | PrevMI = MInsn; |
| 1723 | continue; |
| 1724 | } |
| 1725 | |
Devang Patel | d3526ea | 2011-02-15 17:56:09 +0000 | [diff] [blame] | 1726 | // Ignore DBG_VALUE. It does not contribute any instruction in output. |
| 1727 | if (MInsn->isDebugValue()) |
| 1728 | continue; |
| 1729 | |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1730 | if (RangeBeginMI) { |
| 1731 | // If we have alread seen a beginning of a instruction range and |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1732 | // current instruction scope does not match scope of first instruction |
| 1733 | // in this range then create a new instruction range. |
| 1734 | DbgRange R(RangeBeginMI, PrevMI); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1735 | MI2ScopeMap[RangeBeginMI] = getOrCreateDbgScope(PrevScope, |
Devang Patel | 6140962 | 2010-07-07 20:12:52 +0000 | [diff] [blame] | 1736 | PrevInlinedAt); |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1737 | MIRanges.push_back(R); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1738 | } |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1739 | |
| 1740 | // This is a beginning of a new instruction range. |
| 1741 | RangeBeginMI = MInsn; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1742 | |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1743 | // Reset previous markers. |
| 1744 | PrevMI = MInsn; |
| 1745 | PrevScope = Scope; |
| 1746 | PrevInlinedAt = InlinedAt; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1747 | } |
| 1748 | } |
| 1749 | |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1750 | // Create last instruction range. |
| 1751 | if (RangeBeginMI && PrevMI && PrevScope) { |
| 1752 | DbgRange R(RangeBeginMI, PrevMI); |
| 1753 | MIRanges.push_back(R); |
| 1754 | MI2ScopeMap[RangeBeginMI] = getOrCreateDbgScope(PrevScope, PrevInlinedAt); |
Devang Patel | af9e847 | 2009-10-01 20:31:14 +0000 | [diff] [blame] | 1755 | } |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1756 | |
Devang Patel | 344130e | 2010-01-04 20:44:00 +0000 | [diff] [blame] | 1757 | if (!CurrentFnDbgScope) |
| 1758 | return false; |
| 1759 | |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1760 | calculateDominanceGraph(CurrentFnDbgScope); |
| 1761 | if (PrintDbgScope) |
| 1762 | printDbgScopeInfo(Ctx, Asm->MF, MI2ScopeMap); |
| 1763 | |
| 1764 | // Find ranges of instructions covered by each DbgScope; |
| 1765 | DbgScope *PrevDbgScope = NULL; |
| 1766 | for (SmallVector<DbgRange, 4>::const_iterator RI = MIRanges.begin(), |
| 1767 | RE = MIRanges.end(); RI != RE; ++RI) { |
| 1768 | const DbgRange &R = *RI; |
| 1769 | DbgScope *S = MI2ScopeMap.lookup(R.first); |
| 1770 | assert (S && "Lost DbgScope for a machine instruction!"); |
| 1771 | if (PrevDbgScope && !PrevDbgScope->dominates(S)) |
| 1772 | PrevDbgScope->closeInsnRange(S); |
| 1773 | S->openInsnRange(R.first); |
| 1774 | S->extendInsnRange(R.second); |
| 1775 | PrevDbgScope = S; |
| 1776 | } |
| 1777 | |
| 1778 | if (PrevDbgScope) |
| 1779 | PrevDbgScope->closeInsnRange(); |
Devang Patel | af9e847 | 2009-10-01 20:31:14 +0000 | [diff] [blame] | 1780 | |
Devang Patel | e37b0c6 | 2010-04-08 18:43:56 +0000 | [diff] [blame] | 1781 | identifyScopeMarkers(); |
Devang Patel | 6122a4d | 2010-04-08 15:37:09 +0000 | [diff] [blame] | 1782 | |
| 1783 | return !DbgScopeMap.empty(); |
| 1784 | } |
| 1785 | |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1786 | /// identifyScopeMarkers() - |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1787 | /// Each DbgScope has first instruction and last instruction to mark beginning |
| 1788 | /// and end of a scope respectively. Create an inverse map that list scopes |
| 1789 | /// starts (and ends) with an instruction. One instruction may start (or end) |
| 1790 | /// multiple scopes. Ignore scopes that are not reachable. |
Devang Patel | e37b0c6 | 2010-04-08 18:43:56 +0000 | [diff] [blame] | 1791 | void DwarfDebug::identifyScopeMarkers() { |
Devang Patel | 42aafd7 | 2010-01-20 02:05:23 +0000 | [diff] [blame] | 1792 | SmallVector<DbgScope *, 4> WorkList; |
| 1793 | WorkList.push_back(CurrentFnDbgScope); |
| 1794 | while (!WorkList.empty()) { |
Chris Lattner | 14d750d | 2010-03-31 05:39:57 +0000 | [diff] [blame] | 1795 | DbgScope *S = WorkList.pop_back_val(); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1796 | |
Jeffrey Yasskin | 5c213dc | 2010-03-12 17:45:06 +0000 | [diff] [blame] | 1797 | const SmallVector<DbgScope *, 4> &Children = S->getScopes(); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1798 | if (!Children.empty()) |
Jeffrey Yasskin | 5c213dc | 2010-03-12 17:45:06 +0000 | [diff] [blame] | 1799 | for (SmallVector<DbgScope *, 4>::const_iterator SI = Children.begin(), |
Devang Patel | 42aafd7 | 2010-01-20 02:05:23 +0000 | [diff] [blame] | 1800 | SE = Children.end(); SI != SE; ++SI) |
| 1801 | WorkList.push_back(*SI); |
| 1802 | |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1803 | if (S->isAbstractScope()) |
| 1804 | continue; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1805 | |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1806 | const SmallVector<DbgRange, 4> &Ranges = S->getRanges(); |
| 1807 | if (Ranges.empty()) |
| 1808 | continue; |
| 1809 | for (SmallVector<DbgRange, 4>::const_iterator RI = Ranges.begin(), |
| 1810 | RE = Ranges.end(); RI != RE; ++RI) { |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 1811 | assert(RI->first && "DbgRange does not have first instruction!"); |
| 1812 | assert(RI->second && "DbgRange does not have second instruction!"); |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1813 | requestLabelBeforeInsn(RI->first); |
| 1814 | requestLabelAfterInsn(RI->second); |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1815 | } |
Devang Patel | af9e847 | 2009-10-01 20:31:14 +0000 | [diff] [blame] | 1816 | } |
Devang Patel | af9e847 | 2009-10-01 20:31:14 +0000 | [diff] [blame] | 1817 | } |
| 1818 | |
Devang Patel | a3f4867 | 2011-05-09 22:14:49 +0000 | [diff] [blame] | 1819 | /// getScopeNode - Get MDNode for DebugLoc's scope. |
| 1820 | static MDNode *getScopeNode(DebugLoc DL, const LLVMContext &Ctx) { |
| 1821 | if (MDNode *InlinedAt = DL.getInlinedAt(Ctx)) |
| 1822 | return getScopeNode(DebugLoc::getFromDILocation(InlinedAt), Ctx); |
| 1823 | return DL.getScope(Ctx); |
| 1824 | } |
| 1825 | |
Devang Patel | 4243e67 | 2011-05-11 19:22:19 +0000 | [diff] [blame] | 1826 | /// getFnDebugLoc - Walk up the scope chain of given debug loc and find |
| 1827 | /// line number info for the function. |
| 1828 | static DebugLoc getFnDebugLoc(DebugLoc DL, const LLVMContext &Ctx) { |
| 1829 | const MDNode *Scope = getScopeNode(DL, Ctx); |
| 1830 | DISubprogram SP = getDISubprogram(Scope); |
| 1831 | if (SP.Verify()) |
| 1832 | return DebugLoc::get(SP.getLineNumber(), 0, SP); |
| 1833 | return DebugLoc(); |
| 1834 | } |
| 1835 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1836 | /// beginFunction - Gather pre-function debug information. Assumes being |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1837 | /// emitted immediately after the function entry point. |
Chris Lattner | eec791a | 2010-01-26 23:18:02 +0000 | [diff] [blame] | 1838 | void DwarfDebug::beginFunction(const MachineFunction *MF) { |
Chris Lattner | 994cb12 | 2010-04-05 03:52:55 +0000 | [diff] [blame] | 1839 | if (!MMI->hasDebugInfo()) return; |
Bill Wendling | 5f017e8 | 2010-04-07 09:28:04 +0000 | [diff] [blame] | 1840 | if (!extractScopeInformation()) return; |
Devang Patel | 60b35bd | 2009-10-06 18:37:31 +0000 | [diff] [blame] | 1841 | |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1842 | FunctionBeginSym = Asm->GetTempSymbol("func_begin", |
| 1843 | Asm->getFunctionNumber()); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1844 | // Assumes in correct section after the entry point. |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 1845 | Asm->OutStreamer.EmitLabel(FunctionBeginSym); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1846 | |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1847 | assert(UserVariables.empty() && DbgValues.empty() && "Maps weren't cleaned"); |
| 1848 | |
Devang Patel | b9abe9f | 2010-06-02 16:42:51 +0000 | [diff] [blame] | 1849 | /// ProcessedArgs - Collection of arguments already processed. |
| 1850 | SmallPtrSet<const MDNode *, 8> ProcessedArgs; |
Jakob Stoklund Olesen | 28cf115 | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 1851 | const TargetRegisterInfo *TRI = Asm->TM.getRegisterInfo(); |
Jakob Stoklund Olesen | 28cf115 | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 1852 | /// LiveUserVar - Map physreg numbers to the MDNode they contain. |
| 1853 | std::vector<const MDNode*> LiveUserVar(TRI->getNumRegs()); |
| 1854 | |
Devang Patel | b2b31a6 | 2010-05-26 19:37:24 +0000 | [diff] [blame] | 1855 | for (MachineFunction::const_iterator I = MF->begin(), E = MF->end(); |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1856 | I != E; ++I) { |
| 1857 | bool AtBlockEntry = true; |
Devang Patel | b2b31a6 | 2010-05-26 19:37:24 +0000 | [diff] [blame] | 1858 | for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end(); |
| 1859 | II != IE; ++II) { |
| 1860 | const MachineInstr *MI = II; |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1861 | |
Devang Patel | b2b31a6 | 2010-05-26 19:37:24 +0000 | [diff] [blame] | 1862 | if (MI->isDebugValue()) { |
Devang Patel | b2b31a6 | 2010-05-26 19:37:24 +0000 | [diff] [blame] | 1863 | assert (MI->getNumOperands() > 1 && "Invalid machine instruction!"); |
Jakob Stoklund Olesen | 28cf115 | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 1864 | |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1865 | // Keep track of user variables. |
Jakob Stoklund Olesen | 28cf115 | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 1866 | const MDNode *Var = |
| 1867 | MI->getOperand(MI->getNumOperands() - 1).getMetadata(); |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1868 | |
| 1869 | // Variable is in a register, we need to check for clobbers. |
Jakob Stoklund Olesen | 28cf115 | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 1870 | if (isDbgValueInDefinedReg(MI)) |
| 1871 | LiveUserVar[MI->getOperand(0).getReg()] = Var; |
| 1872 | |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1873 | // Check the history of this variable. |
| 1874 | SmallVectorImpl<const MachineInstr*> &History = DbgValues[Var]; |
| 1875 | if (History.empty()) { |
| 1876 | UserVariables.push_back(Var); |
| 1877 | // The first mention of a function argument gets the FunctionBeginSym |
| 1878 | // label, so arguments are visible when breaking at function entry. |
| 1879 | DIVariable DV(Var); |
| 1880 | if (DV.Verify() && DV.getTag() == dwarf::DW_TAG_arg_variable && |
| 1881 | DISubprogram(getDISubprogram(DV.getContext())) |
| 1882 | .describes(MF->getFunction())) |
| 1883 | LabelsBeforeInsn[MI] = FunctionBeginSym; |
| 1884 | } else { |
| 1885 | // We have seen this variable before. Try to coalesce DBG_VALUEs. |
| 1886 | const MachineInstr *Prev = History.back(); |
| 1887 | if (Prev->isDebugValue()) { |
| 1888 | // Coalesce identical entries at the end of History. |
| 1889 | if (History.size() >= 2 && |
| 1890 | Prev->isIdenticalTo(History[History.size() - 2])) |
| 1891 | History.pop_back(); |
| 1892 | |
| 1893 | // Terminate old register assignments that don't reach MI; |
| 1894 | MachineFunction::const_iterator PrevMBB = Prev->getParent(); |
| 1895 | if (PrevMBB != I && (!AtBlockEntry || llvm::next(PrevMBB) != I) && |
| 1896 | isDbgValueInDefinedReg(Prev)) { |
| 1897 | // Previous register assignment needs to terminate at the end of |
| 1898 | // its basic block. |
| 1899 | MachineBasicBlock::const_iterator LastMI = |
| 1900 | PrevMBB->getLastNonDebugInstr(); |
| 1901 | if (LastMI == PrevMBB->end()) |
| 1902 | // Drop DBG_VALUE for empty range. |
| 1903 | History.pop_back(); |
| 1904 | else { |
| 1905 | // Terminate after LastMI. |
| 1906 | History.push_back(LastMI); |
| 1907 | } |
| 1908 | } |
| 1909 | } |
| 1910 | } |
| 1911 | History.push_back(MI); |
Devang Patel | b2b31a6 | 2010-05-26 19:37:24 +0000 | [diff] [blame] | 1912 | } else { |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1913 | // Not a DBG_VALUE instruction. |
| 1914 | if (!MI->isLabel()) |
| 1915 | AtBlockEntry = false; |
| 1916 | |
Devang Patel | 4243e67 | 2011-05-11 19:22:19 +0000 | [diff] [blame] | 1917 | // First known non DBG_VALUE location marks beginning of function |
| 1918 | // body. |
| 1919 | if (PrologEndLoc.isUnknown() && !MI->getDebugLoc().isUnknown()) |
| 1920 | PrologEndLoc = MI->getDebugLoc(); |
| 1921 | |
Jakob Stoklund Olesen | 28cf115 | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 1922 | // Check if the instruction clobbers any registers with debug vars. |
| 1923 | for (MachineInstr::const_mop_iterator MOI = MI->operands_begin(), |
| 1924 | MOE = MI->operands_end(); MOI != MOE; ++MOI) { |
| 1925 | if (!MOI->isReg() || !MOI->isDef() || !MOI->getReg()) |
| 1926 | continue; |
| 1927 | for (const unsigned *AI = TRI->getOverlaps(MOI->getReg()); |
| 1928 | unsigned Reg = *AI; ++AI) { |
| 1929 | const MDNode *Var = LiveUserVar[Reg]; |
| 1930 | if (!Var) |
| 1931 | continue; |
| 1932 | // Reg is now clobbered. |
| 1933 | LiveUserVar[Reg] = 0; |
| 1934 | |
| 1935 | // Was MD last defined by a DBG_VALUE referring to Reg? |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1936 | DbgValueHistoryMap::iterator HistI = DbgValues.find(Var); |
| 1937 | if (HistI == DbgValues.end()) |
Jakob Stoklund Olesen | 28cf115 | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 1938 | continue; |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1939 | SmallVectorImpl<const MachineInstr*> &History = HistI->second; |
| 1940 | if (History.empty()) |
Jakob Stoklund Olesen | 28cf115 | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 1941 | continue; |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1942 | const MachineInstr *Prev = History.back(); |
| 1943 | // Sanity-check: Register assignments are terminated at the end of |
| 1944 | // their block. |
| 1945 | if (!Prev->isDebugValue() || Prev->getParent() != MI->getParent()) |
| 1946 | continue; |
| 1947 | // Is the variable still in Reg? |
| 1948 | if (!isDbgValueInDefinedReg(Prev) || |
| 1949 | Prev->getOperand(0).getReg() != Reg) |
| 1950 | continue; |
| 1951 | // Var is clobbered. Make sure the next instruction gets a label. |
| 1952 | History.push_back(MI); |
Jakob Stoklund Olesen | 28cf115 | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 1953 | } |
| 1954 | } |
Devang Patel | b2b31a6 | 2010-05-26 19:37:24 +0000 | [diff] [blame] | 1955 | } |
Devang Patel | b2b31a6 | 2010-05-26 19:37:24 +0000 | [diff] [blame] | 1956 | } |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 1957 | } |
| 1958 | |
| 1959 | for (DbgValueHistoryMap::iterator I = DbgValues.begin(), E = DbgValues.end(); |
| 1960 | I != E; ++I) { |
| 1961 | SmallVectorImpl<const MachineInstr*> &History = I->second; |
| 1962 | if (History.empty()) |
| 1963 | continue; |
| 1964 | |
| 1965 | // Make sure the final register assignments are terminated. |
| 1966 | const MachineInstr *Prev = History.back(); |
| 1967 | if (Prev->isDebugValue() && isDbgValueInDefinedReg(Prev)) { |
| 1968 | const MachineBasicBlock *PrevMBB = Prev->getParent(); |
| 1969 | MachineBasicBlock::const_iterator LastMI = PrevMBB->getLastNonDebugInstr(); |
| 1970 | if (LastMI == PrevMBB->end()) |
| 1971 | // Drop DBG_VALUE for empty range. |
| 1972 | History.pop_back(); |
| 1973 | else { |
| 1974 | // Terminate after LastMI. |
| 1975 | History.push_back(LastMI); |
| 1976 | } |
| 1977 | } |
| 1978 | // Request labels for the full history. |
| 1979 | for (unsigned i = 0, e = History.size(); i != e; ++i) { |
| 1980 | const MachineInstr *MI = History[i]; |
| 1981 | if (MI->isDebugValue()) |
| 1982 | requestLabelBeforeInsn(MI); |
| 1983 | else |
| 1984 | requestLabelAfterInsn(MI); |
| 1985 | } |
| 1986 | } |
Devang Patel | b2b31a6 | 2010-05-26 19:37:24 +0000 | [diff] [blame] | 1987 | |
Jakob Stoklund Olesen | 15a3ea0 | 2011-03-25 17:20:59 +0000 | [diff] [blame] | 1988 | PrevInstLoc = DebugLoc(); |
Devang Patel | b2b31a6 | 2010-05-26 19:37:24 +0000 | [diff] [blame] | 1989 | PrevLabel = FunctionBeginSym; |
Devang Patel | 4243e67 | 2011-05-11 19:22:19 +0000 | [diff] [blame] | 1990 | |
| 1991 | // Record beginning of function. |
| 1992 | if (!PrologEndLoc.isUnknown()) { |
| 1993 | DebugLoc FnStartDL = getFnDebugLoc(PrologEndLoc, |
| 1994 | MF->getFunction()->getContext()); |
| 1995 | recordSourceLine(FnStartDL.getLine(), FnStartDL.getCol(), |
| 1996 | FnStartDL.getScope(MF->getFunction()->getContext()), |
| 1997 | DWARF2_FLAG_IS_STMT); |
| 1998 | } |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1999 | } |
| 2000 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2001 | /// endFunction - Gather and emit post-function debug information. |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2002 | /// |
Chris Lattner | eec791a | 2010-01-26 23:18:02 +0000 | [diff] [blame] | 2003 | void DwarfDebug::endFunction(const MachineFunction *MF) { |
Bill Wendling | 5f017e8 | 2010-04-07 09:28:04 +0000 | [diff] [blame] | 2004 | if (!MMI->hasDebugInfo() || DbgScopeMap.empty()) return; |
Devang Patel | 70d75ca | 2009-11-12 19:02:56 +0000 | [diff] [blame] | 2005 | |
Devang Patel | 344130e | 2010-01-04 20:44:00 +0000 | [diff] [blame] | 2006 | if (CurrentFnDbgScope) { |
Devang Patel | 65eb482 | 2010-05-22 00:04:14 +0000 | [diff] [blame] | 2007 | |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 2008 | // Define end label for subprogram. |
| 2009 | FunctionEndSym = Asm->GetTempSymbol("func_end", |
| 2010 | Asm->getFunctionNumber()); |
| 2011 | // Assumes in correct section after the entry point. |
| 2012 | Asm->OutStreamer.EmitLabel(FunctionEndSym); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2013 | |
Devang Patel | 78e127d | 2010-06-25 22:07:34 +0000 | [diff] [blame] | 2014 | SmallPtrSet<const MDNode *, 16> ProcessedVars; |
| 2015 | collectVariableInfo(MF, ProcessedVars); |
Devang Patel | 65eb482 | 2010-05-22 00:04:14 +0000 | [diff] [blame] | 2016 | |
Devang Patel | 344130e | 2010-01-04 20:44:00 +0000 | [diff] [blame] | 2017 | // Construct abstract scopes. |
| 2018 | for (SmallVector<DbgScope *, 4>::iterator AI = AbstractScopesList.begin(), |
Devang Patel | 78e127d | 2010-06-25 22:07:34 +0000 | [diff] [blame] | 2019 | AE = AbstractScopesList.end(); AI != AE; ++AI) { |
Devang Patel | 78e127d | 2010-06-25 22:07:34 +0000 | [diff] [blame] | 2020 | DISubprogram SP((*AI)->getScopeNode()); |
| 2021 | if (SP.Verify()) { |
| 2022 | // Collect info for variables that were optimized out. |
| 2023 | StringRef FName = SP.getLinkageName(); |
| 2024 | if (FName.empty()) |
| 2025 | FName = SP.getName(); |
Devang Patel | 6236704 | 2010-11-10 22:19:21 +0000 | [diff] [blame] | 2026 | if (NamedMDNode *NMD = |
| 2027 | getFnSpecificMDNode(*(MF->getFunction()->getParent()), FName)) { |
Devang Patel | 78e127d | 2010-06-25 22:07:34 +0000 | [diff] [blame] | 2028 | for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) { |
Dan Gohman | 872814a | 2010-07-21 18:54:18 +0000 | [diff] [blame] | 2029 | DIVariable DV(cast<MDNode>(NMD->getOperand(i))); |
Devang Patel | 78e127d | 2010-06-25 22:07:34 +0000 | [diff] [blame] | 2030 | if (!DV || !ProcessedVars.insert(DV)) |
| 2031 | continue; |
Devang Patel | 1d68d21 | 2010-06-30 00:11:08 +0000 | [diff] [blame] | 2032 | DbgScope *Scope = AbstractScopes.lookup(DV.getContext()); |
Devang Patel | 78e127d | 2010-06-25 22:07:34 +0000 | [diff] [blame] | 2033 | if (Scope) |
| 2034 | Scope->addVariable(new DbgVariable(DV)); |
| 2035 | } |
| 2036 | } |
| 2037 | } |
Devang Patel | 90e19aa | 2010-06-30 01:40:11 +0000 | [diff] [blame] | 2038 | if (ProcessedSPNodes.count((*AI)->getScopeNode()) == 0) |
| 2039 | constructScopeDIE(*AI); |
Devang Patel | 78e127d | 2010-06-25 22:07:34 +0000 | [diff] [blame] | 2040 | } |
Devang Patel | 6140962 | 2010-07-07 20:12:52 +0000 | [diff] [blame] | 2041 | |
Devang Patel | 9c48837 | 2010-05-04 06:15:30 +0000 | [diff] [blame] | 2042 | DIE *CurFnDIE = constructScopeDIE(CurrentFnDbgScope); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2043 | |
Devang Patel | 9c48837 | 2010-05-04 06:15:30 +0000 | [diff] [blame] | 2044 | if (!DisableFramePointerElim(*MF)) |
Devang Patel | 3cbee30 | 2011-04-12 22:53:02 +0000 | [diff] [blame] | 2045 | getCompileUnit(CurrentFnDbgScope->getScopeNode())->addUInt(CurFnDIE, |
| 2046 | dwarf::DW_AT_APPLE_omit_frame_ptr, |
| 2047 | dwarf::DW_FORM_flag, 1); |
Devang Patel | 9c48837 | 2010-05-04 06:15:30 +0000 | [diff] [blame] | 2048 | |
| 2049 | |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 2050 | DebugFrames.push_back(FunctionDebugFrameInfo(Asm->getFunctionNumber(), |
Devang Patel | 344130e | 2010-01-04 20:44:00 +0000 | [diff] [blame] | 2051 | MMI->getFrameMoves())); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2052 | } |
| 2053 | |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2054 | // Clear debug info |
Devang Patel | f54b852 | 2010-01-19 01:26:02 +0000 | [diff] [blame] | 2055 | CurrentFnDbgScope = NULL; |
Devang Patel | eac0c9d | 2011-04-22 18:09:57 +0000 | [diff] [blame] | 2056 | DeleteContainerPointers(CurrentFnArguments); |
Devang Patel | 26c1e56 | 2010-05-20 16:36:41 +0000 | [diff] [blame] | 2057 | DbgVariableToFrameIndexMap.clear(); |
| 2058 | VarToAbstractVarMap.clear(); |
| 2059 | DbgVariableToDbgInstMap.clear(); |
Jeffrey Yasskin | 5c213dc | 2010-03-12 17:45:06 +0000 | [diff] [blame] | 2060 | DeleteContainerSeconds(DbgScopeMap); |
Jakob Stoklund Olesen | adb877d | 2011-03-26 02:19:36 +0000 | [diff] [blame] | 2061 | UserVariables.clear(); |
| 2062 | DbgValues.clear(); |
Devang Patel | f54b852 | 2010-01-19 01:26:02 +0000 | [diff] [blame] | 2063 | ConcreteScopes.clear(); |
Jeffrey Yasskin | 5c213dc | 2010-03-12 17:45:06 +0000 | [diff] [blame] | 2064 | DeleteContainerSeconds(AbstractScopes); |
Devang Patel | f54b852 | 2010-01-19 01:26:02 +0000 | [diff] [blame] | 2065 | AbstractScopesList.clear(); |
Jeffrey Yasskin | 5c213dc | 2010-03-12 17:45:06 +0000 | [diff] [blame] | 2066 | AbstractVariables.clear(); |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 2067 | LabelsBeforeInsn.clear(); |
| 2068 | LabelsAfterInsn.clear(); |
Devang Patel | f2548ca | 2010-04-16 23:33:45 +0000 | [diff] [blame] | 2069 | PrevLabel = NULL; |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2070 | } |
| 2071 | |
Devang Patel | 26c1e56 | 2010-05-20 16:36:41 +0000 | [diff] [blame] | 2072 | /// recordVariableFrameIndex - Record a variable's index. |
| 2073 | void DwarfDebug::recordVariableFrameIndex(const DbgVariable *V, int Index) { |
| 2074 | assert (V && "Invalid DbgVariable!"); |
| 2075 | DbgVariableToFrameIndexMap[V] = Index; |
| 2076 | } |
| 2077 | |
| 2078 | /// findVariableFrameIndex - Return true if frame index for the variable |
| 2079 | /// is found. Update FI to hold value of the index. |
| 2080 | bool DwarfDebug::findVariableFrameIndex(const DbgVariable *V, int *FI) { |
| 2081 | assert (V && "Invalid DbgVariable!"); |
| 2082 | DenseMap<const DbgVariable *, int>::iterator I = |
| 2083 | DbgVariableToFrameIndexMap.find(V); |
| 2084 | if (I == DbgVariableToFrameIndexMap.end()) |
| 2085 | return false; |
| 2086 | *FI = I->second; |
| 2087 | return true; |
| 2088 | } |
| 2089 | |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2090 | /// findDbgScope - Find DbgScope for the debug loc attached with an |
Devang Patel | ee43286 | 2010-05-20 19:57:06 +0000 | [diff] [blame] | 2091 | /// instruction. |
| 2092 | DbgScope *DwarfDebug::findDbgScope(const MachineInstr *MInsn) { |
| 2093 | DbgScope *Scope = NULL; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2094 | LLVMContext &Ctx = |
Devang Patel | ee43286 | 2010-05-20 19:57:06 +0000 | [diff] [blame] | 2095 | MInsn->getParent()->getParent()->getFunction()->getContext(); |
| 2096 | DebugLoc DL = MInsn->getDebugLoc(); |
| 2097 | |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2098 | if (DL.isUnknown()) |
Devang Patel | ee43286 | 2010-05-20 19:57:06 +0000 | [diff] [blame] | 2099 | return Scope; |
| 2100 | |
| 2101 | if (const MDNode *IA = DL.getInlinedAt(Ctx)) |
| 2102 | Scope = ConcreteScopes.lookup(IA); |
| 2103 | if (Scope == 0) |
| 2104 | Scope = DbgScopeMap.lookup(DL.getScope(Ctx)); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2105 | |
Devang Patel | ee43286 | 2010-05-20 19:57:06 +0000 | [diff] [blame] | 2106 | return Scope; |
| 2107 | } |
| 2108 | |
| 2109 | |
Chris Lattner | c608784 | 2010-03-09 04:54:43 +0000 | [diff] [blame] | 2110 | /// recordSourceLine - Register a source line with debug info. Returns the |
| 2111 | /// unique label that was emitted and which provides correspondence to |
| 2112 | /// the source line list. |
Devang Patel | 4243e67 | 2011-05-11 19:22:19 +0000 | [diff] [blame] | 2113 | void DwarfDebug::recordSourceLine(unsigned Line, unsigned Col, const MDNode *S, |
| 2114 | unsigned Flags) { |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 2115 | StringRef Fn; |
Devang Patel | 23670e5 | 2011-03-24 20:30:50 +0000 | [diff] [blame] | 2116 | StringRef Dir; |
Dan Gohman | 1cc0d62 | 2010-05-05 23:41:32 +0000 | [diff] [blame] | 2117 | unsigned Src = 1; |
| 2118 | if (S) { |
| 2119 | DIDescriptor Scope(S); |
Devang Patel | f84548d | 2009-10-05 18:03:19 +0000 | [diff] [blame] | 2120 | |
Dan Gohman | 1cc0d62 | 2010-05-05 23:41:32 +0000 | [diff] [blame] | 2121 | if (Scope.isCompileUnit()) { |
| 2122 | DICompileUnit CU(S); |
Dan Gohman | 1cc0d62 | 2010-05-05 23:41:32 +0000 | [diff] [blame] | 2123 | Fn = CU.getFilename(); |
Devang Patel | 23670e5 | 2011-03-24 20:30:50 +0000 | [diff] [blame] | 2124 | Dir = CU.getDirectory(); |
Devang Patel | 3cabc9d | 2010-10-28 17:30:52 +0000 | [diff] [blame] | 2125 | } else if (Scope.isFile()) { |
| 2126 | DIFile F(S); |
Devang Patel | 3cabc9d | 2010-10-28 17:30:52 +0000 | [diff] [blame] | 2127 | Fn = F.getFilename(); |
Devang Patel | 23670e5 | 2011-03-24 20:30:50 +0000 | [diff] [blame] | 2128 | Dir = F.getDirectory(); |
Dan Gohman | 1cc0d62 | 2010-05-05 23:41:32 +0000 | [diff] [blame] | 2129 | } else if (Scope.isSubprogram()) { |
| 2130 | DISubprogram SP(S); |
Dan Gohman | 1cc0d62 | 2010-05-05 23:41:32 +0000 | [diff] [blame] | 2131 | Fn = SP.getFilename(); |
Devang Patel | 23670e5 | 2011-03-24 20:30:50 +0000 | [diff] [blame] | 2132 | Dir = SP.getDirectory(); |
Dan Gohman | 1cc0d62 | 2010-05-05 23:41:32 +0000 | [diff] [blame] | 2133 | } else if (Scope.isLexicalBlock()) { |
| 2134 | DILexicalBlock DB(S); |
Dan Gohman | 1cc0d62 | 2010-05-05 23:41:32 +0000 | [diff] [blame] | 2135 | Fn = DB.getFilename(); |
Devang Patel | 23670e5 | 2011-03-24 20:30:50 +0000 | [diff] [blame] | 2136 | Dir = DB.getDirectory(); |
Dan Gohman | 1cc0d62 | 2010-05-05 23:41:32 +0000 | [diff] [blame] | 2137 | } else |
| 2138 | assert(0 && "Unexpected scope info"); |
| 2139 | |
Devang Patel | 23670e5 | 2011-03-24 20:30:50 +0000 | [diff] [blame] | 2140 | Src = GetOrCreateSourceID(Fn, Dir); |
Dan Gohman | 1cc0d62 | 2010-05-05 23:41:32 +0000 | [diff] [blame] | 2141 | } |
Devang Patel | 4243e67 | 2011-05-11 19:22:19 +0000 | [diff] [blame] | 2142 | Asm->OutStreamer.EmitDwarfLocDirective(Src, Line, Col, Flags, |
Devang Patel | 3f3bf93 | 2011-04-18 20:26:49 +0000 | [diff] [blame] | 2143 | 0, 0, Fn); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2144 | } |
| 2145 | |
Bill Wendling | 829e67b | 2009-05-20 23:22:40 +0000 | [diff] [blame] | 2146 | //===----------------------------------------------------------------------===// |
| 2147 | // Emit Methods |
| 2148 | //===----------------------------------------------------------------------===// |
| 2149 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2150 | /// computeSizeAndOffset - Compute the size and offset of a DIE. |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2151 | /// |
Jim Grosbach | 7ab38df | 2009-11-22 19:20:36 +0000 | [diff] [blame] | 2152 | unsigned |
| 2153 | DwarfDebug::computeSizeAndOffset(DIE *Die, unsigned Offset, bool Last) { |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2154 | // Get the children. |
| 2155 | const std::vector<DIE *> &Children = Die->getChildren(); |
| 2156 | |
| 2157 | // If not last sibling and has children then add sibling offset attribute. |
Jeffrey Yasskin | 638fe8d | 2010-03-22 18:47:14 +0000 | [diff] [blame] | 2158 | if (!Last && !Children.empty()) |
Benjamin Kramer | 345ef34 | 2010-03-31 19:34:01 +0000 | [diff] [blame] | 2159 | Die->addSiblingOffset(DIEValueAllocator); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2160 | |
| 2161 | // Record the abbreviation. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2162 | assignAbbrevNumber(Die->getAbbrev()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2163 | |
| 2164 | // Get the abbreviation for this DIE. |
| 2165 | unsigned AbbrevNumber = Die->getAbbrevNumber(); |
| 2166 | const DIEAbbrev *Abbrev = Abbreviations[AbbrevNumber - 1]; |
| 2167 | |
| 2168 | // Set DIE offset |
| 2169 | Die->setOffset(Offset); |
| 2170 | |
| 2171 | // Start the size with the size of abbreviation code. |
Chris Lattner | af76e59 | 2009-08-22 20:48:53 +0000 | [diff] [blame] | 2172 | Offset += MCAsmInfo::getULEB128Size(AbbrevNumber); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2173 | |
| 2174 | const SmallVector<DIEValue*, 32> &Values = Die->getValues(); |
| 2175 | const SmallVector<DIEAbbrevData, 8> &AbbrevData = Abbrev->getData(); |
| 2176 | |
| 2177 | // Size the DIE attribute values. |
| 2178 | for (unsigned i = 0, N = Values.size(); i < N; ++i) |
| 2179 | // Size attribute value. |
Chris Lattner | a37d538 | 2010-04-05 00:18:22 +0000 | [diff] [blame] | 2180 | Offset += Values[i]->SizeOf(Asm, AbbrevData[i].getForm()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2181 | |
| 2182 | // Size the DIE children if any. |
| 2183 | if (!Children.empty()) { |
| 2184 | assert(Abbrev->getChildrenFlag() == dwarf::DW_CHILDREN_yes && |
| 2185 | "Children flag not set"); |
| 2186 | |
| 2187 | for (unsigned j = 0, M = Children.size(); j < M; ++j) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2188 | Offset = computeSizeAndOffset(Children[j], Offset, (j + 1) == M); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2189 | |
| 2190 | // End of children marker. |
| 2191 | Offset += sizeof(int8_t); |
| 2192 | } |
| 2193 | |
| 2194 | Die->setSize(Offset - Die->getOffset()); |
| 2195 | return Offset; |
| 2196 | } |
| 2197 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2198 | /// computeSizeAndOffsets - Compute the size and offset of all the DIEs. |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2199 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2200 | void DwarfDebug::computeSizeAndOffsets() { |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2201 | for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(), |
| 2202 | E = CUMap.end(); I != E; ++I) { |
| 2203 | // Compute size of compile unit header. |
Devang Patel | 513edf6 | 2011-04-12 23:10:47 +0000 | [diff] [blame] | 2204 | unsigned Offset = |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2205 | sizeof(int32_t) + // Length of Compilation Unit Info |
| 2206 | sizeof(int16_t) + // DWARF version number |
| 2207 | sizeof(int32_t) + // Offset Into Abbrev. Section |
| 2208 | sizeof(int8_t); // Pointer Size (in bytes) |
| 2209 | computeSizeAndOffset(I->second->getCUDie(), Offset, true); |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2210 | } |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2211 | } |
| 2212 | |
Chris Lattner | 11b8f30 | 2010-04-04 23:02:02 +0000 | [diff] [blame] | 2213 | /// EmitSectionSym - Switch to the specified MCSection and emit an assembler |
| 2214 | /// temporary label to it if SymbolStem is specified. |
Chris Lattner | 9c69e28553 | 2010-04-04 22:59:04 +0000 | [diff] [blame] | 2215 | static MCSymbol *EmitSectionSym(AsmPrinter *Asm, const MCSection *Section, |
Chris Lattner | 11b8f30 | 2010-04-04 23:02:02 +0000 | [diff] [blame] | 2216 | const char *SymbolStem = 0) { |
Chris Lattner | 9c69e28553 | 2010-04-04 22:59:04 +0000 | [diff] [blame] | 2217 | Asm->OutStreamer.SwitchSection(Section); |
Chris Lattner | 11b8f30 | 2010-04-04 23:02:02 +0000 | [diff] [blame] | 2218 | if (!SymbolStem) return 0; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2219 | |
Chris Lattner | 9c69e28553 | 2010-04-04 22:59:04 +0000 | [diff] [blame] | 2220 | MCSymbol *TmpSym = Asm->GetTempSymbol(SymbolStem); |
| 2221 | Asm->OutStreamer.EmitLabel(TmpSym); |
| 2222 | return TmpSym; |
| 2223 | } |
| 2224 | |
| 2225 | /// EmitSectionLabels - Emit initial Dwarf sections with a label at |
| 2226 | /// the start of each one. |
Chris Lattner | fa070b0 | 2010-04-04 22:33:59 +0000 | [diff] [blame] | 2227 | void DwarfDebug::EmitSectionLabels() { |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 2228 | const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering(); |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 2229 | |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2230 | // Dwarf sections base addresses. |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2231 | DwarfInfoSectionSym = |
Chris Lattner | 9c69e28553 | 2010-04-04 22:59:04 +0000 | [diff] [blame] | 2232 | EmitSectionSym(Asm, TLOF.getDwarfInfoSection(), "section_info"); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2233 | DwarfAbbrevSectionSym = |
Chris Lattner | 9c69e28553 | 2010-04-04 22:59:04 +0000 | [diff] [blame] | 2234 | EmitSectionSym(Asm, TLOF.getDwarfAbbrevSection(), "section_abbrev"); |
Chris Lattner | 11b8f30 | 2010-04-04 23:02:02 +0000 | [diff] [blame] | 2235 | EmitSectionSym(Asm, TLOF.getDwarfARangesSection()); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2236 | |
Chris Lattner | 9c69e28553 | 2010-04-04 22:59:04 +0000 | [diff] [blame] | 2237 | if (const MCSection *MacroInfo = TLOF.getDwarfMacroInfoSection()) |
Chris Lattner | 11b8f30 | 2010-04-04 23:02:02 +0000 | [diff] [blame] | 2238 | EmitSectionSym(Asm, MacroInfo); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2239 | |
Devang Patel | af608bd | 2010-08-24 00:06:12 +0000 | [diff] [blame] | 2240 | EmitSectionSym(Asm, TLOF.getDwarfLineSection(), "section_line"); |
Chris Lattner | 11b8f30 | 2010-04-04 23:02:02 +0000 | [diff] [blame] | 2241 | EmitSectionSym(Asm, TLOF.getDwarfLocSection()); |
| 2242 | EmitSectionSym(Asm, TLOF.getDwarfPubNamesSection()); |
| 2243 | EmitSectionSym(Asm, TLOF.getDwarfPubTypesSection()); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2244 | DwarfStrSectionSym = |
Chris Lattner | 9c69e28553 | 2010-04-04 22:59:04 +0000 | [diff] [blame] | 2245 | EmitSectionSym(Asm, TLOF.getDwarfStrSection(), "section_str"); |
Devang Patel | f2548ca | 2010-04-16 23:33:45 +0000 | [diff] [blame] | 2246 | DwarfDebugRangeSectionSym = EmitSectionSym(Asm, TLOF.getDwarfRangesSection(), |
| 2247 | "debug_range"); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2248 | |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 2249 | DwarfDebugLocSectionSym = EmitSectionSym(Asm, TLOF.getDwarfLocSection(), |
| 2250 | "section_debug_loc"); |
| 2251 | |
Chris Lattner | 9c69e28553 | 2010-04-04 22:59:04 +0000 | [diff] [blame] | 2252 | TextSectionSym = EmitSectionSym(Asm, TLOF.getTextSection(), "text_begin"); |
Chris Lattner | 4ad1efe | 2010-04-04 23:10:38 +0000 | [diff] [blame] | 2253 | EmitSectionSym(Asm, TLOF.getDataSection()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2254 | } |
| 2255 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2256 | /// emitDIE - Recusively Emits a debug information entry. |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2257 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2258 | void DwarfDebug::emitDIE(DIE *Die) { |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2259 | // Get the abbreviation for this DIE. |
| 2260 | unsigned AbbrevNumber = Die->getAbbrevNumber(); |
| 2261 | const DIEAbbrev *Abbrev = Abbreviations[AbbrevNumber - 1]; |
| 2262 | |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2263 | // Emit the code (index) for the abbreviation. |
Chris Lattner | 3f53c83 | 2010-04-04 18:52:31 +0000 | [diff] [blame] | 2264 | if (Asm->isVerbose()) |
Chris Lattner | 894d75a | 2010-01-22 23:18:42 +0000 | [diff] [blame] | 2265 | Asm->OutStreamer.AddComment("Abbrev [" + Twine(AbbrevNumber) + "] 0x" + |
| 2266 | Twine::utohexstr(Die->getOffset()) + ":0x" + |
| 2267 | Twine::utohexstr(Die->getSize()) + " " + |
| 2268 | dwarf::TagString(Abbrev->getTag())); |
Chris Lattner | 7e1a8f8 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 2269 | Asm->EmitULEB128(AbbrevNumber); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2270 | |
Jeffrey Yasskin | 638fe8d | 2010-03-22 18:47:14 +0000 | [diff] [blame] | 2271 | const SmallVector<DIEValue*, 32> &Values = Die->getValues(); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2272 | const SmallVector<DIEAbbrevData, 8> &AbbrevData = Abbrev->getData(); |
| 2273 | |
| 2274 | // Emit the DIE attribute values. |
| 2275 | for (unsigned i = 0, N = Values.size(); i < N; ++i) { |
| 2276 | unsigned Attr = AbbrevData[i].getAttribute(); |
| 2277 | unsigned Form = AbbrevData[i].getForm(); |
| 2278 | assert(Form && "Too many attributes for DIE (check abbreviation)"); |
| 2279 | |
Chris Lattner | 3f53c83 | 2010-04-04 18:52:31 +0000 | [diff] [blame] | 2280 | if (Asm->isVerbose()) |
Chris Lattner | a801362 | 2010-01-24 18:54:17 +0000 | [diff] [blame] | 2281 | Asm->OutStreamer.AddComment(dwarf::AttributeString(Attr)); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2282 | |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2283 | switch (Attr) { |
| 2284 | case dwarf::DW_AT_sibling: |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2285 | Asm->EmitInt32(Die->getSiblingOffset()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2286 | break; |
| 2287 | case dwarf::DW_AT_abstract_origin: { |
| 2288 | DIEEntry *E = cast<DIEEntry>(Values[i]); |
| 2289 | DIE *Origin = E->getEntry(); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 2290 | unsigned Addr = Origin->getOffset(); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2291 | Asm->EmitInt32(Addr); |
| 2292 | break; |
| 2293 | } |
Devang Patel | f2548ca | 2010-04-16 23:33:45 +0000 | [diff] [blame] | 2294 | case dwarf::DW_AT_ranges: { |
| 2295 | // DW_AT_range Value encodes offset in debug_range section. |
| 2296 | DIEInteger *V = cast<DIEInteger>(Values[i]); |
Devang Patel | b1fcfbe | 2010-09-02 16:43:44 +0000 | [diff] [blame] | 2297 | |
| 2298 | if (Asm->MAI->doesDwarfUsesLabelOffsetForRanges()) { |
| 2299 | Asm->EmitLabelPlusOffset(DwarfDebugRangeSectionSym, |
| 2300 | V->getValue(), |
| 2301 | 4); |
| 2302 | } else { |
| 2303 | Asm->EmitLabelOffsetDifference(DwarfDebugRangeSectionSym, |
| 2304 | V->getValue(), |
| 2305 | DwarfDebugRangeSectionSym, |
| 2306 | 4); |
| 2307 | } |
Devang Patel | f2548ca | 2010-04-16 23:33:45 +0000 | [diff] [blame] | 2308 | break; |
| 2309 | } |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 2310 | case dwarf::DW_AT_location: { |
| 2311 | if (UseDotDebugLocEntry.count(Die) != 0) { |
| 2312 | DIELabel *L = cast<DIELabel>(Values[i]); |
Daniel Dunbar | 83320a0 | 2011-03-16 22:16:39 +0000 | [diff] [blame] | 2313 | Asm->EmitLabelDifference(L->getValue(), DwarfDebugLocSectionSym, 4); |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 2314 | } else |
| 2315 | Values[i]->EmitValue(Asm, Form); |
| 2316 | break; |
| 2317 | } |
Devang Patel | 2a36160 | 2010-09-29 19:08:08 +0000 | [diff] [blame] | 2318 | case dwarf::DW_AT_accessibility: { |
| 2319 | if (Asm->isVerbose()) { |
| 2320 | DIEInteger *V = cast<DIEInteger>(Values[i]); |
| 2321 | Asm->OutStreamer.AddComment(dwarf::AccessibilityString(V->getValue())); |
| 2322 | } |
| 2323 | Values[i]->EmitValue(Asm, Form); |
| 2324 | break; |
| 2325 | } |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2326 | default: |
| 2327 | // Emit an attribute using the defined form. |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 2328 | Values[i]->EmitValue(Asm, Form); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2329 | break; |
| 2330 | } |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2331 | } |
| 2332 | |
| 2333 | // Emit the DIE children if any. |
| 2334 | if (Abbrev->getChildrenFlag() == dwarf::DW_CHILDREN_yes) { |
| 2335 | const std::vector<DIE *> &Children = Die->getChildren(); |
| 2336 | |
| 2337 | for (unsigned j = 0, M = Children.size(); j < M; ++j) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2338 | emitDIE(Children[j]); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2339 | |
Chris Lattner | 3f53c83 | 2010-04-04 18:52:31 +0000 | [diff] [blame] | 2340 | if (Asm->isVerbose()) |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 2341 | Asm->OutStreamer.AddComment("End Of Children Mark"); |
| 2342 | Asm->EmitInt8(0); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2343 | } |
| 2344 | } |
| 2345 | |
Devang Patel | 8a24114 | 2009-12-09 18:24:21 +0000 | [diff] [blame] | 2346 | /// emitDebugInfo - Emit the debug info section. |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2347 | /// |
Devang Patel | 8a24114 | 2009-12-09 18:24:21 +0000 | [diff] [blame] | 2348 | void DwarfDebug::emitDebugInfo() { |
| 2349 | // Start debug info section. |
| 2350 | Asm->OutStreamer.SwitchSection( |
| 2351 | Asm->getObjFileLowering().getDwarfInfoSection()); |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2352 | for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(), |
| 2353 | E = CUMap.end(); I != E; ++I) { |
| 2354 | CompileUnit *TheCU = I->second; |
| 2355 | DIE *Die = TheCU->getCUDie(); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2356 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2357 | // Emit the compile units header. |
| 2358 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("info_begin", |
| 2359 | TheCU->getID())); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2360 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2361 | // Emit size of content not including length itself |
| 2362 | unsigned ContentSize = Die->getSize() + |
| 2363 | sizeof(int16_t) + // DWARF version number |
| 2364 | sizeof(int32_t) + // Offset Into Abbrev. Section |
Devang Patel | 65705d5 | 2011-04-13 19:41:17 +0000 | [diff] [blame] | 2365 | sizeof(int8_t); // Pointer Size (in bytes) |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2366 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2367 | Asm->OutStreamer.AddComment("Length of Compilation Unit Info"); |
| 2368 | Asm->EmitInt32(ContentSize); |
| 2369 | Asm->OutStreamer.AddComment("DWARF version number"); |
| 2370 | Asm->EmitInt16(dwarf::DWARF_VERSION); |
| 2371 | Asm->OutStreamer.AddComment("Offset Into Abbrev. Section"); |
| 2372 | Asm->EmitSectionOffset(Asm->GetTempSymbol("abbrev_begin"), |
| 2373 | DwarfAbbrevSectionSym); |
| 2374 | Asm->OutStreamer.AddComment("Address Size (in bytes)"); |
| 2375 | Asm->EmitInt8(Asm->getTargetData().getPointerSize()); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2376 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2377 | emitDIE(Die); |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2378 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("info_end", TheCU->getID())); |
| 2379 | } |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2380 | } |
| 2381 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2382 | /// emitAbbreviations - Emit the abbreviation section. |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2383 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2384 | void DwarfDebug::emitAbbreviations() const { |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2385 | // Check to see if it is worth the effort. |
| 2386 | if (!Abbreviations.empty()) { |
| 2387 | // Start the debug abbrev section. |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 2388 | Asm->OutStreamer.SwitchSection( |
| 2389 | Asm->getObjFileLowering().getDwarfAbbrevSection()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2390 | |
Chris Lattner | c021572 | 2010-04-04 19:25:43 +0000 | [diff] [blame] | 2391 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("abbrev_begin")); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2392 | |
| 2393 | // For each abbrevation. |
| 2394 | for (unsigned i = 0, N = Abbreviations.size(); i < N; ++i) { |
| 2395 | // Get abbreviation data |
| 2396 | const DIEAbbrev *Abbrev = Abbreviations[i]; |
| 2397 | |
| 2398 | // Emit the abbrevations code (base 1 index.) |
Chris Lattner | 7e1a8f8 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 2399 | Asm->EmitULEB128(Abbrev->getNumber(), "Abbreviation Code"); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2400 | |
| 2401 | // Emit the abbreviations data. |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 2402 | Abbrev->Emit(Asm); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2403 | } |
| 2404 | |
| 2405 | // Mark end of abbreviations. |
Chris Lattner | 7e1a8f8 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 2406 | Asm->EmitULEB128(0, "EOM(3)"); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2407 | |
Chris Lattner | c021572 | 2010-04-04 19:25:43 +0000 | [diff] [blame] | 2408 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("abbrev_end")); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2409 | } |
| 2410 | } |
| 2411 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2412 | /// emitEndOfLineMatrix - Emit the last address of the section and the end of |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2413 | /// the line matrix. |
| 2414 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2415 | void DwarfDebug::emitEndOfLineMatrix(unsigned SectionEnd) { |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2416 | // Define last address of section. |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 2417 | Asm->OutStreamer.AddComment("Extended Op"); |
| 2418 | Asm->EmitInt8(0); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2419 | |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 2420 | Asm->OutStreamer.AddComment("Op size"); |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 2421 | Asm->EmitInt8(Asm->getTargetData().getPointerSize() + 1); |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 2422 | Asm->OutStreamer.AddComment("DW_LNE_set_address"); |
| 2423 | Asm->EmitInt8(dwarf::DW_LNE_set_address); |
| 2424 | |
| 2425 | Asm->OutStreamer.AddComment("Section end label"); |
Chris Lattner | d85fc6e | 2010-03-10 01:17:49 +0000 | [diff] [blame] | 2426 | |
Chris Lattner | c021572 | 2010-04-04 19:25:43 +0000 | [diff] [blame] | 2427 | Asm->OutStreamer.EmitSymbolValue(Asm->GetTempSymbol("section_end",SectionEnd), |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 2428 | Asm->getTargetData().getPointerSize(), |
| 2429 | 0/*AddrSpace*/); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2430 | |
| 2431 | // Mark end of matrix. |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 2432 | Asm->OutStreamer.AddComment("DW_LNE_end_sequence"); |
| 2433 | Asm->EmitInt8(0); |
Chris Lattner | 0ad9c91 | 2010-01-22 22:09:00 +0000 | [diff] [blame] | 2434 | Asm->EmitInt8(1); |
Chris Lattner | 894d75a | 2010-01-22 23:18:42 +0000 | [diff] [blame] | 2435 | Asm->EmitInt8(1); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2436 | } |
| 2437 | |
Devang Patel | 8a24114 | 2009-12-09 18:24:21 +0000 | [diff] [blame] | 2438 | /// emitDebugPubNames - Emit visible names into a debug pubnames section. |
| 2439 | /// |
| 2440 | void DwarfDebug::emitDebugPubNames() { |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2441 | for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(), |
| 2442 | E = CUMap.end(); I != E; ++I) { |
| 2443 | CompileUnit *TheCU = I->second; |
| 2444 | // Start the dwarf pubnames section. |
| 2445 | Asm->OutStreamer.SwitchSection( |
| 2446 | Asm->getObjFileLowering().getDwarfPubNamesSection()); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2447 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2448 | Asm->OutStreamer.AddComment("Length of Public Names Info"); |
| 2449 | Asm->EmitLabelDifference( |
| 2450 | Asm->GetTempSymbol("pubnames_end", TheCU->getID()), |
| 2451 | Asm->GetTempSymbol("pubnames_begin", TheCU->getID()), 4); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2452 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2453 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("pubnames_begin", |
| 2454 | TheCU->getID())); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2455 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2456 | Asm->OutStreamer.AddComment("DWARF Version"); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2457 | Asm->EmitInt16(dwarf::DWARF_VERSION); |
| 2458 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2459 | Asm->OutStreamer.AddComment("Offset of Compilation Unit Info"); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2460 | Asm->EmitSectionOffset(Asm->GetTempSymbol("info_begin", TheCU->getID()), |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2461 | DwarfInfoSectionSym); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2462 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2463 | Asm->OutStreamer.AddComment("Compilation Unit Length"); |
| 2464 | Asm->EmitLabelDifference(Asm->GetTempSymbol("info_end", TheCU->getID()), |
| 2465 | Asm->GetTempSymbol("info_begin", TheCU->getID()), |
| 2466 | 4); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2467 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2468 | const StringMap<DIE*> &Globals = TheCU->getGlobals(); |
| 2469 | for (StringMap<DIE*>::const_iterator |
| 2470 | GI = Globals.begin(), GE = Globals.end(); GI != GE; ++GI) { |
| 2471 | const char *Name = GI->getKeyData(); |
| 2472 | DIE *Entity = GI->second; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2473 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2474 | Asm->OutStreamer.AddComment("DIE offset"); |
| 2475 | Asm->EmitInt32(Entity->getOffset()); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2476 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2477 | if (Asm->isVerbose()) |
| 2478 | Asm->OutStreamer.AddComment("External Name"); |
| 2479 | Asm->OutStreamer.EmitBytes(StringRef(Name, strlen(Name)+1), 0); |
| 2480 | } |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2481 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2482 | Asm->OutStreamer.AddComment("End Mark"); |
| 2483 | Asm->EmitInt32(0); |
| 2484 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("pubnames_end", |
| 2485 | TheCU->getID())); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2486 | } |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2487 | } |
| 2488 | |
Devang Patel | 193f720 | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 2489 | void DwarfDebug::emitDebugPubTypes() { |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2490 | for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(), |
| 2491 | E = CUMap.end(); I != E; ++I) { |
| 2492 | CompileUnit *TheCU = I->second; |
| 2493 | // Start the dwarf pubnames section. |
| 2494 | Asm->OutStreamer.SwitchSection( |
| 2495 | Asm->getObjFileLowering().getDwarfPubTypesSection()); |
| 2496 | Asm->OutStreamer.AddComment("Length of Public Types Info"); |
| 2497 | Asm->EmitLabelDifference( |
| 2498 | Asm->GetTempSymbol("pubtypes_end", TheCU->getID()), |
| 2499 | Asm->GetTempSymbol("pubtypes_begin", TheCU->getID()), 4); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2500 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2501 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("pubtypes_begin", |
| 2502 | TheCU->getID())); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2503 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2504 | if (Asm->isVerbose()) Asm->OutStreamer.AddComment("DWARF Version"); |
| 2505 | Asm->EmitInt16(dwarf::DWARF_VERSION); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2506 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2507 | Asm->OutStreamer.AddComment("Offset of Compilation Unit Info"); |
| 2508 | Asm->EmitSectionOffset(Asm->GetTempSymbol("info_begin", TheCU->getID()), |
| 2509 | DwarfInfoSectionSym); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2510 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2511 | Asm->OutStreamer.AddComment("Compilation Unit Length"); |
| 2512 | Asm->EmitLabelDifference(Asm->GetTempSymbol("info_end", TheCU->getID()), |
| 2513 | Asm->GetTempSymbol("info_begin", TheCU->getID()), |
| 2514 | 4); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2515 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2516 | const StringMap<DIE*> &Globals = TheCU->getGlobalTypes(); |
| 2517 | for (StringMap<DIE*>::const_iterator |
| 2518 | GI = Globals.begin(), GE = Globals.end(); GI != GE; ++GI) { |
| 2519 | const char *Name = GI->getKeyData(); |
| 2520 | DIE * Entity = GI->second; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2521 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2522 | if (Asm->isVerbose()) Asm->OutStreamer.AddComment("DIE offset"); |
| 2523 | Asm->EmitInt32(Entity->getOffset()); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2524 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2525 | if (Asm->isVerbose()) Asm->OutStreamer.AddComment("External Name"); |
| 2526 | Asm->OutStreamer.EmitBytes(StringRef(Name, GI->getKeyLength()+1), 0); |
| 2527 | } |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2528 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2529 | Asm->OutStreamer.AddComment("End Mark"); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2530 | Asm->EmitInt32(0); |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2531 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("pubtypes_end", |
| 2532 | TheCU->getID())); |
Devang Patel | 193f720 | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 2533 | } |
Devang Patel | 193f720 | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 2534 | } |
| 2535 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2536 | /// emitDebugStr - Emit visible names into a debug str section. |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2537 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2538 | void DwarfDebug::emitDebugStr() { |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2539 | // Check to see if it is worth the effort. |
Chris Lattner | 0d9d70f | 2010-03-09 23:38:23 +0000 | [diff] [blame] | 2540 | if (StringPool.empty()) return; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2541 | |
Chris Lattner | 0d9d70f | 2010-03-09 23:38:23 +0000 | [diff] [blame] | 2542 | // Start the dwarf str section. |
| 2543 | Asm->OutStreamer.SwitchSection( |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 2544 | Asm->getObjFileLowering().getDwarfStrSection()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2545 | |
Chris Lattner | bc733f5 | 2010-03-13 02:17:42 +0000 | [diff] [blame] | 2546 | // Get all of the string pool entries and put them in an array by their ID so |
| 2547 | // we can sort them. |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2548 | SmallVector<std::pair<unsigned, |
Chris Lattner | bc733f5 | 2010-03-13 02:17:42 +0000 | [diff] [blame] | 2549 | StringMapEntry<std::pair<MCSymbol*, unsigned> >*>, 64> Entries; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2550 | |
Chris Lattner | bc733f5 | 2010-03-13 02:17:42 +0000 | [diff] [blame] | 2551 | for (StringMap<std::pair<MCSymbol*, unsigned> >::iterator |
| 2552 | I = StringPool.begin(), E = StringPool.end(); I != E; ++I) |
| 2553 | Entries.push_back(std::make_pair(I->second.second, &*I)); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2554 | |
Chris Lattner | bc733f5 | 2010-03-13 02:17:42 +0000 | [diff] [blame] | 2555 | array_pod_sort(Entries.begin(), Entries.end()); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2556 | |
Chris Lattner | bc733f5 | 2010-03-13 02:17:42 +0000 | [diff] [blame] | 2557 | for (unsigned i = 0, e = Entries.size(); i != e; ++i) { |
Chris Lattner | 0d9d70f | 2010-03-09 23:38:23 +0000 | [diff] [blame] | 2558 | // Emit a label for reference from debug information entries. |
Chris Lattner | bc733f5 | 2010-03-13 02:17:42 +0000 | [diff] [blame] | 2559 | Asm->OutStreamer.EmitLabel(Entries[i].second->getValue().first); |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2560 | |
Chris Lattner | 0d9d70f | 2010-03-09 23:38:23 +0000 | [diff] [blame] | 2561 | // Emit the string itself. |
Chris Lattner | bc733f5 | 2010-03-13 02:17:42 +0000 | [diff] [blame] | 2562 | Asm->OutStreamer.EmitBytes(Entries[i].second->getKey(), 0/*addrspace*/); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2563 | } |
| 2564 | } |
| 2565 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2566 | /// emitDebugLoc - Emit visible names into a debug loc section. |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2567 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2568 | void DwarfDebug::emitDebugLoc() { |
Devang Patel | 8025068 | 2010-05-26 23:55:23 +0000 | [diff] [blame] | 2569 | if (DotDebugLocEntries.empty()) |
| 2570 | return; |
| 2571 | |
Devang Patel | 6c3ea90 | 2011-02-04 22:57:18 +0000 | [diff] [blame] | 2572 | for (SmallVector<DotDebugLocEntry, 4>::iterator |
| 2573 | I = DotDebugLocEntries.begin(), E = DotDebugLocEntries.end(); |
| 2574 | I != E; ++I) { |
| 2575 | DotDebugLocEntry &Entry = *I; |
| 2576 | if (I + 1 != DotDebugLocEntries.end()) |
| 2577 | Entry.Merge(I+1); |
| 2578 | } |
| 2579 | |
Daniel Dunbar | 83320a0 | 2011-03-16 22:16:39 +0000 | [diff] [blame] | 2580 | // Start the dwarf loc section. |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 2581 | Asm->OutStreamer.SwitchSection( |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 2582 | Asm->getObjFileLowering().getDwarfLocSection()); |
| 2583 | unsigned char Size = Asm->getTargetData().getPointerSize(); |
Devang Patel | 8025068 | 2010-05-26 23:55:23 +0000 | [diff] [blame] | 2584 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("debug_loc", 0)); |
| 2585 | unsigned index = 1; |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2586 | for (SmallVector<DotDebugLocEntry, 4>::iterator |
| 2587 | I = DotDebugLocEntries.begin(), E = DotDebugLocEntries.end(); |
Devang Patel | 6140962 | 2010-07-07 20:12:52 +0000 | [diff] [blame] | 2588 | I != E; ++I, ++index) { |
Devang Patel | 6c3ea90 | 2011-02-04 22:57:18 +0000 | [diff] [blame] | 2589 | DotDebugLocEntry &Entry = *I; |
| 2590 | if (Entry.isMerged()) continue; |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 2591 | if (Entry.isEmpty()) { |
| 2592 | Asm->OutStreamer.EmitIntValue(0, Size, /*addrspace*/0); |
| 2593 | Asm->OutStreamer.EmitIntValue(0, Size, /*addrspace*/0); |
Devang Patel | 8025068 | 2010-05-26 23:55:23 +0000 | [diff] [blame] | 2594 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("debug_loc", index)); |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 2595 | } else { |
| 2596 | Asm->OutStreamer.EmitSymbolValue(Entry.Begin, Size, 0); |
| 2597 | Asm->OutStreamer.EmitSymbolValue(Entry.End, Size, 0); |
Devang Patel | c26f544 | 2011-04-28 02:22:40 +0000 | [diff] [blame] | 2598 | DIVariable DV(Entry.Variable); |
Rafael Espindola | 5b23b7f | 2011-05-27 22:05:41 +0000 | [diff] [blame] | 2599 | Asm->OutStreamer.AddComment("Loc expr size"); |
| 2600 | MCSymbol *begin = Asm->OutStreamer.getContext().CreateTempSymbol(); |
| 2601 | MCSymbol *end = Asm->OutStreamer.getContext().CreateTempSymbol(); |
| 2602 | Asm->EmitLabelDifference(end, begin, 2); |
| 2603 | Asm->OutStreamer.EmitLabel(begin); |
Devang Patel | c432907 | 2011-06-01 22:03:25 +0000 | [diff] [blame] | 2604 | if (Entry.isConstant()) { |
| 2605 | DIBasicType BTy(DV.getType()); |
| 2606 | if (BTy.Verify() && |
| 2607 | (BTy.getEncoding() == dwarf::DW_ATE_signed |
| 2608 | || BTy.getEncoding() == dwarf::DW_ATE_signed_char)) { |
| 2609 | Asm->OutStreamer.AddComment("DW_OP_consts"); |
| 2610 | Asm->EmitInt8(dwarf::DW_OP_consts); |
| 2611 | Asm->EmitSLEB128(Entry.getConstant()); |
| 2612 | } else { |
| 2613 | Asm->OutStreamer.AddComment("DW_OP_constu"); |
| 2614 | Asm->EmitInt8(dwarf::DW_OP_constu); |
| 2615 | Asm->EmitULEB128(Entry.getConstant()); |
| 2616 | } |
| 2617 | } else if (DV.hasComplexAddress()) { |
Devang Patel | c26f544 | 2011-04-28 02:22:40 +0000 | [diff] [blame] | 2618 | unsigned N = DV.getNumAddrElements(); |
| 2619 | unsigned i = 0; |
Devang Patel | c26f544 | 2011-04-28 02:22:40 +0000 | [diff] [blame] | 2620 | if (N >= 2 && DV.getAddrElement(0) == DIBuilder::OpPlus) { |
Devang Patel | a9b324b | 2011-05-24 00:22:25 +0000 | [diff] [blame] | 2621 | if (Entry.Loc.getOffset()) { |
Devang Patel | a9b324b | 2011-05-24 00:22:25 +0000 | [diff] [blame] | 2622 | i = 2; |
| 2623 | Asm->EmitDwarfRegOp(Entry.Loc); |
| 2624 | Asm->OutStreamer.AddComment("DW_OP_deref"); |
| 2625 | Asm->EmitInt8(dwarf::DW_OP_deref); |
| 2626 | Asm->OutStreamer.AddComment("DW_OP_plus_uconst"); |
| 2627 | Asm->EmitInt8(dwarf::DW_OP_plus_uconst); |
| 2628 | Asm->EmitSLEB128(DV.getAddrElement(1)); |
| 2629 | } else { |
| 2630 | // If first address element is OpPlus then emit |
| 2631 | // DW_OP_breg + Offset instead of DW_OP_reg + Offset. |
| 2632 | MachineLocation Loc(Entry.Loc.getReg(), DV.getAddrElement(1)); |
Devang Patel | a9b324b | 2011-05-24 00:22:25 +0000 | [diff] [blame] | 2633 | Asm->EmitDwarfRegOp(Loc); |
| 2634 | i = 2; |
| 2635 | } |
Devang Patel | c26f544 | 2011-04-28 02:22:40 +0000 | [diff] [blame] | 2636 | } else { |
Devang Patel | c26f544 | 2011-04-28 02:22:40 +0000 | [diff] [blame] | 2637 | Asm->EmitDwarfRegOp(Entry.Loc); |
| 2638 | } |
| 2639 | |
| 2640 | // Emit remaining complex address elements. |
| 2641 | for (; i < N; ++i) { |
| 2642 | uint64_t Element = DV.getAddrElement(i); |
| 2643 | if (Element == DIBuilder::OpPlus) { |
| 2644 | Asm->EmitInt8(dwarf::DW_OP_plus_uconst); |
| 2645 | Asm->EmitULEB128(DV.getAddrElement(++i)); |
| 2646 | } else if (Element == DIBuilder::OpDeref) |
| 2647 | Asm->EmitInt8(dwarf::DW_OP_deref); |
| 2648 | else llvm_unreachable("unknown Opcode found in complex address"); |
| 2649 | } |
| 2650 | } else { |
Devang Patel | c432907 | 2011-06-01 22:03:25 +0000 | [diff] [blame] | 2651 | // Regular entry. |
Devang Patel | c26f544 | 2011-04-28 02:22:40 +0000 | [diff] [blame] | 2652 | Asm->EmitDwarfRegOp(Entry.Loc); |
| 2653 | } |
Rafael Espindola | 5b23b7f | 2011-05-27 22:05:41 +0000 | [diff] [blame] | 2654 | Asm->OutStreamer.EmitLabel(end); |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 2655 | } |
| 2656 | } |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2657 | } |
| 2658 | |
| 2659 | /// EmitDebugARanges - Emit visible names into a debug aranges section. |
| 2660 | /// |
| 2661 | void DwarfDebug::EmitDebugARanges() { |
| 2662 | // Start the dwarf aranges section. |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 2663 | Asm->OutStreamer.SwitchSection( |
| 2664 | Asm->getObjFileLowering().getDwarfARangesSection()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2665 | } |
| 2666 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2667 | /// emitDebugRanges - Emit visible names into a debug ranges section. |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2668 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2669 | void DwarfDebug::emitDebugRanges() { |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2670 | // Start the dwarf ranges section. |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 2671 | Asm->OutStreamer.SwitchSection( |
Devang Patel | f2548ca | 2010-04-16 23:33:45 +0000 | [diff] [blame] | 2672 | Asm->getObjFileLowering().getDwarfRangesSection()); |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 2673 | unsigned char Size = Asm->getTargetData().getPointerSize(); |
| 2674 | for (SmallVector<const MCSymbol *, 8>::iterator |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2675 | I = DebugRangeSymbols.begin(), E = DebugRangeSymbols.end(); |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 2676 | I != E; ++I) { |
| 2677 | if (*I) |
| 2678 | Asm->OutStreamer.EmitSymbolValue(const_cast<MCSymbol*>(*I), Size, 0); |
Devang Patel | f2548ca | 2010-04-16 23:33:45 +0000 | [diff] [blame] | 2679 | else |
Devang Patel | eac9c07 | 2010-04-27 19:46:33 +0000 | [diff] [blame] | 2680 | Asm->OutStreamer.EmitIntValue(0, Size, /*addrspace*/0); |
Devang Patel | f2548ca | 2010-04-16 23:33:45 +0000 | [diff] [blame] | 2681 | } |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2682 | } |
| 2683 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2684 | /// emitDebugMacInfo - Emit visible names into a debug macinfo section. |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2685 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2686 | void DwarfDebug::emitDebugMacInfo() { |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 2687 | if (const MCSection *LineInfo = |
Chris Lattner | 18a4c16 | 2009-08-02 07:24:22 +0000 | [diff] [blame] | 2688 | Asm->getObjFileLowering().getDwarfMacroInfoSection()) { |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2689 | // Start the dwarf macinfo section. |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 2690 | Asm->OutStreamer.SwitchSection(LineInfo); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2691 | } |
| 2692 | } |
| 2693 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2694 | /// emitDebugInlineInfo - Emit inline info using following format. |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2695 | /// Section Header: |
| 2696 | /// 1. length of section |
| 2697 | /// 2. Dwarf version number |
| 2698 | /// 3. address size. |
| 2699 | /// |
| 2700 | /// Entries (one "entry" for each function that was inlined): |
| 2701 | /// |
| 2702 | /// 1. offset into __debug_str section for MIPS linkage name, if exists; |
| 2703 | /// otherwise offset into __debug_str for regular function name. |
| 2704 | /// 2. offset into __debug_str section for regular function name. |
| 2705 | /// 3. an unsigned LEB128 number indicating the number of distinct inlining |
| 2706 | /// instances for the function. |
| 2707 | /// |
| 2708 | /// The rest of the entry consists of a {die_offset, low_pc} pair for each |
| 2709 | /// inlined instance; the die_offset points to the inlined_subroutine die in the |
| 2710 | /// __debug_info section, and the low_pc is the starting address for the |
| 2711 | /// inlining instance. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2712 | void DwarfDebug::emitDebugInlineInfo() { |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 2713 | if (!Asm->MAI->doesDwarfUsesInlineInfoSection()) |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2714 | return; |
| 2715 | |
Devang Patel | 163a9f7 | 2010-05-10 22:49:55 +0000 | [diff] [blame] | 2716 | if (!FirstCU) |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2717 | return; |
| 2718 | |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 2719 | Asm->OutStreamer.SwitchSection( |
| 2720 | Asm->getObjFileLowering().getDwarfDebugInlineSection()); |
Chris Lattner | 0ad9c91 | 2010-01-22 22:09:00 +0000 | [diff] [blame] | 2721 | |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 2722 | Asm->OutStreamer.AddComment("Length of Debug Inlined Information Entry"); |
Chris Lattner | a643718 | 2010-04-04 19:58:12 +0000 | [diff] [blame] | 2723 | Asm->EmitLabelDifference(Asm->GetTempSymbol("debug_inlined_end", 1), |
| 2724 | Asm->GetTempSymbol("debug_inlined_begin", 1), 4); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2725 | |
Chris Lattner | c021572 | 2010-04-04 19:25:43 +0000 | [diff] [blame] | 2726 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("debug_inlined_begin", 1)); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2727 | |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 2728 | Asm->OutStreamer.AddComment("Dwarf Version"); |
| 2729 | Asm->EmitInt16(dwarf::DWARF_VERSION); |
| 2730 | Asm->OutStreamer.AddComment("Address Size (in bytes)"); |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 2731 | Asm->EmitInt8(Asm->getTargetData().getPointerSize()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2732 | |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 2733 | for (SmallVector<const MDNode *, 4>::iterator I = InlinedSPNodes.begin(), |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 2734 | E = InlinedSPNodes.end(); I != E; ++I) { |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 2735 | |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 2736 | const MDNode *Node = *I; |
| 2737 | DenseMap<const MDNode *, SmallVector<InlineInfoLabels, 4> >::iterator II |
Jim Grosbach | 7ab38df | 2009-11-22 19:20:36 +0000 | [diff] [blame] | 2738 | = InlineInfo.find(Node); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 2739 | SmallVector<InlineInfoLabels, 4> &Labels = II->second; |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 2740 | DISubprogram SP(Node); |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 2741 | StringRef LName = SP.getLinkageName(); |
| 2742 | StringRef Name = SP.getName(); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2743 | |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 2744 | Asm->OutStreamer.AddComment("MIPS linkage name"); |
Chris Lattner | 4cf202b | 2010-01-23 03:11:46 +0000 | [diff] [blame] | 2745 | if (LName.empty()) { |
| 2746 | Asm->OutStreamer.EmitBytes(Name, 0); |
| 2747 | Asm->OutStreamer.EmitIntValue(0, 1, 0); // nul terminator. |
Jim Grosbach | 1e20b96 | 2010-07-21 21:21:52 +0000 | [diff] [blame] | 2748 | } else |
Chris Lattner | 6189ed1 | 2010-04-04 23:25:33 +0000 | [diff] [blame] | 2749 | Asm->EmitSectionOffset(getStringPoolEntry(getRealLinkageName(LName)), |
| 2750 | DwarfStrSectionSym); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 2751 | |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 2752 | Asm->OutStreamer.AddComment("Function name"); |
Chris Lattner | 6189ed1 | 2010-04-04 23:25:33 +0000 | [diff] [blame] | 2753 | Asm->EmitSectionOffset(getStringPoolEntry(Name), DwarfStrSectionSym); |
Chris Lattner | 7e1a8f8 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 2754 | Asm->EmitULEB128(Labels.size(), "Inline count"); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2755 | |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 2756 | for (SmallVector<InlineInfoLabels, 4>::iterator LI = Labels.begin(), |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2757 | LE = Labels.end(); LI != LE; ++LI) { |
Chris Lattner | 3f53c83 | 2010-04-04 18:52:31 +0000 | [diff] [blame] | 2758 | if (Asm->isVerbose()) Asm->OutStreamer.AddComment("DIE offset"); |
Chris Lattner | 6ed0f90 | 2010-03-09 00:31:02 +0000 | [diff] [blame] | 2759 | Asm->EmitInt32(LI->second->getOffset()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2760 | |
Chris Lattner | 3f53c83 | 2010-04-04 18:52:31 +0000 | [diff] [blame] | 2761 | if (Asm->isVerbose()) Asm->OutStreamer.AddComment("low_pc"); |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 2762 | Asm->OutStreamer.EmitSymbolValue(LI->first, |
| 2763 | Asm->getTargetData().getPointerSize(),0); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2764 | } |
| 2765 | } |
| 2766 | |
Chris Lattner | c021572 | 2010-04-04 19:25:43 +0000 | [diff] [blame] | 2767 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("debug_inlined_end", 1)); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2768 | } |