blob: 2f4ee5eef15695ceaf6b92a7850072014369c5b0 [file] [log] [blame]
Bill Wendling0310d762009-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//===----------------------------------------------------------------------===//
13
14#include "DwarfDebug.h"
15#include "llvm/Module.h"
David Greeneb2c66fc2009-08-19 21:52:55 +000016#include "llvm/CodeGen/MachineFunction.h"
Bill Wendling0310d762009-05-15 09:23:25 +000017#include "llvm/CodeGen/MachineModuleInfo.h"
Chris Lattnera87dea42009-07-31 18:48:30 +000018#include "llvm/MC/MCSection.h"
Chris Lattner6c2f9e12009-08-19 05:49:37 +000019#include "llvm/MC/MCStreamer.h"
Bill Wendling0310d762009-05-15 09:23:25 +000020#include "llvm/Target/TargetAsmInfo.h"
Bill Wendling0310d762009-05-15 09:23:25 +000021#include "llvm/Target/TargetData.h"
22#include "llvm/Target/TargetFrameInfo.h"
Chris Lattnerf0144122009-07-28 03:13:23 +000023#include "llvm/Target/TargetLoweringObjectFile.h"
24#include "llvm/Target/TargetRegisterInfo.h"
Chris Lattnera87dea42009-07-31 18:48:30 +000025#include "llvm/Support/Timer.h"
26#include "llvm/System/Path.h"
Bill Wendling0310d762009-05-15 09:23:25 +000027using namespace llvm;
28
29static TimerGroup &getDwarfTimerGroup() {
30 static TimerGroup DwarfTimerGroup("Dwarf Debugging");
31 return DwarfTimerGroup;
32}
33
34//===----------------------------------------------------------------------===//
35
36/// Configuration values for initial hash set sizes (log2).
37///
38static const unsigned InitDiesSetSize = 9; // log2(512)
39static const unsigned InitAbbreviationsSetSize = 9; // log2(512)
40static const unsigned InitValuesSetSize = 9; // log2(512)
41
42namespace llvm {
43
44//===----------------------------------------------------------------------===//
45/// CompileUnit - This dwarf writer support class manages information associate
46/// with a source file.
47class VISIBILITY_HIDDEN CompileUnit {
48 /// ID - File identifier for source.
49 ///
50 unsigned ID;
51
52 /// Die - Compile unit debug information entry.
53 ///
54 DIE *Die;
55
56 /// GVToDieMap - Tracks the mapping of unit level debug informaton
57 /// variables to debug information entries.
58 std::map<GlobalVariable *, DIE *> GVToDieMap;
59
60 /// GVToDIEEntryMap - Tracks the mapping of unit level debug informaton
61 /// descriptors to debug information entries using a DIEEntry proxy.
62 std::map<GlobalVariable *, DIEEntry *> GVToDIEEntryMap;
63
64 /// Globals - A map of globally visible named entities for this unit.
65 ///
66 StringMap<DIE*> Globals;
67
68 /// DiesSet - Used to uniquely define dies within the compile unit.
69 ///
70 FoldingSet<DIE> DiesSet;
71public:
72 CompileUnit(unsigned I, DIE *D)
Bill Wendling39dd6962009-05-20 23:31:45 +000073 : ID(I), Die(D), DiesSet(InitDiesSetSize) {}
74 ~CompileUnit() { delete Die; }
Bill Wendling0310d762009-05-15 09:23:25 +000075
76 // Accessors.
Bill Wendling39dd6962009-05-20 23:31:45 +000077 unsigned getID() const { return ID; }
78 DIE* getDie() const { return Die; }
Bill Wendling0310d762009-05-15 09:23:25 +000079 StringMap<DIE*> &getGlobals() { return Globals; }
80
81 /// hasContent - Return true if this compile unit has something to write out.
82 ///
Bill Wendling39dd6962009-05-20 23:31:45 +000083 bool hasContent() const { return !Die->getChildren().empty(); }
Bill Wendling0310d762009-05-15 09:23:25 +000084
85 /// AddGlobal - Add a new global entity to the compile unit.
86 ///
Bill Wendling39dd6962009-05-20 23:31:45 +000087 void AddGlobal(const std::string &Name, DIE *Die) { Globals[Name] = Die; }
Bill Wendling0310d762009-05-15 09:23:25 +000088
89 /// getDieMapSlotFor - Returns the debug information entry map slot for the
90 /// specified debug variable.
Bill Wendling39dd6962009-05-20 23:31:45 +000091 DIE *&getDieMapSlotFor(GlobalVariable *GV) { return GVToDieMap[GV]; }
Bill Wendling0310d762009-05-15 09:23:25 +000092
Chris Lattner1cda87c2009-07-14 04:50:12 +000093 /// getDIEEntrySlotFor - Returns the debug information entry proxy slot for
94 /// the specified debug variable.
Bill Wendling0310d762009-05-15 09:23:25 +000095 DIEEntry *&getDIEEntrySlotFor(GlobalVariable *GV) {
96 return GVToDIEEntryMap[GV];
97 }
98
99 /// AddDie - Adds or interns the DIE to the compile unit.
100 ///
101 DIE *AddDie(DIE &Buffer) {
102 FoldingSetNodeID ID;
103 Buffer.Profile(ID);
104 void *Where;
105 DIE *Die = DiesSet.FindNodeOrInsertPos(ID, Where);
106
107 if (!Die) {
108 Die = new DIE(Buffer);
109 DiesSet.InsertNode(Die, Where);
110 this->Die->AddChild(Die);
111 Buffer.Detach();
112 }
113
114 return Die;
115 }
116};
117
118//===----------------------------------------------------------------------===//
119/// DbgVariable - This class is used to track local variable information.
120///
121class VISIBILITY_HIDDEN DbgVariable {
122 DIVariable Var; // Variable Descriptor.
123 unsigned FrameIndex; // Variable frame index.
Bill Wendling1180c782009-05-18 23:08:55 +0000124 bool InlinedFnVar; // Variable for an inlined function.
Bill Wendling0310d762009-05-15 09:23:25 +0000125public:
Bill Wendling1180c782009-05-18 23:08:55 +0000126 DbgVariable(DIVariable V, unsigned I, bool IFV)
127 : Var(V), FrameIndex(I), InlinedFnVar(IFV) {}
Bill Wendling0310d762009-05-15 09:23:25 +0000128
129 // Accessors.
Bill Wendling1180c782009-05-18 23:08:55 +0000130 DIVariable getVariable() const { return Var; }
Bill Wendling0310d762009-05-15 09:23:25 +0000131 unsigned getFrameIndex() const { return FrameIndex; }
Bill Wendling1180c782009-05-18 23:08:55 +0000132 bool isInlinedFnVar() const { return InlinedFnVar; }
Bill Wendling0310d762009-05-15 09:23:25 +0000133};
134
135//===----------------------------------------------------------------------===//
136/// DbgScope - This class is used to track scope information.
137///
138class DbgConcreteScope;
139class VISIBILITY_HIDDEN DbgScope {
140 DbgScope *Parent; // Parent to this scope.
141 DIDescriptor Desc; // Debug info descriptor for scope.
142 // Either subprogram or block.
143 unsigned StartLabelID; // Label ID of the beginning of scope.
144 unsigned EndLabelID; // Label ID of the end of scope.
145 SmallVector<DbgScope *, 4> Scopes; // Scopes defined in scope.
146 SmallVector<DbgVariable *, 8> Variables;// Variables declared in scope.
147 SmallVector<DbgConcreteScope *, 8> ConcreteInsts;// Concrete insts of funcs.
Owen Anderson04c05f72009-06-24 22:53:20 +0000148
149 // Private state for dump()
150 mutable unsigned IndentLevel;
Bill Wendling0310d762009-05-15 09:23:25 +0000151public:
152 DbgScope(DbgScope *P, DIDescriptor D)
Owen Anderson04c05f72009-06-24 22:53:20 +0000153 : Parent(P), Desc(D), StartLabelID(0), EndLabelID(0), IndentLevel(0) {}
Bill Wendling0310d762009-05-15 09:23:25 +0000154 virtual ~DbgScope();
155
156 // Accessors.
157 DbgScope *getParent() const { return Parent; }
158 DIDescriptor getDesc() const { return Desc; }
159 unsigned getStartLabelID() const { return StartLabelID; }
160 unsigned getEndLabelID() const { return EndLabelID; }
161 SmallVector<DbgScope *, 4> &getScopes() { return Scopes; }
162 SmallVector<DbgVariable *, 8> &getVariables() { return Variables; }
163 SmallVector<DbgConcreteScope*,8> &getConcreteInsts() { return ConcreteInsts; }
164 void setStartLabelID(unsigned S) { StartLabelID = S; }
165 void setEndLabelID(unsigned E) { EndLabelID = E; }
166
167 /// AddScope - Add a scope to the scope.
168 ///
169 void AddScope(DbgScope *S) { Scopes.push_back(S); }
170
171 /// AddVariable - Add a variable to the scope.
172 ///
173 void AddVariable(DbgVariable *V) { Variables.push_back(V); }
174
175 /// AddConcreteInst - Add a concrete instance to the scope.
176 ///
177 void AddConcreteInst(DbgConcreteScope *C) { ConcreteInsts.push_back(C); }
178
179#ifndef NDEBUG
180 void dump() const;
181#endif
182};
183
184#ifndef NDEBUG
185void DbgScope::dump() const {
Bill Wendling0310d762009-05-15 09:23:25 +0000186 std::string Indent(IndentLevel, ' ');
187
188 cerr << Indent; Desc.dump();
189 cerr << " [" << StartLabelID << ", " << EndLabelID << "]\n";
190
191 IndentLevel += 2;
192
193 for (unsigned i = 0, e = Scopes.size(); i != e; ++i)
194 if (Scopes[i] != this)
195 Scopes[i]->dump();
196
197 IndentLevel -= 2;
198}
199#endif
200
201//===----------------------------------------------------------------------===//
202/// DbgConcreteScope - This class is used to track a scope that holds concrete
203/// instance information.
204///
205class VISIBILITY_HIDDEN DbgConcreteScope : public DbgScope {
206 CompileUnit *Unit;
207 DIE *Die; // Debug info for this concrete scope.
208public:
209 DbgConcreteScope(DIDescriptor D) : DbgScope(NULL, D) {}
210
211 // Accessors.
212 DIE *getDie() const { return Die; }
213 void setDie(DIE *D) { Die = D; }
214};
215
216DbgScope::~DbgScope() {
217 for (unsigned i = 0, N = Scopes.size(); i < N; ++i)
218 delete Scopes[i];
219 for (unsigned j = 0, M = Variables.size(); j < M; ++j)
220 delete Variables[j];
221 for (unsigned k = 0, O = ConcreteInsts.size(); k < O; ++k)
222 delete ConcreteInsts[k];
223}
224
225} // end llvm namespace
226
227DwarfDebug::DwarfDebug(raw_ostream &OS, AsmPrinter *A, const TargetAsmInfo *T)
Devang Patel1dbc7712009-06-29 20:45:18 +0000228 : Dwarf(OS, A, T, "dbg"), ModuleCU(0),
Bill Wendling0310d762009-05-15 09:23:25 +0000229 AbbreviationsSet(InitAbbreviationsSetSize), Abbreviations(),
Chris Lattnera87dea42009-07-31 18:48:30 +0000230 ValuesSet(InitValuesSetSize), Values(), StringPool(),
Bill Wendling0310d762009-05-15 09:23:25 +0000231 SectionSourceLines(), didInitial(false), shouldEmit(false),
Devang Patel43da8fb2009-07-13 21:26:33 +0000232 FunctionDbgScope(0), DebugTimer(0) {
Bill Wendling0310d762009-05-15 09:23:25 +0000233 if (TimePassesIsEnabled)
234 DebugTimer = new Timer("Dwarf Debug Writer",
235 getDwarfTimerGroup());
236}
237DwarfDebug::~DwarfDebug() {
238 for (unsigned j = 0, M = Values.size(); j < M; ++j)
239 delete Values[j];
240
241 for (DenseMap<const GlobalVariable *, DbgScope *>::iterator
242 I = AbstractInstanceRootMap.begin(),
243 E = AbstractInstanceRootMap.end(); I != E;++I)
244 delete I->second;
245
246 delete DebugTimer;
247}
248
249/// AssignAbbrevNumber - Define a unique number for the abbreviation.
250///
251void DwarfDebug::AssignAbbrevNumber(DIEAbbrev &Abbrev) {
252 // Profile the node so that we can make it unique.
253 FoldingSetNodeID ID;
254 Abbrev.Profile(ID);
255
256 // Check the set for priors.
257 DIEAbbrev *InSet = AbbreviationsSet.GetOrInsertNode(&Abbrev);
258
259 // If it's newly added.
260 if (InSet == &Abbrev) {
261 // Add to abbreviation list.
262 Abbreviations.push_back(&Abbrev);
263
264 // Assign the vector position + 1 as its number.
265 Abbrev.setNumber(Abbreviations.size());
266 } else {
267 // Assign existing abbreviation number.
268 Abbrev.setNumber(InSet->getNumber());
269 }
270}
271
Bill Wendling995f80a2009-05-20 23:24:48 +0000272/// CreateDIEEntry - Creates a new DIEEntry to be a proxy for a debug
273/// information entry.
274DIEEntry *DwarfDebug::CreateDIEEntry(DIE *Entry) {
Bill Wendling0310d762009-05-15 09:23:25 +0000275 DIEEntry *Value;
276
277 if (Entry) {
278 FoldingSetNodeID ID;
279 DIEEntry::Profile(ID, Entry);
280 void *Where;
281 Value = static_cast<DIEEntry *>(ValuesSet.FindNodeOrInsertPos(ID, Where));
282
283 if (Value) return Value;
284
285 Value = new DIEEntry(Entry);
286 ValuesSet.InsertNode(Value, Where);
287 } else {
288 Value = new DIEEntry(Entry);
289 }
290
291 Values.push_back(Value);
292 return Value;
293}
294
295/// SetDIEEntry - Set a DIEEntry once the debug information entry is defined.
296///
297void DwarfDebug::SetDIEEntry(DIEEntry *Value, DIE *Entry) {
298 Value->setEntry(Entry);
299
300 // Add to values set if not already there. If it is, we merely have a
301 // duplicate in the values list (no harm.)
302 ValuesSet.GetOrInsertNode(Value);
303}
304
305/// AddUInt - Add an unsigned integer attribute data and value.
306///
307void DwarfDebug::AddUInt(DIE *Die, unsigned Attribute,
308 unsigned Form, uint64_t Integer) {
309 if (!Form) Form = DIEInteger::BestForm(false, Integer);
310
311 FoldingSetNodeID ID;
312 DIEInteger::Profile(ID, Integer);
313 void *Where;
314 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
315
316 if (!Value) {
317 Value = new DIEInteger(Integer);
318 ValuesSet.InsertNode(Value, Where);
319 Values.push_back(Value);
320 }
321
322 Die->AddValue(Attribute, Form, Value);
323}
324
325/// AddSInt - Add an signed integer attribute data and value.
326///
327void DwarfDebug::AddSInt(DIE *Die, unsigned Attribute,
328 unsigned Form, int64_t Integer) {
329 if (!Form) Form = DIEInteger::BestForm(true, Integer);
330
331 FoldingSetNodeID ID;
332 DIEInteger::Profile(ID, (uint64_t)Integer);
333 void *Where;
334 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
335
336 if (!Value) {
337 Value = new DIEInteger(Integer);
338 ValuesSet.InsertNode(Value, Where);
339 Values.push_back(Value);
340 }
341
342 Die->AddValue(Attribute, Form, Value);
343}
344
345/// AddString - Add a string attribute data and value.
346///
347void DwarfDebug::AddString(DIE *Die, unsigned Attribute, unsigned Form,
348 const std::string &String) {
349 FoldingSetNodeID ID;
350 DIEString::Profile(ID, String);
351 void *Where;
352 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
353
354 if (!Value) {
355 Value = new DIEString(String);
356 ValuesSet.InsertNode(Value, Where);
357 Values.push_back(Value);
358 }
359
360 Die->AddValue(Attribute, Form, Value);
361}
362
363/// AddLabel - Add a Dwarf label attribute data and value.
364///
365void DwarfDebug::AddLabel(DIE *Die, unsigned Attribute, unsigned Form,
366 const DWLabel &Label) {
367 FoldingSetNodeID ID;
368 DIEDwarfLabel::Profile(ID, Label);
369 void *Where;
370 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
371
372 if (!Value) {
373 Value = new DIEDwarfLabel(Label);
374 ValuesSet.InsertNode(Value, Where);
375 Values.push_back(Value);
376 }
377
378 Die->AddValue(Attribute, Form, Value);
379}
380
381/// AddObjectLabel - Add an non-Dwarf label attribute data and value.
382///
383void DwarfDebug::AddObjectLabel(DIE *Die, unsigned Attribute, unsigned Form,
384 const std::string &Label) {
385 FoldingSetNodeID ID;
386 DIEObjectLabel::Profile(ID, Label);
387 void *Where;
388 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
389
390 if (!Value) {
391 Value = new DIEObjectLabel(Label);
392 ValuesSet.InsertNode(Value, Where);
393 Values.push_back(Value);
394 }
395
396 Die->AddValue(Attribute, Form, Value);
397}
398
399/// AddSectionOffset - Add a section offset label attribute data and value.
400///
401void DwarfDebug::AddSectionOffset(DIE *Die, unsigned Attribute, unsigned Form,
402 const DWLabel &Label, const DWLabel &Section,
403 bool isEH, bool useSet) {
404 FoldingSetNodeID ID;
405 DIESectionOffset::Profile(ID, Label, Section);
406 void *Where;
407 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
408
409 if (!Value) {
410 Value = new DIESectionOffset(Label, Section, isEH, useSet);
411 ValuesSet.InsertNode(Value, Where);
412 Values.push_back(Value);
413 }
414
415 Die->AddValue(Attribute, Form, Value);
416}
417
418/// AddDelta - Add a label delta attribute data and value.
419///
420void DwarfDebug::AddDelta(DIE *Die, unsigned Attribute, unsigned Form,
421 const DWLabel &Hi, const DWLabel &Lo) {
422 FoldingSetNodeID ID;
423 DIEDelta::Profile(ID, Hi, Lo);
424 void *Where;
425 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
426
427 if (!Value) {
428 Value = new DIEDelta(Hi, Lo);
429 ValuesSet.InsertNode(Value, Where);
430 Values.push_back(Value);
431 }
432
433 Die->AddValue(Attribute, Form, Value);
434}
435
436/// AddBlock - Add block data.
437///
438void DwarfDebug::AddBlock(DIE *Die, unsigned Attribute, unsigned Form,
439 DIEBlock *Block) {
440 Block->ComputeSize(TD);
441 FoldingSetNodeID ID;
442 Block->Profile(ID);
443 void *Where;
444 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
445
446 if (!Value) {
447 Value = Block;
448 ValuesSet.InsertNode(Value, Where);
449 Values.push_back(Value);
450 } else {
451 // Already exists, reuse the previous one.
452 delete Block;
453 Block = cast<DIEBlock>(Value);
454 }
455
456 Die->AddValue(Attribute, Block->BestForm(), Value);
457}
458
459/// AddSourceLine - Add location information to specified debug information
460/// entry.
461void DwarfDebug::AddSourceLine(DIE *Die, const DIVariable *V) {
462 // If there is no compile unit specified, don't add a line #.
463 if (V->getCompileUnit().isNull())
464 return;
465
466 unsigned Line = V->getLineNumber();
467 unsigned FileID = FindCompileUnit(V->getCompileUnit()).getID();
468 assert(FileID && "Invalid file id");
469 AddUInt(Die, dwarf::DW_AT_decl_file, 0, FileID);
470 AddUInt(Die, dwarf::DW_AT_decl_line, 0, Line);
471}
472
473/// AddSourceLine - Add location information to specified debug information
474/// entry.
475void DwarfDebug::AddSourceLine(DIE *Die, const DIGlobal *G) {
476 // If there is no compile unit specified, don't add a line #.
477 if (G->getCompileUnit().isNull())
478 return;
479
480 unsigned Line = G->getLineNumber();
481 unsigned FileID = FindCompileUnit(G->getCompileUnit()).getID();
482 assert(FileID && "Invalid file id");
483 AddUInt(Die, dwarf::DW_AT_decl_file, 0, FileID);
484 AddUInt(Die, dwarf::DW_AT_decl_line, 0, Line);
485}
486void DwarfDebug::AddSourceLine(DIE *Die, const DIType *Ty) {
487 // If there is no compile unit specified, don't add a line #.
488 DICompileUnit CU = Ty->getCompileUnit();
489 if (CU.isNull())
490 return;
491
492 unsigned Line = Ty->getLineNumber();
493 unsigned FileID = FindCompileUnit(CU).getID();
494 assert(FileID && "Invalid file id");
495 AddUInt(Die, dwarf::DW_AT_decl_file, 0, FileID);
496 AddUInt(Die, dwarf::DW_AT_decl_line, 0, Line);
497}
498
499/// AddAddress - Add an address attribute to a die based on the location
500/// provided.
501void DwarfDebug::AddAddress(DIE *Die, unsigned Attribute,
502 const MachineLocation &Location) {
503 unsigned Reg = RI->getDwarfRegNum(Location.getReg(), false);
504 DIEBlock *Block = new DIEBlock();
505
506 if (Location.isReg()) {
507 if (Reg < 32) {
508 AddUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_reg0 + Reg);
509 } else {
510 AddUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_regx);
511 AddUInt(Block, 0, dwarf::DW_FORM_udata, Reg);
512 }
513 } else {
514 if (Reg < 32) {
515 AddUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_breg0 + Reg);
516 } else {
517 AddUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_bregx);
518 AddUInt(Block, 0, dwarf::DW_FORM_udata, Reg);
519 }
520
521 AddUInt(Block, 0, dwarf::DW_FORM_sdata, Location.getOffset());
522 }
523
524 AddBlock(Die, Attribute, 0, Block);
525}
526
527/// AddType - Add a new type attribute to the specified entity.
528void DwarfDebug::AddType(CompileUnit *DW_Unit, DIE *Entity, DIType Ty) {
529 if (Ty.isNull())
530 return;
531
532 // Check for pre-existence.
533 DIEEntry *&Slot = DW_Unit->getDIEEntrySlotFor(Ty.getGV());
534
535 // If it exists then use the existing value.
536 if (Slot) {
537 Entity->AddValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, Slot);
538 return;
539 }
540
541 // Set up proxy.
Bill Wendling995f80a2009-05-20 23:24:48 +0000542 Slot = CreateDIEEntry();
Bill Wendling0310d762009-05-15 09:23:25 +0000543
544 // Construct type.
545 DIE Buffer(dwarf::DW_TAG_base_type);
546 if (Ty.isBasicType(Ty.getTag()))
547 ConstructTypeDIE(DW_Unit, Buffer, DIBasicType(Ty.getGV()));
548 else if (Ty.isDerivedType(Ty.getTag()))
549 ConstructTypeDIE(DW_Unit, Buffer, DIDerivedType(Ty.getGV()));
550 else {
551 assert(Ty.isCompositeType(Ty.getTag()) && "Unknown kind of DIType");
552 ConstructTypeDIE(DW_Unit, Buffer, DICompositeType(Ty.getGV()));
553 }
554
555 // Add debug information entry to entity and appropriate context.
556 DIE *Die = NULL;
557 DIDescriptor Context = Ty.getContext();
558 if (!Context.isNull())
559 Die = DW_Unit->getDieMapSlotFor(Context.getGV());
560
561 if (Die) {
562 DIE *Child = new DIE(Buffer);
563 Die->AddChild(Child);
564 Buffer.Detach();
565 SetDIEEntry(Slot, Child);
566 } else {
567 Die = DW_Unit->AddDie(Buffer);
568 SetDIEEntry(Slot, Die);
569 }
570
571 Entity->AddValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, Slot);
572}
573
574/// ConstructTypeDIE - Construct basic type die from DIBasicType.
575void DwarfDebug::ConstructTypeDIE(CompileUnit *DW_Unit, DIE &Buffer,
576 DIBasicType BTy) {
577 // Get core information.
578 std::string Name;
579 BTy.getName(Name);
580 Buffer.setTag(dwarf::DW_TAG_base_type);
581 AddUInt(&Buffer, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1,
582 BTy.getEncoding());
583
584 // Add name if not anonymous or intermediate type.
585 if (!Name.empty())
586 AddString(&Buffer, dwarf::DW_AT_name, dwarf::DW_FORM_string, Name);
587 uint64_t Size = BTy.getSizeInBits() >> 3;
588 AddUInt(&Buffer, dwarf::DW_AT_byte_size, 0, Size);
589}
590
591/// ConstructTypeDIE - Construct derived type die from DIDerivedType.
592void DwarfDebug::ConstructTypeDIE(CompileUnit *DW_Unit, DIE &Buffer,
593 DIDerivedType DTy) {
594 // Get core information.
595 std::string Name;
596 DTy.getName(Name);
597 uint64_t Size = DTy.getSizeInBits() >> 3;
598 unsigned Tag = DTy.getTag();
599
600 // FIXME - Workaround for templates.
601 if (Tag == dwarf::DW_TAG_inheritance) Tag = dwarf::DW_TAG_reference_type;
602
603 Buffer.setTag(Tag);
604
605 // Map to main type, void will not have a type.
606 DIType FromTy = DTy.getTypeDerivedFrom();
607 AddType(DW_Unit, &Buffer, FromTy);
608
609 // Add name if not anonymous or intermediate type.
610 if (!Name.empty())
611 AddString(&Buffer, dwarf::DW_AT_name, dwarf::DW_FORM_string, Name);
612
613 // Add size if non-zero (derived types might be zero-sized.)
614 if (Size)
615 AddUInt(&Buffer, dwarf::DW_AT_byte_size, 0, Size);
616
617 // Add source line info if available and TyDesc is not a forward declaration.
618 if (!DTy.isForwardDecl())
619 AddSourceLine(&Buffer, &DTy);
620}
621
622/// ConstructTypeDIE - Construct type DIE from DICompositeType.
623void DwarfDebug::ConstructTypeDIE(CompileUnit *DW_Unit, DIE &Buffer,
624 DICompositeType CTy) {
625 // Get core information.
626 std::string Name;
627 CTy.getName(Name);
628
629 uint64_t Size = CTy.getSizeInBits() >> 3;
630 unsigned Tag = CTy.getTag();
631 Buffer.setTag(Tag);
632
633 switch (Tag) {
634 case dwarf::DW_TAG_vector_type:
635 case dwarf::DW_TAG_array_type:
636 ConstructArrayTypeDIE(DW_Unit, Buffer, &CTy);
637 break;
638 case dwarf::DW_TAG_enumeration_type: {
639 DIArray Elements = CTy.getTypeArray();
640
641 // Add enumerators to enumeration type.
642 for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
643 DIE *ElemDie = NULL;
644 DIEnumerator Enum(Elements.getElement(i).getGV());
645 ElemDie = ConstructEnumTypeDIE(DW_Unit, &Enum);
646 Buffer.AddChild(ElemDie);
647 }
648 }
649 break;
650 case dwarf::DW_TAG_subroutine_type: {
651 // Add return type.
652 DIArray Elements = CTy.getTypeArray();
653 DIDescriptor RTy = Elements.getElement(0);
654 AddType(DW_Unit, &Buffer, DIType(RTy.getGV()));
655
656 // Add prototype flag.
657 AddUInt(&Buffer, dwarf::DW_AT_prototyped, dwarf::DW_FORM_flag, 1);
658
659 // Add arguments.
660 for (unsigned i = 1, N = Elements.getNumElements(); i < N; ++i) {
661 DIE *Arg = new DIE(dwarf::DW_TAG_formal_parameter);
662 DIDescriptor Ty = Elements.getElement(i);
663 AddType(DW_Unit, Arg, DIType(Ty.getGV()));
664 Buffer.AddChild(Arg);
665 }
666 }
667 break;
668 case dwarf::DW_TAG_structure_type:
669 case dwarf::DW_TAG_union_type:
670 case dwarf::DW_TAG_class_type: {
671 // Add elements to structure type.
672 DIArray Elements = CTy.getTypeArray();
673
674 // A forward struct declared type may not have elements available.
675 if (Elements.isNull())
676 break;
677
678 // Add elements to structure type.
679 for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
680 DIDescriptor Element = Elements.getElement(i);
681 DIE *ElemDie = NULL;
682 if (Element.getTag() == dwarf::DW_TAG_subprogram)
683 ElemDie = CreateSubprogramDIE(DW_Unit,
684 DISubprogram(Element.getGV()));
Bill Wendling0310d762009-05-15 09:23:25 +0000685 else
686 ElemDie = CreateMemberDIE(DW_Unit,
687 DIDerivedType(Element.getGV()));
688 Buffer.AddChild(ElemDie);
689 }
690
691 // FIXME: We'd like an API to register additional attributes for the
692 // frontend to use while synthesizing, and then we'd use that api in clang
693 // instead of this.
694 if (Name == "__block_literal_generic")
695 AddUInt(&Buffer, dwarf::DW_AT_APPLE_block, dwarf::DW_FORM_flag, 1);
696
697 unsigned RLang = CTy.getRunTimeLang();
698 if (RLang)
699 AddUInt(&Buffer, dwarf::DW_AT_APPLE_runtime_class,
700 dwarf::DW_FORM_data1, RLang);
701 break;
702 }
703 default:
704 break;
705 }
706
707 // Add name if not anonymous or intermediate type.
708 if (!Name.empty())
709 AddString(&Buffer, dwarf::DW_AT_name, dwarf::DW_FORM_string, Name);
710
711 if (Tag == dwarf::DW_TAG_enumeration_type ||
712 Tag == dwarf::DW_TAG_structure_type || Tag == dwarf::DW_TAG_union_type) {
713 // Add size if non-zero (derived types might be zero-sized.)
714 if (Size)
715 AddUInt(&Buffer, dwarf::DW_AT_byte_size, 0, Size);
716 else {
717 // Add zero size if it is not a forward declaration.
718 if (CTy.isForwardDecl())
719 AddUInt(&Buffer, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag, 1);
720 else
721 AddUInt(&Buffer, dwarf::DW_AT_byte_size, 0, 0);
722 }
723
724 // Add source line info if available.
725 if (!CTy.isForwardDecl())
726 AddSourceLine(&Buffer, &CTy);
727 }
728}
729
730/// ConstructSubrangeDIE - Construct subrange DIE from DISubrange.
731void DwarfDebug::ConstructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy){
732 int64_t L = SR.getLo();
733 int64_t H = SR.getHi();
734 DIE *DW_Subrange = new DIE(dwarf::DW_TAG_subrange_type);
735
Devang Patel6325a532009-08-14 20:59:16 +0000736 AddDIEEntry(DW_Subrange, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, IndexTy);
737 if (L)
738 AddSInt(DW_Subrange, dwarf::DW_AT_lower_bound, 0, L);
739 if (H)
740 AddSInt(DW_Subrange, dwarf::DW_AT_upper_bound, 0, H);
Bill Wendling0310d762009-05-15 09:23:25 +0000741
742 Buffer.AddChild(DW_Subrange);
743}
744
745/// ConstructArrayTypeDIE - Construct array type DIE from DICompositeType.
746void DwarfDebug::ConstructArrayTypeDIE(CompileUnit *DW_Unit, DIE &Buffer,
747 DICompositeType *CTy) {
748 Buffer.setTag(dwarf::DW_TAG_array_type);
749 if (CTy->getTag() == dwarf::DW_TAG_vector_type)
750 AddUInt(&Buffer, dwarf::DW_AT_GNU_vector, dwarf::DW_FORM_flag, 1);
751
752 // Emit derived type.
753 AddType(DW_Unit, &Buffer, CTy->getTypeDerivedFrom());
754 DIArray Elements = CTy->getTypeArray();
755
756 // Construct an anonymous type for index type.
757 DIE IdxBuffer(dwarf::DW_TAG_base_type);
758 AddUInt(&IdxBuffer, dwarf::DW_AT_byte_size, 0, sizeof(int32_t));
759 AddUInt(&IdxBuffer, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1,
760 dwarf::DW_ATE_signed);
761 DIE *IndexTy = DW_Unit->AddDie(IdxBuffer);
762
763 // Add subranges to array type.
764 for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
765 DIDescriptor Element = Elements.getElement(i);
766 if (Element.getTag() == dwarf::DW_TAG_subrange_type)
767 ConstructSubrangeDIE(Buffer, DISubrange(Element.getGV()), IndexTy);
768 }
769}
770
771/// ConstructEnumTypeDIE - Construct enum type DIE from DIEnumerator.
772DIE *DwarfDebug::ConstructEnumTypeDIE(CompileUnit *DW_Unit, DIEnumerator *ETy) {
773 DIE *Enumerator = new DIE(dwarf::DW_TAG_enumerator);
774 std::string Name;
775 ETy->getName(Name);
776 AddString(Enumerator, dwarf::DW_AT_name, dwarf::DW_FORM_string, Name);
777 int64_t Value = ETy->getEnumValue();
778 AddSInt(Enumerator, dwarf::DW_AT_const_value, dwarf::DW_FORM_sdata, Value);
779 return Enumerator;
780}
781
782/// CreateGlobalVariableDIE - Create new DIE using GV.
783DIE *DwarfDebug::CreateGlobalVariableDIE(CompileUnit *DW_Unit,
784 const DIGlobalVariable &GV) {
785 DIE *GVDie = new DIE(dwarf::DW_TAG_variable);
786 std::string Name;
787 GV.getDisplayName(Name);
788 AddString(GVDie, dwarf::DW_AT_name, dwarf::DW_FORM_string, Name);
789 std::string LinkageName;
790 GV.getLinkageName(LinkageName);
Devang Patel53cb17d2009-07-16 01:01:22 +0000791 if (!LinkageName.empty()) {
Chris Lattner6c2f9e12009-08-19 05:49:37 +0000792 // Skip special LLVM prefix that is used to inform the asm printer to not
793 // emit usual symbol prefix before the symbol name. This happens for
794 // Objective-C symbol names and symbol whose name is replaced using GCC's
795 // __asm__ attribute.
Devang Patel53cb17d2009-07-16 01:01:22 +0000796 if (LinkageName[0] == 1)
797 LinkageName = &LinkageName[1];
Bill Wendling0310d762009-05-15 09:23:25 +0000798 AddString(GVDie, dwarf::DW_AT_MIPS_linkage_name, dwarf::DW_FORM_string,
Devang Patel1a8d2d22009-07-14 00:55:28 +0000799 LinkageName);
Devang Patel53cb17d2009-07-16 01:01:22 +0000800 }
801 AddType(DW_Unit, GVDie, GV.getType());
Bill Wendling0310d762009-05-15 09:23:25 +0000802 if (!GV.isLocalToUnit())
803 AddUInt(GVDie, dwarf::DW_AT_external, dwarf::DW_FORM_flag, 1);
804 AddSourceLine(GVDie, &GV);
805 return GVDie;
806}
807
808/// CreateMemberDIE - Create new member DIE.
809DIE *DwarfDebug::CreateMemberDIE(CompileUnit *DW_Unit, const DIDerivedType &DT){
810 DIE *MemberDie = new DIE(DT.getTag());
811 std::string Name;
812 DT.getName(Name);
813 if (!Name.empty())
814 AddString(MemberDie, dwarf::DW_AT_name, dwarf::DW_FORM_string, Name);
815
816 AddType(DW_Unit, MemberDie, DT.getTypeDerivedFrom());
817
818 AddSourceLine(MemberDie, &DT);
819
820 uint64_t Size = DT.getSizeInBits();
821 uint64_t FieldSize = DT.getOriginalTypeSize();
822
823 if (Size != FieldSize) {
824 // Handle bitfield.
825 AddUInt(MemberDie, dwarf::DW_AT_byte_size, 0, DT.getOriginalTypeSize()>>3);
826 AddUInt(MemberDie, dwarf::DW_AT_bit_size, 0, DT.getSizeInBits());
827
828 uint64_t Offset = DT.getOffsetInBits();
829 uint64_t FieldOffset = Offset;
830 uint64_t AlignMask = ~(DT.getAlignInBits() - 1);
831 uint64_t HiMark = (Offset + FieldSize) & AlignMask;
832 FieldOffset = (HiMark - FieldSize);
833 Offset -= FieldOffset;
834
835 // Maybe we need to work from the other end.
836 if (TD->isLittleEndian()) Offset = FieldSize - (Offset + Size);
837 AddUInt(MemberDie, dwarf::DW_AT_bit_offset, 0, Offset);
838 }
839
840 DIEBlock *Block = new DIEBlock();
841 AddUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst);
842 AddUInt(Block, 0, dwarf::DW_FORM_udata, DT.getOffsetInBits() >> 3);
843 AddBlock(MemberDie, dwarf::DW_AT_data_member_location, 0, Block);
844
845 if (DT.isProtected())
846 AddUInt(MemberDie, dwarf::DW_AT_accessibility, 0,
847 dwarf::DW_ACCESS_protected);
848 else if (DT.isPrivate())
849 AddUInt(MemberDie, dwarf::DW_AT_accessibility, 0,
850 dwarf::DW_ACCESS_private);
851
852 return MemberDie;
853}
854
855/// CreateSubprogramDIE - Create new DIE using SP.
856DIE *DwarfDebug::CreateSubprogramDIE(CompileUnit *DW_Unit,
857 const DISubprogram &SP,
Bill Wendling6679ee42009-05-18 22:02:36 +0000858 bool IsConstructor,
859 bool IsInlined) {
Bill Wendling0310d762009-05-15 09:23:25 +0000860 DIE *SPDie = new DIE(dwarf::DW_TAG_subprogram);
861
862 std::string Name;
863 SP.getName(Name);
864 AddString(SPDie, dwarf::DW_AT_name, dwarf::DW_FORM_string, Name);
865
866 std::string LinkageName;
867 SP.getLinkageName(LinkageName);
Devang Patel53cb17d2009-07-16 01:01:22 +0000868 if (!LinkageName.empty()) {
869 // Skip special LLVM prefix that is used to inform the asm printer to not emit
870 // usual symbol prefix before the symbol name. This happens for Objective-C
871 // symbol names and symbol whose name is replaced using GCC's __asm__ attribute.
872 if (LinkageName[0] == 1)
873 LinkageName = &LinkageName[1];
Bill Wendling0310d762009-05-15 09:23:25 +0000874 AddString(SPDie, dwarf::DW_AT_MIPS_linkage_name, dwarf::DW_FORM_string,
Devang Patel1a8d2d22009-07-14 00:55:28 +0000875 LinkageName);
Devang Patel53cb17d2009-07-16 01:01:22 +0000876 }
Bill Wendling0310d762009-05-15 09:23:25 +0000877 AddSourceLine(SPDie, &SP);
878
879 DICompositeType SPTy = SP.getType();
880 DIArray Args = SPTy.getTypeArray();
881
882 // Add prototyped tag, if C or ObjC.
883 unsigned Lang = SP.getCompileUnit().getLanguage();
884 if (Lang == dwarf::DW_LANG_C99 || Lang == dwarf::DW_LANG_C89 ||
885 Lang == dwarf::DW_LANG_ObjC)
886 AddUInt(SPDie, dwarf::DW_AT_prototyped, dwarf::DW_FORM_flag, 1);
887
888 // Add Return Type.
889 unsigned SPTag = SPTy.getTag();
890 if (!IsConstructor) {
891 if (Args.isNull() || SPTag != dwarf::DW_TAG_subroutine_type)
892 AddType(DW_Unit, SPDie, SPTy);
893 else
894 AddType(DW_Unit, SPDie, DIType(Args.getElement(0).getGV()));
895 }
896
897 if (!SP.isDefinition()) {
898 AddUInt(SPDie, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag, 1);
899
900 // Add arguments. Do not add arguments for subprogram definition. They will
901 // be handled through RecordVariable.
902 if (SPTag == dwarf::DW_TAG_subroutine_type)
903 for (unsigned i = 1, N = Args.getNumElements(); i < N; ++i) {
904 DIE *Arg = new DIE(dwarf::DW_TAG_formal_parameter);
905 AddType(DW_Unit, Arg, DIType(Args.getElement(i).getGV()));
906 AddUInt(Arg, dwarf::DW_AT_artificial, dwarf::DW_FORM_flag, 1); // ??
907 SPDie->AddChild(Arg);
908 }
909 }
910
Bill Wendling6679ee42009-05-18 22:02:36 +0000911 if (!SP.isLocalToUnit() && !IsInlined)
Bill Wendling0310d762009-05-15 09:23:25 +0000912 AddUInt(SPDie, dwarf::DW_AT_external, dwarf::DW_FORM_flag, 1);
913
914 // DW_TAG_inlined_subroutine may refer to this DIE.
915 DIE *&Slot = DW_Unit->getDieMapSlotFor(SP.getGV());
916 Slot = SPDie;
917 return SPDie;
918}
919
920/// FindCompileUnit - Get the compile unit for the given descriptor.
921///
922CompileUnit &DwarfDebug::FindCompileUnit(DICompileUnit Unit) const {
923 DenseMap<Value *, CompileUnit *>::const_iterator I =
924 CompileUnitMap.find(Unit.getGV());
925 assert(I != CompileUnitMap.end() && "Missing compile unit.");
926 return *I->second;
927}
928
Bill Wendling995f80a2009-05-20 23:24:48 +0000929/// CreateDbgScopeVariable - Create a new scope variable.
Bill Wendling0310d762009-05-15 09:23:25 +0000930///
Bill Wendling995f80a2009-05-20 23:24:48 +0000931DIE *DwarfDebug::CreateDbgScopeVariable(DbgVariable *DV, CompileUnit *Unit) {
Bill Wendling0310d762009-05-15 09:23:25 +0000932 // Get the descriptor.
933 const DIVariable &VD = DV->getVariable();
934
935 // Translate tag to proper Dwarf tag. The result variable is dropped for
936 // now.
937 unsigned Tag;
938 switch (VD.getTag()) {
939 case dwarf::DW_TAG_return_variable:
940 return NULL;
941 case dwarf::DW_TAG_arg_variable:
942 Tag = dwarf::DW_TAG_formal_parameter;
943 break;
944 case dwarf::DW_TAG_auto_variable: // fall thru
945 default:
946 Tag = dwarf::DW_TAG_variable;
947 break;
948 }
949
950 // Define variable debug information entry.
951 DIE *VariableDie = new DIE(Tag);
952 std::string Name;
953 VD.getName(Name);
954 AddString(VariableDie, dwarf::DW_AT_name, dwarf::DW_FORM_string, Name);
955
956 // Add source line info if available.
957 AddSourceLine(VariableDie, &VD);
958
959 // Add variable type.
960 AddType(Unit, VariableDie, VD.getType());
961
962 // Add variable address.
Bill Wendling1180c782009-05-18 23:08:55 +0000963 if (!DV->isInlinedFnVar()) {
964 // Variables for abstract instances of inlined functions don't get a
965 // location.
966 MachineLocation Location;
967 Location.set(RI->getFrameRegister(*MF),
968 RI->getFrameIndexOffset(*MF, DV->getFrameIndex()));
969 AddAddress(VariableDie, dwarf::DW_AT_location, Location);
970 }
Bill Wendling0310d762009-05-15 09:23:25 +0000971
972 return VariableDie;
973}
974
975/// getOrCreateScope - Returns the scope associated with the given descriptor.
976///
977DbgScope *DwarfDebug::getOrCreateScope(GlobalVariable *V) {
978 DbgScope *&Slot = DbgScopeMap[V];
979 if (Slot) return Slot;
980
981 DbgScope *Parent = NULL;
982 DIBlock Block(V);
983
Bill Wendling8fff19b2009-06-01 20:18:46 +0000984 // Don't create a new scope if we already created one for an inlined function.
985 DenseMap<const GlobalVariable *, DbgScope *>::iterator
986 II = AbstractInstanceRootMap.find(V);
987 if (II != AbstractInstanceRootMap.end())
988 return LexicalScopeStack.back();
989
Bill Wendling0310d762009-05-15 09:23:25 +0000990 if (!Block.isNull()) {
991 DIDescriptor ParentDesc = Block.getContext();
992 Parent =
993 ParentDesc.isNull() ? NULL : getOrCreateScope(ParentDesc.getGV());
994 }
995
996 Slot = new DbgScope(Parent, DIDescriptor(V));
997
998 if (Parent)
999 Parent->AddScope(Slot);
1000 else
1001 // First function is top level function.
1002 FunctionDbgScope = Slot;
1003
1004 return Slot;
1005}
1006
1007/// ConstructDbgScope - Construct the components of a scope.
1008///
1009void DwarfDebug::ConstructDbgScope(DbgScope *ParentScope,
1010 unsigned ParentStartID,
1011 unsigned ParentEndID,
1012 DIE *ParentDie, CompileUnit *Unit) {
1013 // Add variables to scope.
1014 SmallVector<DbgVariable *, 8> &Variables = ParentScope->getVariables();
1015 for (unsigned i = 0, N = Variables.size(); i < N; ++i) {
Bill Wendling995f80a2009-05-20 23:24:48 +00001016 DIE *VariableDie = CreateDbgScopeVariable(Variables[i], Unit);
Bill Wendling0310d762009-05-15 09:23:25 +00001017 if (VariableDie) ParentDie->AddChild(VariableDie);
1018 }
1019
1020 // Add concrete instances to scope.
1021 SmallVector<DbgConcreteScope *, 8> &ConcreteInsts =
1022 ParentScope->getConcreteInsts();
1023 for (unsigned i = 0, N = ConcreteInsts.size(); i < N; ++i) {
1024 DbgConcreteScope *ConcreteInst = ConcreteInsts[i];
1025 DIE *Die = ConcreteInst->getDie();
1026
1027 unsigned StartID = ConcreteInst->getStartLabelID();
1028 unsigned EndID = ConcreteInst->getEndLabelID();
1029
1030 // Add the scope bounds.
1031 if (StartID)
1032 AddLabel(Die, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr,
1033 DWLabel("label", StartID));
1034 else
1035 AddLabel(Die, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr,
1036 DWLabel("func_begin", SubprogramCount));
1037
1038 if (EndID)
1039 AddLabel(Die, dwarf::DW_AT_high_pc, dwarf::DW_FORM_addr,
1040 DWLabel("label", EndID));
1041 else
1042 AddLabel(Die, dwarf::DW_AT_high_pc, dwarf::DW_FORM_addr,
1043 DWLabel("func_end", SubprogramCount));
1044
1045 ParentDie->AddChild(Die);
1046 }
1047
1048 // Add nested scopes.
1049 SmallVector<DbgScope *, 4> &Scopes = ParentScope->getScopes();
1050 for (unsigned j = 0, M = Scopes.size(); j < M; ++j) {
1051 // Define the Scope debug information entry.
1052 DbgScope *Scope = Scopes[j];
1053
1054 unsigned StartID = MMI->MappedLabel(Scope->getStartLabelID());
1055 unsigned EndID = MMI->MappedLabel(Scope->getEndLabelID());
1056
1057 // Ignore empty scopes.
1058 if (StartID == EndID && StartID != 0) continue;
1059
1060 // Do not ignore inlined scopes even if they don't have any variables or
1061 // scopes.
1062 if (Scope->getScopes().empty() && Scope->getVariables().empty() &&
1063 Scope->getConcreteInsts().empty())
1064 continue;
1065
1066 if (StartID == ParentStartID && EndID == ParentEndID) {
1067 // Just add stuff to the parent scope.
1068 ConstructDbgScope(Scope, ParentStartID, ParentEndID, ParentDie, Unit);
1069 } else {
1070 DIE *ScopeDie = new DIE(dwarf::DW_TAG_lexical_block);
1071
1072 // Add the scope bounds.
1073 if (StartID)
1074 AddLabel(ScopeDie, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr,
1075 DWLabel("label", StartID));
1076 else
1077 AddLabel(ScopeDie, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr,
1078 DWLabel("func_begin", SubprogramCount));
1079
1080 if (EndID)
1081 AddLabel(ScopeDie, dwarf::DW_AT_high_pc, dwarf::DW_FORM_addr,
1082 DWLabel("label", EndID));
1083 else
1084 AddLabel(ScopeDie, dwarf::DW_AT_high_pc, dwarf::DW_FORM_addr,
1085 DWLabel("func_end", SubprogramCount));
1086
1087 // Add the scope's contents.
1088 ConstructDbgScope(Scope, StartID, EndID, ScopeDie, Unit);
1089 ParentDie->AddChild(ScopeDie);
1090 }
1091 }
1092}
1093
1094/// ConstructFunctionDbgScope - Construct the scope for the subprogram.
1095///
Bill Wendling17956162009-05-20 23:28:48 +00001096void DwarfDebug::ConstructFunctionDbgScope(DbgScope *RootScope,
1097 bool AbstractScope) {
Bill Wendling0310d762009-05-15 09:23:25 +00001098 // Exit if there is no root scope.
1099 if (!RootScope) return;
1100 DIDescriptor Desc = RootScope->getDesc();
1101 if (Desc.isNull())
1102 return;
1103
1104 // Get the subprogram debug information entry.
1105 DISubprogram SPD(Desc.getGV());
1106
Bill Wendling0310d762009-05-15 09:23:25 +00001107 // Get the subprogram die.
Devang Patel1dbc7712009-06-29 20:45:18 +00001108 DIE *SPDie = ModuleCU->getDieMapSlotFor(SPD.getGV());
Bill Wendling0310d762009-05-15 09:23:25 +00001109 assert(SPDie && "Missing subprogram descriptor");
1110
Bill Wendling17956162009-05-20 23:28:48 +00001111 if (!AbstractScope) {
1112 // Add the function bounds.
1113 AddLabel(SPDie, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr,
1114 DWLabel("func_begin", SubprogramCount));
1115 AddLabel(SPDie, dwarf::DW_AT_high_pc, dwarf::DW_FORM_addr,
1116 DWLabel("func_end", SubprogramCount));
1117 MachineLocation Location(RI->getFrameRegister(*MF));
1118 AddAddress(SPDie, dwarf::DW_AT_frame_base, Location);
1119 }
Bill Wendling0310d762009-05-15 09:23:25 +00001120
Devang Patel1dbc7712009-06-29 20:45:18 +00001121 ConstructDbgScope(RootScope, 0, 0, SPDie, ModuleCU);
Bill Wendling0310d762009-05-15 09:23:25 +00001122}
1123
Bill Wendling0310d762009-05-15 09:23:25 +00001124/// ConstructDefaultDbgScope - Construct a default scope for the subprogram.
1125///
1126void DwarfDebug::ConstructDefaultDbgScope(MachineFunction *MF) {
Devang Patel1dbc7712009-06-29 20:45:18 +00001127 StringMap<DIE*> &Globals = ModuleCU->getGlobals();
Daniel Dunbar460f6562009-07-26 09:48:23 +00001128 StringMap<DIE*>::iterator GI = Globals.find(MF->getFunction()->getName());
Devang Patel70f44262009-06-29 20:38:13 +00001129 if (GI != Globals.end()) {
1130 DIE *SPDie = GI->second;
1131
1132 // Add the function bounds.
1133 AddLabel(SPDie, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr,
1134 DWLabel("func_begin", SubprogramCount));
1135 AddLabel(SPDie, dwarf::DW_AT_high_pc, dwarf::DW_FORM_addr,
1136 DWLabel("func_end", SubprogramCount));
1137
1138 MachineLocation Location(RI->getFrameRegister(*MF));
1139 AddAddress(SPDie, dwarf::DW_AT_frame_base, Location);
Bill Wendling0310d762009-05-15 09:23:25 +00001140 }
Bill Wendling0310d762009-05-15 09:23:25 +00001141}
1142
Bill Wendlingf0fb9872009-05-20 23:19:06 +00001143/// GetOrCreateSourceID - Look up the source id with the given directory and
1144/// source file names. If none currently exists, create a new id and insert it
1145/// in the SourceIds map. This can update DirectoryNames and SourceFileNames
1146/// maps as well.
1147unsigned DwarfDebug::GetOrCreateSourceID(const std::string &DirName,
1148 const std::string &FileName) {
1149 unsigned DId;
1150 StringMap<unsigned>::iterator DI = DirectoryIdMap.find(DirName);
1151 if (DI != DirectoryIdMap.end()) {
1152 DId = DI->getValue();
1153 } else {
1154 DId = DirectoryNames.size() + 1;
1155 DirectoryIdMap[DirName] = DId;
1156 DirectoryNames.push_back(DirName);
1157 }
1158
1159 unsigned FId;
1160 StringMap<unsigned>::iterator FI = SourceFileIdMap.find(FileName);
1161 if (FI != SourceFileIdMap.end()) {
1162 FId = FI->getValue();
1163 } else {
1164 FId = SourceFileNames.size() + 1;
1165 SourceFileIdMap[FileName] = FId;
1166 SourceFileNames.push_back(FileName);
1167 }
1168
1169 DenseMap<std::pair<unsigned, unsigned>, unsigned>::iterator SI =
1170 SourceIdMap.find(std::make_pair(DId, FId));
1171 if (SI != SourceIdMap.end())
1172 return SI->second;
1173
1174 unsigned SrcId = SourceIds.size() + 1; // DW_AT_decl_file cannot be 0.
1175 SourceIdMap[std::make_pair(DId, FId)] = SrcId;
1176 SourceIds.push_back(std::make_pair(DId, FId));
1177
1178 return SrcId;
1179}
1180
1181void DwarfDebug::ConstructCompileUnit(GlobalVariable *GV) {
1182 DICompileUnit DIUnit(GV);
1183 std::string Dir, FN, Prod;
1184 unsigned ID = GetOrCreateSourceID(DIUnit.getDirectory(Dir),
1185 DIUnit.getFilename(FN));
1186
1187 DIE *Die = new DIE(dwarf::DW_TAG_compile_unit);
1188 AddSectionOffset(Die, dwarf::DW_AT_stmt_list, dwarf::DW_FORM_data4,
1189 DWLabel("section_line", 0), DWLabel("section_line", 0),
1190 false);
1191 AddString(Die, dwarf::DW_AT_producer, dwarf::DW_FORM_string,
1192 DIUnit.getProducer(Prod));
1193 AddUInt(Die, dwarf::DW_AT_language, dwarf::DW_FORM_data1,
1194 DIUnit.getLanguage());
1195 AddString(Die, dwarf::DW_AT_name, dwarf::DW_FORM_string, FN);
1196
1197 if (!Dir.empty())
1198 AddString(Die, dwarf::DW_AT_comp_dir, dwarf::DW_FORM_string, Dir);
1199 if (DIUnit.isOptimized())
1200 AddUInt(Die, dwarf::DW_AT_APPLE_optimized, dwarf::DW_FORM_flag, 1);
1201
1202 std::string Flags;
1203 DIUnit.getFlags(Flags);
1204 if (!Flags.empty())
1205 AddString(Die, dwarf::DW_AT_APPLE_flags, dwarf::DW_FORM_string, Flags);
1206
1207 unsigned RVer = DIUnit.getRunTimeVersion();
1208 if (RVer)
1209 AddUInt(Die, dwarf::DW_AT_APPLE_major_runtime_vers,
1210 dwarf::DW_FORM_data1, RVer);
1211
1212 CompileUnit *Unit = new CompileUnit(ID, Die);
Devang Patel1dbc7712009-06-29 20:45:18 +00001213 if (!ModuleCU && DIUnit.isMain()) {
Devang Patel70f44262009-06-29 20:38:13 +00001214 // Use first compile unit marked as isMain as the compile unit
1215 // for this module.
Devang Patel1dbc7712009-06-29 20:45:18 +00001216 ModuleCU = Unit;
Devang Patel70f44262009-06-29 20:38:13 +00001217 }
Bill Wendlingf0fb9872009-05-20 23:19:06 +00001218
1219 CompileUnitMap[DIUnit.getGV()] = Unit;
1220 CompileUnits.push_back(Unit);
1221}
1222
Devang Patel13e16b62009-06-26 01:49:18 +00001223void DwarfDebug::ConstructGlobalVariableDIE(GlobalVariable *GV) {
Bill Wendlingf0fb9872009-05-20 23:19:06 +00001224 DIGlobalVariable DI_GV(GV);
Bill Wendlingf0fb9872009-05-20 23:19:06 +00001225
1226 // Check for pre-existence.
Devang Patel1dbc7712009-06-29 20:45:18 +00001227 DIE *&Slot = ModuleCU->getDieMapSlotFor(DI_GV.getGV());
Bill Wendlingf0fb9872009-05-20 23:19:06 +00001228 if (Slot)
Devang Patel13e16b62009-06-26 01:49:18 +00001229 return;
Bill Wendlingf0fb9872009-05-20 23:19:06 +00001230
Devang Patel1dbc7712009-06-29 20:45:18 +00001231 DIE *VariableDie = CreateGlobalVariableDIE(ModuleCU, DI_GV);
Bill Wendlingf0fb9872009-05-20 23:19:06 +00001232
1233 // Add address.
1234 DIEBlock *Block = new DIEBlock();
1235 AddUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_addr);
1236 std::string GLN;
1237 AddObjectLabel(Block, 0, dwarf::DW_FORM_udata,
1238 Asm->getGlobalLinkName(DI_GV.getGlobal(), GLN));
1239 AddBlock(VariableDie, dwarf::DW_AT_location, 0, Block);
1240
1241 // Add to map.
1242 Slot = VariableDie;
1243
1244 // Add to context owner.
Devang Patel1dbc7712009-06-29 20:45:18 +00001245 ModuleCU->getDie()->AddChild(VariableDie);
Bill Wendlingf0fb9872009-05-20 23:19:06 +00001246
1247 // Expose as global. FIXME - need to check external flag.
1248 std::string Name;
Devang Patel1dbc7712009-06-29 20:45:18 +00001249 ModuleCU->AddGlobal(DI_GV.getName(Name), VariableDie);
Devang Patel13e16b62009-06-26 01:49:18 +00001250 return;
Bill Wendlingf0fb9872009-05-20 23:19:06 +00001251}
1252
Devang Patel13e16b62009-06-26 01:49:18 +00001253void DwarfDebug::ConstructSubprogram(GlobalVariable *GV) {
Bill Wendlingf0fb9872009-05-20 23:19:06 +00001254 DISubprogram SP(GV);
Bill Wendlingf0fb9872009-05-20 23:19:06 +00001255
1256 // Check for pre-existence.
Devang Patel1dbc7712009-06-29 20:45:18 +00001257 DIE *&Slot = ModuleCU->getDieMapSlotFor(GV);
Bill Wendlingf0fb9872009-05-20 23:19:06 +00001258 if (Slot)
Devang Patel13e16b62009-06-26 01:49:18 +00001259 return;
Bill Wendlingf0fb9872009-05-20 23:19:06 +00001260
1261 if (!SP.isDefinition())
1262 // This is a method declaration which will be handled while constructing
1263 // class type.
Devang Patel13e16b62009-06-26 01:49:18 +00001264 return;
Bill Wendlingf0fb9872009-05-20 23:19:06 +00001265
Devang Patel1dbc7712009-06-29 20:45:18 +00001266 DIE *SubprogramDie = CreateSubprogramDIE(ModuleCU, SP);
Bill Wendlingf0fb9872009-05-20 23:19:06 +00001267
1268 // Add to map.
1269 Slot = SubprogramDie;
1270
1271 // Add to context owner.
Devang Patel1dbc7712009-06-29 20:45:18 +00001272 ModuleCU->getDie()->AddChild(SubprogramDie);
Bill Wendlingf0fb9872009-05-20 23:19:06 +00001273
1274 // Expose as global.
1275 std::string Name;
Devang Patel1dbc7712009-06-29 20:45:18 +00001276 ModuleCU->AddGlobal(SP.getName(Name), SubprogramDie);
Devang Patel13e16b62009-06-26 01:49:18 +00001277 return;
Bill Wendlingf0fb9872009-05-20 23:19:06 +00001278}
1279
Devang Patel208622d2009-06-25 22:36:02 +00001280 /// BeginModule - Emit all Dwarf sections that should come prior to the
1281 /// content. Create global DIEs and emit initial debug info sections.
1282 /// This is inovked by the target AsmPrinter.
1283void DwarfDebug::BeginModule(Module *M, MachineModuleInfo *mmi) {
1284 this->M = M;
1285
Bill Wendlingf0fb9872009-05-20 23:19:06 +00001286 if (TimePassesIsEnabled)
1287 DebugTimer->startTimer();
1288
Devang Patel78ab9e22009-07-30 18:56:46 +00001289 DebugInfoFinder DbgFinder;
1290 DbgFinder.processModule(*M);
Devang Patel13e16b62009-06-26 01:49:18 +00001291
Bill Wendlingf0fb9872009-05-20 23:19:06 +00001292 // Create all the compile unit DIEs.
Devang Patel78ab9e22009-07-30 18:56:46 +00001293 for (DebugInfoFinder::iterator I = DbgFinder.compile_unit_begin(),
1294 E = DbgFinder.compile_unit_end(); I != E; ++I)
Devang Patel13e16b62009-06-26 01:49:18 +00001295 ConstructCompileUnit(*I);
Bill Wendlingf0fb9872009-05-20 23:19:06 +00001296
1297 if (CompileUnits.empty()) {
1298 if (TimePassesIsEnabled)
1299 DebugTimer->stopTimer();
1300
1301 return;
1302 }
1303
Devang Patel70f44262009-06-29 20:38:13 +00001304 // If main compile unit for this module is not seen than randomly
1305 // select first compile unit.
Devang Patel1dbc7712009-06-29 20:45:18 +00001306 if (!ModuleCU)
1307 ModuleCU = CompileUnits[0];
Devang Patel70f44262009-06-29 20:38:13 +00001308
Bill Wendlingf0fb9872009-05-20 23:19:06 +00001309 // If there is not any debug info available for any global variables and any
1310 // subprograms then there is not any debug info to emit.
Devang Patel78ab9e22009-07-30 18:56:46 +00001311 if (DbgFinder.global_variable_count() == 0
1312 && DbgFinder.subprogram_count() == 0) {
Bill Wendlingf0fb9872009-05-20 23:19:06 +00001313 if (TimePassesIsEnabled)
1314 DebugTimer->stopTimer();
Bill Wendlingf0fb9872009-05-20 23:19:06 +00001315 return;
1316 }
Devang Patel78ab9e22009-07-30 18:56:46 +00001317
Devang Patel13e16b62009-06-26 01:49:18 +00001318 // Create DIEs for each of the externally visible global variables.
Devang Patel78ab9e22009-07-30 18:56:46 +00001319 for (DebugInfoFinder::iterator I = DbgFinder.global_variable_begin(),
1320 E = DbgFinder.global_variable_end(); I != E; ++I)
Devang Patel13e16b62009-06-26 01:49:18 +00001321 ConstructGlobalVariableDIE(*I);
1322
1323 // Create DIEs for each of the externally visible subprograms.
Devang Patel78ab9e22009-07-30 18:56:46 +00001324 for (DebugInfoFinder::iterator I = DbgFinder.subprogram_begin(),
1325 E = DbgFinder.subprogram_end(); I != E; ++I)
Devang Patel13e16b62009-06-26 01:49:18 +00001326 ConstructSubprogram(*I);
1327
Bill Wendlingf0fb9872009-05-20 23:19:06 +00001328 MMI = mmi;
1329 shouldEmit = true;
1330 MMI->setDebugInfoAvailability(true);
1331
1332 // Prime section data.
Chris Lattnerf0144122009-07-28 03:13:23 +00001333 SectionMap.insert(Asm->getObjFileLowering().getTextSection());
Bill Wendlingf0fb9872009-05-20 23:19:06 +00001334
1335 // Print out .file directives to specify files for .loc directives. These are
1336 // printed out early so that they precede any .loc directives.
1337 if (TAI->hasDotLocAndDotFile()) {
1338 for (unsigned i = 1, e = getNumSourceIds()+1; i != e; ++i) {
1339 // Remember source id starts at 1.
1340 std::pair<unsigned, unsigned> Id = getSourceDirectoryAndFileIds(i);
1341 sys::Path FullPath(getSourceDirectoryName(Id.first));
1342 bool AppendOk =
1343 FullPath.appendComponent(getSourceFileName(Id.second));
1344 assert(AppendOk && "Could not append filename to directory!");
1345 AppendOk = false;
1346 Asm->EmitFile(i, FullPath.toString());
1347 Asm->EOL();
1348 }
1349 }
1350
1351 // Emit initial sections
1352 EmitInitial();
1353
1354 if (TimePassesIsEnabled)
1355 DebugTimer->stopTimer();
1356}
1357
1358/// EndModule - Emit all Dwarf sections that should come after the content.
1359///
1360void DwarfDebug::EndModule() {
1361 if (!ShouldEmitDwarfDebug())
1362 return;
1363
1364 if (TimePassesIsEnabled)
1365 DebugTimer->startTimer();
1366
1367 // Standard sections final addresses.
Chris Lattner6c2f9e12009-08-19 05:49:37 +00001368 Asm->OutStreamer.SwitchSection(Asm->getObjFileLowering().getTextSection());
Bill Wendlingf0fb9872009-05-20 23:19:06 +00001369 EmitLabel("text_end", 0);
Chris Lattner6c2f9e12009-08-19 05:49:37 +00001370 Asm->OutStreamer.SwitchSection(Asm->getObjFileLowering().getDataSection());
Bill Wendlingf0fb9872009-05-20 23:19:06 +00001371 EmitLabel("data_end", 0);
1372
1373 // End text sections.
1374 for (unsigned i = 1, N = SectionMap.size(); i <= N; ++i) {
Chris Lattner6c2f9e12009-08-19 05:49:37 +00001375 Asm->OutStreamer.SwitchSection(SectionMap[i]);
Bill Wendlingf0fb9872009-05-20 23:19:06 +00001376 EmitLabel("section_end", i);
1377 }
1378
1379 // Emit common frame information.
1380 EmitCommonDebugFrame();
1381
1382 // Emit function debug frame information
1383 for (std::vector<FunctionDebugFrameInfo>::iterator I = DebugFrames.begin(),
1384 E = DebugFrames.end(); I != E; ++I)
1385 EmitFunctionDebugFrame(*I);
1386
1387 // Compute DIE offsets and sizes.
1388 SizeAndOffsets();
1389
1390 // Emit all the DIEs into a debug info section
1391 EmitDebugInfo();
1392
1393 // Corresponding abbreviations into a abbrev section.
1394 EmitAbbreviations();
1395
1396 // Emit source line correspondence into a debug line section.
1397 EmitDebugLines();
1398
1399 // Emit info into a debug pubnames section.
1400 EmitDebugPubNames();
1401
1402 // Emit info into a debug str section.
1403 EmitDebugStr();
1404
1405 // Emit info into a debug loc section.
1406 EmitDebugLoc();
1407
1408 // Emit info into a debug aranges section.
1409 EmitDebugARanges();
1410
1411 // Emit info into a debug ranges section.
1412 EmitDebugRanges();
1413
1414 // Emit info into a debug macinfo section.
1415 EmitDebugMacInfo();
1416
1417 // Emit inline info.
1418 EmitDebugInlineInfo();
1419
1420 if (TimePassesIsEnabled)
1421 DebugTimer->stopTimer();
1422}
1423
1424/// BeginFunction - Gather pre-function debug information. Assumes being
1425/// emitted immediately after the function entry point.
1426void DwarfDebug::BeginFunction(MachineFunction *MF) {
1427 this->MF = MF;
1428
1429 if (!ShouldEmitDwarfDebug()) return;
1430
1431 if (TimePassesIsEnabled)
1432 DebugTimer->startTimer();
1433
1434 // Begin accumulating function debug information.
1435 MMI->BeginFunction(MF);
1436
1437 // Assumes in correct section after the entry point.
1438 EmitLabel("func_begin", ++SubprogramCount);
1439
1440 // Emit label for the implicitly defined dbg.stoppoint at the start of the
1441 // function.
1442 DebugLoc FDL = MF->getDefaultDebugLoc();
1443 if (!FDL.isUnknown()) {
1444 DebugLocTuple DLT = MF->getDebugLocTuple(FDL);
1445 unsigned LabelID = RecordSourceLine(DLT.Line, DLT.Col,
1446 DICompileUnit(DLT.CompileUnit));
1447 Asm->printLabel(LabelID);
1448 }
1449
1450 if (TimePassesIsEnabled)
1451 DebugTimer->stopTimer();
1452}
1453
1454/// EndFunction - Gather and emit post-function debug information.
1455///
1456void DwarfDebug::EndFunction(MachineFunction *MF) {
1457 if (!ShouldEmitDwarfDebug()) return;
1458
1459 if (TimePassesIsEnabled)
1460 DebugTimer->startTimer();
1461
1462 // Define end label for subprogram.
1463 EmitLabel("func_end", SubprogramCount);
1464
1465 // Get function line info.
1466 if (!Lines.empty()) {
1467 // Get section line info.
Chris Lattner290c2f52009-08-03 23:20:21 +00001468 unsigned ID = SectionMap.insert(Asm->getCurrentSection());
Bill Wendlingf0fb9872009-05-20 23:19:06 +00001469 if (SectionSourceLines.size() < ID) SectionSourceLines.resize(ID);
1470 std::vector<SrcLineInfo> &SectionLineInfos = SectionSourceLines[ID-1];
1471 // Append the function info to section info.
1472 SectionLineInfos.insert(SectionLineInfos.end(),
1473 Lines.begin(), Lines.end());
1474 }
1475
1476 // Construct the DbgScope for abstract instances.
1477 for (SmallVector<DbgScope *, 32>::iterator
1478 I = AbstractInstanceRootList.begin(),
1479 E = AbstractInstanceRootList.end(); I != E; ++I)
Bill Wendling17956162009-05-20 23:28:48 +00001480 ConstructFunctionDbgScope(*I);
Bill Wendlingf0fb9872009-05-20 23:19:06 +00001481
1482 // Construct scopes for subprogram.
1483 if (FunctionDbgScope)
1484 ConstructFunctionDbgScope(FunctionDbgScope);
1485 else
1486 // FIXME: This is wrong. We are essentially getting past a problem with
1487 // debug information not being able to handle unreachable blocks that have
1488 // debug information in them. In particular, those unreachable blocks that
1489 // have "region end" info in them. That situation results in the "root
1490 // scope" not being created. If that's the case, then emit a "default"
1491 // scope, i.e., one that encompasses the whole function. This isn't
1492 // desirable. And a better way of handling this (and all of the debugging
1493 // information) needs to be explored.
1494 ConstructDefaultDbgScope(MF);
1495
1496 DebugFrames.push_back(FunctionDebugFrameInfo(SubprogramCount,
1497 MMI->getFrameMoves()));
1498
1499 // Clear debug info
1500 if (FunctionDbgScope) {
1501 delete FunctionDbgScope;
1502 DbgScopeMap.clear();
1503 DbgAbstractScopeMap.clear();
1504 DbgConcreteScopeMap.clear();
1505 InlinedVariableScopes.clear();
1506 FunctionDbgScope = NULL;
1507 LexicalScopeStack.clear();
1508 AbstractInstanceRootList.clear();
Devang Patel9217f792009-06-12 19:24:05 +00001509 AbstractInstanceRootMap.clear();
Bill Wendlingf0fb9872009-05-20 23:19:06 +00001510 }
1511
1512 Lines.clear();
1513
1514 if (TimePassesIsEnabled)
1515 DebugTimer->stopTimer();
1516}
1517
1518/// RecordSourceLine - Records location information and associates it with a
1519/// label. Returns a unique label ID used to generate a label and provide
1520/// correspondence to the source line list.
1521unsigned DwarfDebug::RecordSourceLine(Value *V, unsigned Line, unsigned Col) {
1522 if (TimePassesIsEnabled)
1523 DebugTimer->startTimer();
1524
1525 CompileUnit *Unit = CompileUnitMap[V];
1526 assert(Unit && "Unable to find CompileUnit");
1527 unsigned ID = MMI->NextLabelID();
1528 Lines.push_back(SrcLineInfo(Line, Col, Unit->getID(), ID));
1529
1530 if (TimePassesIsEnabled)
1531 DebugTimer->stopTimer();
1532
1533 return ID;
1534}
1535
1536/// RecordSourceLine - Records location information and associates it with a
1537/// label. Returns a unique label ID used to generate a label and provide
1538/// correspondence to the source line list.
1539unsigned DwarfDebug::RecordSourceLine(unsigned Line, unsigned Col,
1540 DICompileUnit CU) {
1541 if (TimePassesIsEnabled)
1542 DebugTimer->startTimer();
1543
1544 std::string Dir, Fn;
1545 unsigned Src = GetOrCreateSourceID(CU.getDirectory(Dir),
1546 CU.getFilename(Fn));
1547 unsigned ID = MMI->NextLabelID();
1548 Lines.push_back(SrcLineInfo(Line, Col, Src, ID));
1549
1550 if (TimePassesIsEnabled)
1551 DebugTimer->stopTimer();
1552
1553 return ID;
1554}
1555
1556/// getOrCreateSourceID - Public version of GetOrCreateSourceID. This can be
1557/// timed. Look up the source id with the given directory and source file
1558/// names. If none currently exists, create a new id and insert it in the
1559/// SourceIds map. This can update DirectoryNames and SourceFileNames maps as
1560/// well.
1561unsigned DwarfDebug::getOrCreateSourceID(const std::string &DirName,
1562 const std::string &FileName) {
1563 if (TimePassesIsEnabled)
1564 DebugTimer->startTimer();
1565
1566 unsigned SrcId = GetOrCreateSourceID(DirName, FileName);
1567
1568 if (TimePassesIsEnabled)
1569 DebugTimer->stopTimer();
1570
1571 return SrcId;
1572}
1573
1574/// RecordRegionStart - Indicate the start of a region.
1575unsigned DwarfDebug::RecordRegionStart(GlobalVariable *V) {
1576 if (TimePassesIsEnabled)
1577 DebugTimer->startTimer();
1578
1579 DbgScope *Scope = getOrCreateScope(V);
1580 unsigned ID = MMI->NextLabelID();
1581 if (!Scope->getStartLabelID()) Scope->setStartLabelID(ID);
1582 LexicalScopeStack.push_back(Scope);
1583
1584 if (TimePassesIsEnabled)
1585 DebugTimer->stopTimer();
1586
1587 return ID;
1588}
1589
1590/// RecordRegionEnd - Indicate the end of a region.
1591unsigned DwarfDebug::RecordRegionEnd(GlobalVariable *V) {
1592 if (TimePassesIsEnabled)
1593 DebugTimer->startTimer();
1594
1595 DbgScope *Scope = getOrCreateScope(V);
1596 unsigned ID = MMI->NextLabelID();
1597 Scope->setEndLabelID(ID);
Devang Pateldaf9e022009-06-13 02:16:18 +00001598 // FIXME : region.end() may not be in the last basic block.
1599 // For now, do not pop last lexical scope because next basic
1600 // block may start new inlined function's body.
1601 unsigned LSSize = LexicalScopeStack.size();
1602 if (LSSize != 0 && LSSize != 1)
Bill Wendlingf0fb9872009-05-20 23:19:06 +00001603 LexicalScopeStack.pop_back();
1604
1605 if (TimePassesIsEnabled)
1606 DebugTimer->stopTimer();
1607
1608 return ID;
1609}
1610
1611/// RecordVariable - Indicate the declaration of a local variable.
1612void DwarfDebug::RecordVariable(GlobalVariable *GV, unsigned FrameIndex,
1613 const MachineInstr *MI) {
1614 if (TimePassesIsEnabled)
1615 DebugTimer->startTimer();
1616
1617 DIDescriptor Desc(GV);
1618 DbgScope *Scope = NULL;
1619 bool InlinedFnVar = false;
1620
1621 if (Desc.getTag() == dwarf::DW_TAG_variable) {
1622 // GV is a global variable.
1623 DIGlobalVariable DG(GV);
1624 Scope = getOrCreateScope(DG.getContext().getGV());
1625 } else {
1626 DenseMap<const MachineInstr *, DbgScope *>::iterator
1627 SI = InlinedVariableScopes.find(MI);
1628
1629 if (SI != InlinedVariableScopes.end()) {
1630 // or GV is an inlined local variable.
1631 Scope = SI->second;
Devang Patel261cc192009-07-07 21:55:14 +00001632 InlinedFnVar = true;
Bill Wendlingf0fb9872009-05-20 23:19:06 +00001633 } else {
1634 DIVariable DV(GV);
1635 GlobalVariable *V = DV.getContext().getGV();
1636
Devang Patel0a4afb62009-07-07 21:12:32 +00001637 // or GV is a local variable.
1638 Scope = getOrCreateScope(V);
Bill Wendlingf0fb9872009-05-20 23:19:06 +00001639 }
1640 }
1641
1642 assert(Scope && "Unable to find the variable's scope");
1643 DbgVariable *DV = new DbgVariable(DIVariable(GV), FrameIndex, InlinedFnVar);
1644 Scope->AddVariable(DV);
1645
1646 if (TimePassesIsEnabled)
1647 DebugTimer->stopTimer();
1648}
1649
1650//// RecordInlinedFnStart - Indicate the start of inlined subroutine.
1651unsigned DwarfDebug::RecordInlinedFnStart(DISubprogram &SP, DICompileUnit CU,
1652 unsigned Line, unsigned Col) {
1653 unsigned LabelID = MMI->NextLabelID();
1654
1655 if (!TAI->doesDwarfUsesInlineInfoSection())
1656 return LabelID;
1657
1658 if (TimePassesIsEnabled)
1659 DebugTimer->startTimer();
1660
1661 GlobalVariable *GV = SP.getGV();
1662 DenseMap<const GlobalVariable *, DbgScope *>::iterator
1663 II = AbstractInstanceRootMap.find(GV);
1664
1665 if (II == AbstractInstanceRootMap.end()) {
1666 // Create an abstract instance entry for this inlined function if it doesn't
1667 // already exist.
1668 DbgScope *Scope = new DbgScope(NULL, DIDescriptor(GV));
1669
1670 // Get the compile unit context.
Devang Patel1dbc7712009-06-29 20:45:18 +00001671 DIE *SPDie = ModuleCU->getDieMapSlotFor(GV);
Bill Wendlingf0fb9872009-05-20 23:19:06 +00001672 if (!SPDie)
Devang Patel1dbc7712009-06-29 20:45:18 +00001673 SPDie = CreateSubprogramDIE(ModuleCU, SP, false, true);
Bill Wendlingf0fb9872009-05-20 23:19:06 +00001674
1675 // Mark as being inlined. This makes this subprogram entry an abstract
1676 // instance root.
1677 // FIXME: Our debugger doesn't care about the value of DW_AT_inline, only
1678 // that it's defined. That probably won't change in the future. However,
1679 // this could be more elegant.
1680 AddUInt(SPDie, dwarf::DW_AT_inline, 0, dwarf::DW_INL_declared_not_inlined);
1681
1682 // Keep track of the abstract scope for this function.
1683 DbgAbstractScopeMap[GV] = Scope;
1684
1685 AbstractInstanceRootMap[GV] = Scope;
1686 AbstractInstanceRootList.push_back(Scope);
1687 }
1688
1689 // Create a concrete inlined instance for this inlined function.
1690 DbgConcreteScope *ConcreteScope = new DbgConcreteScope(DIDescriptor(GV));
1691 DIE *ScopeDie = new DIE(dwarf::DW_TAG_inlined_subroutine);
Devang Patel1dbc7712009-06-29 20:45:18 +00001692 ScopeDie->setAbstractCompileUnit(ModuleCU);
Bill Wendlingf0fb9872009-05-20 23:19:06 +00001693
Devang Patel1dbc7712009-06-29 20:45:18 +00001694 DIE *Origin = ModuleCU->getDieMapSlotFor(GV);
Bill Wendlingf0fb9872009-05-20 23:19:06 +00001695 AddDIEEntry(ScopeDie, dwarf::DW_AT_abstract_origin,
1696 dwarf::DW_FORM_ref4, Origin);
Devang Patel1dbc7712009-06-29 20:45:18 +00001697 AddUInt(ScopeDie, dwarf::DW_AT_call_file, 0, ModuleCU->getID());
Bill Wendlingf0fb9872009-05-20 23:19:06 +00001698 AddUInt(ScopeDie, dwarf::DW_AT_call_line, 0, Line);
1699 AddUInt(ScopeDie, dwarf::DW_AT_call_column, 0, Col);
1700
1701 ConcreteScope->setDie(ScopeDie);
1702 ConcreteScope->setStartLabelID(LabelID);
1703 MMI->RecordUsedDbgLabel(LabelID);
1704
1705 LexicalScopeStack.back()->AddConcreteInst(ConcreteScope);
1706
1707 // Keep track of the concrete scope that's inlined into this function.
1708 DenseMap<GlobalVariable *, SmallVector<DbgScope *, 8> >::iterator
1709 SI = DbgConcreteScopeMap.find(GV);
1710
1711 if (SI == DbgConcreteScopeMap.end())
1712 DbgConcreteScopeMap[GV].push_back(ConcreteScope);
1713 else
1714 SI->second.push_back(ConcreteScope);
1715
1716 // Track the start label for this inlined function.
1717 DenseMap<GlobalVariable *, SmallVector<unsigned, 4> >::iterator
1718 I = InlineInfo.find(GV);
1719
1720 if (I == InlineInfo.end())
1721 InlineInfo[GV].push_back(LabelID);
1722 else
1723 I->second.push_back(LabelID);
1724
1725 if (TimePassesIsEnabled)
1726 DebugTimer->stopTimer();
1727
1728 return LabelID;
1729}
1730
1731/// RecordInlinedFnEnd - Indicate the end of inlined subroutine.
1732unsigned DwarfDebug::RecordInlinedFnEnd(DISubprogram &SP) {
1733 if (!TAI->doesDwarfUsesInlineInfoSection())
1734 return 0;
1735
1736 if (TimePassesIsEnabled)
1737 DebugTimer->startTimer();
1738
1739 GlobalVariable *GV = SP.getGV();
1740 DenseMap<GlobalVariable *, SmallVector<DbgScope *, 8> >::iterator
1741 I = DbgConcreteScopeMap.find(GV);
1742
1743 if (I == DbgConcreteScopeMap.end()) {
1744 // FIXME: Can this situation actually happen? And if so, should it?
1745 if (TimePassesIsEnabled)
1746 DebugTimer->stopTimer();
1747
1748 return 0;
1749 }
1750
1751 SmallVector<DbgScope *, 8> &Scopes = I->second;
Devang Patel11a407f2009-06-15 21:45:50 +00001752 if (Scopes.empty()) {
1753 // Returned ID is 0 if this is unbalanced "end of inlined
1754 // scope". This could happen if optimizer eats dbg intrinsics
1755 // or "beginning of inlined scope" is not recoginized due to
1756 // missing location info. In such cases, ignore this region.end.
1757 return 0;
1758 }
1759
Bill Wendlingf0fb9872009-05-20 23:19:06 +00001760 DbgScope *Scope = Scopes.back(); Scopes.pop_back();
1761 unsigned ID = MMI->NextLabelID();
1762 MMI->RecordUsedDbgLabel(ID);
1763 Scope->setEndLabelID(ID);
1764
1765 if (TimePassesIsEnabled)
1766 DebugTimer->stopTimer();
1767
1768 return ID;
1769}
1770
1771/// RecordVariableScope - Record scope for the variable declared by
1772/// DeclareMI. DeclareMI must describe TargetInstrInfo::DECLARE. Record scopes
1773/// for only inlined subroutine variables. Other variables's scopes are
1774/// determined during RecordVariable().
1775void DwarfDebug::RecordVariableScope(DIVariable &DV,
1776 const MachineInstr *DeclareMI) {
1777 if (TimePassesIsEnabled)
1778 DebugTimer->startTimer();
1779
1780 DISubprogram SP(DV.getContext().getGV());
1781
1782 if (SP.isNull()) {
1783 if (TimePassesIsEnabled)
1784 DebugTimer->stopTimer();
1785
1786 return;
1787 }
1788
1789 DenseMap<GlobalVariable *, DbgScope *>::iterator
1790 I = DbgAbstractScopeMap.find(SP.getGV());
1791 if (I != DbgAbstractScopeMap.end())
1792 InlinedVariableScopes[DeclareMI] = I->second;
1793
1794 if (TimePassesIsEnabled)
1795 DebugTimer->stopTimer();
1796}
Bill Wendling94d04b82009-05-20 23:21:38 +00001797
Bill Wendling829e67b2009-05-20 23:22:40 +00001798//===----------------------------------------------------------------------===//
1799// Emit Methods
1800//===----------------------------------------------------------------------===//
1801
Bill Wendling94d04b82009-05-20 23:21:38 +00001802/// SizeAndOffsetDie - Compute the size and offset of a DIE.
1803///
1804unsigned DwarfDebug::SizeAndOffsetDie(DIE *Die, unsigned Offset, bool Last) {
1805 // Get the children.
1806 const std::vector<DIE *> &Children = Die->getChildren();
1807
1808 // If not last sibling and has children then add sibling offset attribute.
1809 if (!Last && !Children.empty()) Die->AddSiblingOffset();
1810
1811 // Record the abbreviation.
1812 AssignAbbrevNumber(Die->getAbbrev());
1813
1814 // Get the abbreviation for this DIE.
1815 unsigned AbbrevNumber = Die->getAbbrevNumber();
1816 const DIEAbbrev *Abbrev = Abbreviations[AbbrevNumber - 1];
1817
1818 // Set DIE offset
1819 Die->setOffset(Offset);
1820
1821 // Start the size with the size of abbreviation code.
1822 Offset += TargetAsmInfo::getULEB128Size(AbbrevNumber);
1823
1824 const SmallVector<DIEValue*, 32> &Values = Die->getValues();
1825 const SmallVector<DIEAbbrevData, 8> &AbbrevData = Abbrev->getData();
1826
1827 // Size the DIE attribute values.
1828 for (unsigned i = 0, N = Values.size(); i < N; ++i)
1829 // Size attribute value.
1830 Offset += Values[i]->SizeOf(TD, AbbrevData[i].getForm());
1831
1832 // Size the DIE children if any.
1833 if (!Children.empty()) {
1834 assert(Abbrev->getChildrenFlag() == dwarf::DW_CHILDREN_yes &&
1835 "Children flag not set");
1836
1837 for (unsigned j = 0, M = Children.size(); j < M; ++j)
1838 Offset = SizeAndOffsetDie(Children[j], Offset, (j + 1) == M);
1839
1840 // End of children marker.
1841 Offset += sizeof(int8_t);
1842 }
1843
1844 Die->setSize(Offset - Die->getOffset());
1845 return Offset;
1846}
1847
1848/// SizeAndOffsets - Compute the size and offset of all the DIEs.
1849///
1850void DwarfDebug::SizeAndOffsets() {
1851 // Compute size of compile unit header.
1852 static unsigned Offset =
1853 sizeof(int32_t) + // Length of Compilation Unit Info
1854 sizeof(int16_t) + // DWARF version number
1855 sizeof(int32_t) + // Offset Into Abbrev. Section
1856 sizeof(int8_t); // Pointer Size (in bytes)
1857
Devang Patel1dbc7712009-06-29 20:45:18 +00001858 SizeAndOffsetDie(ModuleCU->getDie(), Offset, true);
1859 CompileUnitOffsets[ModuleCU] = 0;
Bill Wendling94d04b82009-05-20 23:21:38 +00001860}
1861
1862/// EmitInitial - Emit initial Dwarf declarations. This is necessary for cc
1863/// tools to recognize the object file contains Dwarf information.
1864void DwarfDebug::EmitInitial() {
1865 // Check to see if we already emitted intial headers.
1866 if (didInitial) return;
1867 didInitial = true;
1868
Chris Lattner6c2f9e12009-08-19 05:49:37 +00001869 const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
1870
Bill Wendling94d04b82009-05-20 23:21:38 +00001871 // Dwarf sections base addresses.
1872 if (TAI->doesDwarfRequireFrameSection()) {
Chris Lattner6c2f9e12009-08-19 05:49:37 +00001873 Asm->OutStreamer.SwitchSection(TLOF.getDwarfFrameSection());
Bill Wendling94d04b82009-05-20 23:21:38 +00001874 EmitLabel("section_debug_frame", 0);
1875 }
1876
Chris Lattner6c2f9e12009-08-19 05:49:37 +00001877 Asm->OutStreamer.SwitchSection(TLOF.getDwarfInfoSection());
Bill Wendling94d04b82009-05-20 23:21:38 +00001878 EmitLabel("section_info", 0);
Chris Lattner6c2f9e12009-08-19 05:49:37 +00001879 Asm->OutStreamer.SwitchSection(TLOF.getDwarfAbbrevSection());
Bill Wendling94d04b82009-05-20 23:21:38 +00001880 EmitLabel("section_abbrev", 0);
Chris Lattner6c2f9e12009-08-19 05:49:37 +00001881 Asm->OutStreamer.SwitchSection(TLOF.getDwarfARangesSection());
Bill Wendling94d04b82009-05-20 23:21:38 +00001882 EmitLabel("section_aranges", 0);
1883
Chris Lattner6c2f9e12009-08-19 05:49:37 +00001884 if (const MCSection *LineInfoDirective = TLOF.getDwarfMacroInfoSection()) {
1885 Asm->OutStreamer.SwitchSection(LineInfoDirective);
Bill Wendling94d04b82009-05-20 23:21:38 +00001886 EmitLabel("section_macinfo", 0);
1887 }
1888
Chris Lattner6c2f9e12009-08-19 05:49:37 +00001889 Asm->OutStreamer.SwitchSection(TLOF.getDwarfLineSection());
Bill Wendling94d04b82009-05-20 23:21:38 +00001890 EmitLabel("section_line", 0);
Chris Lattner6c2f9e12009-08-19 05:49:37 +00001891 Asm->OutStreamer.SwitchSection(TLOF.getDwarfLocSection());
Bill Wendling94d04b82009-05-20 23:21:38 +00001892 EmitLabel("section_loc", 0);
Chris Lattner6c2f9e12009-08-19 05:49:37 +00001893 Asm->OutStreamer.SwitchSection(TLOF.getDwarfPubNamesSection());
Bill Wendling94d04b82009-05-20 23:21:38 +00001894 EmitLabel("section_pubnames", 0);
Chris Lattner6c2f9e12009-08-19 05:49:37 +00001895 Asm->OutStreamer.SwitchSection(TLOF.getDwarfStrSection());
Bill Wendling94d04b82009-05-20 23:21:38 +00001896 EmitLabel("section_str", 0);
Chris Lattner6c2f9e12009-08-19 05:49:37 +00001897 Asm->OutStreamer.SwitchSection(TLOF.getDwarfRangesSection());
Bill Wendling94d04b82009-05-20 23:21:38 +00001898 EmitLabel("section_ranges", 0);
1899
Chris Lattner6c2f9e12009-08-19 05:49:37 +00001900 Asm->OutStreamer.SwitchSection(TLOF.getTextSection());
Bill Wendling94d04b82009-05-20 23:21:38 +00001901 EmitLabel("text_begin", 0);
Chris Lattner6c2f9e12009-08-19 05:49:37 +00001902 Asm->OutStreamer.SwitchSection(TLOF.getDataSection());
Bill Wendling94d04b82009-05-20 23:21:38 +00001903 EmitLabel("data_begin", 0);
1904}
1905
1906/// EmitDIE - Recusively Emits a debug information entry.
1907///
1908void DwarfDebug::EmitDIE(DIE *Die) {
1909 // Get the abbreviation for this DIE.
1910 unsigned AbbrevNumber = Die->getAbbrevNumber();
1911 const DIEAbbrev *Abbrev = Abbreviations[AbbrevNumber - 1];
1912
1913 Asm->EOL();
1914
1915 // Emit the code (index) for the abbreviation.
1916 Asm->EmitULEB128Bytes(AbbrevNumber);
1917
1918 if (Asm->isVerbose())
1919 Asm->EOL(std::string("Abbrev [" +
1920 utostr(AbbrevNumber) +
1921 "] 0x" + utohexstr(Die->getOffset()) +
1922 ":0x" + utohexstr(Die->getSize()) + " " +
1923 dwarf::TagString(Abbrev->getTag())));
1924 else
1925 Asm->EOL();
1926
1927 SmallVector<DIEValue*, 32> &Values = Die->getValues();
1928 const SmallVector<DIEAbbrevData, 8> &AbbrevData = Abbrev->getData();
1929
1930 // Emit the DIE attribute values.
1931 for (unsigned i = 0, N = Values.size(); i < N; ++i) {
1932 unsigned Attr = AbbrevData[i].getAttribute();
1933 unsigned Form = AbbrevData[i].getForm();
1934 assert(Form && "Too many attributes for DIE (check abbreviation)");
1935
1936 switch (Attr) {
1937 case dwarf::DW_AT_sibling:
1938 Asm->EmitInt32(Die->SiblingOffset());
1939 break;
1940 case dwarf::DW_AT_abstract_origin: {
1941 DIEEntry *E = cast<DIEEntry>(Values[i]);
1942 DIE *Origin = E->getEntry();
1943 unsigned Addr =
1944 CompileUnitOffsets[Die->getAbstractCompileUnit()] +
1945 Origin->getOffset();
1946
1947 Asm->EmitInt32(Addr);
1948 break;
1949 }
1950 default:
1951 // Emit an attribute using the defined form.
1952 Values[i]->EmitValue(this, Form);
1953 break;
1954 }
1955
1956 Asm->EOL(dwarf::AttributeString(Attr));
1957 }
1958
1959 // Emit the DIE children if any.
1960 if (Abbrev->getChildrenFlag() == dwarf::DW_CHILDREN_yes) {
1961 const std::vector<DIE *> &Children = Die->getChildren();
1962
1963 for (unsigned j = 0, M = Children.size(); j < M; ++j)
1964 EmitDIE(Children[j]);
1965
1966 Asm->EmitInt8(0); Asm->EOL("End Of Children Mark");
1967 }
1968}
1969
1970/// EmitDebugInfo / EmitDebugInfoPerCU - Emit the debug info section.
1971///
1972void DwarfDebug::EmitDebugInfoPerCU(CompileUnit *Unit) {
1973 DIE *Die = Unit->getDie();
1974
1975 // Emit the compile units header.
1976 EmitLabel("info_begin", Unit->getID());
1977
1978 // Emit size of content not including length itself
1979 unsigned ContentSize = Die->getSize() +
1980 sizeof(int16_t) + // DWARF version number
1981 sizeof(int32_t) + // Offset Into Abbrev. Section
1982 sizeof(int8_t) + // Pointer Size (in bytes)
1983 sizeof(int32_t); // FIXME - extra pad for gdb bug.
1984
1985 Asm->EmitInt32(ContentSize); Asm->EOL("Length of Compilation Unit Info");
1986 Asm->EmitInt16(dwarf::DWARF_VERSION); Asm->EOL("DWARF version number");
1987 EmitSectionOffset("abbrev_begin", "section_abbrev", 0, 0, true, false);
1988 Asm->EOL("Offset Into Abbrev. Section");
1989 Asm->EmitInt8(TD->getPointerSize()); Asm->EOL("Address Size (in bytes)");
1990
1991 EmitDIE(Die);
1992 // FIXME - extra padding for gdb bug.
1993 Asm->EmitInt8(0); Asm->EOL("Extra Pad For GDB");
1994 Asm->EmitInt8(0); Asm->EOL("Extra Pad For GDB");
1995 Asm->EmitInt8(0); Asm->EOL("Extra Pad For GDB");
1996 Asm->EmitInt8(0); Asm->EOL("Extra Pad For GDB");
1997 EmitLabel("info_end", Unit->getID());
1998
1999 Asm->EOL();
2000}
2001
2002void DwarfDebug::EmitDebugInfo() {
2003 // Start debug info section.
Chris Lattner6c2f9e12009-08-19 05:49:37 +00002004 Asm->OutStreamer.SwitchSection(
2005 Asm->getObjFileLowering().getDwarfInfoSection());
Bill Wendling94d04b82009-05-20 23:21:38 +00002006
Devang Patel1dbc7712009-06-29 20:45:18 +00002007 EmitDebugInfoPerCU(ModuleCU);
Bill Wendling94d04b82009-05-20 23:21:38 +00002008}
2009
2010/// EmitAbbreviations - Emit the abbreviation section.
2011///
2012void DwarfDebug::EmitAbbreviations() const {
2013 // Check to see if it is worth the effort.
2014 if (!Abbreviations.empty()) {
2015 // Start the debug abbrev section.
Chris Lattner6c2f9e12009-08-19 05:49:37 +00002016 Asm->OutStreamer.SwitchSection(
2017 Asm->getObjFileLowering().getDwarfAbbrevSection());
Bill Wendling94d04b82009-05-20 23:21:38 +00002018
2019 EmitLabel("abbrev_begin", 0);
2020
2021 // For each abbrevation.
2022 for (unsigned i = 0, N = Abbreviations.size(); i < N; ++i) {
2023 // Get abbreviation data
2024 const DIEAbbrev *Abbrev = Abbreviations[i];
2025
2026 // Emit the abbrevations code (base 1 index.)
2027 Asm->EmitULEB128Bytes(Abbrev->getNumber());
2028 Asm->EOL("Abbreviation Code");
2029
2030 // Emit the abbreviations data.
2031 Abbrev->Emit(Asm);
2032
2033 Asm->EOL();
2034 }
2035
2036 // Mark end of abbreviations.
2037 Asm->EmitULEB128Bytes(0); Asm->EOL("EOM(3)");
2038
2039 EmitLabel("abbrev_end", 0);
2040 Asm->EOL();
2041 }
2042}
2043
2044/// EmitEndOfLineMatrix - Emit the last address of the section and the end of
2045/// the line matrix.
2046///
2047void DwarfDebug::EmitEndOfLineMatrix(unsigned SectionEnd) {
2048 // Define last address of section.
2049 Asm->EmitInt8(0); Asm->EOL("Extended Op");
2050 Asm->EmitInt8(TD->getPointerSize() + 1); Asm->EOL("Op size");
2051 Asm->EmitInt8(dwarf::DW_LNE_set_address); Asm->EOL("DW_LNE_set_address");
2052 EmitReference("section_end", SectionEnd); Asm->EOL("Section end label");
2053
2054 // Mark end of matrix.
2055 Asm->EmitInt8(0); Asm->EOL("DW_LNE_end_sequence");
2056 Asm->EmitULEB128Bytes(1); Asm->EOL();
2057 Asm->EmitInt8(1); Asm->EOL();
2058}
2059
2060/// EmitDebugLines - Emit source line information.
2061///
2062void DwarfDebug::EmitDebugLines() {
2063 // If the target is using .loc/.file, the assembler will be emitting the
2064 // .debug_line table automatically.
2065 if (TAI->hasDotLocAndDotFile())
2066 return;
2067
2068 // Minimum line delta, thus ranging from -10..(255-10).
2069 const int MinLineDelta = -(dwarf::DW_LNS_fixed_advance_pc + 1);
2070 // Maximum line delta, thus ranging from -10..(255-10).
2071 const int MaxLineDelta = 255 + MinLineDelta;
2072
2073 // Start the dwarf line section.
Chris Lattner6c2f9e12009-08-19 05:49:37 +00002074 Asm->OutStreamer.SwitchSection(
2075 Asm->getObjFileLowering().getDwarfLineSection());
Bill Wendling94d04b82009-05-20 23:21:38 +00002076
2077 // Construct the section header.
2078 EmitDifference("line_end", 0, "line_begin", 0, true);
2079 Asm->EOL("Length of Source Line Info");
2080 EmitLabel("line_begin", 0);
2081
2082 Asm->EmitInt16(dwarf::DWARF_VERSION); Asm->EOL("DWARF version number");
2083
2084 EmitDifference("line_prolog_end", 0, "line_prolog_begin", 0, true);
2085 Asm->EOL("Prolog Length");
2086 EmitLabel("line_prolog_begin", 0);
2087
2088 Asm->EmitInt8(1); Asm->EOL("Minimum Instruction Length");
2089
2090 Asm->EmitInt8(1); Asm->EOL("Default is_stmt_start flag");
2091
2092 Asm->EmitInt8(MinLineDelta); Asm->EOL("Line Base Value (Special Opcodes)");
2093
2094 Asm->EmitInt8(MaxLineDelta); Asm->EOL("Line Range Value (Special Opcodes)");
2095
2096 Asm->EmitInt8(-MinLineDelta); Asm->EOL("Special Opcode Base");
2097
2098 // Line number standard opcode encodings argument count
2099 Asm->EmitInt8(0); Asm->EOL("DW_LNS_copy arg count");
2100 Asm->EmitInt8(1); Asm->EOL("DW_LNS_advance_pc arg count");
2101 Asm->EmitInt8(1); Asm->EOL("DW_LNS_advance_line arg count");
2102 Asm->EmitInt8(1); Asm->EOL("DW_LNS_set_file arg count");
2103 Asm->EmitInt8(1); Asm->EOL("DW_LNS_set_column arg count");
2104 Asm->EmitInt8(0); Asm->EOL("DW_LNS_negate_stmt arg count");
2105 Asm->EmitInt8(0); Asm->EOL("DW_LNS_set_basic_block arg count");
2106 Asm->EmitInt8(0); Asm->EOL("DW_LNS_const_add_pc arg count");
2107 Asm->EmitInt8(1); Asm->EOL("DW_LNS_fixed_advance_pc arg count");
2108
2109 // Emit directories.
2110 for (unsigned DI = 1, DE = getNumSourceDirectories()+1; DI != DE; ++DI) {
2111 Asm->EmitString(getSourceDirectoryName(DI));
2112 Asm->EOL("Directory");
2113 }
2114
2115 Asm->EmitInt8(0); Asm->EOL("End of directories");
2116
2117 // Emit files.
2118 for (unsigned SI = 1, SE = getNumSourceIds()+1; SI != SE; ++SI) {
2119 // Remember source id starts at 1.
2120 std::pair<unsigned, unsigned> Id = getSourceDirectoryAndFileIds(SI);
2121 Asm->EmitString(getSourceFileName(Id.second));
2122 Asm->EOL("Source");
2123 Asm->EmitULEB128Bytes(Id.first);
2124 Asm->EOL("Directory #");
2125 Asm->EmitULEB128Bytes(0);
2126 Asm->EOL("Mod date");
2127 Asm->EmitULEB128Bytes(0);
2128 Asm->EOL("File size");
2129 }
2130
2131 Asm->EmitInt8(0); Asm->EOL("End of files");
2132
2133 EmitLabel("line_prolog_end", 0);
2134
2135 // A sequence for each text section.
2136 unsigned SecSrcLinesSize = SectionSourceLines.size();
2137
2138 for (unsigned j = 0; j < SecSrcLinesSize; ++j) {
2139 // Isolate current sections line info.
2140 const std::vector<SrcLineInfo> &LineInfos = SectionSourceLines[j];
2141
Chris Lattner93b6db32009-08-08 23:39:42 +00002142 /*if (Asm->isVerbose()) {
Chris Lattnera87dea42009-07-31 18:48:30 +00002143 const MCSection *S = SectionMap[j + 1];
Bill Wendling94d04b82009-05-20 23:21:38 +00002144 O << '\t' << TAI->getCommentString() << " Section"
2145 << S->getName() << '\n';
Chris Lattner93b6db32009-08-08 23:39:42 +00002146 }*/
2147 Asm->EOL();
Bill Wendling94d04b82009-05-20 23:21:38 +00002148
2149 // Dwarf assumes we start with first line of first source file.
2150 unsigned Source = 1;
2151 unsigned Line = 1;
2152
2153 // Construct rows of the address, source, line, column matrix.
2154 for (unsigned i = 0, N = LineInfos.size(); i < N; ++i) {
2155 const SrcLineInfo &LineInfo = LineInfos[i];
2156 unsigned LabelID = MMI->MappedLabel(LineInfo.getLabelID());
2157 if (!LabelID) continue;
2158
2159 if (!Asm->isVerbose())
2160 Asm->EOL();
2161 else {
2162 std::pair<unsigned, unsigned> SourceID =
2163 getSourceDirectoryAndFileIds(LineInfo.getSourceID());
2164 O << '\t' << TAI->getCommentString() << ' '
2165 << getSourceDirectoryName(SourceID.first) << ' '
2166 << getSourceFileName(SourceID.second)
2167 <<" :" << utostr_32(LineInfo.getLine()) << '\n';
2168 }
2169
2170 // Define the line address.
2171 Asm->EmitInt8(0); Asm->EOL("Extended Op");
2172 Asm->EmitInt8(TD->getPointerSize() + 1); Asm->EOL("Op size");
2173 Asm->EmitInt8(dwarf::DW_LNE_set_address); Asm->EOL("DW_LNE_set_address");
2174 EmitReference("label", LabelID); Asm->EOL("Location label");
2175
2176 // If change of source, then switch to the new source.
2177 if (Source != LineInfo.getSourceID()) {
2178 Source = LineInfo.getSourceID();
2179 Asm->EmitInt8(dwarf::DW_LNS_set_file); Asm->EOL("DW_LNS_set_file");
2180 Asm->EmitULEB128Bytes(Source); Asm->EOL("New Source");
2181 }
2182
2183 // If change of line.
2184 if (Line != LineInfo.getLine()) {
2185 // Determine offset.
2186 int Offset = LineInfo.getLine() - Line;
2187 int Delta = Offset - MinLineDelta;
2188
2189 // Update line.
2190 Line = LineInfo.getLine();
2191
2192 // If delta is small enough and in range...
2193 if (Delta >= 0 && Delta < (MaxLineDelta - 1)) {
2194 // ... then use fast opcode.
2195 Asm->EmitInt8(Delta - MinLineDelta); Asm->EOL("Line Delta");
2196 } else {
2197 // ... otherwise use long hand.
2198 Asm->EmitInt8(dwarf::DW_LNS_advance_line);
2199 Asm->EOL("DW_LNS_advance_line");
2200 Asm->EmitSLEB128Bytes(Offset); Asm->EOL("Line Offset");
2201 Asm->EmitInt8(dwarf::DW_LNS_copy); Asm->EOL("DW_LNS_copy");
2202 }
2203 } else {
2204 // Copy the previous row (different address or source)
2205 Asm->EmitInt8(dwarf::DW_LNS_copy); Asm->EOL("DW_LNS_copy");
2206 }
2207 }
2208
2209 EmitEndOfLineMatrix(j + 1);
2210 }
2211
2212 if (SecSrcLinesSize == 0)
2213 // Because we're emitting a debug_line section, we still need a line
2214 // table. The linker and friends expect it to exist. If there's nothing to
2215 // put into it, emit an empty table.
2216 EmitEndOfLineMatrix(1);
2217
2218 EmitLabel("line_end", 0);
2219 Asm->EOL();
2220}
2221
2222/// EmitCommonDebugFrame - Emit common frame info into a debug frame section.
2223///
2224void DwarfDebug::EmitCommonDebugFrame() {
2225 if (!TAI->doesDwarfRequireFrameSection())
2226 return;
2227
2228 int stackGrowth =
2229 Asm->TM.getFrameInfo()->getStackGrowthDirection() ==
2230 TargetFrameInfo::StackGrowsUp ?
2231 TD->getPointerSize() : -TD->getPointerSize();
2232
2233 // Start the dwarf frame section.
Chris Lattner6c2f9e12009-08-19 05:49:37 +00002234 Asm->OutStreamer.SwitchSection(
2235 Asm->getObjFileLowering().getDwarfFrameSection());
Bill Wendling94d04b82009-05-20 23:21:38 +00002236
2237 EmitLabel("debug_frame_common", 0);
2238 EmitDifference("debug_frame_common_end", 0,
2239 "debug_frame_common_begin", 0, true);
2240 Asm->EOL("Length of Common Information Entry");
2241
2242 EmitLabel("debug_frame_common_begin", 0);
2243 Asm->EmitInt32((int)dwarf::DW_CIE_ID);
2244 Asm->EOL("CIE Identifier Tag");
2245 Asm->EmitInt8(dwarf::DW_CIE_VERSION);
2246 Asm->EOL("CIE Version");
2247 Asm->EmitString("");
2248 Asm->EOL("CIE Augmentation");
2249 Asm->EmitULEB128Bytes(1);
2250 Asm->EOL("CIE Code Alignment Factor");
2251 Asm->EmitSLEB128Bytes(stackGrowth);
2252 Asm->EOL("CIE Data Alignment Factor");
2253 Asm->EmitInt8(RI->getDwarfRegNum(RI->getRARegister(), false));
2254 Asm->EOL("CIE RA Column");
2255
2256 std::vector<MachineMove> Moves;
2257 RI->getInitialFrameState(Moves);
2258
2259 EmitFrameMoves(NULL, 0, Moves, false);
2260
2261 Asm->EmitAlignment(2, 0, 0, false);
2262 EmitLabel("debug_frame_common_end", 0);
2263
2264 Asm->EOL();
2265}
2266
2267/// EmitFunctionDebugFrame - Emit per function frame info into a debug frame
2268/// section.
2269void
2270DwarfDebug::EmitFunctionDebugFrame(const FunctionDebugFrameInfo&DebugFrameInfo){
2271 if (!TAI->doesDwarfRequireFrameSection())
2272 return;
2273
2274 // Start the dwarf frame section.
Chris Lattner6c2f9e12009-08-19 05:49:37 +00002275 Asm->OutStreamer.SwitchSection(
2276 Asm->getObjFileLowering().getDwarfFrameSection());
Bill Wendling94d04b82009-05-20 23:21:38 +00002277
2278 EmitDifference("debug_frame_end", DebugFrameInfo.Number,
2279 "debug_frame_begin", DebugFrameInfo.Number, true);
2280 Asm->EOL("Length of Frame Information Entry");
2281
2282 EmitLabel("debug_frame_begin", DebugFrameInfo.Number);
2283
2284 EmitSectionOffset("debug_frame_common", "section_debug_frame",
2285 0, 0, true, false);
2286 Asm->EOL("FDE CIE offset");
2287
2288 EmitReference("func_begin", DebugFrameInfo.Number);
2289 Asm->EOL("FDE initial location");
2290 EmitDifference("func_end", DebugFrameInfo.Number,
2291 "func_begin", DebugFrameInfo.Number);
2292 Asm->EOL("FDE address range");
2293
2294 EmitFrameMoves("func_begin", DebugFrameInfo.Number, DebugFrameInfo.Moves,
2295 false);
2296
2297 Asm->EmitAlignment(2, 0, 0, false);
2298 EmitLabel("debug_frame_end", DebugFrameInfo.Number);
2299
2300 Asm->EOL();
2301}
2302
2303void DwarfDebug::EmitDebugPubNamesPerCU(CompileUnit *Unit) {
2304 EmitDifference("pubnames_end", Unit->getID(),
2305 "pubnames_begin", Unit->getID(), true);
2306 Asm->EOL("Length of Public Names Info");
2307
2308 EmitLabel("pubnames_begin", Unit->getID());
2309
2310 Asm->EmitInt16(dwarf::DWARF_VERSION); Asm->EOL("DWARF Version");
2311
2312 EmitSectionOffset("info_begin", "section_info",
2313 Unit->getID(), 0, true, false);
2314 Asm->EOL("Offset of Compilation Unit Info");
2315
2316 EmitDifference("info_end", Unit->getID(), "info_begin", Unit->getID(),
2317 true);
2318 Asm->EOL("Compilation Unit Length");
2319
2320 StringMap<DIE*> &Globals = Unit->getGlobals();
2321 for (StringMap<DIE*>::const_iterator
2322 GI = Globals.begin(), GE = Globals.end(); GI != GE; ++GI) {
2323 const char *Name = GI->getKeyData();
2324 DIE * Entity = GI->second;
2325
2326 Asm->EmitInt32(Entity->getOffset()); Asm->EOL("DIE offset");
2327 Asm->EmitString(Name, strlen(Name)); Asm->EOL("External Name");
2328 }
2329
2330 Asm->EmitInt32(0); Asm->EOL("End Mark");
2331 EmitLabel("pubnames_end", Unit->getID());
2332
2333 Asm->EOL();
2334}
2335
2336/// EmitDebugPubNames - Emit visible names into a debug pubnames section.
2337///
2338void DwarfDebug::EmitDebugPubNames() {
2339 // Start the dwarf pubnames section.
Chris Lattner6c2f9e12009-08-19 05:49:37 +00002340 Asm->OutStreamer.SwitchSection(
2341 Asm->getObjFileLowering().getDwarfPubNamesSection());
Bill Wendling94d04b82009-05-20 23:21:38 +00002342
Devang Patel1dbc7712009-06-29 20:45:18 +00002343 EmitDebugPubNamesPerCU(ModuleCU);
Bill Wendling94d04b82009-05-20 23:21:38 +00002344}
2345
2346/// EmitDebugStr - Emit visible names into a debug str section.
2347///
2348void DwarfDebug::EmitDebugStr() {
2349 // Check to see if it is worth the effort.
2350 if (!StringPool.empty()) {
2351 // Start the dwarf str section.
Chris Lattner6c2f9e12009-08-19 05:49:37 +00002352 Asm->OutStreamer.SwitchSection(
2353 Asm->getObjFileLowering().getDwarfStrSection());
Bill Wendling94d04b82009-05-20 23:21:38 +00002354
2355 // For each of strings in the string pool.
2356 for (unsigned StringID = 1, N = StringPool.size();
2357 StringID <= N; ++StringID) {
2358 // Emit a label for reference from debug information entries.
2359 EmitLabel("string", StringID);
2360
2361 // Emit the string itself.
2362 const std::string &String = StringPool[StringID];
2363 Asm->EmitString(String); Asm->EOL();
2364 }
2365
2366 Asm->EOL();
2367 }
2368}
2369
2370/// EmitDebugLoc - Emit visible names into a debug loc section.
2371///
2372void DwarfDebug::EmitDebugLoc() {
2373 // Start the dwarf loc section.
Chris Lattner6c2f9e12009-08-19 05:49:37 +00002374 Asm->OutStreamer.SwitchSection(
2375 Asm->getObjFileLowering().getDwarfLocSection());
Bill Wendling94d04b82009-05-20 23:21:38 +00002376 Asm->EOL();
2377}
2378
2379/// EmitDebugARanges - Emit visible names into a debug aranges section.
2380///
2381void DwarfDebug::EmitDebugARanges() {
2382 // Start the dwarf aranges section.
Chris Lattner6c2f9e12009-08-19 05:49:37 +00002383 Asm->OutStreamer.SwitchSection(
2384 Asm->getObjFileLowering().getDwarfARangesSection());
Bill Wendling94d04b82009-05-20 23:21:38 +00002385
2386 // FIXME - Mock up
2387#if 0
2388 CompileUnit *Unit = GetBaseCompileUnit();
2389
2390 // Don't include size of length
2391 Asm->EmitInt32(0x1c); Asm->EOL("Length of Address Ranges Info");
2392
2393 Asm->EmitInt16(dwarf::DWARF_VERSION); Asm->EOL("Dwarf Version");
2394
2395 EmitReference("info_begin", Unit->getID());
2396 Asm->EOL("Offset of Compilation Unit Info");
2397
2398 Asm->EmitInt8(TD->getPointerSize()); Asm->EOL("Size of Address");
2399
2400 Asm->EmitInt8(0); Asm->EOL("Size of Segment Descriptor");
2401
2402 Asm->EmitInt16(0); Asm->EOL("Pad (1)");
2403 Asm->EmitInt16(0); Asm->EOL("Pad (2)");
2404
2405 // Range 1
2406 EmitReference("text_begin", 0); Asm->EOL("Address");
2407 EmitDifference("text_end", 0, "text_begin", 0, true); Asm->EOL("Length");
2408
2409 Asm->EmitInt32(0); Asm->EOL("EOM (1)");
2410 Asm->EmitInt32(0); Asm->EOL("EOM (2)");
2411#endif
2412
2413 Asm->EOL();
2414}
2415
2416/// EmitDebugRanges - Emit visible names into a debug ranges section.
2417///
2418void DwarfDebug::EmitDebugRanges() {
2419 // Start the dwarf ranges section.
Chris Lattner6c2f9e12009-08-19 05:49:37 +00002420 Asm->OutStreamer.SwitchSection(
2421 Asm->getObjFileLowering().getDwarfRangesSection());
Bill Wendling94d04b82009-05-20 23:21:38 +00002422 Asm->EOL();
2423}
2424
2425/// EmitDebugMacInfo - Emit visible names into a debug macinfo section.
2426///
2427void DwarfDebug::EmitDebugMacInfo() {
Chris Lattner18a4c162009-08-02 07:24:22 +00002428 if (const MCSection *LineInfo =
2429 Asm->getObjFileLowering().getDwarfMacroInfoSection()) {
Bill Wendling94d04b82009-05-20 23:21:38 +00002430 // Start the dwarf macinfo section.
Chris Lattner6c2f9e12009-08-19 05:49:37 +00002431 Asm->OutStreamer.SwitchSection(LineInfo);
Bill Wendling94d04b82009-05-20 23:21:38 +00002432 Asm->EOL();
2433 }
2434}
2435
2436/// EmitDebugInlineInfo - Emit inline info using following format.
2437/// Section Header:
2438/// 1. length of section
2439/// 2. Dwarf version number
2440/// 3. address size.
2441///
2442/// Entries (one "entry" for each function that was inlined):
2443///
2444/// 1. offset into __debug_str section for MIPS linkage name, if exists;
2445/// otherwise offset into __debug_str for regular function name.
2446/// 2. offset into __debug_str section for regular function name.
2447/// 3. an unsigned LEB128 number indicating the number of distinct inlining
2448/// instances for the function.
2449///
2450/// The rest of the entry consists of a {die_offset, low_pc} pair for each
2451/// inlined instance; the die_offset points to the inlined_subroutine die in the
2452/// __debug_info section, and the low_pc is the starting address for the
2453/// inlining instance.
2454void DwarfDebug::EmitDebugInlineInfo() {
2455 if (!TAI->doesDwarfUsesInlineInfoSection())
2456 return;
2457
Devang Patel1dbc7712009-06-29 20:45:18 +00002458 if (!ModuleCU)
Bill Wendling94d04b82009-05-20 23:21:38 +00002459 return;
2460
Chris Lattner6c2f9e12009-08-19 05:49:37 +00002461 Asm->OutStreamer.SwitchSection(
2462 Asm->getObjFileLowering().getDwarfDebugInlineSection());
Bill Wendling94d04b82009-05-20 23:21:38 +00002463 Asm->EOL();
2464 EmitDifference("debug_inlined_end", 1,
2465 "debug_inlined_begin", 1, true);
2466 Asm->EOL("Length of Debug Inlined Information Entry");
2467
2468 EmitLabel("debug_inlined_begin", 1);
2469
2470 Asm->EmitInt16(dwarf::DWARF_VERSION); Asm->EOL("Dwarf Version");
2471 Asm->EmitInt8(TD->getPointerSize()); Asm->EOL("Address Size (in bytes)");
2472
2473 for (DenseMap<GlobalVariable *, SmallVector<unsigned, 4> >::iterator
2474 I = InlineInfo.begin(), E = InlineInfo.end(); I != E; ++I) {
2475 GlobalVariable *GV = I->first;
2476 SmallVector<unsigned, 4> &Labels = I->second;
2477 DISubprogram SP(GV);
2478 std::string Name;
2479 std::string LName;
2480
2481 SP.getLinkageName(LName);
2482 SP.getName(Name);
2483
Devang Patel53cb17d2009-07-16 01:01:22 +00002484 if (LName.empty())
2485 Asm->EmitString(Name);
2486 else {
Chris Lattner6c2f9e12009-08-19 05:49:37 +00002487 // Skip special LLVM prefix that is used to inform the asm printer to not
2488 // emit usual symbol prefix before the symbol name. This happens for
2489 // Objective-C symbol names and symbol whose name is replaced using GCC's
2490 // __asm__ attribute.
Devang Patel53cb17d2009-07-16 01:01:22 +00002491 if (LName[0] == 1)
2492 LName = &LName[1];
2493 Asm->EmitString(LName);
2494 }
Bill Wendling94d04b82009-05-20 23:21:38 +00002495 Asm->EOL("MIPS linkage name");
2496
2497 Asm->EmitString(Name); Asm->EOL("Function name");
2498
2499 Asm->EmitULEB128Bytes(Labels.size()); Asm->EOL("Inline count");
2500
2501 for (SmallVector<unsigned, 4>::iterator LI = Labels.begin(),
2502 LE = Labels.end(); LI != LE; ++LI) {
Devang Patel1dbc7712009-06-29 20:45:18 +00002503 DIE *SP = ModuleCU->getDieMapSlotFor(GV);
Bill Wendling94d04b82009-05-20 23:21:38 +00002504 Asm->EmitInt32(SP->getOffset()); Asm->EOL("DIE offset");
2505
2506 if (TD->getPointerSize() == sizeof(int32_t))
2507 O << TAI->getData32bitsDirective();
2508 else
2509 O << TAI->getData64bitsDirective();
2510
2511 PrintLabelName("label", *LI); Asm->EOL("low_pc");
2512 }
2513 }
2514
2515 EmitLabel("debug_inlined_end", 1);
2516 Asm->EOL();
2517}