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 | //===----------------------------------------------------------------------===// |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 13 | #define DEBUG_TYPE "dwarfdebug" |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 14 | #include "DwarfDebug.h" |
| 15 | #include "llvm/Module.h" |
David Greene | b2c66fc | 2009-08-19 21:52:55 +0000 | [diff] [blame] | 16 | #include "llvm/CodeGen/MachineFunction.h" |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 17 | #include "llvm/CodeGen/MachineModuleInfo.h" |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 18 | #include "llvm/MC/MCSection.h" |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 19 | #include "llvm/MC/MCStreamer.h" |
Chris Lattner | af76e59 | 2009-08-22 20:48:53 +0000 | [diff] [blame] | 20 | #include "llvm/MC/MCAsmInfo.h" |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 21 | #include "llvm/Target/TargetData.h" |
| 22 | #include "llvm/Target/TargetFrameInfo.h" |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 23 | #include "llvm/Target/TargetLoweringObjectFile.h" |
| 24 | #include "llvm/Target/TargetRegisterInfo.h" |
Chris Lattner | 23132b1 | 2009-08-24 03:52:50 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/StringExtras.h" |
Daniel Dunbar | 6e4bdfc | 2009-10-13 06:47:08 +0000 | [diff] [blame] | 26 | #include "llvm/Support/Debug.h" |
| 27 | #include "llvm/Support/ErrorHandling.h" |
Chris Lattner | 334fd1f | 2009-09-16 00:08:41 +0000 | [diff] [blame] | 28 | #include "llvm/Support/Mangler.h" |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 29 | #include "llvm/Support/Timer.h" |
| 30 | #include "llvm/System/Path.h" |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 31 | using namespace llvm; |
| 32 | |
| 33 | static TimerGroup &getDwarfTimerGroup() { |
| 34 | static TimerGroup DwarfTimerGroup("Dwarf Debugging"); |
| 35 | return DwarfTimerGroup; |
| 36 | } |
| 37 | |
| 38 | //===----------------------------------------------------------------------===// |
| 39 | |
| 40 | /// Configuration values for initial hash set sizes (log2). |
| 41 | /// |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 42 | static const unsigned InitAbbreviationsSetSize = 9; // log2(512) |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 43 | |
| 44 | namespace llvm { |
| 45 | |
| 46 | //===----------------------------------------------------------------------===// |
| 47 | /// CompileUnit - This dwarf writer support class manages information associate |
| 48 | /// with a source file. |
Nick Lewycky | 5f9843f | 2009-11-17 08:11:44 +0000 | [diff] [blame] | 49 | class CompileUnit { |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 50 | /// ID - File identifier for source. |
| 51 | /// |
| 52 | unsigned ID; |
| 53 | |
| 54 | /// Die - Compile unit debug information entry. |
| 55 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 56 | DIE *CUDie; |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 57 | |
Devang Patel | 6f01d9c | 2009-11-21 00:31:03 +0000 | [diff] [blame] | 58 | /// IndexTyDie - An anonymous type for index type. |
| 59 | DIE *IndexTyDie; |
| 60 | |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 61 | /// GVToDieMap - Tracks the mapping of unit level debug informaton |
| 62 | /// variables to debug information entries. |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 63 | /// FIXME : Rename GVToDieMap -> NodeToDieMap |
Devang Patel | 017d121 | 2009-11-20 21:37:22 +0000 | [diff] [blame] | 64 | ValueMap<MDNode *, DIE *> GVToDieMap; |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 65 | |
| 66 | /// GVToDIEEntryMap - Tracks the mapping of unit level debug informaton |
| 67 | /// descriptors to debug information entries using a DIEEntry proxy. |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 68 | /// FIXME : Rename |
Devang Patel | 017d121 | 2009-11-20 21:37:22 +0000 | [diff] [blame] | 69 | ValueMap<MDNode *, DIEEntry *> GVToDIEEntryMap; |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 70 | |
| 71 | /// Globals - A map of globally visible named entities for this unit. |
| 72 | /// |
| 73 | StringMap<DIE*> Globals; |
| 74 | |
Devang Patel | 193f720 | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 75 | /// GlobalTypes - A map of globally visible types for this unit. |
| 76 | /// |
| 77 | StringMap<DIE*> GlobalTypes; |
| 78 | |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 79 | public: |
| 80 | CompileUnit(unsigned I, DIE *D) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 81 | : ID(I), CUDie(D), IndexTyDie(0) {} |
| 82 | ~CompileUnit() { delete CUDie; delete IndexTyDie; } |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 83 | |
| 84 | // Accessors. |
Devang Patel | 193f720 | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 85 | unsigned getID() const { return ID; } |
| 86 | DIE* getCUDie() const { return CUDie; } |
| 87 | const StringMap<DIE*> &getGlobals() const { return Globals; } |
| 88 | const StringMap<DIE*> &getGlobalTypes() const { return GlobalTypes; } |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 89 | |
| 90 | /// hasContent - Return true if this compile unit has something to write out. |
| 91 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 92 | bool hasContent() const { return !CUDie->getChildren().empty(); } |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 93 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 94 | /// addGlobal - Add a new global entity to the compile unit. |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 95 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 96 | void addGlobal(const std::string &Name, DIE *Die) { Globals[Name] = Die; } |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 97 | |
Devang Patel | 193f720 | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 98 | /// addGlobalType - Add a new global type to the compile unit. |
| 99 | /// |
| 100 | void addGlobalType(const std::string &Name, DIE *Die) { |
| 101 | GlobalTypes[Name] = Die; |
| 102 | } |
| 103 | |
Devang Patel | 017d121 | 2009-11-20 21:37:22 +0000 | [diff] [blame] | 104 | /// getDIE - Returns the debug information entry map slot for the |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 105 | /// specified debug variable. |
Devang Patel | 017d121 | 2009-11-20 21:37:22 +0000 | [diff] [blame] | 106 | DIE *getDIE(MDNode *N) { return GVToDieMap.lookup(N); } |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 107 | |
Devang Patel | 017d121 | 2009-11-20 21:37:22 +0000 | [diff] [blame] | 108 | /// insertDIE - Insert DIE into the map. |
| 109 | void insertDIE(MDNode *N, DIE *D) { |
| 110 | GVToDieMap.insert(std::make_pair(N, D)); |
| 111 | } |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 112 | |
Devang Patel | 017d121 | 2009-11-20 21:37:22 +0000 | [diff] [blame] | 113 | /// getDIEEntry - Returns the debug information entry for the speciefied |
| 114 | /// debug variable. |
| 115 | DIEEntry *getDIEEntry(MDNode *N) { return GVToDIEEntryMap.lookup(N); } |
| 116 | |
| 117 | /// insertDIEEntry - Insert debug information entry into the map. |
| 118 | void insertDIEEntry(MDNode *N, DIEEntry *E) { |
| 119 | GVToDIEEntryMap.insert(std::make_pair(N, E)); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 120 | } |
| 121 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 122 | /// addDie - Adds or interns the DIE to the compile unit. |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 123 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 124 | void addDie(DIE *Buffer) { |
| 125 | this->CUDie->addChild(Buffer); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 126 | } |
Devang Patel | 6f01d9c | 2009-11-21 00:31:03 +0000 | [diff] [blame] | 127 | |
| 128 | // getIndexTyDie - Get an anonymous type for index type. |
| 129 | DIE *getIndexTyDie() { |
| 130 | return IndexTyDie; |
| 131 | } |
| 132 | |
Jim Grosbach | 7ab38df | 2009-11-22 19:20:36 +0000 | [diff] [blame] | 133 | // setIndexTyDie - Set D as anonymous type for index which can be reused |
| 134 | // later. |
Devang Patel | 6f01d9c | 2009-11-21 00:31:03 +0000 | [diff] [blame] | 135 | void setIndexTyDie(DIE *D) { |
| 136 | IndexTyDie = D; |
| 137 | } |
| 138 | |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 139 | }; |
| 140 | |
| 141 | //===----------------------------------------------------------------------===// |
| 142 | /// DbgVariable - This class is used to track local variable information. |
| 143 | /// |
Devang Patel | f76a3d6 | 2009-11-16 21:53:40 +0000 | [diff] [blame] | 144 | class DbgVariable { |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 145 | DIVariable Var; // Variable Descriptor. |
| 146 | unsigned FrameIndex; // Variable frame index. |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 147 | DbgVariable *AbstractVar; // Abstract variable for this variable. |
| 148 | DIE *TheDIE; |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 149 | public: |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 150 | DbgVariable(DIVariable V, unsigned I) |
| 151 | : Var(V), FrameIndex(I), AbstractVar(0), TheDIE(0) {} |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 152 | |
| 153 | // Accessors. |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 154 | DIVariable getVariable() const { return Var; } |
| 155 | unsigned getFrameIndex() const { return FrameIndex; } |
| 156 | void setAbstractVariable(DbgVariable *V) { AbstractVar = V; } |
| 157 | DbgVariable *getAbstractVariable() const { return AbstractVar; } |
| 158 | void setDIE(DIE *D) { TheDIE = D; } |
| 159 | DIE *getDIE() const { return TheDIE; } |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 160 | }; |
| 161 | |
| 162 | //===----------------------------------------------------------------------===// |
| 163 | /// DbgScope - This class is used to track scope information. |
| 164 | /// |
Devang Patel | f76a3d6 | 2009-11-16 21:53:40 +0000 | [diff] [blame] | 165 | class DbgScope { |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 166 | DbgScope *Parent; // Parent to this scope. |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 167 | DIDescriptor Desc; // Debug info descriptor for scope. |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 168 | WeakVH InlinedAtLocation; // Location at which scope is inlined. |
| 169 | bool AbstractScope; // Abstract Scope |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 170 | unsigned StartLabelID; // Label ID of the beginning of scope. |
| 171 | unsigned EndLabelID; // Label ID of the end of scope. |
Devang Patel | d38dd11 | 2009-10-01 18:25:23 +0000 | [diff] [blame] | 172 | const MachineInstr *LastInsn; // Last instruction of this scope. |
| 173 | const MachineInstr *FirstInsn; // First instruction of this scope. |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 174 | SmallVector<DbgScope *, 4> Scopes; // Scopes defined in scope. |
| 175 | SmallVector<DbgVariable *, 8> Variables;// Variables declared in scope. |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 176 | |
Owen Anderson | 04c05f7 | 2009-06-24 22:53:20 +0000 | [diff] [blame] | 177 | // Private state for dump() |
| 178 | mutable unsigned IndentLevel; |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 179 | public: |
Devang Patel | c90aefe | 2009-10-14 21:08:09 +0000 | [diff] [blame] | 180 | DbgScope(DbgScope *P, DIDescriptor D, MDNode *I = 0) |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 181 | : Parent(P), Desc(D), InlinedAtLocation(I), AbstractScope(false), |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 182 | StartLabelID(0), EndLabelID(0), |
Devang Patel | c90aefe | 2009-10-14 21:08:09 +0000 | [diff] [blame] | 183 | LastInsn(0), FirstInsn(0), IndentLevel(0) {} |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 184 | virtual ~DbgScope(); |
| 185 | |
| 186 | // Accessors. |
| 187 | DbgScope *getParent() const { return Parent; } |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 188 | void setParent(DbgScope *P) { Parent = P; } |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 189 | DIDescriptor getDesc() const { return Desc; } |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 190 | MDNode *getInlinedAt() const { |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 191 | return dyn_cast_or_null<MDNode>(InlinedAtLocation); |
Devang Patel | c90aefe | 2009-10-14 21:08:09 +0000 | [diff] [blame] | 192 | } |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 193 | MDNode *getScopeNode() const { return Desc.getNode(); } |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 194 | unsigned getStartLabelID() const { return StartLabelID; } |
| 195 | unsigned getEndLabelID() const { return EndLabelID; } |
| 196 | SmallVector<DbgScope *, 4> &getScopes() { return Scopes; } |
| 197 | SmallVector<DbgVariable *, 8> &getVariables() { return Variables; } |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 198 | void setStartLabelID(unsigned S) { StartLabelID = S; } |
| 199 | void setEndLabelID(unsigned E) { EndLabelID = E; } |
Devang Patel | d38dd11 | 2009-10-01 18:25:23 +0000 | [diff] [blame] | 200 | void setLastInsn(const MachineInstr *MI) { LastInsn = MI; } |
| 201 | const MachineInstr *getLastInsn() { return LastInsn; } |
| 202 | void setFirstInsn(const MachineInstr *MI) { FirstInsn = MI; } |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 203 | void setAbstractScope() { AbstractScope = true; } |
| 204 | bool isAbstractScope() const { return AbstractScope; } |
Devang Patel | d38dd11 | 2009-10-01 18:25:23 +0000 | [diff] [blame] | 205 | const MachineInstr *getFirstInsn() { return FirstInsn; } |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 206 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 207 | /// addScope - Add a scope to the scope. |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 208 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 209 | void addScope(DbgScope *S) { Scopes.push_back(S); } |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 210 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 211 | /// addVariable - Add a variable to the scope. |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 212 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 213 | void addVariable(DbgVariable *V) { Variables.push_back(V); } |
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 fixInstructionMarkers() { |
Devang Patel | af9e847 | 2009-10-01 20:31:14 +0000 | [diff] [blame] | 216 | assert (getFirstInsn() && "First instruction is missing!"); |
| 217 | if (getLastInsn()) |
| 218 | return; |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 219 | |
Devang Patel | af9e847 | 2009-10-01 20:31:14 +0000 | [diff] [blame] | 220 | // If a scope does not have an instruction to mark an end then use |
| 221 | // the end of last child scope. |
| 222 | SmallVector<DbgScope *, 4> &Scopes = getScopes(); |
| 223 | assert (!Scopes.empty() && "Inner most scope does not have last insn!"); |
| 224 | DbgScope *L = Scopes.back(); |
| 225 | if (!L->getLastInsn()) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 226 | L->fixInstructionMarkers(); |
Devang Patel | af9e847 | 2009-10-01 20:31:14 +0000 | [diff] [blame] | 227 | setLastInsn(L->getLastInsn()); |
| 228 | } |
| 229 | |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 230 | #ifndef NDEBUG |
| 231 | void dump() const; |
| 232 | #endif |
| 233 | }; |
| 234 | |
| 235 | #ifndef NDEBUG |
| 236 | void DbgScope::dump() const { |
Chris Lattner | c281de1 | 2009-08-23 00:51:00 +0000 | [diff] [blame] | 237 | raw_ostream &err = errs(); |
| 238 | err.indent(IndentLevel); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 239 | MDNode *N = Desc.getNode(); |
| 240 | N->dump(); |
Chris Lattner | c281de1 | 2009-08-23 00:51:00 +0000 | [diff] [blame] | 241 | err << " [" << StartLabelID << ", " << EndLabelID << "]\n"; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 242 | if (AbstractScope) |
| 243 | err << "Abstract Scope\n"; |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 244 | |
| 245 | IndentLevel += 2; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 246 | if (!Scopes.empty()) |
| 247 | err << "Children ...\n"; |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 248 | for (unsigned i = 0, e = Scopes.size(); i != e; ++i) |
| 249 | if (Scopes[i] != this) |
| 250 | Scopes[i]->dump(); |
| 251 | |
| 252 | IndentLevel -= 2; |
| 253 | } |
| 254 | #endif |
| 255 | |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 256 | DbgScope::~DbgScope() { |
| 257 | for (unsigned i = 0, N = Scopes.size(); i < N; ++i) |
| 258 | delete Scopes[i]; |
| 259 | for (unsigned j = 0, M = Variables.size(); j < M; ++j) |
| 260 | delete Variables[j]; |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | } // end llvm namespace |
| 264 | |
Chris Lattner | af76e59 | 2009-08-22 20:48:53 +0000 | [diff] [blame] | 265 | DwarfDebug::DwarfDebug(raw_ostream &OS, AsmPrinter *A, const MCAsmInfo *T) |
Devang Patel | 1dbc771 | 2009-06-29 20:45:18 +0000 | [diff] [blame] | 266 | : Dwarf(OS, A, T, "dbg"), ModuleCU(0), |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 267 | AbbreviationsSet(InitAbbreviationsSetSize), Abbreviations(), |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 268 | DIEValues(), StringPool(), |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 269 | SectionSourceLines(), didInitial(false), shouldEmit(false), |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 270 | CurrentFnDbgScope(0), DebugTimer(0) { |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 271 | if (TimePassesIsEnabled) |
| 272 | DebugTimer = new Timer("Dwarf Debug Writer", |
| 273 | getDwarfTimerGroup()); |
| 274 | } |
| 275 | DwarfDebug::~DwarfDebug() { |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 276 | for (unsigned j = 0, M = DIEValues.size(); j < M; ++j) |
| 277 | delete DIEValues[j]; |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 278 | |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 279 | delete DebugTimer; |
| 280 | } |
| 281 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 282 | /// assignAbbrevNumber - Define a unique number for the abbreviation. |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 283 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 284 | void DwarfDebug::assignAbbrevNumber(DIEAbbrev &Abbrev) { |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 285 | // Profile the node so that we can make it unique. |
| 286 | FoldingSetNodeID ID; |
| 287 | Abbrev.Profile(ID); |
| 288 | |
| 289 | // Check the set for priors. |
| 290 | DIEAbbrev *InSet = AbbreviationsSet.GetOrInsertNode(&Abbrev); |
| 291 | |
| 292 | // If it's newly added. |
| 293 | if (InSet == &Abbrev) { |
| 294 | // Add to abbreviation list. |
| 295 | Abbreviations.push_back(&Abbrev); |
| 296 | |
| 297 | // Assign the vector position + 1 as its number. |
| 298 | Abbrev.setNumber(Abbreviations.size()); |
| 299 | } else { |
| 300 | // Assign existing abbreviation number. |
| 301 | Abbrev.setNumber(InSet->getNumber()); |
| 302 | } |
| 303 | } |
| 304 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 305 | /// createDIEEntry - Creates a new DIEEntry to be a proxy for a debug |
Bill Wendling | 995f80a | 2009-05-20 23:24:48 +0000 | [diff] [blame] | 306 | /// information entry. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 307 | DIEEntry *DwarfDebug::createDIEEntry(DIE *Entry) { |
Devang Patel | 6f01d9c | 2009-11-21 00:31:03 +0000 | [diff] [blame] | 308 | DIEEntry *Value = new DIEEntry(Entry); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 309 | DIEValues.push_back(Value); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 310 | return Value; |
| 311 | } |
| 312 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 313 | /// addUInt - Add an unsigned integer attribute data and value. |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 314 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 315 | void DwarfDebug::addUInt(DIE *Die, unsigned Attribute, |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 316 | unsigned Form, uint64_t Integer) { |
| 317 | if (!Form) Form = DIEInteger::BestForm(false, Integer); |
Devang Patel | 6f01d9c | 2009-11-21 00:31:03 +0000 | [diff] [blame] | 318 | DIEValue *Value = new DIEInteger(Integer); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 319 | DIEValues.push_back(Value); |
| 320 | Die->addValue(Attribute, Form, Value); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 321 | } |
| 322 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 323 | /// addSInt - Add an signed integer attribute data and value. |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 324 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 325 | void DwarfDebug::addSInt(DIE *Die, unsigned Attribute, |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 326 | unsigned Form, int64_t Integer) { |
| 327 | if (!Form) Form = DIEInteger::BestForm(true, Integer); |
Devang Patel | 6f01d9c | 2009-11-21 00:31:03 +0000 | [diff] [blame] | 328 | DIEValue *Value = new DIEInteger(Integer); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 329 | DIEValues.push_back(Value); |
| 330 | Die->addValue(Attribute, Form, Value); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 331 | } |
| 332 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 333 | /// addString - Add a string attribute data and value. |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 334 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 335 | void DwarfDebug::addString(DIE *Die, unsigned Attribute, unsigned Form, |
Devang Patel | e9a0597 | 2009-11-24 19:42:17 +0000 | [diff] [blame] | 336 | const StringRef String) { |
Devang Patel | 6f01d9c | 2009-11-21 00:31:03 +0000 | [diff] [blame] | 337 | DIEValue *Value = new DIEString(String); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 338 | DIEValues.push_back(Value); |
| 339 | Die->addValue(Attribute, Form, Value); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 340 | } |
| 341 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 342 | /// addLabel - Add a Dwarf label attribute data and value. |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 343 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 344 | void DwarfDebug::addLabel(DIE *Die, unsigned Attribute, unsigned Form, |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 345 | const DWLabel &Label) { |
Devang Patel | 6f01d9c | 2009-11-21 00:31:03 +0000 | [diff] [blame] | 346 | DIEValue *Value = new DIEDwarfLabel(Label); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 347 | DIEValues.push_back(Value); |
| 348 | Die->addValue(Attribute, Form, Value); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 349 | } |
| 350 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 351 | /// addObjectLabel - Add an non-Dwarf label attribute data and value. |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 352 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 353 | void DwarfDebug::addObjectLabel(DIE *Die, unsigned Attribute, unsigned Form, |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 354 | const std::string &Label) { |
Devang Patel | 6f01d9c | 2009-11-21 00:31:03 +0000 | [diff] [blame] | 355 | DIEValue *Value = new DIEObjectLabel(Label); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 356 | DIEValues.push_back(Value); |
| 357 | Die->addValue(Attribute, Form, Value); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 358 | } |
| 359 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 360 | /// addSectionOffset - Add a section offset label attribute data and value. |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 361 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 362 | void DwarfDebug::addSectionOffset(DIE *Die, unsigned Attribute, unsigned Form, |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 363 | const DWLabel &Label, const DWLabel &Section, |
| 364 | bool isEH, bool useSet) { |
Devang Patel | 6f01d9c | 2009-11-21 00:31:03 +0000 | [diff] [blame] | 365 | DIEValue *Value = new DIESectionOffset(Label, Section, isEH, useSet); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 366 | DIEValues.push_back(Value); |
| 367 | Die->addValue(Attribute, Form, Value); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 368 | } |
| 369 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 370 | /// addDelta - Add a label delta attribute data and value. |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 371 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 372 | void DwarfDebug::addDelta(DIE *Die, unsigned Attribute, unsigned Form, |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 373 | const DWLabel &Hi, const DWLabel &Lo) { |
Devang Patel | 6f01d9c | 2009-11-21 00:31:03 +0000 | [diff] [blame] | 374 | DIEValue *Value = new DIEDelta(Hi, Lo); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 375 | DIEValues.push_back(Value); |
| 376 | Die->addValue(Attribute, Form, Value); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 377 | } |
| 378 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 379 | /// addBlock - Add block data. |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 380 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 381 | void DwarfDebug::addBlock(DIE *Die, unsigned Attribute, unsigned Form, |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 382 | DIEBlock *Block) { |
| 383 | Block->ComputeSize(TD); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 384 | DIEValues.push_back(Block); |
| 385 | Die->addValue(Attribute, Block->BestForm(), Block); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 386 | } |
| 387 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 388 | /// addSourceLine - Add location information to specified debug information |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 389 | /// entry. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 390 | void DwarfDebug::addSourceLine(DIE *Die, const DIVariable *V) { |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 391 | // If there is no compile unit specified, don't add a line #. |
| 392 | if (V->getCompileUnit().isNull()) |
| 393 | return; |
| 394 | |
| 395 | unsigned Line = V->getLineNumber(); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 396 | unsigned FileID = findCompileUnit(V->getCompileUnit()).getID(); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 397 | assert(FileID && "Invalid file id"); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 398 | addUInt(Die, dwarf::DW_AT_decl_file, 0, FileID); |
| 399 | addUInt(Die, dwarf::DW_AT_decl_line, 0, Line); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 400 | } |
| 401 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 402 | /// addSourceLine - Add location information to specified debug information |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 403 | /// entry. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 404 | void DwarfDebug::addSourceLine(DIE *Die, const DIGlobal *G) { |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 405 | // If there is no compile unit specified, don't add a line #. |
| 406 | if (G->getCompileUnit().isNull()) |
| 407 | return; |
| 408 | |
| 409 | unsigned Line = G->getLineNumber(); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 410 | unsigned FileID = findCompileUnit(G->getCompileUnit()).getID(); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 411 | assert(FileID && "Invalid file id"); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 412 | addUInt(Die, dwarf::DW_AT_decl_file, 0, FileID); |
| 413 | addUInt(Die, dwarf::DW_AT_decl_line, 0, Line); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 414 | } |
Devang Patel | 82dfc0c | 2009-08-31 22:47:13 +0000 | [diff] [blame] | 415 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 416 | /// addSourceLine - Add location information to specified debug information |
Devang Patel | 82dfc0c | 2009-08-31 22:47:13 +0000 | [diff] [blame] | 417 | /// entry. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 418 | void DwarfDebug::addSourceLine(DIE *Die, const DISubprogram *SP) { |
Devang Patel | 82dfc0c | 2009-08-31 22:47:13 +0000 | [diff] [blame] | 419 | // If there is no compile unit specified, don't add a line #. |
| 420 | if (SP->getCompileUnit().isNull()) |
| 421 | return; |
Caroline Tice | c6f9d62 | 2009-09-11 18:25:54 +0000 | [diff] [blame] | 422 | // If the line number is 0, don't add it. |
| 423 | if (SP->getLineNumber() == 0) |
| 424 | return; |
| 425 | |
Devang Patel | 82dfc0c | 2009-08-31 22:47:13 +0000 | [diff] [blame] | 426 | |
| 427 | unsigned Line = SP->getLineNumber(); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 428 | unsigned FileID = findCompileUnit(SP->getCompileUnit()).getID(); |
Devang Patel | 82dfc0c | 2009-08-31 22:47:13 +0000 | [diff] [blame] | 429 | assert(FileID && "Invalid file id"); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 430 | addUInt(Die, dwarf::DW_AT_decl_file, 0, FileID); |
| 431 | addUInt(Die, dwarf::DW_AT_decl_line, 0, Line); |
Devang Patel | 82dfc0c | 2009-08-31 22:47:13 +0000 | [diff] [blame] | 432 | } |
| 433 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 434 | /// addSourceLine - Add location information to specified debug information |
Devang Patel | 82dfc0c | 2009-08-31 22:47:13 +0000 | [diff] [blame] | 435 | /// entry. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 436 | void DwarfDebug::addSourceLine(DIE *Die, const DIType *Ty) { |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 437 | // If there is no compile unit specified, don't add a line #. |
| 438 | DICompileUnit CU = Ty->getCompileUnit(); |
| 439 | if (CU.isNull()) |
| 440 | return; |
| 441 | |
| 442 | unsigned Line = Ty->getLineNumber(); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 443 | unsigned FileID = findCompileUnit(CU).getID(); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 444 | assert(FileID && "Invalid file id"); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 445 | addUInt(Die, dwarf::DW_AT_decl_file, 0, FileID); |
| 446 | addUInt(Die, dwarf::DW_AT_decl_line, 0, Line); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 447 | } |
| 448 | |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 449 | /* Byref variables, in Blocks, are declared by the programmer as |
| 450 | "SomeType VarName;", but the compiler creates a |
| 451 | __Block_byref_x_VarName struct, and gives the variable VarName |
| 452 | either the struct, or a pointer to the struct, as its type. This |
| 453 | is necessary for various behind-the-scenes things the compiler |
| 454 | needs to do with by-reference variables in blocks. |
| 455 | |
| 456 | However, as far as the original *programmer* is concerned, the |
| 457 | variable should still have type 'SomeType', as originally declared. |
| 458 | |
| 459 | The following function dives into the __Block_byref_x_VarName |
| 460 | struct to find the original type of the variable. This will be |
| 461 | passed back to the code generating the type for the Debug |
| 462 | Information Entry for the variable 'VarName'. 'VarName' will then |
| 463 | have the original type 'SomeType' in its debug information. |
| 464 | |
| 465 | The original type 'SomeType' will be the type of the field named |
| 466 | 'VarName' inside the __Block_byref_x_VarName struct. |
| 467 | |
| 468 | NOTE: In order for this to not completely fail on the debugger |
| 469 | side, the Debug Information Entry for the variable VarName needs to |
| 470 | have a DW_AT_location that tells the debugger how to unwind through |
| 471 | the pointers and __Block_byref_x_VarName struct to find the actual |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 472 | value of the variable. The function addBlockByrefType does this. */ |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 473 | |
| 474 | /// Find the type the programmer originally declared the variable to be |
| 475 | /// and return that type. |
| 476 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 477 | DIType DwarfDebug::getBlockByrefType(DIType Ty, std::string Name) { |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 478 | |
| 479 | DIType subType = Ty; |
| 480 | unsigned tag = Ty.getTag(); |
| 481 | |
| 482 | if (tag == dwarf::DW_TAG_pointer_type) { |
Mike Stump | 3e4c9bd | 2009-09-30 00:08:22 +0000 | [diff] [blame] | 483 | DIDerivedType DTy = DIDerivedType(Ty.getNode()); |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 484 | subType = DTy.getTypeDerivedFrom(); |
| 485 | } |
| 486 | |
| 487 | DICompositeType blockStruct = DICompositeType(subType.getNode()); |
| 488 | |
| 489 | DIArray Elements = blockStruct.getTypeArray(); |
| 490 | |
| 491 | if (Elements.isNull()) |
| 492 | return Ty; |
| 493 | |
| 494 | for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) { |
| 495 | DIDescriptor Element = Elements.getElement(i); |
| 496 | DIDerivedType DT = DIDerivedType(Element.getNode()); |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 497 | if (Name == DT.getName()) |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 498 | return (DT.getTypeDerivedFrom()); |
| 499 | } |
| 500 | |
| 501 | return Ty; |
| 502 | } |
| 503 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 504 | /// addComplexAddress - Start with the address based on the location provided, |
Mike Stump | 3e4c9bd | 2009-09-30 00:08:22 +0000 | [diff] [blame] | 505 | /// and generate the DWARF information necessary to find the actual variable |
| 506 | /// given the extra address information encoded in the DIVariable, starting from |
| 507 | /// the starting location. Add the DWARF information to the die. |
| 508 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 509 | void DwarfDebug::addComplexAddress(DbgVariable *&DV, DIE *Die, |
Mike Stump | 3e4c9bd | 2009-09-30 00:08:22 +0000 | [diff] [blame] | 510 | unsigned Attribute, |
| 511 | const MachineLocation &Location) { |
| 512 | const DIVariable &VD = DV->getVariable(); |
| 513 | DIType Ty = VD.getType(); |
| 514 | |
| 515 | // Decode the original location, and use that as the start of the byref |
| 516 | // variable's location. |
| 517 | unsigned Reg = RI->getDwarfRegNum(Location.getReg(), false); |
| 518 | DIEBlock *Block = new DIEBlock(); |
| 519 | |
| 520 | if (Location.isReg()) { |
| 521 | if (Reg < 32) { |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 522 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_reg0 + Reg); |
Mike Stump | 3e4c9bd | 2009-09-30 00:08:22 +0000 | [diff] [blame] | 523 | } else { |
| 524 | Reg = Reg - dwarf::DW_OP_reg0; |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 525 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_breg0 + Reg); |
| 526 | addUInt(Block, 0, dwarf::DW_FORM_udata, Reg); |
Mike Stump | 3e4c9bd | 2009-09-30 00:08:22 +0000 | [diff] [blame] | 527 | } |
| 528 | } else { |
| 529 | if (Reg < 32) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 530 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_breg0 + Reg); |
Mike Stump | 3e4c9bd | 2009-09-30 00:08:22 +0000 | [diff] [blame] | 531 | else { |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 532 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_bregx); |
| 533 | addUInt(Block, 0, dwarf::DW_FORM_udata, Reg); |
Mike Stump | 3e4c9bd | 2009-09-30 00:08:22 +0000 | [diff] [blame] | 534 | } |
| 535 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 536 | addUInt(Block, 0, dwarf::DW_FORM_sdata, Location.getOffset()); |
Mike Stump | 3e4c9bd | 2009-09-30 00:08:22 +0000 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | for (unsigned i = 0, N = VD.getNumAddrElements(); i < N; ++i) { |
| 540 | uint64_t Element = VD.getAddrElement(i); |
| 541 | |
| 542 | if (Element == DIFactory::OpPlus) { |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 543 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst); |
| 544 | addUInt(Block, 0, dwarf::DW_FORM_udata, VD.getAddrElement(++i)); |
Mike Stump | 3e4c9bd | 2009-09-30 00:08:22 +0000 | [diff] [blame] | 545 | } else if (Element == DIFactory::OpDeref) { |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 546 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_deref); |
Mike Stump | 3e4c9bd | 2009-09-30 00:08:22 +0000 | [diff] [blame] | 547 | } else llvm_unreachable("unknown DIFactory Opcode"); |
| 548 | } |
| 549 | |
| 550 | // Now attach the location information to the DIE. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 551 | addBlock(Die, Attribute, 0, Block); |
Mike Stump | 3e4c9bd | 2009-09-30 00:08:22 +0000 | [diff] [blame] | 552 | } |
| 553 | |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 554 | /* Byref variables, in Blocks, are declared by the programmer as "SomeType |
| 555 | VarName;", but the compiler creates a __Block_byref_x_VarName struct, and |
| 556 | gives the variable VarName either the struct, or a pointer to the struct, as |
| 557 | its type. This is necessary for various behind-the-scenes things the |
| 558 | compiler needs to do with by-reference variables in Blocks. |
| 559 | |
| 560 | However, as far as the original *programmer* is concerned, the variable |
| 561 | should still have type 'SomeType', as originally declared. |
| 562 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 563 | The function getBlockByrefType dives into the __Block_byref_x_VarName |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 564 | struct to find the original type of the variable, which is then assigned to |
| 565 | the variable's Debug Information Entry as its real type. So far, so good. |
| 566 | However now the debugger will expect the variable VarName to have the type |
| 567 | SomeType. So we need the location attribute for the variable to be an |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 568 | expression that explains to the debugger how to navigate through the |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 569 | pointers and struct to find the actual variable of type SomeType. |
| 570 | |
| 571 | The following function does just that. We start by getting |
| 572 | the "normal" location for the variable. This will be the location |
| 573 | of either the struct __Block_byref_x_VarName or the pointer to the |
| 574 | struct __Block_byref_x_VarName. |
| 575 | |
| 576 | The struct will look something like: |
| 577 | |
| 578 | struct __Block_byref_x_VarName { |
| 579 | ... <various fields> |
| 580 | struct __Block_byref_x_VarName *forwarding; |
| 581 | ... <various other fields> |
| 582 | SomeType VarName; |
| 583 | ... <maybe more fields> |
| 584 | }; |
| 585 | |
| 586 | If we are given the struct directly (as our starting point) we |
| 587 | need to tell the debugger to: |
| 588 | |
| 589 | 1). Add the offset of the forwarding field. |
| 590 | |
| 591 | 2). Follow that pointer to get the the real __Block_byref_x_VarName |
| 592 | struct to use (the real one may have been copied onto the heap). |
| 593 | |
| 594 | 3). Add the offset for the field VarName, to find the actual variable. |
| 595 | |
| 596 | If we started with a pointer to the struct, then we need to |
| 597 | dereference that pointer first, before the other steps. |
| 598 | Translating this into DWARF ops, we will need to append the following |
| 599 | to the current location description for the variable: |
| 600 | |
| 601 | DW_OP_deref -- optional, if we start with a pointer |
| 602 | DW_OP_plus_uconst <forward_fld_offset> |
| 603 | DW_OP_deref |
| 604 | DW_OP_plus_uconst <varName_fld_offset> |
| 605 | |
| 606 | That is what this function does. */ |
| 607 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 608 | /// addBlockByrefAddress - Start with the address based on the location |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 609 | /// provided, and generate the DWARF information necessary to find the |
| 610 | /// actual Block variable (navigating the Block struct) based on the |
| 611 | /// starting location. Add the DWARF information to the die. For |
| 612 | /// more information, read large comment just above here. |
| 613 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 614 | void DwarfDebug::addBlockByrefAddress(DbgVariable *&DV, DIE *Die, |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 615 | unsigned Attribute, |
| 616 | const MachineLocation &Location) { |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 617 | const DIVariable &VD = DV->getVariable(); |
| 618 | DIType Ty = VD.getType(); |
| 619 | DIType TmpTy = Ty; |
| 620 | unsigned Tag = Ty.getTag(); |
| 621 | bool isPointer = false; |
| 622 | |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 623 | StringRef varName = VD.getName(); |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 624 | |
| 625 | if (Tag == dwarf::DW_TAG_pointer_type) { |
Mike Stump | 3e4c9bd | 2009-09-30 00:08:22 +0000 | [diff] [blame] | 626 | DIDerivedType DTy = DIDerivedType(Ty.getNode()); |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 627 | TmpTy = DTy.getTypeDerivedFrom(); |
| 628 | isPointer = true; |
| 629 | } |
| 630 | |
| 631 | DICompositeType blockStruct = DICompositeType(TmpTy.getNode()); |
| 632 | |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 633 | // Find the __forwarding field and the variable field in the __Block_byref |
| 634 | // struct. |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 635 | DIArray Fields = blockStruct.getTypeArray(); |
| 636 | DIDescriptor varField = DIDescriptor(); |
| 637 | DIDescriptor forwardingField = DIDescriptor(); |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 638 | |
| 639 | |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 640 | for (unsigned i = 0, N = Fields.getNumElements(); i < N; ++i) { |
| 641 | DIDescriptor Element = Fields.getElement(i); |
| 642 | DIDerivedType DT = DIDerivedType(Element.getNode()); |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 643 | StringRef fieldName = DT.getName(); |
| 644 | if (fieldName == "__forwarding") |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 645 | forwardingField = Element; |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 646 | else if (fieldName == varName) |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 647 | varField = Element; |
| 648 | } |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 649 | |
Mike Stump | 7e3720d | 2009-09-24 23:21:26 +0000 | [diff] [blame] | 650 | assert(!varField.isNull() && "Can't find byref variable in Block struct"); |
| 651 | assert(!forwardingField.isNull() |
| 652 | && "Can't find forwarding field in Block struct"); |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 653 | |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 654 | // Get the offsets for the forwarding field and the variable field. |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 655 | unsigned int forwardingFieldOffset = |
| 656 | DIDerivedType(forwardingField.getNode()).getOffsetInBits() >> 3; |
| 657 | unsigned int varFieldOffset = |
| 658 | DIDerivedType(varField.getNode()).getOffsetInBits() >> 3; |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 659 | |
Mike Stump | 7e3720d | 2009-09-24 23:21:26 +0000 | [diff] [blame] | 660 | // Decode the original location, and use that as the start of the byref |
| 661 | // variable's location. |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 662 | unsigned Reg = RI->getDwarfRegNum(Location.getReg(), false); |
| 663 | DIEBlock *Block = new DIEBlock(); |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 664 | |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 665 | if (Location.isReg()) { |
| 666 | if (Reg < 32) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 667 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_reg0 + Reg); |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 668 | else { |
| 669 | Reg = Reg - dwarf::DW_OP_reg0; |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 670 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_breg0 + Reg); |
| 671 | addUInt(Block, 0, dwarf::DW_FORM_udata, Reg); |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 672 | } |
| 673 | } else { |
| 674 | if (Reg < 32) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 675 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_breg0 + Reg); |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 676 | else { |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 677 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_bregx); |
| 678 | addUInt(Block, 0, dwarf::DW_FORM_udata, Reg); |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 679 | } |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 680 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 681 | addUInt(Block, 0, dwarf::DW_FORM_sdata, Location.getOffset()); |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 682 | } |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 683 | |
Mike Stump | 7e3720d | 2009-09-24 23:21:26 +0000 | [diff] [blame] | 684 | // If we started with a pointer to the __Block_byref... struct, then |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 685 | // the first thing we need to do is dereference the pointer (DW_OP_deref). |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 686 | if (isPointer) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 687 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_deref); |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 688 | |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 689 | // Next add the offset for the '__forwarding' field: |
| 690 | // DW_OP_plus_uconst ForwardingFieldOffset. Note there's no point in |
| 691 | // adding the offset if it's 0. |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 692 | if (forwardingFieldOffset > 0) { |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 693 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst); |
| 694 | addUInt(Block, 0, dwarf::DW_FORM_udata, forwardingFieldOffset); |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 695 | } |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 696 | |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 697 | // Now dereference the __forwarding field to get to the real __Block_byref |
| 698 | // struct: DW_OP_deref. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 699 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_deref); |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 700 | |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 701 | // Now that we've got the real __Block_byref... struct, add the offset |
| 702 | // for the variable's field to get to the location of the actual variable: |
| 703 | // DW_OP_plus_uconst varFieldOffset. Again, don't add if it's 0. |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 704 | if (varFieldOffset > 0) { |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 705 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst); |
| 706 | addUInt(Block, 0, dwarf::DW_FORM_udata, varFieldOffset); |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 707 | } |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 708 | |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 709 | // Now attach the location information to the DIE. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 710 | addBlock(Die, Attribute, 0, Block); |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 711 | } |
| 712 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 713 | /// addAddress - Add an address attribute to a die based on the location |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 714 | /// provided. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 715 | void DwarfDebug::addAddress(DIE *Die, unsigned Attribute, |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 716 | const MachineLocation &Location) { |
| 717 | unsigned Reg = RI->getDwarfRegNum(Location.getReg(), false); |
| 718 | DIEBlock *Block = new DIEBlock(); |
| 719 | |
| 720 | if (Location.isReg()) { |
| 721 | if (Reg < 32) { |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 722 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_reg0 + Reg); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 723 | } else { |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 724 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_regx); |
| 725 | addUInt(Block, 0, dwarf::DW_FORM_udata, Reg); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 726 | } |
| 727 | } else { |
| 728 | if (Reg < 32) { |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 729 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_breg0 + Reg); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 730 | } else { |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 731 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_bregx); |
| 732 | addUInt(Block, 0, dwarf::DW_FORM_udata, Reg); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 733 | } |
| 734 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 735 | addUInt(Block, 0, dwarf::DW_FORM_sdata, Location.getOffset()); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 736 | } |
| 737 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 738 | addBlock(Die, Attribute, 0, Block); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 739 | } |
| 740 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 741 | /// addType - Add a new type attribute to the specified entity. |
| 742 | void DwarfDebug::addType(CompileUnit *DW_Unit, DIE *Entity, DIType Ty) { |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 743 | if (Ty.isNull()) |
| 744 | return; |
| 745 | |
| 746 | // Check for pre-existence. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 747 | DIEEntry *Entry = DW_Unit->getDIEEntry(Ty.getNode()); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 748 | |
| 749 | // If it exists then use the existing value. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 750 | if (Entry) { |
| 751 | Entity->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, Entry); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 752 | return; |
| 753 | } |
| 754 | |
| 755 | // Set up proxy. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 756 | Entry = createDIEEntry(); |
| 757 | DW_Unit->insertDIEEntry(Ty.getNode(), Entry); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 758 | |
| 759 | // Construct type. |
Devang Patel | 6f01d9c | 2009-11-21 00:31:03 +0000 | [diff] [blame] | 760 | DIE *Buffer = new DIE(dwarf::DW_TAG_base_type); |
Devang Patel | 6ceea33 | 2009-08-31 18:49:10 +0000 | [diff] [blame] | 761 | if (Ty.isBasicType()) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 762 | constructTypeDIE(DW_Unit, *Buffer, DIBasicType(Ty.getNode())); |
Devang Patel | 6ceea33 | 2009-08-31 18:49:10 +0000 | [diff] [blame] | 763 | else if (Ty.isCompositeType()) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 764 | constructTypeDIE(DW_Unit, *Buffer, DICompositeType(Ty.getNode())); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 765 | else { |
Devang Patel | 6ceea33 | 2009-08-31 18:49:10 +0000 | [diff] [blame] | 766 | assert(Ty.isDerivedType() && "Unknown kind of DIType"); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 767 | constructTypeDIE(DW_Unit, *Buffer, DIDerivedType(Ty.getNode())); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | // Add debug information entry to entity and appropriate context. |
| 771 | DIE *Die = NULL; |
| 772 | DIDescriptor Context = Ty.getContext(); |
| 773 | if (!Context.isNull()) |
Devang Patel | 017d121 | 2009-11-20 21:37:22 +0000 | [diff] [blame] | 774 | Die = DW_Unit->getDIE(Context.getNode()); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 775 | |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 776 | if (Die) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 777 | Die->addChild(Buffer); |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 778 | else |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 779 | DW_Unit->addDie(Buffer); |
| 780 | Entry->setEntry(Buffer); |
| 781 | Entity->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, Entry); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 782 | } |
| 783 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 784 | /// constructTypeDIE - Construct basic type die from DIBasicType. |
| 785 | void DwarfDebug::constructTypeDIE(CompileUnit *DW_Unit, DIE &Buffer, |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 786 | DIBasicType BTy) { |
| 787 | // Get core information. |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 788 | StringRef Name = BTy.getName(); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 789 | Buffer.setTag(dwarf::DW_TAG_base_type); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 790 | addUInt(&Buffer, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 791 | BTy.getEncoding()); |
| 792 | |
| 793 | // Add name if not anonymous or intermediate type. |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 794 | if (!Name.empty()) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 795 | addString(&Buffer, dwarf::DW_AT_name, dwarf::DW_FORM_string, Name); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 796 | uint64_t Size = BTy.getSizeInBits() >> 3; |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 797 | addUInt(&Buffer, dwarf::DW_AT_byte_size, 0, Size); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 798 | } |
| 799 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 800 | /// constructTypeDIE - Construct derived type die from DIDerivedType. |
| 801 | void DwarfDebug::constructTypeDIE(CompileUnit *DW_Unit, DIE &Buffer, |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 802 | DIDerivedType DTy) { |
| 803 | // Get core information. |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 804 | StringRef Name = DTy.getName(); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 805 | uint64_t Size = DTy.getSizeInBits() >> 3; |
| 806 | unsigned Tag = DTy.getTag(); |
| 807 | |
| 808 | // FIXME - Workaround for templates. |
| 809 | if (Tag == dwarf::DW_TAG_inheritance) Tag = dwarf::DW_TAG_reference_type; |
| 810 | |
| 811 | Buffer.setTag(Tag); |
| 812 | |
| 813 | // Map to main type, void will not have a type. |
| 814 | DIType FromTy = DTy.getTypeDerivedFrom(); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 815 | addType(DW_Unit, &Buffer, FromTy); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 816 | |
| 817 | // Add name if not anonymous or intermediate type. |
Devang Patel | deea564 | 2009-11-30 23:56:56 +0000 | [diff] [blame] | 818 | if (!Name.empty()) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 819 | addString(&Buffer, dwarf::DW_AT_name, dwarf::DW_FORM_string, Name); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 820 | |
| 821 | // Add size if non-zero (derived types might be zero-sized.) |
| 822 | if (Size) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 823 | addUInt(&Buffer, dwarf::DW_AT_byte_size, 0, Size); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 824 | |
| 825 | // Add source line info if available and TyDesc is not a forward declaration. |
Devang Patel | 05f6fa8 | 2009-11-23 18:43:37 +0000 | [diff] [blame] | 826 | if (!DTy.isForwardDecl()) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 827 | addSourceLine(&Buffer, &DTy); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 828 | } |
| 829 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 830 | /// constructTypeDIE - Construct type DIE from DICompositeType. |
| 831 | void DwarfDebug::constructTypeDIE(CompileUnit *DW_Unit, DIE &Buffer, |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 832 | DICompositeType CTy) { |
| 833 | // Get core information. |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 834 | StringRef Name = CTy.getName(); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 835 | |
| 836 | uint64_t Size = CTy.getSizeInBits() >> 3; |
| 837 | unsigned Tag = CTy.getTag(); |
| 838 | Buffer.setTag(Tag); |
| 839 | |
| 840 | switch (Tag) { |
| 841 | case dwarf::DW_TAG_vector_type: |
| 842 | case dwarf::DW_TAG_array_type: |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 843 | constructArrayTypeDIE(DW_Unit, Buffer, &CTy); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 844 | break; |
| 845 | case dwarf::DW_TAG_enumeration_type: { |
| 846 | DIArray Elements = CTy.getTypeArray(); |
| 847 | |
| 848 | // Add enumerators to enumeration type. |
| 849 | for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) { |
| 850 | DIE *ElemDie = NULL; |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 851 | DIEnumerator Enum(Elements.getElement(i).getNode()); |
Devang Patel | c525472 | 2009-10-09 17:51:49 +0000 | [diff] [blame] | 852 | if (!Enum.isNull()) { |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 853 | ElemDie = constructEnumTypeDIE(DW_Unit, &Enum); |
| 854 | Buffer.addChild(ElemDie); |
Devang Patel | c525472 | 2009-10-09 17:51:49 +0000 | [diff] [blame] | 855 | } |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 856 | } |
| 857 | } |
| 858 | break; |
| 859 | case dwarf::DW_TAG_subroutine_type: { |
| 860 | // Add return type. |
| 861 | DIArray Elements = CTy.getTypeArray(); |
| 862 | DIDescriptor RTy = Elements.getElement(0); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 863 | addType(DW_Unit, &Buffer, DIType(RTy.getNode())); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 864 | |
| 865 | // Add prototype flag. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 866 | addUInt(&Buffer, dwarf::DW_AT_prototyped, dwarf::DW_FORM_flag, 1); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 867 | |
| 868 | // Add arguments. |
| 869 | for (unsigned i = 1, N = Elements.getNumElements(); i < N; ++i) { |
| 870 | DIE *Arg = new DIE(dwarf::DW_TAG_formal_parameter); |
| 871 | DIDescriptor Ty = Elements.getElement(i); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 872 | addType(DW_Unit, Arg, DIType(Ty.getNode())); |
| 873 | Buffer.addChild(Arg); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 874 | } |
| 875 | } |
| 876 | break; |
| 877 | case dwarf::DW_TAG_structure_type: |
| 878 | case dwarf::DW_TAG_union_type: |
| 879 | case dwarf::DW_TAG_class_type: { |
| 880 | // Add elements to structure type. |
| 881 | DIArray Elements = CTy.getTypeArray(); |
| 882 | |
| 883 | // A forward struct declared type may not have elements available. |
| 884 | if (Elements.isNull()) |
| 885 | break; |
| 886 | |
| 887 | // Add elements to structure type. |
| 888 | for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) { |
| 889 | DIDescriptor Element = Elements.getElement(i); |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 890 | if (Element.isNull()) |
| 891 | continue; |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 892 | DIE *ElemDie = NULL; |
| 893 | if (Element.getTag() == dwarf::DW_TAG_subprogram) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 894 | ElemDie = createSubprogramDIE(DW_Unit, |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 895 | DISubprogram(Element.getNode())); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 896 | else |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 897 | ElemDie = createMemberDIE(DW_Unit, |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 898 | DIDerivedType(Element.getNode())); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 899 | Buffer.addChild(ElemDie); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 900 | } |
| 901 | |
Devang Patel | a1ba269 | 2009-08-27 23:51:51 +0000 | [diff] [blame] | 902 | if (CTy.isAppleBlockExtension()) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 903 | addUInt(&Buffer, dwarf::DW_AT_APPLE_block, dwarf::DW_FORM_flag, 1); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 904 | |
| 905 | unsigned RLang = CTy.getRunTimeLang(); |
| 906 | if (RLang) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 907 | addUInt(&Buffer, dwarf::DW_AT_APPLE_runtime_class, |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 908 | dwarf::DW_FORM_data1, RLang); |
| 909 | break; |
| 910 | } |
| 911 | default: |
| 912 | break; |
| 913 | } |
| 914 | |
| 915 | // Add name if not anonymous or intermediate type. |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 916 | if (!Name.empty()) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 917 | addString(&Buffer, dwarf::DW_AT_name, dwarf::DW_FORM_string, Name); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 918 | |
| 919 | if (Tag == dwarf::DW_TAG_enumeration_type || |
| 920 | Tag == dwarf::DW_TAG_structure_type || Tag == dwarf::DW_TAG_union_type) { |
| 921 | // Add size if non-zero (derived types might be zero-sized.) |
| 922 | if (Size) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 923 | addUInt(&Buffer, dwarf::DW_AT_byte_size, 0, Size); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 924 | else { |
| 925 | // Add zero size if it is not a forward declaration. |
| 926 | if (CTy.isForwardDecl()) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 927 | addUInt(&Buffer, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag, 1); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 928 | else |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 929 | addUInt(&Buffer, dwarf::DW_AT_byte_size, 0, 0); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 930 | } |
| 931 | |
| 932 | // Add source line info if available. |
| 933 | if (!CTy.isForwardDecl()) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 934 | addSourceLine(&Buffer, &CTy); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 935 | } |
| 936 | } |
| 937 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 938 | /// constructSubrangeDIE - Construct subrange DIE from DISubrange. |
| 939 | void DwarfDebug::constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy){ |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 940 | int64_t L = SR.getLo(); |
| 941 | int64_t H = SR.getHi(); |
| 942 | DIE *DW_Subrange = new DIE(dwarf::DW_TAG_subrange_type); |
| 943 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 944 | addDIEEntry(DW_Subrange, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, IndexTy); |
Devang Patel | 6325a53 | 2009-08-14 20:59:16 +0000 | [diff] [blame] | 945 | if (L) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 946 | addSInt(DW_Subrange, dwarf::DW_AT_lower_bound, 0, L); |
Devang Patel | 6325a53 | 2009-08-14 20:59:16 +0000 | [diff] [blame] | 947 | if (H) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 948 | addSInt(DW_Subrange, dwarf::DW_AT_upper_bound, 0, H); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 949 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 950 | Buffer.addChild(DW_Subrange); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 951 | } |
| 952 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 953 | /// constructArrayTypeDIE - Construct array type DIE from DICompositeType. |
| 954 | void DwarfDebug::constructArrayTypeDIE(CompileUnit *DW_Unit, DIE &Buffer, |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 955 | DICompositeType *CTy) { |
| 956 | Buffer.setTag(dwarf::DW_TAG_array_type); |
| 957 | if (CTy->getTag() == dwarf::DW_TAG_vector_type) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 958 | addUInt(&Buffer, dwarf::DW_AT_GNU_vector, dwarf::DW_FORM_flag, 1); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 959 | |
| 960 | // Emit derived type. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 961 | addType(DW_Unit, &Buffer, CTy->getTypeDerivedFrom()); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 962 | DIArray Elements = CTy->getTypeArray(); |
| 963 | |
Devang Patel | 6f01d9c | 2009-11-21 00:31:03 +0000 | [diff] [blame] | 964 | // Get an anonymous type for index type. |
| 965 | DIE *IdxTy = DW_Unit->getIndexTyDie(); |
| 966 | if (!IdxTy) { |
| 967 | // Construct an anonymous type for index type. |
| 968 | IdxTy = new DIE(dwarf::DW_TAG_base_type); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 969 | addUInt(IdxTy, dwarf::DW_AT_byte_size, 0, sizeof(int32_t)); |
| 970 | addUInt(IdxTy, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, |
Devang Patel | 6f01d9c | 2009-11-21 00:31:03 +0000 | [diff] [blame] | 971 | dwarf::DW_ATE_signed); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 972 | DW_Unit->addDie(IdxTy); |
Devang Patel | 6f01d9c | 2009-11-21 00:31:03 +0000 | [diff] [blame] | 973 | DW_Unit->setIndexTyDie(IdxTy); |
| 974 | } |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 975 | |
| 976 | // Add subranges to array type. |
| 977 | for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) { |
| 978 | DIDescriptor Element = Elements.getElement(i); |
| 979 | if (Element.getTag() == dwarf::DW_TAG_subrange_type) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 980 | constructSubrangeDIE(Buffer, DISubrange(Element.getNode()), IdxTy); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 981 | } |
| 982 | } |
| 983 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 984 | /// constructEnumTypeDIE - Construct enum type DIE from DIEnumerator. |
| 985 | DIE *DwarfDebug::constructEnumTypeDIE(CompileUnit *DW_Unit, DIEnumerator *ETy) { |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 986 | DIE *Enumerator = new DIE(dwarf::DW_TAG_enumerator); |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 987 | StringRef Name = ETy->getName(); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 988 | addString(Enumerator, dwarf::DW_AT_name, dwarf::DW_FORM_string, Name); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 989 | int64_t Value = ETy->getEnumValue(); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 990 | addSInt(Enumerator, dwarf::DW_AT_const_value, dwarf::DW_FORM_sdata, Value); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 991 | return Enumerator; |
| 992 | } |
| 993 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 994 | /// createGlobalVariableDIE - Create new DIE using GV. |
| 995 | DIE *DwarfDebug::createGlobalVariableDIE(CompileUnit *DW_Unit, |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 996 | const DIGlobalVariable &GV) { |
Jim Grosbach | 7ab38df | 2009-11-22 19:20:36 +0000 | [diff] [blame] | 997 | // If the global variable was optmized out then no need to create debug info |
| 998 | // entry. |
Devang Patel | 84c73e9 | 2009-11-06 17:58:12 +0000 | [diff] [blame] | 999 | if (!GV.getGlobal()) return NULL; |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 1000 | if (GV.getDisplayName().empty()) return NULL; |
Devang Patel | 465c3be | 2009-11-06 01:30:04 +0000 | [diff] [blame] | 1001 | |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1002 | DIE *GVDie = new DIE(dwarf::DW_TAG_variable); |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 1003 | addString(GVDie, dwarf::DW_AT_name, dwarf::DW_FORM_string, |
Devang Patel | 5ccdd10 | 2009-09-29 18:40:58 +0000 | [diff] [blame] | 1004 | GV.getDisplayName()); |
| 1005 | |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 1006 | StringRef LinkageName = GV.getLinkageName(); |
| 1007 | if (!LinkageName.empty()) { |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 1008 | // Skip special LLVM prefix that is used to inform the asm printer to not |
| 1009 | // emit usual symbol prefix before the symbol name. This happens for |
| 1010 | // Objective-C symbol names and symbol whose name is replaced using GCC's |
| 1011 | // __asm__ attribute. |
Devang Patel | 53cb17d | 2009-07-16 01:01:22 +0000 | [diff] [blame] | 1012 | if (LinkageName[0] == 1) |
Benjamin Kramer | 1c3451f | 2009-11-25 18:26:09 +0000 | [diff] [blame] | 1013 | LinkageName = LinkageName.substr(1); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1014 | addString(GVDie, dwarf::DW_AT_MIPS_linkage_name, dwarf::DW_FORM_string, |
Devang Patel | 1a8d2d2 | 2009-07-14 00:55:28 +0000 | [diff] [blame] | 1015 | LinkageName); |
Devang Patel | 53cb17d | 2009-07-16 01:01:22 +0000 | [diff] [blame] | 1016 | } |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1017 | addType(DW_Unit, GVDie, GV.getType()); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1018 | if (!GV.isLocalToUnit()) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1019 | addUInt(GVDie, dwarf::DW_AT_external, dwarf::DW_FORM_flag, 1); |
| 1020 | addSourceLine(GVDie, &GV); |
Devang Patel | b71a16d | 2009-10-05 23:22:08 +0000 | [diff] [blame] | 1021 | |
| 1022 | // Add address. |
| 1023 | DIEBlock *Block = new DIEBlock(); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1024 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_addr); |
| 1025 | addObjectLabel(Block, 0, dwarf::DW_FORM_udata, |
Devang Patel | b71a16d | 2009-10-05 23:22:08 +0000 | [diff] [blame] | 1026 | Asm->Mang->getMangledName(GV.getGlobal())); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1027 | addBlock(GVDie, dwarf::DW_AT_location, 0, Block); |
Devang Patel | b71a16d | 2009-10-05 23:22:08 +0000 | [diff] [blame] | 1028 | |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1029 | return GVDie; |
| 1030 | } |
| 1031 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1032 | /// createMemberDIE - Create new member DIE. |
| 1033 | DIE *DwarfDebug::createMemberDIE(CompileUnit *DW_Unit, const DIDerivedType &DT){ |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1034 | DIE *MemberDie = new DIE(DT.getTag()); |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 1035 | StringRef Name = DT.getName(); |
| 1036 | if (!Name.empty()) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1037 | addString(MemberDie, dwarf::DW_AT_name, dwarf::DW_FORM_string, Name); |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 1038 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1039 | addType(DW_Unit, MemberDie, DT.getTypeDerivedFrom()); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1040 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1041 | addSourceLine(MemberDie, &DT); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1042 | |
Devang Patel | 33db508 | 2009-11-04 22:06:12 +0000 | [diff] [blame] | 1043 | DIEBlock *MemLocationDie = new DIEBlock(); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1044 | addUInt(MemLocationDie, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst); |
Devang Patel | 33db508 | 2009-11-04 22:06:12 +0000 | [diff] [blame] | 1045 | |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1046 | uint64_t Size = DT.getSizeInBits(); |
Devang Patel | 61ecbd1 | 2009-11-04 23:48:00 +0000 | [diff] [blame] | 1047 | uint64_t FieldSize = DT.getOriginalTypeSize(); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1048 | |
| 1049 | if (Size != FieldSize) { |
| 1050 | // Handle bitfield. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1051 | addUInt(MemberDie, dwarf::DW_AT_byte_size, 0, DT.getOriginalTypeSize()>>3); |
| 1052 | addUInt(MemberDie, dwarf::DW_AT_bit_size, 0, DT.getSizeInBits()); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1053 | |
| 1054 | uint64_t Offset = DT.getOffsetInBits(); |
| 1055 | uint64_t FieldOffset = Offset; |
| 1056 | uint64_t AlignMask = ~(DT.getAlignInBits() - 1); |
| 1057 | uint64_t HiMark = (Offset + FieldSize) & AlignMask; |
| 1058 | FieldOffset = (HiMark - FieldSize); |
| 1059 | Offset -= FieldOffset; |
| 1060 | |
| 1061 | // Maybe we need to work from the other end. |
| 1062 | if (TD->isLittleEndian()) Offset = FieldSize - (Offset + Size); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1063 | addUInt(MemberDie, dwarf::DW_AT_bit_offset, 0, Offset); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1064 | |
Devang Patel | 33db508 | 2009-11-04 22:06:12 +0000 | [diff] [blame] | 1065 | // Here WD_AT_data_member_location points to the anonymous |
| 1066 | // field that includes this bit field. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1067 | addUInt(MemLocationDie, 0, dwarf::DW_FORM_udata, FieldOffset >> 3); |
Devang Patel | 33db508 | 2009-11-04 22:06:12 +0000 | [diff] [blame] | 1068 | |
| 1069 | } else |
| 1070 | // This is not a bitfield. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1071 | addUInt(MemLocationDie, 0, dwarf::DW_FORM_udata, DT.getOffsetInBits() >> 3); |
Devang Patel | 33db508 | 2009-11-04 22:06:12 +0000 | [diff] [blame] | 1072 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1073 | addBlock(MemberDie, dwarf::DW_AT_data_member_location, 0, MemLocationDie); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1074 | |
| 1075 | if (DT.isProtected()) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1076 | addUInt(MemberDie, dwarf::DW_AT_accessibility, 0, |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1077 | dwarf::DW_ACCESS_protected); |
| 1078 | else if (DT.isPrivate()) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1079 | addUInt(MemberDie, dwarf::DW_AT_accessibility, 0, |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1080 | dwarf::DW_ACCESS_private); |
| 1081 | |
| 1082 | return MemberDie; |
| 1083 | } |
| 1084 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1085 | /// createSubprogramDIE - Create new DIE using SP. |
| 1086 | DIE *DwarfDebug::createSubprogramDIE(CompileUnit *DW_Unit, |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1087 | const DISubprogram &SP, |
Bill Wendling | 6679ee4 | 2009-05-18 22:02:36 +0000 | [diff] [blame] | 1088 | bool IsConstructor, |
| 1089 | bool IsInlined) { |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1090 | DIE *SPDie = new DIE(dwarf::DW_TAG_subprogram); |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 1091 | addString(SPDie, dwarf::DW_AT_name, dwarf::DW_FORM_string, SP.getName()); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1092 | |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 1093 | StringRef LinkageName = SP.getLinkageName(); |
| 1094 | if (!LinkageName.empty()) { |
Jim Grosbach | 7ab38df | 2009-11-22 19:20:36 +0000 | [diff] [blame] | 1095 | // Skip special LLVM prefix that is used to inform the asm printer to not |
| 1096 | // emit usual symbol prefix before the symbol name. This happens for |
| 1097 | // Objective-C symbol names and symbol whose name is replaced using GCC's |
| 1098 | // __asm__ attribute. |
Devang Patel | 53cb17d | 2009-07-16 01:01:22 +0000 | [diff] [blame] | 1099 | if (LinkageName[0] == 1) |
Benjamin Kramer | 1c3451f | 2009-11-25 18:26:09 +0000 | [diff] [blame] | 1100 | LinkageName = LinkageName.substr(1); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1101 | addString(SPDie, dwarf::DW_AT_MIPS_linkage_name, dwarf::DW_FORM_string, |
Devang Patel | 1a8d2d2 | 2009-07-14 00:55:28 +0000 | [diff] [blame] | 1102 | LinkageName); |
Devang Patel | 53cb17d | 2009-07-16 01:01:22 +0000 | [diff] [blame] | 1103 | } |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1104 | addSourceLine(SPDie, &SP); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1105 | |
| 1106 | DICompositeType SPTy = SP.getType(); |
| 1107 | DIArray Args = SPTy.getTypeArray(); |
| 1108 | |
| 1109 | // Add prototyped tag, if C or ObjC. |
| 1110 | unsigned Lang = SP.getCompileUnit().getLanguage(); |
| 1111 | if (Lang == dwarf::DW_LANG_C99 || Lang == dwarf::DW_LANG_C89 || |
| 1112 | Lang == dwarf::DW_LANG_ObjC) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1113 | addUInt(SPDie, dwarf::DW_AT_prototyped, dwarf::DW_FORM_flag, 1); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1114 | |
| 1115 | // Add Return Type. |
| 1116 | unsigned SPTag = SPTy.getTag(); |
| 1117 | if (!IsConstructor) { |
| 1118 | if (Args.isNull() || SPTag != dwarf::DW_TAG_subroutine_type) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1119 | addType(DW_Unit, SPDie, SPTy); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1120 | else |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1121 | addType(DW_Unit, SPDie, DIType(Args.getElement(0).getNode())); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1122 | } |
| 1123 | |
| 1124 | if (!SP.isDefinition()) { |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1125 | addUInt(SPDie, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag, 1); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1126 | |
| 1127 | // Add arguments. Do not add arguments for subprogram definition. They will |
| 1128 | // be handled through RecordVariable. |
| 1129 | if (SPTag == dwarf::DW_TAG_subroutine_type) |
| 1130 | for (unsigned i = 1, N = Args.getNumElements(); i < N; ++i) { |
| 1131 | DIE *Arg = new DIE(dwarf::DW_TAG_formal_parameter); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1132 | addType(DW_Unit, Arg, DIType(Args.getElement(i).getNode())); |
| 1133 | addUInt(Arg, dwarf::DW_AT_artificial, dwarf::DW_FORM_flag, 1); // ?? |
| 1134 | SPDie->addChild(Arg); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1135 | } |
| 1136 | } |
| 1137 | |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1138 | // DW_TAG_inlined_subroutine may refer to this DIE. |
Devang Patel | 017d121 | 2009-11-20 21:37:22 +0000 | [diff] [blame] | 1139 | DW_Unit->insertDIE(SP.getNode(), SPDie); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1140 | return SPDie; |
| 1141 | } |
| 1142 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1143 | /// findCompileUnit - Get the compile unit for the given descriptor. |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1144 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1145 | CompileUnit &DwarfDebug::findCompileUnit(DICompileUnit Unit) const { |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1146 | DenseMap<Value *, CompileUnit *>::const_iterator I = |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1147 | CompileUnitMap.find(Unit.getNode()); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1148 | assert(I != CompileUnitMap.end() && "Missing compile unit."); |
| 1149 | return *I->second; |
| 1150 | } |
| 1151 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1152 | /// createDbgScopeVariable - Create a new scope variable. |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1153 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1154 | DIE *DwarfDebug::createDbgScopeVariable(DbgVariable *DV, CompileUnit *Unit) { |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1155 | // Get the descriptor. |
| 1156 | const DIVariable &VD = DV->getVariable(); |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 1157 | StringRef Name = VD.getName(); |
| 1158 | if (Name.empty()) |
Devang Patel | 1b84597 | 2009-11-03 18:30:27 +0000 | [diff] [blame] | 1159 | return NULL; |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1160 | |
| 1161 | // Translate tag to proper Dwarf tag. The result variable is dropped for |
| 1162 | // now. |
| 1163 | unsigned Tag; |
| 1164 | switch (VD.getTag()) { |
| 1165 | case dwarf::DW_TAG_return_variable: |
| 1166 | return NULL; |
| 1167 | case dwarf::DW_TAG_arg_variable: |
| 1168 | Tag = dwarf::DW_TAG_formal_parameter; |
| 1169 | break; |
| 1170 | case dwarf::DW_TAG_auto_variable: // fall thru |
| 1171 | default: |
| 1172 | Tag = dwarf::DW_TAG_variable; |
| 1173 | break; |
| 1174 | } |
| 1175 | |
| 1176 | // Define variable debug information entry. |
| 1177 | DIE *VariableDie = new DIE(Tag); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1178 | addString(VariableDie, dwarf::DW_AT_name, dwarf::DW_FORM_string, Name); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1179 | |
| 1180 | // Add source line info if available. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1181 | addSourceLine(VariableDie, &VD); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1182 | |
| 1183 | // Add variable type. |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 1184 | // FIXME: isBlockByrefVariable should be reformulated in terms of complex |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1185 | // addresses instead. |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 1186 | if (VD.isBlockByrefVariable()) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1187 | addType(Unit, VariableDie, getBlockByrefType(VD.getType(), Name)); |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 1188 | else |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1189 | addType(Unit, VariableDie, VD.getType()); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1190 | |
| 1191 | // Add variable address. |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1192 | // Variables for abstract instances of inlined functions don't get a |
| 1193 | // location. |
| 1194 | MachineLocation Location; |
Jim Grosbach | a2f20b2 | 2009-11-22 20:14:00 +0000 | [diff] [blame] | 1195 | unsigned FrameReg; |
| 1196 | int Offset = RI->getFrameIndexReference(*MF, DV->getFrameIndex(), FrameReg); |
| 1197 | Location.set(FrameReg, Offset); |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 1198 | |
| 1199 | |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1200 | if (VD.hasComplexAddress()) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1201 | addComplexAddress(DV, VariableDie, dwarf::DW_AT_location, Location); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1202 | else if (VD.isBlockByrefVariable()) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1203 | addBlockByrefAddress(DV, VariableDie, dwarf::DW_AT_location, Location); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1204 | else |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1205 | addAddress(VariableDie, dwarf::DW_AT_location, Location); |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 1206 | |
| 1207 | return VariableDie; |
| 1208 | } |
| 1209 | |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1210 | /// getUpdatedDbgScope - Find or create DbgScope assicated with the instruction. |
| 1211 | /// Initialize scope and update scope hierarchy. |
| 1212 | DbgScope *DwarfDebug::getUpdatedDbgScope(MDNode *N, const MachineInstr *MI, |
| 1213 | MDNode *InlinedAt) { |
| 1214 | assert (N && "Invalid Scope encoding!"); |
| 1215 | assert (MI && "Missing machine instruction!"); |
| 1216 | bool GetConcreteScope = (MI && InlinedAt); |
| 1217 | |
| 1218 | DbgScope *NScope = NULL; |
| 1219 | |
| 1220 | if (InlinedAt) |
| 1221 | NScope = DbgScopeMap.lookup(InlinedAt); |
| 1222 | else |
| 1223 | NScope = DbgScopeMap.lookup(N); |
| 1224 | assert (NScope && "Unable to find working scope!"); |
| 1225 | |
| 1226 | if (NScope->getFirstInsn()) |
| 1227 | return NScope; |
Devang Patel | af9e847 | 2009-10-01 20:31:14 +0000 | [diff] [blame] | 1228 | |
| 1229 | DbgScope *Parent = NULL; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1230 | if (GetConcreteScope) { |
Devang Patel | c90aefe | 2009-10-14 21:08:09 +0000 | [diff] [blame] | 1231 | DILocation IL(InlinedAt); |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 1232 | Parent = getUpdatedDbgScope(IL.getScope().getNode(), MI, |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1233 | IL.getOrigLocation().getNode()); |
| 1234 | assert (Parent && "Unable to find Parent scope!"); |
| 1235 | NScope->setParent(Parent); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1236 | Parent->addScope(NScope); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1237 | } else if (DIDescriptor(N).isLexicalBlock()) { |
| 1238 | DILexicalBlock DB(N); |
| 1239 | if (!DB.getContext().isNull()) { |
| 1240 | Parent = getUpdatedDbgScope(DB.getContext().getNode(), MI, InlinedAt); |
| 1241 | NScope->setParent(Parent); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1242 | Parent->addScope(NScope); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1243 | } |
Devang Patel | c90aefe | 2009-10-14 21:08:09 +0000 | [diff] [blame] | 1244 | } |
Devang Patel | af9e847 | 2009-10-01 20:31:14 +0000 | [diff] [blame] | 1245 | |
Devang Patel | bdf45cb | 2009-10-27 20:47:17 +0000 | [diff] [blame] | 1246 | NScope->setFirstInsn(MI); |
Devang Patel | af9e847 | 2009-10-01 20:31:14 +0000 | [diff] [blame] | 1247 | |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1248 | if (!Parent && !InlinedAt) { |
Devang Patel | 39ae3ff | 2009-11-11 00:31:36 +0000 | [diff] [blame] | 1249 | StringRef SPName = DISubprogram(N).getLinkageName(); |
| 1250 | if (SPName == MF->getFunction()->getName()) |
| 1251 | CurrentFnDbgScope = NScope; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1252 | } |
Devang Patel | af9e847 | 2009-10-01 20:31:14 +0000 | [diff] [blame] | 1253 | |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1254 | if (GetConcreteScope) { |
| 1255 | ConcreteScopes[InlinedAt] = NScope; |
| 1256 | getOrCreateAbstractScope(N); |
| 1257 | } |
| 1258 | |
Devang Patel | bdf45cb | 2009-10-27 20:47:17 +0000 | [diff] [blame] | 1259 | return NScope; |
Devang Patel | af9e847 | 2009-10-01 20:31:14 +0000 | [diff] [blame] | 1260 | } |
| 1261 | |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1262 | DbgScope *DwarfDebug::getOrCreateAbstractScope(MDNode *N) { |
| 1263 | assert (N && "Invalid Scope encoding!"); |
| 1264 | |
| 1265 | DbgScope *AScope = AbstractScopes.lookup(N); |
| 1266 | if (AScope) |
| 1267 | return AScope; |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 1268 | |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1269 | DbgScope *Parent = NULL; |
| 1270 | |
| 1271 | DIDescriptor Scope(N); |
| 1272 | if (Scope.isLexicalBlock()) { |
| 1273 | DILexicalBlock DB(N); |
| 1274 | DIDescriptor ParentDesc = DB.getContext(); |
| 1275 | if (!ParentDesc.isNull()) |
| 1276 | Parent = getOrCreateAbstractScope(ParentDesc.getNode()); |
| 1277 | } |
| 1278 | |
| 1279 | AScope = new DbgScope(Parent, DIDescriptor(N), NULL); |
| 1280 | |
| 1281 | if (Parent) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1282 | Parent->addScope(AScope); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1283 | AScope->setAbstractScope(); |
| 1284 | AbstractScopes[N] = AScope; |
| 1285 | if (DIDescriptor(N).isSubprogram()) |
| 1286 | AbstractScopesList.push_back(AScope); |
| 1287 | return AScope; |
| 1288 | } |
Devang Patel | af9e847 | 2009-10-01 20:31:14 +0000 | [diff] [blame] | 1289 | |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 1290 | /// updateSubprogramScopeDIE - Find DIE for the given subprogram and |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1291 | /// attach appropriate DW_AT_low_pc and DW_AT_high_pc attributes. |
| 1292 | /// If there are global variables in this scope then create and insert |
| 1293 | /// DIEs for these variables. |
| 1294 | DIE *DwarfDebug::updateSubprogramScopeDIE(MDNode *SPNode) { |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1295 | |
Devang Patel | 017d121 | 2009-11-20 21:37:22 +0000 | [diff] [blame] | 1296 | DIE *SPDie = ModuleCU->getDIE(SPNode); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1297 | assert (SPDie && "Unable to find subprogram DIE!"); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1298 | addLabel(SPDie, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr, |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1299 | DWLabel("func_begin", SubprogramCount)); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1300 | addLabel(SPDie, dwarf::DW_AT_high_pc, dwarf::DW_FORM_addr, |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1301 | DWLabel("func_end", SubprogramCount)); |
| 1302 | MachineLocation Location(RI->getFrameRegister(*MF)); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1303 | addAddress(SPDie, dwarf::DW_AT_frame_base, Location); |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 1304 | |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1305 | if (!DISubprogram(SPNode).isLocalToUnit()) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1306 | addUInt(SPDie, dwarf::DW_AT_external, dwarf::DW_FORM_flag, 1); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1307 | |
| 1308 | // If there are global variables at this scope then add their dies. |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 1309 | for (SmallVector<WeakVH, 4>::iterator SGI = ScopedGVs.begin(), |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1310 | SGE = ScopedGVs.end(); SGI != SGE; ++SGI) { |
| 1311 | MDNode *N = dyn_cast_or_null<MDNode>(*SGI); |
| 1312 | if (!N) continue; |
| 1313 | DIGlobalVariable GV(N); |
| 1314 | if (GV.getContext().getNode() == SPNode) { |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1315 | DIE *ScopedGVDie = createGlobalVariableDIE(ModuleCU, GV); |
Devang Patel | fb0ee43 | 2009-11-10 23:20:04 +0000 | [diff] [blame] | 1316 | if (ScopedGVDie) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1317 | SPDie->addChild(ScopedGVDie); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1318 | } |
| 1319 | } |
Devang Patel | 193f720 | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 1320 | |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1321 | return SPDie; |
| 1322 | } |
| 1323 | |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 1324 | /// constructLexicalScope - Construct new DW_TAG_lexical_block |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1325 | /// for this scope and attach DW_AT_low_pc/DW_AT_high_pc labels. |
| 1326 | DIE *DwarfDebug::constructLexicalScopeDIE(DbgScope *Scope) { |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1327 | unsigned StartID = MMI->MappedLabel(Scope->getStartLabelID()); |
| 1328 | unsigned EndID = MMI->MappedLabel(Scope->getEndLabelID()); |
| 1329 | |
| 1330 | // Ignore empty scopes. |
| 1331 | if (StartID == EndID && StartID != 0) |
| 1332 | return NULL; |
| 1333 | |
| 1334 | DIE *ScopeDIE = new DIE(dwarf::DW_TAG_lexical_block); |
| 1335 | if (Scope->isAbstractScope()) |
| 1336 | return ScopeDIE; |
| 1337 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1338 | addLabel(ScopeDIE, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr, |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 1339 | StartID ? |
| 1340 | DWLabel("label", StartID) |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1341 | : DWLabel("func_begin", SubprogramCount)); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1342 | addLabel(ScopeDIE, dwarf::DW_AT_high_pc, dwarf::DW_FORM_addr, |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 1343 | EndID ? |
| 1344 | DWLabel("label", EndID) |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1345 | : DWLabel("func_end", SubprogramCount)); |
| 1346 | |
| 1347 | |
| 1348 | |
| 1349 | return ScopeDIE; |
| 1350 | } |
| 1351 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1352 | /// constructInlinedScopeDIE - This scope represents inlined body of |
| 1353 | /// a function. Construct DIE to represent this concrete inlined copy |
| 1354 | /// of the function. |
| 1355 | DIE *DwarfDebug::constructInlinedScopeDIE(DbgScope *Scope) { |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1356 | unsigned StartID = MMI->MappedLabel(Scope->getStartLabelID()); |
| 1357 | unsigned EndID = MMI->MappedLabel(Scope->getEndLabelID()); |
| 1358 | assert (StartID && "Invalid starting label for an inlined scope!"); |
| 1359 | assert (EndID && "Invalid end label for an inlined scope!"); |
| 1360 | // Ignore empty scopes. |
| 1361 | if (StartID == EndID && StartID != 0) |
| 1362 | return NULL; |
| 1363 | |
| 1364 | DIScope DS(Scope->getScopeNode()); |
| 1365 | if (DS.isNull()) |
| 1366 | return NULL; |
| 1367 | DIE *ScopeDIE = new DIE(dwarf::DW_TAG_inlined_subroutine); |
| 1368 | |
| 1369 | DISubprogram InlinedSP = getDISubprogram(DS.getNode()); |
Devang Patel | 017d121 | 2009-11-20 21:37:22 +0000 | [diff] [blame] | 1370 | DIE *OriginDIE = ModuleCU->getDIE(InlinedSP.getNode()); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1371 | assert (OriginDIE && "Unable to find Origin DIE!"); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1372 | addDIEEntry(ScopeDIE, dwarf::DW_AT_abstract_origin, |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1373 | dwarf::DW_FORM_ref4, OriginDIE); |
| 1374 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1375 | addLabel(ScopeDIE, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr, |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1376 | DWLabel("label", StartID)); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1377 | addLabel(ScopeDIE, dwarf::DW_AT_high_pc, dwarf::DW_FORM_addr, |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1378 | DWLabel("label", EndID)); |
| 1379 | |
| 1380 | InlinedSubprogramDIEs.insert(OriginDIE); |
| 1381 | |
| 1382 | // Track the start label for this inlined function. |
| 1383 | ValueMap<MDNode *, SmallVector<InlineInfoLabels, 4> >::iterator |
| 1384 | I = InlineInfo.find(InlinedSP.getNode()); |
| 1385 | |
| 1386 | if (I == InlineInfo.end()) { |
Jim Grosbach | 7ab38df | 2009-11-22 19:20:36 +0000 | [diff] [blame] | 1387 | InlineInfo[InlinedSP.getNode()].push_back(std::make_pair(StartID, |
| 1388 | ScopeDIE)); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1389 | InlinedSPNodes.push_back(InlinedSP.getNode()); |
| 1390 | } else |
| 1391 | I->second.push_back(std::make_pair(StartID, ScopeDIE)); |
| 1392 | |
| 1393 | StringPool.insert(InlinedSP.getName()); |
| 1394 | StringPool.insert(InlinedSP.getLinkageName()); |
| 1395 | DILocation DL(Scope->getInlinedAt()); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1396 | addUInt(ScopeDIE, dwarf::DW_AT_call_file, 0, ModuleCU->getID()); |
| 1397 | addUInt(ScopeDIE, dwarf::DW_AT_call_line, 0, DL.getLineNumber()); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1398 | |
| 1399 | return ScopeDIE; |
| 1400 | } |
| 1401 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1402 | |
| 1403 | /// constructVariableDIE - Construct a DIE for the given DbgVariable. |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 1404 | DIE *DwarfDebug::constructVariableDIE(DbgVariable *DV, |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1405 | DbgScope *Scope, CompileUnit *Unit) { |
| 1406 | // Get the descriptor. |
| 1407 | const DIVariable &VD = DV->getVariable(); |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 1408 | StringRef Name = VD.getName(); |
| 1409 | if (Name.empty()) |
Devang Patel | 3fb6bd6 | 2009-11-13 02:25:26 +0000 | [diff] [blame] | 1410 | return NULL; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1411 | |
| 1412 | // Translate tag to proper Dwarf tag. The result variable is dropped for |
| 1413 | // now. |
| 1414 | unsigned Tag; |
| 1415 | switch (VD.getTag()) { |
| 1416 | case dwarf::DW_TAG_return_variable: |
| 1417 | return NULL; |
| 1418 | case dwarf::DW_TAG_arg_variable: |
| 1419 | Tag = dwarf::DW_TAG_formal_parameter; |
| 1420 | break; |
| 1421 | case dwarf::DW_TAG_auto_variable: // fall thru |
| 1422 | default: |
| 1423 | Tag = dwarf::DW_TAG_variable; |
| 1424 | break; |
| 1425 | } |
| 1426 | |
| 1427 | // Define variable debug information entry. |
| 1428 | DIE *VariableDie = new DIE(Tag); |
| 1429 | |
| 1430 | |
| 1431 | DIE *AbsDIE = NULL; |
| 1432 | if (DbgVariable *AV = DV->getAbstractVariable()) |
| 1433 | AbsDIE = AV->getDIE(); |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 1434 | |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1435 | if (AbsDIE) { |
| 1436 | DIScope DS(Scope->getScopeNode()); |
| 1437 | DISubprogram InlinedSP = getDISubprogram(DS.getNode()); |
Devang Patel | 017d121 | 2009-11-20 21:37:22 +0000 | [diff] [blame] | 1438 | DIE *OriginSPDIE = ModuleCU->getDIE(InlinedSP.getNode()); |
Daniel Dunbar | c032679 | 2009-11-11 03:09:50 +0000 | [diff] [blame] | 1439 | (void) OriginSPDIE; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1440 | assert (OriginSPDIE && "Unable to find Origin DIE for the SP!"); |
| 1441 | DIE *AbsDIE = DV->getAbstractVariable()->getDIE(); |
| 1442 | assert (AbsDIE && "Unable to find Origin DIE for the Variable!"); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1443 | addDIEEntry(VariableDie, dwarf::DW_AT_abstract_origin, |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1444 | dwarf::DW_FORM_ref4, AbsDIE); |
| 1445 | } |
| 1446 | else { |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1447 | addString(VariableDie, dwarf::DW_AT_name, dwarf::DW_FORM_string, Name); |
| 1448 | addSourceLine(VariableDie, &VD); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1449 | |
| 1450 | // Add variable type. |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 1451 | // FIXME: isBlockByrefVariable should be reformulated in terms of complex |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1452 | // addresses instead. |
| 1453 | if (VD.isBlockByrefVariable()) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1454 | addType(Unit, VariableDie, getBlockByrefType(VD.getType(), Name)); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1455 | else |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1456 | addType(Unit, VariableDie, VD.getType()); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1457 | } |
| 1458 | |
| 1459 | // Add variable address. |
| 1460 | if (!Scope->isAbstractScope()) { |
| 1461 | MachineLocation Location; |
Jim Grosbach | a2f20b2 | 2009-11-22 20:14:00 +0000 | [diff] [blame] | 1462 | unsigned FrameReg; |
| 1463 | int Offset = RI->getFrameIndexReference(*MF, DV->getFrameIndex(), FrameReg); |
| 1464 | Location.set(FrameReg, Offset); |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 1465 | |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1466 | if (VD.hasComplexAddress()) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1467 | addComplexAddress(DV, VariableDie, dwarf::DW_AT_location, Location); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1468 | else if (VD.isBlockByrefVariable()) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1469 | addBlockByrefAddress(DV, VariableDie, dwarf::DW_AT_location, Location); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1470 | else |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1471 | addAddress(VariableDie, dwarf::DW_AT_location, Location); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1472 | } |
| 1473 | DV->setDIE(VariableDie); |
| 1474 | return VariableDie; |
| 1475 | |
| 1476 | } |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1477 | |
Devang Patel | 193f720 | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 1478 | void DwarfDebug::addPubTypes(DISubprogram SP) { |
| 1479 | DICompositeType SPTy = SP.getType(); |
| 1480 | unsigned SPTag = SPTy.getTag(); |
| 1481 | if (SPTag != dwarf::DW_TAG_subroutine_type) |
| 1482 | return; |
| 1483 | |
| 1484 | DIArray Args = SPTy.getTypeArray(); |
| 1485 | if (Args.isNull()) |
| 1486 | return; |
| 1487 | |
| 1488 | for (unsigned i = 0, e = Args.getNumElements(); i != e; ++i) { |
| 1489 | DIType ATy(Args.getElement(i).getNode()); |
| 1490 | if (ATy.isNull()) |
| 1491 | continue; |
| 1492 | DICompositeType CATy = getDICompositeType(ATy); |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 1493 | if (!CATy.isNull() && !CATy.getName().empty()) { |
Devang Patel | 193f720 | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 1494 | if (DIEEntry *Entry = ModuleCU->getDIEEntry(CATy.getNode())) |
| 1495 | ModuleCU->addGlobalType(CATy.getName(), Entry->getEntry()); |
| 1496 | } |
| 1497 | } |
| 1498 | } |
| 1499 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1500 | /// constructScopeDIE - Construct a DIE for this scope. |
| 1501 | DIE *DwarfDebug::constructScopeDIE(DbgScope *Scope) { |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1502 | if (!Scope) |
| 1503 | return NULL; |
| 1504 | DIScope DS(Scope->getScopeNode()); |
| 1505 | if (DS.isNull()) |
| 1506 | return NULL; |
| 1507 | |
| 1508 | DIE *ScopeDIE = NULL; |
| 1509 | if (Scope->getInlinedAt()) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1510 | ScopeDIE = constructInlinedScopeDIE(Scope); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1511 | else if (DS.isSubprogram()) { |
| 1512 | if (Scope->isAbstractScope()) |
Devang Patel | 017d121 | 2009-11-20 21:37:22 +0000 | [diff] [blame] | 1513 | ScopeDIE = ModuleCU->getDIE(DS.getNode()); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1514 | else |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1515 | ScopeDIE = updateSubprogramScopeDIE(DS.getNode()); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1516 | } |
| 1517 | else { |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1518 | ScopeDIE = constructLexicalScopeDIE(Scope); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1519 | if (!ScopeDIE) return NULL; |
| 1520 | } |
| 1521 | |
| 1522 | // Add variables to scope. |
| 1523 | SmallVector<DbgVariable *, 8> &Variables = Scope->getVariables(); |
| 1524 | for (unsigned i = 0, N = Variables.size(); i < N; ++i) { |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1525 | DIE *VariableDIE = constructVariableDIE(Variables[i], Scope, ModuleCU); |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 1526 | if (VariableDIE) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1527 | ScopeDIE->addChild(VariableDIE); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1528 | } |
| 1529 | |
| 1530 | // Add nested scopes. |
| 1531 | SmallVector<DbgScope *, 4> &Scopes = Scope->getScopes(); |
| 1532 | for (unsigned j = 0, M = Scopes.size(); j < M; ++j) { |
| 1533 | // Define the Scope debug information entry. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1534 | DIE *NestedDIE = constructScopeDIE(Scopes[j]); |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 1535 | if (NestedDIE) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1536 | ScopeDIE->addChild(NestedDIE); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1537 | } |
Devang Patel | 193f720 | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 1538 | |
| 1539 | if (DS.isSubprogram()) |
| 1540 | addPubTypes(DISubprogram(DS.getNode())); |
| 1541 | |
| 1542 | return ScopeDIE; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1543 | } |
| 1544 | |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1545 | /// GetOrCreateSourceID - Look up the source id with the given directory and |
| 1546 | /// source file names. If none currently exists, create a new id and insert it |
| 1547 | /// in the SourceIds map. This can update DirectoryNames and SourceFileNames |
| 1548 | /// maps as well. |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 1549 | unsigned DwarfDebug::GetOrCreateSourceID(StringRef DirName, StringRef FileName) { |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1550 | unsigned DId; |
| 1551 | StringMap<unsigned>::iterator DI = DirectoryIdMap.find(DirName); |
| 1552 | if (DI != DirectoryIdMap.end()) { |
| 1553 | DId = DI->getValue(); |
| 1554 | } else { |
| 1555 | DId = DirectoryNames.size() + 1; |
| 1556 | DirectoryIdMap[DirName] = DId; |
| 1557 | DirectoryNames.push_back(DirName); |
| 1558 | } |
| 1559 | |
| 1560 | unsigned FId; |
| 1561 | StringMap<unsigned>::iterator FI = SourceFileIdMap.find(FileName); |
| 1562 | if (FI != SourceFileIdMap.end()) { |
| 1563 | FId = FI->getValue(); |
| 1564 | } else { |
| 1565 | FId = SourceFileNames.size() + 1; |
| 1566 | SourceFileIdMap[FileName] = FId; |
| 1567 | SourceFileNames.push_back(FileName); |
| 1568 | } |
| 1569 | |
| 1570 | DenseMap<std::pair<unsigned, unsigned>, unsigned>::iterator SI = |
| 1571 | SourceIdMap.find(std::make_pair(DId, FId)); |
| 1572 | if (SI != SourceIdMap.end()) |
| 1573 | return SI->second; |
| 1574 | |
| 1575 | unsigned SrcId = SourceIds.size() + 1; // DW_AT_decl_file cannot be 0. |
| 1576 | SourceIdMap[std::make_pair(DId, FId)] = SrcId; |
| 1577 | SourceIds.push_back(std::make_pair(DId, FId)); |
| 1578 | |
| 1579 | return SrcId; |
| 1580 | } |
| 1581 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1582 | void DwarfDebug::constructCompileUnit(MDNode *N) { |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1583 | DICompileUnit DIUnit(N); |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 1584 | StringRef FN = DIUnit.getFilename(); |
| 1585 | StringRef Dir = DIUnit.getDirectory(); |
Devang Patel | 5ccdd10 | 2009-09-29 18:40:58 +0000 | [diff] [blame] | 1586 | unsigned ID = GetOrCreateSourceID(Dir, FN); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1587 | |
| 1588 | DIE *Die = new DIE(dwarf::DW_TAG_compile_unit); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1589 | addSectionOffset(Die, dwarf::DW_AT_stmt_list, dwarf::DW_FORM_data4, |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1590 | DWLabel("section_line", 0), DWLabel("section_line", 0), |
| 1591 | false); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1592 | addString(Die, dwarf::DW_AT_producer, dwarf::DW_FORM_string, |
Devang Patel | 5ccdd10 | 2009-09-29 18:40:58 +0000 | [diff] [blame] | 1593 | DIUnit.getProducer()); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1594 | addUInt(Die, dwarf::DW_AT_language, dwarf::DW_FORM_data1, |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1595 | DIUnit.getLanguage()); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1596 | addString(Die, dwarf::DW_AT_name, dwarf::DW_FORM_string, FN); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1597 | |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 1598 | if (!Dir.empty()) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1599 | addString(Die, dwarf::DW_AT_comp_dir, dwarf::DW_FORM_string, Dir); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1600 | if (DIUnit.isOptimized()) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1601 | addUInt(Die, dwarf::DW_AT_APPLE_optimized, dwarf::DW_FORM_flag, 1); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1602 | |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 1603 | StringRef Flags = DIUnit.getFlags(); |
| 1604 | if (!Flags.empty()) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1605 | addString(Die, dwarf::DW_AT_APPLE_flags, dwarf::DW_FORM_string, Flags); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1606 | |
| 1607 | unsigned RVer = DIUnit.getRunTimeVersion(); |
| 1608 | if (RVer) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1609 | addUInt(Die, dwarf::DW_AT_APPLE_major_runtime_vers, |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1610 | dwarf::DW_FORM_data1, RVer); |
| 1611 | |
| 1612 | CompileUnit *Unit = new CompileUnit(ID, Die); |
Devang Patel | 1dbc771 | 2009-06-29 20:45:18 +0000 | [diff] [blame] | 1613 | if (!ModuleCU && DIUnit.isMain()) { |
Devang Patel | 70f4426 | 2009-06-29 20:38:13 +0000 | [diff] [blame] | 1614 | // Use first compile unit marked as isMain as the compile unit |
| 1615 | // for this module. |
Devang Patel | 1dbc771 | 2009-06-29 20:45:18 +0000 | [diff] [blame] | 1616 | ModuleCU = Unit; |
Devang Patel | 70f4426 | 2009-06-29 20:38:13 +0000 | [diff] [blame] | 1617 | } |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1618 | |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1619 | CompileUnitMap[DIUnit.getNode()] = Unit; |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1620 | CompileUnits.push_back(Unit); |
| 1621 | } |
| 1622 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1623 | void DwarfDebug::constructGlobalVariableDIE(MDNode *N) { |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1624 | DIGlobalVariable DI_GV(N); |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 1625 | |
Devang Patel | 905cf5e | 2009-09-04 23:59:07 +0000 | [diff] [blame] | 1626 | // If debug information is malformed then ignore it. |
| 1627 | if (DI_GV.Verify() == false) |
| 1628 | return; |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1629 | |
| 1630 | // Check for pre-existence. |
Devang Patel | 017d121 | 2009-11-20 21:37:22 +0000 | [diff] [blame] | 1631 | if (ModuleCU->getDIE(DI_GV.getNode())) |
Devang Patel | 13e16b6 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 1632 | return; |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1633 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1634 | DIE *VariableDie = createGlobalVariableDIE(ModuleCU, DI_GV); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1635 | |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1636 | // Add to map. |
Devang Patel | 017d121 | 2009-11-20 21:37:22 +0000 | [diff] [blame] | 1637 | ModuleCU->insertDIE(N, VariableDie); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1638 | |
| 1639 | // Add to context owner. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1640 | ModuleCU->getCUDie()->addChild(VariableDie); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1641 | |
| 1642 | // Expose as global. FIXME - need to check external flag. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1643 | ModuleCU->addGlobal(DI_GV.getName(), VariableDie); |
Devang Patel | 193f720 | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 1644 | |
| 1645 | DIType GTy = DI_GV.getType(); |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 1646 | if (GTy.isCompositeType() && !GTy.getName().empty()) { |
Devang Patel | 193f720 | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 1647 | DIEEntry *Entry = ModuleCU->getDIEEntry(GTy.getNode()); |
| 1648 | assert (Entry && "Missing global type!"); |
| 1649 | ModuleCU->addGlobalType(GTy.getName(), Entry->getEntry()); |
| 1650 | } |
Devang Patel | 13e16b6 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 1651 | return; |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1652 | } |
| 1653 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1654 | void DwarfDebug::constructSubprogramDIE(MDNode *N) { |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1655 | DISubprogram SP(N); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1656 | |
| 1657 | // Check for pre-existence. |
Devang Patel | 017d121 | 2009-11-20 21:37:22 +0000 | [diff] [blame] | 1658 | if (ModuleCU->getDIE(N)) |
Devang Patel | 13e16b6 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 1659 | return; |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1660 | |
| 1661 | if (!SP.isDefinition()) |
| 1662 | // This is a method declaration which will be handled while constructing |
| 1663 | // class type. |
Devang Patel | 13e16b6 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 1664 | return; |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1665 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1666 | DIE *SubprogramDie = createSubprogramDIE(ModuleCU, SP); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1667 | |
| 1668 | // Add to map. |
Devang Patel | 017d121 | 2009-11-20 21:37:22 +0000 | [diff] [blame] | 1669 | ModuleCU->insertDIE(N, SubprogramDie); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1670 | |
| 1671 | // Add to context owner. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1672 | ModuleCU->getCUDie()->addChild(SubprogramDie); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1673 | |
| 1674 | // Expose as global. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1675 | ModuleCU->addGlobal(SP.getName(), SubprogramDie); |
Devang Patel | 193f720 | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 1676 | |
Devang Patel | 13e16b6 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 1677 | return; |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1678 | } |
| 1679 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1680 | /// beginModule - Emit all Dwarf sections that should come prior to the |
Daniel Dunbar | 0056499 | 2009-09-19 20:40:14 +0000 | [diff] [blame] | 1681 | /// content. Create global DIEs and emit initial debug info sections. |
| 1682 | /// This is inovked by the target AsmPrinter. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1683 | void DwarfDebug::beginModule(Module *M, MachineModuleInfo *mmi) { |
Devang Patel | 208622d | 2009-06-25 22:36:02 +0000 | [diff] [blame] | 1684 | this->M = M; |
| 1685 | |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1686 | if (TimePassesIsEnabled) |
| 1687 | DebugTimer->startTimer(); |
| 1688 | |
Devang Patel | 3380cc5 | 2009-11-11 19:55:08 +0000 | [diff] [blame] | 1689 | if (!MAI->doesSupportDebugInformation()) |
| 1690 | return; |
| 1691 | |
Devang Patel | 78ab9e2 | 2009-07-30 18:56:46 +0000 | [diff] [blame] | 1692 | DebugInfoFinder DbgFinder; |
| 1693 | DbgFinder.processModule(*M); |
Devang Patel | 13e16b6 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 1694 | |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1695 | // Create all the compile unit DIEs. |
Devang Patel | 78ab9e2 | 2009-07-30 18:56:46 +0000 | [diff] [blame] | 1696 | for (DebugInfoFinder::iterator I = DbgFinder.compile_unit_begin(), |
| 1697 | E = DbgFinder.compile_unit_end(); I != E; ++I) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1698 | constructCompileUnit(*I); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1699 | |
| 1700 | if (CompileUnits.empty()) { |
| 1701 | if (TimePassesIsEnabled) |
| 1702 | DebugTimer->stopTimer(); |
| 1703 | |
| 1704 | return; |
| 1705 | } |
| 1706 | |
Devang Patel | 70f4426 | 2009-06-29 20:38:13 +0000 | [diff] [blame] | 1707 | // If main compile unit for this module is not seen than randomly |
| 1708 | // select first compile unit. |
Devang Patel | 1dbc771 | 2009-06-29 20:45:18 +0000 | [diff] [blame] | 1709 | if (!ModuleCU) |
| 1710 | ModuleCU = CompileUnits[0]; |
Devang Patel | 70f4426 | 2009-06-29 20:38:13 +0000 | [diff] [blame] | 1711 | |
Devang Patel | 13e16b6 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 1712 | // Create DIEs for each of the externally visible global variables. |
Devang Patel | 78ab9e2 | 2009-07-30 18:56:46 +0000 | [diff] [blame] | 1713 | for (DebugInfoFinder::iterator I = DbgFinder.global_variable_begin(), |
Devang Patel | fd07cf5 | 2009-10-05 23:40:42 +0000 | [diff] [blame] | 1714 | E = DbgFinder.global_variable_end(); I != E; ++I) { |
| 1715 | DIGlobalVariable GV(*I); |
| 1716 | if (GV.getContext().getNode() != GV.getCompileUnit().getNode()) |
| 1717 | ScopedGVs.push_back(*I); |
| 1718 | else |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1719 | constructGlobalVariableDIE(*I); |
Devang Patel | fd07cf5 | 2009-10-05 23:40:42 +0000 | [diff] [blame] | 1720 | } |
Devang Patel | 13e16b6 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 1721 | |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1722 | // Create DIEs for each subprogram. |
Devang Patel | 78ab9e2 | 2009-07-30 18:56:46 +0000 | [diff] [blame] | 1723 | for (DebugInfoFinder::iterator I = DbgFinder.subprogram_begin(), |
| 1724 | E = DbgFinder.subprogram_end(); I != E; ++I) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1725 | constructSubprogramDIE(*I); |
Devang Patel | 13e16b6 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 1726 | |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1727 | MMI = mmi; |
| 1728 | shouldEmit = true; |
| 1729 | MMI->setDebugInfoAvailability(true); |
| 1730 | |
| 1731 | // Prime section data. |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 1732 | SectionMap.insert(Asm->getObjFileLowering().getTextSection()); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1733 | |
| 1734 | // Print out .file directives to specify files for .loc directives. These are |
| 1735 | // printed out early so that they precede any .loc directives. |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 1736 | if (MAI->hasDotLocAndDotFile()) { |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1737 | for (unsigned i = 1, e = getNumSourceIds()+1; i != e; ++i) { |
| 1738 | // Remember source id starts at 1. |
| 1739 | std::pair<unsigned, unsigned> Id = getSourceDirectoryAndFileIds(i); |
| 1740 | sys::Path FullPath(getSourceDirectoryName(Id.first)); |
| 1741 | bool AppendOk = |
| 1742 | FullPath.appendComponent(getSourceFileName(Id.second)); |
| 1743 | assert(AppendOk && "Could not append filename to directory!"); |
| 1744 | AppendOk = false; |
Chris Lattner | 74382b7 | 2009-08-23 22:45:37 +0000 | [diff] [blame] | 1745 | Asm->EmitFile(i, FullPath.str()); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1746 | Asm->EOL(); |
| 1747 | } |
| 1748 | } |
| 1749 | |
| 1750 | // Emit initial sections |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1751 | emitInitial(); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1752 | |
| 1753 | if (TimePassesIsEnabled) |
| 1754 | DebugTimer->stopTimer(); |
| 1755 | } |
| 1756 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1757 | /// endModule - Emit all Dwarf sections that should come after the content. |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1758 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1759 | void DwarfDebug::endModule() { |
Devang Patel | 6f3dc92 | 2009-10-06 00:03:14 +0000 | [diff] [blame] | 1760 | if (!ModuleCU) |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1761 | return; |
| 1762 | |
| 1763 | if (TimePassesIsEnabled) |
| 1764 | DebugTimer->startTimer(); |
| 1765 | |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1766 | // Attach DW_AT_inline attribute with inlined subprogram DIEs. |
| 1767 | for (SmallPtrSet<DIE *, 4>::iterator AI = InlinedSubprogramDIEs.begin(), |
| 1768 | AE = InlinedSubprogramDIEs.end(); AI != AE; ++AI) { |
| 1769 | DIE *ISP = *AI; |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1770 | addUInt(ISP, dwarf::DW_AT_inline, 0, dwarf::DW_INL_inlined); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1771 | } |
| 1772 | |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1773 | // Standard sections final addresses. |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 1774 | Asm->OutStreamer.SwitchSection(Asm->getObjFileLowering().getTextSection()); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1775 | EmitLabel("text_end", 0); |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 1776 | Asm->OutStreamer.SwitchSection(Asm->getObjFileLowering().getDataSection()); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1777 | EmitLabel("data_end", 0); |
| 1778 | |
| 1779 | // End text sections. |
| 1780 | for (unsigned i = 1, N = SectionMap.size(); i <= N; ++i) { |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 1781 | Asm->OutStreamer.SwitchSection(SectionMap[i]); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1782 | EmitLabel("section_end", i); |
| 1783 | } |
| 1784 | |
| 1785 | // Emit common frame information. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1786 | emitCommonDebugFrame(); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1787 | |
| 1788 | // Emit function debug frame information |
| 1789 | for (std::vector<FunctionDebugFrameInfo>::iterator I = DebugFrames.begin(), |
| 1790 | E = DebugFrames.end(); I != E; ++I) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1791 | emitFunctionDebugFrame(*I); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1792 | |
| 1793 | // Compute DIE offsets and sizes. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1794 | computeSizeAndOffsets(); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1795 | |
| 1796 | // Emit all the DIEs into a debug info section |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1797 | emitDebugInfo(); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1798 | |
| 1799 | // Corresponding abbreviations into a abbrev section. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1800 | emitAbbreviations(); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1801 | |
| 1802 | // Emit source line correspondence into a debug line section. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1803 | emitDebugLines(); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1804 | |
| 1805 | // Emit info into a debug pubnames section. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1806 | emitDebugPubNames(); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1807 | |
Devang Patel | 193f720 | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 1808 | // Emit info into a debug pubtypes section. |
| 1809 | emitDebugPubTypes(); |
| 1810 | |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1811 | // Emit info into a debug str section. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1812 | emitDebugStr(); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1813 | |
| 1814 | // Emit info into a debug loc section. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1815 | emitDebugLoc(); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1816 | |
| 1817 | // Emit info into a debug aranges section. |
| 1818 | EmitDebugARanges(); |
| 1819 | |
| 1820 | // Emit info into a debug ranges section. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1821 | emitDebugRanges(); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1822 | |
| 1823 | // Emit info into a debug macinfo section. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1824 | emitDebugMacInfo(); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1825 | |
| 1826 | // Emit inline info. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1827 | emitDebugInlineInfo(); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 1828 | |
| 1829 | if (TimePassesIsEnabled) |
| 1830 | DebugTimer->stopTimer(); |
| 1831 | } |
| 1832 | |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1833 | /// findAbstractVariable - Find abstract variable, if any, associated with Var. |
Jim Grosbach | 7ab38df | 2009-11-22 19:20:36 +0000 | [diff] [blame] | 1834 | DbgVariable *DwarfDebug::findAbstractVariable(DIVariable &Var, |
| 1835 | unsigned FrameIdx, |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1836 | DILocation &ScopeLoc) { |
| 1837 | |
| 1838 | DbgVariable *AbsDbgVariable = AbstractVariables.lookup(Var.getNode()); |
| 1839 | if (AbsDbgVariable) |
| 1840 | return AbsDbgVariable; |
| 1841 | |
| 1842 | DbgScope *Scope = AbstractScopes.lookup(ScopeLoc.getScope().getNode()); |
| 1843 | if (!Scope) |
| 1844 | return NULL; |
| 1845 | |
| 1846 | AbsDbgVariable = new DbgVariable(Var, FrameIdx); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1847 | Scope->addVariable(AbsDbgVariable); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1848 | AbstractVariables[Var.getNode()] = AbsDbgVariable; |
| 1849 | return AbsDbgVariable; |
| 1850 | } |
| 1851 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1852 | /// collectVariableInfo - Populate DbgScope entries with variables' info. |
| 1853 | void DwarfDebug::collectVariableInfo() { |
Devang Patel | ac1ceb3 | 2009-10-09 22:42:28 +0000 | [diff] [blame] | 1854 | if (!MMI) return; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1855 | |
Devang Patel | e717faa | 2009-10-06 01:26:37 +0000 | [diff] [blame] | 1856 | MachineModuleInfo::VariableDbgInfoMapTy &VMap = MMI->getVariableDbgInfo(); |
| 1857 | for (MachineModuleInfo::VariableDbgInfoMapTy::iterator VI = VMap.begin(), |
| 1858 | VE = VMap.end(); VI != VE; ++VI) { |
Devang Patel | ac1ceb3 | 2009-10-09 22:42:28 +0000 | [diff] [blame] | 1859 | MetadataBase *MB = VI->first; |
| 1860 | MDNode *Var = dyn_cast_or_null<MDNode>(MB); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1861 | if (!Var) continue; |
Devang Patel | eda3121 | 2009-10-08 18:48:03 +0000 | [diff] [blame] | 1862 | DIVariable DV (Var); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1863 | std::pair< unsigned, MDNode *> VP = VI->second; |
| 1864 | DILocation ScopeLoc(VP.second); |
| 1865 | |
| 1866 | DbgScope *Scope = |
| 1867 | ConcreteScopes.lookup(ScopeLoc.getOrigLocation().getNode()); |
| 1868 | if (!Scope) |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 1869 | Scope = DbgScopeMap.lookup(ScopeLoc.getScope().getNode()); |
Devang Patel | fb0ee43 | 2009-11-10 23:20:04 +0000 | [diff] [blame] | 1870 | // If variable scope is not found then skip this variable. |
| 1871 | if (!Scope) |
| 1872 | continue; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1873 | |
| 1874 | DbgVariable *RegVar = new DbgVariable(DV, VP.first); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1875 | Scope->addVariable(RegVar); |
Jim Grosbach | 7ab38df | 2009-11-22 19:20:36 +0000 | [diff] [blame] | 1876 | if (DbgVariable *AbsDbgVariable = findAbstractVariable(DV, VP.first, |
| 1877 | ScopeLoc)) |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1878 | RegVar->setAbstractVariable(AbsDbgVariable); |
Devang Patel | e717faa | 2009-10-06 01:26:37 +0000 | [diff] [blame] | 1879 | } |
| 1880 | } |
| 1881 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1882 | /// beginScope - Process beginning of a scope starting at Label. |
| 1883 | void DwarfDebug::beginScope(const MachineInstr *MI, unsigned Label) { |
Devang Patel | 0d20ac8 | 2009-10-06 01:50:42 +0000 | [diff] [blame] | 1884 | InsnToDbgScopeMapTy::iterator I = DbgScopeBeginMap.find(MI); |
| 1885 | if (I == DbgScopeBeginMap.end()) |
| 1886 | return; |
Dan Gohman | 277207e | 2009-11-23 21:30:55 +0000 | [diff] [blame] | 1887 | ScopeVector &SD = I->second; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1888 | for (ScopeVector::iterator SDI = SD.begin(), SDE = SD.end(); |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 1889 | SDI != SDE; ++SDI) |
Devang Patel | 0d20ac8 | 2009-10-06 01:50:42 +0000 | [diff] [blame] | 1890 | (*SDI)->setStartLabelID(Label); |
| 1891 | } |
| 1892 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1893 | /// endScope - Process end of a scope. |
| 1894 | void DwarfDebug::endScope(const MachineInstr *MI) { |
Devang Patel | 0d20ac8 | 2009-10-06 01:50:42 +0000 | [diff] [blame] | 1895 | InsnToDbgScopeMapTy::iterator I = DbgScopeEndMap.find(MI); |
Devang Patel | 8a4087d | 2009-10-06 03:15:38 +0000 | [diff] [blame] | 1896 | if (I == DbgScopeEndMap.end()) |
Devang Patel | 0d20ac8 | 2009-10-06 01:50:42 +0000 | [diff] [blame] | 1897 | return; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1898 | |
| 1899 | unsigned Label = MMI->NextLabelID(); |
| 1900 | Asm->printLabel(Label); |
| 1901 | |
Devang Patel | 0d20ac8 | 2009-10-06 01:50:42 +0000 | [diff] [blame] | 1902 | SmallVector<DbgScope *, 2> &SD = I->second; |
| 1903 | for (SmallVector<DbgScope *, 2>::iterator SDI = SD.begin(), SDE = SD.end(); |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 1904 | SDI != SDE; ++SDI) |
Devang Patel | 0d20ac8 | 2009-10-06 01:50:42 +0000 | [diff] [blame] | 1905 | (*SDI)->setEndLabelID(Label); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1906 | return; |
| 1907 | } |
| 1908 | |
| 1909 | /// createDbgScope - Create DbgScope for the scope. |
| 1910 | void DwarfDebug::createDbgScope(MDNode *Scope, MDNode *InlinedAt) { |
| 1911 | |
| 1912 | if (!InlinedAt) { |
| 1913 | DbgScope *WScope = DbgScopeMap.lookup(Scope); |
| 1914 | if (WScope) |
| 1915 | return; |
| 1916 | WScope = new DbgScope(NULL, DIDescriptor(Scope), NULL); |
| 1917 | DbgScopeMap.insert(std::make_pair(Scope, WScope)); |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 1918 | if (DIDescriptor(Scope).isLexicalBlock()) |
Devang Patel | 2f105c6 | 2009-11-11 00:18:40 +0000 | [diff] [blame] | 1919 | createDbgScope(DILexicalBlock(Scope).getContext().getNode(), NULL); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1920 | return; |
| 1921 | } |
| 1922 | |
| 1923 | DbgScope *WScope = DbgScopeMap.lookup(InlinedAt); |
| 1924 | if (WScope) |
| 1925 | return; |
| 1926 | |
| 1927 | WScope = new DbgScope(NULL, DIDescriptor(Scope), InlinedAt); |
| 1928 | DbgScopeMap.insert(std::make_pair(InlinedAt, WScope)); |
| 1929 | DILocation DL(InlinedAt); |
| 1930 | createDbgScope(DL.getScope().getNode(), DL.getOrigLocation().getNode()); |
Devang Patel | 0d20ac8 | 2009-10-06 01:50:42 +0000 | [diff] [blame] | 1931 | } |
| 1932 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1933 | /// extractScopeInformation - Scan machine instructions in this function |
Devang Patel | af9e847 | 2009-10-01 20:31:14 +0000 | [diff] [blame] | 1934 | /// and collect DbgScopes. Return true, if atleast one scope was found. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1935 | bool DwarfDebug::extractScopeInformation(MachineFunction *MF) { |
Devang Patel | af9e847 | 2009-10-01 20:31:14 +0000 | [diff] [blame] | 1936 | // If scope information was extracted using .dbg intrinsics then there is not |
| 1937 | // any need to extract these information by scanning each instruction. |
| 1938 | if (!DbgScopeMap.empty()) |
| 1939 | return false; |
| 1940 | |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1941 | // Scan each instruction and create scopes. First build working set of scopes. |
Devang Patel | af9e847 | 2009-10-01 20:31:14 +0000 | [diff] [blame] | 1942 | for (MachineFunction::const_iterator I = MF->begin(), E = MF->end(); |
| 1943 | I != E; ++I) { |
| 1944 | for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end(); |
| 1945 | II != IE; ++II) { |
| 1946 | const MachineInstr *MInsn = II; |
| 1947 | DebugLoc DL = MInsn->getDebugLoc(); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1948 | if (DL.isUnknown()) continue; |
Devang Patel | af9e847 | 2009-10-01 20:31:14 +0000 | [diff] [blame] | 1949 | DebugLocTuple DLT = MF->getDebugLocTuple(DL); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1950 | if (!DLT.Scope) continue; |
Devang Patel | af9e847 | 2009-10-01 20:31:14 +0000 | [diff] [blame] | 1951 | // There is no need to create another DIE for compile unit. For all |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 1952 | // other scopes, create one DbgScope now. This will be translated |
Devang Patel | af9e847 | 2009-10-01 20:31:14 +0000 | [diff] [blame] | 1953 | // into a scope DIE at the end. |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1954 | if (DIDescriptor(DLT.Scope).isCompileUnit()) continue; |
| 1955 | createDbgScope(DLT.Scope, DLT.InlinedAtLoc); |
| 1956 | } |
| 1957 | } |
| 1958 | |
| 1959 | |
| 1960 | // Build scope hierarchy using working set of scopes. |
| 1961 | for (MachineFunction::const_iterator I = MF->begin(), E = MF->end(); |
| 1962 | I != E; ++I) { |
| 1963 | for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end(); |
| 1964 | II != IE; ++II) { |
| 1965 | const MachineInstr *MInsn = II; |
| 1966 | DebugLoc DL = MInsn->getDebugLoc(); |
| 1967 | if (DL.isUnknown()) continue; |
| 1968 | DebugLocTuple DLT = MF->getDebugLocTuple(DL); |
| 1969 | if (!DLT.Scope) continue; |
| 1970 | // There is no need to create another DIE for compile unit. For all |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 1971 | // other scopes, create one DbgScope now. This will be translated |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1972 | // into a scope DIE at the end. |
| 1973 | if (DIDescriptor(DLT.Scope).isCompileUnit()) continue; |
| 1974 | DbgScope *Scope = getUpdatedDbgScope(DLT.Scope, MInsn, DLT.InlinedAtLoc); |
| 1975 | Scope->setLastInsn(MInsn); |
Devang Patel | af9e847 | 2009-10-01 20:31:14 +0000 | [diff] [blame] | 1976 | } |
| 1977 | } |
| 1978 | |
| 1979 | // If a scope's last instruction is not set then use its child scope's |
| 1980 | // last instruction as this scope's last instrunction. |
Devang Patel | bdf45cb | 2009-10-27 20:47:17 +0000 | [diff] [blame] | 1981 | for (ValueMap<MDNode *, DbgScope *>::iterator DI = DbgScopeMap.begin(), |
Devang Patel | af9e847 | 2009-10-01 20:31:14 +0000 | [diff] [blame] | 1982 | DE = DbgScopeMap.end(); DI != DE; ++DI) { |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1983 | if (DI->second->isAbstractScope()) |
| 1984 | continue; |
Devang Patel | af9e847 | 2009-10-01 20:31:14 +0000 | [diff] [blame] | 1985 | assert (DI->second->getFirstInsn() && "Invalid first instruction!"); |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 1986 | DI->second->fixInstructionMarkers(); |
Devang Patel | af9e847 | 2009-10-01 20:31:14 +0000 | [diff] [blame] | 1987 | assert (DI->second->getLastInsn() && "Invalid last instruction!"); |
| 1988 | } |
| 1989 | |
| 1990 | // Each scope has first instruction and last instruction to mark beginning |
| 1991 | // and end of a scope respectively. Create an inverse map that list scopes |
| 1992 | // starts (and ends) with an instruction. One instruction may start (or end) |
| 1993 | // multiple scopes. |
Devang Patel | bdf45cb | 2009-10-27 20:47:17 +0000 | [diff] [blame] | 1994 | for (ValueMap<MDNode *, DbgScope *>::iterator DI = DbgScopeMap.begin(), |
Devang Patel | af9e847 | 2009-10-01 20:31:14 +0000 | [diff] [blame] | 1995 | DE = DbgScopeMap.end(); DI != DE; ++DI) { |
| 1996 | DbgScope *S = DI->second; |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 1997 | if (S->isAbstractScope()) |
| 1998 | continue; |
Devang Patel | af9e847 | 2009-10-01 20:31:14 +0000 | [diff] [blame] | 1999 | const MachineInstr *MI = S->getFirstInsn(); |
| 2000 | assert (MI && "DbgScope does not have first instruction!"); |
| 2001 | |
| 2002 | InsnToDbgScopeMapTy::iterator IDI = DbgScopeBeginMap.find(MI); |
| 2003 | if (IDI != DbgScopeBeginMap.end()) |
| 2004 | IDI->second.push_back(S); |
| 2005 | else |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 2006 | DbgScopeBeginMap[MI].push_back(S); |
Devang Patel | af9e847 | 2009-10-01 20:31:14 +0000 | [diff] [blame] | 2007 | |
| 2008 | MI = S->getLastInsn(); |
| 2009 | assert (MI && "DbgScope does not have last instruction!"); |
| 2010 | IDI = DbgScopeEndMap.find(MI); |
| 2011 | if (IDI != DbgScopeEndMap.end()) |
| 2012 | IDI->second.push_back(S); |
| 2013 | else |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 2014 | DbgScopeEndMap[MI].push_back(S); |
Devang Patel | af9e847 | 2009-10-01 20:31:14 +0000 | [diff] [blame] | 2015 | } |
| 2016 | |
| 2017 | return !DbgScopeMap.empty(); |
| 2018 | } |
| 2019 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2020 | /// beginFunction - Gather pre-function debug information. Assumes being |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2021 | /// emitted immediately after the function entry point. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2022 | void DwarfDebug::beginFunction(MachineFunction *MF) { |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2023 | this->MF = MF; |
| 2024 | |
| 2025 | if (!ShouldEmitDwarfDebug()) return; |
| 2026 | |
| 2027 | if (TimePassesIsEnabled) |
| 2028 | DebugTimer->startTimer(); |
| 2029 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2030 | if (!extractScopeInformation(MF)) |
Devang Patel | 60b35bd | 2009-10-06 18:37:31 +0000 | [diff] [blame] | 2031 | return; |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2032 | |
| 2033 | collectVariableInfo(); |
Devang Patel | 60b35bd | 2009-10-06 18:37:31 +0000 | [diff] [blame] | 2034 | |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2035 | // Begin accumulating function debug information. |
| 2036 | MMI->BeginFunction(MF); |
| 2037 | |
| 2038 | // Assumes in correct section after the entry point. |
| 2039 | EmitLabel("func_begin", ++SubprogramCount); |
| 2040 | |
| 2041 | // Emit label for the implicitly defined dbg.stoppoint at the start of the |
| 2042 | // function. |
Devang Patel | ac1ceb3 | 2009-10-09 22:42:28 +0000 | [diff] [blame] | 2043 | DebugLoc FDL = MF->getDefaultDebugLoc(); |
| 2044 | if (!FDL.isUnknown()) { |
| 2045 | DebugLocTuple DLT = MF->getDebugLocTuple(FDL); |
| 2046 | unsigned LabelID = 0; |
Devang Patel | 1619dc3 | 2009-10-13 23:28:53 +0000 | [diff] [blame] | 2047 | DISubprogram SP = getDISubprogram(DLT.Scope); |
Devang Patel | ac1ceb3 | 2009-10-09 22:42:28 +0000 | [diff] [blame] | 2048 | if (!SP.isNull()) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2049 | LabelID = recordSourceLine(SP.getLineNumber(), 0, DLT.Scope); |
Devang Patel | ac1ceb3 | 2009-10-09 22:42:28 +0000 | [diff] [blame] | 2050 | else |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2051 | LabelID = recordSourceLine(DLT.Line, DLT.Col, DLT.Scope); |
Devang Patel | ac1ceb3 | 2009-10-09 22:42:28 +0000 | [diff] [blame] | 2052 | Asm->printLabel(LabelID); |
| 2053 | O << '\n'; |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2054 | } |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2055 | if (TimePassesIsEnabled) |
| 2056 | DebugTimer->stopTimer(); |
| 2057 | } |
| 2058 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2059 | /// endFunction - Gather and emit post-function debug information. |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2060 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2061 | void DwarfDebug::endFunction(MachineFunction *MF) { |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2062 | if (!ShouldEmitDwarfDebug()) return; |
| 2063 | |
| 2064 | if (TimePassesIsEnabled) |
| 2065 | DebugTimer->startTimer(); |
| 2066 | |
Devang Patel | ac1ceb3 | 2009-10-09 22:42:28 +0000 | [diff] [blame] | 2067 | if (DbgScopeMap.empty()) |
| 2068 | return; |
Devang Patel | 70d75ca | 2009-11-12 19:02:56 +0000 | [diff] [blame] | 2069 | |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2070 | // Define end label for subprogram. |
| 2071 | EmitLabel("func_end", SubprogramCount); |
| 2072 | |
| 2073 | // Get function line info. |
| 2074 | if (!Lines.empty()) { |
| 2075 | // Get section line info. |
Chris Lattner | 290c2f5 | 2009-08-03 23:20:21 +0000 | [diff] [blame] | 2076 | unsigned ID = SectionMap.insert(Asm->getCurrentSection()); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2077 | if (SectionSourceLines.size() < ID) SectionSourceLines.resize(ID); |
| 2078 | std::vector<SrcLineInfo> &SectionLineInfos = SectionSourceLines[ID-1]; |
| 2079 | // Append the function info to section info. |
| 2080 | SectionLineInfos.insert(SectionLineInfos.end(), |
| 2081 | Lines.begin(), Lines.end()); |
| 2082 | } |
| 2083 | |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 2084 | // Construct abstract scopes. |
| 2085 | for (SmallVector<DbgScope *, 4>::iterator AI = AbstractScopesList.begin(), |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 2086 | AE = AbstractScopesList.end(); AI != AE; ++AI) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2087 | constructScopeDIE(*AI); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2088 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2089 | constructScopeDIE(CurrentFnDbgScope); |
Devang Patel | 70d75ca | 2009-11-12 19:02:56 +0000 | [diff] [blame] | 2090 | |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2091 | DebugFrames.push_back(FunctionDebugFrameInfo(SubprogramCount, |
| 2092 | MMI->getFrameMoves())); |
| 2093 | |
| 2094 | // Clear debug info |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 2095 | if (CurrentFnDbgScope) { |
| 2096 | CurrentFnDbgScope = NULL; |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2097 | DbgScopeMap.clear(); |
Devang Patel | af9e847 | 2009-10-01 20:31:14 +0000 | [diff] [blame] | 2098 | DbgScopeBeginMap.clear(); |
| 2099 | DbgScopeEndMap.clear(); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 2100 | ConcreteScopes.clear(); |
| 2101 | AbstractScopesList.clear(); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2102 | } |
| 2103 | |
| 2104 | Lines.clear(); |
| 2105 | |
| 2106 | if (TimePassesIsEnabled) |
| 2107 | DebugTimer->stopTimer(); |
| 2108 | } |
| 2109 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2110 | /// recordSourceLine - Records location information and associates it with a |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2111 | /// label. Returns a unique label ID used to generate a label and provide |
| 2112 | /// correspondence to the source line list. |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 2113 | unsigned DwarfDebug::recordSourceLine(unsigned Line, unsigned Col, |
Devang Patel | f84548d | 2009-10-05 18:03:19 +0000 | [diff] [blame] | 2114 | MDNode *S) { |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 2115 | if (!MMI) |
| 2116 | return 0; |
| 2117 | |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2118 | if (TimePassesIsEnabled) |
| 2119 | DebugTimer->startTimer(); |
| 2120 | |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 2121 | StringRef Dir; |
| 2122 | StringRef Fn; |
Devang Patel | f84548d | 2009-10-05 18:03:19 +0000 | [diff] [blame] | 2123 | |
| 2124 | DIDescriptor Scope(S); |
| 2125 | if (Scope.isCompileUnit()) { |
| 2126 | DICompileUnit CU(S); |
| 2127 | Dir = CU.getDirectory(); |
| 2128 | Fn = CU.getFilename(); |
| 2129 | } else if (Scope.isSubprogram()) { |
| 2130 | DISubprogram SP(S); |
| 2131 | Dir = SP.getDirectory(); |
| 2132 | Fn = SP.getFilename(); |
| 2133 | } else if (Scope.isLexicalBlock()) { |
| 2134 | DILexicalBlock DB(S); |
| 2135 | Dir = DB.getDirectory(); |
| 2136 | Fn = DB.getFilename(); |
| 2137 | } else |
| 2138 | assert (0 && "Unexpected scope info"); |
| 2139 | |
| 2140 | unsigned Src = GetOrCreateSourceID(Dir, Fn); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2141 | unsigned ID = MMI->NextLabelID(); |
| 2142 | Lines.push_back(SrcLineInfo(Line, Col, Src, ID)); |
| 2143 | |
| 2144 | if (TimePassesIsEnabled) |
| 2145 | DebugTimer->stopTimer(); |
| 2146 | |
| 2147 | return ID; |
| 2148 | } |
| 2149 | |
| 2150 | /// getOrCreateSourceID - Public version of GetOrCreateSourceID. This can be |
| 2151 | /// timed. Look up the source id with the given directory and source file |
| 2152 | /// names. If none currently exists, create a new id and insert it in the |
| 2153 | /// SourceIds map. This can update DirectoryNames and SourceFileNames maps as |
| 2154 | /// well. |
| 2155 | unsigned DwarfDebug::getOrCreateSourceID(const std::string &DirName, |
| 2156 | const std::string &FileName) { |
| 2157 | if (TimePassesIsEnabled) |
| 2158 | DebugTimer->startTimer(); |
| 2159 | |
Devang Patel | 5ccdd10 | 2009-09-29 18:40:58 +0000 | [diff] [blame] | 2160 | unsigned SrcId = GetOrCreateSourceID(DirName.c_str(), FileName.c_str()); |
Bill Wendling | f0fb987 | 2009-05-20 23:19:06 +0000 | [diff] [blame] | 2161 | |
| 2162 | if (TimePassesIsEnabled) |
| 2163 | DebugTimer->stopTimer(); |
| 2164 | |
| 2165 | return SrcId; |
| 2166 | } |
| 2167 | |
Bill Wendling | 829e67b | 2009-05-20 23:22:40 +0000 | [diff] [blame] | 2168 | //===----------------------------------------------------------------------===// |
| 2169 | // Emit Methods |
| 2170 | //===----------------------------------------------------------------------===// |
| 2171 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2172 | /// computeSizeAndOffset - Compute the size and offset of a DIE. |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2173 | /// |
Jim Grosbach | 7ab38df | 2009-11-22 19:20:36 +0000 | [diff] [blame] | 2174 | unsigned |
| 2175 | DwarfDebug::computeSizeAndOffset(DIE *Die, unsigned Offset, bool Last) { |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2176 | // Get the children. |
| 2177 | const std::vector<DIE *> &Children = Die->getChildren(); |
| 2178 | |
| 2179 | // If not last sibling and has children then add sibling offset attribute. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2180 | if (!Last && !Children.empty()) Die->addSiblingOffset(); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2181 | |
| 2182 | // Record the abbreviation. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2183 | assignAbbrevNumber(Die->getAbbrev()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2184 | |
| 2185 | // Get the abbreviation for this DIE. |
| 2186 | unsigned AbbrevNumber = Die->getAbbrevNumber(); |
| 2187 | const DIEAbbrev *Abbrev = Abbreviations[AbbrevNumber - 1]; |
| 2188 | |
| 2189 | // Set DIE offset |
| 2190 | Die->setOffset(Offset); |
| 2191 | |
| 2192 | // Start the size with the size of abbreviation code. |
Chris Lattner | af76e59 | 2009-08-22 20:48:53 +0000 | [diff] [blame] | 2193 | Offset += MCAsmInfo::getULEB128Size(AbbrevNumber); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2194 | |
| 2195 | const SmallVector<DIEValue*, 32> &Values = Die->getValues(); |
| 2196 | const SmallVector<DIEAbbrevData, 8> &AbbrevData = Abbrev->getData(); |
| 2197 | |
| 2198 | // Size the DIE attribute values. |
| 2199 | for (unsigned i = 0, N = Values.size(); i < N; ++i) |
| 2200 | // Size attribute value. |
| 2201 | Offset += Values[i]->SizeOf(TD, AbbrevData[i].getForm()); |
| 2202 | |
| 2203 | // Size the DIE children if any. |
| 2204 | if (!Children.empty()) { |
| 2205 | assert(Abbrev->getChildrenFlag() == dwarf::DW_CHILDREN_yes && |
| 2206 | "Children flag not set"); |
| 2207 | |
| 2208 | for (unsigned j = 0, M = Children.size(); j < M; ++j) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2209 | Offset = computeSizeAndOffset(Children[j], Offset, (j + 1) == M); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2210 | |
| 2211 | // End of children marker. |
| 2212 | Offset += sizeof(int8_t); |
| 2213 | } |
| 2214 | |
| 2215 | Die->setSize(Offset - Die->getOffset()); |
| 2216 | return Offset; |
| 2217 | } |
| 2218 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2219 | /// computeSizeAndOffsets - Compute the size and offset of all the DIEs. |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2220 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2221 | void DwarfDebug::computeSizeAndOffsets() { |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2222 | // Compute size of compile unit header. |
| 2223 | static unsigned Offset = |
| 2224 | sizeof(int32_t) + // Length of Compilation Unit Info |
| 2225 | sizeof(int16_t) + // DWARF version number |
| 2226 | sizeof(int32_t) + // Offset Into Abbrev. Section |
| 2227 | sizeof(int8_t); // Pointer Size (in bytes) |
| 2228 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2229 | computeSizeAndOffset(ModuleCU->getCUDie(), Offset, true); |
Devang Patel | 1dbc771 | 2009-06-29 20:45:18 +0000 | [diff] [blame] | 2230 | CompileUnitOffsets[ModuleCU] = 0; |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2231 | } |
| 2232 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2233 | /// emitInitial - Emit initial Dwarf declarations. This is necessary for cc |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2234 | /// tools to recognize the object file contains Dwarf information. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2235 | void DwarfDebug::emitInitial() { |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2236 | // Check to see if we already emitted intial headers. |
| 2237 | if (didInitial) return; |
| 2238 | didInitial = true; |
| 2239 | |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 2240 | const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering(); |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 2241 | |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2242 | // Dwarf sections base addresses. |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 2243 | if (MAI->doesDwarfRequireFrameSection()) { |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 2244 | Asm->OutStreamer.SwitchSection(TLOF.getDwarfFrameSection()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2245 | EmitLabel("section_debug_frame", 0); |
| 2246 | } |
| 2247 | |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 2248 | Asm->OutStreamer.SwitchSection(TLOF.getDwarfInfoSection()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2249 | EmitLabel("section_info", 0); |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 2250 | Asm->OutStreamer.SwitchSection(TLOF.getDwarfAbbrevSection()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2251 | EmitLabel("section_abbrev", 0); |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 2252 | Asm->OutStreamer.SwitchSection(TLOF.getDwarfARangesSection()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2253 | EmitLabel("section_aranges", 0); |
| 2254 | |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 2255 | if (const MCSection *LineInfoDirective = TLOF.getDwarfMacroInfoSection()) { |
| 2256 | Asm->OutStreamer.SwitchSection(LineInfoDirective); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2257 | EmitLabel("section_macinfo", 0); |
| 2258 | } |
| 2259 | |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 2260 | Asm->OutStreamer.SwitchSection(TLOF.getDwarfLineSection()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2261 | EmitLabel("section_line", 0); |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 2262 | Asm->OutStreamer.SwitchSection(TLOF.getDwarfLocSection()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2263 | EmitLabel("section_loc", 0); |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 2264 | Asm->OutStreamer.SwitchSection(TLOF.getDwarfPubNamesSection()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2265 | EmitLabel("section_pubnames", 0); |
Devang Patel | 193f720 | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 2266 | Asm->OutStreamer.SwitchSection(TLOF.getDwarfPubTypesSection()); |
| 2267 | EmitLabel("section_pubtypes", 0); |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 2268 | Asm->OutStreamer.SwitchSection(TLOF.getDwarfStrSection()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2269 | EmitLabel("section_str", 0); |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 2270 | Asm->OutStreamer.SwitchSection(TLOF.getDwarfRangesSection()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2271 | EmitLabel("section_ranges", 0); |
| 2272 | |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 2273 | Asm->OutStreamer.SwitchSection(TLOF.getTextSection()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2274 | EmitLabel("text_begin", 0); |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 2275 | Asm->OutStreamer.SwitchSection(TLOF.getDataSection()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2276 | EmitLabel("data_begin", 0); |
| 2277 | } |
| 2278 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2279 | /// emitDIE - Recusively Emits a debug information entry. |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2280 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2281 | void DwarfDebug::emitDIE(DIE *Die) { |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2282 | // Get the abbreviation for this DIE. |
| 2283 | unsigned AbbrevNumber = Die->getAbbrevNumber(); |
| 2284 | const DIEAbbrev *Abbrev = Abbreviations[AbbrevNumber - 1]; |
| 2285 | |
| 2286 | Asm->EOL(); |
| 2287 | |
| 2288 | // Emit the code (index) for the abbreviation. |
| 2289 | Asm->EmitULEB128Bytes(AbbrevNumber); |
| 2290 | |
| 2291 | if (Asm->isVerbose()) |
| 2292 | Asm->EOL(std::string("Abbrev [" + |
| 2293 | utostr(AbbrevNumber) + |
| 2294 | "] 0x" + utohexstr(Die->getOffset()) + |
| 2295 | ":0x" + utohexstr(Die->getSize()) + " " + |
| 2296 | dwarf::TagString(Abbrev->getTag()))); |
| 2297 | else |
| 2298 | Asm->EOL(); |
| 2299 | |
| 2300 | SmallVector<DIEValue*, 32> &Values = Die->getValues(); |
| 2301 | const SmallVector<DIEAbbrevData, 8> &AbbrevData = Abbrev->getData(); |
| 2302 | |
| 2303 | // Emit the DIE attribute values. |
| 2304 | for (unsigned i = 0, N = Values.size(); i < N; ++i) { |
| 2305 | unsigned Attr = AbbrevData[i].getAttribute(); |
| 2306 | unsigned Form = AbbrevData[i].getForm(); |
| 2307 | assert(Form && "Too many attributes for DIE (check abbreviation)"); |
| 2308 | |
| 2309 | switch (Attr) { |
| 2310 | case dwarf::DW_AT_sibling: |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2311 | Asm->EmitInt32(Die->getSiblingOffset()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2312 | break; |
| 2313 | case dwarf::DW_AT_abstract_origin: { |
| 2314 | DIEEntry *E = cast<DIEEntry>(Values[i]); |
| 2315 | DIE *Origin = E->getEntry(); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 2316 | unsigned Addr = Origin->getOffset(); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2317 | Asm->EmitInt32(Addr); |
| 2318 | break; |
| 2319 | } |
| 2320 | default: |
| 2321 | // Emit an attribute using the defined form. |
| 2322 | Values[i]->EmitValue(this, Form); |
| 2323 | break; |
| 2324 | } |
| 2325 | |
| 2326 | Asm->EOL(dwarf::AttributeString(Attr)); |
| 2327 | } |
| 2328 | |
| 2329 | // Emit the DIE children if any. |
| 2330 | if (Abbrev->getChildrenFlag() == dwarf::DW_CHILDREN_yes) { |
| 2331 | const std::vector<DIE *> &Children = Die->getChildren(); |
| 2332 | |
| 2333 | for (unsigned j = 0, M = Children.size(); j < M; ++j) |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2334 | emitDIE(Children[j]); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2335 | |
| 2336 | Asm->EmitInt8(0); Asm->EOL("End Of Children Mark"); |
| 2337 | } |
| 2338 | } |
| 2339 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2340 | /// emitDebugInfo / emitDebugInfoPerCU - Emit the debug info section. |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2341 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2342 | void DwarfDebug::emitDebugInfoPerCU(CompileUnit *Unit) { |
Devang Patel | 017d121 | 2009-11-20 21:37:22 +0000 | [diff] [blame] | 2343 | DIE *Die = Unit->getCUDie(); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2344 | |
| 2345 | // Emit the compile units header. |
| 2346 | EmitLabel("info_begin", Unit->getID()); |
| 2347 | |
| 2348 | // Emit size of content not including length itself |
| 2349 | unsigned ContentSize = Die->getSize() + |
| 2350 | sizeof(int16_t) + // DWARF version number |
| 2351 | sizeof(int32_t) + // Offset Into Abbrev. Section |
| 2352 | sizeof(int8_t) + // Pointer Size (in bytes) |
| 2353 | sizeof(int32_t); // FIXME - extra pad for gdb bug. |
| 2354 | |
| 2355 | Asm->EmitInt32(ContentSize); Asm->EOL("Length of Compilation Unit Info"); |
| 2356 | Asm->EmitInt16(dwarf::DWARF_VERSION); Asm->EOL("DWARF version number"); |
| 2357 | EmitSectionOffset("abbrev_begin", "section_abbrev", 0, 0, true, false); |
| 2358 | Asm->EOL("Offset Into Abbrev. Section"); |
| 2359 | Asm->EmitInt8(TD->getPointerSize()); Asm->EOL("Address Size (in bytes)"); |
| 2360 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2361 | emitDIE(Die); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2362 | // FIXME - extra padding for gdb bug. |
| 2363 | Asm->EmitInt8(0); Asm->EOL("Extra Pad For GDB"); |
| 2364 | Asm->EmitInt8(0); Asm->EOL("Extra Pad For GDB"); |
| 2365 | Asm->EmitInt8(0); Asm->EOL("Extra Pad For GDB"); |
| 2366 | Asm->EmitInt8(0); Asm->EOL("Extra Pad For GDB"); |
| 2367 | EmitLabel("info_end", Unit->getID()); |
| 2368 | |
| 2369 | Asm->EOL(); |
| 2370 | } |
| 2371 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2372 | void DwarfDebug::emitDebugInfo() { |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2373 | // Start debug info section. |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 2374 | Asm->OutStreamer.SwitchSection( |
| 2375 | Asm->getObjFileLowering().getDwarfInfoSection()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2376 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2377 | emitDebugInfoPerCU(ModuleCU); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2378 | } |
| 2379 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2380 | /// emitAbbreviations - Emit the abbreviation section. |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2381 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2382 | void DwarfDebug::emitAbbreviations() const { |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2383 | // Check to see if it is worth the effort. |
| 2384 | if (!Abbreviations.empty()) { |
| 2385 | // Start the debug abbrev section. |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 2386 | Asm->OutStreamer.SwitchSection( |
| 2387 | Asm->getObjFileLowering().getDwarfAbbrevSection()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2388 | |
| 2389 | EmitLabel("abbrev_begin", 0); |
| 2390 | |
| 2391 | // For each abbrevation. |
| 2392 | for (unsigned i = 0, N = Abbreviations.size(); i < N; ++i) { |
| 2393 | // Get abbreviation data |
| 2394 | const DIEAbbrev *Abbrev = Abbreviations[i]; |
| 2395 | |
| 2396 | // Emit the abbrevations code (base 1 index.) |
| 2397 | Asm->EmitULEB128Bytes(Abbrev->getNumber()); |
| 2398 | Asm->EOL("Abbreviation Code"); |
| 2399 | |
| 2400 | // Emit the abbreviations data. |
| 2401 | Abbrev->Emit(Asm); |
| 2402 | |
| 2403 | Asm->EOL(); |
| 2404 | } |
| 2405 | |
| 2406 | // Mark end of abbreviations. |
| 2407 | Asm->EmitULEB128Bytes(0); Asm->EOL("EOM(3)"); |
| 2408 | |
| 2409 | EmitLabel("abbrev_end", 0); |
| 2410 | Asm->EOL(); |
| 2411 | } |
| 2412 | } |
| 2413 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2414 | /// emitEndOfLineMatrix - Emit the last address of the section and the end of |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2415 | /// the line matrix. |
| 2416 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2417 | void DwarfDebug::emitEndOfLineMatrix(unsigned SectionEnd) { |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2418 | // Define last address of section. |
| 2419 | Asm->EmitInt8(0); Asm->EOL("Extended Op"); |
| 2420 | Asm->EmitInt8(TD->getPointerSize() + 1); Asm->EOL("Op size"); |
| 2421 | Asm->EmitInt8(dwarf::DW_LNE_set_address); Asm->EOL("DW_LNE_set_address"); |
| 2422 | EmitReference("section_end", SectionEnd); Asm->EOL("Section end label"); |
| 2423 | |
| 2424 | // Mark end of matrix. |
| 2425 | Asm->EmitInt8(0); Asm->EOL("DW_LNE_end_sequence"); |
| 2426 | Asm->EmitULEB128Bytes(1); Asm->EOL(); |
| 2427 | Asm->EmitInt8(1); Asm->EOL(); |
| 2428 | } |
| 2429 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2430 | /// emitDebugLines - Emit source line information. |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2431 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2432 | void DwarfDebug::emitDebugLines() { |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2433 | // If the target is using .loc/.file, the assembler will be emitting the |
| 2434 | // .debug_line table automatically. |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 2435 | if (MAI->hasDotLocAndDotFile()) |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2436 | return; |
| 2437 | |
| 2438 | // Minimum line delta, thus ranging from -10..(255-10). |
| 2439 | const int MinLineDelta = -(dwarf::DW_LNS_fixed_advance_pc + 1); |
| 2440 | // Maximum line delta, thus ranging from -10..(255-10). |
| 2441 | const int MaxLineDelta = 255 + MinLineDelta; |
| 2442 | |
| 2443 | // Start the dwarf line section. |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 2444 | Asm->OutStreamer.SwitchSection( |
| 2445 | Asm->getObjFileLowering().getDwarfLineSection()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2446 | |
| 2447 | // Construct the section header. |
| 2448 | EmitDifference("line_end", 0, "line_begin", 0, true); |
| 2449 | Asm->EOL("Length of Source Line Info"); |
| 2450 | EmitLabel("line_begin", 0); |
| 2451 | |
| 2452 | Asm->EmitInt16(dwarf::DWARF_VERSION); Asm->EOL("DWARF version number"); |
| 2453 | |
| 2454 | EmitDifference("line_prolog_end", 0, "line_prolog_begin", 0, true); |
| 2455 | Asm->EOL("Prolog Length"); |
| 2456 | EmitLabel("line_prolog_begin", 0); |
| 2457 | |
| 2458 | Asm->EmitInt8(1); Asm->EOL("Minimum Instruction Length"); |
| 2459 | |
| 2460 | Asm->EmitInt8(1); Asm->EOL("Default is_stmt_start flag"); |
| 2461 | |
| 2462 | Asm->EmitInt8(MinLineDelta); Asm->EOL("Line Base Value (Special Opcodes)"); |
| 2463 | |
| 2464 | Asm->EmitInt8(MaxLineDelta); Asm->EOL("Line Range Value (Special Opcodes)"); |
| 2465 | |
| 2466 | Asm->EmitInt8(-MinLineDelta); Asm->EOL("Special Opcode Base"); |
| 2467 | |
| 2468 | // Line number standard opcode encodings argument count |
| 2469 | Asm->EmitInt8(0); Asm->EOL("DW_LNS_copy arg count"); |
| 2470 | Asm->EmitInt8(1); Asm->EOL("DW_LNS_advance_pc arg count"); |
| 2471 | Asm->EmitInt8(1); Asm->EOL("DW_LNS_advance_line arg count"); |
| 2472 | Asm->EmitInt8(1); Asm->EOL("DW_LNS_set_file arg count"); |
| 2473 | Asm->EmitInt8(1); Asm->EOL("DW_LNS_set_column arg count"); |
| 2474 | Asm->EmitInt8(0); Asm->EOL("DW_LNS_negate_stmt arg count"); |
| 2475 | Asm->EmitInt8(0); Asm->EOL("DW_LNS_set_basic_block arg count"); |
| 2476 | Asm->EmitInt8(0); Asm->EOL("DW_LNS_const_add_pc arg count"); |
| 2477 | Asm->EmitInt8(1); Asm->EOL("DW_LNS_fixed_advance_pc arg count"); |
| 2478 | |
| 2479 | // Emit directories. |
| 2480 | for (unsigned DI = 1, DE = getNumSourceDirectories()+1; DI != DE; ++DI) { |
| 2481 | Asm->EmitString(getSourceDirectoryName(DI)); |
| 2482 | Asm->EOL("Directory"); |
| 2483 | } |
| 2484 | |
| 2485 | Asm->EmitInt8(0); Asm->EOL("End of directories"); |
| 2486 | |
| 2487 | // Emit files. |
| 2488 | for (unsigned SI = 1, SE = getNumSourceIds()+1; SI != SE; ++SI) { |
| 2489 | // Remember source id starts at 1. |
| 2490 | std::pair<unsigned, unsigned> Id = getSourceDirectoryAndFileIds(SI); |
| 2491 | Asm->EmitString(getSourceFileName(Id.second)); |
| 2492 | Asm->EOL("Source"); |
| 2493 | Asm->EmitULEB128Bytes(Id.first); |
| 2494 | Asm->EOL("Directory #"); |
| 2495 | Asm->EmitULEB128Bytes(0); |
| 2496 | Asm->EOL("Mod date"); |
| 2497 | Asm->EmitULEB128Bytes(0); |
| 2498 | Asm->EOL("File size"); |
| 2499 | } |
| 2500 | |
| 2501 | Asm->EmitInt8(0); Asm->EOL("End of files"); |
| 2502 | |
| 2503 | EmitLabel("line_prolog_end", 0); |
| 2504 | |
| 2505 | // A sequence for each text section. |
| 2506 | unsigned SecSrcLinesSize = SectionSourceLines.size(); |
| 2507 | |
| 2508 | for (unsigned j = 0; j < SecSrcLinesSize; ++j) { |
| 2509 | // Isolate current sections line info. |
| 2510 | const std::vector<SrcLineInfo> &LineInfos = SectionSourceLines[j]; |
| 2511 | |
Chris Lattner | 93b6db3 | 2009-08-08 23:39:42 +0000 | [diff] [blame] | 2512 | /*if (Asm->isVerbose()) { |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 2513 | const MCSection *S = SectionMap[j + 1]; |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 2514 | O << '\t' << MAI->getCommentString() << " Section" |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2515 | << S->getName() << '\n'; |
Chris Lattner | 93b6db3 | 2009-08-08 23:39:42 +0000 | [diff] [blame] | 2516 | }*/ |
| 2517 | Asm->EOL(); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2518 | |
| 2519 | // Dwarf assumes we start with first line of first source file. |
| 2520 | unsigned Source = 1; |
| 2521 | unsigned Line = 1; |
| 2522 | |
| 2523 | // Construct rows of the address, source, line, column matrix. |
| 2524 | for (unsigned i = 0, N = LineInfos.size(); i < N; ++i) { |
| 2525 | const SrcLineInfo &LineInfo = LineInfos[i]; |
| 2526 | unsigned LabelID = MMI->MappedLabel(LineInfo.getLabelID()); |
| 2527 | if (!LabelID) continue; |
| 2528 | |
Caroline Tice | c6f9d62 | 2009-09-11 18:25:54 +0000 | [diff] [blame] | 2529 | if (LineInfo.getLine() == 0) continue; |
| 2530 | |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2531 | if (!Asm->isVerbose()) |
| 2532 | Asm->EOL(); |
| 2533 | else { |
| 2534 | std::pair<unsigned, unsigned> SourceID = |
| 2535 | getSourceDirectoryAndFileIds(LineInfo.getSourceID()); |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 2536 | O << '\t' << MAI->getCommentString() << ' ' |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2537 | << getSourceDirectoryName(SourceID.first) << ' ' |
| 2538 | << getSourceFileName(SourceID.second) |
| 2539 | <<" :" << utostr_32(LineInfo.getLine()) << '\n'; |
| 2540 | } |
| 2541 | |
| 2542 | // Define the line address. |
| 2543 | Asm->EmitInt8(0); Asm->EOL("Extended Op"); |
| 2544 | Asm->EmitInt8(TD->getPointerSize() + 1); Asm->EOL("Op size"); |
| 2545 | Asm->EmitInt8(dwarf::DW_LNE_set_address); Asm->EOL("DW_LNE_set_address"); |
| 2546 | EmitReference("label", LabelID); Asm->EOL("Location label"); |
| 2547 | |
| 2548 | // If change of source, then switch to the new source. |
| 2549 | if (Source != LineInfo.getSourceID()) { |
| 2550 | Source = LineInfo.getSourceID(); |
| 2551 | Asm->EmitInt8(dwarf::DW_LNS_set_file); Asm->EOL("DW_LNS_set_file"); |
| 2552 | Asm->EmitULEB128Bytes(Source); Asm->EOL("New Source"); |
| 2553 | } |
| 2554 | |
| 2555 | // If change of line. |
| 2556 | if (Line != LineInfo.getLine()) { |
| 2557 | // Determine offset. |
| 2558 | int Offset = LineInfo.getLine() - Line; |
| 2559 | int Delta = Offset - MinLineDelta; |
| 2560 | |
| 2561 | // Update line. |
| 2562 | Line = LineInfo.getLine(); |
| 2563 | |
| 2564 | // If delta is small enough and in range... |
| 2565 | if (Delta >= 0 && Delta < (MaxLineDelta - 1)) { |
| 2566 | // ... then use fast opcode. |
| 2567 | Asm->EmitInt8(Delta - MinLineDelta); Asm->EOL("Line Delta"); |
| 2568 | } else { |
| 2569 | // ... otherwise use long hand. |
| 2570 | Asm->EmitInt8(dwarf::DW_LNS_advance_line); |
| 2571 | Asm->EOL("DW_LNS_advance_line"); |
| 2572 | Asm->EmitSLEB128Bytes(Offset); Asm->EOL("Line Offset"); |
| 2573 | Asm->EmitInt8(dwarf::DW_LNS_copy); Asm->EOL("DW_LNS_copy"); |
| 2574 | } |
| 2575 | } else { |
| 2576 | // Copy the previous row (different address or source) |
| 2577 | Asm->EmitInt8(dwarf::DW_LNS_copy); Asm->EOL("DW_LNS_copy"); |
| 2578 | } |
| 2579 | } |
| 2580 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2581 | emitEndOfLineMatrix(j + 1); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2582 | } |
| 2583 | |
| 2584 | if (SecSrcLinesSize == 0) |
| 2585 | // Because we're emitting a debug_line section, we still need a line |
| 2586 | // table. The linker and friends expect it to exist. If there's nothing to |
| 2587 | // put into it, emit an empty table. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2588 | emitEndOfLineMatrix(1); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2589 | |
| 2590 | EmitLabel("line_end", 0); |
| 2591 | Asm->EOL(); |
| 2592 | } |
| 2593 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2594 | /// emitCommonDebugFrame - Emit common frame info into a debug frame section. |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2595 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2596 | void DwarfDebug::emitCommonDebugFrame() { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 2597 | if (!MAI->doesDwarfRequireFrameSection()) |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2598 | return; |
| 2599 | |
| 2600 | int stackGrowth = |
| 2601 | Asm->TM.getFrameInfo()->getStackGrowthDirection() == |
| 2602 | TargetFrameInfo::StackGrowsUp ? |
| 2603 | TD->getPointerSize() : -TD->getPointerSize(); |
| 2604 | |
| 2605 | // Start the dwarf frame section. |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 2606 | Asm->OutStreamer.SwitchSection( |
| 2607 | Asm->getObjFileLowering().getDwarfFrameSection()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2608 | |
| 2609 | EmitLabel("debug_frame_common", 0); |
| 2610 | EmitDifference("debug_frame_common_end", 0, |
| 2611 | "debug_frame_common_begin", 0, true); |
| 2612 | Asm->EOL("Length of Common Information Entry"); |
| 2613 | |
| 2614 | EmitLabel("debug_frame_common_begin", 0); |
| 2615 | Asm->EmitInt32((int)dwarf::DW_CIE_ID); |
| 2616 | Asm->EOL("CIE Identifier Tag"); |
| 2617 | Asm->EmitInt8(dwarf::DW_CIE_VERSION); |
| 2618 | Asm->EOL("CIE Version"); |
| 2619 | Asm->EmitString(""); |
| 2620 | Asm->EOL("CIE Augmentation"); |
| 2621 | Asm->EmitULEB128Bytes(1); |
| 2622 | Asm->EOL("CIE Code Alignment Factor"); |
| 2623 | Asm->EmitSLEB128Bytes(stackGrowth); |
| 2624 | Asm->EOL("CIE Data Alignment Factor"); |
| 2625 | Asm->EmitInt8(RI->getDwarfRegNum(RI->getRARegister(), false)); |
| 2626 | Asm->EOL("CIE RA Column"); |
| 2627 | |
| 2628 | std::vector<MachineMove> Moves; |
| 2629 | RI->getInitialFrameState(Moves); |
| 2630 | |
| 2631 | EmitFrameMoves(NULL, 0, Moves, false); |
| 2632 | |
| 2633 | Asm->EmitAlignment(2, 0, 0, false); |
| 2634 | EmitLabel("debug_frame_common_end", 0); |
| 2635 | |
| 2636 | Asm->EOL(); |
| 2637 | } |
| 2638 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2639 | /// emitFunctionDebugFrame - Emit per function frame info into a debug frame |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2640 | /// section. |
| 2641 | void |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2642 | DwarfDebug::emitFunctionDebugFrame(const FunctionDebugFrameInfo&DebugFrameInfo){ |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 2643 | if (!MAI->doesDwarfRequireFrameSection()) |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2644 | return; |
| 2645 | |
| 2646 | // Start the dwarf frame section. |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 2647 | Asm->OutStreamer.SwitchSection( |
| 2648 | Asm->getObjFileLowering().getDwarfFrameSection()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2649 | |
| 2650 | EmitDifference("debug_frame_end", DebugFrameInfo.Number, |
| 2651 | "debug_frame_begin", DebugFrameInfo.Number, true); |
| 2652 | Asm->EOL("Length of Frame Information Entry"); |
| 2653 | |
| 2654 | EmitLabel("debug_frame_begin", DebugFrameInfo.Number); |
| 2655 | |
| 2656 | EmitSectionOffset("debug_frame_common", "section_debug_frame", |
| 2657 | 0, 0, true, false); |
| 2658 | Asm->EOL("FDE CIE offset"); |
| 2659 | |
| 2660 | EmitReference("func_begin", DebugFrameInfo.Number); |
| 2661 | Asm->EOL("FDE initial location"); |
| 2662 | EmitDifference("func_end", DebugFrameInfo.Number, |
| 2663 | "func_begin", DebugFrameInfo.Number); |
| 2664 | Asm->EOL("FDE address range"); |
| 2665 | |
| 2666 | EmitFrameMoves("func_begin", DebugFrameInfo.Number, DebugFrameInfo.Moves, |
| 2667 | false); |
| 2668 | |
| 2669 | Asm->EmitAlignment(2, 0, 0, false); |
| 2670 | EmitLabel("debug_frame_end", DebugFrameInfo.Number); |
| 2671 | |
| 2672 | Asm->EOL(); |
| 2673 | } |
| 2674 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2675 | void DwarfDebug::emitDebugPubNamesPerCU(CompileUnit *Unit) { |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2676 | EmitDifference("pubnames_end", Unit->getID(), |
| 2677 | "pubnames_begin", Unit->getID(), true); |
| 2678 | Asm->EOL("Length of Public Names Info"); |
| 2679 | |
| 2680 | EmitLabel("pubnames_begin", Unit->getID()); |
| 2681 | |
| 2682 | Asm->EmitInt16(dwarf::DWARF_VERSION); Asm->EOL("DWARF Version"); |
| 2683 | |
| 2684 | EmitSectionOffset("info_begin", "section_info", |
| 2685 | Unit->getID(), 0, true, false); |
| 2686 | Asm->EOL("Offset of Compilation Unit Info"); |
| 2687 | |
| 2688 | EmitDifference("info_end", Unit->getID(), "info_begin", Unit->getID(), |
| 2689 | true); |
| 2690 | Asm->EOL("Compilation Unit Length"); |
| 2691 | |
Devang Patel | 193f720 | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 2692 | const StringMap<DIE*> &Globals = Unit->getGlobals(); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2693 | for (StringMap<DIE*>::const_iterator |
| 2694 | GI = Globals.begin(), GE = Globals.end(); GI != GE; ++GI) { |
| 2695 | const char *Name = GI->getKeyData(); |
| 2696 | DIE * Entity = GI->second; |
| 2697 | |
| 2698 | Asm->EmitInt32(Entity->getOffset()); Asm->EOL("DIE offset"); |
| 2699 | Asm->EmitString(Name, strlen(Name)); Asm->EOL("External Name"); |
| 2700 | } |
| 2701 | |
| 2702 | Asm->EmitInt32(0); Asm->EOL("End Mark"); |
| 2703 | EmitLabel("pubnames_end", Unit->getID()); |
| 2704 | |
| 2705 | Asm->EOL(); |
| 2706 | } |
| 2707 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2708 | /// emitDebugPubNames - Emit visible names into a debug pubnames section. |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2709 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2710 | void DwarfDebug::emitDebugPubNames() { |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2711 | // Start the dwarf pubnames section. |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 2712 | Asm->OutStreamer.SwitchSection( |
| 2713 | Asm->getObjFileLowering().getDwarfPubNamesSection()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2714 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2715 | emitDebugPubNamesPerCU(ModuleCU); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2716 | } |
| 2717 | |
Devang Patel | 193f720 | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 2718 | void DwarfDebug::emitDebugPubTypes() { |
Devang Patel | f3a0376 | 2009-11-24 19:18:41 +0000 | [diff] [blame] | 2719 | // Start the dwarf pubnames section. |
| 2720 | Asm->OutStreamer.SwitchSection( |
| 2721 | Asm->getObjFileLowering().getDwarfPubTypesSection()); |
Devang Patel | 193f720 | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 2722 | EmitDifference("pubtypes_end", ModuleCU->getID(), |
| 2723 | "pubtypes_begin", ModuleCU->getID(), true); |
| 2724 | Asm->EOL("Length of Public Types Info"); |
| 2725 | |
| 2726 | EmitLabel("pubtypes_begin", ModuleCU->getID()); |
| 2727 | |
| 2728 | Asm->EmitInt16(dwarf::DWARF_VERSION); Asm->EOL("DWARF Version"); |
| 2729 | |
| 2730 | EmitSectionOffset("info_begin", "section_info", |
| 2731 | ModuleCU->getID(), 0, true, false); |
| 2732 | Asm->EOL("Offset of Compilation ModuleCU Info"); |
| 2733 | |
| 2734 | EmitDifference("info_end", ModuleCU->getID(), "info_begin", ModuleCU->getID(), |
| 2735 | true); |
| 2736 | Asm->EOL("Compilation ModuleCU Length"); |
| 2737 | |
| 2738 | const StringMap<DIE*> &Globals = ModuleCU->getGlobalTypes(); |
| 2739 | for (StringMap<DIE*>::const_iterator |
| 2740 | GI = Globals.begin(), GE = Globals.end(); GI != GE; ++GI) { |
| 2741 | const char *Name = GI->getKeyData(); |
| 2742 | DIE * Entity = GI->second; |
| 2743 | |
| 2744 | Asm->EmitInt32(Entity->getOffset()); Asm->EOL("DIE offset"); |
| 2745 | Asm->EmitString(Name, strlen(Name)); Asm->EOL("External Name"); |
| 2746 | } |
| 2747 | |
| 2748 | Asm->EmitInt32(0); Asm->EOL("End Mark"); |
| 2749 | EmitLabel("pubtypes_end", ModuleCU->getID()); |
| 2750 | |
| 2751 | Asm->EOL(); |
| 2752 | } |
| 2753 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2754 | /// emitDebugStr - Emit visible names into a debug str section. |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2755 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2756 | void DwarfDebug::emitDebugStr() { |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2757 | // Check to see if it is worth the effort. |
| 2758 | if (!StringPool.empty()) { |
| 2759 | // Start the dwarf str section. |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 2760 | Asm->OutStreamer.SwitchSection( |
| 2761 | Asm->getObjFileLowering().getDwarfStrSection()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2762 | |
| 2763 | // For each of strings in the string pool. |
| 2764 | for (unsigned StringID = 1, N = StringPool.size(); |
| 2765 | StringID <= N; ++StringID) { |
| 2766 | // Emit a label for reference from debug information entries. |
| 2767 | EmitLabel("string", StringID); |
| 2768 | |
| 2769 | // Emit the string itself. |
| 2770 | const std::string &String = StringPool[StringID]; |
| 2771 | Asm->EmitString(String); Asm->EOL(); |
| 2772 | } |
| 2773 | |
| 2774 | Asm->EOL(); |
| 2775 | } |
| 2776 | } |
| 2777 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2778 | /// emitDebugLoc - Emit visible names into a debug loc section. |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2779 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2780 | void DwarfDebug::emitDebugLoc() { |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2781 | // Start the dwarf loc section. |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 2782 | Asm->OutStreamer.SwitchSection( |
| 2783 | Asm->getObjFileLowering().getDwarfLocSection()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2784 | Asm->EOL(); |
| 2785 | } |
| 2786 | |
| 2787 | /// EmitDebugARanges - Emit visible names into a debug aranges section. |
| 2788 | /// |
| 2789 | void DwarfDebug::EmitDebugARanges() { |
| 2790 | // Start the dwarf aranges section. |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 2791 | Asm->OutStreamer.SwitchSection( |
| 2792 | Asm->getObjFileLowering().getDwarfARangesSection()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2793 | |
| 2794 | // FIXME - Mock up |
| 2795 | #if 0 |
| 2796 | CompileUnit *Unit = GetBaseCompileUnit(); |
| 2797 | |
| 2798 | // Don't include size of length |
| 2799 | Asm->EmitInt32(0x1c); Asm->EOL("Length of Address Ranges Info"); |
| 2800 | |
| 2801 | Asm->EmitInt16(dwarf::DWARF_VERSION); Asm->EOL("Dwarf Version"); |
| 2802 | |
| 2803 | EmitReference("info_begin", Unit->getID()); |
| 2804 | Asm->EOL("Offset of Compilation Unit Info"); |
| 2805 | |
| 2806 | Asm->EmitInt8(TD->getPointerSize()); Asm->EOL("Size of Address"); |
| 2807 | |
| 2808 | Asm->EmitInt8(0); Asm->EOL("Size of Segment Descriptor"); |
| 2809 | |
| 2810 | Asm->EmitInt16(0); Asm->EOL("Pad (1)"); |
| 2811 | Asm->EmitInt16(0); Asm->EOL("Pad (2)"); |
| 2812 | |
| 2813 | // Range 1 |
| 2814 | EmitReference("text_begin", 0); Asm->EOL("Address"); |
| 2815 | EmitDifference("text_end", 0, "text_begin", 0, true); Asm->EOL("Length"); |
| 2816 | |
| 2817 | Asm->EmitInt32(0); Asm->EOL("EOM (1)"); |
| 2818 | Asm->EmitInt32(0); Asm->EOL("EOM (2)"); |
| 2819 | #endif |
| 2820 | |
| 2821 | Asm->EOL(); |
| 2822 | } |
| 2823 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2824 | /// emitDebugRanges - Emit visible names into a debug ranges section. |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2825 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2826 | void DwarfDebug::emitDebugRanges() { |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2827 | // Start the dwarf ranges section. |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 2828 | Asm->OutStreamer.SwitchSection( |
| 2829 | Asm->getObjFileLowering().getDwarfRangesSection()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2830 | Asm->EOL(); |
| 2831 | } |
| 2832 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2833 | /// emitDebugMacInfo - Emit visible names into a debug macinfo section. |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2834 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2835 | void DwarfDebug::emitDebugMacInfo() { |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 2836 | if (const MCSection *LineInfo = |
Chris Lattner | 18a4c16 | 2009-08-02 07:24:22 +0000 | [diff] [blame] | 2837 | Asm->getObjFileLowering().getDwarfMacroInfoSection()) { |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2838 | // Start the dwarf macinfo section. |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 2839 | Asm->OutStreamer.SwitchSection(LineInfo); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2840 | Asm->EOL(); |
| 2841 | } |
| 2842 | } |
| 2843 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2844 | /// emitDebugInlineInfo - Emit inline info using following format. |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2845 | /// Section Header: |
| 2846 | /// 1. length of section |
| 2847 | /// 2. Dwarf version number |
| 2848 | /// 3. address size. |
| 2849 | /// |
| 2850 | /// Entries (one "entry" for each function that was inlined): |
| 2851 | /// |
| 2852 | /// 1. offset into __debug_str section for MIPS linkage name, if exists; |
| 2853 | /// otherwise offset into __debug_str for regular function name. |
| 2854 | /// 2. offset into __debug_str section for regular function name. |
| 2855 | /// 3. an unsigned LEB128 number indicating the number of distinct inlining |
| 2856 | /// instances for the function. |
| 2857 | /// |
| 2858 | /// The rest of the entry consists of a {die_offset, low_pc} pair for each |
| 2859 | /// inlined instance; the die_offset points to the inlined_subroutine die in the |
| 2860 | /// __debug_info section, and the low_pc is the starting address for the |
| 2861 | /// inlining instance. |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 2862 | void DwarfDebug::emitDebugInlineInfo() { |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 2863 | if (!MAI->doesDwarfUsesInlineInfoSection()) |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2864 | return; |
| 2865 | |
Devang Patel | 1dbc771 | 2009-06-29 20:45:18 +0000 | [diff] [blame] | 2866 | if (!ModuleCU) |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2867 | return; |
| 2868 | |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 2869 | Asm->OutStreamer.SwitchSection( |
| 2870 | Asm->getObjFileLowering().getDwarfDebugInlineSection()); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2871 | Asm->EOL(); |
| 2872 | EmitDifference("debug_inlined_end", 1, |
| 2873 | "debug_inlined_begin", 1, true); |
| 2874 | Asm->EOL("Length of Debug Inlined Information Entry"); |
| 2875 | |
| 2876 | EmitLabel("debug_inlined_begin", 1); |
| 2877 | |
| 2878 | Asm->EmitInt16(dwarf::DWARF_VERSION); Asm->EOL("Dwarf Version"); |
| 2879 | Asm->EmitInt8(TD->getPointerSize()); Asm->EOL("Address Size (in bytes)"); |
| 2880 | |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 2881 | for (SmallVector<MDNode *, 4>::iterator I = InlinedSPNodes.begin(), |
| 2882 | E = InlinedSPNodes.end(); I != E; ++I) { |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 2883 | |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 2884 | // for (ValueMap<MDNode *, SmallVector<InlineInfoLabels, 4> >::iterator |
| 2885 | // I = InlineInfo.begin(), E = InlineInfo.end(); I != E; ++I) { |
| 2886 | MDNode *Node = *I; |
Jim Grosbach | 7ab38df | 2009-11-22 19:20:36 +0000 | [diff] [blame] | 2887 | ValueMap<MDNode *, SmallVector<InlineInfoLabels, 4> >::iterator II |
| 2888 | = InlineInfo.find(Node); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 2889 | SmallVector<InlineInfoLabels, 4> &Labels = II->second; |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 2890 | DISubprogram SP(Node); |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 2891 | StringRef LName = SP.getLinkageName(); |
| 2892 | StringRef Name = SP.getName(); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2893 | |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 2894 | if (LName.empty()) |
Devang Patel | 53cb17d | 2009-07-16 01:01:22 +0000 | [diff] [blame] | 2895 | Asm->EmitString(Name); |
| 2896 | else { |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 2897 | // Skip special LLVM prefix that is used to inform the asm printer to not |
| 2898 | // emit usual symbol prefix before the symbol name. This happens for |
| 2899 | // Objective-C symbol names and symbol whose name is replaced using GCC's |
| 2900 | // __asm__ attribute. |
Devang Patel | 53cb17d | 2009-07-16 01:01:22 +0000 | [diff] [blame] | 2901 | if (LName[0] == 1) |
Benjamin Kramer | 1c3451f | 2009-11-25 18:26:09 +0000 | [diff] [blame] | 2902 | LName = LName.substr(1); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 2903 | // Asm->EmitString(LName); |
| 2904 | EmitSectionOffset("string", "section_str", |
| 2905 | StringPool.idFor(LName), false, true); |
| 2906 | |
Devang Patel | 53cb17d | 2009-07-16 01:01:22 +0000 | [diff] [blame] | 2907 | } |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2908 | Asm->EOL("MIPS linkage name"); |
Jim Grosbach | 31ef40e | 2009-11-21 23:12:12 +0000 | [diff] [blame] | 2909 | // Asm->EmitString(Name); |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 2910 | EmitSectionOffset("string", "section_str", |
| 2911 | StringPool.idFor(Name), false, true); |
| 2912 | Asm->EOL("Function name"); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2913 | Asm->EmitULEB128Bytes(Labels.size()); Asm->EOL("Inline count"); |
| 2914 | |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 2915 | for (SmallVector<InlineInfoLabels, 4>::iterator LI = Labels.begin(), |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2916 | LE = Labels.end(); LI != LE; ++LI) { |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 2917 | DIE *SP = LI->second; |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2918 | Asm->EmitInt32(SP->getOffset()); Asm->EOL("DIE offset"); |
| 2919 | |
| 2920 | if (TD->getPointerSize() == sizeof(int32_t)) |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 2921 | O << MAI->getData32bitsDirective(); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2922 | else |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 2923 | O << MAI->getData64bitsDirective(); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2924 | |
Devang Patel | 53bb5c9 | 2009-11-10 23:06:00 +0000 | [diff] [blame] | 2925 | PrintLabelName("label", LI->first); Asm->EOL("low_pc"); |
Bill Wendling | 94d04b8 | 2009-05-20 23:21:38 +0000 | [diff] [blame] | 2926 | } |
| 2927 | } |
| 2928 | |
| 2929 | EmitLabel("debug_inlined_end", 1); |
| 2930 | Asm->EOL(); |
| 2931 | } |