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