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