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