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