1 //===-- llvm/CodeGen/DwarfWriter.cpp - Dwarf Framework --------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains support for writing dwarf info into asm files.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/CodeGen/DwarfWriter.h"
15 #include "llvm/Module.h"
16 #include "llvm/DerivedTypes.h"
17 #include "llvm/Constants.h"
18 #include "llvm/CodeGen/AsmPrinter.h"
19 #include "llvm/CodeGen/MachineModuleInfo.h"
20 #include "llvm/CodeGen/MachineFrameInfo.h"
21 #include "llvm/CodeGen/MachineLocation.h"
22 #include "llvm/Analysis/DebugInfo.h"
23 #include "llvm/Support/Debug.h"
24 #include "llvm/Support/Dwarf.h"
25 #include "llvm/Support/CommandLine.h"
26 #include "llvm/Support/DataTypes.h"
27 #include "llvm/Support/Mangler.h"
28 #include "llvm/Support/Timer.h"
29 #include "llvm/Support/raw_ostream.h"
30 #include "llvm/System/Path.h"
31 #include "llvm/Target/TargetAsmInfo.h"
32 #include "llvm/Target/TargetRegisterInfo.h"
33 #include "llvm/Target/TargetData.h"
34 #include "llvm/Target/TargetFrameInfo.h"
35 #include "llvm/Target/TargetInstrInfo.h"
36 #include "llvm/Target/TargetMachine.h"
37 #include "llvm/Target/TargetOptions.h"
38 #include "llvm/ADT/DenseMap.h"
39 #include "llvm/ADT/FoldingSet.h"
40 #include "llvm/ADT/StringExtras.h"
41 #include "llvm/ADT/StringMap.h"
45 using namespace llvm::dwarf;
47 static RegisterPass<DwarfWriter>
48 X("dwarfwriter", "DWARF Information Writer");
49 char DwarfWriter::ID = 0;
51 static TimerGroup &getDwarfTimerGroup() {
52 static TimerGroup DwarfTimerGroup("Dwarf Exception and Debugging");
53 return DwarfTimerGroup;
58 //===----------------------------------------------------------------------===//
60 /// Configuration values for initial hash set sizes (log2).
62 static const unsigned InitDiesSetSize = 9; // log2(512)
63 static const unsigned InitAbbreviationsSetSize = 9; // log2(512)
64 static const unsigned InitValuesSetSize = 9; // log2(512)
66 //===----------------------------------------------------------------------===//
67 /// Forward declarations.
72 //===----------------------------------------------------------------------===//
73 /// DWLabel - Labels are used to track locations in the assembler file.
74 /// Labels appear in the form @verbatim <prefix><Tag><Number> @endverbatim,
75 /// where the tag is a category of label (Ex. location) and number is a value
76 /// unique in that category.
79 /// Tag - Label category tag. Should always be a staticly declared C string.
83 /// Number - Value to make label unique.
87 DWLabel(const char *T, unsigned N) : Tag(T), Number(N) {}
89 void Profile(FoldingSetNodeID &ID) const {
91 ID.AddInteger(Number);
95 void print(std::ostream *O) const {
98 void print(std::ostream &O) const {
100 if (Number) O << Number;
105 //===----------------------------------------------------------------------===//
106 /// DIEAbbrevData - Dwarf abbreviation data, describes the one attribute of a
107 /// Dwarf abbreviation.
108 class DIEAbbrevData {
109 /// Attribute - Dwarf attribute code.
113 /// Form - Dwarf form code.
117 DIEAbbrevData(unsigned A, unsigned F) : Attribute(A), Form(F) {}
120 unsigned getAttribute() const { return Attribute; }
121 unsigned getForm() const { return Form; }
123 /// Profile - Used to gather unique data for the abbreviation folding set.
125 void Profile(FoldingSetNodeID &ID)const {
126 ID.AddInteger(Attribute);
131 //===----------------------------------------------------------------------===//
132 /// DIEAbbrev - Dwarf abbreviation, describes the organization of a debug
133 /// information object.
134 class DIEAbbrev : public FoldingSetNode {
136 /// Tag - Dwarf tag code.
140 /// Unique number for node.
144 /// ChildrenFlag - Dwarf children flag.
146 unsigned ChildrenFlag;
148 /// Data - Raw data bytes for abbreviation.
150 SmallVector<DIEAbbrevData, 8> Data;
152 DIEAbbrev(unsigned T, unsigned C) : Tag(T), ChildrenFlag(C), Data() {}
153 virtual ~DIEAbbrev() {}
156 unsigned getTag() const { return Tag; }
157 unsigned getNumber() const { return Number; }
158 unsigned getChildrenFlag() const { return ChildrenFlag; }
159 const SmallVector<DIEAbbrevData, 8> &getData() const { return Data; }
160 void setTag(unsigned T) { Tag = T; }
161 void setChildrenFlag(unsigned CF) { ChildrenFlag = CF; }
162 void setNumber(unsigned N) { Number = N; }
164 /// AddAttribute - Adds another set of attribute information to the
166 void AddAttribute(unsigned Attribute, unsigned Form) {
167 Data.push_back(DIEAbbrevData(Attribute, Form));
170 /// AddFirstAttribute - Adds a set of attribute information to the front
171 /// of the abbreviation.
172 void AddFirstAttribute(unsigned Attribute, unsigned Form) {
173 Data.insert(Data.begin(), DIEAbbrevData(Attribute, Form));
176 /// Profile - Used to gather unique data for the abbreviation folding set.
178 void Profile(FoldingSetNodeID &ID) {
180 ID.AddInteger(ChildrenFlag);
182 // For each attribute description.
183 for (unsigned i = 0, N = Data.size(); i < N; ++i)
187 /// Emit - Print the abbreviation using the specified Dwarf writer.
189 void Emit(const DwarfDebug &DD) const;
192 void print(std::ostream *O) {
195 void print(std::ostream &O);
200 //===----------------------------------------------------------------------===//
201 /// DIE - A structured debug information entry. Has an abbreviation which
202 /// describes it's organization.
204 class DIE : public FoldingSetNode {
206 /// Abbrev - Buffer for constructing abbreviation.
210 /// Offset - Offset in debug info section.
214 /// Size - Size of instance + children.
220 std::vector<DIE *> Children;
222 /// Attributes values.
224 SmallVector<DIEValue*, 32> Values;
226 /// Abstract compile unit.
227 CompileUnit *AbstractCU;
229 explicit DIE(unsigned Tag)
230 : Abbrev(Tag, DW_CHILDREN_no), Offset(0), Size(0) {}
234 DIEAbbrev &getAbbrev() { return Abbrev; }
235 unsigned getAbbrevNumber() const {
236 return Abbrev.getNumber();
238 unsigned getTag() const { return Abbrev.getTag(); }
239 unsigned getOffset() const { return Offset; }
240 unsigned getSize() const { return Size; }
241 const std::vector<DIE *> &getChildren() const { return Children; }
242 SmallVector<DIEValue*, 32> &getValues() { return Values; }
243 CompileUnit *getAbstractCompileUnit() const { return AbstractCU; }
245 void setTag(unsigned Tag) { Abbrev.setTag(Tag); }
246 void setOffset(unsigned O) { Offset = O; }
247 void setSize(unsigned S) { Size = S; }
248 void setAbstractCompileUnit(CompileUnit *CU) { AbstractCU = CU; }
250 /// AddValue - Add a value and attributes to a DIE.
252 void AddValue(unsigned Attribute, unsigned Form, DIEValue *Value) {
253 Abbrev.AddAttribute(Attribute, Form);
254 Values.push_back(Value);
257 /// SiblingOffset - Return the offset of the debug information entry's
259 unsigned SiblingOffset() const { return Offset + Size; }
261 /// AddSiblingOffset - Add a sibling offset field to the front of the DIE.
263 void AddSiblingOffset();
265 /// AddChild - Add a child to the DIE.
267 void AddChild(DIE *Child) {
268 Abbrev.setChildrenFlag(DW_CHILDREN_yes);
269 Children.push_back(Child);
272 /// Detach - Detaches objects connected to it after copying.
278 /// Profile - Used to gather unique data for the value folding set.
280 void Profile(FoldingSetNodeID &ID) ;
283 void print(std::ostream *O, unsigned IncIndent = 0) {
284 if (O) print(*O, IncIndent);
286 void print(std::ostream &O, unsigned IncIndent = 0);
291 //===----------------------------------------------------------------------===//
292 /// DIEValue - A debug information entry value.
294 class DIEValue : public FoldingSetNode {
307 /// Type - Type of data stored in the value.
311 explicit DIEValue(unsigned T) : Type(T) {}
312 virtual ~DIEValue() {}
315 unsigned getType() const { return Type; }
317 // Implement isa/cast/dyncast.
318 static bool classof(const DIEValue *) { return true; }
320 /// EmitValue - Emit value via the Dwarf writer.
322 virtual void EmitValue(DwarfDebug &DD, unsigned Form) = 0;
324 /// SizeOf - Return the size of a value in bytes.
326 virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const = 0;
328 /// Profile - Used to gather unique data for the value folding set.
330 virtual void Profile(FoldingSetNodeID &ID) = 0;
333 void print(std::ostream *O) {
336 virtual void print(std::ostream &O) = 0;
341 //===----------------------------------------------------------------------===//
342 /// DWInteger - An integer value DIE.
344 class DIEInteger : public DIEValue {
349 explicit DIEInteger(uint64_t I) : DIEValue(isInteger), Integer(I) {}
351 // Implement isa/cast/dyncast.
352 static bool classof(const DIEInteger *) { return true; }
353 static bool classof(const DIEValue *I) { return I->Type == isInteger; }
355 /// BestForm - Choose the best form for integer.
357 static unsigned BestForm(bool IsSigned, uint64_t Integer) {
359 if ((char)Integer == (signed)Integer) return DW_FORM_data1;
360 if ((short)Integer == (signed)Integer) return DW_FORM_data2;
361 if ((int)Integer == (signed)Integer) return DW_FORM_data4;
363 if ((unsigned char)Integer == Integer) return DW_FORM_data1;
364 if ((unsigned short)Integer == Integer) return DW_FORM_data2;
365 if ((unsigned int)Integer == Integer) return DW_FORM_data4;
367 return DW_FORM_data8;
370 /// EmitValue - Emit integer of appropriate size.
372 virtual void EmitValue(DwarfDebug &DD, unsigned Form);
374 /// SizeOf - Determine size of integer value in bytes.
376 virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const;
378 /// Profile - Used to gather unique data for the value folding set.
380 static void Profile(FoldingSetNodeID &ID, unsigned Integer) {
381 ID.AddInteger(isInteger);
382 ID.AddInteger(Integer);
384 virtual void Profile(FoldingSetNodeID &ID) { Profile(ID, Integer); }
387 virtual void print(std::ostream &O) {
388 O << "Int: " << (int64_t)Integer
389 << " 0x" << std::hex << Integer << std::dec;
394 //===----------------------------------------------------------------------===//
395 /// DIEString - A string value DIE.
397 class DIEString : public DIEValue {
398 const std::string Str;
400 explicit DIEString(const std::string &S) : DIEValue(isString), Str(S) {}
402 // Implement isa/cast/dyncast.
403 static bool classof(const DIEString *) { return true; }
404 static bool classof(const DIEValue *S) { return S->Type == isString; }
406 /// EmitValue - Emit string value.
408 virtual void EmitValue(DwarfDebug &DD, unsigned Form);
410 /// SizeOf - Determine size of string value in bytes.
412 virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const {
413 return Str.size() + sizeof(char); // sizeof('\0');
416 /// Profile - Used to gather unique data for the value folding set.
418 static void Profile(FoldingSetNodeID &ID, const std::string &Str) {
419 ID.AddInteger(isString);
422 virtual void Profile(FoldingSetNodeID &ID) { Profile(ID, Str); }
425 virtual void print(std::ostream &O) {
426 O << "Str: \"" << Str << "\"";
431 //===----------------------------------------------------------------------===//
432 /// DIEDwarfLabel - A Dwarf internal label expression DIE.
434 class DIEDwarfLabel : public DIEValue {
437 explicit DIEDwarfLabel(const DWLabel &L) : DIEValue(isLabel), Label(L) {}
439 // Implement isa/cast/dyncast.
440 static bool classof(const DIEDwarfLabel *) { return true; }
441 static bool classof(const DIEValue *L) { return L->Type == isLabel; }
443 /// EmitValue - Emit label value.
445 virtual void EmitValue(DwarfDebug &DD, unsigned Form);
447 /// SizeOf - Determine size of label value in bytes.
449 virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const;
451 /// Profile - Used to gather unique data for the value folding set.
453 static void Profile(FoldingSetNodeID &ID, const DWLabel &Label) {
454 ID.AddInteger(isLabel);
457 virtual void Profile(FoldingSetNodeID &ID) { Profile(ID, Label); }
460 virtual void print(std::ostream &O) {
467 //===----------------------------------------------------------------------===//
468 /// DIEObjectLabel - A label to an object in code or data.
470 class DIEObjectLabel : public DIEValue {
471 const std::string Label;
473 explicit DIEObjectLabel(const std::string &L)
474 : DIEValue(isAsIsLabel), Label(L) {}
476 // Implement isa/cast/dyncast.
477 static bool classof(const DIEObjectLabel *) { return true; }
478 static bool classof(const DIEValue *L) { return L->Type == isAsIsLabel; }
480 /// EmitValue - Emit label value.
482 virtual void EmitValue(DwarfDebug &DD, unsigned Form);
484 /// SizeOf - Determine size of label value in bytes.
486 virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const;
488 /// Profile - Used to gather unique data for the value folding set.
490 static void Profile(FoldingSetNodeID &ID, const std::string &Label) {
491 ID.AddInteger(isAsIsLabel);
494 virtual void Profile(FoldingSetNodeID &ID) { Profile(ID, Label.c_str()); }
497 virtual void print(std::ostream &O) {
498 O << "Obj: " << Label;
503 //===----------------------------------------------------------------------===//
504 /// DIESectionOffset - A section offset DIE.
506 class DIESectionOffset : public DIEValue {
508 const DWLabel Section;
512 DIESectionOffset(const DWLabel &Lab, const DWLabel &Sec,
513 bool isEH = false, bool useSet = true)
514 : DIEValue(isSectionOffset), Label(Lab), Section(Sec),
515 IsEH(isEH), UseSet(useSet) {}
517 // Implement isa/cast/dyncast.
518 static bool classof(const DIESectionOffset *) { return true; }
519 static bool classof(const DIEValue *D) { return D->Type == isSectionOffset; }
521 /// EmitValue - Emit section offset.
523 virtual void EmitValue(DwarfDebug &DD, unsigned Form);
525 /// SizeOf - Determine size of section offset value in bytes.
527 virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const;
529 /// Profile - Used to gather unique data for the value folding set.
531 static void Profile(FoldingSetNodeID &ID, const DWLabel &Label,
532 const DWLabel &Section) {
533 ID.AddInteger(isSectionOffset);
536 // IsEH and UseSet are specific to the Label/Section that we will emit
537 // the offset for; so Label/Section are enough for uniqueness.
539 virtual void Profile(FoldingSetNodeID &ID) { Profile(ID, Label, Section); }
542 virtual void print(std::ostream &O) {
547 O << "-" << IsEH << "-" << UseSet;
552 //===----------------------------------------------------------------------===//
553 /// DIEDelta - A simple label difference DIE.
555 class DIEDelta : public DIEValue {
556 const DWLabel LabelHi;
557 const DWLabel LabelLo;
559 DIEDelta(const DWLabel &Hi, const DWLabel &Lo)
560 : DIEValue(isDelta), LabelHi(Hi), LabelLo(Lo) {}
562 // Implement isa/cast/dyncast.
563 static bool classof(const DIEDelta *) { return true; }
564 static bool classof(const DIEValue *D) { return D->Type == isDelta; }
566 /// EmitValue - Emit delta value.
568 virtual void EmitValue(DwarfDebug &DD, unsigned Form);
570 /// SizeOf - Determine size of delta value in bytes.
572 virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const;
574 /// Profile - Used to gather unique data for the value folding set.
576 static void Profile(FoldingSetNodeID &ID, const DWLabel &LabelHi,
577 const DWLabel &LabelLo) {
578 ID.AddInteger(isDelta);
582 virtual void Profile(FoldingSetNodeID &ID) { Profile(ID, LabelHi, LabelLo); }
585 virtual void print(std::ostream &O) {
594 //===----------------------------------------------------------------------===//
595 /// DIEntry - A pointer to another debug information entry. An instance of this
596 /// class can also be used as a proxy for a debug information entry not yet
597 /// defined (ie. types.)
598 class DIEntry : public DIEValue {
601 explicit DIEntry(DIE *E) : DIEValue(isEntry), Entry(E) {}
603 DIE *getEntry() const { return Entry; }
604 void setEntry(DIE *E) { Entry = E; }
606 // Implement isa/cast/dyncast.
607 static bool classof(const DIEntry *) { return true; }
608 static bool classof(const DIEValue *E) { return E->Type == isEntry; }
610 /// EmitValue - Emit debug information entry offset.
612 virtual void EmitValue(DwarfDebug &DD, unsigned Form);
614 /// SizeOf - Determine size of debug information entry in bytes.
616 virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const {
617 return sizeof(int32_t);
620 /// Profile - Used to gather unique data for the value folding set.
622 static void Profile(FoldingSetNodeID &ID, DIE *Entry) {
623 ID.AddInteger(isEntry);
624 ID.AddPointer(Entry);
626 virtual void Profile(FoldingSetNodeID &ID) {
627 ID.AddInteger(isEntry);
630 ID.AddPointer(Entry);
637 virtual void print(std::ostream &O) {
638 O << "Die: 0x" << std::hex << (intptr_t)Entry << std::dec;
643 //===----------------------------------------------------------------------===//
644 /// DIEBlock - A block of values. Primarily used for location expressions.
646 class DIEBlock : public DIEValue, public DIE {
647 unsigned Size; // Size in bytes excluding size header.
650 : DIEValue(isBlock), DIE(0), Size(0) {}
651 virtual ~DIEBlock() {}
653 // Implement isa/cast/dyncast.
654 static bool classof(const DIEBlock *) { return true; }
655 static bool classof(const DIEValue *E) { return E->Type == isBlock; }
657 /// ComputeSize - calculate the size of the block.
659 unsigned ComputeSize(DwarfDebug &DD);
661 /// BestForm - Choose the best form for data.
663 unsigned BestForm() const {
664 if ((unsigned char)Size == Size) return DW_FORM_block1;
665 if ((unsigned short)Size == Size) return DW_FORM_block2;
666 if ((unsigned int)Size == Size) return DW_FORM_block4;
667 return DW_FORM_block;
670 /// EmitValue - Emit block data.
672 virtual void EmitValue(DwarfDebug &DD, unsigned Form);
674 /// SizeOf - Determine size of block data in bytes.
676 virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const;
678 /// Profile - Used to gather unique data for the value folding set.
680 virtual void Profile(FoldingSetNodeID &ID) {
681 ID.AddInteger(isBlock);
686 virtual void print(std::ostream &O) {
693 //===----------------------------------------------------------------------===//
694 /// CompileUnit - This dwarf writer support class manages information associate
695 /// with a source file.
697 /// ID - File identifier for source.
701 /// Die - Compile unit debug information entry.
705 /// GVToDieMap - Tracks the mapping of unit level debug informaton
706 /// variables to debug information entries.
707 std::map<GlobalVariable *, DIE *> GVToDieMap;
709 /// GVToDIEntryMap - Tracks the mapping of unit level debug informaton
710 /// descriptors to debug information entries using a DIEntry proxy.
711 std::map<GlobalVariable *, DIEntry *> GVToDIEntryMap;
713 /// Globals - A map of globally visible named entities for this unit.
715 StringMap<DIE*> Globals;
717 /// DiesSet - Used to uniquely define dies within the compile unit.
719 FoldingSet<DIE> DiesSet;
721 CompileUnit(unsigned I, DIE *D)
722 : ID(I), Die(D), GVToDieMap(),
723 GVToDIEntryMap(), Globals(), DiesSet(InitDiesSetSize)
731 unsigned getID() const { return ID; }
732 DIE* getDie() const { return Die; }
733 StringMap<DIE*> &getGlobals() { return Globals; }
735 /// hasContent - Return true if this compile unit has something to write out.
737 bool hasContent() const {
738 return !Die->getChildren().empty();
741 /// AddGlobal - Add a new global entity to the compile unit.
743 void AddGlobal(const std::string &Name, DIE *Die) {
747 /// getDieMapSlotFor - Returns the debug information entry map slot for the
748 /// specified debug variable.
749 DIE *&getDieMapSlotFor(GlobalVariable *GV) {
750 return GVToDieMap[GV];
753 /// getDIEntrySlotFor - Returns the debug information entry proxy slot for the
754 /// specified debug variable.
755 DIEntry *&getDIEntrySlotFor(GlobalVariable *GV) {
756 return GVToDIEntryMap[GV];
759 /// AddDie - Adds or interns the DIE to the compile unit.
761 DIE *AddDie(DIE &Buffer) {
765 DIE *Die = DiesSet.FindNodeOrInsertPos(ID, Where);
768 Die = new DIE(Buffer);
769 DiesSet.InsertNode(Die, Where);
770 this->Die->AddChild(Die);
778 //===----------------------------------------------------------------------===//
779 /// Dwarf - Emits general Dwarf directives.
783 //===--------------------------------------------------------------------===//
784 // Core attributes used by the Dwarf writer.
788 /// O - Stream to .s file.
792 /// Asm - Target of Dwarf emission.
796 /// TAI - Target asm information.
797 const TargetAsmInfo *TAI;
799 /// TD - Target data.
800 const TargetData *TD;
802 /// RI - Register Information.
803 const TargetRegisterInfo *RI;
805 /// M - Current module.
809 /// MF - Current machine function.
813 /// MMI - Collected machine module information.
815 MachineModuleInfo *MMI;
817 /// SubprogramCount - The running count of functions being compiled.
819 unsigned SubprogramCount;
821 /// Flavor - A unique string indicating what dwarf producer this is, used to
823 const char * const Flavor;
826 Dwarf(raw_ostream &OS, AsmPrinter *A, const TargetAsmInfo *T,
831 , TD(Asm->TM.getTargetData())
832 , RI(Asm->TM.getRegisterInfo())
843 //===--------------------------------------------------------------------===//
846 const AsmPrinter *getAsm() const { return Asm; }
847 MachineModuleInfo *getMMI() const { return MMI; }
848 const TargetAsmInfo *getTargetAsmInfo() const { return TAI; }
849 const TargetData *getTargetData() const { return TD; }
851 void PrintRelDirective(bool Force32Bit = false, bool isInSection = false)
853 if (isInSection && TAI->getDwarfSectionOffsetDirective())
854 O << TAI->getDwarfSectionOffsetDirective();
855 else if (Force32Bit || TD->getPointerSize() == sizeof(int32_t))
856 O << TAI->getData32bitsDirective();
858 O << TAI->getData64bitsDirective();
861 /// PrintLabelName - Print label name in form used by Dwarf writer.
863 void PrintLabelName(DWLabel Label) const {
864 PrintLabelName(Label.Tag, Label.Number);
866 void PrintLabelName(const char *Tag, unsigned Number) const {
867 O << TAI->getPrivateGlobalPrefix() << Tag;
868 if (Number) O << Number;
871 void PrintLabelName(const char *Tag, unsigned Number,
872 const char *Suffix) const {
873 O << TAI->getPrivateGlobalPrefix() << Tag;
874 if (Number) O << Number;
878 /// EmitLabel - Emit location label for internal use by Dwarf.
880 void EmitLabel(DWLabel Label) const {
881 EmitLabel(Label.Tag, Label.Number);
883 void EmitLabel(const char *Tag, unsigned Number) const {
884 PrintLabelName(Tag, Number);
888 /// EmitReference - Emit a reference to a label.
890 void EmitReference(DWLabel Label, bool IsPCRelative = false,
891 bool Force32Bit = false) const {
892 EmitReference(Label.Tag, Label.Number, IsPCRelative, Force32Bit);
894 void EmitReference(const char *Tag, unsigned Number,
895 bool IsPCRelative = false, bool Force32Bit = false) const {
896 PrintRelDirective(Force32Bit);
897 PrintLabelName(Tag, Number);
899 if (IsPCRelative) O << "-" << TAI->getPCSymbol();
901 void EmitReference(const std::string &Name, bool IsPCRelative = false,
902 bool Force32Bit = false) const {
903 PrintRelDirective(Force32Bit);
907 if (IsPCRelative) O << "-" << TAI->getPCSymbol();
910 /// EmitDifference - Emit the difference between two labels. Some
911 /// assemblers do not behave with absolute expressions with data directives,
912 /// so there is an option (needsSet) to use an intermediary set expression.
913 void EmitDifference(DWLabel LabelHi, DWLabel LabelLo,
914 bool IsSmall = false) {
915 EmitDifference(LabelHi.Tag, LabelHi.Number,
916 LabelLo.Tag, LabelLo.Number,
919 void EmitDifference(const char *TagHi, unsigned NumberHi,
920 const char *TagLo, unsigned NumberLo,
921 bool IsSmall = false) {
922 if (TAI->needsSet()) {
924 PrintLabelName("set", SetCounter, Flavor);
926 PrintLabelName(TagHi, NumberHi);
928 PrintLabelName(TagLo, NumberLo);
931 PrintRelDirective(IsSmall);
932 PrintLabelName("set", SetCounter, Flavor);
935 PrintRelDirective(IsSmall);
937 PrintLabelName(TagHi, NumberHi);
939 PrintLabelName(TagLo, NumberLo);
943 void EmitSectionOffset(const char* Label, const char* Section,
944 unsigned LabelNumber, unsigned SectionNumber,
945 bool IsSmall = false, bool isEH = false,
946 bool useSet = true) {
947 bool printAbsolute = false;
949 printAbsolute = TAI->isAbsoluteEHSectionOffsets();
951 printAbsolute = TAI->isAbsoluteDebugSectionOffsets();
953 if (TAI->needsSet() && useSet) {
955 PrintLabelName("set", SetCounter, Flavor);
957 PrintLabelName(Label, LabelNumber);
959 if (!printAbsolute) {
961 PrintLabelName(Section, SectionNumber);
965 PrintRelDirective(IsSmall);
967 PrintLabelName("set", SetCounter, Flavor);
970 PrintRelDirective(IsSmall, true);
972 PrintLabelName(Label, LabelNumber);
974 if (!printAbsolute) {
976 PrintLabelName(Section, SectionNumber);
981 /// EmitFrameMoves - Emit frame instructions to describe the layout of the
983 void EmitFrameMoves(const char *BaseLabel, unsigned BaseLabelID,
984 const std::vector<MachineMove> &Moves, bool isEH) {
986 Asm->TM.getFrameInfo()->getStackGrowthDirection() ==
987 TargetFrameInfo::StackGrowsUp ?
988 TD->getPointerSize() : -TD->getPointerSize();
989 bool IsLocal = BaseLabel && strcmp(BaseLabel, "label") == 0;
991 for (unsigned i = 0, N = Moves.size(); i < N; ++i) {
992 const MachineMove &Move = Moves[i];
993 unsigned LabelID = Move.getLabelID();
996 LabelID = MMI->MappedLabel(LabelID);
998 // Throw out move if the label is invalid.
999 if (!LabelID) continue;
1002 const MachineLocation &Dst = Move.getDestination();
1003 const MachineLocation &Src = Move.getSource();
1005 // Advance row if new location.
1006 if (BaseLabel && LabelID && (BaseLabelID != LabelID || !IsLocal)) {
1007 Asm->EmitInt8(DW_CFA_advance_loc4);
1008 Asm->EOL("DW_CFA_advance_loc4");
1009 EmitDifference("label", LabelID, BaseLabel, BaseLabelID, true);
1012 BaseLabelID = LabelID;
1013 BaseLabel = "label";
1017 // If advancing cfa.
1018 if (Dst.isReg() && Dst.getReg() == MachineLocation::VirtualFP) {
1020 if (Src.getReg() == MachineLocation::VirtualFP) {
1021 Asm->EmitInt8(DW_CFA_def_cfa_offset);
1022 Asm->EOL("DW_CFA_def_cfa_offset");
1024 Asm->EmitInt8(DW_CFA_def_cfa);
1025 Asm->EOL("DW_CFA_def_cfa");
1026 Asm->EmitULEB128Bytes(RI->getDwarfRegNum(Src.getReg(), isEH));
1027 Asm->EOL("Register");
1030 int Offset = -Src.getOffset();
1032 Asm->EmitULEB128Bytes(Offset);
1035 assert(0 && "Machine move no supported yet.");
1037 } else if (Src.isReg() &&
1038 Src.getReg() == MachineLocation::VirtualFP) {
1040 Asm->EmitInt8(DW_CFA_def_cfa_register);
1041 Asm->EOL("DW_CFA_def_cfa_register");
1042 Asm->EmitULEB128Bytes(RI->getDwarfRegNum(Dst.getReg(), isEH));
1043 Asm->EOL("Register");
1045 assert(0 && "Machine move no supported yet.");
1048 unsigned Reg = RI->getDwarfRegNum(Src.getReg(), isEH);
1049 int Offset = Dst.getOffset() / stackGrowth;
1052 Asm->EmitInt8(DW_CFA_offset_extended_sf);
1053 Asm->EOL("DW_CFA_offset_extended_sf");
1054 Asm->EmitULEB128Bytes(Reg);
1056 Asm->EmitSLEB128Bytes(Offset);
1058 } else if (Reg < 64) {
1059 Asm->EmitInt8(DW_CFA_offset + Reg);
1060 if (Asm->isVerbose())
1061 Asm->EOL("DW_CFA_offset + Reg (" + utostr(Reg) + ")");
1064 Asm->EmitULEB128Bytes(Offset);
1067 Asm->EmitInt8(DW_CFA_offset_extended);
1068 Asm->EOL("DW_CFA_offset_extended");
1069 Asm->EmitULEB128Bytes(Reg);
1071 Asm->EmitULEB128Bytes(Offset);
1080 //===----------------------------------------------------------------------===//
1081 /// SrcLineInfo - This class is used to record source line correspondence.
1084 unsigned Line; // Source line number.
1085 unsigned Column; // Source column.
1086 unsigned SourceID; // Source ID number.
1087 unsigned LabelID; // Label in code ID number.
1089 SrcLineInfo(unsigned L, unsigned C, unsigned S, unsigned I)
1090 : Line(L), Column(C), SourceID(S), LabelID(I) {}
1093 unsigned getLine() const { return Line; }
1094 unsigned getColumn() const { return Column; }
1095 unsigned getSourceID() const { return SourceID; }
1096 unsigned getLabelID() const { return LabelID; }
1099 //===----------------------------------------------------------------------===//
1100 /// DbgVariable - This class is used to track local variable information.
1103 DIVariable Var; // Variable Descriptor.
1104 unsigned FrameIndex; // Variable frame index.
1106 DbgVariable(DIVariable V, unsigned I) : Var(V), FrameIndex(I) {}
1109 DIVariable getVariable() const { return Var; }
1110 unsigned getFrameIndex() const { return FrameIndex; }
1113 //===----------------------------------------------------------------------===//
1114 /// DbgScope - This class is used to track scope information.
1116 class DbgConcreteScope;
1118 DbgScope *Parent; // Parent to this scope.
1119 DIDescriptor Desc; // Debug info descriptor for scope.
1120 // Either subprogram or block.
1121 unsigned StartLabelID; // Label ID of the beginning of scope.
1122 unsigned EndLabelID; // Label ID of the end of scope.
1123 SmallVector<DbgScope *, 4> Scopes; // Scopes defined in scope.
1124 SmallVector<DbgVariable *, 8> Variables;// Variables declared in scope.
1125 SmallVector<DbgConcreteScope *, 8> ConcreteInsts;// Concrete insts of funcs.
1127 DbgScope(DbgScope *P, DIDescriptor D)
1128 : Parent(P), Desc(D), StartLabelID(0), EndLabelID(0) {}
1129 virtual ~DbgScope();
1132 DbgScope *getParent() const { return Parent; }
1133 DIDescriptor getDesc() const { return Desc; }
1134 unsigned getStartLabelID() const { return StartLabelID; }
1135 unsigned getEndLabelID() const { return EndLabelID; }
1136 SmallVector<DbgScope *, 4> &getScopes() { return Scopes; }
1137 SmallVector<DbgVariable *, 8> &getVariables() { return Variables; }
1138 SmallVector<DbgConcreteScope*,8> &getConcreteInsts() { return ConcreteInsts; }
1139 void setStartLabelID(unsigned S) { StartLabelID = S; }
1140 void setEndLabelID(unsigned E) { EndLabelID = E; }
1142 /// AddScope - Add a scope to the scope.
1144 void AddScope(DbgScope *S) { Scopes.push_back(S); }
1146 /// AddVariable - Add a variable to the scope.
1148 void AddVariable(DbgVariable *V) { Variables.push_back(V); }
1150 /// AddConcreteInst - Add a concrete instance to the scope.
1152 void AddConcreteInst(DbgConcreteScope *C) { ConcreteInsts.push_back(C); }
1160 void DbgScope::dump() const {
1161 static unsigned IndentLevel = 0;
1162 std::string Indent(IndentLevel, ' ');
1164 cerr << Indent; Desc.dump();
1165 cerr << " [" << StartLabelID << ", " << EndLabelID << "]\n";
1169 for (unsigned i = 0, e = Scopes.size(); i != e; ++i)
1170 if (Scopes[i] != this)
1177 //===----------------------------------------------------------------------===//
1178 /// DbgConcreteScope - This class is used to track a scope that holds concrete
1179 /// instance information.
1181 class DbgConcreteScope : public DbgScope {
1183 DIE *Die; // Debug info for this concrete scope.
1185 DbgConcreteScope(DIDescriptor D) : DbgScope(NULL, D) {}
1188 DIE *getDie() const { return Die; }
1189 void setDie(DIE *D) { Die = D; }
1192 DbgScope::~DbgScope() {
1193 for (unsigned i = 0, N = Scopes.size(); i < N; ++i)
1195 for (unsigned j = 0, M = Variables.size(); j < M; ++j)
1196 delete Variables[j];
1197 for (unsigned k = 0, O = ConcreteInsts.size(); k < O; ++k)
1198 delete ConcreteInsts[k];
1201 //===----------------------------------------------------------------------===//
1202 /// DwarfDebug - Emits Dwarf debug directives.
1204 class DwarfDebug : public Dwarf {
1205 //===--------------------------------------------------------------------===//
1206 // Attributes used to construct specific Dwarf sections.
1209 /// CompileUnitMap - A map of global variables representing compile units to
1211 DenseMap<Value *, CompileUnit *> CompileUnitMap;
1213 /// CompileUnits - All the compile units in this module.
1215 SmallVector<CompileUnit *, 8> CompileUnits;
1217 /// MainCU - Some platform prefers one compile unit per .o file. In such
1218 /// cases, all dies are inserted in MainCU.
1219 CompileUnit *MainCU;
1221 /// AbbreviationsSet - Used to uniquely define abbreviations.
1223 FoldingSet<DIEAbbrev> AbbreviationsSet;
1225 /// Abbreviations - A list of all the unique abbreviations in use.
1227 std::vector<DIEAbbrev *> Abbreviations;
1229 /// DirectoryIdMap - Directory name to directory id map.
1231 StringMap<unsigned> DirectoryIdMap;
1233 /// DirectoryNames - A list of directory names.
1234 SmallVector<std::string, 8> DirectoryNames;
1236 /// SourceFileIdMap - Source file name to source file id map.
1238 StringMap<unsigned> SourceFileIdMap;
1240 /// SourceFileNames - A list of source file names.
1241 SmallVector<std::string, 8> SourceFileNames;
1243 /// SourceIdMap - Source id map, i.e. pair of directory id and source file
1244 /// id mapped to a unique id.
1245 DenseMap<std::pair<unsigned, unsigned>, unsigned> SourceIdMap;
1247 /// SourceIds - Reverse map from source id to directory id + file id pair.
1249 SmallVector<std::pair<unsigned, unsigned>, 8> SourceIds;
1251 /// Lines - List of of source line correspondence.
1252 std::vector<SrcLineInfo> Lines;
1254 /// ValuesSet - Used to uniquely define values.
1256 FoldingSet<DIEValue> ValuesSet;
1258 /// Values - A list of all the unique values in use.
1260 std::vector<DIEValue *> Values;
1262 /// StringPool - A UniqueVector of strings used by indirect references.
1264 UniqueVector<std::string> StringPool;
1266 /// SectionMap - Provides a unique id per text section.
1268 UniqueVector<const Section*> SectionMap;
1270 /// SectionSourceLines - Tracks line numbers per text section.
1272 std::vector<std::vector<SrcLineInfo> > SectionSourceLines;
1274 /// didInitial - Flag to indicate if initial emission has been done.
1278 /// shouldEmit - Flag to indicate if debug information should be emitted.
1282 // FunctionDbgScope - Top level scope for the current function.
1284 DbgScope *FunctionDbgScope;
1286 /// DbgScopeMap - Tracks the scopes in the current function.
1287 DenseMap<GlobalVariable *, DbgScope *> DbgScopeMap;
1289 /// DbgConcreteScopeMap - Tracks inlined scopes in the current function.
1290 DenseMap<GlobalVariable *,
1291 SmallVector<DbgConcreteScope *, 8> > DbgConcreteScopeMap;
1293 /// InlineInfo - Keep track of inlined functions and their location. This
1294 /// information is used to populate debug_inlined section.
1295 DenseMap<GlobalVariable *, SmallVector<unsigned, 4> > InlineInfo;
1297 /// InlinedVariableScopes - Scopes information for the inlined subroutine
1299 DenseMap<const MachineInstr *, DbgScope *> InlinedVariableScopes;
1301 /// AbstractInstanceRootMap - Map of abstract instance roots of inlined
1302 /// functions. These are subroutine entries that contain a DW_AT_inline
1304 DenseMap<const GlobalVariable *, DbgScope *> AbstractInstanceRootMap;
1306 /// AbstractInstanceRootList - List of abstract instance roots of inlined
1307 /// functions. These are subroutine entries that contain a DW_AT_inline
1309 SmallVector<DbgScope *, 32> AbstractInstanceRootList;
1311 /// LexicalScopeStack - A stack of lexical scopes. The top one is the current
1313 SmallVector<DbgScope *, 16> LexicalScopeStack;
1315 /// CompileUnitOffsets - A vector of the offsets of the compile units. This is
1316 /// used when calculating the "origin" of a concrete instance of an inlined
1318 DenseMap<CompileUnit *, unsigned> CompileUnitOffsets;
1320 /// DebugTimer - Timer for the Dwarf debug writer.
1323 struct FunctionDebugFrameInfo {
1325 std::vector<MachineMove> Moves;
1327 FunctionDebugFrameInfo(unsigned Num, const std::vector<MachineMove> &M):
1328 Number(Num), Moves(M) { }
1331 std::vector<FunctionDebugFrameInfo> DebugFrames;
1334 /// getSourceDirectoryAndFileIds - Return the directory and file ids that
1335 /// maps to the source id. Source id starts at 1.
1336 std::pair<unsigned, unsigned>
1337 getSourceDirectoryAndFileIds(unsigned SId) const {
1338 return SourceIds[SId-1];
1341 /// getNumSourceDirectories - Return the number of source directories in the
1343 unsigned getNumSourceDirectories() const {
1344 return DirectoryNames.size();
1347 /// getSourceDirectoryName - Return the name of the directory corresponding
1349 const std::string &getSourceDirectoryName(unsigned Id) const {
1350 return DirectoryNames[Id - 1];
1353 /// getSourceFileName - Return the name of the source file corresponding
1355 const std::string &getSourceFileName(unsigned Id) const {
1356 return SourceFileNames[Id - 1];
1359 /// getNumSourceIds - Return the number of unique source ids.
1360 unsigned getNumSourceIds() const {
1361 return SourceIds.size();
1364 /// AssignAbbrevNumber - Define a unique number for the abbreviation.
1366 void AssignAbbrevNumber(DIEAbbrev &Abbrev) {
1367 // Profile the node so that we can make it unique.
1368 FoldingSetNodeID ID;
1371 // Check the set for priors.
1372 DIEAbbrev *InSet = AbbreviationsSet.GetOrInsertNode(&Abbrev);
1374 // If it's newly added.
1375 if (InSet == &Abbrev) {
1376 // Add to abbreviation list.
1377 Abbreviations.push_back(&Abbrev);
1378 // Assign the vector position + 1 as its number.
1379 Abbrev.setNumber(Abbreviations.size());
1381 // Assign existing abbreviation number.
1382 Abbrev.setNumber(InSet->getNumber());
1386 /// NewString - Add a string to the constant pool and returns a label.
1388 DWLabel NewString(const std::string &String) {
1389 unsigned StringID = StringPool.insert(String);
1390 return DWLabel("string", StringID);
1393 /// NewDIEntry - Creates a new DIEntry to be a proxy for a debug information
1395 DIEntry *NewDIEntry(DIE *Entry = NULL) {
1399 FoldingSetNodeID ID;
1400 DIEntry::Profile(ID, Entry);
1402 Value = static_cast<DIEntry *>(ValuesSet.FindNodeOrInsertPos(ID, Where));
1404 if (Value) return Value;
1406 Value = new DIEntry(Entry);
1407 ValuesSet.InsertNode(Value, Where);
1409 Value = new DIEntry(Entry);
1412 Values.push_back(Value);
1416 /// SetDIEntry - Set a DIEntry once the debug information entry is defined.
1418 void SetDIEntry(DIEntry *Value, DIE *Entry) {
1419 Value->setEntry(Entry);
1420 // Add to values set if not already there. If it is, we merely have a
1421 // duplicate in the values list (no harm.)
1422 ValuesSet.GetOrInsertNode(Value);
1425 /// AddUInt - Add an unsigned integer attribute data and value.
1427 void AddUInt(DIE *Die, unsigned Attribute, unsigned Form, uint64_t Integer) {
1428 if (!Form) Form = DIEInteger::BestForm(false, Integer);
1430 FoldingSetNodeID ID;
1431 DIEInteger::Profile(ID, Integer);
1433 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
1435 Value = new DIEInteger(Integer);
1436 ValuesSet.InsertNode(Value, Where);
1437 Values.push_back(Value);
1440 Die->AddValue(Attribute, Form, Value);
1443 /// AddSInt - Add an signed integer attribute data and value.
1445 void AddSInt(DIE *Die, unsigned Attribute, unsigned Form, int64_t Integer) {
1446 if (!Form) Form = DIEInteger::BestForm(true, Integer);
1448 FoldingSetNodeID ID;
1449 DIEInteger::Profile(ID, (uint64_t)Integer);
1451 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
1453 Value = new DIEInteger(Integer);
1454 ValuesSet.InsertNode(Value, Where);
1455 Values.push_back(Value);
1458 Die->AddValue(Attribute, Form, Value);
1461 /// AddString - Add a string attribute data and value.
1463 void AddString(DIE *Die, unsigned Attribute, unsigned Form,
1464 const std::string &String) {
1465 FoldingSetNodeID ID;
1466 DIEString::Profile(ID, String);
1468 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
1470 Value = new DIEString(String);
1471 ValuesSet.InsertNode(Value, Where);
1472 Values.push_back(Value);
1475 Die->AddValue(Attribute, Form, Value);
1478 /// AddLabel - Add a Dwarf label attribute data and value.
1480 void AddLabel(DIE *Die, unsigned Attribute, unsigned Form,
1481 const DWLabel &Label) {
1482 FoldingSetNodeID ID;
1483 DIEDwarfLabel::Profile(ID, Label);
1485 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
1487 Value = new DIEDwarfLabel(Label);
1488 ValuesSet.InsertNode(Value, Where);
1489 Values.push_back(Value);
1492 Die->AddValue(Attribute, Form, Value);
1495 /// AddObjectLabel - Add an non-Dwarf label attribute data and value.
1497 void AddObjectLabel(DIE *Die, unsigned Attribute, unsigned Form,
1498 const std::string &Label) {
1499 FoldingSetNodeID ID;
1500 DIEObjectLabel::Profile(ID, Label);
1502 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
1504 Value = new DIEObjectLabel(Label);
1505 ValuesSet.InsertNode(Value, Where);
1506 Values.push_back(Value);
1509 Die->AddValue(Attribute, Form, Value);
1512 /// AddSectionOffset - Add a section offset label attribute data and value.
1514 void AddSectionOffset(DIE *Die, unsigned Attribute, unsigned Form,
1515 const DWLabel &Label, const DWLabel &Section,
1516 bool isEH = false, bool useSet = true) {
1517 FoldingSetNodeID ID;
1518 DIESectionOffset::Profile(ID, Label, Section);
1520 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
1522 Value = new DIESectionOffset(Label, Section, isEH, useSet);
1523 ValuesSet.InsertNode(Value, Where);
1524 Values.push_back(Value);
1527 Die->AddValue(Attribute, Form, Value);
1530 /// AddDelta - Add a label delta attribute data and value.
1532 void AddDelta(DIE *Die, unsigned Attribute, unsigned Form,
1533 const DWLabel &Hi, const DWLabel &Lo) {
1534 FoldingSetNodeID ID;
1535 DIEDelta::Profile(ID, Hi, Lo);
1537 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
1539 Value = new DIEDelta(Hi, Lo);
1540 ValuesSet.InsertNode(Value, Where);
1541 Values.push_back(Value);
1544 Die->AddValue(Attribute, Form, Value);
1547 /// AddDIEntry - Add a DIE attribute data and value.
1549 void AddDIEntry(DIE *Die, unsigned Attribute, unsigned Form, DIE *Entry) {
1550 Die->AddValue(Attribute, Form, NewDIEntry(Entry));
1553 /// AddBlock - Add block data.
1555 void AddBlock(DIE *Die, unsigned Attribute, unsigned Form, DIEBlock *Block) {
1556 Block->ComputeSize(*this);
1557 FoldingSetNodeID ID;
1560 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
1563 ValuesSet.InsertNode(Value, Where);
1564 Values.push_back(Value);
1566 // Already exists, reuse the previous one.
1568 Block = cast<DIEBlock>(Value);
1571 Die->AddValue(Attribute, Block->BestForm(), Value);
1574 /// AddSourceLine - Add location information to specified debug information
1576 void AddSourceLine(DIE *Die, const DIVariable *V) {
1577 // If there is no compile unit specified, don't add a line #.
1578 if (V->getCompileUnit().isNull())
1581 unsigned Line = V->getLineNumber();
1582 unsigned FileID = FindCompileUnit(V->getCompileUnit()).getID();
1583 assert(FileID && "Invalid file id");
1584 AddUInt(Die, DW_AT_decl_file, 0, FileID);
1585 AddUInt(Die, DW_AT_decl_line, 0, Line);
1588 /// AddSourceLine - Add location information to specified debug information
1590 void AddSourceLine(DIE *Die, const DIGlobal *G) {
1591 // If there is no compile unit specified, don't add a line #.
1592 if (G->getCompileUnit().isNull())
1594 unsigned Line = G->getLineNumber();
1595 unsigned FileID = FindCompileUnit(G->getCompileUnit()).getID();
1596 assert(FileID && "Invalid file id");
1597 AddUInt(Die, DW_AT_decl_file, 0, FileID);
1598 AddUInt(Die, DW_AT_decl_line, 0, Line);
1601 void AddSourceLine(DIE *Die, const DIType *Ty) {
1602 // If there is no compile unit specified, don't add a line #.
1603 DICompileUnit CU = Ty->getCompileUnit();
1607 unsigned Line = Ty->getLineNumber();
1608 unsigned FileID = FindCompileUnit(CU).getID();
1609 assert(FileID && "Invalid file id");
1610 AddUInt(Die, DW_AT_decl_file, 0, FileID);
1611 AddUInt(Die, DW_AT_decl_line, 0, Line);
1614 /// AddAddress - Add an address attribute to a die based on the location
1616 void AddAddress(DIE *Die, unsigned Attribute,
1617 const MachineLocation &Location) {
1618 unsigned Reg = RI->getDwarfRegNum(Location.getReg(), false);
1619 DIEBlock *Block = new DIEBlock();
1621 if (Location.isReg()) {
1623 AddUInt(Block, 0, DW_FORM_data1, DW_OP_reg0 + Reg);
1625 AddUInt(Block, 0, DW_FORM_data1, DW_OP_regx);
1626 AddUInt(Block, 0, DW_FORM_udata, Reg);
1630 AddUInt(Block, 0, DW_FORM_data1, DW_OP_breg0 + Reg);
1632 AddUInt(Block, 0, DW_FORM_data1, DW_OP_bregx);
1633 AddUInt(Block, 0, DW_FORM_udata, Reg);
1635 AddUInt(Block, 0, DW_FORM_sdata, Location.getOffset());
1638 AddBlock(Die, Attribute, 0, Block);
1641 /// AddType - Add a new type attribute to the specified entity.
1642 void AddType(CompileUnit *DW_Unit, DIE *Entity, DIType Ty) {
1646 // Check for pre-existence.
1647 DIEntry *&Slot = DW_Unit->getDIEntrySlotFor(Ty.getGV());
1648 // If it exists then use the existing value.
1650 Entity->AddValue(DW_AT_type, DW_FORM_ref4, Slot);
1655 Slot = NewDIEntry();
1658 DIE Buffer(DW_TAG_base_type);
1659 if (Ty.isBasicType(Ty.getTag()))
1660 ConstructTypeDIE(DW_Unit, Buffer, DIBasicType(Ty.getGV()));
1661 else if (Ty.isDerivedType(Ty.getTag()))
1662 ConstructTypeDIE(DW_Unit, Buffer, DIDerivedType(Ty.getGV()));
1664 assert(Ty.isCompositeType(Ty.getTag()) && "Unknown kind of DIType");
1665 ConstructTypeDIE(DW_Unit, Buffer, DICompositeType(Ty.getGV()));
1668 // Add debug information entry to entity and appropriate context.
1670 DIDescriptor Context = Ty.getContext();
1671 if (!Context.isNull())
1672 Die = DW_Unit->getDieMapSlotFor(Context.getGV());
1675 DIE *Child = new DIE(Buffer);
1676 Die->AddChild(Child);
1678 SetDIEntry(Slot, Child);
1680 Die = DW_Unit->AddDie(Buffer);
1681 SetDIEntry(Slot, Die);
1684 Entity->AddValue(DW_AT_type, DW_FORM_ref4, Slot);
1687 /// ConstructTypeDIE - Construct basic type die from DIBasicType.
1688 void ConstructTypeDIE(CompileUnit *DW_Unit, DIE &Buffer,
1691 // Get core information.
1694 Buffer.setTag(DW_TAG_base_type);
1695 AddUInt(&Buffer, DW_AT_encoding, DW_FORM_data1, BTy.getEncoding());
1696 // Add name if not anonymous or intermediate type.
1698 AddString(&Buffer, DW_AT_name, DW_FORM_string, Name);
1699 uint64_t Size = BTy.getSizeInBits() >> 3;
1700 AddUInt(&Buffer, DW_AT_byte_size, 0, Size);
1703 /// ConstructTypeDIE - Construct derived type die from DIDerivedType.
1704 void ConstructTypeDIE(CompileUnit *DW_Unit, DIE &Buffer,
1705 DIDerivedType DTy) {
1707 // Get core information.
1710 uint64_t Size = DTy.getSizeInBits() >> 3;
1711 unsigned Tag = DTy.getTag();
1713 // FIXME - Workaround for templates.
1714 if (Tag == DW_TAG_inheritance) Tag = DW_TAG_reference_type;
1718 // Map to main type, void will not have a type.
1719 DIType FromTy = DTy.getTypeDerivedFrom();
1720 AddType(DW_Unit, &Buffer, FromTy);
1722 // Add name if not anonymous or intermediate type.
1724 AddString(&Buffer, DW_AT_name, DW_FORM_string, Name);
1726 // Add size if non-zero (derived types might be zero-sized.)
1728 AddUInt(&Buffer, DW_AT_byte_size, 0, Size);
1730 // Add source line info if available and TyDesc is not a forward
1732 if (!DTy.isForwardDecl())
1733 AddSourceLine(&Buffer, &DTy);
1736 /// ConstructTypeDIE - Construct type DIE from DICompositeType.
1737 void ConstructTypeDIE(CompileUnit *DW_Unit, DIE &Buffer,
1738 DICompositeType CTy) {
1739 // Get core information.
1743 uint64_t Size = CTy.getSizeInBits() >> 3;
1744 unsigned Tag = CTy.getTag();
1748 case DW_TAG_vector_type:
1749 case DW_TAG_array_type:
1750 ConstructArrayTypeDIE(DW_Unit, Buffer, &CTy);
1752 case DW_TAG_enumeration_type:
1754 DIArray Elements = CTy.getTypeArray();
1755 // Add enumerators to enumeration type.
1756 for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
1757 DIE *ElemDie = NULL;
1758 DIEnumerator Enum(Elements.getElement(i).getGV());
1759 ElemDie = ConstructEnumTypeDIE(DW_Unit, &Enum);
1760 Buffer.AddChild(ElemDie);
1764 case DW_TAG_subroutine_type:
1767 DIArray Elements = CTy.getTypeArray();
1768 DIDescriptor RTy = Elements.getElement(0);
1769 AddType(DW_Unit, &Buffer, DIType(RTy.getGV()));
1771 // Add prototype flag.
1772 AddUInt(&Buffer, DW_AT_prototyped, DW_FORM_flag, 1);
1775 for (unsigned i = 1, N = Elements.getNumElements(); i < N; ++i) {
1776 DIE *Arg = new DIE(DW_TAG_formal_parameter);
1777 DIDescriptor Ty = Elements.getElement(i);
1778 AddType(DW_Unit, Arg, DIType(Ty.getGV()));
1779 Buffer.AddChild(Arg);
1783 case DW_TAG_structure_type:
1784 case DW_TAG_union_type:
1785 case DW_TAG_class_type:
1787 // Add elements to structure type.
1788 DIArray Elements = CTy.getTypeArray();
1790 // A forward struct declared type may not have elements available.
1791 if (Elements.isNull())
1794 // Add elements to structure type.
1795 for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
1796 DIDescriptor Element = Elements.getElement(i);
1797 DIE *ElemDie = NULL;
1798 if (Element.getTag() == dwarf::DW_TAG_subprogram)
1799 ElemDie = CreateSubprogramDIE(DW_Unit,
1800 DISubprogram(Element.getGV()));
1801 else if (Element.getTag() == dwarf::DW_TAG_variable) // ??
1802 ElemDie = CreateGlobalVariableDIE(DW_Unit,
1803 DIGlobalVariable(Element.getGV()));
1805 ElemDie = CreateMemberDIE(DW_Unit,
1806 DIDerivedType(Element.getGV()));
1807 Buffer.AddChild(ElemDie);
1809 unsigned RLang = CTy.getRunTimeLang();
1811 AddUInt(&Buffer, DW_AT_APPLE_runtime_class, DW_FORM_data1, RLang);
1818 // Add name if not anonymous or intermediate type.
1820 AddString(&Buffer, DW_AT_name, DW_FORM_string, Name);
1822 if (Tag == DW_TAG_enumeration_type || Tag == DW_TAG_structure_type
1823 || Tag == DW_TAG_union_type) {
1824 // Add size if non-zero (derived types might be zero-sized.)
1826 AddUInt(&Buffer, DW_AT_byte_size, 0, Size);
1828 // Add zero size if it is not a forward declaration.
1829 if (CTy.isForwardDecl())
1830 AddUInt(&Buffer, DW_AT_declaration, DW_FORM_flag, 1);
1832 AddUInt(&Buffer, DW_AT_byte_size, 0, 0);
1835 // Add source line info if available.
1836 if (!CTy.isForwardDecl())
1837 AddSourceLine(&Buffer, &CTy);
1841 /// ConstructSubrangeDIE - Construct subrange DIE from DISubrange.
1842 void ConstructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy) {
1843 int64_t L = SR.getLo();
1844 int64_t H = SR.getHi();
1845 DIE *DW_Subrange = new DIE(DW_TAG_subrange_type);
1847 AddDIEntry(DW_Subrange, DW_AT_type, DW_FORM_ref4, IndexTy);
1849 AddSInt(DW_Subrange, DW_AT_lower_bound, 0, L);
1850 AddSInt(DW_Subrange, DW_AT_upper_bound, 0, H);
1852 Buffer.AddChild(DW_Subrange);
1855 /// ConstructArrayTypeDIE - Construct array type DIE from DICompositeType.
1856 void ConstructArrayTypeDIE(CompileUnit *DW_Unit, DIE &Buffer,
1857 DICompositeType *CTy) {
1858 Buffer.setTag(DW_TAG_array_type);
1859 if (CTy->getTag() == DW_TAG_vector_type)
1860 AddUInt(&Buffer, DW_AT_GNU_vector, DW_FORM_flag, 1);
1862 // Emit derived type.
1863 AddType(DW_Unit, &Buffer, CTy->getTypeDerivedFrom());
1864 DIArray Elements = CTy->getTypeArray();
1866 // Construct an anonymous type for index type.
1867 DIE IdxBuffer(DW_TAG_base_type);
1868 AddUInt(&IdxBuffer, DW_AT_byte_size, 0, sizeof(int32_t));
1869 AddUInt(&IdxBuffer, DW_AT_encoding, DW_FORM_data1, DW_ATE_signed);
1870 DIE *IndexTy = DW_Unit->AddDie(IdxBuffer);
1872 // Add subranges to array type.
1873 for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
1874 DIDescriptor Element = Elements.getElement(i);
1875 if (Element.getTag() == dwarf::DW_TAG_subrange_type)
1876 ConstructSubrangeDIE(Buffer, DISubrange(Element.getGV()), IndexTy);
1880 /// ConstructEnumTypeDIE - Construct enum type DIE from DIEnumerator.
1881 DIE *ConstructEnumTypeDIE(CompileUnit *DW_Unit, DIEnumerator *ETy) {
1883 DIE *Enumerator = new DIE(DW_TAG_enumerator);
1886 AddString(Enumerator, DW_AT_name, DW_FORM_string, Name);
1887 int64_t Value = ETy->getEnumValue();
1888 AddSInt(Enumerator, DW_AT_const_value, DW_FORM_sdata, Value);
1892 /// CreateGlobalVariableDIE - Create new DIE using GV.
1893 DIE *CreateGlobalVariableDIE(CompileUnit *DW_Unit, const DIGlobalVariable &GV)
1895 DIE *GVDie = new DIE(DW_TAG_variable);
1897 GV.getDisplayName(Name);
1898 AddString(GVDie, DW_AT_name, DW_FORM_string, Name);
1899 std::string LinkageName;
1900 GV.getLinkageName(LinkageName);
1901 if (!LinkageName.empty())
1902 AddString(GVDie, DW_AT_MIPS_linkage_name, DW_FORM_string, LinkageName);
1903 AddType(DW_Unit, GVDie, GV.getType());
1904 if (!GV.isLocalToUnit())
1905 AddUInt(GVDie, DW_AT_external, DW_FORM_flag, 1);
1906 AddSourceLine(GVDie, &GV);
1910 /// CreateMemberDIE - Create new member DIE.
1911 DIE *CreateMemberDIE(CompileUnit *DW_Unit, const DIDerivedType &DT) {
1912 DIE *MemberDie = new DIE(DT.getTag());
1916 AddString(MemberDie, DW_AT_name, DW_FORM_string, Name);
1918 AddType(DW_Unit, MemberDie, DT.getTypeDerivedFrom());
1920 AddSourceLine(MemberDie, &DT);
1922 uint64_t Size = DT.getSizeInBits();
1923 uint64_t FieldSize = DT.getOriginalTypeSize();
1925 if (Size != FieldSize) {
1927 AddUInt(MemberDie, DW_AT_byte_size, 0, DT.getOriginalTypeSize() >> 3);
1928 AddUInt(MemberDie, DW_AT_bit_size, 0, DT.getSizeInBits());
1930 uint64_t Offset = DT.getOffsetInBits();
1931 uint64_t FieldOffset = Offset;
1932 uint64_t AlignMask = ~(DT.getAlignInBits() - 1);
1933 uint64_t HiMark = (Offset + FieldSize) & AlignMask;
1934 FieldOffset = (HiMark - FieldSize);
1935 Offset -= FieldOffset;
1936 // Maybe we need to work from the other end.
1937 if (TD->isLittleEndian()) Offset = FieldSize - (Offset + Size);
1938 AddUInt(MemberDie, DW_AT_bit_offset, 0, Offset);
1940 DIEBlock *Block = new DIEBlock();
1941 AddUInt(Block, 0, DW_FORM_data1, DW_OP_plus_uconst);
1942 AddUInt(Block, 0, DW_FORM_udata, DT.getOffsetInBits() >> 3);
1943 AddBlock(MemberDie, DW_AT_data_member_location, 0, Block);
1945 if (DT.isProtected())
1946 AddUInt(MemberDie, DW_AT_accessibility, 0, DW_ACCESS_protected);
1947 else if (DT.isPrivate())
1948 AddUInt(MemberDie, DW_AT_accessibility, 0, DW_ACCESS_private);
1953 /// CreateSubprogramDIE - Create new DIE using SP.
1954 DIE *CreateSubprogramDIE(CompileUnit *DW_Unit,
1955 const DISubprogram &SP,
1956 bool IsConstructor = false) {
1957 DIE *SPDie = new DIE(DW_TAG_subprogram);
1961 AddString(SPDie, DW_AT_name, DW_FORM_string, Name);
1963 std::string LinkageName;
1964 SP.getLinkageName(LinkageName);
1966 if (!LinkageName.empty())
1967 AddString(SPDie, DW_AT_MIPS_linkage_name, DW_FORM_string, LinkageName);
1969 AddSourceLine(SPDie, &SP);
1971 DICompositeType SPTy = SP.getType();
1972 DIArray Args = SPTy.getTypeArray();
1974 // Add prototyped tag, if C or ObjC.
1975 unsigned Lang = SP.getCompileUnit().getLanguage();
1976 if (Lang == DW_LANG_C99 || Lang == DW_LANG_C89 || Lang == DW_LANG_ObjC)
1977 AddUInt(SPDie, DW_AT_prototyped, DW_FORM_flag, 1);
1980 unsigned SPTag = SPTy.getTag();
1981 if (!IsConstructor) {
1982 if (Args.isNull() || SPTag != DW_TAG_subroutine_type)
1983 AddType(DW_Unit, SPDie, SPTy);
1985 AddType(DW_Unit, SPDie, DIType(Args.getElement(0).getGV()));
1988 if (!SP.isDefinition()) {
1989 AddUInt(SPDie, DW_AT_declaration, DW_FORM_flag, 1);
1990 // Add arguments. Do not add arguments for subprogram definition. They
1991 // will be handled through RecordVariable.
1992 if (SPTag == DW_TAG_subroutine_type)
1993 for (unsigned i = 1, N = Args.getNumElements(); i < N; ++i) {
1994 DIE *Arg = new DIE(DW_TAG_formal_parameter);
1995 AddType(DW_Unit, Arg, DIType(Args.getElement(i).getGV()));
1996 AddUInt(Arg, DW_AT_artificial, DW_FORM_flag, 1); // ??
1997 SPDie->AddChild(Arg);
2001 if (!SP.isLocalToUnit())
2002 AddUInt(SPDie, DW_AT_external, DW_FORM_flag, 1);
2004 // DW_TAG_inlined_subroutine may refer to this DIE.
2005 DIE *&Slot = DW_Unit->getDieMapSlotFor(SP.getGV());
2010 /// FindCompileUnit - Get the compile unit for the given descriptor.
2012 CompileUnit &FindCompileUnit(DICompileUnit Unit) const {
2013 DenseMap<Value *, CompileUnit *>::const_iterator I =
2014 CompileUnitMap.find(Unit.getGV());
2015 assert(I != CompileUnitMap.end() && "Missing compile unit.");
2019 /// NewDbgScopeVariable - Create a new scope variable.
2021 DIE *NewDbgScopeVariable(DbgVariable *DV, CompileUnit *Unit) {
2022 // Get the descriptor.
2023 const DIVariable &VD = DV->getVariable();
2025 // Translate tag to proper Dwarf tag. The result variable is dropped for
2028 switch (VD.getTag()) {
2029 case DW_TAG_return_variable: return NULL;
2030 case DW_TAG_arg_variable: Tag = DW_TAG_formal_parameter; break;
2031 case DW_TAG_auto_variable: // fall thru
2032 default: Tag = DW_TAG_variable; break;
2035 // Define variable debug information entry.
2036 DIE *VariableDie = new DIE(Tag);
2039 AddString(VariableDie, DW_AT_name, DW_FORM_string, Name);
2041 // Add source line info if available.
2042 AddSourceLine(VariableDie, &VD);
2044 // Add variable type.
2045 AddType(Unit, VariableDie, VD.getType());
2047 // Add variable address.
2048 MachineLocation Location;
2049 Location.set(RI->getFrameRegister(*MF),
2050 RI->getFrameIndexOffset(*MF, DV->getFrameIndex()));
2051 AddAddress(VariableDie, DW_AT_location, Location);
2056 /// getOrCreateScope - Returns the scope associated with the given descriptor.
2058 DbgScope *getOrCreateScope(GlobalVariable *V) {
2059 DbgScope *&Slot = DbgScopeMap[V];
2060 if (Slot) return Slot;
2062 DbgScope *Parent = NULL;
2065 // Don't create a new scope if we already created one for an inlined
2067 DenseMap<const GlobalVariable *, DbgScope *>::iterator
2068 II = AbstractInstanceRootMap.find(V);
2069 if (II != AbstractInstanceRootMap.end())
2070 return LexicalScopeStack.back();
2072 if (!Block.isNull()) {
2073 DIDescriptor ParentDesc = Block.getContext();
2075 ParentDesc.isNull() ? NULL : getOrCreateScope(ParentDesc.getGV());
2078 Slot = new DbgScope(Parent, DIDescriptor(V));
2081 Parent->AddScope(Slot);
2083 // First function is top level function.
2084 FunctionDbgScope = Slot;
2089 /// ConstructDbgScope - Construct the components of a scope.
2091 void ConstructDbgScope(DbgScope *ParentScope,
2092 unsigned ParentStartID, unsigned ParentEndID,
2093 DIE *ParentDie, CompileUnit *Unit) {
2094 // Add variables to scope.
2095 SmallVector<DbgVariable *, 8> &Variables = ParentScope->getVariables();
2096 for (unsigned i = 0, N = Variables.size(); i < N; ++i) {
2097 DIE *VariableDie = NewDbgScopeVariable(Variables[i], Unit);
2098 if (VariableDie) ParentDie->AddChild(VariableDie);
2101 // Add concrete instances to scope.
2102 SmallVector<DbgConcreteScope *, 8> &ConcreteInsts = ParentScope->getConcreteInsts();
2103 for (unsigned i = 0, N = ConcreteInsts.size(); i < N; ++i) {
2104 DbgConcreteScope *ConcreteInst = ConcreteInsts[i];
2105 DIE *Die = ConcreteInst->getDie();
2107 unsigned StartID = ConcreteInst->getStartLabelID();
2108 unsigned EndID = ConcreteInst->getEndLabelID();
2110 // Add the scope bounds.
2112 AddLabel(Die, DW_AT_low_pc, DW_FORM_addr,
2113 DWLabel("label", StartID));
2115 AddLabel(Die, DW_AT_low_pc, DW_FORM_addr,
2116 DWLabel("func_begin", SubprogramCount));
2119 AddLabel(Die, DW_AT_high_pc, DW_FORM_addr,
2120 DWLabel("label", EndID));
2122 AddLabel(Die, DW_AT_high_pc, DW_FORM_addr,
2123 DWLabel("func_end", SubprogramCount));
2125 ParentDie->AddChild(Die);
2128 // Add nested scopes.
2129 SmallVector<DbgScope *, 4> &Scopes = ParentScope->getScopes();
2130 for (unsigned j = 0, M = Scopes.size(); j < M; ++j) {
2131 // Define the Scope debug information entry.
2132 DbgScope *Scope = Scopes[j];
2134 unsigned StartID = MMI->MappedLabel(Scope->getStartLabelID());
2135 unsigned EndID = MMI->MappedLabel(Scope->getEndLabelID());
2137 // Ignore empty scopes.
2138 if (StartID == EndID && StartID != 0) continue;
2140 // Do not ignore inlined scopes even if they don't have any variables or
2142 if (Scope->getScopes().empty() && Scope->getVariables().empty() &&
2143 Scope->getConcreteInsts().empty())
2146 if (StartID == ParentStartID && EndID == ParentEndID) {
2147 // Just add stuff to the parent scope.
2148 ConstructDbgScope(Scope, ParentStartID, ParentEndID, ParentDie, Unit);
2150 DIE *ScopeDie = new DIE(DW_TAG_lexical_block);
2152 // Add the scope bounds.
2154 AddLabel(ScopeDie, DW_AT_low_pc, DW_FORM_addr,
2155 DWLabel("label", StartID));
2157 AddLabel(ScopeDie, DW_AT_low_pc, DW_FORM_addr,
2158 DWLabel("func_begin", SubprogramCount));
2161 AddLabel(ScopeDie, DW_AT_high_pc, DW_FORM_addr,
2162 DWLabel("label", EndID));
2164 AddLabel(ScopeDie, DW_AT_high_pc, DW_FORM_addr,
2165 DWLabel("func_end", SubprogramCount));
2167 // Add the scope's contents.
2168 ConstructDbgScope(Scope, StartID, EndID, ScopeDie, Unit);
2169 ParentDie->AddChild(ScopeDie);
2174 /// ConstructFunctionDbgScope - Construct the scope for the subprogram.
2176 void ConstructFunctionDbgScope(DbgScope *RootScope) {
2177 // Exit if there is no root scope.
2178 if (!RootScope) return;
2179 DIDescriptor Desc = RootScope->getDesc();
2183 // Get the subprogram debug information entry.
2184 DISubprogram SPD(Desc.getGV());
2186 // Get the compile unit context.
2187 CompileUnit *Unit = MainCU;
2189 Unit = &FindCompileUnit(SPD.getCompileUnit());
2191 // Get the subprogram die.
2192 DIE *SPDie = Unit->getDieMapSlotFor(SPD.getGV());
2193 assert(SPDie && "Missing subprogram descriptor");
2195 // Add the function bounds.
2196 AddLabel(SPDie, DW_AT_low_pc, DW_FORM_addr,
2197 DWLabel("func_begin", SubprogramCount));
2198 AddLabel(SPDie, DW_AT_high_pc, DW_FORM_addr,
2199 DWLabel("func_end", SubprogramCount));
2200 MachineLocation Location(RI->getFrameRegister(*MF));
2201 AddAddress(SPDie, DW_AT_frame_base, Location);
2203 ConstructDbgScope(RootScope, 0, 0, SPDie, Unit);
2206 /// ConstructFunctionDbgScope - Construct the scope for the abstract debug
2209 void ConstructAbstractDbgScope(DbgScope *AbsScope) {
2210 // Exit if there is no root scope.
2211 if (!AbsScope) return;
2213 DIDescriptor Desc = AbsScope->getDesc();
2217 // Get the subprogram debug information entry.
2218 DISubprogram SPD(Desc.getGV());
2220 // Get the compile unit context.
2221 CompileUnit *Unit = MainCU;
2223 Unit = &FindCompileUnit(SPD.getCompileUnit());
2225 // Get the subprogram die.
2226 DIE *SPDie = Unit->getDieMapSlotFor(SPD.getGV());
2227 assert(SPDie && "Missing subprogram descriptor");
2229 ConstructDbgScope(AbsScope, 0, 0, SPDie, Unit);
2232 /// ConstructDefaultDbgScope - Construct a default scope for the subprogram.
2234 void ConstructDefaultDbgScope(MachineFunction *MF) {
2235 const char *FnName = MF->getFunction()->getNameStart();
2237 StringMap<DIE*> &Globals = MainCU->getGlobals();
2238 StringMap<DIE*>::iterator GI = Globals.find(FnName);
2239 if (GI != Globals.end()) {
2240 DIE *SPDie = GI->second;
2242 // Add the function bounds.
2243 AddLabel(SPDie, DW_AT_low_pc, DW_FORM_addr,
2244 DWLabel("func_begin", SubprogramCount));
2245 AddLabel(SPDie, DW_AT_high_pc, DW_FORM_addr,
2246 DWLabel("func_end", SubprogramCount));
2248 MachineLocation Location(RI->getFrameRegister(*MF));
2249 AddAddress(SPDie, DW_AT_frame_base, Location);
2253 for (unsigned i = 0, e = CompileUnits.size(); i != e; ++i) {
2254 CompileUnit *Unit = CompileUnits[i];
2255 StringMap<DIE*> &Globals = Unit->getGlobals();
2256 StringMap<DIE*>::iterator GI = Globals.find(FnName);
2257 if (GI != Globals.end()) {
2258 DIE *SPDie = GI->second;
2260 // Add the function bounds.
2261 AddLabel(SPDie, DW_AT_low_pc, DW_FORM_addr,
2262 DWLabel("func_begin", SubprogramCount));
2263 AddLabel(SPDie, DW_AT_high_pc, DW_FORM_addr,
2264 DWLabel("func_end", SubprogramCount));
2266 MachineLocation Location(RI->getFrameRegister(*MF));
2267 AddAddress(SPDie, DW_AT_frame_base, Location);
2274 // FIXME: This is causing an abort because C++ mangled names are compared
2275 // with their unmangled counterparts. See PR2885. Don't do this assert.
2276 assert(0 && "Couldn't find DIE for machine function!");
2280 /// EmitInitial - Emit initial Dwarf declarations. This is necessary for cc
2281 /// tools to recognize the object file contains Dwarf information.
2282 void EmitInitial() {
2283 // Check to see if we already emitted intial headers.
2284 if (didInitial) return;
2287 // Dwarf sections base addresses.
2288 if (TAI->doesDwarfRequireFrameSection()) {
2289 Asm->SwitchToDataSection(TAI->getDwarfFrameSection());
2290 EmitLabel("section_debug_frame", 0);
2292 Asm->SwitchToDataSection(TAI->getDwarfInfoSection());
2293 EmitLabel("section_info", 0);
2294 Asm->SwitchToDataSection(TAI->getDwarfAbbrevSection());
2295 EmitLabel("section_abbrev", 0);
2296 Asm->SwitchToDataSection(TAI->getDwarfARangesSection());
2297 EmitLabel("section_aranges", 0);
2298 if (TAI->doesSupportMacInfoSection()) {
2299 Asm->SwitchToDataSection(TAI->getDwarfMacInfoSection());
2300 EmitLabel("section_macinfo", 0);
2302 Asm->SwitchToDataSection(TAI->getDwarfLineSection());
2303 EmitLabel("section_line", 0);
2304 Asm->SwitchToDataSection(TAI->getDwarfLocSection());
2305 EmitLabel("section_loc", 0);
2306 Asm->SwitchToDataSection(TAI->getDwarfPubNamesSection());
2307 EmitLabel("section_pubnames", 0);
2308 Asm->SwitchToDataSection(TAI->getDwarfStrSection());
2309 EmitLabel("section_str", 0);
2310 Asm->SwitchToDataSection(TAI->getDwarfRangesSection());
2311 EmitLabel("section_ranges", 0);
2313 Asm->SwitchToSection(TAI->getTextSection());
2314 EmitLabel("text_begin", 0);
2315 Asm->SwitchToSection(TAI->getDataSection());
2316 EmitLabel("data_begin", 0);
2319 /// EmitDIE - Recusively Emits a debug information entry.
2321 void EmitDIE(DIE *Die) {
2322 // Get the abbreviation for this DIE.
2323 unsigned AbbrevNumber = Die->getAbbrevNumber();
2324 const DIEAbbrev *Abbrev = Abbreviations[AbbrevNumber - 1];
2328 // Emit the code (index) for the abbreviation.
2329 Asm->EmitULEB128Bytes(AbbrevNumber);
2331 if (Asm->isVerbose())
2332 Asm->EOL(std::string("Abbrev [" +
2333 utostr(AbbrevNumber) +
2334 "] 0x" + utohexstr(Die->getOffset()) +
2335 ":0x" + utohexstr(Die->getSize()) + " " +
2336 TagString(Abbrev->getTag())));
2340 SmallVector<DIEValue*, 32> &Values = Die->getValues();
2341 const SmallVector<DIEAbbrevData, 8> &AbbrevData = Abbrev->getData();
2343 // Emit the DIE attribute values.
2344 for (unsigned i = 0, N = Values.size(); i < N; ++i) {
2345 unsigned Attr = AbbrevData[i].getAttribute();
2346 unsigned Form = AbbrevData[i].getForm();
2347 assert(Form && "Too many attributes for DIE (check abbreviation)");
2351 Asm->EmitInt32(Die->SiblingOffset());
2353 case DW_AT_abstract_origin: {
2354 DIEntry *E = cast<DIEntry>(Values[i]);
2355 DIE *Origin = E->getEntry();
2357 CompileUnitOffsets[Die->getAbstractCompileUnit()] +
2358 Origin->getOffset();
2360 Asm->EmitInt32(Addr);
2364 // Emit an attribute using the defined form.
2365 Values[i]->EmitValue(*this, Form);
2369 Asm->EOL(AttributeString(Attr));
2372 // Emit the DIE children if any.
2373 if (Abbrev->getChildrenFlag() == DW_CHILDREN_yes) {
2374 const std::vector<DIE *> &Children = Die->getChildren();
2376 for (unsigned j = 0, M = Children.size(); j < M; ++j)
2377 EmitDIE(Children[j]);
2379 Asm->EmitInt8(0); Asm->EOL("End Of Children Mark");
2383 /// SizeAndOffsetDie - Compute the size and offset of a DIE.
2385 unsigned SizeAndOffsetDie(DIE *Die, unsigned Offset, bool Last) {
2386 // Get the children.
2387 const std::vector<DIE *> &Children = Die->getChildren();
2389 // If not last sibling and has children then add sibling offset attribute.
2390 if (!Last && !Children.empty()) Die->AddSiblingOffset();
2392 // Record the abbreviation.
2393 AssignAbbrevNumber(Die->getAbbrev());
2395 // Get the abbreviation for this DIE.
2396 unsigned AbbrevNumber = Die->getAbbrevNumber();
2397 const DIEAbbrev *Abbrev = Abbreviations[AbbrevNumber - 1];
2400 Die->setOffset(Offset);
2402 // Start the size with the size of abbreviation code.
2403 Offset += TargetAsmInfo::getULEB128Size(AbbrevNumber);
2405 const SmallVector<DIEValue*, 32> &Values = Die->getValues();
2406 const SmallVector<DIEAbbrevData, 8> &AbbrevData = Abbrev->getData();
2408 // Size the DIE attribute values.
2409 for (unsigned i = 0, N = Values.size(); i < N; ++i) {
2410 // Size attribute value.
2411 Offset += Values[i]->SizeOf(*this, AbbrevData[i].getForm());
2414 // Size the DIE children if any.
2415 if (!Children.empty()) {
2416 assert(Abbrev->getChildrenFlag() == DW_CHILDREN_yes &&
2417 "Children flag not set");
2419 for (unsigned j = 0, M = Children.size(); j < M; ++j) {
2420 Offset = SizeAndOffsetDie(Children[j], Offset, (j + 1) == M);
2423 // End of children marker.
2424 Offset += sizeof(int8_t);
2427 Die->setSize(Offset - Die->getOffset());
2431 /// SizeAndOffsets - Compute the size and offset of all the DIEs.
2433 void SizeAndOffsets() {
2434 // Compute size of compile unit header.
2435 static unsigned Offset =
2436 sizeof(int32_t) + // Length of Compilation Unit Info
2437 sizeof(int16_t) + // DWARF version number
2438 sizeof(int32_t) + // Offset Into Abbrev. Section
2439 sizeof(int8_t); // Pointer Size (in bytes)
2441 // Process base compile unit.
2443 SizeAndOffsetDie(MainCU->getDie(), Offset, true);
2444 CompileUnitOffsets[MainCU] = 0;
2448 // Process all compile units.
2449 unsigned PrevOffset = 0;
2451 for (unsigned i = 0, e = CompileUnits.size(); i != e; ++i) {
2452 CompileUnit *Unit = CompileUnits[i];
2453 CompileUnitOffsets[Unit] = PrevOffset;
2454 PrevOffset += SizeAndOffsetDie(Unit->getDie(), Offset, true)
2455 + sizeof(int32_t); // FIXME - extra pad for gdb bug.
2459 /// EmitDebugInfo / EmitDebugInfoPerCU - Emit the debug info section.
2461 void EmitDebugInfoPerCU(CompileUnit *Unit) {
2462 DIE *Die = Unit->getDie();
2463 // Emit the compile units header.
2464 EmitLabel("info_begin", Unit->getID());
2465 // Emit size of content not including length itself
2466 unsigned ContentSize = Die->getSize() +
2467 sizeof(int16_t) + // DWARF version number
2468 sizeof(int32_t) + // Offset Into Abbrev. Section
2469 sizeof(int8_t) + // Pointer Size (in bytes)
2470 sizeof(int32_t); // FIXME - extra pad for gdb bug.
2472 Asm->EmitInt32(ContentSize); Asm->EOL("Length of Compilation Unit Info");
2473 Asm->EmitInt16(DWARF_VERSION); Asm->EOL("DWARF version number");
2474 EmitSectionOffset("abbrev_begin", "section_abbrev", 0, 0, true, false);
2475 Asm->EOL("Offset Into Abbrev. Section");
2476 Asm->EmitInt8(TD->getPointerSize()); Asm->EOL("Address Size (in bytes)");
2479 // FIXME - extra padding for gdb bug.
2480 Asm->EmitInt8(0); Asm->EOL("Extra Pad For GDB");
2481 Asm->EmitInt8(0); Asm->EOL("Extra Pad For GDB");
2482 Asm->EmitInt8(0); Asm->EOL("Extra Pad For GDB");
2483 Asm->EmitInt8(0); Asm->EOL("Extra Pad For GDB");
2484 EmitLabel("info_end", Unit->getID());
2489 void EmitDebugInfo() {
2490 // Start debug info section.
2491 Asm->SwitchToDataSection(TAI->getDwarfInfoSection());
2494 EmitDebugInfoPerCU(MainCU);
2498 for (unsigned i = 0, e = CompileUnits.size(); i != e; ++i)
2499 EmitDebugInfoPerCU(CompileUnits[i]);
2502 /// EmitAbbreviations - Emit the abbreviation section.
2504 void EmitAbbreviations() const {
2505 // Check to see if it is worth the effort.
2506 if (!Abbreviations.empty()) {
2507 // Start the debug abbrev section.
2508 Asm->SwitchToDataSection(TAI->getDwarfAbbrevSection());
2510 EmitLabel("abbrev_begin", 0);
2512 // For each abbrevation.
2513 for (unsigned i = 0, N = Abbreviations.size(); i < N; ++i) {
2514 // Get abbreviation data
2515 const DIEAbbrev *Abbrev = Abbreviations[i];
2517 // Emit the abbrevations code (base 1 index.)
2518 Asm->EmitULEB128Bytes(Abbrev->getNumber());
2519 Asm->EOL("Abbreviation Code");
2521 // Emit the abbreviations data.
2522 Abbrev->Emit(*this);
2527 // Mark end of abbreviations.
2528 Asm->EmitULEB128Bytes(0); Asm->EOL("EOM(3)");
2530 EmitLabel("abbrev_end", 0);
2536 /// EmitEndOfLineMatrix - Emit the last address of the section and the end of
2537 /// the line matrix.
2539 void EmitEndOfLineMatrix(unsigned SectionEnd) {
2540 // Define last address of section.
2541 Asm->EmitInt8(0); Asm->EOL("Extended Op");
2542 Asm->EmitInt8(TD->getPointerSize() + 1); Asm->EOL("Op size");
2543 Asm->EmitInt8(DW_LNE_set_address); Asm->EOL("DW_LNE_set_address");
2544 EmitReference("section_end", SectionEnd); Asm->EOL("Section end label");
2546 // Mark end of matrix.
2547 Asm->EmitInt8(0); Asm->EOL("DW_LNE_end_sequence");
2548 Asm->EmitULEB128Bytes(1); Asm->EOL();
2549 Asm->EmitInt8(1); Asm->EOL();
2552 /// EmitDebugLines - Emit source line information.
2554 void EmitDebugLines() {
2555 // If the target is using .loc/.file, the assembler will be emitting the
2556 // .debug_line table automatically.
2557 if (TAI->hasDotLocAndDotFile())
2560 // Minimum line delta, thus ranging from -10..(255-10).
2561 const int MinLineDelta = -(DW_LNS_fixed_advance_pc + 1);
2562 // Maximum line delta, thus ranging from -10..(255-10).
2563 const int MaxLineDelta = 255 + MinLineDelta;
2565 // Start the dwarf line section.
2566 Asm->SwitchToDataSection(TAI->getDwarfLineSection());
2568 // Construct the section header.
2570 EmitDifference("line_end", 0, "line_begin", 0, true);
2571 Asm->EOL("Length of Source Line Info");
2572 EmitLabel("line_begin", 0);
2574 Asm->EmitInt16(DWARF_VERSION); Asm->EOL("DWARF version number");
2576 EmitDifference("line_prolog_end", 0, "line_prolog_begin", 0, true);
2577 Asm->EOL("Prolog Length");
2578 EmitLabel("line_prolog_begin", 0);
2580 Asm->EmitInt8(1); Asm->EOL("Minimum Instruction Length");
2582 Asm->EmitInt8(1); Asm->EOL("Default is_stmt_start flag");
2584 Asm->EmitInt8(MinLineDelta); Asm->EOL("Line Base Value (Special Opcodes)");
2586 Asm->EmitInt8(MaxLineDelta); Asm->EOL("Line Range Value (Special Opcodes)");
2588 Asm->EmitInt8(-MinLineDelta); Asm->EOL("Special Opcode Base");
2590 // Line number standard opcode encodings argument count
2591 Asm->EmitInt8(0); Asm->EOL("DW_LNS_copy arg count");
2592 Asm->EmitInt8(1); Asm->EOL("DW_LNS_advance_pc arg count");
2593 Asm->EmitInt8(1); Asm->EOL("DW_LNS_advance_line arg count");
2594 Asm->EmitInt8(1); Asm->EOL("DW_LNS_set_file arg count");
2595 Asm->EmitInt8(1); Asm->EOL("DW_LNS_set_column arg count");
2596 Asm->EmitInt8(0); Asm->EOL("DW_LNS_negate_stmt arg count");
2597 Asm->EmitInt8(0); Asm->EOL("DW_LNS_set_basic_block arg count");
2598 Asm->EmitInt8(0); Asm->EOL("DW_LNS_const_add_pc arg count");
2599 Asm->EmitInt8(1); Asm->EOL("DW_LNS_fixed_advance_pc arg count");
2601 // Emit directories.
2602 for (unsigned DI = 1, DE = getNumSourceDirectories()+1; DI != DE; ++DI) {
2603 Asm->EmitString(getSourceDirectoryName(DI));
2604 Asm->EOL("Directory");
2606 Asm->EmitInt8(0); Asm->EOL("End of directories");
2609 for (unsigned SI = 1, SE = getNumSourceIds()+1; SI != SE; ++SI) {
2610 // Remember source id starts at 1.
2611 std::pair<unsigned, unsigned> Id = getSourceDirectoryAndFileIds(SI);
2612 Asm->EmitString(getSourceFileName(Id.second));
2614 Asm->EmitULEB128Bytes(Id.first);
2615 Asm->EOL("Directory #");
2616 Asm->EmitULEB128Bytes(0);
2617 Asm->EOL("Mod date");
2618 Asm->EmitULEB128Bytes(0);
2619 Asm->EOL("File size");
2621 Asm->EmitInt8(0); Asm->EOL("End of files");
2623 EmitLabel("line_prolog_end", 0);
2625 // A sequence for each text section.
2626 unsigned SecSrcLinesSize = SectionSourceLines.size();
2628 for (unsigned j = 0; j < SecSrcLinesSize; ++j) {
2629 // Isolate current sections line info.
2630 const std::vector<SrcLineInfo> &LineInfos = SectionSourceLines[j];
2632 if (Asm->isVerbose()) {
2633 const Section* S = SectionMap[j + 1];
2634 O << '\t' << TAI->getCommentString() << " Section"
2635 << S->getName() << '\n';
2639 // Dwarf assumes we start with first line of first source file.
2640 unsigned Source = 1;
2643 // Construct rows of the address, source, line, column matrix.
2644 for (unsigned i = 0, N = LineInfos.size(); i < N; ++i) {
2645 const SrcLineInfo &LineInfo = LineInfos[i];
2646 unsigned LabelID = MMI->MappedLabel(LineInfo.getLabelID());
2647 if (!LabelID) continue;
2649 if (!Asm->isVerbose())
2652 std::pair<unsigned, unsigned> SourceID =
2653 getSourceDirectoryAndFileIds(LineInfo.getSourceID());
2654 O << '\t' << TAI->getCommentString() << ' '
2655 << getSourceDirectoryName(SourceID.first) << ' '
2656 << getSourceFileName(SourceID.second)
2657 <<" :" << utostr_32(LineInfo.getLine()) << '\n';
2660 // Define the line address.
2661 Asm->EmitInt8(0); Asm->EOL("Extended Op");
2662 Asm->EmitInt8(TD->getPointerSize() + 1); Asm->EOL("Op size");
2663 Asm->EmitInt8(DW_LNE_set_address); Asm->EOL("DW_LNE_set_address");
2664 EmitReference("label", LabelID); Asm->EOL("Location label");
2666 // If change of source, then switch to the new source.
2667 if (Source != LineInfo.getSourceID()) {
2668 Source = LineInfo.getSourceID();
2669 Asm->EmitInt8(DW_LNS_set_file); Asm->EOL("DW_LNS_set_file");
2670 Asm->EmitULEB128Bytes(Source); Asm->EOL("New Source");
2673 // If change of line.
2674 if (Line != LineInfo.getLine()) {
2675 // Determine offset.
2676 int Offset = LineInfo.getLine() - Line;
2677 int Delta = Offset - MinLineDelta;
2680 Line = LineInfo.getLine();
2682 // If delta is small enough and in range...
2683 if (Delta >= 0 && Delta < (MaxLineDelta - 1)) {
2684 // ... then use fast opcode.
2685 Asm->EmitInt8(Delta - MinLineDelta); Asm->EOL("Line Delta");
2687 // ... otherwise use long hand.
2688 Asm->EmitInt8(DW_LNS_advance_line); Asm->EOL("DW_LNS_advance_line");
2689 Asm->EmitSLEB128Bytes(Offset); Asm->EOL("Line Offset");
2690 Asm->EmitInt8(DW_LNS_copy); Asm->EOL("DW_LNS_copy");
2693 // Copy the previous row (different address or source)
2694 Asm->EmitInt8(DW_LNS_copy); Asm->EOL("DW_LNS_copy");
2698 EmitEndOfLineMatrix(j + 1);
2701 if (SecSrcLinesSize == 0)
2702 // Because we're emitting a debug_line section, we still need a line
2703 // table. The linker and friends expect it to exist. If there's nothing to
2704 // put into it, emit an empty table.
2705 EmitEndOfLineMatrix(1);
2707 EmitLabel("line_end", 0);
2712 /// EmitCommonDebugFrame - Emit common frame info into a debug frame section.
2714 void EmitCommonDebugFrame() {
2715 if (!TAI->doesDwarfRequireFrameSection())
2719 Asm->TM.getFrameInfo()->getStackGrowthDirection() ==
2720 TargetFrameInfo::StackGrowsUp ?
2721 TD->getPointerSize() : -TD->getPointerSize();
2723 // Start the dwarf frame section.
2724 Asm->SwitchToDataSection(TAI->getDwarfFrameSection());
2726 EmitLabel("debug_frame_common", 0);
2727 EmitDifference("debug_frame_common_end", 0,
2728 "debug_frame_common_begin", 0, true);
2729 Asm->EOL("Length of Common Information Entry");
2731 EmitLabel("debug_frame_common_begin", 0);
2732 Asm->EmitInt32((int)DW_CIE_ID);
2733 Asm->EOL("CIE Identifier Tag");
2734 Asm->EmitInt8(DW_CIE_VERSION);
2735 Asm->EOL("CIE Version");
2736 Asm->EmitString("");
2737 Asm->EOL("CIE Augmentation");
2738 Asm->EmitULEB128Bytes(1);
2739 Asm->EOL("CIE Code Alignment Factor");
2740 Asm->EmitSLEB128Bytes(stackGrowth);
2741 Asm->EOL("CIE Data Alignment Factor");
2742 Asm->EmitInt8(RI->getDwarfRegNum(RI->getRARegister(), false));
2743 Asm->EOL("CIE RA Column");
2745 std::vector<MachineMove> Moves;
2746 RI->getInitialFrameState(Moves);
2748 EmitFrameMoves(NULL, 0, Moves, false);
2750 Asm->EmitAlignment(2, 0, 0, false);
2751 EmitLabel("debug_frame_common_end", 0);
2756 /// EmitFunctionDebugFrame - Emit per function frame info into a debug frame
2758 void EmitFunctionDebugFrame(const FunctionDebugFrameInfo &DebugFrameInfo) {
2759 if (!TAI->doesDwarfRequireFrameSection())
2762 // Start the dwarf frame section.
2763 Asm->SwitchToDataSection(TAI->getDwarfFrameSection());
2765 EmitDifference("debug_frame_end", DebugFrameInfo.Number,
2766 "debug_frame_begin", DebugFrameInfo.Number, true);
2767 Asm->EOL("Length of Frame Information Entry");
2769 EmitLabel("debug_frame_begin", DebugFrameInfo.Number);
2771 EmitSectionOffset("debug_frame_common", "section_debug_frame",
2773 Asm->EOL("FDE CIE offset");
2775 EmitReference("func_begin", DebugFrameInfo.Number);
2776 Asm->EOL("FDE initial location");
2777 EmitDifference("func_end", DebugFrameInfo.Number,
2778 "func_begin", DebugFrameInfo.Number);
2779 Asm->EOL("FDE address range");
2781 EmitFrameMoves("func_begin", DebugFrameInfo.Number, DebugFrameInfo.Moves,
2784 Asm->EmitAlignment(2, 0, 0, false);
2785 EmitLabel("debug_frame_end", DebugFrameInfo.Number);
2790 void EmitDebugPubNamesPerCU(CompileUnit *Unit) {
2791 EmitDifference("pubnames_end", Unit->getID(),
2792 "pubnames_begin", Unit->getID(), true);
2793 Asm->EOL("Length of Public Names Info");
2795 EmitLabel("pubnames_begin", Unit->getID());
2797 Asm->EmitInt16(DWARF_VERSION); Asm->EOL("DWARF Version");
2799 EmitSectionOffset("info_begin", "section_info",
2800 Unit->getID(), 0, true, false);
2801 Asm->EOL("Offset of Compilation Unit Info");
2803 EmitDifference("info_end", Unit->getID(), "info_begin", Unit->getID(),
2805 Asm->EOL("Compilation Unit Length");
2807 StringMap<DIE*> &Globals = Unit->getGlobals();
2808 for (StringMap<DIE*>::const_iterator
2809 GI = Globals.begin(), GE = Globals.end(); GI != GE; ++GI) {
2810 const char *Name = GI->getKeyData();
2811 DIE * Entity = GI->second;
2813 Asm->EmitInt32(Entity->getOffset()); Asm->EOL("DIE offset");
2814 Asm->EmitString(Name, strlen(Name)); Asm->EOL("External Name");
2817 Asm->EmitInt32(0); Asm->EOL("End Mark");
2818 EmitLabel("pubnames_end", Unit->getID());
2823 /// EmitDebugPubNames - Emit visible names into a debug pubnames section.
2825 void EmitDebugPubNames() {
2826 // Start the dwarf pubnames section.
2827 Asm->SwitchToDataSection(TAI->getDwarfPubNamesSection());
2830 EmitDebugPubNamesPerCU(MainCU);
2834 for (unsigned i = 0, e = CompileUnits.size(); i != e; ++i)
2835 EmitDebugPubNamesPerCU(CompileUnits[i]);
2838 /// EmitDebugStr - Emit visible names into a debug str section.
2840 void EmitDebugStr() {
2841 // Check to see if it is worth the effort.
2842 if (!StringPool.empty()) {
2843 // Start the dwarf str section.
2844 Asm->SwitchToDataSection(TAI->getDwarfStrSection());
2846 // For each of strings in the string pool.
2847 for (unsigned StringID = 1, N = StringPool.size();
2848 StringID <= N; ++StringID) {
2849 // Emit a label for reference from debug information entries.
2850 EmitLabel("string", StringID);
2851 // Emit the string itself.
2852 const std::string &String = StringPool[StringID];
2853 Asm->EmitString(String); Asm->EOL();
2860 /// EmitDebugLoc - Emit visible names into a debug loc section.
2862 void EmitDebugLoc() {
2863 // Start the dwarf loc section.
2864 Asm->SwitchToDataSection(TAI->getDwarfLocSection());
2869 /// EmitDebugARanges - Emit visible names into a debug aranges section.
2871 void EmitDebugARanges() {
2872 // Start the dwarf aranges section.
2873 Asm->SwitchToDataSection(TAI->getDwarfARangesSection());
2877 CompileUnit *Unit = GetBaseCompileUnit();
2879 // Don't include size of length
2880 Asm->EmitInt32(0x1c); Asm->EOL("Length of Address Ranges Info");
2882 Asm->EmitInt16(DWARF_VERSION); Asm->EOL("Dwarf Version");
2884 EmitReference("info_begin", Unit->getID());
2885 Asm->EOL("Offset of Compilation Unit Info");
2887 Asm->EmitInt8(TD->getPointerSize()); Asm->EOL("Size of Address");
2889 Asm->EmitInt8(0); Asm->EOL("Size of Segment Descriptor");
2891 Asm->EmitInt16(0); Asm->EOL("Pad (1)");
2892 Asm->EmitInt16(0); Asm->EOL("Pad (2)");
2895 EmitReference("text_begin", 0); Asm->EOL("Address");
2896 EmitDifference("text_end", 0, "text_begin", 0, true); Asm->EOL("Length");
2898 Asm->EmitInt32(0); Asm->EOL("EOM (1)");
2899 Asm->EmitInt32(0); Asm->EOL("EOM (2)");
2905 /// EmitDebugRanges - Emit visible names into a debug ranges section.
2907 void EmitDebugRanges() {
2908 // Start the dwarf ranges section.
2909 Asm->SwitchToDataSection(TAI->getDwarfRangesSection());
2914 /// EmitDebugMacInfo - Emit visible names into a debug macinfo section.
2916 void EmitDebugMacInfo() {
2917 if (TAI->doesSupportMacInfoSection()) {
2918 // Start the dwarf macinfo section.
2919 Asm->SwitchToDataSection(TAI->getDwarfMacInfoSection());
2925 /// EmitDebugInlineInfo - Emit inline info using following format.
2927 /// 1. length of section
2928 /// 2. Dwarf version number
2929 /// 3. address size.
2931 /// Entries (one "entry" for each function that was inlined):
2933 /// 1. offset into __debug_str section for MIPS linkage name, if exists;
2934 /// otherwise offset into __debug_str for regular function name.
2935 /// 2. offset into __debug_str section for regular function name.
2936 /// 3. an unsigned LEB128 number indicating the number of distinct inlining
2937 /// instances for the function.
2939 /// The rest of the entry consists of a {die_offset, low_pc} pair for each
2940 /// inlined instance; the die_offset points to the inlined_subroutine die in
2941 /// the __debug_info section, and the low_pc is the starting address for the
2942 /// inlining instance.
2943 void EmitDebugInlineInfo() {
2944 if (!TAI->doesDwarfUsesInlineInfoSection())
2950 Asm->SwitchToDataSection(TAI->getDwarfDebugInlineSection());
2952 EmitDifference("debug_inlined_end", 1,
2953 "debug_inlined_begin", 1, true);
2954 Asm->EOL("Length of Debug Inlined Information Entry");
2956 EmitLabel("debug_inlined_begin", 1);
2958 Asm->EmitInt16(DWARF_VERSION); Asm->EOL("Dwarf Version");
2959 Asm->EmitInt8(TD->getPointerSize()); Asm->EOL("Address Size (in bytes)");
2961 for (DenseMap<GlobalVariable *, SmallVector<unsigned, 4> >::iterator
2962 I = InlineInfo.begin(), E = InlineInfo.end(); I != E; ++I) {
2963 GlobalVariable *GV = I->first;
2964 SmallVector<unsigned, 4> &Labels = I->second;
2965 DISubprogram SP(GV);
2969 SP.getLinkageName(LName);
2972 Asm->EmitString(LName.empty() ? Name : LName);
2973 Asm->EOL("MIPS linkage name");
2975 Asm->EmitString(Name); Asm->EOL("Function name");
2977 Asm->EmitULEB128Bytes(Labels.size()); Asm->EOL("Inline count");
2979 for (SmallVector<unsigned, 4>::iterator LI = Labels.begin(),
2980 LE = Labels.end(); LI != LE; ++LI) {
2981 DIE *SP = MainCU->getDieMapSlotFor(GV);
2982 Asm->EmitInt32(SP->getOffset()); Asm->EOL("DIE offset");
2984 if (TD->getPointerSize() == sizeof(int32_t))
2985 O << TAI->getData32bitsDirective();
2987 O << TAI->getData64bitsDirective();
2988 PrintLabelName("label", *LI); Asm->EOL("low_pc");
2992 EmitLabel("debug_inlined_end", 1);
2996 /// GetOrCreateSourceID - Look up the source id with the given directory and
2997 /// source file names. If none currently exists, create a new id and insert it
2998 /// in the SourceIds map. This can update DirectoryNames and SourceFileNames maps
3000 unsigned GetOrCreateSourceID(const std::string &DirName,
3001 const std::string &FileName) {
3003 StringMap<unsigned>::iterator DI = DirectoryIdMap.find(DirName);
3004 if (DI != DirectoryIdMap.end()) {
3005 DId = DI->getValue();
3007 DId = DirectoryNames.size() + 1;
3008 DirectoryIdMap[DirName] = DId;
3009 DirectoryNames.push_back(DirName);
3013 StringMap<unsigned>::iterator FI = SourceFileIdMap.find(FileName);
3014 if (FI != SourceFileIdMap.end()) {
3015 FId = FI->getValue();
3017 FId = SourceFileNames.size() + 1;
3018 SourceFileIdMap[FileName] = FId;
3019 SourceFileNames.push_back(FileName);
3022 DenseMap<std::pair<unsigned, unsigned>, unsigned>::iterator SI =
3023 SourceIdMap.find(std::make_pair(DId, FId));
3024 if (SI != SourceIdMap.end())
3027 unsigned SrcId = SourceIds.size() + 1; // DW_AT_decl_file cannot be 0.
3028 SourceIdMap[std::make_pair(DId, FId)] = SrcId;
3029 SourceIds.push_back(std::make_pair(DId, FId));
3034 void ConstructCompileUnit(GlobalVariable *GV) {
3035 DICompileUnit DIUnit(GV);
3036 std::string Dir, FN, Prod;
3037 unsigned ID = GetOrCreateSourceID(DIUnit.getDirectory(Dir),
3038 DIUnit.getFilename(FN));
3040 DIE *Die = new DIE(DW_TAG_compile_unit);
3041 AddSectionOffset(Die, DW_AT_stmt_list, DW_FORM_data4,
3042 DWLabel("section_line", 0), DWLabel("section_line", 0),
3044 AddString(Die, DW_AT_producer, DW_FORM_string, DIUnit.getProducer(Prod));
3045 AddUInt(Die, DW_AT_language, DW_FORM_data1, DIUnit.getLanguage());
3046 AddString(Die, DW_AT_name, DW_FORM_string, FN);
3048 AddString(Die, DW_AT_comp_dir, DW_FORM_string, Dir);
3049 if (DIUnit.isOptimized())
3050 AddUInt(Die, DW_AT_APPLE_optimized, DW_FORM_flag, 1);
3052 DIUnit.getFlags(Flags);
3054 AddString(Die, DW_AT_APPLE_flags, DW_FORM_string, Flags);
3055 unsigned RVer = DIUnit.getRunTimeVersion();
3057 AddUInt(Die, DW_AT_APPLE_major_runtime_vers, DW_FORM_data1, RVer);
3059 CompileUnit *Unit = new CompileUnit(ID, Die);
3060 if (DIUnit.isMain()) {
3061 assert(!MainCU && "Multiple main compile units are found!");
3064 CompileUnitMap[DIUnit.getGV()] = Unit;
3065 CompileUnits.push_back(Unit);
3068 /// ConstructCompileUnits - Create a compile unit DIEs.
3069 void ConstructCompileUnits() {
3070 GlobalVariable *Root = M->getGlobalVariable("llvm.dbg.compile_units");
3073 assert(Root->hasLinkOnceLinkage() && Root->hasOneUse() &&
3074 "Malformed compile unit descriptor anchor type");
3075 Constant *RootC = cast<Constant>(*Root->use_begin());
3076 assert(RootC->hasNUsesOrMore(1) &&
3077 "Malformed compile unit descriptor anchor type");
3078 for (Value::use_iterator UI = RootC->use_begin(), UE = Root->use_end();
3080 for (Value::use_iterator UUI = UI->use_begin(), UUE = UI->use_end();
3081 UUI != UUE; ++UUI) {
3082 GlobalVariable *GV = cast<GlobalVariable>(*UUI);
3083 ConstructCompileUnit(GV);
3087 bool ConstructGlobalVariableDIE(GlobalVariable *GV) {
3088 DIGlobalVariable DI_GV(GV);
3089 CompileUnit *DW_Unit = MainCU;
3091 DW_Unit = &FindCompileUnit(DI_GV.getCompileUnit());
3093 // Check for pre-existence.
3094 DIE *&Slot = DW_Unit->getDieMapSlotFor(DI_GV.getGV());
3098 DIE *VariableDie = CreateGlobalVariableDIE(DW_Unit, DI_GV);
3101 DIEBlock *Block = new DIEBlock();
3102 AddUInt(Block, 0, DW_FORM_data1, DW_OP_addr);
3104 AddObjectLabel(Block, 0, DW_FORM_udata,
3105 Asm->getGlobalLinkName(DI_GV.getGlobal(), GLN));
3106 AddBlock(VariableDie, DW_AT_location, 0, Block);
3111 // Add to context owner.
3112 DW_Unit->getDie()->AddChild(VariableDie);
3114 // Expose as global. FIXME - need to check external flag.
3116 DW_Unit->AddGlobal(DI_GV.getName(Name), VariableDie);
3120 /// ConstructGlobalVariableDIEs - Create DIEs for each of the externally
3121 /// visible global variables. Return true if at least one global DIE is
3123 bool ConstructGlobalVariableDIEs() {
3124 GlobalVariable *Root = M->getGlobalVariable("llvm.dbg.global_variables");
3128 assert(Root->hasLinkOnceLinkage() && Root->hasOneUse() &&
3129 "Malformed global variable descriptor anchor type");
3130 Constant *RootC = cast<Constant>(*Root->use_begin());
3131 assert(RootC->hasNUsesOrMore(1) &&
3132 "Malformed global variable descriptor anchor type");
3134 bool Result = false;
3135 for (Value::use_iterator UI = RootC->use_begin(), UE = Root->use_end();
3137 for (Value::use_iterator UUI = UI->use_begin(), UUE = UI->use_end();
3139 Result |= ConstructGlobalVariableDIE(cast<GlobalVariable>(*UUI));
3144 bool ConstructSubprogram(GlobalVariable *GV) {
3145 DISubprogram SP(GV);
3146 CompileUnit *Unit = MainCU;
3148 Unit = &FindCompileUnit(SP.getCompileUnit());
3150 // Check for pre-existence.
3151 DIE *&Slot = Unit->getDieMapSlotFor(GV);
3155 if (!SP.isDefinition())
3156 // This is a method declaration which will be handled while
3157 // constructing class type.
3160 DIE *SubprogramDie = CreateSubprogramDIE(Unit, SP);
3163 Slot = SubprogramDie;
3164 // Add to context owner.
3165 Unit->getDie()->AddChild(SubprogramDie);
3166 // Expose as global.
3168 Unit->AddGlobal(SP.getName(Name), SubprogramDie);
3172 /// ConstructSubprograms - Create DIEs for each of the externally visible
3173 /// subprograms. Return true if at least one subprogram DIE is created.
3174 bool ConstructSubprograms() {
3175 GlobalVariable *Root = M->getGlobalVariable("llvm.dbg.subprograms");
3179 assert(Root->hasLinkOnceLinkage() && Root->hasOneUse() &&
3180 "Malformed subprogram descriptor anchor type");
3181 Constant *RootC = cast<Constant>(*Root->use_begin());
3182 assert(RootC->hasNUsesOrMore(1) &&
3183 "Malformed subprogram descriptor anchor type");
3185 bool Result = false;
3186 for (Value::use_iterator UI = RootC->use_begin(), UE = Root->use_end();
3188 for (Value::use_iterator UUI = UI->use_begin(), UUE = UI->use_end();
3190 Result |= ConstructSubprogram(cast<GlobalVariable>(*UUI));
3196 //===--------------------------------------------------------------------===//
3197 // Main entry points.
3199 DwarfDebug(raw_ostream &OS, AsmPrinter *A, const TargetAsmInfo *T)
3200 : Dwarf(OS, A, T, "dbg"), MainCU(0),
3201 AbbreviationsSet(InitAbbreviationsSetSize), Abbreviations(),
3202 ValuesSet(InitValuesSetSize), Values(), StringPool(), SectionMap(),
3203 SectionSourceLines(), didInitial(false), shouldEmit(false),
3204 FunctionDbgScope(0), DebugTimer(0) {
3205 if (TimePassesIsEnabled)
3206 DebugTimer = new Timer("Dwarf Debug Writer",
3207 getDwarfTimerGroup());
3209 virtual ~DwarfDebug() {
3210 for (unsigned j = 0, M = Values.size(); j < M; ++j)
3213 for (DenseMap<const GlobalVariable *, DbgScope *>::iterator
3214 I = AbstractInstanceRootMap.begin(),
3215 E = AbstractInstanceRootMap.end(); I != E;++I)
3221 /// ShouldEmitDwarfDebug - Returns true if Dwarf debugging declarations should
3223 bool ShouldEmitDwarfDebug() const { return shouldEmit; }
3225 /// SetDebugInfo - Create global DIEs and emit initial debug info sections.
3226 /// This is inovked by the target AsmPrinter.
3227 void SetDebugInfo(MachineModuleInfo *mmi) {
3228 if (TimePassesIsEnabled)
3229 DebugTimer->startTimer();
3231 // Create all the compile unit DIEs.
3232 ConstructCompileUnits();
3234 if (CompileUnits.empty()) {
3235 if (TimePassesIsEnabled)
3236 DebugTimer->stopTimer();
3241 // Create DIEs for each of the externally visible global variables.
3242 bool globalDIEs = ConstructGlobalVariableDIEs();
3244 // Create DIEs for each of the externally visible subprograms.
3245 bool subprogramDIEs = ConstructSubprograms();
3247 // If there is not any debug info available for any global variables
3248 // and any subprograms then there is not any debug info to emit.
3249 if (!globalDIEs && !subprogramDIEs) {
3250 if (TimePassesIsEnabled)
3251 DebugTimer->stopTimer();
3258 MMI->setDebugInfoAvailability(true);
3260 // Prime section data.
3261 SectionMap.insert(TAI->getTextSection());
3263 // Print out .file directives to specify files for .loc directives. These
3264 // are printed out early so that they precede any .loc directives.
3265 if (TAI->hasDotLocAndDotFile()) {
3266 for (unsigned i = 1, e = getNumSourceIds()+1; i != e; ++i) {
3267 // Remember source id starts at 1.
3268 std::pair<unsigned, unsigned> Id = getSourceDirectoryAndFileIds(i);
3269 sys::Path FullPath(getSourceDirectoryName(Id.first));
3271 FullPath.appendComponent(getSourceFileName(Id.second));
3272 assert(AppendOk && "Could not append filename to directory!");
3274 Asm->EmitFile(i, FullPath.toString());
3279 // Emit initial sections
3282 if (TimePassesIsEnabled)
3283 DebugTimer->stopTimer();
3286 /// BeginModule - Emit all Dwarf sections that should come prior to the
3288 void BeginModule(Module *M) {
3292 /// EndModule - Emit all Dwarf sections that should come after the content.
3295 if (!ShouldEmitDwarfDebug())
3298 if (TimePassesIsEnabled)
3299 DebugTimer->startTimer();
3301 // Standard sections final addresses.
3302 Asm->SwitchToSection(TAI->getTextSection());
3303 EmitLabel("text_end", 0);
3304 Asm->SwitchToSection(TAI->getDataSection());
3305 EmitLabel("data_end", 0);
3307 // End text sections.
3308 for (unsigned i = 1, N = SectionMap.size(); i <= N; ++i) {
3309 Asm->SwitchToSection(SectionMap[i]);
3310 EmitLabel("section_end", i);
3313 // Emit common frame information.
3314 EmitCommonDebugFrame();
3316 // Emit function debug frame information
3317 for (std::vector<FunctionDebugFrameInfo>::iterator I = DebugFrames.begin(),
3318 E = DebugFrames.end(); I != E; ++I)
3319 EmitFunctionDebugFrame(*I);
3321 // Compute DIE offsets and sizes.
3324 // Emit all the DIEs into a debug info section
3327 // Corresponding abbreviations into a abbrev section.
3328 EmitAbbreviations();
3330 // Emit source line correspondence into a debug line section.
3333 // Emit info into a debug pubnames section.
3334 EmitDebugPubNames();
3336 // Emit info into a debug str section.
3339 // Emit info into a debug loc section.
3342 // Emit info into a debug aranges section.
3345 // Emit info into a debug ranges section.
3348 // Emit info into a debug macinfo section.
3351 // Emit inline info.
3352 EmitDebugInlineInfo();
3354 if (TimePassesIsEnabled)
3355 DebugTimer->stopTimer();
3358 /// BeginFunction - Gather pre-function debug information. Assumes being
3359 /// emitted immediately after the function entry point.
3360 void BeginFunction(MachineFunction *MF) {
3363 if (!ShouldEmitDwarfDebug()) return;
3365 if (TimePassesIsEnabled)
3366 DebugTimer->startTimer();
3368 // Begin accumulating function debug information.
3369 MMI->BeginFunction(MF);
3371 // Assumes in correct section after the entry point.
3372 EmitLabel("func_begin", ++SubprogramCount);
3374 // Emit label for the implicitly defined dbg.stoppoint at the start of
3376 DebugLoc FDL = MF->getDefaultDebugLoc();
3377 if (!FDL.isUnknown()) {
3378 DebugLocTuple DLT = MF->getDebugLocTuple(FDL);
3379 unsigned LabelID = RecordSourceLine(DLT.Line, DLT.Col,
3380 DICompileUnit(DLT.CompileUnit));
3381 Asm->printLabel(LabelID);
3384 if (TimePassesIsEnabled)
3385 DebugTimer->stopTimer();
3388 /// EndFunction - Gather and emit post-function debug information.
3390 void EndFunction(MachineFunction *MF) {
3391 if (!ShouldEmitDwarfDebug()) return;
3393 if (TimePassesIsEnabled)
3394 DebugTimer->startTimer();
3396 // Define end label for subprogram.
3397 EmitLabel("func_end", SubprogramCount);
3399 // Get function line info.
3400 if (!Lines.empty()) {
3401 // Get section line info.
3402 unsigned ID = SectionMap.insert(Asm->CurrentSection_);
3403 if (SectionSourceLines.size() < ID) SectionSourceLines.resize(ID);
3404 std::vector<SrcLineInfo> &SectionLineInfos = SectionSourceLines[ID-1];
3405 // Append the function info to section info.
3406 SectionLineInfos.insert(SectionLineInfos.end(),
3407 Lines.begin(), Lines.end());
3410 // Construct the DbgScope for abstract instances.
3411 for (SmallVector<DbgScope *, 32>::iterator
3412 I = AbstractInstanceRootList.begin(),
3413 E = AbstractInstanceRootList.end(); I != E; ++I)
3414 ConstructAbstractDbgScope(*I);
3416 // Construct scopes for subprogram.
3417 if (FunctionDbgScope)
3418 ConstructFunctionDbgScope(FunctionDbgScope);
3420 // FIXME: This is wrong. We are essentially getting past a problem with
3421 // debug information not being able to handle unreachable blocks that have
3422 // debug information in them. In particular, those unreachable blocks that
3423 // have "region end" info in them. That situation results in the "root
3424 // scope" not being created. If that's the case, then emit a "default"
3425 // scope, i.e., one that encompasses the whole function. This isn't
3426 // desirable. And a better way of handling this (and all of the debugging
3427 // information) needs to be explored.
3428 ConstructDefaultDbgScope(MF);
3430 DebugFrames.push_back(FunctionDebugFrameInfo(SubprogramCount,
3431 MMI->getFrameMoves()));
3434 if (FunctionDbgScope) {
3435 delete FunctionDbgScope;
3436 DbgScopeMap.clear();
3437 DbgConcreteScopeMap.clear();
3438 InlinedVariableScopes.clear();
3439 FunctionDbgScope = NULL;
3440 LexicalScopeStack.clear();
3441 AbstractInstanceRootList.clear();
3446 if (TimePassesIsEnabled)
3447 DebugTimer->stopTimer();
3450 /// RecordSourceLine - Records location information and associates it with a
3451 /// label. Returns a unique label ID used to generate a label and provide
3452 /// correspondence to the source line list.
3453 unsigned RecordSourceLine(Value *V, unsigned Line, unsigned Col) {
3454 if (TimePassesIsEnabled)
3455 DebugTimer->startTimer();
3457 CompileUnit *Unit = CompileUnitMap[V];
3458 assert(Unit && "Unable to find CompileUnit");
3459 unsigned ID = MMI->NextLabelID();
3460 Lines.push_back(SrcLineInfo(Line, Col, Unit->getID(), ID));
3462 if (TimePassesIsEnabled)
3463 DebugTimer->stopTimer();
3468 /// RecordSourceLine - Records location information and associates it with a
3469 /// label. Returns a unique label ID used to generate a label and provide
3470 /// correspondence to the source line list.
3471 unsigned RecordSourceLine(unsigned Line, unsigned Col, DICompileUnit CU) {
3472 if (TimePassesIsEnabled)
3473 DebugTimer->startTimer();
3475 std::string Dir, Fn;
3476 unsigned Src = GetOrCreateSourceID(CU.getDirectory(Dir),
3477 CU.getFilename(Fn));
3478 unsigned ID = MMI->NextLabelID();
3479 Lines.push_back(SrcLineInfo(Line, Col, Src, ID));
3481 if (TimePassesIsEnabled)
3482 DebugTimer->stopTimer();
3487 /// getRecordSourceLineCount - Return the number of source lines in the debug
3489 unsigned getRecordSourceLineCount() const {
3490 return Lines.size();
3493 /// getOrCreateSourceID - Public version of GetOrCreateSourceID. This can be
3494 /// timed. Look up the source id with the given directory and source file
3495 /// names. If none currently exists, create a new id and insert it in the
3496 /// SourceIds map. This can update DirectoryNames and SourceFileNames maps as
3498 unsigned getOrCreateSourceID(const std::string &DirName,
3499 const std::string &FileName) {
3500 if (TimePassesIsEnabled)
3501 DebugTimer->startTimer();
3503 unsigned SrcId = GetOrCreateSourceID(DirName, FileName);
3505 if (TimePassesIsEnabled)
3506 DebugTimer->stopTimer();
3511 /// RecordRegionStart - Indicate the start of a region.
3512 unsigned RecordRegionStart(GlobalVariable *V) {
3513 if (TimePassesIsEnabled)
3514 DebugTimer->startTimer();
3516 DbgScope *Scope = getOrCreateScope(V);
3517 unsigned ID = MMI->NextLabelID();
3518 if (!Scope->getStartLabelID()) Scope->setStartLabelID(ID);
3519 LexicalScopeStack.push_back(Scope);
3521 if (TimePassesIsEnabled)
3522 DebugTimer->stopTimer();
3527 /// RecordRegionEnd - Indicate the end of a region.
3528 unsigned RecordRegionEnd(GlobalVariable *V) {
3529 if (TimePassesIsEnabled)
3530 DebugTimer->startTimer();
3532 DbgScope *Scope = getOrCreateScope(V);
3533 unsigned ID = MMI->NextLabelID();
3534 Scope->setEndLabelID(ID);
3535 if (LexicalScopeStack.size() != 0)
3536 LexicalScopeStack.pop_back();
3538 if (TimePassesIsEnabled)
3539 DebugTimer->stopTimer();
3544 /// RecordVariable - Indicate the declaration of a local variable.
3545 void RecordVariable(GlobalVariable *GV, unsigned FrameIndex,
3546 const MachineInstr *MI) {
3547 if (TimePassesIsEnabled)
3548 DebugTimer->startTimer();
3550 DIDescriptor Desc(GV);
3551 DbgScope *Scope = NULL;
3553 if (Desc.getTag() == DW_TAG_variable) {
3554 // GV is a global variable.
3555 DIGlobalVariable DG(GV);
3556 Scope = getOrCreateScope(DG.getContext().getGV());
3558 DenseMap<const MachineInstr *, DbgScope *>::iterator
3559 SI = InlinedVariableScopes.find(MI);
3561 if (SI != InlinedVariableScopes.end()) {
3562 // or GV is an inlined local variable.
3566 GlobalVariable *V = DV.getContext().getGV();
3568 // FIXME: The code that checks for the inlined local variable is a hack!
3569 DenseMap<const GlobalVariable *, DbgScope *>::iterator
3570 AI = AbstractInstanceRootMap.find(V);
3572 if (AI != AbstractInstanceRootMap.end())
3573 // or GV is an inlined local variable.
3576 // or GV is a local variable.
3577 Scope = getOrCreateScope(V);
3581 assert(Scope && "Unable to find variable' scope");
3582 DbgVariable *DV = new DbgVariable(DIVariable(GV), FrameIndex);
3583 Scope->AddVariable(DV);
3585 if (TimePassesIsEnabled)
3586 DebugTimer->stopTimer();
3589 //// RecordInlinedFnStart - Indicate the start of inlined subroutine.
3590 unsigned RecordInlinedFnStart(DISubprogram &SP, DICompileUnit CU,
3591 unsigned Line, unsigned Col) {
3592 unsigned LabelID = MMI->NextLabelID();
3594 if (!TAI->doesDwarfUsesInlineInfoSection())
3597 if (TimePassesIsEnabled)
3598 DebugTimer->startTimer();
3600 GlobalVariable *GV = SP.getGV();
3601 DenseMap<const GlobalVariable *, DbgScope *>::iterator
3602 II = AbstractInstanceRootMap.find(GV);
3604 if (II == AbstractInstanceRootMap.end()) {
3605 // Create an abstract instance entry for this inlined function if it
3606 // doesn't already exist.
3607 DbgScope *Scope = new DbgScope(NULL, DIDescriptor(GV));
3609 // Get the compile unit context.
3610 CompileUnit *Unit = &FindCompileUnit(SP.getCompileUnit());
3611 DIE *SPDie = Unit->getDieMapSlotFor(GV);
3613 SPDie = CreateSubprogramDIE(Unit, SP);
3615 // Mark as being inlined. This makes this subprogram entry an abstract
3617 // FIXME: Our debugger doesn't care about the value of DW_AT_inline, only
3618 // that it's defined. It probably won't change in the future, but this
3619 // could be more elegant.
3620 AddUInt(SPDie, DW_AT_inline, 0, DW_INL_declared_not_inlined);
3622 // Track the start label for this inlined function.
3623 DenseMap<GlobalVariable *, SmallVector<unsigned, 4> >::iterator
3624 I = InlineInfo.find(GV);
3626 if (I == InlineInfo.end())
3627 InlineInfo[GV].push_back(LabelID);
3629 I->second.push_back(LabelID);
3631 AbstractInstanceRootMap[GV] = Scope;
3632 AbstractInstanceRootList.push_back(Scope);
3635 // Create a concrete inlined instance for this inlined function.
3636 DbgConcreteScope *ConcreteScope = new DbgConcreteScope(DIDescriptor(GV));
3637 DIE *ScopeDie = new DIE(DW_TAG_inlined_subroutine);
3638 CompileUnit *Unit = &FindCompileUnit(SP.getCompileUnit());
3639 ScopeDie->setAbstractCompileUnit(Unit);
3641 DIE *Origin = Unit->getDieMapSlotFor(GV);
3642 AddDIEntry(ScopeDie, DW_AT_abstract_origin, DW_FORM_ref4, Origin);
3643 AddUInt(ScopeDie, DW_AT_call_file, 0, Unit->getID());
3644 AddUInt(ScopeDie, DW_AT_call_line, 0, Line);
3645 AddUInt(ScopeDie, DW_AT_call_column, 0, Col);
3647 ConcreteScope->setDie(ScopeDie);
3648 ConcreteScope->setStartLabelID(LabelID);
3650 LexicalScopeStack.back()->AddConcreteInst(ConcreteScope);
3652 // Keep track of the scope that's inlined into this function.
3653 DenseMap<GlobalVariable *, SmallVector<DbgConcreteScope *, 8> >::iterator
3654 SI = DbgConcreteScopeMap.find(GV);
3656 if (SI == DbgConcreteScopeMap.end())
3657 DbgConcreteScopeMap[GV].push_back(ConcreteScope);
3659 SI->second.push_back(ConcreteScope);
3661 if (TimePassesIsEnabled)
3662 DebugTimer->stopTimer();
3667 /// RecordInlinedFnEnd - Indicate the end of inlined subroutine.
3668 unsigned RecordInlinedFnEnd(DISubprogram &SP) {
3669 if (!TAI->doesDwarfUsesInlineInfoSection())
3672 if (TimePassesIsEnabled)
3673 DebugTimer->startTimer();
3675 GlobalVariable *GV = SP.getGV();
3676 DenseMap<GlobalVariable *, SmallVector<DbgConcreteScope *, 8> >::iterator
3677 I = DbgConcreteScopeMap.find(GV);
3679 if (I == DbgConcreteScopeMap.end()) {
3680 if (TimePassesIsEnabled)
3681 DebugTimer->stopTimer();
3686 SmallVector<DbgConcreteScope *, 8> &Scopes = I->second;
3687 assert(!Scopes.empty() && "We should have at least one debug scope!");
3688 DbgConcreteScope *Scope = Scopes.back(); Scopes.pop_back();
3689 unsigned ID = MMI->NextLabelID();
3691 MMI->RecordUsedDbgLabel(ID);
3692 Scope->setEndLabelID(ID);
3694 if (TimePassesIsEnabled)
3695 DebugTimer->stopTimer();
3700 /// RecordVariableScope - Record scope for the variable declared by
3701 /// DeclareMI. DeclareMI must describe TargetInstrInfo::DECLARE.
3702 /// Record scopes for only inlined subroutine variables. Other
3703 /// variables' scopes are determined during RecordVariable().
3704 void RecordVariableScope(DIVariable &DV, const MachineInstr *DeclareMI) {
3705 if (TimePassesIsEnabled)
3706 DebugTimer->startTimer();
3708 DISubprogram SP(DV.getContext().getGV());
3711 if (TimePassesIsEnabled)
3712 DebugTimer->stopTimer();
3717 DenseMap<GlobalVariable *, SmallVector<DbgConcreteScope *, 8> >::iterator
3718 I = DbgConcreteScopeMap.find(SP.getGV());
3719 if (I != DbgConcreteScopeMap.end())
3720 InlinedVariableScopes[DeclareMI] = I->second.back();
3722 if (TimePassesIsEnabled)
3723 DebugTimer->stopTimer();
3727 //===----------------------------------------------------------------------===//
3728 /// DwarfException - Emits Dwarf exception handling directives.
3730 class DwarfException : public Dwarf {
3731 struct FunctionEHFrameInfo {
3734 unsigned PersonalityIndex;
3736 bool hasLandingPads;
3737 std::vector<MachineMove> Moves;
3738 const Function * function;
3740 FunctionEHFrameInfo(const std::string &FN, unsigned Num, unsigned P,
3742 const std::vector<MachineMove> &M,
3744 FnName(FN), Number(Num), PersonalityIndex(P),
3745 hasCalls(hC), hasLandingPads(hL), Moves(M), function (f) { }
3748 std::vector<FunctionEHFrameInfo> EHFrames;
3750 /// shouldEmitTable - Per-function flag to indicate if EH tables should
3752 bool shouldEmitTable;
3754 /// shouldEmitMoves - Per-function flag to indicate if frame moves info
3755 /// should be emitted.
3756 bool shouldEmitMoves;
3758 /// shouldEmitTableModule - Per-module flag to indicate if EH tables
3759 /// should be emitted.
3760 bool shouldEmitTableModule;
3762 /// shouldEmitFrameModule - Per-module flag to indicate if frame moves
3763 /// should be emitted.
3764 bool shouldEmitMovesModule;
3766 /// ExceptionTimer - Timer for the Dwarf exception writer.
3767 Timer *ExceptionTimer;
3769 /// EmitCommonEHFrame - Emit the common eh unwind frame.
3771 void EmitCommonEHFrame(const Function *Personality, unsigned Index) {
3772 // Size and sign of stack growth.
3774 Asm->TM.getFrameInfo()->getStackGrowthDirection() ==
3775 TargetFrameInfo::StackGrowsUp ?
3776 TD->getPointerSize() : -TD->getPointerSize();
3778 // Begin eh frame section.
3779 Asm->SwitchToTextSection(TAI->getDwarfEHFrameSection());
3781 if (!TAI->doesRequireNonLocalEHFrameLabel())
3782 O << TAI->getEHGlobalPrefix();
3783 O << "EH_frame" << Index << ":\n";
3784 EmitLabel("section_eh_frame", Index);
3786 // Define base labels.
3787 EmitLabel("eh_frame_common", Index);
3789 // Define the eh frame length.
3790 EmitDifference("eh_frame_common_end", Index,
3791 "eh_frame_common_begin", Index, true);
3792 Asm->EOL("Length of Common Information Entry");
3795 EmitLabel("eh_frame_common_begin", Index);
3796 Asm->EmitInt32((int)0);
3797 Asm->EOL("CIE Identifier Tag");
3798 Asm->EmitInt8(DW_CIE_VERSION);
3799 Asm->EOL("CIE Version");
3801 // The personality presence indicates that language specific information
3802 // will show up in the eh frame.
3803 Asm->EmitString(Personality ? "zPLR" : "zR");
3804 Asm->EOL("CIE Augmentation");
3806 // Round out reader.
3807 Asm->EmitULEB128Bytes(1);
3808 Asm->EOL("CIE Code Alignment Factor");
3809 Asm->EmitSLEB128Bytes(stackGrowth);
3810 Asm->EOL("CIE Data Alignment Factor");
3811 Asm->EmitInt8(RI->getDwarfRegNum(RI->getRARegister(), true));
3812 Asm->EOL("CIE Return Address Column");
3814 // If there is a personality, we need to indicate the functions location.
3816 Asm->EmitULEB128Bytes(7);
3817 Asm->EOL("Augmentation Size");
3819 if (TAI->getNeedsIndirectEncoding()) {
3820 Asm->EmitInt8(DW_EH_PE_pcrel | DW_EH_PE_sdata4 | DW_EH_PE_indirect);
3821 Asm->EOL("Personality (pcrel sdata4 indirect)");
3823 Asm->EmitInt8(DW_EH_PE_pcrel | DW_EH_PE_sdata4);
3824 Asm->EOL("Personality (pcrel sdata4)");
3827 PrintRelDirective(true);
3828 O << TAI->getPersonalityPrefix();
3829 Asm->EmitExternalGlobal((const GlobalVariable *)(Personality));
3830 O << TAI->getPersonalitySuffix();
3831 if (strcmp(TAI->getPersonalitySuffix(), "+4@GOTPCREL"))
3832 O << "-" << TAI->getPCSymbol();
3833 Asm->EOL("Personality");
3835 Asm->EmitInt8(DW_EH_PE_pcrel | DW_EH_PE_sdata4);
3836 Asm->EOL("LSDA Encoding (pcrel sdata4)");
3838 Asm->EmitInt8(DW_EH_PE_pcrel | DW_EH_PE_sdata4);
3839 Asm->EOL("FDE Encoding (pcrel sdata4)");
3841 Asm->EmitULEB128Bytes(1);
3842 Asm->EOL("Augmentation Size");
3844 Asm->EmitInt8(DW_EH_PE_pcrel | DW_EH_PE_sdata4);
3845 Asm->EOL("FDE Encoding (pcrel sdata4)");
3848 // Indicate locations of general callee saved registers in frame.
3849 std::vector<MachineMove> Moves;
3850 RI->getInitialFrameState(Moves);
3851 EmitFrameMoves(NULL, 0, Moves, true);
3853 // On Darwin the linker honors the alignment of eh_frame, which means it
3854 // must be 8-byte on 64-bit targets to match what gcc does. Otherwise
3855 // you get holes which confuse readers of eh_frame.
3856 Asm->EmitAlignment(TD->getPointerSize() == sizeof(int32_t) ? 2 : 3,
3858 EmitLabel("eh_frame_common_end", Index);
3863 /// EmitEHFrame - Emit function exception frame information.
3865 void EmitEHFrame(const FunctionEHFrameInfo &EHFrameInfo) {
3866 Function::LinkageTypes linkage = EHFrameInfo.function->getLinkage();
3868 assert(!EHFrameInfo.function->hasAvailableExternallyLinkage() &&
3869 "Should not emit 'available externally' functions at all");
3871 Asm->SwitchToTextSection(TAI->getDwarfEHFrameSection());
3873 // Externally visible entry into the functions eh frame info.
3874 // If the corresponding function is static, this should not be
3875 // externally visible.
3876 if (linkage != Function::InternalLinkage &&
3877 linkage != Function::PrivateLinkage) {
3878 if (const char *GlobalEHDirective = TAI->getGlobalEHDirective())
3879 O << GlobalEHDirective << EHFrameInfo.FnName << "\n";
3882 // If corresponding function is weak definition, this should be too.
3883 if ((linkage == Function::WeakAnyLinkage ||
3884 linkage == Function::WeakODRLinkage ||
3885 linkage == Function::LinkOnceAnyLinkage ||
3886 linkage == Function::LinkOnceODRLinkage) &&
3887 TAI->getWeakDefDirective())
3888 O << TAI->getWeakDefDirective() << EHFrameInfo.FnName << "\n";
3890 // If there are no calls then you can't unwind. This may mean we can
3891 // omit the EH Frame, but some environments do not handle weak absolute
3893 // If UnwindTablesMandatory is set we cannot do this optimization; the
3894 // unwind info is to be available for non-EH uses.
3895 if (!EHFrameInfo.hasCalls &&
3896 !UnwindTablesMandatory &&
3897 ((linkage != Function::WeakAnyLinkage &&
3898 linkage != Function::WeakODRLinkage &&
3899 linkage != Function::LinkOnceAnyLinkage &&
3900 linkage != Function::LinkOnceODRLinkage) ||
3901 !TAI->getWeakDefDirective() ||
3902 TAI->getSupportsWeakOmittedEHFrame()))
3904 O << EHFrameInfo.FnName << " = 0\n";
3905 // This name has no connection to the function, so it might get
3906 // dead-stripped when the function is not, erroneously. Prohibit
3907 // dead-stripping unconditionally.
3908 if (const char *UsedDirective = TAI->getUsedDirective())
3909 O << UsedDirective << EHFrameInfo.FnName << "\n\n";
3911 O << EHFrameInfo.FnName << ":\n";
3914 EmitDifference("eh_frame_end", EHFrameInfo.Number,
3915 "eh_frame_begin", EHFrameInfo.Number, true);
3916 Asm->EOL("Length of Frame Information Entry");
3918 EmitLabel("eh_frame_begin", EHFrameInfo.Number);
3920 if (TAI->doesRequireNonLocalEHFrameLabel()) {
3921 PrintRelDirective(true, true);
3922 PrintLabelName("eh_frame_begin", EHFrameInfo.Number);
3924 if (!TAI->isAbsoluteEHSectionOffsets())
3925 O << "-EH_frame" << EHFrameInfo.PersonalityIndex;
3927 EmitSectionOffset("eh_frame_begin", "eh_frame_common",
3928 EHFrameInfo.Number, EHFrameInfo.PersonalityIndex,
3932 Asm->EOL("FDE CIE offset");
3934 EmitReference("eh_func_begin", EHFrameInfo.Number, true, true);
3935 Asm->EOL("FDE initial location");
3936 EmitDifference("eh_func_end", EHFrameInfo.Number,
3937 "eh_func_begin", EHFrameInfo.Number, true);
3938 Asm->EOL("FDE address range");
3940 // If there is a personality and landing pads then point to the language
3941 // specific data area in the exception table.
3942 if (EHFrameInfo.PersonalityIndex) {
3943 Asm->EmitULEB128Bytes(4);
3944 Asm->EOL("Augmentation size");
3946 if (EHFrameInfo.hasLandingPads)
3947 EmitReference("exception", EHFrameInfo.Number, true, true);
3949 Asm->EmitInt32((int)0);
3950 Asm->EOL("Language Specific Data Area");
3952 Asm->EmitULEB128Bytes(0);
3953 Asm->EOL("Augmentation size");
3956 // Indicate locations of function specific callee saved registers in
3958 EmitFrameMoves("eh_func_begin", EHFrameInfo.Number, EHFrameInfo.Moves,
3961 // On Darwin the linker honors the alignment of eh_frame, which means it
3962 // must be 8-byte on 64-bit targets to match what gcc does. Otherwise
3963 // you get holes which confuse readers of eh_frame.
3964 Asm->EmitAlignment(TD->getPointerSize() == sizeof(int32_t) ? 2 : 3,
3966 EmitLabel("eh_frame_end", EHFrameInfo.Number);
3968 // If the function is marked used, this table should be also. We cannot
3969 // make the mark unconditional in this case, since retaining the table
3970 // also retains the function in this case, and there is code around
3971 // that depends on unused functions (calling undefined externals) being
3972 // dead-stripped to link correctly. Yes, there really is.
3973 if (MMI->getUsedFunctions().count(EHFrameInfo.function))
3974 if (const char *UsedDirective = TAI->getUsedDirective())
3975 O << UsedDirective << EHFrameInfo.FnName << "\n\n";
3979 /// EmitExceptionTable - Emit landing pads and actions.
3981 /// The general organization of the table is complex, but the basic concepts
3982 /// are easy. First there is a header which describes the location and
3983 /// organization of the three components that follow.
3984 /// 1. The landing pad site information describes the range of code covered
3985 /// by the try. In our case it's an accumulation of the ranges covered
3986 /// by the invokes in the try. There is also a reference to the landing
3987 /// pad that handles the exception once processed. Finally an index into
3988 /// the actions table.
3989 /// 2. The action table, in our case, is composed of pairs of type ids
3990 /// and next action offset. Starting with the action index from the
3991 /// landing pad site, each type Id is checked for a match to the current
3992 /// exception. If it matches then the exception and type id are passed
3993 /// on to the landing pad. Otherwise the next action is looked up. This
3994 /// chain is terminated with a next action of zero. If no type id is
3995 /// found the the frame is unwound and handling continues.
3996 /// 3. Type id table contains references to all the C++ typeinfo for all
3997 /// catches in the function. This tables is reversed indexed base 1.
3999 /// SharedTypeIds - How many leading type ids two landing pads have in common.
4000 static unsigned SharedTypeIds(const LandingPadInfo *L,
4001 const LandingPadInfo *R) {
4002 const std::vector<int> &LIds = L->TypeIds, &RIds = R->TypeIds;
4003 unsigned LSize = LIds.size(), RSize = RIds.size();
4004 unsigned MinSize = LSize < RSize ? LSize : RSize;
4007 for (; Count != MinSize; ++Count)
4008 if (LIds[Count] != RIds[Count])
4014 /// PadLT - Order landing pads lexicographically by type id.
4015 static bool PadLT(const LandingPadInfo *L, const LandingPadInfo *R) {
4016 const std::vector<int> &LIds = L->TypeIds, &RIds = R->TypeIds;
4017 unsigned LSize = LIds.size(), RSize = RIds.size();
4018 unsigned MinSize = LSize < RSize ? LSize : RSize;
4020 for (unsigned i = 0; i != MinSize; ++i)
4021 if (LIds[i] != RIds[i])
4022 return LIds[i] < RIds[i];
4024 return LSize < RSize;
4028 static inline unsigned getEmptyKey() { return -1U; }
4029 static inline unsigned getTombstoneKey() { return -2U; }
4030 static unsigned getHashValue(const unsigned &Key) { return Key; }
4031 static bool isEqual(unsigned LHS, unsigned RHS) { return LHS == RHS; }
4032 static bool isPod() { return true; }
4035 /// ActionEntry - Structure describing an entry in the actions table.
4036 struct ActionEntry {
4037 int ValueForTypeID; // The value to write - may not be equal to the type id.
4039 struct ActionEntry *Previous;
4042 /// PadRange - Structure holding a try-range and the associated landing pad.
4044 // The index of the landing pad.
4046 // The index of the begin and end labels in the landing pad's label lists.
4047 unsigned RangeIndex;
4050 typedef DenseMap<unsigned, PadRange, KeyInfo> RangeMapType;
4052 /// CallSiteEntry - Structure describing an entry in the call-site table.
4053 struct CallSiteEntry {
4054 // The 'try-range' is BeginLabel .. EndLabel.
4055 unsigned BeginLabel; // zero indicates the start of the function.
4056 unsigned EndLabel; // zero indicates the end of the function.
4057 // The landing pad starts at PadLabel.
4058 unsigned PadLabel; // zero indicates that there is no landing pad.
4062 void EmitExceptionTable() {
4063 const std::vector<GlobalVariable *> &TypeInfos = MMI->getTypeInfos();
4064 const std::vector<unsigned> &FilterIds = MMI->getFilterIds();
4065 const std::vector<LandingPadInfo> &PadInfos = MMI->getLandingPads();
4066 if (PadInfos.empty()) return;
4068 // Sort the landing pads in order of their type ids. This is used to fold
4069 // duplicate actions.
4070 SmallVector<const LandingPadInfo *, 64> LandingPads;
4071 LandingPads.reserve(PadInfos.size());
4072 for (unsigned i = 0, N = PadInfos.size(); i != N; ++i)
4073 LandingPads.push_back(&PadInfos[i]);
4074 std::sort(LandingPads.begin(), LandingPads.end(), PadLT);
4076 // Negative type ids index into FilterIds, positive type ids index into
4077 // TypeInfos. The value written for a positive type id is just the type
4078 // id itself. For a negative type id, however, the value written is the
4079 // (negative) byte offset of the corresponding FilterIds entry. The byte
4080 // offset is usually equal to the type id, because the FilterIds entries
4081 // are written using a variable width encoding which outputs one byte per
4082 // entry as long as the value written is not too large, but can differ.
4083 // This kind of complication does not occur for positive type ids because
4084 // type infos are output using a fixed width encoding.
4085 // FilterOffsets[i] holds the byte offset corresponding to FilterIds[i].
4086 SmallVector<int, 16> FilterOffsets;
4087 FilterOffsets.reserve(FilterIds.size());
4089 for(std::vector<unsigned>::const_iterator I = FilterIds.begin(),
4090 E = FilterIds.end(); I != E; ++I) {
4091 FilterOffsets.push_back(Offset);
4092 Offset -= TargetAsmInfo::getULEB128Size(*I);
4095 // Compute the actions table and gather the first action index for each
4096 // landing pad site.
4097 SmallVector<ActionEntry, 32> Actions;
4098 SmallVector<unsigned, 64> FirstActions;
4099 FirstActions.reserve(LandingPads.size());
4101 int FirstAction = 0;
4102 unsigned SizeActions = 0;
4103 for (unsigned i = 0, N = LandingPads.size(); i != N; ++i) {
4104 const LandingPadInfo *LP = LandingPads[i];
4105 const std::vector<int> &TypeIds = LP->TypeIds;
4106 const unsigned NumShared = i ? SharedTypeIds(LP, LandingPads[i-1]) : 0;
4107 unsigned SizeSiteActions = 0;
4109 if (NumShared < TypeIds.size()) {
4110 unsigned SizeAction = 0;
4111 ActionEntry *PrevAction = 0;
4114 const unsigned SizePrevIds = LandingPads[i-1]->TypeIds.size();
4115 assert(Actions.size());
4116 PrevAction = &Actions.back();
4117 SizeAction = TargetAsmInfo::getSLEB128Size(PrevAction->NextAction) +
4118 TargetAsmInfo::getSLEB128Size(PrevAction->ValueForTypeID);
4119 for (unsigned j = NumShared; j != SizePrevIds; ++j) {
4121 TargetAsmInfo::getSLEB128Size(PrevAction->ValueForTypeID);
4122 SizeAction += -PrevAction->NextAction;
4123 PrevAction = PrevAction->Previous;
4127 // Compute the actions.
4128 for (unsigned I = NumShared, M = TypeIds.size(); I != M; ++I) {
4129 int TypeID = TypeIds[I];
4130 assert(-1-TypeID < (int)FilterOffsets.size() && "Unknown filter id!");
4131 int ValueForTypeID = TypeID < 0 ? FilterOffsets[-1 - TypeID] : TypeID;
4132 unsigned SizeTypeID = TargetAsmInfo::getSLEB128Size(ValueForTypeID);
4134 int NextAction = SizeAction ? -(SizeAction + SizeTypeID) : 0;
4135 SizeAction = SizeTypeID + TargetAsmInfo::getSLEB128Size(NextAction);
4136 SizeSiteActions += SizeAction;
4138 ActionEntry Action = {ValueForTypeID, NextAction, PrevAction};
4139 Actions.push_back(Action);
4141 PrevAction = &Actions.back();
4144 // Record the first action of the landing pad site.
4145 FirstAction = SizeActions + SizeSiteActions - SizeAction + 1;
4146 } // else identical - re-use previous FirstAction
4148 FirstActions.push_back(FirstAction);
4150 // Compute this sites contribution to size.
4151 SizeActions += SizeSiteActions;
4154 // Compute the call-site table. The entry for an invoke has a try-range
4155 // containing the call, a non-zero landing pad and an appropriate action.
4156 // The entry for an ordinary call has a try-range containing the call and
4157 // zero for the landing pad and the action. Calls marked 'nounwind' have
4158 // no entry and must not be contained in the try-range of any entry - they
4159 // form gaps in the table. Entries must be ordered by try-range address.
4160 SmallVector<CallSiteEntry, 64> CallSites;
4162 RangeMapType PadMap;
4163 // Invokes and nounwind calls have entries in PadMap (due to being bracketed
4164 // by try-range labels when lowered). Ordinary calls do not, so appropriate
4165 // try-ranges for them need be deduced.
4166 for (unsigned i = 0, N = LandingPads.size(); i != N; ++i) {
4167 const LandingPadInfo *LandingPad = LandingPads[i];
4168 for (unsigned j = 0, E = LandingPad->BeginLabels.size(); j != E; ++j) {
4169 unsigned BeginLabel = LandingPad->BeginLabels[j];
4170 assert(!PadMap.count(BeginLabel) && "Duplicate landing pad labels!");
4171 PadRange P = { i, j };
4172 PadMap[BeginLabel] = P;
4176 // The end label of the previous invoke or nounwind try-range.
4177 unsigned LastLabel = 0;
4179 // Whether there is a potentially throwing instruction (currently this means
4180 // an ordinary call) between the end of the previous try-range and now.
4181 bool SawPotentiallyThrowing = false;
4183 // Whether the last callsite entry was for an invoke.
4184 bool PreviousIsInvoke = false;
4186 // Visit all instructions in order of address.
4187 for (MachineFunction::const_iterator I = MF->begin(), E = MF->end();
4189 for (MachineBasicBlock::const_iterator MI = I->begin(), E = I->end();
4191 if (!MI->isLabel()) {
4192 SawPotentiallyThrowing |= MI->getDesc().isCall();
4196 unsigned BeginLabel = MI->getOperand(0).getImm();
4197 assert(BeginLabel && "Invalid label!");
4199 // End of the previous try-range?
4200 if (BeginLabel == LastLabel)
4201 SawPotentiallyThrowing = false;
4203 // Beginning of a new try-range?
4204 RangeMapType::iterator L = PadMap.find(BeginLabel);
4205 if (L == PadMap.end())
4206 // Nope, it was just some random label.
4209 PadRange P = L->second;
4210 const LandingPadInfo *LandingPad = LandingPads[P.PadIndex];
4212 assert(BeginLabel == LandingPad->BeginLabels[P.RangeIndex] &&
4213 "Inconsistent landing pad map!");
4215 // If some instruction between the previous try-range and this one may
4216 // throw, create a call-site entry with no landing pad for the region
4217 // between the try-ranges.
4218 if (SawPotentiallyThrowing) {
4219 CallSiteEntry Site = {LastLabel, BeginLabel, 0, 0};
4220 CallSites.push_back(Site);
4221 PreviousIsInvoke = false;
4224 LastLabel = LandingPad->EndLabels[P.RangeIndex];
4225 assert(BeginLabel && LastLabel && "Invalid landing pad!");
4227 if (LandingPad->LandingPadLabel) {
4228 // This try-range is for an invoke.
4229 CallSiteEntry Site = {BeginLabel, LastLabel,
4230 LandingPad->LandingPadLabel, FirstActions[P.PadIndex]};
4232 // Try to merge with the previous call-site.
4233 if (PreviousIsInvoke) {
4234 CallSiteEntry &Prev = CallSites.back();
4235 if (Site.PadLabel == Prev.PadLabel && Site.Action == Prev.Action) {
4236 // Extend the range of the previous entry.
4237 Prev.EndLabel = Site.EndLabel;
4242 // Otherwise, create a new call-site.
4243 CallSites.push_back(Site);
4244 PreviousIsInvoke = true;
4247 PreviousIsInvoke = false;
4251 // If some instruction between the previous try-range and the end of the
4252 // function may throw, create a call-site entry with no landing pad for the
4253 // region following the try-range.
4254 if (SawPotentiallyThrowing) {
4255 CallSiteEntry Site = {LastLabel, 0, 0, 0};
4256 CallSites.push_back(Site);
4262 const unsigned SiteStartSize = sizeof(int32_t); // DW_EH_PE_udata4
4263 const unsigned SiteLengthSize = sizeof(int32_t); // DW_EH_PE_udata4
4264 const unsigned LandingPadSize = sizeof(int32_t); // DW_EH_PE_udata4
4265 unsigned SizeSites = CallSites.size() * (SiteStartSize +
4268 for (unsigned i = 0, e = CallSites.size(); i < e; ++i)
4269 SizeSites += TargetAsmInfo::getULEB128Size(CallSites[i].Action);
4272 const unsigned TypeInfoSize = TD->getPointerSize(); // DW_EH_PE_absptr
4273 unsigned SizeTypes = TypeInfos.size() * TypeInfoSize;
4275 unsigned TypeOffset = sizeof(int8_t) + // Call site format
4276 TargetAsmInfo::getULEB128Size(SizeSites) + // Call-site table length
4277 SizeSites + SizeActions + SizeTypes;
4279 unsigned TotalSize = sizeof(int8_t) + // LPStart format
4280 sizeof(int8_t) + // TType format
4281 TargetAsmInfo::getULEB128Size(TypeOffset) + // TType base offset
4284 unsigned SizeAlign = (4 - TotalSize) & 3;
4286 // Begin the exception table.
4287 Asm->SwitchToDataSection(TAI->getDwarfExceptionSection());
4288 Asm->EmitAlignment(2, 0, 0, false);
4289 O << "GCC_except_table" << SubprogramCount << ":\n";
4290 for (unsigned i = 0; i != SizeAlign; ++i) {
4292 Asm->EOL("Padding");
4294 EmitLabel("exception", SubprogramCount);
4297 Asm->EmitInt8(DW_EH_PE_omit);
4298 Asm->EOL("LPStart format (DW_EH_PE_omit)");
4299 Asm->EmitInt8(DW_EH_PE_absptr);
4300 Asm->EOL("TType format (DW_EH_PE_absptr)");
4301 Asm->EmitULEB128Bytes(TypeOffset);
4302 Asm->EOL("TType base offset");
4303 Asm->EmitInt8(DW_EH_PE_udata4);
4304 Asm->EOL("Call site format (DW_EH_PE_udata4)");
4305 Asm->EmitULEB128Bytes(SizeSites);
4306 Asm->EOL("Call-site table length");
4308 // Emit the landing pad site information.
4309 for (unsigned i = 0; i < CallSites.size(); ++i) {
4310 CallSiteEntry &S = CallSites[i];
4311 const char *BeginTag;
4312 unsigned BeginNumber;
4314 if (!S.BeginLabel) {
4315 BeginTag = "eh_func_begin";
4316 BeginNumber = SubprogramCount;
4319 BeginNumber = S.BeginLabel;
4322 EmitSectionOffset(BeginTag, "eh_func_begin", BeginNumber, SubprogramCount,
4324 Asm->EOL("Region start");
4327 EmitDifference("eh_func_end", SubprogramCount, BeginTag, BeginNumber,
4330 EmitDifference("label", S.EndLabel, BeginTag, BeginNumber, true);
4332 Asm->EOL("Region length");
4337 EmitSectionOffset("label", "eh_func_begin", S.PadLabel, SubprogramCount,
4339 Asm->EOL("Landing pad");
4341 Asm->EmitULEB128Bytes(S.Action);
4345 // Emit the actions.
4346 for (unsigned I = 0, N = Actions.size(); I != N; ++I) {
4347 ActionEntry &Action = Actions[I];
4349 Asm->EmitSLEB128Bytes(Action.ValueForTypeID);
4350 Asm->EOL("TypeInfo index");
4351 Asm->EmitSLEB128Bytes(Action.NextAction);
4352 Asm->EOL("Next action");
4355 // Emit the type ids.
4356 for (unsigned M = TypeInfos.size(); M; --M) {
4357 GlobalVariable *GV = TypeInfos[M - 1];
4359 PrintRelDirective();
4363 O << Asm->getGlobalLinkName(GV, GLN);
4368 Asm->EOL("TypeInfo");
4371 // Emit the filter typeids.
4372 for (unsigned j = 0, M = FilterIds.size(); j < M; ++j) {
4373 unsigned TypeID = FilterIds[j];
4374 Asm->EmitULEB128Bytes(TypeID);
4375 Asm->EOL("Filter TypeInfo index");
4378 Asm->EmitAlignment(2, 0, 0, false);
4382 //===--------------------------------------------------------------------===//
4383 // Main entry points.
4385 DwarfException(raw_ostream &OS, AsmPrinter *A, const TargetAsmInfo *T)
4386 : Dwarf(OS, A, T, "eh"), shouldEmitTable(false), shouldEmitMoves(false),
4387 shouldEmitTableModule(false), shouldEmitMovesModule(false),
4389 if (TimePassesIsEnabled)
4390 ExceptionTimer = new Timer("Dwarf Exception Writer",
4391 getDwarfTimerGroup());
4394 virtual ~DwarfException() {
4395 delete ExceptionTimer;
4398 /// SetModuleInfo - Set machine module information when it's known that pass
4399 /// manager has created it. Set by the target AsmPrinter.
4400 void SetModuleInfo(MachineModuleInfo *mmi) {
4404 /// BeginModule - Emit all exception information that should come prior to the
4406 void BeginModule(Module *M) {
4410 /// EndModule - Emit all exception information that should come after the
4413 if (TimePassesIsEnabled)
4414 ExceptionTimer->startTimer();
4416 if (shouldEmitMovesModule || shouldEmitTableModule) {
4417 const std::vector<Function *> Personalities = MMI->getPersonalities();
4418 for (unsigned i = 0; i < Personalities.size(); ++i)
4419 EmitCommonEHFrame(Personalities[i], i);
4421 for (std::vector<FunctionEHFrameInfo>::iterator I = EHFrames.begin(),
4422 E = EHFrames.end(); I != E; ++I)
4426 if (TimePassesIsEnabled)
4427 ExceptionTimer->stopTimer();
4430 /// BeginFunction - Gather pre-function exception information. Assumes being
4431 /// emitted immediately after the function entry point.
4432 void BeginFunction(MachineFunction *MF) {
4433 if (TimePassesIsEnabled)
4434 ExceptionTimer->startTimer();
4437 shouldEmitTable = shouldEmitMoves = false;
4439 if (MMI && TAI->doesSupportExceptionHandling()) {
4440 // Map all labels and get rid of any dead landing pads.
4441 MMI->TidyLandingPads();
4443 // If any landing pads survive, we need an EH table.
4444 if (MMI->getLandingPads().size())
4445 shouldEmitTable = true;
4447 // See if we need frame move info.
4448 if (!MF->getFunction()->doesNotThrow() || UnwindTablesMandatory)
4449 shouldEmitMoves = true;
4451 if (shouldEmitMoves || shouldEmitTable)
4452 // Assumes in correct section after the entry point.
4453 EmitLabel("eh_func_begin", ++SubprogramCount);
4456 shouldEmitTableModule |= shouldEmitTable;
4457 shouldEmitMovesModule |= shouldEmitMoves;
4459 if (TimePassesIsEnabled)
4460 ExceptionTimer->stopTimer();
4463 /// EndFunction - Gather and emit post-function exception information.
4465 void EndFunction() {
4466 if (TimePassesIsEnabled)
4467 ExceptionTimer->startTimer();
4469 if (shouldEmitMoves || shouldEmitTable) {
4470 EmitLabel("eh_func_end", SubprogramCount);
4471 EmitExceptionTable();
4473 // Save EH frame information
4476 FunctionEHFrameInfo(getAsm()->getCurrentFunctionEHName(MF, Name),
4478 MMI->getPersonalityIndex(),
4479 MF->getFrameInfo()->hasCalls(),
4480 !MMI->getLandingPads().empty(),
4481 MMI->getFrameMoves(),
4482 MF->getFunction()));
4485 if (TimePassesIsEnabled)
4486 ExceptionTimer->stopTimer();
4490 } // End of namespace llvm
4492 //===----------------------------------------------------------------------===//
4494 /// Emit - Print the abbreviation using the specified Dwarf writer.
4496 void DIEAbbrev::Emit(const DwarfDebug &DD) const {
4497 // Emit its Dwarf tag type.
4498 DD.getAsm()->EmitULEB128Bytes(Tag);
4499 DD.getAsm()->EOL(TagString(Tag));
4501 // Emit whether it has children DIEs.
4502 DD.getAsm()->EmitULEB128Bytes(ChildrenFlag);
4503 DD.getAsm()->EOL(ChildrenString(ChildrenFlag));
4505 // For each attribute description.
4506 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
4507 const DIEAbbrevData &AttrData = Data[i];
4509 // Emit attribute type.
4510 DD.getAsm()->EmitULEB128Bytes(AttrData.getAttribute());
4511 DD.getAsm()->EOL(AttributeString(AttrData.getAttribute()));
4514 DD.getAsm()->EmitULEB128Bytes(AttrData.getForm());
4515 DD.getAsm()->EOL(FormEncodingString(AttrData.getForm()));
4518 // Mark end of abbreviation.
4519 DD.getAsm()->EmitULEB128Bytes(0); DD.getAsm()->EOL("EOM(1)");
4520 DD.getAsm()->EmitULEB128Bytes(0); DD.getAsm()->EOL("EOM(2)");
4524 void DIEAbbrev::print(std::ostream &O) {
4525 O << "Abbreviation @"
4526 << std::hex << (intptr_t)this << std::dec
4530 << ChildrenString(ChildrenFlag)
4533 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
4535 << AttributeString(Data[i].getAttribute())
4537 << FormEncodingString(Data[i].getForm())
4541 void DIEAbbrev::dump() { print(cerr); }
4544 //===----------------------------------------------------------------------===//
4547 void DIEValue::dump() {
4552 //===----------------------------------------------------------------------===//
4554 /// EmitValue - Emit integer of appropriate size.
4556 void DIEInteger::EmitValue(DwarfDebug &DD, unsigned Form) {
4558 case DW_FORM_flag: // Fall thru
4559 case DW_FORM_ref1: // Fall thru
4560 case DW_FORM_data1: DD.getAsm()->EmitInt8(Integer); break;
4561 case DW_FORM_ref2: // Fall thru
4562 case DW_FORM_data2: DD.getAsm()->EmitInt16(Integer); break;
4563 case DW_FORM_ref4: // Fall thru
4564 case DW_FORM_data4: DD.getAsm()->EmitInt32(Integer); break;
4565 case DW_FORM_ref8: // Fall thru
4566 case DW_FORM_data8: DD.getAsm()->EmitInt64(Integer); break;
4567 case DW_FORM_udata: DD.getAsm()->EmitULEB128Bytes(Integer); break;
4568 case DW_FORM_sdata: DD.getAsm()->EmitSLEB128Bytes(Integer); break;
4569 default: assert(0 && "DIE Value form not supported yet"); break;
4573 /// SizeOf - Determine size of integer value in bytes.
4575 unsigned DIEInteger::SizeOf(const DwarfDebug &DD, unsigned Form) const {
4577 case DW_FORM_flag: // Fall thru
4578 case DW_FORM_ref1: // Fall thru
4579 case DW_FORM_data1: return sizeof(int8_t);
4580 case DW_FORM_ref2: // Fall thru
4581 case DW_FORM_data2: return sizeof(int16_t);
4582 case DW_FORM_ref4: // Fall thru
4583 case DW_FORM_data4: return sizeof(int32_t);
4584 case DW_FORM_ref8: // Fall thru
4585 case DW_FORM_data8: return sizeof(int64_t);
4586 case DW_FORM_udata: return TargetAsmInfo::getULEB128Size(Integer);
4587 case DW_FORM_sdata: return TargetAsmInfo::getSLEB128Size(Integer);
4588 default: assert(0 && "DIE Value form not supported yet"); break;
4593 //===----------------------------------------------------------------------===//
4595 /// EmitValue - Emit string value.
4597 void DIEString::EmitValue(DwarfDebug &DD, unsigned Form) {
4598 DD.getAsm()->EmitString(Str);
4601 //===----------------------------------------------------------------------===//
4603 /// EmitValue - Emit label value.
4605 void DIEDwarfLabel::EmitValue(DwarfDebug &DD, unsigned Form) {
4606 bool IsSmall = Form == DW_FORM_data4;
4607 DD.EmitReference(Label, false, IsSmall);
4610 /// SizeOf - Determine size of label value in bytes.
4612 unsigned DIEDwarfLabel::SizeOf(const DwarfDebug &DD, unsigned Form) const {
4613 if (Form == DW_FORM_data4) return 4;
4614 return DD.getTargetData()->getPointerSize();
4617 //===----------------------------------------------------------------------===//
4619 /// EmitValue - Emit label value.
4621 void DIEObjectLabel::EmitValue(DwarfDebug &DD, unsigned Form) {
4622 bool IsSmall = Form == DW_FORM_data4;
4623 DD.EmitReference(Label, false, IsSmall);
4626 /// SizeOf - Determine size of label value in bytes.
4628 unsigned DIEObjectLabel::SizeOf(const DwarfDebug &DD, unsigned Form) const {
4629 if (Form == DW_FORM_data4) return 4;
4630 return DD.getTargetData()->getPointerSize();
4633 //===----------------------------------------------------------------------===//
4635 /// EmitValue - Emit delta value.
4637 void DIESectionOffset::EmitValue(DwarfDebug &DD, unsigned Form) {
4638 bool IsSmall = Form == DW_FORM_data4;
4639 DD.EmitSectionOffset(Label.Tag, Section.Tag,
4640 Label.Number, Section.Number, IsSmall, IsEH, UseSet);
4643 /// SizeOf - Determine size of delta value in bytes.
4645 unsigned DIESectionOffset::SizeOf(const DwarfDebug &DD, unsigned Form) const {
4646 if (Form == DW_FORM_data4) return 4;
4647 return DD.getTargetData()->getPointerSize();
4650 //===----------------------------------------------------------------------===//
4652 /// EmitValue - Emit delta value.
4654 void DIEDelta::EmitValue(DwarfDebug &DD, unsigned Form) {
4655 bool IsSmall = Form == DW_FORM_data4;
4656 DD.EmitDifference(LabelHi, LabelLo, IsSmall);
4659 /// SizeOf - Determine size of delta value in bytes.
4661 unsigned DIEDelta::SizeOf(const DwarfDebug &DD, unsigned Form) const {
4662 if (Form == DW_FORM_data4) return 4;
4663 return DD.getTargetData()->getPointerSize();
4666 //===----------------------------------------------------------------------===//
4668 /// EmitValue - Emit debug information entry offset.
4670 void DIEntry::EmitValue(DwarfDebug &DD, unsigned Form) {
4671 DD.getAsm()->EmitInt32(Entry->getOffset());
4674 //===----------------------------------------------------------------------===//
4676 /// ComputeSize - calculate the size of the block.
4678 unsigned DIEBlock::ComputeSize(DwarfDebug &DD) {
4680 const SmallVector<DIEAbbrevData, 8> &AbbrevData = Abbrev.getData();
4682 for (unsigned i = 0, N = Values.size(); i < N; ++i) {
4683 Size += Values[i]->SizeOf(DD, AbbrevData[i].getForm());
4689 /// EmitValue - Emit block data.
4691 void DIEBlock::EmitValue(DwarfDebug &DD, unsigned Form) {
4693 case DW_FORM_block1: DD.getAsm()->EmitInt8(Size); break;
4694 case DW_FORM_block2: DD.getAsm()->EmitInt16(Size); break;
4695 case DW_FORM_block4: DD.getAsm()->EmitInt32(Size); break;
4696 case DW_FORM_block: DD.getAsm()->EmitULEB128Bytes(Size); break;
4697 default: assert(0 && "Improper form for block"); break;
4700 const SmallVector<DIEAbbrevData, 8> &AbbrevData = Abbrev.getData();
4702 for (unsigned i = 0, N = Values.size(); i < N; ++i) {
4704 Values[i]->EmitValue(DD, AbbrevData[i].getForm());
4708 /// SizeOf - Determine size of block data in bytes.
4710 unsigned DIEBlock::SizeOf(const DwarfDebug &DD, unsigned Form) const {
4712 case DW_FORM_block1: return Size + sizeof(int8_t);
4713 case DW_FORM_block2: return Size + sizeof(int16_t);
4714 case DW_FORM_block4: return Size + sizeof(int32_t);
4715 case DW_FORM_block: return Size + TargetAsmInfo::getULEB128Size(Size);
4716 default: assert(0 && "Improper form for block"); break;
4721 //===----------------------------------------------------------------------===//
4722 /// DIE Implementation
4725 for (unsigned i = 0, N = Children.size(); i < N; ++i)
4729 /// AddSiblingOffset - Add a sibling offset field to the front of the DIE.
4731 void DIE::AddSiblingOffset() {
4732 DIEInteger *DI = new DIEInteger(0);
4733 Values.insert(Values.begin(), DI);
4734 Abbrev.AddFirstAttribute(DW_AT_sibling, DW_FORM_ref4);
4737 /// Profile - Used to gather unique data for the value folding set.
4739 void DIE::Profile(FoldingSetNodeID &ID) {
4742 for (unsigned i = 0, N = Children.size(); i < N; ++i)
4743 ID.AddPointer(Children[i]);
4745 for (unsigned j = 0, M = Values.size(); j < M; ++j)
4746 ID.AddPointer(Values[j]);
4750 void DIE::print(std::ostream &O, unsigned IncIndent) {
4751 static unsigned IndentCount = 0;
4752 IndentCount += IncIndent;
4753 const std::string Indent(IndentCount, ' ');
4754 bool isBlock = Abbrev.getTag() == 0;
4759 << "0x" << std::hex << (intptr_t)this << std::dec
4760 << ", Offset: " << Offset
4761 << ", Size: " << Size
4765 << TagString(Abbrev.getTag())
4767 << ChildrenString(Abbrev.getChildrenFlag());
4769 O << "Size: " << Size;
4773 const SmallVector<DIEAbbrevData, 8> &Data = Abbrev.getData();
4776 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
4780 O << AttributeString(Data[i].getAttribute());
4782 O << "Blk[" << i << "]";
4785 << FormEncodingString(Data[i].getForm())
4787 Values[i]->print(O);
4792 for (unsigned j = 0, M = Children.size(); j < M; ++j) {
4793 Children[j]->print(O, 4);
4796 if (!isBlock) O << "\n";
4797 IndentCount -= IncIndent;
4805 //===----------------------------------------------------------------------===//
4806 /// DwarfWriter Implementation
4809 DwarfWriter::DwarfWriter()
4810 : ImmutablePass(&ID), DD(0), DE(0) {}
4812 DwarfWriter::~DwarfWriter() {
4817 /// BeginModule - Emit all Dwarf sections that should come prior to the
4819 void DwarfWriter::BeginModule(Module *M,
4820 MachineModuleInfo *MMI,
4821 raw_ostream &OS, AsmPrinter *A,
4822 const TargetAsmInfo *T) {
4823 DE = new DwarfException(OS, A, T);
4824 DD = new DwarfDebug(OS, A, T);
4827 DD->SetDebugInfo(MMI);
4828 DE->SetModuleInfo(MMI);
4831 /// EndModule - Emit all Dwarf sections that should come after the content.
4833 void DwarfWriter::EndModule() {
4838 /// BeginFunction - Gather pre-function debug information. Assumes being
4839 /// emitted immediately after the function entry point.
4840 void DwarfWriter::BeginFunction(MachineFunction *MF) {
4841 DE->BeginFunction(MF);
4842 DD->BeginFunction(MF);
4845 /// EndFunction - Gather and emit post-function debug information.
4847 void DwarfWriter::EndFunction(MachineFunction *MF) {
4848 DD->EndFunction(MF);
4851 if (MachineModuleInfo *MMI = DD->getMMI() ? DD->getMMI() : DE->getMMI())
4852 // Clear function debug information.
4856 /// RecordSourceLine - Records location information and associates it with a
4857 /// label. Returns a unique label ID used to generate a label and provide
4858 /// correspondence to the source line list.
4859 unsigned DwarfWriter::RecordSourceLine(unsigned Line, unsigned Col,
4861 return DD->RecordSourceLine(Line, Col, CU);
4864 /// RecordRegionStart - Indicate the start of a region.
4865 unsigned DwarfWriter::RecordRegionStart(GlobalVariable *V) {
4866 return DD->RecordRegionStart(V);
4869 /// RecordRegionEnd - Indicate the end of a region.
4870 unsigned DwarfWriter::RecordRegionEnd(GlobalVariable *V) {
4871 return DD->RecordRegionEnd(V);
4874 /// getRecordSourceLineCount - Count source lines.
4875 unsigned DwarfWriter::getRecordSourceLineCount() {
4876 return DD->getRecordSourceLineCount();
4879 /// RecordVariable - Indicate the declaration of a local variable.
4881 void DwarfWriter::RecordVariable(GlobalVariable *GV, unsigned FrameIndex,
4882 const MachineInstr *MI) {
4883 DD->RecordVariable(GV, FrameIndex, MI);
4886 /// ShouldEmitDwarfDebug - Returns true if Dwarf debugging declarations should
4888 bool DwarfWriter::ShouldEmitDwarfDebug() const {
4889 return DD && DD->ShouldEmitDwarfDebug();
4892 //// RecordInlinedFnStart - Global variable GV is inlined at the location marked
4893 //// by LabelID label.
4894 unsigned DwarfWriter::RecordInlinedFnStart(DISubprogram SP, DICompileUnit CU,
4895 unsigned Line, unsigned Col) {
4896 return DD->RecordInlinedFnStart(SP, CU, Line, Col);
4899 /// RecordInlinedFnEnd - Indicate the end of inlined subroutine.
4900 unsigned DwarfWriter::RecordInlinedFnEnd(DISubprogram SP) {
4901 return DD->RecordInlinedFnEnd(SP);
4904 /// RecordVariableScope - Record scope for the variable declared by
4905 /// DeclareMI. DeclareMI must describe TargetInstrInfo::DECLARE.
4906 void DwarfWriter::RecordVariableScope(DIVariable &DV,
4907 const MachineInstr *DeclareMI) {
4908 DD->RecordVariableScope(DV, DeclareMI);