blob: 6e877c7e3ab7557c695c69f439316761b7d26d21 [file] [log] [blame]
Bill Wendlingb12b3d72009-05-15 09:23:25 +00001//===-- 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 Lattner2ab0c442010-03-09 00:39:24 +000013
Devang Patel15e723d2009-08-28 23:24:31 +000014#define DEBUG_TYPE "dwarfdebug"
Bill Wendlingb12b3d72009-05-15 09:23:25 +000015#include "DwarfDebug.h"
Chris Lattner855b6bb2010-04-05 05:24:55 +000016#include "DIE.h"
Bill Wendling989a27e2010-04-05 22:59:21 +000017#include "llvm/Constants.h"
Bill Wendlingb12b3d72009-05-15 09:23:25 +000018#include "llvm/Module.h"
David Greened87baff2009-08-19 21:52:55 +000019#include "llvm/CodeGen/MachineFunction.h"
Bill Wendlingb12b3d72009-05-15 09:23:25 +000020#include "llvm/CodeGen/MachineModuleInfo.h"
Chris Lattner855e8f52010-03-09 01:58:53 +000021#include "llvm/MC/MCAsmInfo.h"
Chris Lattnere6ad12f2009-07-31 18:48:30 +000022#include "llvm/MC/MCSection.h"
Chris Lattner73266f92009-08-19 05:49:37 +000023#include "llvm/MC/MCStreamer.h"
Chris Lattner855e8f52010-03-09 01:58:53 +000024#include "llvm/MC/MCSymbol.h"
Chris Lattner31a54742010-01-16 21:57:06 +000025#include "llvm/Target/Mangler.h"
Bill Wendlingb12b3d72009-05-15 09:23:25 +000026#include "llvm/Target/TargetData.h"
27#include "llvm/Target/TargetFrameInfo.h"
Chris Lattnerc4c40a92009-07-28 03:13:23 +000028#include "llvm/Target/TargetLoweringObjectFile.h"
Chris Lattner017c7f92010-04-04 18:06:11 +000029#include "llvm/Target/TargetMachine.h"
Chris Lattnerc4c40a92009-07-28 03:13:23 +000030#include "llvm/Target/TargetRegisterInfo.h"
Devang Patel91474172010-04-19 19:14:02 +000031#include "llvm/Target/TargetOptions.h"
Chris Lattner855b6bb2010-04-05 05:24:55 +000032#include "llvm/Analysis/DebugInfo.h"
Jeffrey Yasskinecca2e62010-03-12 17:45:06 +000033#include "llvm/ADT/STLExtras.h"
Chris Lattnerf5377682009-08-24 03:52:50 +000034#include "llvm/ADT/StringExtras.h"
Devang Patelec3b2a42010-04-21 16:32:19 +000035#include "llvm/Support/CommandLine.h"
Daniel Dunbarc74255d2009-10-13 06:47:08 +000036#include "llvm/Support/Debug.h"
37#include "llvm/Support/ErrorHandling.h"
Devang Patelae89d3b2010-01-26 21:39:14 +000038#include "llvm/Support/ValueHandle.h"
Chris Lattnerad653482010-01-22 22:09:00 +000039#include "llvm/Support/FormattedStream.h"
Chris Lattnere6ad12f2009-07-31 18:48:30 +000040#include "llvm/Support/Timer.h"
41#include "llvm/System/Path.h"
Bill Wendlingb12b3d72009-05-15 09:23:25 +000042using namespace llvm;
43
Devang Patelec3b2a42010-04-21 16:32:19 +000044static cl::opt<bool> PrintDbgScope("print-dbgscope", cl::Hidden,
45 cl::desc("Print DbgScope information for each machine instruction"));
46
Devang Patel58e58f62010-04-21 19:08:53 +000047static cl::opt<bool> DisableDebugInfoPrinting("disable-debug-info-print", cl::Hidden,
48 cl::desc("Disable debug info printing"));
49
Bill Wendlingce3c6252010-04-07 09:28:04 +000050namespace {
51 const char *DWARFGroupName = "DWARF Emission";
52 const char *DbgTimerName = "DWARF Debug Writer";
53} // end anonymous namespace
54
Bill Wendlingb12b3d72009-05-15 09:23:25 +000055//===----------------------------------------------------------------------===//
56
57/// Configuration values for initial hash set sizes (log2).
58///
Bill Wendlingb12b3d72009-05-15 09:23:25 +000059static const unsigned InitAbbreviationsSetSize = 9; // log2(512)
Bill Wendlingb12b3d72009-05-15 09:23:25 +000060
61namespace llvm {
62
63//===----------------------------------------------------------------------===//
64/// CompileUnit - This dwarf writer support class manages information associate
65/// with a source file.
Nick Lewyckyee68f452009-11-17 08:11:44 +000066class CompileUnit {
Bill Wendlingb12b3d72009-05-15 09:23:25 +000067 /// ID - File identifier for source.
68 ///
69 unsigned ID;
70
71 /// Die - Compile unit debug information entry.
72 ///
Jeffrey Yasskinecca2e62010-03-12 17:45:06 +000073 const OwningPtr<DIE> CUDie;
Bill Wendlingb12b3d72009-05-15 09:23:25 +000074
Jeffrey Yasskinc3545712010-03-11 18:29:55 +000075 /// IndexTyDie - An anonymous type for index type. Owned by CUDie.
Devang Patel1233f912009-11-21 00:31:03 +000076 DIE *IndexTyDie;
77
Bill Wendlingb12b3d72009-05-15 09:23:25 +000078 /// GVToDieMap - Tracks the mapping of unit level debug informaton
79 /// variables to debug information entries.
Devang Patel15e723d2009-08-28 23:24:31 +000080 /// FIXME : Rename GVToDieMap -> NodeToDieMap
Devang Patel7d707f92010-01-19 06:19:05 +000081 DenseMap<MDNode *, DIE *> GVToDieMap;
Bill Wendlingb12b3d72009-05-15 09:23:25 +000082
83 /// GVToDIEEntryMap - Tracks the mapping of unit level debug informaton
84 /// descriptors to debug information entries using a DIEEntry proxy.
Devang Patel15e723d2009-08-28 23:24:31 +000085 /// FIXME : Rename
Devang Patel7d707f92010-01-19 06:19:05 +000086 DenseMap<MDNode *, DIEEntry *> GVToDIEEntryMap;
Bill Wendlingb12b3d72009-05-15 09:23:25 +000087
88 /// Globals - A map of globally visible named entities for this unit.
89 ///
90 StringMap<DIE*> Globals;
91
Devang Patelec13b4f2009-11-24 01:14:22 +000092 /// GlobalTypes - A map of globally visible types for this unit.
93 ///
94 StringMap<DIE*> GlobalTypes;
95
Bill Wendlingb12b3d72009-05-15 09:23:25 +000096public:
97 CompileUnit(unsigned I, DIE *D)
Devang Patelc50078e2009-11-21 02:48:08 +000098 : ID(I), CUDie(D), IndexTyDie(0) {}
Bill Wendlingb12b3d72009-05-15 09:23:25 +000099
100 // Accessors.
Devang Patelec13b4f2009-11-24 01:14:22 +0000101 unsigned getID() const { return ID; }
Jeffrey Yasskinc3545712010-03-11 18:29:55 +0000102 DIE* getCUDie() const { return CUDie.get(); }
Devang Patelec13b4f2009-11-24 01:14:22 +0000103 const StringMap<DIE*> &getGlobals() const { return Globals; }
104 const StringMap<DIE*> &getGlobalTypes() const { return GlobalTypes; }
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000105
106 /// hasContent - Return true if this compile unit has something to write out.
107 ///
Devang Patelc50078e2009-11-21 02:48:08 +0000108 bool hasContent() const { return !CUDie->getChildren().empty(); }
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000109
Devang Patelc50078e2009-11-21 02:48:08 +0000110 /// addGlobal - Add a new global entity to the compile unit.
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000111 ///
Benjamin Kramer648940b2010-03-31 20:15:45 +0000112 void addGlobal(StringRef Name, DIE *Die) { Globals[Name] = Die; }
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000113
Devang Patelec13b4f2009-11-24 01:14:22 +0000114 /// addGlobalType - Add a new global type to the compile unit.
115 ///
Benjamin Kramer648940b2010-03-31 20:15:45 +0000116 void addGlobalType(StringRef Name, DIE *Die) {
Devang Patelec13b4f2009-11-24 01:14:22 +0000117 GlobalTypes[Name] = Die;
118 }
119
Devang Pateld90672c2009-11-20 21:37:22 +0000120 /// getDIE - Returns the debug information entry map slot for the
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000121 /// specified debug variable.
Devang Pateld90672c2009-11-20 21:37:22 +0000122 DIE *getDIE(MDNode *N) { return GVToDieMap.lookup(N); }
Jim Grosbach652b7432009-11-21 23:12:12 +0000123
Devang Pateld90672c2009-11-20 21:37:22 +0000124 /// insertDIE - Insert DIE into the map.
125 void insertDIE(MDNode *N, DIE *D) {
126 GVToDieMap.insert(std::make_pair(N, D));
127 }
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000128
Devang Pateld90672c2009-11-20 21:37:22 +0000129 /// getDIEEntry - Returns the debug information entry for the speciefied
130 /// debug variable.
Devang Patel8287d662009-12-15 19:16:48 +0000131 DIEEntry *getDIEEntry(MDNode *N) {
Devang Patel7d707f92010-01-19 06:19:05 +0000132 DenseMap<MDNode *, DIEEntry *>::iterator I = GVToDIEEntryMap.find(N);
Devang Patel8287d662009-12-15 19:16:48 +0000133 if (I == GVToDIEEntryMap.end())
134 return NULL;
135 return I->second;
136 }
Devang Pateld90672c2009-11-20 21:37:22 +0000137
138 /// insertDIEEntry - Insert debug information entry into the map.
139 void insertDIEEntry(MDNode *N, DIEEntry *E) {
140 GVToDIEEntryMap.insert(std::make_pair(N, E));
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000141 }
142
Devang Patelc50078e2009-11-21 02:48:08 +0000143 /// addDie - Adds or interns the DIE to the compile unit.
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000144 ///
Devang Patelc50078e2009-11-21 02:48:08 +0000145 void addDie(DIE *Buffer) {
146 this->CUDie->addChild(Buffer);
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000147 }
Devang Patel1233f912009-11-21 00:31:03 +0000148
149 // getIndexTyDie - Get an anonymous type for index type.
150 DIE *getIndexTyDie() {
151 return IndexTyDie;
152 }
153
Jim Grosbachb23f2422009-11-22 19:20:36 +0000154 // setIndexTyDie - Set D as anonymous type for index which can be reused
155 // later.
Devang Patel1233f912009-11-21 00:31:03 +0000156 void setIndexTyDie(DIE *D) {
157 IndexTyDie = D;
158 }
159
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000160};
161
162//===----------------------------------------------------------------------===//
163/// DbgVariable - This class is used to track local variable information.
164///
Devang Patel4cb32c32009-11-16 21:53:40 +0000165class DbgVariable {
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000166 DIVariable Var; // Variable Descriptor.
167 unsigned FrameIndex; // Variable frame index.
Devang Patel14da02f2010-03-15 18:33:46 +0000168 const MachineInstr *DbgValueMInsn; // DBG_VALUE
Devang Patel9a9a4ac2010-03-29 22:59:58 +0000169 // DbgValueLabel - DBG_VALUE is effective from this label.
170 MCSymbol *DbgValueLabel;
Jeffrey Yasskinecca2e62010-03-12 17:45:06 +0000171 DbgVariable *const AbstractVar; // Abstract variable for this variable.
Devang Patel90a0fe32009-11-10 23:06:00 +0000172 DIE *TheDIE;
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000173public:
Jeffrey Yasskinecca2e62010-03-12 17:45:06 +0000174 // AbsVar may be NULL.
175 DbgVariable(DIVariable V, unsigned I, DbgVariable *AbsVar)
Devang Patel9a9a4ac2010-03-29 22:59:58 +0000176 : Var(V), FrameIndex(I), DbgValueMInsn(0),
177 DbgValueLabel(0), AbstractVar(AbsVar), TheDIE(0) {}
Devang Patel14da02f2010-03-15 18:33:46 +0000178 DbgVariable(DIVariable V, const MachineInstr *MI, DbgVariable *AbsVar)
Devang Patel9a9a4ac2010-03-29 22:59:58 +0000179 : Var(V), FrameIndex(0), DbgValueMInsn(MI), DbgValueLabel(0),
180 AbstractVar(AbsVar), TheDIE(0)
Devang Patel14da02f2010-03-15 18:33:46 +0000181 {}
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000182
183 // Accessors.
Devang Patel90a0fe32009-11-10 23:06:00 +0000184 DIVariable getVariable() const { return Var; }
185 unsigned getFrameIndex() const { return FrameIndex; }
Devang Patel14da02f2010-03-15 18:33:46 +0000186 const MachineInstr *getDbgValue() const { return DbgValueMInsn; }
Devang Patel9a9a4ac2010-03-29 22:59:58 +0000187 MCSymbol *getDbgValueLabel() const { return DbgValueLabel; }
188 void setDbgValueLabel(MCSymbol *L) { DbgValueLabel = L; }
Devang Patel90a0fe32009-11-10 23:06:00 +0000189 DbgVariable *getAbstractVariable() const { return AbstractVar; }
190 void setDIE(DIE *D) { TheDIE = D; }
191 DIE *getDIE() const { return TheDIE; }
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000192};
193
194//===----------------------------------------------------------------------===//
Devang Patelec3b2a42010-04-21 16:32:19 +0000195/// DbgRange - This is used to track range of instructions with identical
196/// debug info scope.
197///
198typedef std::pair<const MachineInstr *, const MachineInstr *> DbgRange;
199
200//===----------------------------------------------------------------------===//
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000201/// DbgScope - This class is used to track scope information.
202///
Devang Patel4cb32c32009-11-16 21:53:40 +0000203class DbgScope {
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000204 DbgScope *Parent; // Parent to this scope.
Jim Grosbach652b7432009-11-21 23:12:12 +0000205 DIDescriptor Desc; // Debug info descriptor for scope.
Devang Patelae89d3b2010-01-26 21:39:14 +0000206 // Location at which this scope is inlined.
207 AssertingVH<MDNode> InlinedAtLocation;
Devang Patel90a0fe32009-11-10 23:06:00 +0000208 bool AbstractScope; // Abstract Scope
Devang Patel90ecd192009-10-01 18:25:23 +0000209 const MachineInstr *LastInsn; // Last instruction of this scope.
210 const MachineInstr *FirstInsn; // First instruction of this scope.
Devang Patelec3b2a42010-04-21 16:32:19 +0000211 unsigned DFSIn, DFSOut;
Jeffrey Yasskinecca2e62010-03-12 17:45:06 +0000212 // Scopes defined in scope. Contents not owned.
213 SmallVector<DbgScope *, 4> Scopes;
214 // Variables declared in scope. Contents owned.
215 SmallVector<DbgVariable *, 8> Variables;
Devang Patelec3b2a42010-04-21 16:32:19 +0000216 SmallVector<DbgRange, 4> Ranges;
Owen Anderson696d4862009-06-24 22:53:20 +0000217 // Private state for dump()
218 mutable unsigned IndentLevel;
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000219public:
Devang Pateldd7bb432009-10-14 21:08:09 +0000220 DbgScope(DbgScope *P, DIDescriptor D, MDNode *I = 0)
Devang Patel90a0fe32009-11-10 23:06:00 +0000221 : Parent(P), Desc(D), InlinedAtLocation(I), AbstractScope(false),
Devang Patelec3b2a42010-04-21 16:32:19 +0000222 LastInsn(0), FirstInsn(0),
223 DFSIn(0), DFSOut(0), IndentLevel(0) {}
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000224 virtual ~DbgScope();
225
226 // Accessors.
227 DbgScope *getParent() const { return Parent; }
Devang Patel90a0fe32009-11-10 23:06:00 +0000228 void setParent(DbgScope *P) { Parent = P; }
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000229 DIDescriptor getDesc() const { return Desc; }
Chris Lattner0f093f82010-03-13 02:17:42 +0000230 MDNode *getInlinedAt() const { return InlinedAtLocation; }
Devang Patel90a0fe32009-11-10 23:06:00 +0000231 MDNode *getScopeNode() const { return Desc.getNode(); }
Jeffrey Yasskinecca2e62010-03-12 17:45:06 +0000232 const SmallVector<DbgScope *, 4> &getScopes() { return Scopes; }
233 const SmallVector<DbgVariable *, 8> &getVariables() { return Variables; }
Devang Patelec3b2a42010-04-21 16:32:19 +0000234 const SmallVector<DbgRange, 4> &getRanges() { return Ranges; }
235
236 /// openInsnRange - This scope covers instruction range starting from MI.
237 void openInsnRange(const MachineInstr *MI) {
238 if (!FirstInsn)
239 FirstInsn = MI;
240
241 if (Parent)
242 Parent->openInsnRange(MI);
243 }
244
245 /// extendInsnRange - Extend the current instruction range covered by
246 /// this scope.
247 void extendInsnRange(const MachineInstr *MI) {
248 assert (FirstInsn && "MI Range is not open!");
249 LastInsn = MI;
250 if (Parent)
251 Parent->extendInsnRange(MI);
252 }
253
254 /// closeInsnRange - Create a range based on FirstInsn and LastInsn collected
255 /// until now. This is used when a new scope is encountered while walking
256 /// machine instructions.
257 void closeInsnRange(DbgScope *NewScope = NULL) {
258 assert (LastInsn && "Last insn missing!");
259 Ranges.push_back(DbgRange(FirstInsn, LastInsn));
260 FirstInsn = NULL;
261 LastInsn = NULL;
262 // If Parent dominates NewScope then do not close Parent's instruction
263 // range.
264 if (Parent && (!NewScope || !Parent->dominates(NewScope)))
265 Parent->closeInsnRange(NewScope);
266 }
267
Devang Patel90a0fe32009-11-10 23:06:00 +0000268 void setAbstractScope() { AbstractScope = true; }
269 bool isAbstractScope() const { return AbstractScope; }
Devang Patelec3b2a42010-04-21 16:32:19 +0000270
271 // Depth First Search support to walk and mainpluate DbgScope hierarchy.
272 unsigned getDFSOut() const { return DFSOut; }
273 void setDFSOut(unsigned O) { DFSOut = O; }
274 unsigned getDFSIn() const { return DFSIn; }
275 void setDFSIn(unsigned I) { DFSIn = I; }
276 bool dominates(const DbgScope *S) {
277 if (S == this)
278 return true;
279 if (DFSIn < S->getDFSIn() && DFSOut > S->getDFSOut())
280 return true;
281 return false;
282 }
Devang Patel90a0fe32009-11-10 23:06:00 +0000283
Devang Patelc50078e2009-11-21 02:48:08 +0000284 /// addScope - Add a scope to the scope.
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000285 ///
Devang Patelc50078e2009-11-21 02:48:08 +0000286 void addScope(DbgScope *S) { Scopes.push_back(S); }
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000287
Devang Patelc50078e2009-11-21 02:48:08 +0000288 /// addVariable - Add a variable to the scope.
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000289 ///
Devang Patelc50078e2009-11-21 02:48:08 +0000290 void addVariable(DbgVariable *V) { Variables.push_back(V); }
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000291
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000292#ifndef NDEBUG
293 void dump() const;
294#endif
295};
Devang Patelec3b2a42010-04-21 16:32:19 +0000296
Chris Lattner8b9430c2010-04-05 04:09:20 +0000297} // end llvm namespace
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000298
299#ifndef NDEBUG
300void DbgScope::dump() const {
David Greenedbc06132009-12-24 00:31:35 +0000301 raw_ostream &err = dbgs();
Chris Lattnerebb8c082009-08-23 00:51:00 +0000302 err.indent(IndentLevel);
Devang Patel90a0fe32009-11-10 23:06:00 +0000303 MDNode *N = Desc.getNode();
304 N->dump();
Devang Patel90a0fe32009-11-10 23:06:00 +0000305 if (AbstractScope)
306 err << "Abstract Scope\n";
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000307
308 IndentLevel += 2;
Devang Patel90a0fe32009-11-10 23:06:00 +0000309 if (!Scopes.empty())
310 err << "Children ...\n";
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000311 for (unsigned i = 0, e = Scopes.size(); i != e; ++i)
312 if (Scopes[i] != this)
313 Scopes[i]->dump();
314
315 IndentLevel -= 2;
316}
317#endif
318
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000319DbgScope::~DbgScope() {
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000320 for (unsigned j = 0, M = Variables.size(); j < M; ++j)
321 delete Variables[j];
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000322}
323
Chris Lattnerec9a1f42010-04-05 05:11:15 +0000324DwarfDebug::DwarfDebug(AsmPrinter *A, Module *M)
Chris Lattnerbc0027b2010-04-05 00:13:49 +0000325 : Asm(A), MMI(Asm->MMI), ModuleCU(0),
Chris Lattner2cb53302010-04-05 03:52:55 +0000326 AbbreviationsSet(InitAbbreviationsSetSize),
Devang Patel146c6f72010-04-16 23:33:45 +0000327 CurrentFnDbgScope(0), PrevLabel(NULL) {
Chris Lattner0f093f82010-03-13 02:17:42 +0000328 NextStringPoolNumber = 0;
Chris Lattner66143d22010-04-04 22:59:04 +0000329
Chris Lattner094932e2010-04-04 23:10:38 +0000330 DwarfFrameSectionSym = DwarfInfoSectionSym = DwarfAbbrevSectionSym = 0;
331 DwarfStrSectionSym = TextSectionSym = 0;
Devang Patelec3b2a42010-04-21 16:32:19 +0000332 DwarfDebugRangeSectionSym = 0;
Edwin Törökc669cb62010-04-07 10:44:46 +0000333 if (TimePassesIsEnabled) {
334 NamedRegionTimer T(DbgTimerName, DWARFGroupName);
335 beginModule(M);
336 } else {
337 beginModule(M);
338 }
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000339}
340DwarfDebug::~DwarfDebug() {
Benjamin Kramer138c7ff2010-03-31 19:34:01 +0000341 for (unsigned j = 0, M = DIEBlocks.size(); j < M; ++j)
342 DIEBlocks[j]->~DIEBlock();
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000343}
344
Chris Lattner0f093f82010-03-13 02:17:42 +0000345MCSymbol *DwarfDebug::getStringPoolEntry(StringRef Str) {
346 std::pair<MCSymbol*, unsigned> &Entry = StringPool[Str];
347 if (Entry.first) return Entry.first;
348
349 Entry.second = NextStringPoolNumber++;
Chris Lattnerb93558d2010-04-04 19:25:43 +0000350 return Entry.first = Asm->GetTempSymbol("string", Entry.second);
Chris Lattner0f093f82010-03-13 02:17:42 +0000351}
352
353
Devang Patelc50078e2009-11-21 02:48:08 +0000354/// assignAbbrevNumber - Define a unique number for the abbreviation.
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000355///
Devang Patelc50078e2009-11-21 02:48:08 +0000356void DwarfDebug::assignAbbrevNumber(DIEAbbrev &Abbrev) {
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000357 // Profile the node so that we can make it unique.
358 FoldingSetNodeID ID;
359 Abbrev.Profile(ID);
360
361 // Check the set for priors.
362 DIEAbbrev *InSet = AbbreviationsSet.GetOrInsertNode(&Abbrev);
363
364 // If it's newly added.
365 if (InSet == &Abbrev) {
366 // Add to abbreviation list.
367 Abbreviations.push_back(&Abbrev);
368
369 // Assign the vector position + 1 as its number.
370 Abbrev.setNumber(Abbreviations.size());
371 } else {
372 // Assign existing abbreviation number.
373 Abbrev.setNumber(InSet->getNumber());
374 }
375}
376
Devang Patelc50078e2009-11-21 02:48:08 +0000377/// createDIEEntry - Creates a new DIEEntry to be a proxy for a debug
Bill Wendling0d3db8b2009-05-20 23:24:48 +0000378/// information entry.
Devang Patelc50078e2009-11-21 02:48:08 +0000379DIEEntry *DwarfDebug::createDIEEntry(DIE *Entry) {
Benjamin Kramer138c7ff2010-03-31 19:34:01 +0000380 DIEEntry *Value = new (DIEValueAllocator) DIEEntry(Entry);
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000381 return Value;
382}
383
Devang Patelc50078e2009-11-21 02:48:08 +0000384/// addUInt - Add an unsigned integer attribute data and value.
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000385///
Devang Patelc50078e2009-11-21 02:48:08 +0000386void DwarfDebug::addUInt(DIE *Die, unsigned Attribute,
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000387 unsigned Form, uint64_t Integer) {
388 if (!Form) Form = DIEInteger::BestForm(false, Integer);
Benjamin Kramer138c7ff2010-03-31 19:34:01 +0000389 DIEValue *Value = new (DIEValueAllocator) DIEInteger(Integer);
Devang Patelc50078e2009-11-21 02:48:08 +0000390 Die->addValue(Attribute, Form, Value);
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000391}
392
Devang Patelc50078e2009-11-21 02:48:08 +0000393/// addSInt - Add an signed integer attribute data and value.
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000394///
Devang Patelc50078e2009-11-21 02:48:08 +0000395void DwarfDebug::addSInt(DIE *Die, unsigned Attribute,
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000396 unsigned Form, int64_t Integer) {
397 if (!Form) Form = DIEInteger::BestForm(true, Integer);
Benjamin Kramer138c7ff2010-03-31 19:34:01 +0000398 DIEValue *Value = new (DIEValueAllocator) DIEInteger(Integer);
Devang Patelc50078e2009-11-21 02:48:08 +0000399 Die->addValue(Attribute, Form, Value);
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000400}
401
Devang Pateldf0f2152009-12-02 15:25:16 +0000402/// addString - Add a string attribute data and value. DIEString only
403/// keeps string reference.
Devang Patelc50078e2009-11-21 02:48:08 +0000404void DwarfDebug::addString(DIE *Die, unsigned Attribute, unsigned Form,
Chris Lattnercc564642010-01-23 03:11:46 +0000405 StringRef String) {
Benjamin Kramer138c7ff2010-03-31 19:34:01 +0000406 DIEValue *Value = new (DIEValueAllocator) DIEString(String);
Devang Patelc50078e2009-11-21 02:48:08 +0000407 Die->addValue(Attribute, Form, Value);
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000408}
409
Devang Patelc50078e2009-11-21 02:48:08 +0000410/// addLabel - Add a Dwarf label attribute data and value.
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000411///
Devang Patelc50078e2009-11-21 02:48:08 +0000412void DwarfDebug::addLabel(DIE *Die, unsigned Attribute, unsigned Form,
Chris Lattnerbe4c2fc2010-03-08 22:23:36 +0000413 const MCSymbol *Label) {
Benjamin Kramer138c7ff2010-03-31 19:34:01 +0000414 DIEValue *Value = new (DIEValueAllocator) DIELabel(Label);
Devang Patelc50078e2009-11-21 02:48:08 +0000415 Die->addValue(Attribute, Form, Value);
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000416}
417
Devang Patelc50078e2009-11-21 02:48:08 +0000418/// addDelta - Add a label delta attribute data and value.
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000419///
Devang Patelc50078e2009-11-21 02:48:08 +0000420void DwarfDebug::addDelta(DIE *Die, unsigned Attribute, unsigned Form,
Chris Lattnerbe4c2fc2010-03-08 22:23:36 +0000421 const MCSymbol *Hi, const MCSymbol *Lo) {
Benjamin Kramer138c7ff2010-03-31 19:34:01 +0000422 DIEValue *Value = new (DIEValueAllocator) DIEDelta(Hi, Lo);
Devang Patelc50078e2009-11-21 02:48:08 +0000423 Die->addValue(Attribute, Form, Value);
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000424}
425
Chris Lattner855b6bb2010-04-05 05:24:55 +0000426/// addDIEEntry - Add a DIE attribute data and value.
427///
428void DwarfDebug::addDIEEntry(DIE *Die, unsigned Attribute, unsigned Form,
429 DIE *Entry) {
430 Die->addValue(Attribute, Form, createDIEEntry(Entry));
431}
432
433
Devang Patelc50078e2009-11-21 02:48:08 +0000434/// addBlock - Add block data.
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000435///
Devang Patelc50078e2009-11-21 02:48:08 +0000436void DwarfDebug::addBlock(DIE *Die, unsigned Attribute, unsigned Form,
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000437 DIEBlock *Block) {
Chris Lattner352c8e22010-04-05 00:18:22 +0000438 Block->ComputeSize(Asm);
Benjamin Kramer138c7ff2010-03-31 19:34:01 +0000439 DIEBlocks.push_back(Block); // Memoize so we can call the destructor later on.
Devang Patelc50078e2009-11-21 02:48:08 +0000440 Die->addValue(Attribute, Block->BestForm(), Block);
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000441}
442
Devang Patelc50078e2009-11-21 02:48:08 +0000443/// addSourceLine - Add location information to specified debug information
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000444/// entry.
Devang Patelc50078e2009-11-21 02:48:08 +0000445void DwarfDebug::addSourceLine(DIE *Die, const DIVariable *V) {
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000446 // If there is no compile unit specified, don't add a line #.
Devang Patel9e592492010-03-08 20:52:55 +0000447 if (!V->getCompileUnit().Verify())
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000448 return;
449
450 unsigned Line = V->getLineNumber();
Devang Patel7f9e0f32010-03-08 22:02:50 +0000451 unsigned FileID = GetOrCreateSourceID(V->getContext().getDirectory(),
452 V->getContext().getFilename());
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000453 assert(FileID && "Invalid file id");
Devang Patelc50078e2009-11-21 02:48:08 +0000454 addUInt(Die, dwarf::DW_AT_decl_file, 0, FileID);
455 addUInt(Die, dwarf::DW_AT_decl_line, 0, Line);
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000456}
457
Devang Patelc50078e2009-11-21 02:48:08 +0000458/// addSourceLine - Add location information to specified debug information
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000459/// entry.
Devang Patelc50078e2009-11-21 02:48:08 +0000460void DwarfDebug::addSourceLine(DIE *Die, const DIGlobal *G) {
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000461 // If there is no compile unit specified, don't add a line #.
Devang Patel9e592492010-03-08 20:52:55 +0000462 if (!G->getCompileUnit().Verify())
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000463 return;
464
465 unsigned Line = G->getLineNumber();
Devang Patel7f9e0f32010-03-08 22:02:50 +0000466 unsigned FileID = GetOrCreateSourceID(G->getContext().getDirectory(),
467 G->getContext().getFilename());
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000468 assert(FileID && "Invalid file id");
Devang Patelc50078e2009-11-21 02:48:08 +0000469 addUInt(Die, dwarf::DW_AT_decl_file, 0, FileID);
470 addUInt(Die, dwarf::DW_AT_decl_line, 0, Line);
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000471}
Devang Patel318d70d2009-08-31 22:47:13 +0000472
Devang Patelc50078e2009-11-21 02:48:08 +0000473/// addSourceLine - Add location information to specified debug information
Devang Patel318d70d2009-08-31 22:47:13 +0000474/// entry.
Devang Patelc50078e2009-11-21 02:48:08 +0000475void DwarfDebug::addSourceLine(DIE *Die, const DISubprogram *SP) {
Devang Patel318d70d2009-08-31 22:47:13 +0000476 // If there is no compile unit specified, don't add a line #.
Devang Patel9e592492010-03-08 20:52:55 +0000477 if (!SP->getCompileUnit().Verify())
Devang Patel318d70d2009-08-31 22:47:13 +0000478 return;
Caroline Tice9da96d82009-09-11 18:25:54 +0000479 // If the line number is 0, don't add it.
480 if (SP->getLineNumber() == 0)
481 return;
482
Devang Patel318d70d2009-08-31 22:47:13 +0000483 unsigned Line = SP->getLineNumber();
Devang Patel7f9e0f32010-03-08 22:02:50 +0000484 if (!SP->getContext().Verify())
485 return;
Devang Patele485a5d2010-03-24 21:30:35 +0000486 unsigned FileID = GetOrCreateSourceID(SP->getDirectory(),
487 SP->getFilename());
Devang Patel318d70d2009-08-31 22:47:13 +0000488 assert(FileID && "Invalid file id");
Devang Patelc50078e2009-11-21 02:48:08 +0000489 addUInt(Die, dwarf::DW_AT_decl_file, 0, FileID);
490 addUInt(Die, dwarf::DW_AT_decl_line, 0, Line);
Devang Patel318d70d2009-08-31 22:47:13 +0000491}
492
Devang Patelc50078e2009-11-21 02:48:08 +0000493/// addSourceLine - Add location information to specified debug information
Devang Patel318d70d2009-08-31 22:47:13 +0000494/// entry.
Devang Patelc50078e2009-11-21 02:48:08 +0000495void DwarfDebug::addSourceLine(DIE *Die, const DIType *Ty) {
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000496 // If there is no compile unit specified, don't add a line #.
497 DICompileUnit CU = Ty->getCompileUnit();
Devang Patel9e592492010-03-08 20:52:55 +0000498 if (!CU.Verify())
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000499 return;
500
501 unsigned Line = Ty->getLineNumber();
Devang Patel7f9e0f32010-03-08 22:02:50 +0000502 if (!Ty->getContext().Verify())
503 return;
504 unsigned FileID = GetOrCreateSourceID(Ty->getContext().getDirectory(),
505 Ty->getContext().getFilename());
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000506 assert(FileID && "Invalid file id");
Devang Patelc50078e2009-11-21 02:48:08 +0000507 addUInt(Die, dwarf::DW_AT_decl_file, 0, FileID);
508 addUInt(Die, dwarf::DW_AT_decl_line, 0, Line);
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000509}
510
Devang Patel8287d662009-12-15 19:16:48 +0000511/// addSourceLine - Add location information to specified debug information
512/// entry.
513void DwarfDebug::addSourceLine(DIE *Die, const DINameSpace *NS) {
514 // If there is no compile unit specified, don't add a line #.
Devang Patel9e592492010-03-08 20:52:55 +0000515 if (!NS->getCompileUnit().Verify())
Devang Patel8287d662009-12-15 19:16:48 +0000516 return;
517
518 unsigned Line = NS->getLineNumber();
519 StringRef FN = NS->getFilename();
520 StringRef Dir = NS->getDirectory();
521
522 unsigned FileID = GetOrCreateSourceID(Dir, FN);
523 assert(FileID && "Invalid file id");
524 addUInt(Die, dwarf::DW_AT_decl_file, 0, FileID);
525 addUInt(Die, dwarf::DW_AT_decl_line, 0, Line);
526}
527
Caroline Tice248d5572009-08-31 21:19:37 +0000528/* Byref variables, in Blocks, are declared by the programmer as
529 "SomeType VarName;", but the compiler creates a
530 __Block_byref_x_VarName struct, and gives the variable VarName
531 either the struct, or a pointer to the struct, as its type. This
532 is necessary for various behind-the-scenes things the compiler
533 needs to do with by-reference variables in blocks.
534
535 However, as far as the original *programmer* is concerned, the
536 variable should still have type 'SomeType', as originally declared.
537
538 The following function dives into the __Block_byref_x_VarName
539 struct to find the original type of the variable. This will be
540 passed back to the code generating the type for the Debug
541 Information Entry for the variable 'VarName'. 'VarName' will then
542 have the original type 'SomeType' in its debug information.
543
544 The original type 'SomeType' will be the type of the field named
545 'VarName' inside the __Block_byref_x_VarName struct.
546
547 NOTE: In order for this to not completely fail on the debugger
548 side, the Debug Information Entry for the variable VarName needs to
549 have a DW_AT_location that tells the debugger how to unwind through
550 the pointers and __Block_byref_x_VarName struct to find the actual
Devang Patelc50078e2009-11-21 02:48:08 +0000551 value of the variable. The function addBlockByrefType does this. */
Caroline Tice248d5572009-08-31 21:19:37 +0000552
553/// Find the type the programmer originally declared the variable to be
554/// and return that type.
555///
Devang Patelc50078e2009-11-21 02:48:08 +0000556DIType DwarfDebug::getBlockByrefType(DIType Ty, std::string Name) {
Caroline Tice248d5572009-08-31 21:19:37 +0000557
558 DIType subType = Ty;
559 unsigned tag = Ty.getTag();
560
561 if (tag == dwarf::DW_TAG_pointer_type) {
Mike Stumpb22cd0f2009-09-30 00:08:22 +0000562 DIDerivedType DTy = DIDerivedType(Ty.getNode());
Caroline Tice248d5572009-08-31 21:19:37 +0000563 subType = DTy.getTypeDerivedFrom();
564 }
565
566 DICompositeType blockStruct = DICompositeType(subType.getNode());
Caroline Tice248d5572009-08-31 21:19:37 +0000567 DIArray Elements = blockStruct.getTypeArray();
568
Caroline Tice248d5572009-08-31 21:19:37 +0000569 for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
570 DIDescriptor Element = Elements.getElement(i);
571 DIDerivedType DT = DIDerivedType(Element.getNode());
Devang Patel7f75bbe2009-11-25 17:36:49 +0000572 if (Name == DT.getName())
Caroline Tice248d5572009-08-31 21:19:37 +0000573 return (DT.getTypeDerivedFrom());
574 }
575
576 return Ty;
577}
578
Devang Patelc50078e2009-11-21 02:48:08 +0000579/// addComplexAddress - Start with the address based on the location provided,
Mike Stumpb22cd0f2009-09-30 00:08:22 +0000580/// and generate the DWARF information necessary to find the actual variable
581/// given the extra address information encoded in the DIVariable, starting from
582/// the starting location. Add the DWARF information to the die.
583///
Devang Patelc50078e2009-11-21 02:48:08 +0000584void DwarfDebug::addComplexAddress(DbgVariable *&DV, DIE *Die,
Mike Stumpb22cd0f2009-09-30 00:08:22 +0000585 unsigned Attribute,
586 const MachineLocation &Location) {
587 const DIVariable &VD = DV->getVariable();
588 DIType Ty = VD.getType();
589
590 // Decode the original location, and use that as the start of the byref
591 // variable's location.
Chris Lattnerbc0027b2010-04-05 00:13:49 +0000592 const TargetRegisterInfo *RI = Asm->TM.getRegisterInfo();
Mike Stumpb22cd0f2009-09-30 00:08:22 +0000593 unsigned Reg = RI->getDwarfRegNum(Location.getReg(), false);
Benjamin Kramer138c7ff2010-03-31 19:34:01 +0000594 DIEBlock *Block = new (DIEValueAllocator) DIEBlock();
Mike Stumpb22cd0f2009-09-30 00:08:22 +0000595
596 if (Location.isReg()) {
597 if (Reg < 32) {
Devang Patelc50078e2009-11-21 02:48:08 +0000598 addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_reg0 + Reg);
Mike Stumpb22cd0f2009-09-30 00:08:22 +0000599 } else {
600 Reg = Reg - dwarf::DW_OP_reg0;
Devang Patelc50078e2009-11-21 02:48:08 +0000601 addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_breg0 + Reg);
602 addUInt(Block, 0, dwarf::DW_FORM_udata, Reg);
Mike Stumpb22cd0f2009-09-30 00:08:22 +0000603 }
604 } else {
605 if (Reg < 32)
Devang Patelc50078e2009-11-21 02:48:08 +0000606 addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_breg0 + Reg);
Mike Stumpb22cd0f2009-09-30 00:08:22 +0000607 else {
Devang Patelc50078e2009-11-21 02:48:08 +0000608 addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_bregx);
609 addUInt(Block, 0, dwarf::DW_FORM_udata, Reg);
Mike Stumpb22cd0f2009-09-30 00:08:22 +0000610 }
611
Devang Patelc50078e2009-11-21 02:48:08 +0000612 addUInt(Block, 0, dwarf::DW_FORM_sdata, Location.getOffset());
Mike Stumpb22cd0f2009-09-30 00:08:22 +0000613 }
614
615 for (unsigned i = 0, N = VD.getNumAddrElements(); i < N; ++i) {
616 uint64_t Element = VD.getAddrElement(i);
617
618 if (Element == DIFactory::OpPlus) {
Devang Patelc50078e2009-11-21 02:48:08 +0000619 addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst);
620 addUInt(Block, 0, dwarf::DW_FORM_udata, VD.getAddrElement(++i));
Mike Stumpb22cd0f2009-09-30 00:08:22 +0000621 } else if (Element == DIFactory::OpDeref) {
Devang Patelc50078e2009-11-21 02:48:08 +0000622 addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_deref);
Mike Stumpb22cd0f2009-09-30 00:08:22 +0000623 } else llvm_unreachable("unknown DIFactory Opcode");
624 }
625
626 // Now attach the location information to the DIE.
Devang Patelc50078e2009-11-21 02:48:08 +0000627 addBlock(Die, Attribute, 0, Block);
Mike Stumpb22cd0f2009-09-30 00:08:22 +0000628}
629
Caroline Tice248d5572009-08-31 21:19:37 +0000630/* Byref variables, in Blocks, are declared by the programmer as "SomeType
631 VarName;", but the compiler creates a __Block_byref_x_VarName struct, and
632 gives the variable VarName either the struct, or a pointer to the struct, as
633 its type. This is necessary for various behind-the-scenes things the
634 compiler needs to do with by-reference variables in Blocks.
635
636 However, as far as the original *programmer* is concerned, the variable
637 should still have type 'SomeType', as originally declared.
638
Devang Patelc50078e2009-11-21 02:48:08 +0000639 The function getBlockByrefType dives into the __Block_byref_x_VarName
Caroline Tice248d5572009-08-31 21:19:37 +0000640 struct to find the original type of the variable, which is then assigned to
641 the variable's Debug Information Entry as its real type. So far, so good.
642 However now the debugger will expect the variable VarName to have the type
643 SomeType. So we need the location attribute for the variable to be an
Daniel Dunbar41716322009-09-19 20:40:05 +0000644 expression that explains to the debugger how to navigate through the
Caroline Tice248d5572009-08-31 21:19:37 +0000645 pointers and struct to find the actual variable of type SomeType.
646
647 The following function does just that. We start by getting
648 the "normal" location for the variable. This will be the location
649 of either the struct __Block_byref_x_VarName or the pointer to the
650 struct __Block_byref_x_VarName.
651
652 The struct will look something like:
653
654 struct __Block_byref_x_VarName {
655 ... <various fields>
656 struct __Block_byref_x_VarName *forwarding;
657 ... <various other fields>
658 SomeType VarName;
659 ... <maybe more fields>
660 };
661
662 If we are given the struct directly (as our starting point) we
663 need to tell the debugger to:
664
665 1). Add the offset of the forwarding field.
666
Dan Gohmandf1a7ff2010-02-10 16:03:48 +0000667 2). Follow that pointer to get the real __Block_byref_x_VarName
Caroline Tice248d5572009-08-31 21:19:37 +0000668 struct to use (the real one may have been copied onto the heap).
669
670 3). Add the offset for the field VarName, to find the actual variable.
671
672 If we started with a pointer to the struct, then we need to
673 dereference that pointer first, before the other steps.
674 Translating this into DWARF ops, we will need to append the following
675 to the current location description for the variable:
676
677 DW_OP_deref -- optional, if we start with a pointer
678 DW_OP_plus_uconst <forward_fld_offset>
679 DW_OP_deref
680 DW_OP_plus_uconst <varName_fld_offset>
681
682 That is what this function does. */
683
Devang Patelc50078e2009-11-21 02:48:08 +0000684/// addBlockByrefAddress - Start with the address based on the location
Caroline Tice248d5572009-08-31 21:19:37 +0000685/// provided, and generate the DWARF information necessary to find the
686/// actual Block variable (navigating the Block struct) based on the
687/// starting location. Add the DWARF information to the die. For
688/// more information, read large comment just above here.
689///
Devang Patelc50078e2009-11-21 02:48:08 +0000690void DwarfDebug::addBlockByrefAddress(DbgVariable *&DV, DIE *Die,
Daniel Dunbar19f1d442009-09-19 20:40:14 +0000691 unsigned Attribute,
692 const MachineLocation &Location) {
Caroline Tice248d5572009-08-31 21:19:37 +0000693 const DIVariable &VD = DV->getVariable();
694 DIType Ty = VD.getType();
695 DIType TmpTy = Ty;
696 unsigned Tag = Ty.getTag();
697 bool isPointer = false;
698
Devang Patel7f75bbe2009-11-25 17:36:49 +0000699 StringRef varName = VD.getName();
Caroline Tice248d5572009-08-31 21:19:37 +0000700
701 if (Tag == dwarf::DW_TAG_pointer_type) {
Mike Stumpb22cd0f2009-09-30 00:08:22 +0000702 DIDerivedType DTy = DIDerivedType(Ty.getNode());
Caroline Tice248d5572009-08-31 21:19:37 +0000703 TmpTy = DTy.getTypeDerivedFrom();
704 isPointer = true;
705 }
706
707 DICompositeType blockStruct = DICompositeType(TmpTy.getNode());
708
Daniel Dunbar19f1d442009-09-19 20:40:14 +0000709 // Find the __forwarding field and the variable field in the __Block_byref
710 // struct.
Daniel Dunbar19f1d442009-09-19 20:40:14 +0000711 DIArray Fields = blockStruct.getTypeArray();
712 DIDescriptor varField = DIDescriptor();
713 DIDescriptor forwardingField = DIDescriptor();
Caroline Tice248d5572009-08-31 21:19:37 +0000714
Daniel Dunbar19f1d442009-09-19 20:40:14 +0000715 for (unsigned i = 0, N = Fields.getNumElements(); i < N; ++i) {
716 DIDescriptor Element = Fields.getElement(i);
717 DIDerivedType DT = DIDerivedType(Element.getNode());
Devang Patel7f75bbe2009-11-25 17:36:49 +0000718 StringRef fieldName = DT.getName();
719 if (fieldName == "__forwarding")
Daniel Dunbar19f1d442009-09-19 20:40:14 +0000720 forwardingField = Element;
Devang Patel7f75bbe2009-11-25 17:36:49 +0000721 else if (fieldName == varName)
Daniel Dunbar19f1d442009-09-19 20:40:14 +0000722 varField = Element;
723 }
Daniel Dunbar41716322009-09-19 20:40:05 +0000724
Daniel Dunbar19f1d442009-09-19 20:40:14 +0000725 // Get the offsets for the forwarding field and the variable field.
Chris Lattner5df82552010-03-31 06:06:37 +0000726 unsigned forwardingFieldOffset =
Daniel Dunbar19f1d442009-09-19 20:40:14 +0000727 DIDerivedType(forwardingField.getNode()).getOffsetInBits() >> 3;
Chris Lattner5df82552010-03-31 06:06:37 +0000728 unsigned varFieldOffset =
Daniel Dunbar19f1d442009-09-19 20:40:14 +0000729 DIDerivedType(varField.getNode()).getOffsetInBits() >> 3;
Caroline Tice248d5572009-08-31 21:19:37 +0000730
Mike Stump2fd84e22009-09-24 23:21:26 +0000731 // Decode the original location, and use that as the start of the byref
732 // variable's location.
Chris Lattnerbc0027b2010-04-05 00:13:49 +0000733 const TargetRegisterInfo *RI = Asm->TM.getRegisterInfo();
Daniel Dunbar19f1d442009-09-19 20:40:14 +0000734 unsigned Reg = RI->getDwarfRegNum(Location.getReg(), false);
Benjamin Kramer138c7ff2010-03-31 19:34:01 +0000735 DIEBlock *Block = new (DIEValueAllocator) DIEBlock();
Caroline Tice248d5572009-08-31 21:19:37 +0000736
Daniel Dunbar19f1d442009-09-19 20:40:14 +0000737 if (Location.isReg()) {
738 if (Reg < 32)
Devang Patelc50078e2009-11-21 02:48:08 +0000739 addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_reg0 + Reg);
Daniel Dunbar19f1d442009-09-19 20:40:14 +0000740 else {
741 Reg = Reg - dwarf::DW_OP_reg0;
Devang Patelc50078e2009-11-21 02:48:08 +0000742 addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_breg0 + Reg);
743 addUInt(Block, 0, dwarf::DW_FORM_udata, Reg);
Daniel Dunbar19f1d442009-09-19 20:40:14 +0000744 }
745 } else {
746 if (Reg < 32)
Devang Patelc50078e2009-11-21 02:48:08 +0000747 addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_breg0 + Reg);
Daniel Dunbar19f1d442009-09-19 20:40:14 +0000748 else {
Devang Patelc50078e2009-11-21 02:48:08 +0000749 addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_bregx);
750 addUInt(Block, 0, dwarf::DW_FORM_udata, Reg);
Daniel Dunbar19f1d442009-09-19 20:40:14 +0000751 }
Caroline Tice248d5572009-08-31 21:19:37 +0000752
Devang Patelc50078e2009-11-21 02:48:08 +0000753 addUInt(Block, 0, dwarf::DW_FORM_sdata, Location.getOffset());
Daniel Dunbar19f1d442009-09-19 20:40:14 +0000754 }
Caroline Tice248d5572009-08-31 21:19:37 +0000755
Mike Stump2fd84e22009-09-24 23:21:26 +0000756 // If we started with a pointer to the __Block_byref... struct, then
Daniel Dunbar19f1d442009-09-19 20:40:14 +0000757 // the first thing we need to do is dereference the pointer (DW_OP_deref).
Daniel Dunbar19f1d442009-09-19 20:40:14 +0000758 if (isPointer)
Devang Patelc50078e2009-11-21 02:48:08 +0000759 addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_deref);
Caroline Tice248d5572009-08-31 21:19:37 +0000760
Daniel Dunbar19f1d442009-09-19 20:40:14 +0000761 // Next add the offset for the '__forwarding' field:
762 // DW_OP_plus_uconst ForwardingFieldOffset. Note there's no point in
763 // adding the offset if it's 0.
Daniel Dunbar19f1d442009-09-19 20:40:14 +0000764 if (forwardingFieldOffset > 0) {
Devang Patelc50078e2009-11-21 02:48:08 +0000765 addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst);
766 addUInt(Block, 0, dwarf::DW_FORM_udata, forwardingFieldOffset);
Daniel Dunbar19f1d442009-09-19 20:40:14 +0000767 }
Caroline Tice248d5572009-08-31 21:19:37 +0000768
Daniel Dunbar19f1d442009-09-19 20:40:14 +0000769 // Now dereference the __forwarding field to get to the real __Block_byref
770 // struct: DW_OP_deref.
Devang Patelc50078e2009-11-21 02:48:08 +0000771 addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_deref);
Caroline Tice248d5572009-08-31 21:19:37 +0000772
Daniel Dunbar19f1d442009-09-19 20:40:14 +0000773 // Now that we've got the real __Block_byref... struct, add the offset
774 // for the variable's field to get to the location of the actual variable:
775 // DW_OP_plus_uconst varFieldOffset. Again, don't add if it's 0.
Daniel Dunbar19f1d442009-09-19 20:40:14 +0000776 if (varFieldOffset > 0) {
Devang Patelc50078e2009-11-21 02:48:08 +0000777 addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst);
778 addUInt(Block, 0, dwarf::DW_FORM_udata, varFieldOffset);
Daniel Dunbar19f1d442009-09-19 20:40:14 +0000779 }
Caroline Tice248d5572009-08-31 21:19:37 +0000780
Daniel Dunbar19f1d442009-09-19 20:40:14 +0000781 // Now attach the location information to the DIE.
Devang Patelc50078e2009-11-21 02:48:08 +0000782 addBlock(Die, Attribute, 0, Block);
Caroline Tice248d5572009-08-31 21:19:37 +0000783}
784
Devang Patelc50078e2009-11-21 02:48:08 +0000785/// addAddress - Add an address attribute to a die based on the location
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000786/// provided.
Devang Patelc50078e2009-11-21 02:48:08 +0000787void DwarfDebug::addAddress(DIE *Die, unsigned Attribute,
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000788 const MachineLocation &Location) {
Chris Lattnerbc0027b2010-04-05 00:13:49 +0000789 const TargetRegisterInfo *RI = Asm->TM.getRegisterInfo();
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000790 unsigned Reg = RI->getDwarfRegNum(Location.getReg(), false);
Benjamin Kramer138c7ff2010-03-31 19:34:01 +0000791 DIEBlock *Block = new (DIEValueAllocator) DIEBlock();
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000792
793 if (Location.isReg()) {
794 if (Reg < 32) {
Devang Patelc50078e2009-11-21 02:48:08 +0000795 addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_reg0 + Reg);
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000796 } else {
Devang Patelc50078e2009-11-21 02:48:08 +0000797 addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_regx);
798 addUInt(Block, 0, dwarf::DW_FORM_udata, Reg);
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000799 }
800 } else {
801 if (Reg < 32) {
Devang Patelc50078e2009-11-21 02:48:08 +0000802 addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_breg0 + Reg);
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000803 } else {
Devang Patelc50078e2009-11-21 02:48:08 +0000804 addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_bregx);
805 addUInt(Block, 0, dwarf::DW_FORM_udata, Reg);
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000806 }
807
Devang Patelc50078e2009-11-21 02:48:08 +0000808 addUInt(Block, 0, dwarf::DW_FORM_sdata, Location.getOffset());
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000809 }
810
Devang Patelc50078e2009-11-21 02:48:08 +0000811 addBlock(Die, Attribute, 0, Block);
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000812}
813
Devang Patel1a8f9a82009-12-10 19:14:49 +0000814/// addToContextOwner - Add Die into the list of its context owner's children.
815void DwarfDebug::addToContextOwner(DIE *Die, DIDescriptor Context) {
Devang Patel9e592492010-03-08 20:52:55 +0000816 if (Context.isType()) {
Devang Patel1a8f9a82009-12-10 19:14:49 +0000817 DIE *ContextDIE = getOrCreateTypeDIE(DIType(Context.getNode()));
818 ContextDIE->addChild(Die);
Devang Patel8287d662009-12-15 19:16:48 +0000819 } else if (Context.isNameSpace()) {
820 DIE *ContextDIE = getOrCreateNameSpace(DINameSpace(Context.getNode()));
821 ContextDIE->addChild(Die);
Devang Patel1a8f9a82009-12-10 19:14:49 +0000822 } else if (DIE *ContextDIE = ModuleCU->getDIE(Context.getNode()))
823 ContextDIE->addChild(Die);
824 else
825 ModuleCU->addDie(Die);
826}
827
Devang Patel7f139c12009-12-10 18:05:33 +0000828/// getOrCreateTypeDIE - Find existing DIE or create new DIE for the
829/// given DIType.
830DIE *DwarfDebug::getOrCreateTypeDIE(DIType Ty) {
831 DIE *TyDIE = ModuleCU->getDIE(Ty.getNode());
832 if (TyDIE)
833 return TyDIE;
834
835 // Create new type.
836 TyDIE = new DIE(dwarf::DW_TAG_base_type);
837 ModuleCU->insertDIE(Ty.getNode(), TyDIE);
838 if (Ty.isBasicType())
839 constructTypeDIE(*TyDIE, DIBasicType(Ty.getNode()));
840 else if (Ty.isCompositeType())
841 constructTypeDIE(*TyDIE, DICompositeType(Ty.getNode()));
842 else {
843 assert(Ty.isDerivedType() && "Unknown kind of DIType");
844 constructTypeDIE(*TyDIE, DIDerivedType(Ty.getNode()));
845 }
846
Devang Patel1a8f9a82009-12-10 19:14:49 +0000847 addToContextOwner(TyDIE, Ty.getContext());
Devang Patel7f139c12009-12-10 18:05:33 +0000848 return TyDIE;
849}
850
Devang Patelc50078e2009-11-21 02:48:08 +0000851/// addType - Add a new type attribute to the specified entity.
Devang Patelfe0be132009-12-09 18:24:21 +0000852void DwarfDebug::addType(DIE *Entity, DIType Ty) {
Devang Patel9e592492010-03-08 20:52:55 +0000853 if (!Ty.isValid())
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000854 return;
855
856 // Check for pre-existence.
Devang Patelfe0be132009-12-09 18:24:21 +0000857 DIEEntry *Entry = ModuleCU->getDIEEntry(Ty.getNode());
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000858 // If it exists then use the existing value.
Devang Patelc50078e2009-11-21 02:48:08 +0000859 if (Entry) {
860 Entity->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, Entry);
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000861 return;
862 }
863
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000864 // Construct type.
Devang Patel7f139c12009-12-10 18:05:33 +0000865 DIE *Buffer = getOrCreateTypeDIE(Ty);
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000866
Jeffrey Yasskinecca2e62010-03-12 17:45:06 +0000867 // Set up proxy.
868 Entry = createDIEEntry(Buffer);
869 ModuleCU->insertDIEEntry(Ty.getNode(), Entry);
870
Devang Patelc50078e2009-11-21 02:48:08 +0000871 Entity->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, Entry);
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000872}
873
Devang Patelc50078e2009-11-21 02:48:08 +0000874/// constructTypeDIE - Construct basic type die from DIBasicType.
Devang Patelfe0be132009-12-09 18:24:21 +0000875void DwarfDebug::constructTypeDIE(DIE &Buffer, DIBasicType BTy) {
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000876 // Get core information.
Devang Patel7f75bbe2009-11-25 17:36:49 +0000877 StringRef Name = BTy.getName();
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000878 Buffer.setTag(dwarf::DW_TAG_base_type);
Devang Patelc50078e2009-11-21 02:48:08 +0000879 addUInt(&Buffer, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1,
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000880 BTy.getEncoding());
881
882 // Add name if not anonymous or intermediate type.
Devang Patel7f75bbe2009-11-25 17:36:49 +0000883 if (!Name.empty())
Devang Patelc50078e2009-11-21 02:48:08 +0000884 addString(&Buffer, dwarf::DW_AT_name, dwarf::DW_FORM_string, Name);
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000885 uint64_t Size = BTy.getSizeInBits() >> 3;
Devang Patelc50078e2009-11-21 02:48:08 +0000886 addUInt(&Buffer, dwarf::DW_AT_byte_size, 0, Size);
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000887}
888
Devang Patelc50078e2009-11-21 02:48:08 +0000889/// constructTypeDIE - Construct derived type die from DIDerivedType.
Devang Patelfe0be132009-12-09 18:24:21 +0000890void DwarfDebug::constructTypeDIE(DIE &Buffer, DIDerivedType DTy) {
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000891 // Get core information.
Devang Patel7f75bbe2009-11-25 17:36:49 +0000892 StringRef Name = DTy.getName();
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000893 uint64_t Size = DTy.getSizeInBits() >> 3;
894 unsigned Tag = DTy.getTag();
895
896 // FIXME - Workaround for templates.
897 if (Tag == dwarf::DW_TAG_inheritance) Tag = dwarf::DW_TAG_reference_type;
898
899 Buffer.setTag(Tag);
900
901 // Map to main type, void will not have a type.
902 DIType FromTy = DTy.getTypeDerivedFrom();
Devang Patelfe0be132009-12-09 18:24:21 +0000903 addType(&Buffer, FromTy);
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000904
905 // Add name if not anonymous or intermediate type.
Devang Patel76b80672009-11-30 23:56:56 +0000906 if (!Name.empty())
Devang Patelc50078e2009-11-21 02:48:08 +0000907 addString(&Buffer, dwarf::DW_AT_name, dwarf::DW_FORM_string, Name);
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000908
909 // Add size if non-zero (derived types might be zero-sized.)
910 if (Size)
Devang Patelc50078e2009-11-21 02:48:08 +0000911 addUInt(&Buffer, dwarf::DW_AT_byte_size, 0, Size);
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000912
913 // Add source line info if available and TyDesc is not a forward declaration.
Devang Patelb125c6e2009-11-23 18:43:37 +0000914 if (!DTy.isForwardDecl())
Devang Patelc50078e2009-11-21 02:48:08 +0000915 addSourceLine(&Buffer, &DTy);
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000916}
917
Devang Patelc50078e2009-11-21 02:48:08 +0000918/// constructTypeDIE - Construct type DIE from DICompositeType.
Devang Patelfe0be132009-12-09 18:24:21 +0000919void DwarfDebug::constructTypeDIE(DIE &Buffer, DICompositeType CTy) {
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000920 // Get core information.
Devang Patel7f75bbe2009-11-25 17:36:49 +0000921 StringRef Name = CTy.getName();
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000922
923 uint64_t Size = CTy.getSizeInBits() >> 3;
924 unsigned Tag = CTy.getTag();
925 Buffer.setTag(Tag);
926
927 switch (Tag) {
928 case dwarf::DW_TAG_vector_type:
929 case dwarf::DW_TAG_array_type:
Devang Patelfe0be132009-12-09 18:24:21 +0000930 constructArrayTypeDIE(Buffer, &CTy);
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000931 break;
932 case dwarf::DW_TAG_enumeration_type: {
933 DIArray Elements = CTy.getTypeArray();
934
935 // Add enumerators to enumeration type.
936 for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
937 DIE *ElemDie = NULL;
Devang Patel9e592492010-03-08 20:52:55 +0000938 DIDescriptor Enum(Elements.getElement(i).getNode());
939 if (Enum.isEnumerator()) {
940 ElemDie = constructEnumTypeDIE(DIEnumerator(Enum.getNode()));
Devang Patelc50078e2009-11-21 02:48:08 +0000941 Buffer.addChild(ElemDie);
Devang Patelfb812752009-10-09 17:51:49 +0000942 }
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000943 }
944 }
945 break;
946 case dwarf::DW_TAG_subroutine_type: {
947 // Add return type.
948 DIArray Elements = CTy.getTypeArray();
949 DIDescriptor RTy = Elements.getElement(0);
Devang Patelfe0be132009-12-09 18:24:21 +0000950 addType(&Buffer, DIType(RTy.getNode()));
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000951
952 // Add prototype flag.
Devang Patelc50078e2009-11-21 02:48:08 +0000953 addUInt(&Buffer, dwarf::DW_AT_prototyped, dwarf::DW_FORM_flag, 1);
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000954
955 // Add arguments.
956 for (unsigned i = 1, N = Elements.getNumElements(); i < N; ++i) {
957 DIE *Arg = new DIE(dwarf::DW_TAG_formal_parameter);
958 DIDescriptor Ty = Elements.getElement(i);
Devang Patelfe0be132009-12-09 18:24:21 +0000959 addType(Arg, DIType(Ty.getNode()));
Devang Patelc50078e2009-11-21 02:48:08 +0000960 Buffer.addChild(Arg);
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000961 }
962 }
963 break;
964 case dwarf::DW_TAG_structure_type:
965 case dwarf::DW_TAG_union_type:
966 case dwarf::DW_TAG_class_type: {
967 // Add elements to structure type.
968 DIArray Elements = CTy.getTypeArray();
969
970 // A forward struct declared type may not have elements available.
Devang Patel9e592492010-03-08 20:52:55 +0000971 unsigned N = Elements.getNumElements();
972 if (N == 0)
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000973 break;
974
975 // Add elements to structure type.
Devang Patel9e592492010-03-08 20:52:55 +0000976 for (unsigned i = 0; i < N; ++i) {
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000977 DIDescriptor Element = Elements.getElement(i);
978 DIE *ElemDie = NULL;
Devang Patel9e592492010-03-08 20:52:55 +0000979 if (Element.isSubprogram())
Devang Patel814a12c2009-12-14 16:18:45 +0000980 ElemDie = createSubprogramDIE(DISubprogram(Element.getNode()));
Devang Patel9e592492010-03-08 20:52:55 +0000981 else if (Element.isVariable()) {
Devang Patel423dfa02010-01-30 01:08:30 +0000982 DIVariable DV(Element.getNode());
983 ElemDie = new DIE(dwarf::DW_TAG_variable);
984 addString(ElemDie, dwarf::DW_AT_name, dwarf::DW_FORM_string,
985 DV.getName());
986 addType(ElemDie, DV.getType());
987 addUInt(ElemDie, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag, 1);
988 addUInt(ElemDie, dwarf::DW_AT_external, dwarf::DW_FORM_flag, 1);
989 addSourceLine(ElemDie, &DV);
Devang Patel9e592492010-03-08 20:52:55 +0000990 } else if (Element.isDerivedType())
Devang Patelfe0be132009-12-09 18:24:21 +0000991 ElemDie = createMemberDIE(DIDerivedType(Element.getNode()));
Devang Patel9e592492010-03-08 20:52:55 +0000992 else
993 continue;
Devang Patelc50078e2009-11-21 02:48:08 +0000994 Buffer.addChild(ElemDie);
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000995 }
996
Devang Patel20b32102009-08-27 23:51:51 +0000997 if (CTy.isAppleBlockExtension())
Devang Patelc50078e2009-11-21 02:48:08 +0000998 addUInt(&Buffer, dwarf::DW_AT_APPLE_block, dwarf::DW_FORM_flag, 1);
Bill Wendlingb12b3d72009-05-15 09:23:25 +0000999
1000 unsigned RLang = CTy.getRunTimeLang();
1001 if (RLang)
Devang Patelc50078e2009-11-21 02:48:08 +00001002 addUInt(&Buffer, dwarf::DW_AT_APPLE_runtime_class,
Bill Wendlingb12b3d72009-05-15 09:23:25 +00001003 dwarf::DW_FORM_data1, RLang);
Devang Patel5ae52402010-01-26 21:16:06 +00001004
1005 DICompositeType ContainingType = CTy.getContainingType();
Devang Patel9e592492010-03-08 20:52:55 +00001006 if (DIDescriptor(ContainingType.getNode()).isCompositeType())
Devang Patel5ae52402010-01-26 21:16:06 +00001007 addDIEEntry(&Buffer, dwarf::DW_AT_containing_type, dwarf::DW_FORM_ref4,
1008 getOrCreateTypeDIE(DIType(ContainingType.getNode())));
Bill Wendlingb12b3d72009-05-15 09:23:25 +00001009 break;
1010 }
1011 default:
1012 break;
1013 }
1014
1015 // Add name if not anonymous or intermediate type.
Devang Patel7f75bbe2009-11-25 17:36:49 +00001016 if (!Name.empty())
Devang Patelc50078e2009-11-21 02:48:08 +00001017 addString(&Buffer, dwarf::DW_AT_name, dwarf::DW_FORM_string, Name);
Bill Wendlingb12b3d72009-05-15 09:23:25 +00001018
Devang Pateldc73c372010-01-29 18:34:58 +00001019 if (Tag == dwarf::DW_TAG_enumeration_type || Tag == dwarf::DW_TAG_class_type ||
Bill Wendlingb12b3d72009-05-15 09:23:25 +00001020 Tag == dwarf::DW_TAG_structure_type || Tag == dwarf::DW_TAG_union_type) {
1021 // Add size if non-zero (derived types might be zero-sized.)
1022 if (Size)
Devang Patelc50078e2009-11-21 02:48:08 +00001023 addUInt(&Buffer, dwarf::DW_AT_byte_size, 0, Size);
Bill Wendlingb12b3d72009-05-15 09:23:25 +00001024 else {
1025 // Add zero size if it is not a forward declaration.
1026 if (CTy.isForwardDecl())
Devang Patelc50078e2009-11-21 02:48:08 +00001027 addUInt(&Buffer, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag, 1);
Bill Wendlingb12b3d72009-05-15 09:23:25 +00001028 else
Devang Patelc50078e2009-11-21 02:48:08 +00001029 addUInt(&Buffer, dwarf::DW_AT_byte_size, 0, 0);
Bill Wendlingb12b3d72009-05-15 09:23:25 +00001030 }
1031
1032 // Add source line info if available.
1033 if (!CTy.isForwardDecl())
Devang Patelc50078e2009-11-21 02:48:08 +00001034 addSourceLine(&Buffer, &CTy);
Bill Wendlingb12b3d72009-05-15 09:23:25 +00001035 }
1036}
1037
Devang Patelc50078e2009-11-21 02:48:08 +00001038/// constructSubrangeDIE - Construct subrange DIE from DISubrange.
1039void DwarfDebug::constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy){
Bill Wendlingb12b3d72009-05-15 09:23:25 +00001040 int64_t L = SR.getLo();
1041 int64_t H = SR.getHi();
1042 DIE *DW_Subrange = new DIE(dwarf::DW_TAG_subrange_type);
1043
Devang Patelc50078e2009-11-21 02:48:08 +00001044 addDIEEntry(DW_Subrange, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, IndexTy);
Devang Patele7ff5092009-08-14 20:59:16 +00001045 if (L)
Devang Patelc50078e2009-11-21 02:48:08 +00001046 addSInt(DW_Subrange, dwarf::DW_AT_lower_bound, 0, L);
Devang Pateld3df6972009-12-04 23:10:24 +00001047 addSInt(DW_Subrange, dwarf::DW_AT_upper_bound, 0, H);
Bill Wendlingb12b3d72009-05-15 09:23:25 +00001048
Devang Patelc50078e2009-11-21 02:48:08 +00001049 Buffer.addChild(DW_Subrange);
Bill Wendlingb12b3d72009-05-15 09:23:25 +00001050}
1051
Devang Patelc50078e2009-11-21 02:48:08 +00001052/// constructArrayTypeDIE - Construct array type DIE from DICompositeType.
Devang Patelfe0be132009-12-09 18:24:21 +00001053void DwarfDebug::constructArrayTypeDIE(DIE &Buffer,
Bill Wendlingb12b3d72009-05-15 09:23:25 +00001054 DICompositeType *CTy) {
1055 Buffer.setTag(dwarf::DW_TAG_array_type);
1056 if (CTy->getTag() == dwarf::DW_TAG_vector_type)
Devang Patelc50078e2009-11-21 02:48:08 +00001057 addUInt(&Buffer, dwarf::DW_AT_GNU_vector, dwarf::DW_FORM_flag, 1);
Bill Wendlingb12b3d72009-05-15 09:23:25 +00001058
1059 // Emit derived type.
Devang Patelfe0be132009-12-09 18:24:21 +00001060 addType(&Buffer, CTy->getTypeDerivedFrom());
Bill Wendlingb12b3d72009-05-15 09:23:25 +00001061 DIArray Elements = CTy->getTypeArray();
1062
Devang Patel1233f912009-11-21 00:31:03 +00001063 // Get an anonymous type for index type.
Devang Patelfe0be132009-12-09 18:24:21 +00001064 DIE *IdxTy = ModuleCU->getIndexTyDie();
Devang Patel1233f912009-11-21 00:31:03 +00001065 if (!IdxTy) {
1066 // Construct an anonymous type for index type.
1067 IdxTy = new DIE(dwarf::DW_TAG_base_type);
Devang Patelc50078e2009-11-21 02:48:08 +00001068 addUInt(IdxTy, dwarf::DW_AT_byte_size, 0, sizeof(int32_t));
1069 addUInt(IdxTy, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1,
Devang Patel1233f912009-11-21 00:31:03 +00001070 dwarf::DW_ATE_signed);
Devang Patelfe0be132009-12-09 18:24:21 +00001071 ModuleCU->addDie(IdxTy);
1072 ModuleCU->setIndexTyDie(IdxTy);
Devang Patel1233f912009-11-21 00:31:03 +00001073 }
Bill Wendlingb12b3d72009-05-15 09:23:25 +00001074
1075 // Add subranges to array type.
1076 for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
1077 DIDescriptor Element = Elements.getElement(i);
1078 if (Element.getTag() == dwarf::DW_TAG_subrange_type)
Devang Patelc50078e2009-11-21 02:48:08 +00001079 constructSubrangeDIE(Buffer, DISubrange(Element.getNode()), IdxTy);
Bill Wendlingb12b3d72009-05-15 09:23:25 +00001080 }
1081}
1082
Devang Patelc50078e2009-11-21 02:48:08 +00001083/// constructEnumTypeDIE - Construct enum type DIE from DIEnumerator.
Devang Patel9e592492010-03-08 20:52:55 +00001084DIE *DwarfDebug::constructEnumTypeDIE(DIEnumerator ETy) {
Bill Wendlingb12b3d72009-05-15 09:23:25 +00001085 DIE *Enumerator = new DIE(dwarf::DW_TAG_enumerator);
Devang Patel9e592492010-03-08 20:52:55 +00001086 StringRef Name = ETy.getName();
Devang Patelc50078e2009-11-21 02:48:08 +00001087 addString(Enumerator, dwarf::DW_AT_name, dwarf::DW_FORM_string, Name);
Devang Patel9e592492010-03-08 20:52:55 +00001088 int64_t Value = ETy.getEnumValue();
Devang Patelc50078e2009-11-21 02:48:08 +00001089 addSInt(Enumerator, dwarf::DW_AT_const_value, dwarf::DW_FORM_sdata, Value);
Bill Wendlingb12b3d72009-05-15 09:23:25 +00001090 return Enumerator;
1091}
1092
Devang Patel141e1c42010-01-05 01:46:14 +00001093/// getRealLinkageName - If special LLVM prefix that is used to inform the asm
1094/// printer to not emit usual symbol prefix before the symbol name is used then
1095/// return linkage name after skipping this special LLVM prefix.
1096static StringRef getRealLinkageName(StringRef LinkageName) {
1097 char One = '\1';
1098 if (LinkageName.startswith(StringRef(&One, 1)))
1099 return LinkageName.substr(1);
1100 return LinkageName;
1101}
1102
Devang Patelc50078e2009-11-21 02:48:08 +00001103/// createGlobalVariableDIE - Create new DIE using GV.
Devang Patelfe0be132009-12-09 18:24:21 +00001104DIE *DwarfDebug::createGlobalVariableDIE(const DIGlobalVariable &GV) {
Jim Grosbachb23f2422009-11-22 19:20:36 +00001105 // If the global variable was optmized out then no need to create debug info
1106 // entry.
Devang Patel83e42c72009-11-06 17:58:12 +00001107 if (!GV.getGlobal()) return NULL;
Devang Patel7f75bbe2009-11-25 17:36:49 +00001108 if (GV.getDisplayName().empty()) return NULL;
Devang Patelfabc47c2009-11-06 01:30:04 +00001109
Bill Wendlingb12b3d72009-05-15 09:23:25 +00001110 DIE *GVDie = new DIE(dwarf::DW_TAG_variable);
Jim Grosbach652b7432009-11-21 23:12:12 +00001111 addString(GVDie, dwarf::DW_AT_name, dwarf::DW_FORM_string,
Devang Patelaaf012e2009-09-29 18:40:58 +00001112 GV.getDisplayName());
1113
Devang Patel7f75bbe2009-11-25 17:36:49 +00001114 StringRef LinkageName = GV.getLinkageName();
Devang Patel141e1c42010-01-05 01:46:14 +00001115 if (!LinkageName.empty())
Devang Patelc50078e2009-11-21 02:48:08 +00001116 addString(GVDie, dwarf::DW_AT_MIPS_linkage_name, dwarf::DW_FORM_string,
Devang Patel141e1c42010-01-05 01:46:14 +00001117 getRealLinkageName(LinkageName));
1118
Devang Patelfe0be132009-12-09 18:24:21 +00001119 addType(GVDie, GV.getType());
Bill Wendlingb12b3d72009-05-15 09:23:25 +00001120 if (!GV.isLocalToUnit())
Devang Patelc50078e2009-11-21 02:48:08 +00001121 addUInt(GVDie, dwarf::DW_AT_external, dwarf::DW_FORM_flag, 1);
1122 addSourceLine(GVDie, &GV);
Devang Patel6bd5cc82009-10-05 23:22:08 +00001123
Bill Wendlingb12b3d72009-05-15 09:23:25 +00001124 return GVDie;
1125}
1126
Devang Patelc50078e2009-11-21 02:48:08 +00001127/// createMemberDIE - Create new member DIE.
Devang Patelfe0be132009-12-09 18:24:21 +00001128DIE *DwarfDebug::createMemberDIE(const DIDerivedType &DT) {
Bill Wendlingb12b3d72009-05-15 09:23:25 +00001129 DIE *MemberDie = new DIE(DT.getTag());
Devang Patel7f75bbe2009-11-25 17:36:49 +00001130 StringRef Name = DT.getName();
1131 if (!Name.empty())
Devang Patelc50078e2009-11-21 02:48:08 +00001132 addString(MemberDie, dwarf::DW_AT_name, dwarf::DW_FORM_string, Name);
Devang Patel7f75bbe2009-11-25 17:36:49 +00001133
Devang Patelfe0be132009-12-09 18:24:21 +00001134 addType(MemberDie, DT.getTypeDerivedFrom());
Bill Wendlingb12b3d72009-05-15 09:23:25 +00001135
Devang Patelc50078e2009-11-21 02:48:08 +00001136 addSourceLine(MemberDie, &DT);
Bill Wendlingb12b3d72009-05-15 09:23:25 +00001137
Benjamin Kramer138c7ff2010-03-31 19:34:01 +00001138 DIEBlock *MemLocationDie = new (DIEValueAllocator) DIEBlock();
Devang Patelc50078e2009-11-21 02:48:08 +00001139 addUInt(MemLocationDie, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst);
Devang Patel7d9fe582009-11-04 22:06:12 +00001140
Bill Wendlingb12b3d72009-05-15 09:23:25 +00001141 uint64_t Size = DT.getSizeInBits();
Devang Patel71842a92009-11-04 23:48:00 +00001142 uint64_t FieldSize = DT.getOriginalTypeSize();
Bill Wendlingb12b3d72009-05-15 09:23:25 +00001143
1144 if (Size != FieldSize) {
1145 // Handle bitfield.
Devang Patelc50078e2009-11-21 02:48:08 +00001146 addUInt(MemberDie, dwarf::DW_AT_byte_size, 0, DT.getOriginalTypeSize()>>3);
1147 addUInt(MemberDie, dwarf::DW_AT_bit_size, 0, DT.getSizeInBits());
Bill Wendlingb12b3d72009-05-15 09:23:25 +00001148
1149 uint64_t Offset = DT.getOffsetInBits();
Bill Wendlingb12b3d72009-05-15 09:23:25 +00001150 uint64_t AlignMask = ~(DT.getAlignInBits() - 1);
1151 uint64_t HiMark = (Offset + FieldSize) & AlignMask;
Benjamin Kramer631e3e32010-01-07 17:50:57 +00001152 uint64_t FieldOffset = (HiMark - FieldSize);
Bill Wendlingb12b3d72009-05-15 09:23:25 +00001153 Offset -= FieldOffset;
1154
1155 // Maybe we need to work from the other end.
Chris Lattnerbc0027b2010-04-05 00:13:49 +00001156 if (Asm->getTargetData().isLittleEndian())
1157 Offset = FieldSize - (Offset + Size);
Devang Patelc50078e2009-11-21 02:48:08 +00001158 addUInt(MemberDie, dwarf::DW_AT_bit_offset, 0, Offset);
Bill Wendlingb12b3d72009-05-15 09:23:25 +00001159
Devang Patel7d9fe582009-11-04 22:06:12 +00001160 // Here WD_AT_data_member_location points to the anonymous
1161 // field that includes this bit field.
Devang Patelc50078e2009-11-21 02:48:08 +00001162 addUInt(MemLocationDie, 0, dwarf::DW_FORM_udata, FieldOffset >> 3);
Devang Patel7d9fe582009-11-04 22:06:12 +00001163
1164 } else
1165 // This is not a bitfield.
Devang Patelc50078e2009-11-21 02:48:08 +00001166 addUInt(MemLocationDie, 0, dwarf::DW_FORM_udata, DT.getOffsetInBits() >> 3);
Devang Patel7d9fe582009-11-04 22:06:12 +00001167
Devang Patel84aba942010-02-03 20:08:48 +00001168 if (DT.getTag() == dwarf::DW_TAG_inheritance
1169 && DT.isVirtual()) {
1170
1171 // For C++, virtual base classes are not at fixed offset. Use following
1172 // expression to extract appropriate offset from vtable.
1173 // BaseAddr = ObAddr + *((*ObAddr) - Offset)
1174
Benjamin Kramer138c7ff2010-03-31 19:34:01 +00001175 DIEBlock *VBaseLocationDie = new (DIEValueAllocator) DIEBlock();
Devang Patel84aba942010-02-03 20:08:48 +00001176 addUInt(VBaseLocationDie, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_dup);
1177 addUInt(VBaseLocationDie, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_deref);
1178 addUInt(VBaseLocationDie, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_constu);
1179 addUInt(VBaseLocationDie, 0, dwarf::DW_FORM_udata, DT.getOffsetInBits());
1180 addUInt(VBaseLocationDie, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_minus);
1181 addUInt(VBaseLocationDie, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_deref);
1182 addUInt(VBaseLocationDie, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_plus);
1183
1184 addBlock(MemberDie, dwarf::DW_AT_data_member_location, 0,
1185 VBaseLocationDie);
1186 } else
1187 addBlock(MemberDie, dwarf::DW_AT_data_member_location, 0, MemLocationDie);
Bill Wendlingb12b3d72009-05-15 09:23:25 +00001188
1189 if (DT.isProtected())
Devang Patel188c85d2009-12-03 19:11:07 +00001190 addUInt(MemberDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_flag,
Bill Wendlingb12b3d72009-05-15 09:23:25 +00001191 dwarf::DW_ACCESS_protected);
1192 else if (DT.isPrivate())
Devang Patel188c85d2009-12-03 19:11:07 +00001193 addUInt(MemberDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_flag,
Bill Wendlingb12b3d72009-05-15 09:23:25 +00001194 dwarf::DW_ACCESS_private);
Devang Patel188c85d2009-12-03 19:11:07 +00001195 else if (DT.getTag() == dwarf::DW_TAG_inheritance)
1196 addUInt(MemberDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_flag,
1197 dwarf::DW_ACCESS_public);
1198 if (DT.isVirtual())
1199 addUInt(MemberDie, dwarf::DW_AT_virtuality, dwarf::DW_FORM_flag,
1200 dwarf::DW_VIRTUALITY_virtual);
Bill Wendlingb12b3d72009-05-15 09:23:25 +00001201 return MemberDie;
1202}
1203
Devang Patel814a12c2009-12-14 16:18:45 +00001204/// createSubprogramDIE - Create new DIE using SP.
1205DIE *DwarfDebug::createSubprogramDIE(const DISubprogram &SP, bool MakeDecl) {
1206 DIE *SPDie = ModuleCU->getDIE(SP.getNode());
1207 if (SPDie)
1208 return SPDie;
1209
1210 SPDie = new DIE(dwarf::DW_TAG_subprogram);
Devang Patel36cd9f82010-03-02 17:58:15 +00001211 // Constructors and operators for anonymous aggregates do not have names.
Devang Patel0ab194f2010-03-02 01:26:20 +00001212 if (!SP.getName().empty())
1213 addString(SPDie, dwarf::DW_AT_name, dwarf::DW_FORM_string, SP.getName());
Bill Wendlingb12b3d72009-05-15 09:23:25 +00001214
Devang Patel7f75bbe2009-11-25 17:36:49 +00001215 StringRef LinkageName = SP.getLinkageName();
Devang Patel141e1c42010-01-05 01:46:14 +00001216 if (!LinkageName.empty())
Devang Patelc50078e2009-11-21 02:48:08 +00001217 addString(SPDie, dwarf::DW_AT_MIPS_linkage_name, dwarf::DW_FORM_string,
Devang Patel141e1c42010-01-05 01:46:14 +00001218 getRealLinkageName(LinkageName));
1219
Devang Patelc50078e2009-11-21 02:48:08 +00001220 addSourceLine(SPDie, &SP);
Bill Wendlingb12b3d72009-05-15 09:23:25 +00001221
Bill Wendlingb12b3d72009-05-15 09:23:25 +00001222 // Add prototyped tag, if C or ObjC.
1223 unsigned Lang = SP.getCompileUnit().getLanguage();
1224 if (Lang == dwarf::DW_LANG_C99 || Lang == dwarf::DW_LANG_C89 ||
1225 Lang == dwarf::DW_LANG_ObjC)
Devang Patelc50078e2009-11-21 02:48:08 +00001226 addUInt(SPDie, dwarf::DW_AT_prototyped, dwarf::DW_FORM_flag, 1);
Bill Wendlingb12b3d72009-05-15 09:23:25 +00001227
1228 // Add Return Type.
Devang Patelc1df8792009-12-03 01:25:38 +00001229 DICompositeType SPTy = SP.getType();
1230 DIArray Args = SPTy.getTypeArray();
Bill Wendlingb12b3d72009-05-15 09:23:25 +00001231 unsigned SPTag = SPTy.getTag();
Devang Patel188c85d2009-12-03 19:11:07 +00001232
Devang Patel9e592492010-03-08 20:52:55 +00001233 if (Args.getNumElements() == 0 || SPTag != dwarf::DW_TAG_subroutine_type)
Devang Patelfe0be132009-12-09 18:24:21 +00001234 addType(SPDie, SPTy);
Devang Patelc1df8792009-12-03 01:25:38 +00001235 else
Devang Patelfe0be132009-12-09 18:24:21 +00001236 addType(SPDie, DIType(Args.getElement(0).getNode()));
Devang Patelc1df8792009-12-03 01:25:38 +00001237
Devang Patel188c85d2009-12-03 19:11:07 +00001238 unsigned VK = SP.getVirtuality();
1239 if (VK) {
1240 addUInt(SPDie, dwarf::DW_AT_virtuality, dwarf::DW_FORM_flag, VK);
Benjamin Kramer138c7ff2010-03-31 19:34:01 +00001241 DIEBlock *Block = new (DIEValueAllocator) DIEBlock();
Devang Patel188c85d2009-12-03 19:11:07 +00001242 addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_constu);
1243 addUInt(Block, 0, dwarf::DW_FORM_data1, SP.getVirtualIndex());
1244 addBlock(SPDie, dwarf::DW_AT_vtable_elem_location, 0, Block);
Devang Patel7d707f92010-01-19 06:19:05 +00001245 ContainingTypeMap.insert(std::make_pair(SPDie,
1246 SP.getContainingType().getNode()));
Devang Patel188c85d2009-12-03 19:11:07 +00001247 }
1248
Devang Patel814a12c2009-12-14 16:18:45 +00001249 if (MakeDecl || !SP.isDefinition()) {
Devang Patelc50078e2009-11-21 02:48:08 +00001250 addUInt(SPDie, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag, 1);
Bill Wendlingb12b3d72009-05-15 09:23:25 +00001251
1252 // Add arguments. Do not add arguments for subprogram definition. They will
Devang Patelc1df8792009-12-03 01:25:38 +00001253 // be handled while processing variables.
1254 DICompositeType SPTy = SP.getType();
1255 DIArray Args = SPTy.getTypeArray();
1256 unsigned SPTag = SPTy.getTag();
1257
Bill Wendlingb12b3d72009-05-15 09:23:25 +00001258 if (SPTag == dwarf::DW_TAG_subroutine_type)
1259 for (unsigned i = 1, N = Args.getNumElements(); i < N; ++i) {
1260 DIE *Arg = new DIE(dwarf::DW_TAG_formal_parameter);
Devang Patelc5dc7252010-02-06 01:02:37 +00001261 DIType ATy = DIType(DIType(Args.getElement(i).getNode()));
1262 addType(Arg, ATy);
1263 if (ATy.isArtificial())
1264 addUInt(Arg, dwarf::DW_AT_artificial, dwarf::DW_FORM_flag, 1);
Devang Patelc50078e2009-11-21 02:48:08 +00001265 SPDie->addChild(Arg);
Bill Wendlingb12b3d72009-05-15 09:23:25 +00001266 }
1267 }
1268
Devang Patelbf7d00a2010-02-03 19:57:19 +00001269 if (SP.isArtificial())
1270 addUInt(SPDie, dwarf::DW_AT_artificial, dwarf::DW_FORM_flag, 1);
1271
Bill Wendlingb12b3d72009-05-15 09:23:25 +00001272 // DW_TAG_inlined_subroutine may refer to this DIE.
Devang Patelfe0be132009-12-09 18:24:21 +00001273 ModuleCU->insertDIE(SP.getNode(), SPDie);
Devang Patel91474172010-04-19 19:14:02 +00001274
Evan Cheng88989062010-04-21 03:18:23 +00001275 if (!DisableFramePointerElim(*Asm->MF))
Devang Patel91474172010-04-19 19:14:02 +00001276 addUInt(SPDie, dwarf::DW_AT_APPLE_omit_frame_ptr, dwarf::DW_FORM_flag, 1);
1277
Bill Wendlingb12b3d72009-05-15 09:23:25 +00001278 return SPDie;
1279}
1280
Devang Patel90a0fe32009-11-10 23:06:00 +00001281DbgScope *DwarfDebug::getOrCreateAbstractScope(MDNode *N) {
Chris Lattner8143ce82010-03-31 05:36:29 +00001282 assert(N && "Invalid Scope encoding!");
Devang Patel90a0fe32009-11-10 23:06:00 +00001283
1284 DbgScope *AScope = AbstractScopes.lookup(N);
1285 if (AScope)
1286 return AScope;
Jim Grosbach652b7432009-11-21 23:12:12 +00001287
Devang Patel90a0fe32009-11-10 23:06:00 +00001288 DbgScope *Parent = NULL;
1289
1290 DIDescriptor Scope(N);
1291 if (Scope.isLexicalBlock()) {
1292 DILexicalBlock DB(N);
1293 DIDescriptor ParentDesc = DB.getContext();
Devang Patel9e592492010-03-08 20:52:55 +00001294 Parent = getOrCreateAbstractScope(ParentDesc.getNode());
Devang Patel90a0fe32009-11-10 23:06:00 +00001295 }
1296
1297 AScope = new DbgScope(Parent, DIDescriptor(N), NULL);
1298
1299 if (Parent)
Devang Patelc50078e2009-11-21 02:48:08 +00001300 Parent->addScope(AScope);
Devang Patel90a0fe32009-11-10 23:06:00 +00001301 AScope->setAbstractScope();
1302 AbstractScopes[N] = AScope;
1303 if (DIDescriptor(N).isSubprogram())
1304 AbstractScopesList.push_back(AScope);
1305 return AScope;
1306}
Devang Patel6a260102009-10-01 20:31:14 +00001307
Devang Patel75c10622010-04-06 23:53:48 +00001308/// isSubprogramContext - Return true if Context is either a subprogram
1309/// or another context nested inside a subprogram.
Dan Gohman738422f2010-04-15 17:08:50 +00001310static bool isSubprogramContext(MDNode *Context) {
Devang Patel75c10622010-04-06 23:53:48 +00001311 if (!Context)
1312 return false;
1313 DIDescriptor D(Context);
1314 if (D.isSubprogram())
1315 return true;
1316 if (D.isType())
1317 return isSubprogramContext(DIType(Context).getContext().getNode());
1318 return false;
1319}
1320
Jim Grosbach652b7432009-11-21 23:12:12 +00001321/// updateSubprogramScopeDIE - Find DIE for the given subprogram and
Devang Patelc50078e2009-11-21 02:48:08 +00001322/// attach appropriate DW_AT_low_pc and DW_AT_high_pc attributes.
1323/// If there are global variables in this scope then create and insert
1324/// DIEs for these variables.
1325DIE *DwarfDebug::updateSubprogramScopeDIE(MDNode *SPNode) {
Chris Lattnerbc0027b2010-04-05 00:13:49 +00001326 DIE *SPDie = ModuleCU->getDIE(SPNode);
1327 assert(SPDie && "Unable to find subprogram DIE!");
1328 DISubprogram SP(SPNode);
Chris Lattnerdd21da82010-03-13 07:26:18 +00001329
Chris Lattnerbc0027b2010-04-05 00:13:49 +00001330 // There is not any need to generate specification DIE for a function
1331 // defined at compile unit level. If a function is defined inside another
1332 // function then gdb prefers the definition at top level and but does not
1333 // expect specification DIE in parent function. So avoid creating
1334 // specification DIE for a function defined inside a function.
1335 if (SP.isDefinition() && !SP.getContext().isCompileUnit() &&
Devang Patel75c10622010-04-06 23:53:48 +00001336 !SP.getContext().isFile() &&
1337 !isSubprogramContext(SP.getContext().getNode())) {
Chris Lattnerbc0027b2010-04-05 00:13:49 +00001338 addUInt(SPDie, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag, 1);
1339
1340 // Add arguments.
1341 DICompositeType SPTy = SP.getType();
1342 DIArray Args = SPTy.getTypeArray();
1343 unsigned SPTag = SPTy.getTag();
1344 if (SPTag == dwarf::DW_TAG_subroutine_type)
1345 for (unsigned i = 1, N = Args.getNumElements(); i < N; ++i) {
1346 DIE *Arg = new DIE(dwarf::DW_TAG_formal_parameter);
1347 DIType ATy = DIType(DIType(Args.getElement(i).getNode()));
1348 addType(Arg, ATy);
1349 if (ATy.isArtificial())
1350 addUInt(Arg, dwarf::DW_AT_artificial, dwarf::DW_FORM_flag, 1);
1351 SPDie->addChild(Arg);
1352 }
1353 DIE *SPDeclDie = SPDie;
1354 SPDie = new DIE(dwarf::DW_TAG_subprogram);
1355 addDIEEntry(SPDie, dwarf::DW_AT_specification, dwarf::DW_FORM_ref4,
1356 SPDeclDie);
1357 ModuleCU->addDie(SPDie);
1358 }
1359
1360 addLabel(SPDie, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr,
1361 Asm->GetTempSymbol("func_begin", Asm->getFunctionNumber()));
1362 addLabel(SPDie, dwarf::DW_AT_high_pc, dwarf::DW_FORM_addr,
1363 Asm->GetTempSymbol("func_end", Asm->getFunctionNumber()));
1364 const TargetRegisterInfo *RI = Asm->TM.getRegisterInfo();
1365 MachineLocation Location(RI->getFrameRegister(*Asm->MF));
1366 addAddress(SPDie, dwarf::DW_AT_frame_base, Location);
Devang Patelc5dc7252010-02-06 01:02:37 +00001367
Chris Lattnerbc0027b2010-04-05 00:13:49 +00001368 if (!DISubprogram(SPNode).isLocalToUnit())
1369 addUInt(SPDie, dwarf::DW_AT_external, dwarf::DW_FORM_flag, 1);
1370
1371 return SPDie;
Devang Patel90a0fe32009-11-10 23:06:00 +00001372}
1373
Jim Grosbach652b7432009-11-21 23:12:12 +00001374/// constructLexicalScope - Construct new DW_TAG_lexical_block
Devang Patelc50078e2009-11-21 02:48:08 +00001375/// for this scope and attach DW_AT_low_pc/DW_AT_high_pc labels.
1376DIE *DwarfDebug::constructLexicalScopeDIE(DbgScope *Scope) {
Devang Patelec3b2a42010-04-21 16:32:19 +00001377
1378 DIE *ScopeDIE = new DIE(dwarf::DW_TAG_lexical_block);
1379 if (Scope->isAbstractScope())
1380 return ScopeDIE;
1381
1382 const SmallVector<DbgRange, 4> &Ranges = Scope->getRanges();
1383 if (Ranges.empty())
1384 return 0;
1385
1386 SmallVector<DbgRange, 4>::const_iterator RI = Ranges.begin();
1387 if (Ranges.size() > 1) {
1388 // .debug_range section has not been laid out yet. Emit offset in
1389 // .debug_range as a uint, size 4, for now. emitDIE will handle
1390 // DW_AT_ranges appropriately.
1391 addUInt(ScopeDIE, dwarf::DW_AT_ranges, dwarf::DW_FORM_data4,
1392 DebugRangeSymbols.size() * Asm->getTargetData().getPointerSize());
1393 for (SmallVector<DbgRange, 4>::const_iterator RI = Ranges.begin(),
1394 RE = Ranges.end(); RI != RE; ++RI) {
1395 DebugRangeSymbols.push_back(InsnBeforeLabelMap.lookup(RI->first));
1396 DebugRangeSymbols.push_back(InsnAfterLabelMap.lookup(RI->second));
1397 }
1398 DebugRangeSymbols.push_back(NULL);
1399 DebugRangeSymbols.push_back(NULL);
1400 return ScopeDIE;
1401 }
1402
1403 MCSymbol *Start = InsnBeforeLabelMap.lookup(RI->first);
1404 MCSymbol *End = InsnAfterLabelMap.lookup(RI->second);
1405
Devang Patel9a9a4ac2010-03-29 22:59:58 +00001406 if (Start == 0 || End == 0) return 0;
Devang Patel90a0fe32009-11-10 23:06:00 +00001407
Chris Lattner855e8f52010-03-09 01:58:53 +00001408 assert(Start->isDefined() && "Invalid starting label for an inlined scope!");
1409 assert(End->isDefined() && "Invalid end label for an inlined scope!");
Chris Lattner5e423432010-03-09 01:51:43 +00001410
Devang Patelc50078e2009-11-21 02:48:08 +00001411 addLabel(ScopeDIE, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr,
Chris Lattnerbc0027b2010-04-05 00:13:49 +00001412 Start ? Start : Asm->GetTempSymbol("func_begin",
1413 Asm->getFunctionNumber()));
Devang Patelc50078e2009-11-21 02:48:08 +00001414 addLabel(ScopeDIE, dwarf::DW_AT_high_pc, dwarf::DW_FORM_addr,
Chris Lattnerbc0027b2010-04-05 00:13:49 +00001415 End ? End : Asm->GetTempSymbol("func_end",Asm->getFunctionNumber()));
Devang Patel90a0fe32009-11-10 23:06:00 +00001416
1417 return ScopeDIE;
1418}
1419
Devang Patelc50078e2009-11-21 02:48:08 +00001420/// constructInlinedScopeDIE - This scope represents inlined body of
1421/// a function. Construct DIE to represent this concrete inlined copy
1422/// of the function.
1423DIE *DwarfDebug::constructInlinedScopeDIE(DbgScope *Scope) {
Devang Patelec3b2a42010-04-21 16:32:19 +00001424
1425 const SmallVector<DbgRange, 4> &Ranges = Scope->getRanges();
1426 assert (Ranges.empty() == false
1427 && "DbgScope does not have instruction markers!");
1428
1429 // FIXME : .debug_inlined section specification does not clearly state how
1430 // to emit inlined scope that is split into multiple instruction ranges.
1431 // For now, use first instruction range and emit low_pc/high_pc pair and
1432 // corresponding .debug_inlined section entry for this pair.
1433 SmallVector<DbgRange, 4>::const_iterator RI = Ranges.begin();
1434 MCSymbol *StartLabel = InsnBeforeLabelMap.lookup(RI->first);
1435 MCSymbol *EndLabel = InsnAfterLabelMap.lookup(RI->second);
1436
1437 if (StartLabel == 0 || EndLabel == 0) {
1438 assert (0 && "Unexpected Start and End labels for a inlined scope!");
1439 return 0;
1440 }
Chris Lattner855e8f52010-03-09 01:58:53 +00001441 assert(StartLabel->isDefined() &&
Chris Lattner5e423432010-03-09 01:51:43 +00001442 "Invalid starting label for an inlined scope!");
Chris Lattner855e8f52010-03-09 01:58:53 +00001443 assert(EndLabel->isDefined() &&
Chris Lattner5e423432010-03-09 01:51:43 +00001444 "Invalid end label for an inlined scope!");
Devang Patelec3b2a42010-04-21 16:32:19 +00001445
Devang Patel9e592492010-03-08 20:52:55 +00001446 if (!Scope->getScopeNode())
Devang Patelbe149872010-03-08 19:20:38 +00001447 return NULL;
Devang Patel9e592492010-03-08 20:52:55 +00001448 DIScope DS(Scope->getScopeNode());
Devang Patel90a0fe32009-11-10 23:06:00 +00001449 DIE *ScopeDIE = new DIE(dwarf::DW_TAG_inlined_subroutine);
1450
1451 DISubprogram InlinedSP = getDISubprogram(DS.getNode());
Devang Pateld90672c2009-11-20 21:37:22 +00001452 DIE *OriginDIE = ModuleCU->getDIE(InlinedSP.getNode());
Chris Lattner8143ce82010-03-31 05:36:29 +00001453 assert(OriginDIE && "Unable to find Origin DIE!");
Devang Patelc50078e2009-11-21 02:48:08 +00001454 addDIEEntry(ScopeDIE, dwarf::DW_AT_abstract_origin,
Devang Patel90a0fe32009-11-10 23:06:00 +00001455 dwarf::DW_FORM_ref4, OriginDIE);
1456
Chris Lattneread58652010-03-09 00:31:02 +00001457 addLabel(ScopeDIE, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr, StartLabel);
Chris Lattner855e8f52010-03-09 01:58:53 +00001458 addLabel(ScopeDIE, dwarf::DW_AT_high_pc, dwarf::DW_FORM_addr, EndLabel);
Devang Patel90a0fe32009-11-10 23:06:00 +00001459
1460 InlinedSubprogramDIEs.insert(OriginDIE);
1461
1462 // Track the start label for this inlined function.
Devang Patel7d707f92010-01-19 06:19:05 +00001463 DenseMap<MDNode *, SmallVector<InlineInfoLabels, 4> >::iterator
Devang Patel90a0fe32009-11-10 23:06:00 +00001464 I = InlineInfo.find(InlinedSP.getNode());
1465
1466 if (I == InlineInfo.end()) {
Chris Lattneread58652010-03-09 00:31:02 +00001467 InlineInfo[InlinedSP.getNode()].push_back(std::make_pair(StartLabel,
Jim Grosbachb23f2422009-11-22 19:20:36 +00001468 ScopeDIE));
Devang Patel90a0fe32009-11-10 23:06:00 +00001469 InlinedSPNodes.push_back(InlinedSP.getNode());
1470 } else
Chris Lattneread58652010-03-09 00:31:02 +00001471 I->second.push_back(std::make_pair(StartLabel, ScopeDIE));
Devang Patel90a0fe32009-11-10 23:06:00 +00001472
Devang Patel90a0fe32009-11-10 23:06:00 +00001473 DILocation DL(Scope->getInlinedAt());
Devang Patelc50078e2009-11-21 02:48:08 +00001474 addUInt(ScopeDIE, dwarf::DW_AT_call_file, 0, ModuleCU->getID());
1475 addUInt(ScopeDIE, dwarf::DW_AT_call_line, 0, DL.getLineNumber());
Devang Patel90a0fe32009-11-10 23:06:00 +00001476
1477 return ScopeDIE;
1478}
1479
Devang Patelc50078e2009-11-21 02:48:08 +00001480
1481/// constructVariableDIE - Construct a DIE for the given DbgVariable.
Devang Patelfe0be132009-12-09 18:24:21 +00001482DIE *DwarfDebug::constructVariableDIE(DbgVariable *DV, DbgScope *Scope) {
Devang Patel90a0fe32009-11-10 23:06:00 +00001483 // Get the descriptor.
1484 const DIVariable &VD = DV->getVariable();
Devang Patel7f75bbe2009-11-25 17:36:49 +00001485 StringRef Name = VD.getName();
1486 if (Name.empty())
Devang Patelab9a0682009-11-13 02:25:26 +00001487 return NULL;
Devang Patel90a0fe32009-11-10 23:06:00 +00001488
1489 // Translate tag to proper Dwarf tag. The result variable is dropped for
1490 // now.
1491 unsigned Tag;
1492 switch (VD.getTag()) {
1493 case dwarf::DW_TAG_return_variable:
1494 return NULL;
1495 case dwarf::DW_TAG_arg_variable:
1496 Tag = dwarf::DW_TAG_formal_parameter;
1497 break;
1498 case dwarf::DW_TAG_auto_variable: // fall thru
1499 default:
1500 Tag = dwarf::DW_TAG_variable;
1501 break;
1502 }
1503
1504 // Define variable debug information entry.
1505 DIE *VariableDie = new DIE(Tag);
1506
1507
1508 DIE *AbsDIE = NULL;
1509 if (DbgVariable *AV = DV->getAbstractVariable())
1510 AbsDIE = AV->getDIE();
Jim Grosbach652b7432009-11-21 23:12:12 +00001511
Devang Patel90a0fe32009-11-10 23:06:00 +00001512 if (AbsDIE) {
1513 DIScope DS(Scope->getScopeNode());
1514 DISubprogram InlinedSP = getDISubprogram(DS.getNode());
Devang Pateld90672c2009-11-20 21:37:22 +00001515 DIE *OriginSPDIE = ModuleCU->getDIE(InlinedSP.getNode());
Daniel Dunbarc9f2d242009-11-11 03:09:50 +00001516 (void) OriginSPDIE;
Chris Lattner8143ce82010-03-31 05:36:29 +00001517 assert(OriginSPDIE && "Unable to find Origin DIE for the SP!");
Devang Patel90a0fe32009-11-10 23:06:00 +00001518 DIE *AbsDIE = DV->getAbstractVariable()->getDIE();
Chris Lattner8143ce82010-03-31 05:36:29 +00001519 assert(AbsDIE && "Unable to find Origin DIE for the Variable!");
Devang Patelc50078e2009-11-21 02:48:08 +00001520 addDIEEntry(VariableDie, dwarf::DW_AT_abstract_origin,
Devang Patel90a0fe32009-11-10 23:06:00 +00001521 dwarf::DW_FORM_ref4, AbsDIE);
1522 }
1523 else {
Devang Patelc50078e2009-11-21 02:48:08 +00001524 addString(VariableDie, dwarf::DW_AT_name, dwarf::DW_FORM_string, Name);
1525 addSourceLine(VariableDie, &VD);
Devang Patel90a0fe32009-11-10 23:06:00 +00001526
1527 // Add variable type.
Jim Grosbach652b7432009-11-21 23:12:12 +00001528 // FIXME: isBlockByrefVariable should be reformulated in terms of complex
Devang Patel90a0fe32009-11-10 23:06:00 +00001529 // addresses instead.
1530 if (VD.isBlockByrefVariable())
Devang Patelfe0be132009-12-09 18:24:21 +00001531 addType(VariableDie, getBlockByrefType(VD.getType(), Name));
Devang Patel90a0fe32009-11-10 23:06:00 +00001532 else
Devang Patelfe0be132009-12-09 18:24:21 +00001533 addType(VariableDie, VD.getType());
Devang Patel90a0fe32009-11-10 23:06:00 +00001534 }
1535
1536 // Add variable address.
1537 if (!Scope->isAbstractScope()) {
Devang Patel14da02f2010-03-15 18:33:46 +00001538 // Check if variable is described by DBG_VALUE instruction.
1539 if (const MachineInstr *DbgValueInsn = DV->getDbgValue()) {
1540 if (DbgValueInsn->getNumOperands() == 3) {
1541 // FIXME : Handle getNumOperands != 3
1542 if (DbgValueInsn->getOperand(0).getType()
1543 == MachineOperand::MO_Register
1544 && DbgValueInsn->getOperand(0).getReg()) {
1545 MachineLocation Location;
1546 Location.set(DbgValueInsn->getOperand(0).getReg());
1547 addAddress(VariableDie, dwarf::DW_AT_location, Location);
Devang Patel9a9a4ac2010-03-29 22:59:58 +00001548 if (MCSymbol *VS = DV->getDbgValueLabel())
1549 addLabel(VariableDie, dwarf::DW_AT_start_scope, dwarf::DW_FORM_addr,
1550 VS);
Devang Patel14da02f2010-03-15 18:33:46 +00001551 } else if (DbgValueInsn->getOperand(0).getType() ==
1552 MachineOperand::MO_Immediate) {
Benjamin Kramer138c7ff2010-03-31 19:34:01 +00001553 DIEBlock *Block = new (DIEValueAllocator) DIEBlock();
Devang Patel14da02f2010-03-15 18:33:46 +00001554 unsigned Imm = DbgValueInsn->getOperand(0).getImm();
1555 addUInt(Block, 0, dwarf::DW_FORM_udata, Imm);
1556 addBlock(VariableDie, dwarf::DW_AT_const_value, 0, Block);
Devang Patel9a9a4ac2010-03-29 22:59:58 +00001557 if (MCSymbol *VS = DV->getDbgValueLabel())
1558 addLabel(VariableDie, dwarf::DW_AT_start_scope, dwarf::DW_FORM_addr,
1559 VS);
Bill Wendling989a27e2010-04-05 22:59:21 +00001560 } else if (DbgValueInsn->getOperand(0).getType() ==
1561 MachineOperand::MO_FPImmediate) {
1562 DIEBlock *Block = new (DIEValueAllocator) DIEBlock();
1563 APFloat FPImm = DbgValueInsn->getOperand(0).getFPImm()->getValueAPF();
1564
1565 // Get the raw data form of the floating point.
1566 const APInt FltVal = FPImm.bitcastToAPInt();
1567 const char *FltPtr = (const char*)FltVal.getRawData();
1568
John McCall6fbbcc872010-04-06 23:35:53 +00001569 int NumBytes = FltVal.getBitWidth() / 8; // 8 bits per byte.
Bill Wendling989a27e2010-04-05 22:59:21 +00001570 bool LittleEndian = Asm->getTargetData().isLittleEndian();
1571 int Incr = (LittleEndian ? 1 : -1);
1572 int Start = (LittleEndian ? 0 : NumBytes - 1);
1573 int Stop = (LittleEndian ? NumBytes : -1);
1574
1575 // Output the constant to DWARF one byte at a time.
1576 for (; Start != Stop; Start += Incr)
1577 addUInt(Block, 0, dwarf::DW_FORM_data1,
1578 (unsigned char)0xFF & FltPtr[Start]);
1579
1580 addBlock(VariableDie, dwarf::DW_AT_const_value, 0, Block);
1581
1582 if (MCSymbol *VS = DV->getDbgValueLabel())
1583 addLabel(VariableDie, dwarf::DW_AT_start_scope, dwarf::DW_FORM_addr,
1584 VS);
Devang Patel14da02f2010-03-15 18:33:46 +00001585 } else {
1586 //FIXME : Handle other operand types.
1587 delete VariableDie;
1588 return NULL;
1589 }
1590 }
1591 } else {
1592 MachineLocation Location;
1593 unsigned FrameReg;
Chris Lattnerbc0027b2010-04-05 00:13:49 +00001594 const TargetRegisterInfo *RI = Asm->TM.getRegisterInfo();
1595 int Offset = RI->getFrameIndexReference(*Asm->MF, DV->getFrameIndex(),
Chris Lattner5df82552010-03-31 06:06:37 +00001596 FrameReg);
Devang Patel14da02f2010-03-15 18:33:46 +00001597 Location.set(FrameReg, Offset);
1598
1599 if (VD.hasComplexAddress())
1600 addComplexAddress(DV, VariableDie, dwarf::DW_AT_location, Location);
1601 else if (VD.isBlockByrefVariable())
1602 addBlockByrefAddress(DV, VariableDie, dwarf::DW_AT_location, Location);
1603 else
1604 addAddress(VariableDie, dwarf::DW_AT_location, Location);
1605 }
Devang Patel90a0fe32009-11-10 23:06:00 +00001606 }
Devang Patelc5dc7252010-02-06 01:02:37 +00001607
1608 if (Tag == dwarf::DW_TAG_formal_parameter && VD.getType().isArtificial())
1609 addUInt(VariableDie, dwarf::DW_AT_artificial, dwarf::DW_FORM_flag, 1);
Devang Patel90a0fe32009-11-10 23:06:00 +00001610 DV->setDIE(VariableDie);
1611 return VariableDie;
1612
1613}
Devang Patelc50078e2009-11-21 02:48:08 +00001614
Devang Patelec13b4f2009-11-24 01:14:22 +00001615void DwarfDebug::addPubTypes(DISubprogram SP) {
1616 DICompositeType SPTy = SP.getType();
1617 unsigned SPTag = SPTy.getTag();
1618 if (SPTag != dwarf::DW_TAG_subroutine_type)
1619 return;
1620
1621 DIArray Args = SPTy.getTypeArray();
Devang Patelec13b4f2009-11-24 01:14:22 +00001622 for (unsigned i = 0, e = Args.getNumElements(); i != e; ++i) {
1623 DIType ATy(Args.getElement(i).getNode());
Devang Patel9e592492010-03-08 20:52:55 +00001624 if (!ATy.isValid())
Devang Patelec13b4f2009-11-24 01:14:22 +00001625 continue;
1626 DICompositeType CATy = getDICompositeType(ATy);
Devang Patel21171c22010-04-13 20:35:04 +00001627 if (DIDescriptor(CATy.getNode()).Verify() && !CATy.getName().empty()
1628 && !CATy.isForwardDecl()) {
Devang Patelec13b4f2009-11-24 01:14:22 +00001629 if (DIEEntry *Entry = ModuleCU->getDIEEntry(CATy.getNode()))
1630 ModuleCU->addGlobalType(CATy.getName(), Entry->getEntry());
1631 }
1632 }
1633}
1634
Devang Patelc50078e2009-11-21 02:48:08 +00001635/// constructScopeDIE - Construct a DIE for this scope.
1636DIE *DwarfDebug::constructScopeDIE(DbgScope *Scope) {
Devang Patel9e592492010-03-08 20:52:55 +00001637 if (!Scope || !Scope->getScopeNode())
1638 return NULL;
1639
1640 DIScope DS(Scope->getScopeNode());
1641 DIE *ScopeDIE = NULL;
1642 if (Scope->getInlinedAt())
1643 ScopeDIE = constructInlinedScopeDIE(Scope);
1644 else if (DS.isSubprogram()) {
1645 if (Scope->isAbstractScope())
1646 ScopeDIE = ModuleCU->getDIE(DS.getNode());
1647 else
1648 ScopeDIE = updateSubprogramScopeDIE(DS.getNode());
1649 }
Devang Patel9a9a4ac2010-03-29 22:59:58 +00001650 else
Devang Patel9e592492010-03-08 20:52:55 +00001651 ScopeDIE = constructLexicalScopeDIE(Scope);
Devang Patel9a9a4ac2010-03-29 22:59:58 +00001652 if (!ScopeDIE) return NULL;
Devang Patel9e592492010-03-08 20:52:55 +00001653
Devang Patel90a0fe32009-11-10 23:06:00 +00001654 // Add variables to scope.
Jeffrey Yasskinecca2e62010-03-12 17:45:06 +00001655 const SmallVector<DbgVariable *, 8> &Variables = Scope->getVariables();
Devang Patel90a0fe32009-11-10 23:06:00 +00001656 for (unsigned i = 0, N = Variables.size(); i < N; ++i) {
Devang Patelfe0be132009-12-09 18:24:21 +00001657 DIE *VariableDIE = constructVariableDIE(Variables[i], Scope);
Jim Grosbach652b7432009-11-21 23:12:12 +00001658 if (VariableDIE)
Devang Patelc50078e2009-11-21 02:48:08 +00001659 ScopeDIE->addChild(VariableDIE);
Devang Patel90a0fe32009-11-10 23:06:00 +00001660 }
1661
1662 // Add nested scopes.
Jeffrey Yasskinecca2e62010-03-12 17:45:06 +00001663 const SmallVector<DbgScope *, 4> &Scopes = Scope->getScopes();
Devang Patel90a0fe32009-11-10 23:06:00 +00001664 for (unsigned j = 0, M = Scopes.size(); j < M; ++j) {
1665 // Define the Scope debug information entry.
Devang Patelc50078e2009-11-21 02:48:08 +00001666 DIE *NestedDIE = constructScopeDIE(Scopes[j]);
Jim Grosbach652b7432009-11-21 23:12:12 +00001667 if (NestedDIE)
Devang Patelc50078e2009-11-21 02:48:08 +00001668 ScopeDIE->addChild(NestedDIE);
Devang Patel90a0fe32009-11-10 23:06:00 +00001669 }
Devang Patelec13b4f2009-11-24 01:14:22 +00001670
1671 if (DS.isSubprogram())
1672 addPubTypes(DISubprogram(DS.getNode()));
1673
1674 return ScopeDIE;
Devang Patel90a0fe32009-11-10 23:06:00 +00001675}
1676
Bill Wendlingf5839192009-05-20 23:19:06 +00001677/// GetOrCreateSourceID - Look up the source id with the given directory and
1678/// source file names. If none currently exists, create a new id and insert it
1679/// in the SourceIds map. This can update DirectoryNames and SourceFileNames
1680/// maps as well.
Chris Lattner5df82552010-03-31 06:06:37 +00001681unsigned DwarfDebug::GetOrCreateSourceID(StringRef DirName, StringRef FileName){
Bill Wendlingf5839192009-05-20 23:19:06 +00001682 unsigned DId;
1683 StringMap<unsigned>::iterator DI = DirectoryIdMap.find(DirName);
1684 if (DI != DirectoryIdMap.end()) {
1685 DId = DI->getValue();
1686 } else {
1687 DId = DirectoryNames.size() + 1;
1688 DirectoryIdMap[DirName] = DId;
1689 DirectoryNames.push_back(DirName);
1690 }
1691
1692 unsigned FId;
1693 StringMap<unsigned>::iterator FI = SourceFileIdMap.find(FileName);
1694 if (FI != SourceFileIdMap.end()) {
1695 FId = FI->getValue();
1696 } else {
1697 FId = SourceFileNames.size() + 1;
1698 SourceFileIdMap[FileName] = FId;
1699 SourceFileNames.push_back(FileName);
1700 }
1701
1702 DenseMap<std::pair<unsigned, unsigned>, unsigned>::iterator SI =
1703 SourceIdMap.find(std::make_pair(DId, FId));
1704 if (SI != SourceIdMap.end())
1705 return SI->second;
1706
1707 unsigned SrcId = SourceIds.size() + 1; // DW_AT_decl_file cannot be 0.
1708 SourceIdMap[std::make_pair(DId, FId)] = SrcId;
1709 SourceIds.push_back(std::make_pair(DId, FId));
1710
1711 return SrcId;
1712}
1713
Devang Patel8287d662009-12-15 19:16:48 +00001714/// getOrCreateNameSpace - Create a DIE for DINameSpace.
1715DIE *DwarfDebug::getOrCreateNameSpace(DINameSpace NS) {
1716 DIE *NDie = ModuleCU->getDIE(NS.getNode());
1717 if (NDie)
1718 return NDie;
1719 NDie = new DIE(dwarf::DW_TAG_namespace);
1720 ModuleCU->insertDIE(NS.getNode(), NDie);
1721 if (!NS.getName().empty())
1722 addString(NDie, dwarf::DW_AT_name, dwarf::DW_FORM_string, NS.getName());
1723 addSourceLine(NDie, &NS);
1724 addToContextOwner(NDie, NS.getContext());
1725 return NDie;
1726}
1727
Jeffrey Yasskinc3545712010-03-11 18:29:55 +00001728void DwarfDebug::constructCompileUnit(MDNode *N) {
Devang Patel15e723d2009-08-28 23:24:31 +00001729 DICompileUnit DIUnit(N);
Jeffrey Yasskinc3545712010-03-11 18:29:55 +00001730 // Use first compile unit marked as isMain as the compile unit for this
1731 // module.
1732 if (ModuleCU || !DIUnit.isMain())
1733 return;
Devang Patel7f75bbe2009-11-25 17:36:49 +00001734 StringRef FN = DIUnit.getFilename();
1735 StringRef Dir = DIUnit.getDirectory();
Devang Patelaaf012e2009-09-29 18:40:58 +00001736 unsigned ID = GetOrCreateSourceID(Dir, FN);
Bill Wendlingf5839192009-05-20 23:19:06 +00001737
1738 DIE *Die = new DIE(dwarf::DW_TAG_compile_unit);
Devang Patelc50078e2009-11-21 02:48:08 +00001739 addString(Die, dwarf::DW_AT_producer, dwarf::DW_FORM_string,
Devang Patelaaf012e2009-09-29 18:40:58 +00001740 DIUnit.getProducer());
Devang Patelc50078e2009-11-21 02:48:08 +00001741 addUInt(Die, dwarf::DW_AT_language, dwarf::DW_FORM_data1,
Bill Wendlingf5839192009-05-20 23:19:06 +00001742 DIUnit.getLanguage());
Devang Patelc50078e2009-11-21 02:48:08 +00001743 addString(Die, dwarf::DW_AT_name, dwarf::DW_FORM_string, FN);
Chris Lattner66143d22010-04-04 22:59:04 +00001744 addLabel(Die, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr, TextSectionSym);
Devang Patel7ac39832010-03-22 23:11:36 +00001745 addLabel(Die, dwarf::DW_AT_high_pc, dwarf::DW_FORM_addr,
Chris Lattnerb93558d2010-04-04 19:25:43 +00001746 Asm->GetTempSymbol("text_end"));
Devang Patel7ac39832010-03-22 23:11:36 +00001747 // DW_AT_stmt_list is a offset of line number information for this
1748 // compile unit in debug_line section. It is always zero when only one
1749 // compile unit is emitted in one object file.
1750 addUInt(Die, dwarf::DW_AT_stmt_list, dwarf::DW_FORM_data4, 0);
Bill Wendlingf5839192009-05-20 23:19:06 +00001751
Devang Patel7f75bbe2009-11-25 17:36:49 +00001752 if (!Dir.empty())
Devang Patelc50078e2009-11-21 02:48:08 +00001753 addString(Die, dwarf::DW_AT_comp_dir, dwarf::DW_FORM_string, Dir);
Bill Wendlingf5839192009-05-20 23:19:06 +00001754 if (DIUnit.isOptimized())
Devang Patelc50078e2009-11-21 02:48:08 +00001755 addUInt(Die, dwarf::DW_AT_APPLE_optimized, dwarf::DW_FORM_flag, 1);
Bill Wendlingf5839192009-05-20 23:19:06 +00001756
Devang Patel7f75bbe2009-11-25 17:36:49 +00001757 StringRef Flags = DIUnit.getFlags();
1758 if (!Flags.empty())
Devang Patelc50078e2009-11-21 02:48:08 +00001759 addString(Die, dwarf::DW_AT_APPLE_flags, dwarf::DW_FORM_string, Flags);
Bill Wendlingf5839192009-05-20 23:19:06 +00001760
1761 unsigned RVer = DIUnit.getRunTimeVersion();
1762 if (RVer)
Devang Patelc50078e2009-11-21 02:48:08 +00001763 addUInt(Die, dwarf::DW_AT_APPLE_major_runtime_vers,
Bill Wendlingf5839192009-05-20 23:19:06 +00001764 dwarf::DW_FORM_data1, RVer);
1765
Jeffrey Yasskinc3545712010-03-11 18:29:55 +00001766 assert(!ModuleCU &&
1767 "ModuleCU assigned since the top of constructCompileUnit");
1768 ModuleCU = new CompileUnit(ID, Die);
Bill Wendlingf5839192009-05-20 23:19:06 +00001769}
1770
Devang Patelc50078e2009-11-21 02:48:08 +00001771void DwarfDebug::constructGlobalVariableDIE(MDNode *N) {
Devang Patel15e723d2009-08-28 23:24:31 +00001772 DIGlobalVariable DI_GV(N);
Daniel Dunbar41716322009-09-19 20:40:05 +00001773
Devang Patel0c03f062009-09-04 23:59:07 +00001774 // If debug information is malformed then ignore it.
1775 if (DI_GV.Verify() == false)
1776 return;
Bill Wendlingf5839192009-05-20 23:19:06 +00001777
1778 // Check for pre-existence.
Devang Pateld90672c2009-11-20 21:37:22 +00001779 if (ModuleCU->getDIE(DI_GV.getNode()))
Devang Patel166f8432009-06-26 01:49:18 +00001780 return;
Bill Wendlingf5839192009-05-20 23:19:06 +00001781
Devang Patelfe0be132009-12-09 18:24:21 +00001782 DIE *VariableDie = createGlobalVariableDIE(DI_GV);
Devang Patel6d479632009-12-10 23:25:41 +00001783 if (!VariableDie)
1784 return;
Bill Wendlingf5839192009-05-20 23:19:06 +00001785
Bill Wendlingf5839192009-05-20 23:19:06 +00001786 // Add to map.
Devang Pateld90672c2009-11-20 21:37:22 +00001787 ModuleCU->insertDIE(N, VariableDie);
Bill Wendlingf5839192009-05-20 23:19:06 +00001788
1789 // Add to context owner.
Devang Pateldcc0dce2010-01-15 01:12:22 +00001790 DIDescriptor GVContext = DI_GV.getContext();
1791 // Do not create specification DIE if context is either compile unit
1792 // or a subprogram.
Chris Lattner5df82552010-03-31 06:06:37 +00001793 if (DI_GV.isDefinition() && !GVContext.isCompileUnit() &&
Devang Patel75c10622010-04-06 23:53:48 +00001794 !GVContext.isFile() &&
1795 !isSubprogramContext(GVContext.getNode())) {
Devang Patel8287d662009-12-15 19:16:48 +00001796 // Create specification DIE.
1797 DIE *VariableSpecDIE = new DIE(dwarf::DW_TAG_variable);
1798 addDIEEntry(VariableSpecDIE, dwarf::DW_AT_specification,
1799 dwarf::DW_FORM_ref4, VariableDie);
Benjamin Kramer138c7ff2010-03-31 19:34:01 +00001800 DIEBlock *Block = new (DIEValueAllocator) DIEBlock();
Devang Patel8287d662009-12-15 19:16:48 +00001801 addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_addr);
Chris Lattner703d12e2010-03-08 22:31:46 +00001802 addLabel(Block, 0, dwarf::DW_FORM_udata,
Chris Lattner90825792010-03-12 21:09:07 +00001803 Asm->Mang->getSymbol(DI_GV.getGlobal()));
Devang Patel8287d662009-12-15 19:16:48 +00001804 addBlock(VariableSpecDIE, dwarf::DW_AT_location, 0, Block);
Devang Patela0a98582010-02-09 01:58:33 +00001805 addUInt(VariableDie, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag, 1);
Devang Patel8287d662009-12-15 19:16:48 +00001806 ModuleCU->addDie(VariableSpecDIE);
1807 } else {
Benjamin Kramer138c7ff2010-03-31 19:34:01 +00001808 DIEBlock *Block = new (DIEValueAllocator) DIEBlock();
Devang Patel8287d662009-12-15 19:16:48 +00001809 addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_addr);
Chris Lattner703d12e2010-03-08 22:31:46 +00001810 addLabel(Block, 0, dwarf::DW_FORM_udata,
Chris Lattner90825792010-03-12 21:09:07 +00001811 Asm->Mang->getSymbol(DI_GV.getGlobal()));
Devang Patel8287d662009-12-15 19:16:48 +00001812 addBlock(VariableDie, dwarf::DW_AT_location, 0, Block);
1813 }
Devang Pateldcc0dce2010-01-15 01:12:22 +00001814 addToContextOwner(VariableDie, GVContext);
Devang Patel1a8f9a82009-12-10 19:14:49 +00001815
Bill Wendlingf5839192009-05-20 23:19:06 +00001816 // Expose as global. FIXME - need to check external flag.
Devang Patelc50078e2009-11-21 02:48:08 +00001817 ModuleCU->addGlobal(DI_GV.getName(), VariableDie);
Devang Patelec13b4f2009-11-24 01:14:22 +00001818
1819 DIType GTy = DI_GV.getType();
Devang Patel21171c22010-04-13 20:35:04 +00001820 if (GTy.isCompositeType() && !GTy.getName().empty()
1821 && !GTy.isForwardDecl()) {
Devang Patelec13b4f2009-11-24 01:14:22 +00001822 DIEEntry *Entry = ModuleCU->getDIEEntry(GTy.getNode());
Chris Lattner8143ce82010-03-31 05:36:29 +00001823 assert(Entry && "Missing global type!");
Devang Patelec13b4f2009-11-24 01:14:22 +00001824 ModuleCU->addGlobalType(GTy.getName(), Entry->getEntry());
1825 }
Devang Patel166f8432009-06-26 01:49:18 +00001826 return;
Bill Wendlingf5839192009-05-20 23:19:06 +00001827}
1828
Devang Patelc50078e2009-11-21 02:48:08 +00001829void DwarfDebug::constructSubprogramDIE(MDNode *N) {
Devang Patel15e723d2009-08-28 23:24:31 +00001830 DISubprogram SP(N);
Bill Wendlingf5839192009-05-20 23:19:06 +00001831
Stuart Hastings0f5779e2010-04-06 21:38:29 +00001832 // Check for pre-existence.
1833 if (ModuleCU->getDIE(N))
1834 return;
1835
Bill Wendlingf5839192009-05-20 23:19:06 +00001836 if (!SP.isDefinition())
1837 // This is a method declaration which will be handled while constructing
1838 // class type.
Devang Patel166f8432009-06-26 01:49:18 +00001839 return;
Bill Wendlingf5839192009-05-20 23:19:06 +00001840
Stuart Hastings0f5779e2010-04-06 21:38:29 +00001841 DIE *SubprogramDie = createSubprogramDIE(SP);
1842
1843 // Add to map.
1844 ModuleCU->insertDIE(N, SubprogramDie);
Bill Wendlingf5839192009-05-20 23:19:06 +00001845
1846 // Add to context owner.
Devang Patel8287d662009-12-15 19:16:48 +00001847 addToContextOwner(SubprogramDie, SP.getContext());
Devang Patelde2d3682009-12-08 23:21:45 +00001848
Bill Wendlingf5839192009-05-20 23:19:06 +00001849 // Expose as global.
Devang Patelc50078e2009-11-21 02:48:08 +00001850 ModuleCU->addGlobal(SP.getName(), SubprogramDie);
Devang Patelec13b4f2009-11-24 01:14:22 +00001851
Devang Patel166f8432009-06-26 01:49:18 +00001852 return;
Bill Wendlingf5839192009-05-20 23:19:06 +00001853}
1854
Devang Patelc50078e2009-11-21 02:48:08 +00001855/// beginModule - Emit all Dwarf sections that should come prior to the
Daniel Dunbar19f1d442009-09-19 20:40:14 +00001856/// content. Create global DIEs and emit initial debug info sections.
1857/// This is inovked by the target AsmPrinter.
Chris Lattner75e113c2010-04-04 07:48:20 +00001858void DwarfDebug::beginModule(Module *M) {
Devang Patel58e58f62010-04-21 19:08:53 +00001859 if (DisableDebugInfoPrinting)
1860 return;
1861
Devang Patelfda766d2009-07-30 18:56:46 +00001862 DebugInfoFinder DbgFinder;
1863 DbgFinder.processModule(*M);
Devang Patel166f8432009-06-26 01:49:18 +00001864
Chris Lattnera52b6172010-04-05 02:19:28 +00001865 bool HasDebugInfo = false;
1866
1867 // Scan all the compile-units to see if there are any marked as the main unit.
1868 // if not, we do not generate debug info.
1869 for (DebugInfoFinder::iterator I = DbgFinder.compile_unit_begin(),
1870 E = DbgFinder.compile_unit_end(); I != E; ++I) {
1871 if (DICompileUnit(*I).isMain()) {
1872 HasDebugInfo = true;
1873 break;
1874 }
1875 }
1876
1877 if (!HasDebugInfo) return;
1878
1879 // Tell MMI that we have debug info.
1880 MMI->setDebugInfoAvailability(true);
1881
Chris Lattner706afc02010-04-04 23:17:54 +00001882 // Emit initial sections.
Chris Lattnera52b6172010-04-05 02:19:28 +00001883 EmitSectionLabels();
Chris Lattner706afc02010-04-04 23:17:54 +00001884
Bill Wendlingf5839192009-05-20 23:19:06 +00001885 // Create all the compile unit DIEs.
Devang Patelfda766d2009-07-30 18:56:46 +00001886 for (DebugInfoFinder::iterator I = DbgFinder.compile_unit_begin(),
1887 E = DbgFinder.compile_unit_end(); I != E; ++I)
Devang Patelc50078e2009-11-21 02:48:08 +00001888 constructCompileUnit(*I);
Bill Wendlingf5839192009-05-20 23:19:06 +00001889
Devang Patel90a0fe32009-11-10 23:06:00 +00001890 // Create DIEs for each subprogram.
Devang Patelfda766d2009-07-30 18:56:46 +00001891 for (DebugInfoFinder::iterator I = DbgFinder.subprogram_begin(),
1892 E = DbgFinder.subprogram_end(); I != E; ++I)
Devang Patelc50078e2009-11-21 02:48:08 +00001893 constructSubprogramDIE(*I);
Devang Patel166f8432009-06-26 01:49:18 +00001894
Devang Patel1a8f9a82009-12-10 19:14:49 +00001895 // Create DIEs for each global variable.
1896 for (DebugInfoFinder::iterator I = DbgFinder.global_variable_begin(),
1897 E = DbgFinder.global_variable_end(); I != E; ++I)
1898 constructGlobalVariableDIE(*I);
1899
Bill Wendlingf5839192009-05-20 23:19:06 +00001900 // Prime section data.
Chris Lattnerc4c40a92009-07-28 03:13:23 +00001901 SectionMap.insert(Asm->getObjFileLowering().getTextSection());
Bill Wendlingf5839192009-05-20 23:19:06 +00001902
1903 // Print out .file directives to specify files for .loc directives. These are
1904 // printed out early so that they precede any .loc directives.
Chris Lattnerbc0027b2010-04-05 00:13:49 +00001905 if (Asm->MAI->hasDotLocAndDotFile()) {
Bill Wendlingf5839192009-05-20 23:19:06 +00001906 for (unsigned i = 1, e = getNumSourceIds()+1; i != e; ++i) {
1907 // Remember source id starts at 1.
1908 std::pair<unsigned, unsigned> Id = getSourceDirectoryAndFileIds(i);
Chris Lattnerad653482010-01-22 22:09:00 +00001909 // FIXME: don't use sys::path for this! This should not depend on the
1910 // host.
Bill Wendlingf5839192009-05-20 23:19:06 +00001911 sys::Path FullPath(getSourceDirectoryName(Id.first));
1912 bool AppendOk =
1913 FullPath.appendComponent(getSourceFileName(Id.second));
1914 assert(AppendOk && "Could not append filename to directory!");
1915 AppendOk = false;
Chris Lattner59be4ea2010-01-25 18:58:59 +00001916 Asm->OutStreamer.EmitDwarfFileDirective(i, FullPath.str());
Bill Wendlingf5839192009-05-20 23:19:06 +00001917 }
1918 }
Bill Wendlingf5839192009-05-20 23:19:06 +00001919}
1920
Devang Patelc50078e2009-11-21 02:48:08 +00001921/// endModule - Emit all Dwarf sections that should come after the content.
Bill Wendlingf5839192009-05-20 23:19:06 +00001922///
Devang Patelc50078e2009-11-21 02:48:08 +00001923void DwarfDebug::endModule() {
Bill Wendlingce3c6252010-04-07 09:28:04 +00001924 if (!ModuleCU) return;
Bill Wendlingf5839192009-05-20 23:19:06 +00001925
Devang Patel90a0fe32009-11-10 23:06:00 +00001926 // Attach DW_AT_inline attribute with inlined subprogram DIEs.
1927 for (SmallPtrSet<DIE *, 4>::iterator AI = InlinedSubprogramDIEs.begin(),
1928 AE = InlinedSubprogramDIEs.end(); AI != AE; ++AI) {
1929 DIE *ISP = *AI;
Devang Patelc50078e2009-11-21 02:48:08 +00001930 addUInt(ISP, dwarf::DW_AT_inline, 0, dwarf::DW_INL_inlined);
Devang Patel90a0fe32009-11-10 23:06:00 +00001931 }
1932
Devang Patel7d707f92010-01-19 06:19:05 +00001933 for (DenseMap<DIE *, MDNode *>::iterator CI = ContainingTypeMap.begin(),
Devang Patel188c85d2009-12-03 19:11:07 +00001934 CE = ContainingTypeMap.end(); CI != CE; ++CI) {
1935 DIE *SPDie = CI->first;
1936 MDNode *N = dyn_cast_or_null<MDNode>(CI->second);
1937 if (!N) continue;
1938 DIE *NDie = ModuleCU->getDIE(N);
1939 if (!NDie) continue;
1940 addDIEEntry(SPDie, dwarf::DW_AT_containing_type, dwarf::DW_FORM_ref4, NDie);
Devang Patel188c85d2009-12-03 19:11:07 +00001941 }
1942
Bill Wendlingf5839192009-05-20 23:19:06 +00001943 // Standard sections final addresses.
Chris Lattner73266f92009-08-19 05:49:37 +00001944 Asm->OutStreamer.SwitchSection(Asm->getObjFileLowering().getTextSection());
Chris Lattnerb93558d2010-04-04 19:25:43 +00001945 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("text_end"));
Chris Lattner73266f92009-08-19 05:49:37 +00001946 Asm->OutStreamer.SwitchSection(Asm->getObjFileLowering().getDataSection());
Chris Lattnerb93558d2010-04-04 19:25:43 +00001947 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("data_end"));
Bill Wendlingf5839192009-05-20 23:19:06 +00001948
1949 // End text sections.
1950 for (unsigned i = 1, N = SectionMap.size(); i <= N; ++i) {
Chris Lattner73266f92009-08-19 05:49:37 +00001951 Asm->OutStreamer.SwitchSection(SectionMap[i]);
Chris Lattnerb93558d2010-04-04 19:25:43 +00001952 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("section_end", i));
Bill Wendlingf5839192009-05-20 23:19:06 +00001953 }
1954
1955 // Emit common frame information.
Devang Patelc50078e2009-11-21 02:48:08 +00001956 emitCommonDebugFrame();
Bill Wendlingf5839192009-05-20 23:19:06 +00001957
1958 // Emit function debug frame information
1959 for (std::vector<FunctionDebugFrameInfo>::iterator I = DebugFrames.begin(),
1960 E = DebugFrames.end(); I != E; ++I)
Devang Patelc50078e2009-11-21 02:48:08 +00001961 emitFunctionDebugFrame(*I);
Bill Wendlingf5839192009-05-20 23:19:06 +00001962
1963 // Compute DIE offsets and sizes.
Devang Patelc50078e2009-11-21 02:48:08 +00001964 computeSizeAndOffsets();
Bill Wendlingf5839192009-05-20 23:19:06 +00001965
1966 // Emit all the DIEs into a debug info section
Devang Patelc50078e2009-11-21 02:48:08 +00001967 emitDebugInfo();
Bill Wendlingf5839192009-05-20 23:19:06 +00001968
1969 // Corresponding abbreviations into a abbrev section.
Devang Patelc50078e2009-11-21 02:48:08 +00001970 emitAbbreviations();
Bill Wendlingf5839192009-05-20 23:19:06 +00001971
1972 // Emit source line correspondence into a debug line section.
Devang Patelc50078e2009-11-21 02:48:08 +00001973 emitDebugLines();
Bill Wendlingf5839192009-05-20 23:19:06 +00001974
1975 // Emit info into a debug pubnames section.
Devang Patelc50078e2009-11-21 02:48:08 +00001976 emitDebugPubNames();
Bill Wendlingf5839192009-05-20 23:19:06 +00001977
Devang Patelec13b4f2009-11-24 01:14:22 +00001978 // Emit info into a debug pubtypes section.
1979 emitDebugPubTypes();
1980
Bill Wendlingf5839192009-05-20 23:19:06 +00001981 // Emit info into a debug loc section.
Devang Patelc50078e2009-11-21 02:48:08 +00001982 emitDebugLoc();
Bill Wendlingf5839192009-05-20 23:19:06 +00001983
1984 // Emit info into a debug aranges section.
1985 EmitDebugARanges();
1986
1987 // Emit info into a debug ranges section.
Devang Patelc50078e2009-11-21 02:48:08 +00001988 emitDebugRanges();
Bill Wendlingf5839192009-05-20 23:19:06 +00001989
1990 // Emit info into a debug macinfo section.
Devang Patelc50078e2009-11-21 02:48:08 +00001991 emitDebugMacInfo();
Bill Wendlingf5839192009-05-20 23:19:06 +00001992
1993 // Emit inline info.
Devang Patelc50078e2009-11-21 02:48:08 +00001994 emitDebugInlineInfo();
Bill Wendlingf5839192009-05-20 23:19:06 +00001995
Chris Lattner0f093f82010-03-13 02:17:42 +00001996 // Emit info into a debug str section.
1997 emitDebugStr();
1998
Jeffrey Yasskinc3545712010-03-11 18:29:55 +00001999 delete ModuleCU;
2000 ModuleCU = NULL; // Reset for the next Module, if any.
Bill Wendlingf5839192009-05-20 23:19:06 +00002001}
2002
Devang Patel90a0fe32009-11-10 23:06:00 +00002003/// findAbstractVariable - Find abstract variable, if any, associated with Var.
Jim Grosbachb23f2422009-11-22 19:20:36 +00002004DbgVariable *DwarfDebug::findAbstractVariable(DIVariable &Var,
2005 unsigned FrameIdx,
Chris Lattnerb9692a72010-04-02 19:42:39 +00002006 DebugLoc ScopeLoc) {
Devang Patel90a0fe32009-11-10 23:06:00 +00002007
2008 DbgVariable *AbsDbgVariable = AbstractVariables.lookup(Var.getNode());
2009 if (AbsDbgVariable)
2010 return AbsDbgVariable;
2011
Chris Lattnerb9692a72010-04-02 19:42:39 +00002012 LLVMContext &Ctx = Var.getNode()->getContext();
2013 DbgScope *Scope = AbstractScopes.lookup(ScopeLoc.getScope(Ctx));
Devang Patel90a0fe32009-11-10 23:06:00 +00002014 if (!Scope)
2015 return NULL;
2016
Jeffrey Yasskinecca2e62010-03-12 17:45:06 +00002017 AbsDbgVariable = new DbgVariable(Var, FrameIdx,
2018 NULL /* No more-abstract variable*/);
Devang Patelc50078e2009-11-21 02:48:08 +00002019 Scope->addVariable(AbsDbgVariable);
Devang Patel90a0fe32009-11-10 23:06:00 +00002020 AbstractVariables[Var.getNode()] = AbsDbgVariable;
2021 return AbsDbgVariable;
2022}
2023
Devang Patel14da02f2010-03-15 18:33:46 +00002024/// findAbstractVariable - Find abstract variable, if any, associated with Var.
2025/// FIXME : Refactor findAbstractVariable.
2026DbgVariable *DwarfDebug::findAbstractVariable(DIVariable &Var,
2027 const MachineInstr *MI,
Chris Lattnerb9692a72010-04-02 19:42:39 +00002028 DebugLoc ScopeLoc) {
Devang Patel14da02f2010-03-15 18:33:46 +00002029
2030 DbgVariable *AbsDbgVariable = AbstractVariables.lookup(Var.getNode());
2031 if (AbsDbgVariable)
2032 return AbsDbgVariable;
2033
Chris Lattnerb9692a72010-04-02 19:42:39 +00002034 LLVMContext &Ctx = Var.getNode()->getContext();
2035 DbgScope *Scope = AbstractScopes.lookup(ScopeLoc.getScope(Ctx));
Devang Patel14da02f2010-03-15 18:33:46 +00002036 if (!Scope)
2037 return NULL;
2038
Devang Patel9a9a4ac2010-03-29 22:59:58 +00002039 AbsDbgVariable = new DbgVariable(Var, MI,
Devang Patel14da02f2010-03-15 18:33:46 +00002040 NULL /* No more-abstract variable*/);
2041 Scope->addVariable(AbsDbgVariable);
2042 AbstractVariables[Var.getNode()] = AbsDbgVariable;
Devang Patel9a9a4ac2010-03-29 22:59:58 +00002043 DbgValueStartMap[MI] = AbsDbgVariable;
Devang Patel14da02f2010-03-15 18:33:46 +00002044 return AbsDbgVariable;
2045}
2046
Devang Patelc50078e2009-11-21 02:48:08 +00002047/// collectVariableInfo - Populate DbgScope entries with variables' info.
2048void DwarfDebug::collectVariableInfo() {
Chris Lattnerbc0027b2010-04-05 00:13:49 +00002049 const LLVMContext &Ctx = Asm->MF->getFunction()->getContext();
Chris Lattnerb9692a72010-04-02 19:42:39 +00002050
Devang Patel84139992009-10-06 01:26:37 +00002051 MachineModuleInfo::VariableDbgInfoMapTy &VMap = MMI->getVariableDbgInfo();
2052 for (MachineModuleInfo::VariableDbgInfoMapTy::iterator VI = VMap.begin(),
2053 VE = VMap.end(); VI != VE; ++VI) {
Devang Patel0a0ea052010-01-22 22:52:10 +00002054 MDNode *Var = VI->first;
Devang Patel90a0fe32009-11-10 23:06:00 +00002055 if (!Var) continue;
Chris Lattnerb9692a72010-04-02 19:42:39 +00002056 DIVariable DV(Var);
2057 const std::pair<unsigned, DebugLoc> &VP = VI->second;
Devang Patel90a0fe32009-11-10 23:06:00 +00002058
Chris Lattnerb9692a72010-04-02 19:42:39 +00002059 DbgScope *Scope = 0;
2060 if (MDNode *IA = VP.second.getInlinedAt(Ctx))
2061 Scope = ConcreteScopes.lookup(IA);
2062 if (Scope == 0)
2063 Scope = DbgScopeMap.lookup(VP.second.getScope(Ctx));
2064
Devang Patelbad42262009-11-10 23:20:04 +00002065 // If variable scope is not found then skip this variable.
Chris Lattnerb9692a72010-04-02 19:42:39 +00002066 if (Scope == 0)
Devang Patelbad42262009-11-10 23:20:04 +00002067 continue;
Devang Patel90a0fe32009-11-10 23:06:00 +00002068
Chris Lattnerb9692a72010-04-02 19:42:39 +00002069 DbgVariable *AbsDbgVariable = findAbstractVariable(DV, VP.first, VP.second);
Jeffrey Yasskinecca2e62010-03-12 17:45:06 +00002070 DbgVariable *RegVar = new DbgVariable(DV, VP.first, AbsDbgVariable);
Devang Patelc50078e2009-11-21 02:48:08 +00002071 Scope->addVariable(RegVar);
Devang Patel84139992009-10-06 01:26:37 +00002072 }
Devang Patel14da02f2010-03-15 18:33:46 +00002073
2074 // Collect variable information from DBG_VALUE machine instructions;
Chris Lattnerbc0027b2010-04-05 00:13:49 +00002075 for (MachineFunction::const_iterator I = Asm->MF->begin(), E = Asm->MF->end();
Devang Patel14da02f2010-03-15 18:33:46 +00002076 I != E; ++I) {
2077 for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end();
2078 II != IE; ++II) {
2079 const MachineInstr *MInsn = II;
Chris Lattner202f10b2010-03-31 05:39:57 +00002080 if (!MInsn->isDebugValue())
Devang Patel14da02f2010-03-15 18:33:46 +00002081 continue;
Devang Patel9a9a4ac2010-03-29 22:59:58 +00002082
Devang Patel14da02f2010-03-15 18:33:46 +00002083 // FIXME : Lift this restriction.
2084 if (MInsn->getNumOperands() != 3)
2085 continue;
Dan Gohman8db62492010-04-17 16:43:55 +00002086 DIVariable DV(
2087 const_cast<MDNode *>(MInsn->getOperand(MInsn->getNumOperands() - 1)
2088 .getMetadata()));
Devang Patel14da02f2010-03-15 18:33:46 +00002089 if (DV.getTag() == dwarf::DW_TAG_arg_variable) {
2090 // FIXME Handle inlined subroutine arguments.
2091 DbgVariable *ArgVar = new DbgVariable(DV, MInsn, NULL);
2092 CurrentFnDbgScope->addVariable(ArgVar);
Devang Patel9a9a4ac2010-03-29 22:59:58 +00002093 DbgValueStartMap[MInsn] = ArgVar;
Devang Patel14da02f2010-03-15 18:33:46 +00002094 continue;
2095 }
2096
2097 DebugLoc DL = MInsn->getDebugLoc();
2098 if (DL.isUnknown()) continue;
Chris Lattnerb9692a72010-04-02 19:42:39 +00002099 DbgScope *Scope = 0;
2100 if (MDNode *IA = DL.getInlinedAt(Ctx))
2101 Scope = ConcreteScopes.lookup(IA);
2102 if (Scope == 0)
2103 Scope = DbgScopeMap.lookup(DL.getScope(Ctx));
2104
Devang Patel14da02f2010-03-15 18:33:46 +00002105 // If variable scope is not found then skip this variable.
Chris Lattnerb9692a72010-04-02 19:42:39 +00002106 if (Scope == 0)
Devang Patel14da02f2010-03-15 18:33:46 +00002107 continue;
2108
Chris Lattnerb9692a72010-04-02 19:42:39 +00002109 DbgVariable *AbsDbgVariable = findAbstractVariable(DV, MInsn, DL);
Devang Patel14da02f2010-03-15 18:33:46 +00002110 DbgVariable *RegVar = new DbgVariable(DV, MInsn, AbsDbgVariable);
Devang Patel9a9a4ac2010-03-29 22:59:58 +00002111 DbgValueStartMap[MInsn] = RegVar;
Devang Patel14da02f2010-03-15 18:33:46 +00002112 Scope->addVariable(RegVar);
2113 }
2114 }
Devang Patel84139992009-10-06 01:26:37 +00002115}
2116
Devang Patelabc2b352010-03-29 17:20:31 +00002117/// beginScope - Process beginning of a scope.
2118void DwarfDebug::beginScope(const MachineInstr *MI) {
Devang Patelabc2b352010-03-29 17:20:31 +00002119 // Check location.
2120 DebugLoc DL = MI->getDebugLoc();
2121 if (DL.isUnknown())
2122 return;
Devang Patelabc2b352010-03-29 17:20:31 +00002123
Chris Lattnerbc0027b2010-04-05 00:13:49 +00002124 MDNode *Scope = DL.getScope(Asm->MF->getFunction()->getContext());
Chris Lattnerb9692a72010-04-02 19:42:39 +00002125
2126 // FIXME: Should only verify each scope once!
2127 if (!DIScope(Scope).Verify())
Devang Patelabc2b352010-03-29 17:20:31 +00002128 return;
Devang Patelabc2b352010-03-29 17:20:31 +00002129
Devang Patel9a9a4ac2010-03-29 22:59:58 +00002130 // DBG_VALUE instruction establishes new value.
Chris Lattner202f10b2010-03-31 05:39:57 +00002131 if (MI->isDebugValue()) {
Devang Patel9a9a4ac2010-03-29 22:59:58 +00002132 DenseMap<const MachineInstr *, DbgVariable *>::iterator DI
2133 = DbgValueStartMap.find(MI);
2134 if (DI != DbgValueStartMap.end()) {
Devang Patelec3b2a42010-04-21 16:32:19 +00002135 MCSymbol *Label = NULL;
2136 if (DL == PrevInstLoc)
2137 Label = PrevLabel;
2138 else {
2139 Label = recordSourceLine(DL.getLine(), DL.getCol(), Scope);
2140 PrevInstLoc = DL;
2141 PrevLabel = Label;
2142 }
Devang Patel9a9a4ac2010-03-29 22:59:58 +00002143 DI->second->setDbgValueLabel(Label);
2144 }
Devang Patel98ca2372010-03-30 18:07:00 +00002145 return;
Devang Patel9a9a4ac2010-03-29 22:59:58 +00002146 }
2147
Devang Patelabc2b352010-03-29 17:20:31 +00002148 // Emit a label to indicate location change. This is used for line
Devang Patelec3b2a42010-04-21 16:32:19 +00002149 // table even if this instruction does not start a new scope.
2150 MCSymbol *Label = NULL;
2151 if (DL == PrevInstLoc)
2152 Label = PrevLabel;
2153 else {
2154 Label = recordSourceLine(DL.getLine(), DL.getCol(), Scope);
2155 PrevInstLoc = DL;
2156 PrevLabel = Label;
2157 }
Devang Patelabc2b352010-03-29 17:20:31 +00002158
Devang Patel6f878382010-04-08 16:50:29 +00002159 // If this instruction begins a scope then note down corresponding label.
2160 if (InsnsBeginScopeSet.count(MI) != 0)
2161 InsnBeforeLabelMap[MI] = Label;
Devang Patel393a46d2009-10-06 01:50:42 +00002162}
2163
Devang Patelc50078e2009-11-21 02:48:08 +00002164/// endScope - Process end of a scope.
2165void DwarfDebug::endScope(const MachineInstr *MI) {
Devang Patel6f878382010-04-08 16:50:29 +00002166 if (InsnsEndScopeSet.count(MI) != 0) {
2167 // Emit a label if this instruction ends a scope.
2168 MCSymbol *Label = MMI->getContext().CreateTempSymbol();
2169 Asm->OutStreamer.EmitLabel(Label);
2170 InsnAfterLabelMap[MI] = Label;
2171 }
Devang Patel90a0fe32009-11-10 23:06:00 +00002172}
2173
Devang Patelec3b2a42010-04-21 16:32:19 +00002174/// getOrCreateDbgScope - Create DbgScope for the scope.
2175DbgScope *DwarfDebug::getOrCreateDbgScope(MDNode *Scope, MDNode *InlinedAt) {
Devang Patel90a0fe32009-11-10 23:06:00 +00002176 if (!InlinedAt) {
2177 DbgScope *WScope = DbgScopeMap.lookup(Scope);
2178 if (WScope)
Devang Patelec3b2a42010-04-21 16:32:19 +00002179 return WScope;
Devang Patel90a0fe32009-11-10 23:06:00 +00002180 WScope = new DbgScope(NULL, DIDescriptor(Scope), NULL);
2181 DbgScopeMap.insert(std::make_pair(Scope, WScope));
Devang Patelec3b2a42010-04-21 16:32:19 +00002182 if (DIDescriptor(Scope).isLexicalBlock()) {
2183 DbgScope *Parent =
2184 getOrCreateDbgScope(DILexicalBlock(Scope).getContext().getNode(), NULL);
2185 WScope->setParent(Parent);
2186 Parent->addScope(WScope);
2187 }
2188
2189 if (!WScope->getParent()) {
2190 StringRef SPName = DISubprogram(Scope).getLinkageName();
2191 if (SPName == Asm->MF->getFunction()->getName())
2192 CurrentFnDbgScope = WScope;
2193 }
2194
2195 return WScope;
Devang Patel90a0fe32009-11-10 23:06:00 +00002196 }
2197
2198 DbgScope *WScope = DbgScopeMap.lookup(InlinedAt);
2199 if (WScope)
Devang Patelec3b2a42010-04-21 16:32:19 +00002200 return WScope;
Devang Patel90a0fe32009-11-10 23:06:00 +00002201
2202 WScope = new DbgScope(NULL, DIDescriptor(Scope), InlinedAt);
2203 DbgScopeMap.insert(std::make_pair(InlinedAt, WScope));
2204 DILocation DL(InlinedAt);
Devang Patelec3b2a42010-04-21 16:32:19 +00002205 DbgScope *Parent =
2206 getOrCreateDbgScope(DL.getScope().getNode(), DL.getOrigLocation().getNode());
2207 WScope->setParent(Parent);
2208 Parent->addScope(WScope);
2209
2210 ConcreteScopes[InlinedAt] = WScope;
2211 getOrCreateAbstractScope(Scope);
2212
2213 return WScope;
Devang Patel393a46d2009-10-06 01:50:42 +00002214}
2215
Devang Patelec3b2a42010-04-21 16:32:19 +00002216/// hasValidLocation - Return true if debug location entry attached with
2217/// machine instruction encodes valid location info.
2218static bool hasValidLocation(LLVMContext &Ctx,
2219 const MachineInstr *MInsn,
2220 MDNode *&Scope, MDNode *&InlinedAt) {
2221 if (MInsn->isDebugValue())
2222 return false;
2223 DebugLoc DL = MInsn->getDebugLoc();
2224 if (DL.isUnknown()) return false;
2225
2226 MDNode *S = DL.getScope(Ctx);
2227
2228 // There is no need to create another DIE for compile unit. For all
2229 // other scopes, create one DbgScope now. This will be translated
2230 // into a scope DIE at the end.
2231 if (DIScope(S).isCompileUnit()) return false;
2232
2233 Scope = S;
2234 InlinedAt = DL.getInlinedAt(Ctx);
2235 return true;
2236}
2237
2238/// calculateDominanceGraph - Calculate dominance graph for DbgScope
2239/// hierarchy.
2240static void calculateDominanceGraph(DbgScope *Scope) {
2241 assert (Scope && "Unable to calculate scop edominance graph!");
2242 SmallVector<DbgScope *, 4> WorkStack;
2243 WorkStack.push_back(Scope);
2244 unsigned Counter = 0;
2245 while (!WorkStack.empty()) {
2246 DbgScope *WS = WorkStack.back();
2247 const SmallVector<DbgScope *, 4> &Children = WS->getScopes();
2248 bool visitedChildren = false;
2249 for (SmallVector<DbgScope *, 4>::const_iterator SI = Children.begin(),
2250 SE = Children.end(); SI != SE; ++SI) {
2251 DbgScope *ChildScope = *SI;
2252 if (!ChildScope->getDFSOut()) {
2253 WorkStack.push_back(ChildScope);
2254 visitedChildren = true;
2255 ChildScope->setDFSIn(++Counter);
2256 break;
2257 }
2258 }
2259 if (!visitedChildren) {
2260 WorkStack.pop_back();
2261 WS->setDFSOut(++Counter);
2262 }
2263 }
2264}
2265
2266/// printDbgScopeInfo - Print DbgScope info for each machine instruction.
2267static
2268void printDbgScopeInfo(LLVMContext &Ctx, const MachineFunction *MF,
2269 DenseMap<const MachineInstr *, DbgScope *> &MI2ScopeMap)
2270{
2271#ifndef NDEBUG
2272 unsigned PrevDFSIn = 0;
2273 for (MachineFunction::const_iterator I = MF->begin(), E = MF->end();
2274 I != E; ++I) {
2275 for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end();
2276 II != IE; ++II) {
2277 const MachineInstr *MInsn = II;
2278 MDNode *Scope = NULL;
2279 MDNode *InlinedAt = NULL;
2280
2281 // Check if instruction has valid location information.
2282 if (hasValidLocation(Ctx, MInsn, Scope, InlinedAt)) {
2283 dbgs() << " [ ";
2284 if (InlinedAt)
2285 dbgs() << "*";
2286 DenseMap<const MachineInstr *, DbgScope *>::iterator DI =
2287 MI2ScopeMap.find(MInsn);
2288 if (DI != MI2ScopeMap.end()) {
2289 DbgScope *S = DI->second;
2290 dbgs() << S->getDFSIn();
2291 PrevDFSIn = S->getDFSIn();
2292 } else
2293 dbgs() << PrevDFSIn;
2294 } else
2295 dbgs() << " [ x" << PrevDFSIn;
2296 dbgs() << " ]";
2297 MInsn->dump();
2298 }
2299 dbgs() << "\n";
2300 }
2301#endif
2302}
Devang Patelc50078e2009-11-21 02:48:08 +00002303/// extractScopeInformation - Scan machine instructions in this function
Chris Lattner202f10b2010-03-31 05:39:57 +00002304/// and collect DbgScopes. Return true, if at least one scope was found.
Chris Lattner69a76972010-01-26 23:18:02 +00002305bool DwarfDebug::extractScopeInformation() {
Devang Patel6a260102009-10-01 20:31:14 +00002306 // If scope information was extracted using .dbg intrinsics then there is not
2307 // any need to extract these information by scanning each instruction.
2308 if (!DbgScopeMap.empty())
2309 return false;
2310
Devang Patel90a0fe32009-11-10 23:06:00 +00002311 // Scan each instruction and create scopes. First build working set of scopes.
Devang Patelec3b2a42010-04-21 16:32:19 +00002312 LLVMContext &Ctx = Asm->MF->getFunction()->getContext();
2313 SmallVector<DbgRange, 4> MIRanges;
2314 DenseMap<const MachineInstr *, DbgScope *> MI2ScopeMap;
2315 MDNode *PrevScope = NULL;
2316 MDNode *PrevInlinedAt = NULL;
2317 const MachineInstr *RangeBeginMI = NULL;
2318 const MachineInstr *PrevMI = NULL;
Chris Lattnerbc0027b2010-04-05 00:13:49 +00002319 for (MachineFunction::const_iterator I = Asm->MF->begin(), E = Asm->MF->end();
Devang Patel6a260102009-10-01 20:31:14 +00002320 I != E; ++I) {
2321 for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end();
2322 II != IE; ++II) {
2323 const MachineInstr *MInsn = II;
Devang Patelec3b2a42010-04-21 16:32:19 +00002324 MDNode *Scope = NULL;
2325 MDNode *InlinedAt = NULL;
2326
2327 // Check if instruction has valid location information.
2328 if (!hasValidLocation(Ctx, MInsn, Scope, InlinedAt)) {
2329 PrevMI = MInsn;
2330 continue;
2331 }
Chris Lattnerb9692a72010-04-02 19:42:39 +00002332
Devang Patelec3b2a42010-04-21 16:32:19 +00002333 // If scope has not changed then skip this instruction.
2334 if (Scope == PrevScope && PrevInlinedAt == InlinedAt) {
2335 PrevMI = MInsn;
2336 continue;
2337 }
2338
2339 if (RangeBeginMI) {
2340 // If we have alread seen a beginning of a instruction range and
2341 // current instruction scope does not match scope of first instruction
2342 // in this range then create a new instruction range.
2343 DbgRange R(RangeBeginMI, PrevMI);
2344 MI2ScopeMap[RangeBeginMI] = getOrCreateDbgScope(PrevScope, PrevInlinedAt);
2345 MIRanges.push_back(R);
2346 }
2347
2348 // This is a beginning of a new instruction range.
2349 RangeBeginMI = MInsn;
Chris Lattnerb9692a72010-04-02 19:42:39 +00002350
Devang Patelec3b2a42010-04-21 16:32:19 +00002351 // Reset previous markers.
2352 PrevMI = MInsn;
2353 PrevScope = Scope;
2354 PrevInlinedAt = InlinedAt;
Devang Patel90a0fe32009-11-10 23:06:00 +00002355 }
2356 }
2357
Devang Patelec3b2a42010-04-21 16:32:19 +00002358 // Create last instruction range.
2359 if (RangeBeginMI && PrevMI && PrevScope) {
2360 DbgRange R(RangeBeginMI, PrevMI);
2361 MIRanges.push_back(R);
2362 MI2ScopeMap[RangeBeginMI] = getOrCreateDbgScope(PrevScope, PrevInlinedAt);
Devang Patel6a260102009-10-01 20:31:14 +00002363 }
Devang Patelec3b2a42010-04-21 16:32:19 +00002364
Devang Patel98e77302010-01-04 20:44:00 +00002365 if (!CurrentFnDbgScope)
2366 return false;
2367
Devang Patelec3b2a42010-04-21 16:32:19 +00002368 calculateDominanceGraph(CurrentFnDbgScope);
2369 if (PrintDbgScope)
2370 printDbgScopeInfo(Ctx, Asm->MF, MI2ScopeMap);
2371
2372 // Find ranges of instructions covered by each DbgScope;
2373 DbgScope *PrevDbgScope = NULL;
2374 for (SmallVector<DbgRange, 4>::const_iterator RI = MIRanges.begin(),
2375 RE = MIRanges.end(); RI != RE; ++RI) {
2376 const DbgRange &R = *RI;
2377 DbgScope *S = MI2ScopeMap.lookup(R.first);
2378 assert (S && "Lost DbgScope for a machine instruction!");
2379 if (PrevDbgScope && !PrevDbgScope->dominates(S))
2380 PrevDbgScope->closeInsnRange(S);
2381 S->openInsnRange(R.first);
2382 S->extendInsnRange(R.second);
2383 PrevDbgScope = S;
2384 }
2385
2386 if (PrevDbgScope)
2387 PrevDbgScope->closeInsnRange();
Devang Patel6a260102009-10-01 20:31:14 +00002388
Devang Patelf63b2262010-04-08 18:43:56 +00002389 identifyScopeMarkers();
Devang Patel0d8f3b72010-04-08 15:37:09 +00002390
2391 return !DbgScopeMap.empty();
2392}
2393
Devang Patelec3b2a42010-04-21 16:32:19 +00002394/// identifyScopeMarkers() -
2395/// Each DbgScope has first instruction and last instruction to mark beginning
2396/// and end of a scope respectively. Create an inverse map that list scopes
2397/// starts (and ends) with an instruction. One instruction may start (or end)
2398/// multiple scopes. Ignore scopes that are not reachable.
Devang Patelf63b2262010-04-08 18:43:56 +00002399void DwarfDebug::identifyScopeMarkers() {
Devang Patelfd311df2010-01-20 02:05:23 +00002400 SmallVector<DbgScope *, 4> WorkList;
2401 WorkList.push_back(CurrentFnDbgScope);
2402 while (!WorkList.empty()) {
Chris Lattner202f10b2010-03-31 05:39:57 +00002403 DbgScope *S = WorkList.pop_back_val();
Devang Patelec3b2a42010-04-21 16:32:19 +00002404
Jeffrey Yasskinecca2e62010-03-12 17:45:06 +00002405 const SmallVector<DbgScope *, 4> &Children = S->getScopes();
Devang Patelfd311df2010-01-20 02:05:23 +00002406 if (!Children.empty())
Jeffrey Yasskinecca2e62010-03-12 17:45:06 +00002407 for (SmallVector<DbgScope *, 4>::const_iterator SI = Children.begin(),
Devang Patelfd311df2010-01-20 02:05:23 +00002408 SE = Children.end(); SI != SE; ++SI)
2409 WorkList.push_back(*SI);
2410
Devang Patel90a0fe32009-11-10 23:06:00 +00002411 if (S->isAbstractScope())
2412 continue;
Devang Patelec3b2a42010-04-21 16:32:19 +00002413
2414 const SmallVector<DbgRange, 4> &Ranges = S->getRanges();
2415 if (Ranges.empty())
2416 continue;
2417 for (SmallVector<DbgRange, 4>::const_iterator RI = Ranges.begin(),
2418 RE = Ranges.end(); RI != RE; ++RI) {
2419 assert(RI->first && "DbgRange does not have first instruction!");
2420 assert(RI->second && "DbgRange does not have second instruction!");
2421 InsnsBeginScopeSet.insert(RI->first);
2422 InsnsEndScopeSet.insert(RI->second);
2423 }
Devang Patel6a260102009-10-01 20:31:14 +00002424 }
Devang Patel6a260102009-10-01 20:31:14 +00002425}
2426
Dan Gohmand0e9b672010-04-20 00:37:27 +00002427/// FindFirstDebugLoc - Find the first debug location in the function. This
2428/// is intended to be an approximation for the source position of the
2429/// beginning of the function.
2430static DebugLoc FindFirstDebugLoc(const MachineFunction *MF) {
2431 for (MachineFunction::const_iterator I = MF->begin(), E = MF->end();
2432 I != E; ++I)
2433 for (MachineBasicBlock::const_iterator MBBI = I->begin(), MBBE = I->end();
2434 MBBI != MBBE; ++MBBI) {
2435 DebugLoc DL = MBBI->getDebugLoc();
2436 if (!DL.isUnknown())
2437 return DL;
2438 }
2439 return DebugLoc();
2440}
2441
Devang Patelc50078e2009-11-21 02:48:08 +00002442/// beginFunction - Gather pre-function debug information. Assumes being
Bill Wendlingf5839192009-05-20 23:19:06 +00002443/// emitted immediately after the function entry point.
Chris Lattner69a76972010-01-26 23:18:02 +00002444void DwarfDebug::beginFunction(const MachineFunction *MF) {
Chris Lattner2cb53302010-04-05 03:52:55 +00002445 if (!MMI->hasDebugInfo()) return;
Bill Wendlingce3c6252010-04-07 09:28:04 +00002446 if (!extractScopeInformation()) return;
Chris Lattnerb49c9f82010-03-29 20:38:20 +00002447
Devang Patelc50078e2009-11-21 02:48:08 +00002448 collectVariableInfo();
Devang Patel0feae422009-10-06 18:37:31 +00002449
Bill Wendlingf5839192009-05-20 23:19:06 +00002450 // Assumes in correct section after the entry point.
Chris Lattnerb93558d2010-04-04 19:25:43 +00002451 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("func_begin",
Chris Lattnerbc0027b2010-04-05 00:13:49 +00002452 Asm->getFunctionNumber()));
Bill Wendlingf5839192009-05-20 23:19:06 +00002453
2454 // Emit label for the implicitly defined dbg.stoppoint at the start of the
2455 // function.
Dan Gohmand0e9b672010-04-20 00:37:27 +00002456 DebugLoc FDL = FindFirstDebugLoc(MF);
Chris Lattnerb9692a72010-04-02 19:42:39 +00002457 if (FDL.isUnknown()) return;
2458
2459 MDNode *Scope = FDL.getScope(MF->getFunction()->getContext());
2460
2461 DISubprogram SP = getDISubprogram(Scope);
2462 unsigned Line, Col;
2463 if (SP.Verify()) {
2464 Line = SP.getLineNumber();
2465 Col = 0;
2466 } else {
2467 Line = FDL.getLine();
2468 Col = FDL.getCol();
Bill Wendlingf5839192009-05-20 23:19:06 +00002469 }
Chris Lattnerb9692a72010-04-02 19:42:39 +00002470
2471 recordSourceLine(Line, Col, Scope);
Bill Wendlingf5839192009-05-20 23:19:06 +00002472}
2473
Devang Patelc50078e2009-11-21 02:48:08 +00002474/// endFunction - Gather and emit post-function debug information.
Bill Wendlingf5839192009-05-20 23:19:06 +00002475///
Chris Lattner69a76972010-01-26 23:18:02 +00002476void DwarfDebug::endFunction(const MachineFunction *MF) {
Bill Wendlingce3c6252010-04-07 09:28:04 +00002477 if (!MMI->hasDebugInfo() || DbgScopeMap.empty()) return;
Devang Patel4a7ef8d2009-11-12 19:02:56 +00002478
Devang Patel98e77302010-01-04 20:44:00 +00002479 if (CurrentFnDbgScope) {
2480 // Define end label for subprogram.
Chris Lattnerbc0027b2010-04-05 00:13:49 +00002481 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("func_end",
2482 Asm->getFunctionNumber()));
Devang Patel98e77302010-01-04 20:44:00 +00002483
2484 // Get function line info.
2485 if (!Lines.empty()) {
2486 // Get section line info.
2487 unsigned ID = SectionMap.insert(Asm->getCurrentSection());
2488 if (SectionSourceLines.size() < ID) SectionSourceLines.resize(ID);
2489 std::vector<SrcLineInfo> &SectionLineInfos = SectionSourceLines[ID-1];
2490 // Append the function info to section info.
2491 SectionLineInfos.insert(SectionLineInfos.end(),
2492 Lines.begin(), Lines.end());
2493 }
2494
2495 // Construct abstract scopes.
2496 for (SmallVector<DbgScope *, 4>::iterator AI = AbstractScopesList.begin(),
2497 AE = AbstractScopesList.end(); AI != AE; ++AI)
2498 constructScopeDIE(*AI);
2499
2500 constructScopeDIE(CurrentFnDbgScope);
2501
Chris Lattnerbc0027b2010-04-05 00:13:49 +00002502 DebugFrames.push_back(FunctionDebugFrameInfo(Asm->getFunctionNumber(),
Devang Patel98e77302010-01-04 20:44:00 +00002503 MMI->getFrameMoves()));
Bill Wendlingf5839192009-05-20 23:19:06 +00002504 }
2505
Bill Wendlingf5839192009-05-20 23:19:06 +00002506 // Clear debug info
Devang Patel387e9c12010-01-19 01:26:02 +00002507 CurrentFnDbgScope = NULL;
Jeffrey Yasskinecca2e62010-03-12 17:45:06 +00002508 DeleteContainerSeconds(DbgScopeMap);
Devang Patelfd0ebd52010-04-09 16:04:20 +00002509 InsnsBeginScopeSet.clear();
2510 InsnsEndScopeSet.clear();
Devang Patel9a9a4ac2010-03-29 22:59:58 +00002511 DbgValueStartMap.clear();
Devang Patel387e9c12010-01-19 01:26:02 +00002512 ConcreteScopes.clear();
Jeffrey Yasskinecca2e62010-03-12 17:45:06 +00002513 DeleteContainerSeconds(AbstractScopes);
Devang Patel387e9c12010-01-19 01:26:02 +00002514 AbstractScopesList.clear();
Jeffrey Yasskinecca2e62010-03-12 17:45:06 +00002515 AbstractVariables.clear();
Devang Patelacbf6662010-04-14 01:18:28 +00002516 InsnBeforeLabelMap.clear();
2517 InsnAfterLabelMap.clear();
Bill Wendlingf5839192009-05-20 23:19:06 +00002518 Lines.clear();
Devang Patel146c6f72010-04-16 23:33:45 +00002519 PrevLabel = NULL;
Bill Wendlingf5839192009-05-20 23:19:06 +00002520}
2521
Chris Lattner597b0fc2010-03-09 04:54:43 +00002522/// recordSourceLine - Register a source line with debug info. Returns the
2523/// unique label that was emitted and which provides correspondence to
2524/// the source line list.
2525MCSymbol *DwarfDebug::recordSourceLine(unsigned Line, unsigned Col, MDNode *S) {
Devang Patel7f75bbe2009-11-25 17:36:49 +00002526 StringRef Dir;
2527 StringRef Fn;
Devang Patel946d0ae2009-10-05 18:03:19 +00002528
2529 DIDescriptor Scope(S);
2530 if (Scope.isCompileUnit()) {
2531 DICompileUnit CU(S);
2532 Dir = CU.getDirectory();
2533 Fn = CU.getFilename();
2534 } else if (Scope.isSubprogram()) {
2535 DISubprogram SP(S);
2536 Dir = SP.getDirectory();
2537 Fn = SP.getFilename();
2538 } else if (Scope.isLexicalBlock()) {
2539 DILexicalBlock DB(S);
2540 Dir = DB.getDirectory();
2541 Fn = DB.getFilename();
2542 } else
Chris Lattnerdd21da82010-03-13 07:26:18 +00002543 assert(0 && "Unexpected scope info");
Devang Patel946d0ae2009-10-05 18:03:19 +00002544
2545 unsigned Src = GetOrCreateSourceID(Dir, Fn);
Chris Lattner54e56f22010-03-14 08:36:50 +00002546 MCSymbol *Label = MMI->getContext().CreateTempSymbol();
Chris Lattner8d9d06a2010-03-14 08:15:55 +00002547 Lines.push_back(SrcLineInfo(Line, Col, Src, Label));
Bill Wendlingf5839192009-05-20 23:19:06 +00002548
Chris Lattner597b0fc2010-03-09 04:54:43 +00002549 Asm->OutStreamer.EmitLabel(Label);
2550 return Label;
Bill Wendlingf5839192009-05-20 23:19:06 +00002551}
2552
Bill Wendlinge1a5bbb2009-05-20 23:22:40 +00002553//===----------------------------------------------------------------------===//
2554// Emit Methods
2555//===----------------------------------------------------------------------===//
2556
Devang Patelc50078e2009-11-21 02:48:08 +00002557/// computeSizeAndOffset - Compute the size and offset of a DIE.
Bill Wendling55fccda2009-05-20 23:21:38 +00002558///
Jim Grosbachb23f2422009-11-22 19:20:36 +00002559unsigned
2560DwarfDebug::computeSizeAndOffset(DIE *Die, unsigned Offset, bool Last) {
Bill Wendling55fccda2009-05-20 23:21:38 +00002561 // Get the children.
2562 const std::vector<DIE *> &Children = Die->getChildren();
2563
2564 // If not last sibling and has children then add sibling offset attribute.
Jeffrey Yasskin2944ced2010-03-22 18:47:14 +00002565 if (!Last && !Children.empty())
Benjamin Kramer138c7ff2010-03-31 19:34:01 +00002566 Die->addSiblingOffset(DIEValueAllocator);
Bill Wendling55fccda2009-05-20 23:21:38 +00002567
2568 // Record the abbreviation.
Devang Patelc50078e2009-11-21 02:48:08 +00002569 assignAbbrevNumber(Die->getAbbrev());
Bill Wendling55fccda2009-05-20 23:21:38 +00002570
2571 // Get the abbreviation for this DIE.
2572 unsigned AbbrevNumber = Die->getAbbrevNumber();
2573 const DIEAbbrev *Abbrev = Abbreviations[AbbrevNumber - 1];
2574
2575 // Set DIE offset
2576 Die->setOffset(Offset);
2577
2578 // Start the size with the size of abbreviation code.
Chris Lattner621c44d2009-08-22 20:48:53 +00002579 Offset += MCAsmInfo::getULEB128Size(AbbrevNumber);
Bill Wendling55fccda2009-05-20 23:21:38 +00002580
2581 const SmallVector<DIEValue*, 32> &Values = Die->getValues();
2582 const SmallVector<DIEAbbrevData, 8> &AbbrevData = Abbrev->getData();
2583
2584 // Size the DIE attribute values.
2585 for (unsigned i = 0, N = Values.size(); i < N; ++i)
2586 // Size attribute value.
Chris Lattner352c8e22010-04-05 00:18:22 +00002587 Offset += Values[i]->SizeOf(Asm, AbbrevData[i].getForm());
Bill Wendling55fccda2009-05-20 23:21:38 +00002588
2589 // Size the DIE children if any.
2590 if (!Children.empty()) {
2591 assert(Abbrev->getChildrenFlag() == dwarf::DW_CHILDREN_yes &&
2592 "Children flag not set");
2593
2594 for (unsigned j = 0, M = Children.size(); j < M; ++j)
Devang Patelc50078e2009-11-21 02:48:08 +00002595 Offset = computeSizeAndOffset(Children[j], Offset, (j + 1) == M);
Bill Wendling55fccda2009-05-20 23:21:38 +00002596
2597 // End of children marker.
2598 Offset += sizeof(int8_t);
2599 }
2600
2601 Die->setSize(Offset - Die->getOffset());
2602 return Offset;
2603}
2604
Devang Patelc50078e2009-11-21 02:48:08 +00002605/// computeSizeAndOffsets - Compute the size and offset of all the DIEs.
Bill Wendling55fccda2009-05-20 23:21:38 +00002606///
Devang Patelc50078e2009-11-21 02:48:08 +00002607void DwarfDebug::computeSizeAndOffsets() {
Bill Wendling55fccda2009-05-20 23:21:38 +00002608 // Compute size of compile unit header.
2609 static unsigned Offset =
2610 sizeof(int32_t) + // Length of Compilation Unit Info
2611 sizeof(int16_t) + // DWARF version number
2612 sizeof(int32_t) + // Offset Into Abbrev. Section
2613 sizeof(int8_t); // Pointer Size (in bytes)
2614
Devang Patelc50078e2009-11-21 02:48:08 +00002615 computeSizeAndOffset(ModuleCU->getCUDie(), Offset, true);
Bill Wendling55fccda2009-05-20 23:21:38 +00002616}
2617
Chris Lattner733c69d2010-04-04 23:02:02 +00002618/// EmitSectionSym - Switch to the specified MCSection and emit an assembler
2619/// temporary label to it if SymbolStem is specified.
Chris Lattner66143d22010-04-04 22:59:04 +00002620static MCSymbol *EmitSectionSym(AsmPrinter *Asm, const MCSection *Section,
Chris Lattner733c69d2010-04-04 23:02:02 +00002621 const char *SymbolStem = 0) {
Chris Lattner66143d22010-04-04 22:59:04 +00002622 Asm->OutStreamer.SwitchSection(Section);
Chris Lattner733c69d2010-04-04 23:02:02 +00002623 if (!SymbolStem) return 0;
2624
Chris Lattner66143d22010-04-04 22:59:04 +00002625 MCSymbol *TmpSym = Asm->GetTempSymbol(SymbolStem);
2626 Asm->OutStreamer.EmitLabel(TmpSym);
2627 return TmpSym;
2628}
2629
2630/// EmitSectionLabels - Emit initial Dwarf sections with a label at
2631/// the start of each one.
Chris Lattnerd91fd8c2010-04-04 22:33:59 +00002632void DwarfDebug::EmitSectionLabels() {
Chris Lattner73266f92009-08-19 05:49:37 +00002633 const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
Daniel Dunbar41716322009-09-19 20:40:05 +00002634
Bill Wendling55fccda2009-05-20 23:21:38 +00002635 // Dwarf sections base addresses.
Chris Lattnerbc0027b2010-04-05 00:13:49 +00002636 if (Asm->MAI->doesDwarfRequireFrameSection()) {
Chris Lattner66143d22010-04-04 22:59:04 +00002637 DwarfFrameSectionSym =
2638 EmitSectionSym(Asm, TLOF.getDwarfFrameSection(), "section_debug_frame");
2639 }
Bill Wendling55fccda2009-05-20 23:21:38 +00002640
Chris Lattner66143d22010-04-04 22:59:04 +00002641 DwarfInfoSectionSym =
2642 EmitSectionSym(Asm, TLOF.getDwarfInfoSection(), "section_info");
2643 DwarfAbbrevSectionSym =
2644 EmitSectionSym(Asm, TLOF.getDwarfAbbrevSection(), "section_abbrev");
Chris Lattner733c69d2010-04-04 23:02:02 +00002645 EmitSectionSym(Asm, TLOF.getDwarfARangesSection());
Chris Lattner66143d22010-04-04 22:59:04 +00002646
2647 if (const MCSection *MacroInfo = TLOF.getDwarfMacroInfoSection())
Chris Lattner733c69d2010-04-04 23:02:02 +00002648 EmitSectionSym(Asm, MacroInfo);
Bill Wendling55fccda2009-05-20 23:21:38 +00002649
Chris Lattner733c69d2010-04-04 23:02:02 +00002650 EmitSectionSym(Asm, TLOF.getDwarfLineSection());
2651 EmitSectionSym(Asm, TLOF.getDwarfLocSection());
2652 EmitSectionSym(Asm, TLOF.getDwarfPubNamesSection());
2653 EmitSectionSym(Asm, TLOF.getDwarfPubTypesSection());
Chris Lattner66143d22010-04-04 22:59:04 +00002654 DwarfStrSectionSym =
2655 EmitSectionSym(Asm, TLOF.getDwarfStrSection(), "section_str");
Devang Patel146c6f72010-04-16 23:33:45 +00002656 DwarfDebugRangeSectionSym = EmitSectionSym(Asm, TLOF.getDwarfRangesSection(),
2657 "debug_range");
Bill Wendling55fccda2009-05-20 23:21:38 +00002658
Chris Lattner66143d22010-04-04 22:59:04 +00002659 TextSectionSym = EmitSectionSym(Asm, TLOF.getTextSection(), "text_begin");
Chris Lattner094932e2010-04-04 23:10:38 +00002660 EmitSectionSym(Asm, TLOF.getDataSection());
Bill Wendling55fccda2009-05-20 23:21:38 +00002661}
2662
Devang Patelc50078e2009-11-21 02:48:08 +00002663/// emitDIE - Recusively Emits a debug information entry.
Bill Wendling55fccda2009-05-20 23:21:38 +00002664///
Devang Patelc50078e2009-11-21 02:48:08 +00002665void DwarfDebug::emitDIE(DIE *Die) {
Bill Wendling55fccda2009-05-20 23:21:38 +00002666 // Get the abbreviation for this DIE.
2667 unsigned AbbrevNumber = Die->getAbbrevNumber();
2668 const DIEAbbrev *Abbrev = Abbreviations[AbbrevNumber - 1];
2669
Bill Wendling55fccda2009-05-20 23:21:38 +00002670 // Emit the code (index) for the abbreviation.
Chris Lattner97c69b72010-04-04 18:52:31 +00002671 if (Asm->isVerbose())
Chris Lattnerbcc79432010-01-22 23:18:42 +00002672 Asm->OutStreamer.AddComment("Abbrev [" + Twine(AbbrevNumber) + "] 0x" +
2673 Twine::utohexstr(Die->getOffset()) + ":0x" +
2674 Twine::utohexstr(Die->getSize()) + " " +
2675 dwarf::TagString(Abbrev->getTag()));
Chris Lattner26be1c12010-04-04 19:09:29 +00002676 Asm->EmitULEB128(AbbrevNumber);
Bill Wendling55fccda2009-05-20 23:21:38 +00002677
Jeffrey Yasskin2944ced2010-03-22 18:47:14 +00002678 const SmallVector<DIEValue*, 32> &Values = Die->getValues();
Bill Wendling55fccda2009-05-20 23:21:38 +00002679 const SmallVector<DIEAbbrevData, 8> &AbbrevData = Abbrev->getData();
2680
2681 // Emit the DIE attribute values.
2682 for (unsigned i = 0, N = Values.size(); i < N; ++i) {
2683 unsigned Attr = AbbrevData[i].getAttribute();
2684 unsigned Form = AbbrevData[i].getForm();
2685 assert(Form && "Too many attributes for DIE (check abbreviation)");
2686
Chris Lattner97c69b72010-04-04 18:52:31 +00002687 if (Asm->isVerbose())
Chris Lattner91e06b42010-01-24 18:54:17 +00002688 Asm->OutStreamer.AddComment(dwarf::AttributeString(Attr));
2689
Bill Wendling55fccda2009-05-20 23:21:38 +00002690 switch (Attr) {
2691 case dwarf::DW_AT_sibling:
Devang Patelc50078e2009-11-21 02:48:08 +00002692 Asm->EmitInt32(Die->getSiblingOffset());
Bill Wendling55fccda2009-05-20 23:21:38 +00002693 break;
2694 case dwarf::DW_AT_abstract_origin: {
2695 DIEEntry *E = cast<DIEEntry>(Values[i]);
2696 DIE *Origin = E->getEntry();
Devang Patel90a0fe32009-11-10 23:06:00 +00002697 unsigned Addr = Origin->getOffset();
Bill Wendling55fccda2009-05-20 23:21:38 +00002698 Asm->EmitInt32(Addr);
2699 break;
2700 }
Devang Patel146c6f72010-04-16 23:33:45 +00002701 case dwarf::DW_AT_ranges: {
2702 // DW_AT_range Value encodes offset in debug_range section.
2703 DIEInteger *V = cast<DIEInteger>(Values[i]);
2704 Asm->EmitLabelOffsetDifference(DwarfDebugRangeSectionSym,
2705 V->getValue(),
2706 DwarfDebugRangeSectionSym,
2707 4);
2708 break;
2709 }
Bill Wendling55fccda2009-05-20 23:21:38 +00002710 default:
2711 // Emit an attribute using the defined form.
Chris Lattnerbc0027b2010-04-05 00:13:49 +00002712 Values[i]->EmitValue(Asm, Form);
Bill Wendling55fccda2009-05-20 23:21:38 +00002713 break;
2714 }
Bill Wendling55fccda2009-05-20 23:21:38 +00002715 }
2716
2717 // Emit the DIE children if any.
2718 if (Abbrev->getChildrenFlag() == dwarf::DW_CHILDREN_yes) {
2719 const std::vector<DIE *> &Children = Die->getChildren();
2720
2721 for (unsigned j = 0, M = Children.size(); j < M; ++j)
Devang Patelc50078e2009-11-21 02:48:08 +00002722 emitDIE(Children[j]);
Bill Wendling55fccda2009-05-20 23:21:38 +00002723
Chris Lattner97c69b72010-04-04 18:52:31 +00002724 if (Asm->isVerbose())
Chris Lattner9ef8efd2010-03-09 23:52:58 +00002725 Asm->OutStreamer.AddComment("End Of Children Mark");
2726 Asm->EmitInt8(0);
Bill Wendling55fccda2009-05-20 23:21:38 +00002727 }
2728}
2729
Devang Patelfe0be132009-12-09 18:24:21 +00002730/// emitDebugInfo - Emit the debug info section.
Bill Wendling55fccda2009-05-20 23:21:38 +00002731///
Devang Patelfe0be132009-12-09 18:24:21 +00002732void DwarfDebug::emitDebugInfo() {
2733 // Start debug info section.
2734 Asm->OutStreamer.SwitchSection(
2735 Asm->getObjFileLowering().getDwarfInfoSection());
2736 DIE *Die = ModuleCU->getCUDie();
Bill Wendling55fccda2009-05-20 23:21:38 +00002737
2738 // Emit the compile units header.
Chris Lattnerb93558d2010-04-04 19:25:43 +00002739 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("info_begin",
2740 ModuleCU->getID()));
Bill Wendling55fccda2009-05-20 23:21:38 +00002741
2742 // Emit size of content not including length itself
2743 unsigned ContentSize = Die->getSize() +
2744 sizeof(int16_t) + // DWARF version number
2745 sizeof(int32_t) + // Offset Into Abbrev. Section
2746 sizeof(int8_t) + // Pointer Size (in bytes)
2747 sizeof(int32_t); // FIXME - extra pad for gdb bug.
2748
Chris Lattner9ef8efd2010-03-09 23:52:58 +00002749 Asm->OutStreamer.AddComment("Length of Compilation Unit Info");
2750 Asm->EmitInt32(ContentSize);
2751 Asm->OutStreamer.AddComment("DWARF version number");
2752 Asm->EmitInt16(dwarf::DWARF_VERSION);
2753 Asm->OutStreamer.AddComment("Offset Into Abbrev. Section");
Chris Lattnerc06b4742010-04-04 23:25:33 +00002754 Asm->EmitSectionOffset(Asm->GetTempSymbol("abbrev_begin"),
2755 DwarfAbbrevSectionSym);
Chris Lattner9ef8efd2010-03-09 23:52:58 +00002756 Asm->OutStreamer.AddComment("Address Size (in bytes)");
Chris Lattnerbc0027b2010-04-05 00:13:49 +00002757 Asm->EmitInt8(Asm->getTargetData().getPointerSize());
Bill Wendling55fccda2009-05-20 23:21:38 +00002758
Devang Patelc50078e2009-11-21 02:48:08 +00002759 emitDIE(Die);
Bill Wendling55fccda2009-05-20 23:21:38 +00002760 // FIXME - extra padding for gdb bug.
Chris Lattner9ef8efd2010-03-09 23:52:58 +00002761 Asm->OutStreamer.AddComment("4 extra padding bytes for GDB");
2762 Asm->EmitInt8(0);
2763 Asm->EmitInt8(0);
2764 Asm->EmitInt8(0);
2765 Asm->EmitInt8(0);
Chris Lattnerb93558d2010-04-04 19:25:43 +00002766 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("info_end", ModuleCU->getID()));
Bill Wendling55fccda2009-05-20 23:21:38 +00002767}
2768
Devang Patelc50078e2009-11-21 02:48:08 +00002769/// emitAbbreviations - Emit the abbreviation section.
Bill Wendling55fccda2009-05-20 23:21:38 +00002770///
Devang Patelc50078e2009-11-21 02:48:08 +00002771void DwarfDebug::emitAbbreviations() const {
Bill Wendling55fccda2009-05-20 23:21:38 +00002772 // Check to see if it is worth the effort.
2773 if (!Abbreviations.empty()) {
2774 // Start the debug abbrev section.
Chris Lattner73266f92009-08-19 05:49:37 +00002775 Asm->OutStreamer.SwitchSection(
2776 Asm->getObjFileLowering().getDwarfAbbrevSection());
Bill Wendling55fccda2009-05-20 23:21:38 +00002777
Chris Lattnerb93558d2010-04-04 19:25:43 +00002778 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("abbrev_begin"));
Bill Wendling55fccda2009-05-20 23:21:38 +00002779
2780 // For each abbrevation.
2781 for (unsigned i = 0, N = Abbreviations.size(); i < N; ++i) {
2782 // Get abbreviation data
2783 const DIEAbbrev *Abbrev = Abbreviations[i];
2784
2785 // Emit the abbrevations code (base 1 index.)
Chris Lattner26be1c12010-04-04 19:09:29 +00002786 Asm->EmitULEB128(Abbrev->getNumber(), "Abbreviation Code");
Bill Wendling55fccda2009-05-20 23:21:38 +00002787
2788 // Emit the abbreviations data.
Chris Lattnerbc0027b2010-04-05 00:13:49 +00002789 Abbrev->Emit(Asm);
Bill Wendling55fccda2009-05-20 23:21:38 +00002790 }
2791
2792 // Mark end of abbreviations.
Chris Lattner26be1c12010-04-04 19:09:29 +00002793 Asm->EmitULEB128(0, "EOM(3)");
Bill Wendling55fccda2009-05-20 23:21:38 +00002794
Chris Lattnerb93558d2010-04-04 19:25:43 +00002795 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("abbrev_end"));
Bill Wendling55fccda2009-05-20 23:21:38 +00002796 }
2797}
2798
Devang Patelc50078e2009-11-21 02:48:08 +00002799/// emitEndOfLineMatrix - Emit the last address of the section and the end of
Bill Wendling55fccda2009-05-20 23:21:38 +00002800/// the line matrix.
2801///
Devang Patelc50078e2009-11-21 02:48:08 +00002802void DwarfDebug::emitEndOfLineMatrix(unsigned SectionEnd) {
Bill Wendling55fccda2009-05-20 23:21:38 +00002803 // Define last address of section.
Chris Lattner9ef8efd2010-03-09 23:52:58 +00002804 Asm->OutStreamer.AddComment("Extended Op");
2805 Asm->EmitInt8(0);
2806
2807 Asm->OutStreamer.AddComment("Op size");
Chris Lattnerbc0027b2010-04-05 00:13:49 +00002808 Asm->EmitInt8(Asm->getTargetData().getPointerSize() + 1);
Chris Lattner9ef8efd2010-03-09 23:52:58 +00002809 Asm->OutStreamer.AddComment("DW_LNE_set_address");
2810 Asm->EmitInt8(dwarf::DW_LNE_set_address);
2811
2812 Asm->OutStreamer.AddComment("Section end label");
Chris Lattnereb159d62010-03-10 01:17:49 +00002813
Chris Lattnerb93558d2010-04-04 19:25:43 +00002814 Asm->OutStreamer.EmitSymbolValue(Asm->GetTempSymbol("section_end",SectionEnd),
Chris Lattnerbc0027b2010-04-05 00:13:49 +00002815 Asm->getTargetData().getPointerSize(),
2816 0/*AddrSpace*/);
Bill Wendling55fccda2009-05-20 23:21:38 +00002817
2818 // Mark end of matrix.
Chris Lattner9ef8efd2010-03-09 23:52:58 +00002819 Asm->OutStreamer.AddComment("DW_LNE_end_sequence");
2820 Asm->EmitInt8(0);
Chris Lattnerad653482010-01-22 22:09:00 +00002821 Asm->EmitInt8(1);
Chris Lattnerbcc79432010-01-22 23:18:42 +00002822 Asm->EmitInt8(1);
Bill Wendling55fccda2009-05-20 23:21:38 +00002823}
2824
Devang Patelc50078e2009-11-21 02:48:08 +00002825/// emitDebugLines - Emit source line information.
Bill Wendling55fccda2009-05-20 23:21:38 +00002826///
Devang Patelc50078e2009-11-21 02:48:08 +00002827void DwarfDebug::emitDebugLines() {
Bill Wendling55fccda2009-05-20 23:21:38 +00002828 // If the target is using .loc/.file, the assembler will be emitting the
2829 // .debug_line table automatically.
Chris Lattnerbc0027b2010-04-05 00:13:49 +00002830 if (Asm->MAI->hasDotLocAndDotFile())
Bill Wendling55fccda2009-05-20 23:21:38 +00002831 return;
2832
2833 // Minimum line delta, thus ranging from -10..(255-10).
2834 const int MinLineDelta = -(dwarf::DW_LNS_fixed_advance_pc + 1);
2835 // Maximum line delta, thus ranging from -10..(255-10).
2836 const int MaxLineDelta = 255 + MinLineDelta;
2837
2838 // Start the dwarf line section.
Chris Lattner73266f92009-08-19 05:49:37 +00002839 Asm->OutStreamer.SwitchSection(
2840 Asm->getObjFileLowering().getDwarfLineSection());
Bill Wendling55fccda2009-05-20 23:21:38 +00002841
2842 // Construct the section header.
Chris Lattner9ef8efd2010-03-09 23:52:58 +00002843 Asm->OutStreamer.AddComment("Length of Source Line Info");
Chris Lattnerfd2a3f62010-04-04 19:58:12 +00002844 Asm->EmitLabelDifference(Asm->GetTempSymbol("line_end"),
2845 Asm->GetTempSymbol("line_begin"), 4);
Chris Lattnerb93558d2010-04-04 19:25:43 +00002846 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("line_begin"));
Bill Wendling55fccda2009-05-20 23:21:38 +00002847
Chris Lattner9ef8efd2010-03-09 23:52:58 +00002848 Asm->OutStreamer.AddComment("DWARF version number");
2849 Asm->EmitInt16(dwarf::DWARF_VERSION);
Bill Wendling55fccda2009-05-20 23:21:38 +00002850
Chris Lattner9ef8efd2010-03-09 23:52:58 +00002851 Asm->OutStreamer.AddComment("Prolog Length");
Chris Lattnerfd2a3f62010-04-04 19:58:12 +00002852 Asm->EmitLabelDifference(Asm->GetTempSymbol("line_prolog_end"),
2853 Asm->GetTempSymbol("line_prolog_begin"), 4);
Chris Lattnerb93558d2010-04-04 19:25:43 +00002854 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("line_prolog_begin"));
Bill Wendling55fccda2009-05-20 23:21:38 +00002855
Chris Lattner9ef8efd2010-03-09 23:52:58 +00002856 Asm->OutStreamer.AddComment("Minimum Instruction Length");
2857 Asm->EmitInt8(1);
2858 Asm->OutStreamer.AddComment("Default is_stmt_start flag");
2859 Asm->EmitInt8(1);
2860 Asm->OutStreamer.AddComment("Line Base Value (Special Opcodes)");
2861 Asm->EmitInt8(MinLineDelta);
2862 Asm->OutStreamer.AddComment("Line Range Value (Special Opcodes)");
2863 Asm->EmitInt8(MaxLineDelta);
2864 Asm->OutStreamer.AddComment("Special Opcode Base");
2865 Asm->EmitInt8(-MinLineDelta);
Bill Wendling55fccda2009-05-20 23:21:38 +00002866
2867 // Line number standard opcode encodings argument count
Chris Lattner9ef8efd2010-03-09 23:52:58 +00002868 Asm->OutStreamer.AddComment("DW_LNS_copy arg count");
2869 Asm->EmitInt8(0);
2870 Asm->OutStreamer.AddComment("DW_LNS_advance_pc arg count");
2871 Asm->EmitInt8(1);
2872 Asm->OutStreamer.AddComment("DW_LNS_advance_line arg count");
2873 Asm->EmitInt8(1);
2874 Asm->OutStreamer.AddComment("DW_LNS_set_file arg count");
2875 Asm->EmitInt8(1);
2876 Asm->OutStreamer.AddComment("DW_LNS_set_column arg count");
2877 Asm->EmitInt8(1);
2878 Asm->OutStreamer.AddComment("DW_LNS_negate_stmt arg count");
2879 Asm->EmitInt8(0);
2880 Asm->OutStreamer.AddComment("DW_LNS_set_basic_block arg count");
2881 Asm->EmitInt8(0);
2882 Asm->OutStreamer.AddComment("DW_LNS_const_add_pc arg count");
2883 Asm->EmitInt8(0);
2884 Asm->OutStreamer.AddComment("DW_LNS_fixed_advance_pc arg count");
2885 Asm->EmitInt8(1);
Bill Wendling55fccda2009-05-20 23:21:38 +00002886
2887 // Emit directories.
2888 for (unsigned DI = 1, DE = getNumSourceDirectories()+1; DI != DE; ++DI) {
Chris Lattnercc564642010-01-23 03:11:46 +00002889 const std::string &Dir = getSourceDirectoryName(DI);
Chris Lattner97c69b72010-04-04 18:52:31 +00002890 if (Asm->isVerbose()) Asm->OutStreamer.AddComment("Directory");
Chris Lattnercc564642010-01-23 03:11:46 +00002891 Asm->OutStreamer.EmitBytes(StringRef(Dir.c_str(), Dir.size()+1), 0);
Bill Wendling55fccda2009-05-20 23:21:38 +00002892 }
2893
Chris Lattner9ef8efd2010-03-09 23:52:58 +00002894 Asm->OutStreamer.AddComment("End of directories");
2895 Asm->EmitInt8(0);
Bill Wendling55fccda2009-05-20 23:21:38 +00002896
2897 // Emit files.
2898 for (unsigned SI = 1, SE = getNumSourceIds()+1; SI != SE; ++SI) {
2899 // Remember source id starts at 1.
2900 std::pair<unsigned, unsigned> Id = getSourceDirectoryAndFileIds(SI);
Chris Lattnercc564642010-01-23 03:11:46 +00002901 const std::string &FN = getSourceFileName(Id.second);
Chris Lattner97c69b72010-04-04 18:52:31 +00002902 if (Asm->isVerbose()) Asm->OutStreamer.AddComment("Source");
Chris Lattnercc564642010-01-23 03:11:46 +00002903 Asm->OutStreamer.EmitBytes(StringRef(FN.c_str(), FN.size()+1), 0);
2904
Chris Lattner26be1c12010-04-04 19:09:29 +00002905 Asm->EmitULEB128(Id.first, "Directory #");
2906 Asm->EmitULEB128(0, "Mod date");
2907 Asm->EmitULEB128(0, "File size");
Bill Wendling55fccda2009-05-20 23:21:38 +00002908 }
2909
Chris Lattner9ef8efd2010-03-09 23:52:58 +00002910 Asm->OutStreamer.AddComment("End of files");
2911 Asm->EmitInt8(0);
Bill Wendling55fccda2009-05-20 23:21:38 +00002912
Chris Lattnerb93558d2010-04-04 19:25:43 +00002913 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("line_prolog_end"));
Bill Wendling55fccda2009-05-20 23:21:38 +00002914
2915 // A sequence for each text section.
2916 unsigned SecSrcLinesSize = SectionSourceLines.size();
2917
2918 for (unsigned j = 0; j < SecSrcLinesSize; ++j) {
2919 // Isolate current sections line info.
2920 const std::vector<SrcLineInfo> &LineInfos = SectionSourceLines[j];
2921
Bill Wendling55fccda2009-05-20 23:21:38 +00002922 // Dwarf assumes we start with first line of first source file.
2923 unsigned Source = 1;
2924 unsigned Line = 1;
2925
2926 // Construct rows of the address, source, line, column matrix.
2927 for (unsigned i = 0, N = LineInfos.size(); i < N; ++i) {
2928 const SrcLineInfo &LineInfo = LineInfos[i];
Chris Lattner8d9d06a2010-03-14 08:15:55 +00002929 MCSymbol *Label = LineInfo.getLabel();
Chris Lattner31ae74d2010-03-14 02:20:58 +00002930 if (!Label->isDefined()) continue; // Not emitted, in dead code.
Bill Wendling55fccda2009-05-20 23:21:38 +00002931
Caroline Tice9da96d82009-09-11 18:25:54 +00002932 if (LineInfo.getLine() == 0) continue;
2933
Chris Lattner8bd2f8f2010-03-09 23:38:23 +00002934 if (Asm->isVerbose()) {
Chris Lattneree3b40f2010-03-10 01:04:13 +00002935 std::pair<unsigned, unsigned> SrcID =
Bill Wendling55fccda2009-05-20 23:21:38 +00002936 getSourceDirectoryAndFileIds(LineInfo.getSourceID());
Chris Lattneree3b40f2010-03-10 01:04:13 +00002937 Asm->OutStreamer.AddComment(Twine(getSourceDirectoryName(SrcID.first)) +
Chris Lattner48fb0b12010-03-10 02:29:31 +00002938 "/" +
2939 Twine(getSourceFileName(SrcID.second)) +
Chris Lattneree3b40f2010-03-10 01:04:13 +00002940 ":" + Twine(LineInfo.getLine()));
Bill Wendling55fccda2009-05-20 23:21:38 +00002941 }
2942
2943 // Define the line address.
Chris Lattner9ef8efd2010-03-09 23:52:58 +00002944 Asm->OutStreamer.AddComment("Extended Op");
2945 Asm->EmitInt8(0);
2946 Asm->OutStreamer.AddComment("Op size");
Chris Lattnerbc0027b2010-04-05 00:13:49 +00002947 Asm->EmitInt8(Asm->getTargetData().getPointerSize() + 1);
Chris Lattner9ef8efd2010-03-09 23:52:58 +00002948
2949 Asm->OutStreamer.AddComment("DW_LNE_set_address");
2950 Asm->EmitInt8(dwarf::DW_LNE_set_address);
2951
2952 Asm->OutStreamer.AddComment("Location label");
Chris Lattnerbc0027b2010-04-05 00:13:49 +00002953 Asm->OutStreamer.EmitSymbolValue(Label,
2954 Asm->getTargetData().getPointerSize(),
Chris Lattner31ae74d2010-03-14 02:20:58 +00002955 0/*AddrSpace*/);
Chris Lattnereb159d62010-03-10 01:17:49 +00002956
Bill Wendling55fccda2009-05-20 23:21:38 +00002957 // If change of source, then switch to the new source.
2958 if (Source != LineInfo.getSourceID()) {
2959 Source = LineInfo.getSourceID();
Chris Lattner9ef8efd2010-03-09 23:52:58 +00002960 Asm->OutStreamer.AddComment("DW_LNS_set_file");
2961 Asm->EmitInt8(dwarf::DW_LNS_set_file);
Chris Lattner26be1c12010-04-04 19:09:29 +00002962 Asm->EmitULEB128(Source, "New Source");
Bill Wendling55fccda2009-05-20 23:21:38 +00002963 }
2964
2965 // If change of line.
2966 if (Line != LineInfo.getLine()) {
2967 // Determine offset.
2968 int Offset = LineInfo.getLine() - Line;
2969 int Delta = Offset - MinLineDelta;
2970
2971 // Update line.
2972 Line = LineInfo.getLine();
2973
2974 // If delta is small enough and in range...
2975 if (Delta >= 0 && Delta < (MaxLineDelta - 1)) {
2976 // ... then use fast opcode.
Chris Lattner9ef8efd2010-03-09 23:52:58 +00002977 Asm->OutStreamer.AddComment("Line Delta");
2978 Asm->EmitInt8(Delta - MinLineDelta);
Bill Wendling55fccda2009-05-20 23:21:38 +00002979 } else {
2980 // ... otherwise use long hand.
Chris Lattner9ef8efd2010-03-09 23:52:58 +00002981 Asm->OutStreamer.AddComment("DW_LNS_advance_line");
Bill Wendling55fccda2009-05-20 23:21:38 +00002982 Asm->EmitInt8(dwarf::DW_LNS_advance_line);
Chris Lattner26be1c12010-04-04 19:09:29 +00002983 Asm->EmitSLEB128(Offset, "Line Offset");
Chris Lattner9ef8efd2010-03-09 23:52:58 +00002984 Asm->OutStreamer.AddComment("DW_LNS_copy");
2985 Asm->EmitInt8(dwarf::DW_LNS_copy);
Bill Wendling55fccda2009-05-20 23:21:38 +00002986 }
2987 } else {
2988 // Copy the previous row (different address or source)
Chris Lattner9ef8efd2010-03-09 23:52:58 +00002989 Asm->OutStreamer.AddComment("DW_LNS_copy");
2990 Asm->EmitInt8(dwarf::DW_LNS_copy);
Bill Wendling55fccda2009-05-20 23:21:38 +00002991 }
2992 }
2993
Devang Patelc50078e2009-11-21 02:48:08 +00002994 emitEndOfLineMatrix(j + 1);
Bill Wendling55fccda2009-05-20 23:21:38 +00002995 }
2996
2997 if (SecSrcLinesSize == 0)
2998 // Because we're emitting a debug_line section, we still need a line
2999 // table. The linker and friends expect it to exist. If there's nothing to
3000 // put into it, emit an empty table.
Devang Patelc50078e2009-11-21 02:48:08 +00003001 emitEndOfLineMatrix(1);
Bill Wendling55fccda2009-05-20 23:21:38 +00003002
Chris Lattnerb93558d2010-04-04 19:25:43 +00003003 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("line_end"));
Bill Wendling55fccda2009-05-20 23:21:38 +00003004}
3005
Devang Patelc50078e2009-11-21 02:48:08 +00003006/// emitCommonDebugFrame - Emit common frame info into a debug frame section.
Bill Wendling55fccda2009-05-20 23:21:38 +00003007///
Devang Patelc50078e2009-11-21 02:48:08 +00003008void DwarfDebug::emitCommonDebugFrame() {
Chris Lattnerbc0027b2010-04-05 00:13:49 +00003009 if (!Asm->MAI->doesDwarfRequireFrameSection())
Bill Wendling55fccda2009-05-20 23:21:38 +00003010 return;
3011
Chris Lattnerbc0027b2010-04-05 00:13:49 +00003012 int stackGrowth = Asm->getTargetData().getPointerSize();
3013 if (Asm->TM.getFrameInfo()->getStackGrowthDirection() ==
3014 TargetFrameInfo::StackGrowsDown)
3015 stackGrowth *= -1;
Bill Wendling55fccda2009-05-20 23:21:38 +00003016
3017 // Start the dwarf frame section.
Chris Lattner73266f92009-08-19 05:49:37 +00003018 Asm->OutStreamer.SwitchSection(
3019 Asm->getObjFileLowering().getDwarfFrameSection());
Bill Wendling55fccda2009-05-20 23:21:38 +00003020
Chris Lattnerb93558d2010-04-04 19:25:43 +00003021 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("debug_frame_common"));
Chris Lattner9ef8efd2010-03-09 23:52:58 +00003022 Asm->OutStreamer.AddComment("Length of Common Information Entry");
Chris Lattnerfd2a3f62010-04-04 19:58:12 +00003023 Asm->EmitLabelDifference(Asm->GetTempSymbol("debug_frame_common_end"),
3024 Asm->GetTempSymbol("debug_frame_common_begin"), 4);
Bill Wendling55fccda2009-05-20 23:21:38 +00003025
Chris Lattnerb93558d2010-04-04 19:25:43 +00003026 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("debug_frame_common_begin"));
Chris Lattner9ef8efd2010-03-09 23:52:58 +00003027 Asm->OutStreamer.AddComment("CIE Identifier Tag");
Bill Wendling55fccda2009-05-20 23:21:38 +00003028 Asm->EmitInt32((int)dwarf::DW_CIE_ID);
Chris Lattner9ef8efd2010-03-09 23:52:58 +00003029 Asm->OutStreamer.AddComment("CIE Version");
Bill Wendling55fccda2009-05-20 23:21:38 +00003030 Asm->EmitInt8(dwarf::DW_CIE_VERSION);
Chris Lattner9ef8efd2010-03-09 23:52:58 +00003031 Asm->OutStreamer.AddComment("CIE Augmentation");
Chris Lattnercc564642010-01-23 03:11:46 +00003032 Asm->OutStreamer.EmitIntValue(0, 1, /*addrspace*/0); // nul terminator.
Chris Lattner26be1c12010-04-04 19:09:29 +00003033 Asm->EmitULEB128(1, "CIE Code Alignment Factor");
3034 Asm->EmitSLEB128(stackGrowth, "CIE Data Alignment Factor");
Chris Lattner9ef8efd2010-03-09 23:52:58 +00003035 Asm->OutStreamer.AddComment("CIE RA Column");
Chris Lattnerbc0027b2010-04-05 00:13:49 +00003036 const TargetRegisterInfo *RI = Asm->TM.getRegisterInfo();
Bill Wendling55fccda2009-05-20 23:21:38 +00003037 Asm->EmitInt8(RI->getDwarfRegNum(RI->getRARegister(), false));
Bill Wendling55fccda2009-05-20 23:21:38 +00003038
3039 std::vector<MachineMove> Moves;
3040 RI->getInitialFrameState(Moves);
3041
Chris Lattner193fec02010-04-04 23:41:46 +00003042 Asm->EmitFrameMoves(Moves, 0, false);
Bill Wendling55fccda2009-05-20 23:21:38 +00003043
3044 Asm->EmitAlignment(2, 0, 0, false);
Chris Lattnerb93558d2010-04-04 19:25:43 +00003045 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("debug_frame_common_end"));
Bill Wendling55fccda2009-05-20 23:21:38 +00003046}
3047
Devang Patelc50078e2009-11-21 02:48:08 +00003048/// emitFunctionDebugFrame - Emit per function frame info into a debug frame
Bill Wendling55fccda2009-05-20 23:21:38 +00003049/// section.
Chris Lattnerdd21da82010-03-13 07:26:18 +00003050void DwarfDebug::
3051emitFunctionDebugFrame(const FunctionDebugFrameInfo &DebugFrameInfo) {
Chris Lattnerbc0027b2010-04-05 00:13:49 +00003052 if (!Asm->MAI->doesDwarfRequireFrameSection())
Bill Wendling55fccda2009-05-20 23:21:38 +00003053 return;
3054
3055 // Start the dwarf frame section.
Chris Lattner73266f92009-08-19 05:49:37 +00003056 Asm->OutStreamer.SwitchSection(
3057 Asm->getObjFileLowering().getDwarfFrameSection());
Bill Wendling55fccda2009-05-20 23:21:38 +00003058
Chris Lattner9ef8efd2010-03-09 23:52:58 +00003059 Asm->OutStreamer.AddComment("Length of Frame Information Entry");
Chris Lattnerdd21da82010-03-13 07:26:18 +00003060 MCSymbol *DebugFrameBegin =
Chris Lattnerb93558d2010-04-04 19:25:43 +00003061 Asm->GetTempSymbol("debug_frame_begin", DebugFrameInfo.Number);
Chris Lattnerdd21da82010-03-13 07:26:18 +00003062 MCSymbol *DebugFrameEnd =
Chris Lattnerb93558d2010-04-04 19:25:43 +00003063 Asm->GetTempSymbol("debug_frame_end", DebugFrameInfo.Number);
Chris Lattnerfd2a3f62010-04-04 19:58:12 +00003064 Asm->EmitLabelDifference(DebugFrameEnd, DebugFrameBegin, 4);
Bill Wendling55fccda2009-05-20 23:21:38 +00003065
Chris Lattnerdd21da82010-03-13 07:26:18 +00003066 Asm->OutStreamer.EmitLabel(DebugFrameBegin);
Bill Wendling55fccda2009-05-20 23:21:38 +00003067
Chris Lattner9ef8efd2010-03-09 23:52:58 +00003068 Asm->OutStreamer.AddComment("FDE CIE offset");
Chris Lattnerc06b4742010-04-04 23:25:33 +00003069 Asm->EmitSectionOffset(Asm->GetTempSymbol("debug_frame_common"),
3070 DwarfFrameSectionSym);
Bill Wendling55fccda2009-05-20 23:21:38 +00003071
Chris Lattner9ef8efd2010-03-09 23:52:58 +00003072 Asm->OutStreamer.AddComment("FDE initial location");
Chris Lattnerb93558d2010-04-04 19:25:43 +00003073 MCSymbol *FuncBeginSym =
3074 Asm->GetTempSymbol("func_begin", DebugFrameInfo.Number);
Chris Lattner314e3362010-03-13 07:40:56 +00003075 Asm->OutStreamer.EmitSymbolValue(FuncBeginSym,
Chris Lattnerbc0027b2010-04-05 00:13:49 +00003076 Asm->getTargetData().getPointerSize(),
3077 0/*AddrSpace*/);
Chris Lattnereb159d62010-03-10 01:17:49 +00003078
3079
Chris Lattner9ef8efd2010-03-09 23:52:58 +00003080 Asm->OutStreamer.AddComment("FDE address range");
Chris Lattnerfd2a3f62010-04-04 19:58:12 +00003081 Asm->EmitLabelDifference(Asm->GetTempSymbol("func_end",DebugFrameInfo.Number),
Chris Lattnerbc0027b2010-04-05 00:13:49 +00003082 FuncBeginSym, Asm->getTargetData().getPointerSize());
Bill Wendling55fccda2009-05-20 23:21:38 +00003083
Chris Lattner193fec02010-04-04 23:41:46 +00003084 Asm->EmitFrameMoves(DebugFrameInfo.Moves, FuncBeginSym, false);
Bill Wendling55fccda2009-05-20 23:21:38 +00003085
3086 Asm->EmitAlignment(2, 0, 0, false);
Chris Lattnerdd21da82010-03-13 07:26:18 +00003087 Asm->OutStreamer.EmitLabel(DebugFrameEnd);
Bill Wendling55fccda2009-05-20 23:21:38 +00003088}
3089
Devang Patelfe0be132009-12-09 18:24:21 +00003090/// emitDebugPubNames - Emit visible names into a debug pubnames section.
3091///
3092void DwarfDebug::emitDebugPubNames() {
3093 // Start the dwarf pubnames section.
3094 Asm->OutStreamer.SwitchSection(
3095 Asm->getObjFileLowering().getDwarfPubNamesSection());
3096
Chris Lattner9ef8efd2010-03-09 23:52:58 +00003097 Asm->OutStreamer.AddComment("Length of Public Names Info");
Chris Lattnerfd2a3f62010-04-04 19:58:12 +00003098 Asm->EmitLabelDifference(
3099 Asm->GetTempSymbol("pubnames_end", ModuleCU->getID()),
3100 Asm->GetTempSymbol("pubnames_begin", ModuleCU->getID()), 4);
Bill Wendling55fccda2009-05-20 23:21:38 +00003101
Chris Lattnerb93558d2010-04-04 19:25:43 +00003102 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("pubnames_begin",
3103 ModuleCU->getID()));
Bill Wendling55fccda2009-05-20 23:21:38 +00003104
Chris Lattner9ef8efd2010-03-09 23:52:58 +00003105 Asm->OutStreamer.AddComment("DWARF Version");
3106 Asm->EmitInt16(dwarf::DWARF_VERSION);
Bill Wendling55fccda2009-05-20 23:21:38 +00003107
Chris Lattner9ef8efd2010-03-09 23:52:58 +00003108 Asm->OutStreamer.AddComment("Offset of Compilation Unit Info");
Chris Lattnerc06b4742010-04-04 23:25:33 +00003109 Asm->EmitSectionOffset(Asm->GetTempSymbol("info_begin", ModuleCU->getID()),
3110 DwarfInfoSectionSym);
Bill Wendling55fccda2009-05-20 23:21:38 +00003111
Chris Lattner9ef8efd2010-03-09 23:52:58 +00003112 Asm->OutStreamer.AddComment("Compilation Unit Length");
Chris Lattnerfd2a3f62010-04-04 19:58:12 +00003113 Asm->EmitLabelDifference(Asm->GetTempSymbol("info_end", ModuleCU->getID()),
3114 Asm->GetTempSymbol("info_begin", ModuleCU->getID()),
3115 4);
Bill Wendling55fccda2009-05-20 23:21:38 +00003116
Devang Patelfe0be132009-12-09 18:24:21 +00003117 const StringMap<DIE*> &Globals = ModuleCU->getGlobals();
Bill Wendling55fccda2009-05-20 23:21:38 +00003118 for (StringMap<DIE*>::const_iterator
3119 GI = Globals.begin(), GE = Globals.end(); GI != GE; ++GI) {
3120 const char *Name = GI->getKeyData();
Chris Lattner9ef8efd2010-03-09 23:52:58 +00003121 DIE *Entity = GI->second;
Bill Wendling55fccda2009-05-20 23:21:38 +00003122
Chris Lattner9ef8efd2010-03-09 23:52:58 +00003123 Asm->OutStreamer.AddComment("DIE offset");
3124 Asm->EmitInt32(Entity->getOffset());
Chris Lattnercc564642010-01-23 03:11:46 +00003125
Chris Lattner97c69b72010-04-04 18:52:31 +00003126 if (Asm->isVerbose())
Chris Lattnercc564642010-01-23 03:11:46 +00003127 Asm->OutStreamer.AddComment("External Name");
3128 Asm->OutStreamer.EmitBytes(StringRef(Name, strlen(Name)+1), 0);
Bill Wendling55fccda2009-05-20 23:21:38 +00003129 }
3130
Chris Lattner9ef8efd2010-03-09 23:52:58 +00003131 Asm->OutStreamer.AddComment("End Mark");
3132 Asm->EmitInt32(0);
Chris Lattnerb93558d2010-04-04 19:25:43 +00003133 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("pubnames_end",
3134 ModuleCU->getID()));
Bill Wendling55fccda2009-05-20 23:21:38 +00003135}
3136
Devang Patelec13b4f2009-11-24 01:14:22 +00003137void DwarfDebug::emitDebugPubTypes() {
Devang Patel6f2bdd52009-11-24 19:18:41 +00003138 // Start the dwarf pubnames section.
3139 Asm->OutStreamer.SwitchSection(
3140 Asm->getObjFileLowering().getDwarfPubTypesSection());
Chris Lattner9ef8efd2010-03-09 23:52:58 +00003141 Asm->OutStreamer.AddComment("Length of Public Types Info");
Chris Lattnerfd2a3f62010-04-04 19:58:12 +00003142 Asm->EmitLabelDifference(
3143 Asm->GetTempSymbol("pubtypes_end", ModuleCU->getID()),
3144 Asm->GetTempSymbol("pubtypes_begin", ModuleCU->getID()), 4);
Devang Patelec13b4f2009-11-24 01:14:22 +00003145
Chris Lattnerb93558d2010-04-04 19:25:43 +00003146 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("pubtypes_begin",
3147 ModuleCU->getID()));
Devang Patelec13b4f2009-11-24 01:14:22 +00003148
Chris Lattner97c69b72010-04-04 18:52:31 +00003149 if (Asm->isVerbose()) Asm->OutStreamer.AddComment("DWARF Version");
Devang Patel40b6cda2010-02-02 03:47:27 +00003150 Asm->EmitInt16(dwarf::DWARF_VERSION);
Devang Patelec13b4f2009-11-24 01:14:22 +00003151
Chris Lattner9ef8efd2010-03-09 23:52:58 +00003152 Asm->OutStreamer.AddComment("Offset of Compilation ModuleCU Info");
Chris Lattnerc06b4742010-04-04 23:25:33 +00003153 Asm->EmitSectionOffset(Asm->GetTempSymbol("info_begin", ModuleCU->getID()),
3154 DwarfInfoSectionSym);
Devang Patelec13b4f2009-11-24 01:14:22 +00003155
Chris Lattner9ef8efd2010-03-09 23:52:58 +00003156 Asm->OutStreamer.AddComment("Compilation ModuleCU Length");
Chris Lattnerfd2a3f62010-04-04 19:58:12 +00003157 Asm->EmitLabelDifference(Asm->GetTempSymbol("info_end", ModuleCU->getID()),
3158 Asm->GetTempSymbol("info_begin", ModuleCU->getID()),
3159 4);
Devang Patelec13b4f2009-11-24 01:14:22 +00003160
3161 const StringMap<DIE*> &Globals = ModuleCU->getGlobalTypes();
3162 for (StringMap<DIE*>::const_iterator
3163 GI = Globals.begin(), GE = Globals.end(); GI != GE; ++GI) {
3164 const char *Name = GI->getKeyData();
3165 DIE * Entity = GI->second;
3166
Chris Lattner97c69b72010-04-04 18:52:31 +00003167 if (Asm->isVerbose()) Asm->OutStreamer.AddComment("DIE offset");
Devang Patel40b6cda2010-02-02 03:47:27 +00003168 Asm->EmitInt32(Entity->getOffset());
Chris Lattnercc564642010-01-23 03:11:46 +00003169
Chris Lattner97c69b72010-04-04 18:52:31 +00003170 if (Asm->isVerbose()) Asm->OutStreamer.AddComment("External Name");
Devang Patel0ceb4892010-02-02 03:37:03 +00003171 Asm->OutStreamer.EmitBytes(StringRef(Name, GI->getKeyLength()+1), 0);
Devang Patelec13b4f2009-11-24 01:14:22 +00003172 }
3173
Chris Lattner9ef8efd2010-03-09 23:52:58 +00003174 Asm->OutStreamer.AddComment("End Mark");
3175 Asm->EmitInt32(0);
Chris Lattnerb93558d2010-04-04 19:25:43 +00003176 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("pubtypes_end",
3177 ModuleCU->getID()));
Devang Patelec13b4f2009-11-24 01:14:22 +00003178}
3179
Devang Patelc50078e2009-11-21 02:48:08 +00003180/// emitDebugStr - Emit visible names into a debug str section.
Bill Wendling55fccda2009-05-20 23:21:38 +00003181///
Devang Patelc50078e2009-11-21 02:48:08 +00003182void DwarfDebug::emitDebugStr() {
Bill Wendling55fccda2009-05-20 23:21:38 +00003183 // Check to see if it is worth the effort.
Chris Lattner8bd2f8f2010-03-09 23:38:23 +00003184 if (StringPool.empty()) return;
3185
3186 // Start the dwarf str section.
3187 Asm->OutStreamer.SwitchSection(
Chris Lattner73266f92009-08-19 05:49:37 +00003188 Asm->getObjFileLowering().getDwarfStrSection());
Bill Wendling55fccda2009-05-20 23:21:38 +00003189
Chris Lattner0f093f82010-03-13 02:17:42 +00003190 // Get all of the string pool entries and put them in an array by their ID so
3191 // we can sort them.
3192 SmallVector<std::pair<unsigned,
3193 StringMapEntry<std::pair<MCSymbol*, unsigned> >*>, 64> Entries;
3194
3195 for (StringMap<std::pair<MCSymbol*, unsigned> >::iterator
3196 I = StringPool.begin(), E = StringPool.end(); I != E; ++I)
3197 Entries.push_back(std::make_pair(I->second.second, &*I));
3198
3199 array_pod_sort(Entries.begin(), Entries.end());
3200
3201 for (unsigned i = 0, e = Entries.size(); i != e; ++i) {
Chris Lattner8bd2f8f2010-03-09 23:38:23 +00003202 // Emit a label for reference from debug information entries.
Chris Lattner0f093f82010-03-13 02:17:42 +00003203 Asm->OutStreamer.EmitLabel(Entries[i].second->getValue().first);
Chris Lattner8bd2f8f2010-03-09 23:38:23 +00003204
3205 // Emit the string itself.
Chris Lattner0f093f82010-03-13 02:17:42 +00003206 Asm->OutStreamer.EmitBytes(Entries[i].second->getKey(), 0/*addrspace*/);
Bill Wendling55fccda2009-05-20 23:21:38 +00003207 }
3208}
3209
Devang Patelc50078e2009-11-21 02:48:08 +00003210/// emitDebugLoc - Emit visible names into a debug loc section.
Bill Wendling55fccda2009-05-20 23:21:38 +00003211///
Devang Patelc50078e2009-11-21 02:48:08 +00003212void DwarfDebug::emitDebugLoc() {
Bill Wendling55fccda2009-05-20 23:21:38 +00003213 // Start the dwarf loc section.
Chris Lattner73266f92009-08-19 05:49:37 +00003214 Asm->OutStreamer.SwitchSection(
3215 Asm->getObjFileLowering().getDwarfLocSection());
Bill Wendling55fccda2009-05-20 23:21:38 +00003216}
3217
3218/// EmitDebugARanges - Emit visible names into a debug aranges section.
3219///
3220void DwarfDebug::EmitDebugARanges() {
3221 // Start the dwarf aranges section.
Chris Lattner73266f92009-08-19 05:49:37 +00003222 Asm->OutStreamer.SwitchSection(
3223 Asm->getObjFileLowering().getDwarfARangesSection());
Bill Wendling55fccda2009-05-20 23:21:38 +00003224}
3225
Devang Patelc50078e2009-11-21 02:48:08 +00003226/// emitDebugRanges - Emit visible names into a debug ranges section.
Bill Wendling55fccda2009-05-20 23:21:38 +00003227///
Devang Patelc50078e2009-11-21 02:48:08 +00003228void DwarfDebug::emitDebugRanges() {
Bill Wendling55fccda2009-05-20 23:21:38 +00003229 // Start the dwarf ranges section.
Chris Lattner73266f92009-08-19 05:49:37 +00003230 Asm->OutStreamer.SwitchSection(
Devang Patel146c6f72010-04-16 23:33:45 +00003231 Asm->getObjFileLowering().getDwarfRangesSection());
3232 for (SmallVector<const MCSymbol *, 8>::const_iterator I = DebugRangeSymbols.begin(),
3233 E = DebugRangeSymbols.end(); I != E; ++I) {
3234 if (*I)
3235 Asm->EmitLabelDifference(*I, TextSectionSym,
3236 Asm->getTargetData().getPointerSize());
3237 else
3238 Asm->OutStreamer.EmitIntValue(0, Asm->getTargetData().getPointerSize(),
3239 /*addrspace*/0);
3240 }
Bill Wendling55fccda2009-05-20 23:21:38 +00003241}
3242
Devang Patelc50078e2009-11-21 02:48:08 +00003243/// emitDebugMacInfo - Emit visible names into a debug macinfo section.
Bill Wendling55fccda2009-05-20 23:21:38 +00003244///
Devang Patelc50078e2009-11-21 02:48:08 +00003245void DwarfDebug::emitDebugMacInfo() {
Daniel Dunbar41716322009-09-19 20:40:05 +00003246 if (const MCSection *LineInfo =
Chris Lattner72d228d2009-08-02 07:24:22 +00003247 Asm->getObjFileLowering().getDwarfMacroInfoSection()) {
Bill Wendling55fccda2009-05-20 23:21:38 +00003248 // Start the dwarf macinfo section.
Chris Lattner73266f92009-08-19 05:49:37 +00003249 Asm->OutStreamer.SwitchSection(LineInfo);
Bill Wendling55fccda2009-05-20 23:21:38 +00003250 }
3251}
3252
Devang Patelc50078e2009-11-21 02:48:08 +00003253/// emitDebugInlineInfo - Emit inline info using following format.
Bill Wendling55fccda2009-05-20 23:21:38 +00003254/// Section Header:
3255/// 1. length of section
3256/// 2. Dwarf version number
3257/// 3. address size.
3258///
3259/// Entries (one "entry" for each function that was inlined):
3260///
3261/// 1. offset into __debug_str section for MIPS linkage name, if exists;
3262/// otherwise offset into __debug_str for regular function name.
3263/// 2. offset into __debug_str section for regular function name.
3264/// 3. an unsigned LEB128 number indicating the number of distinct inlining
3265/// instances for the function.
3266///
3267/// The rest of the entry consists of a {die_offset, low_pc} pair for each
3268/// inlined instance; the die_offset points to the inlined_subroutine die in the
3269/// __debug_info section, and the low_pc is the starting address for the
3270/// inlining instance.
Devang Patelc50078e2009-11-21 02:48:08 +00003271void DwarfDebug::emitDebugInlineInfo() {
Chris Lattnerbc0027b2010-04-05 00:13:49 +00003272 if (!Asm->MAI->doesDwarfUsesInlineInfoSection())
Bill Wendling55fccda2009-05-20 23:21:38 +00003273 return;
3274
Devang Patel5a3d37f2009-06-29 20:45:18 +00003275 if (!ModuleCU)
Bill Wendling55fccda2009-05-20 23:21:38 +00003276 return;
3277
Chris Lattner73266f92009-08-19 05:49:37 +00003278 Asm->OutStreamer.SwitchSection(
3279 Asm->getObjFileLowering().getDwarfDebugInlineSection());
Chris Lattnerad653482010-01-22 22:09:00 +00003280
Chris Lattner9ef8efd2010-03-09 23:52:58 +00003281 Asm->OutStreamer.AddComment("Length of Debug Inlined Information Entry");
Chris Lattnerfd2a3f62010-04-04 19:58:12 +00003282 Asm->EmitLabelDifference(Asm->GetTempSymbol("debug_inlined_end", 1),
3283 Asm->GetTempSymbol("debug_inlined_begin", 1), 4);
Bill Wendling55fccda2009-05-20 23:21:38 +00003284
Chris Lattnerb93558d2010-04-04 19:25:43 +00003285 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("debug_inlined_begin", 1));
Bill Wendling55fccda2009-05-20 23:21:38 +00003286
Chris Lattner9ef8efd2010-03-09 23:52:58 +00003287 Asm->OutStreamer.AddComment("Dwarf Version");
3288 Asm->EmitInt16(dwarf::DWARF_VERSION);
3289 Asm->OutStreamer.AddComment("Address Size (in bytes)");
Chris Lattnerbc0027b2010-04-05 00:13:49 +00003290 Asm->EmitInt8(Asm->getTargetData().getPointerSize());
Bill Wendling55fccda2009-05-20 23:21:38 +00003291
Devang Patel90a0fe32009-11-10 23:06:00 +00003292 for (SmallVector<MDNode *, 4>::iterator I = InlinedSPNodes.begin(),
3293 E = InlinedSPNodes.end(); I != E; ++I) {
Jim Grosbach652b7432009-11-21 23:12:12 +00003294
Devang Patel90a0fe32009-11-10 23:06:00 +00003295 MDNode *Node = *I;
Devang Patel7d707f92010-01-19 06:19:05 +00003296 DenseMap<MDNode *, SmallVector<InlineInfoLabels, 4> >::iterator II
Jim Grosbachb23f2422009-11-22 19:20:36 +00003297 = InlineInfo.find(Node);
Devang Patel90a0fe32009-11-10 23:06:00 +00003298 SmallVector<InlineInfoLabels, 4> &Labels = II->second;
Devang Patel15e723d2009-08-28 23:24:31 +00003299 DISubprogram SP(Node);
Devang Patel7f75bbe2009-11-25 17:36:49 +00003300 StringRef LName = SP.getLinkageName();
3301 StringRef Name = SP.getName();
Bill Wendling55fccda2009-05-20 23:21:38 +00003302
Chris Lattner9ef8efd2010-03-09 23:52:58 +00003303 Asm->OutStreamer.AddComment("MIPS linkage name");
Chris Lattnercc564642010-01-23 03:11:46 +00003304 if (LName.empty()) {
3305 Asm->OutStreamer.EmitBytes(Name, 0);
3306 Asm->OutStreamer.EmitIntValue(0, 1, 0); // nul terminator.
3307 } else
Chris Lattnerc06b4742010-04-04 23:25:33 +00003308 Asm->EmitSectionOffset(getStringPoolEntry(getRealLinkageName(LName)),
3309 DwarfStrSectionSym);
Devang Patel90a0fe32009-11-10 23:06:00 +00003310
Chris Lattner9ef8efd2010-03-09 23:52:58 +00003311 Asm->OutStreamer.AddComment("Function name");
Chris Lattnerc06b4742010-04-04 23:25:33 +00003312 Asm->EmitSectionOffset(getStringPoolEntry(Name), DwarfStrSectionSym);
Chris Lattner26be1c12010-04-04 19:09:29 +00003313 Asm->EmitULEB128(Labels.size(), "Inline count");
Bill Wendling55fccda2009-05-20 23:21:38 +00003314
Devang Patel90a0fe32009-11-10 23:06:00 +00003315 for (SmallVector<InlineInfoLabels, 4>::iterator LI = Labels.begin(),
Bill Wendling55fccda2009-05-20 23:21:38 +00003316 LE = Labels.end(); LI != LE; ++LI) {
Chris Lattner97c69b72010-04-04 18:52:31 +00003317 if (Asm->isVerbose()) Asm->OutStreamer.AddComment("DIE offset");
Chris Lattneread58652010-03-09 00:31:02 +00003318 Asm->EmitInt32(LI->second->getOffset());
Bill Wendling55fccda2009-05-20 23:21:38 +00003319
Chris Lattner97c69b72010-04-04 18:52:31 +00003320 if (Asm->isVerbose()) Asm->OutStreamer.AddComment("low_pc");
Chris Lattnerbc0027b2010-04-05 00:13:49 +00003321 Asm->OutStreamer.EmitSymbolValue(LI->first,
3322 Asm->getTargetData().getPointerSize(),0);
Bill Wendling55fccda2009-05-20 23:21:38 +00003323 }
3324 }
3325
Chris Lattnerb93558d2010-04-04 19:25:43 +00003326 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("debug_inlined_end", 1));
Bill Wendling55fccda2009-05-20 23:21:38 +00003327}