1 //===-- llvm/CodeGen/DwarfWriter.cpp - Dwarf Framework ----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by James M. Laskey and is distributed under the
6 // University of Illinois Open Source 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"
16 #include "llvm/ADT/FoldingSet.h"
17 #include "llvm/ADT/StringExtras.h"
18 #include "llvm/ADT/UniqueVector.h"
19 #include "llvm/Module.h"
20 #include "llvm/Type.h"
21 #include "llvm/CodeGen/AsmPrinter.h"
22 #include "llvm/CodeGen/MachineModuleInfo.h"
23 #include "llvm/CodeGen/MachineFrameInfo.h"
24 #include "llvm/CodeGen/MachineLocation.h"
25 #include "llvm/Support/Dwarf.h"
26 #include "llvm/Support/CommandLine.h"
27 #include "llvm/Support/DataTypes.h"
28 #include "llvm/Support/Mangler.h"
29 #include "llvm/Target/TargetAsmInfo.h"
30 #include "llvm/Target/MRegisterInfo.h"
31 #include "llvm/Target/TargetData.h"
32 #include "llvm/Target/TargetFrameInfo.h"
33 #include "llvm/Target/TargetMachine.h"
37 using namespace llvm::dwarf;
41 //===----------------------------------------------------------------------===//
43 /// Configuration values for initial hash set sizes (log2).
45 static const unsigned InitDiesSetSize = 9; // 512
46 static const unsigned InitAbbreviationsSetSize = 9; // 512
47 static const unsigned InitValuesSetSize = 9; // 512
49 //===----------------------------------------------------------------------===//
50 /// Forward declarations.
55 //===----------------------------------------------------------------------===//
56 /// DWLabel - Labels are used to track locations in the assembler file.
57 /// Labels appear in the form <prefix>debug_<Tag><Number>, where the tag is a
58 /// category of label (Ex. location) and number is a value unique in that
62 /// Tag - Label category tag. Should always be a staticly declared C string.
66 /// Number - Value to make label unique.
70 DWLabel(const char *T, unsigned N) : Tag(T), Number(N) {}
72 void Profile(FoldingSetNodeID &ID) const {
73 ID.AddString(std::string(Tag));
74 ID.AddInteger(Number);
78 void print(std::ostream *O) const {
81 void print(std::ostream &O) const {
82 O << ".debug_" << Tag;
83 if (Number) O << Number;
88 //===----------------------------------------------------------------------===//
89 /// DIEAbbrevData - Dwarf abbreviation data, describes the one attribute of a
90 /// Dwarf abbreviation.
93 /// Attribute - Dwarf attribute code.
97 /// Form - Dwarf form code.
102 DIEAbbrevData(unsigned A, unsigned F)
108 unsigned getAttribute() const { return Attribute; }
109 unsigned getForm() const { return Form; }
111 /// Profile - Used to gather unique data for the abbreviation folding set.
113 void Profile(FoldingSetNodeID &ID)const {
114 ID.AddInteger(Attribute);
119 //===----------------------------------------------------------------------===//
120 /// DIEAbbrev - Dwarf abbreviation, describes the organization of a debug
121 /// information object.
122 class DIEAbbrev : public FoldingSetNode {
124 /// Tag - Dwarf tag code.
128 /// Unique number for node.
132 /// ChildrenFlag - Dwarf children flag.
134 unsigned ChildrenFlag;
136 /// Data - Raw data bytes for abbreviation.
138 std::vector<DIEAbbrevData> Data;
142 DIEAbbrev(unsigned T, unsigned C)
150 unsigned getTag() const { return Tag; }
151 unsigned getNumber() const { return Number; }
152 unsigned getChildrenFlag() const { return ChildrenFlag; }
153 const std::vector<DIEAbbrevData> &getData() const { return Data; }
154 void setTag(unsigned T) { Tag = T; }
155 void setChildrenFlag(unsigned CF) { ChildrenFlag = CF; }
156 void setNumber(unsigned N) { Number = N; }
158 /// AddAttribute - Adds another set of attribute information to the
160 void AddAttribute(unsigned Attribute, unsigned Form) {
161 Data.push_back(DIEAbbrevData(Attribute, Form));
164 /// AddFirstAttribute - Adds a set of attribute information to the front
165 /// of the abbreviation.
166 void AddFirstAttribute(unsigned Attribute, unsigned Form) {
167 Data.insert(Data.begin(), DIEAbbrevData(Attribute, Form));
170 /// Profile - Used to gather unique data for the abbreviation folding set.
172 void Profile(FoldingSetNodeID &ID) {
174 ID.AddInteger(ChildrenFlag);
176 // For each attribute description.
177 for (unsigned i = 0, N = Data.size(); i < N; ++i)
181 /// Emit - Print the abbreviation using the specified Dwarf writer.
183 void Emit(const DwarfDebug &DD) const;
186 void print(std::ostream *O) {
189 void print(std::ostream &O);
194 //===----------------------------------------------------------------------===//
195 /// DIE - A structured debug information entry. Has an abbreviation which
196 /// describes it's organization.
197 class DIE : public FoldingSetNode {
199 /// Abbrev - Buffer for constructing abbreviation.
203 /// Offset - Offset in debug info section.
207 /// Size - Size of instance + children.
213 std::vector<DIE *> Children;
215 /// Attributes values.
217 std::vector<DIEValue *> Values;
221 : Abbrev(Tag, DW_CHILDREN_no)
230 DIEAbbrev &getAbbrev() { return Abbrev; }
231 unsigned getAbbrevNumber() const {
232 return Abbrev.getNumber();
234 unsigned getTag() const { return Abbrev.getTag(); }
235 unsigned getOffset() const { return Offset; }
236 unsigned getSize() const { return Size; }
237 const std::vector<DIE *> &getChildren() const { return Children; }
238 const std::vector<DIEValue *> &getValues() const { return Values; }
239 void setTag(unsigned Tag) { Abbrev.setTag(Tag); }
240 void setOffset(unsigned O) { Offset = O; }
241 void setSize(unsigned S) { Size = S; }
243 /// AddValue - Add a value and attributes to a DIE.
245 void AddValue(unsigned Attribute, unsigned Form, DIEValue *Value) {
246 Abbrev.AddAttribute(Attribute, Form);
247 Values.push_back(Value);
250 /// SiblingOffset - Return the offset of the debug information entry's
252 unsigned SiblingOffset() const { return Offset + Size; }
254 /// AddSiblingOffset - Add a sibling offset field to the front of the DIE.
256 void AddSiblingOffset();
258 /// AddChild - Add a child to the DIE.
260 void AddChild(DIE *Child) {
261 Abbrev.setChildrenFlag(DW_CHILDREN_yes);
262 Children.push_back(Child);
265 /// Detach - Detaches objects connected to it after copying.
271 /// Profile - Used to gather unique data for the value folding set.
273 void Profile(FoldingSetNodeID &ID) ;
276 void print(std::ostream *O, unsigned IncIndent = 0) {
277 if (O) print(*O, IncIndent);
279 void print(std::ostream &O, unsigned IncIndent = 0);
284 //===----------------------------------------------------------------------===//
285 /// DIEValue - A debug information entry value.
287 class DIEValue : public FoldingSetNode {
299 /// Type - Type of data stored in the value.
306 virtual ~DIEValue() {}
309 unsigned getType() const { return Type; }
311 // Implement isa/cast/dyncast.
312 static bool classof(const DIEValue *) { return true; }
314 /// EmitValue - Emit value via the Dwarf writer.
316 virtual void EmitValue(const DwarfDebug &DD, unsigned Form) const = 0;
318 /// SizeOf - Return the size of a value in bytes.
320 virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const = 0;
322 /// Profile - Used to gather unique data for the value folding set.
324 virtual void Profile(FoldingSetNodeID &ID) = 0;
327 void print(std::ostream *O) {
330 virtual void print(std::ostream &O) = 0;
335 //===----------------------------------------------------------------------===//
336 /// DWInteger - An integer value DIE.
338 class DIEInteger : public DIEValue {
343 DIEInteger(uint64_t I) : DIEValue(isInteger), Integer(I) {}
345 // Implement isa/cast/dyncast.
346 static bool classof(const DIEInteger *) { return true; }
347 static bool classof(const DIEValue *I) { return I->Type == isInteger; }
349 /// BestForm - Choose the best form for integer.
351 static unsigned BestForm(bool IsSigned, uint64_t Integer) {
353 if ((char)Integer == (signed)Integer) return DW_FORM_data1;
354 if ((short)Integer == (signed)Integer) return DW_FORM_data2;
355 if ((int)Integer == (signed)Integer) return DW_FORM_data4;
357 if ((unsigned char)Integer == Integer) return DW_FORM_data1;
358 if ((unsigned short)Integer == Integer) return DW_FORM_data2;
359 if ((unsigned int)Integer == Integer) return DW_FORM_data4;
361 return DW_FORM_data8;
364 /// EmitValue - Emit integer of appropriate size.
366 virtual void EmitValue(const DwarfDebug &DD, unsigned Form) const;
368 /// SizeOf - Determine size of integer value in bytes.
370 virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const;
372 /// Profile - Used to gather unique data for the value folding set.
374 static void Profile(FoldingSetNodeID &ID, unsigned Integer) {
375 ID.AddInteger(isInteger);
376 ID.AddInteger(Integer);
378 virtual void Profile(FoldingSetNodeID &ID) { Profile(ID, Integer); }
381 virtual void print(std::ostream &O) {
382 O << "Int: " << (int64_t)Integer
383 << " 0x" << std::hex << Integer << std::dec;
388 //===----------------------------------------------------------------------===//
389 /// DIEString - A string value DIE.
391 class DIEString : public DIEValue {
393 const std::string String;
395 DIEString(const std::string &S) : DIEValue(isString), String(S) {}
397 // Implement isa/cast/dyncast.
398 static bool classof(const DIEString *) { return true; }
399 static bool classof(const DIEValue *S) { return S->Type == isString; }
401 /// EmitValue - Emit string value.
403 virtual void EmitValue(const DwarfDebug &DD, unsigned Form) const;
405 /// SizeOf - Determine size of string value in bytes.
407 virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const {
408 return String.size() + sizeof(char); // sizeof('\0');
411 /// Profile - Used to gather unique data for the value folding set.
413 static void Profile(FoldingSetNodeID &ID, const std::string &String) {
414 ID.AddInteger(isString);
415 ID.AddString(String);
417 virtual void Profile(FoldingSetNodeID &ID) { Profile(ID, String); }
420 virtual void print(std::ostream &O) {
421 O << "Str: \"" << String << "\"";
426 //===----------------------------------------------------------------------===//
427 /// DIEDwarfLabel - A Dwarf internal label expression DIE.
429 class DIEDwarfLabel : public DIEValue {
434 DIEDwarfLabel(const DWLabel &L) : DIEValue(isLabel), Label(L) {}
436 // Implement isa/cast/dyncast.
437 static bool classof(const DIEDwarfLabel *) { return true; }
438 static bool classof(const DIEValue *L) { return L->Type == isLabel; }
440 /// EmitValue - Emit label value.
442 virtual void EmitValue(const DwarfDebug &DD, unsigned Form) const;
444 /// SizeOf - Determine size of label value in bytes.
446 virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const;
448 /// Profile - Used to gather unique data for the value folding set.
450 static void Profile(FoldingSetNodeID &ID, const DWLabel &Label) {
451 ID.AddInteger(isLabel);
454 virtual void Profile(FoldingSetNodeID &ID) { Profile(ID, Label); }
457 virtual void print(std::ostream &O) {
465 //===----------------------------------------------------------------------===//
466 /// DIEObjectLabel - A label to an object in code or data.
468 class DIEObjectLabel : public DIEValue {
470 const std::string Label;
472 DIEObjectLabel(const std::string &L) : DIEValue(isAsIsLabel), Label(L) {}
474 // Implement isa/cast/dyncast.
475 static bool classof(const DIEObjectLabel *) { return true; }
476 static bool classof(const DIEValue *L) { return L->Type == isAsIsLabel; }
478 /// EmitValue - Emit label value.
480 virtual void EmitValue(const DwarfDebug &DD, unsigned Form) const;
482 /// SizeOf - Determine size of label value in bytes.
484 virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const;
486 /// Profile - Used to gather unique data for the value folding set.
488 static void Profile(FoldingSetNodeID &ID, const std::string &Label) {
489 ID.AddInteger(isAsIsLabel);
492 virtual void Profile(FoldingSetNodeID &ID) { Profile(ID, Label); }
495 virtual void print(std::ostream &O) {
496 O << "Obj: " << Label;
501 //===----------------------------------------------------------------------===//
502 /// DIEDelta - A simple label difference DIE.
504 class DIEDelta : public DIEValue {
506 const DWLabel LabelHi;
507 const DWLabel LabelLo;
509 DIEDelta(const DWLabel &Hi, const DWLabel &Lo)
510 : DIEValue(isDelta), LabelHi(Hi), LabelLo(Lo) {}
512 // Implement isa/cast/dyncast.
513 static bool classof(const DIEDelta *) { return true; }
514 static bool classof(const DIEValue *D) { return D->Type == isDelta; }
516 /// EmitValue - Emit delta value.
518 virtual void EmitValue(const DwarfDebug &DD, unsigned Form) const;
520 /// SizeOf - Determine size of delta value in bytes.
522 virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const;
524 /// Profile - Used to gather unique data for the value folding set.
526 static void Profile(FoldingSetNodeID &ID, const DWLabel &LabelHi,
527 const DWLabel &LabelLo) {
528 ID.AddInteger(isDelta);
532 virtual void Profile(FoldingSetNodeID &ID) { Profile(ID, LabelHi, LabelLo); }
535 virtual void print(std::ostream &O) {
544 //===----------------------------------------------------------------------===//
545 /// DIEntry - A pointer to another debug information entry. An instance of this
546 /// class can also be used as a proxy for a debug information entry not yet
547 /// defined (ie. types.)
548 class DIEntry : public DIEValue {
552 DIEntry(DIE *E) : DIEValue(isEntry), Entry(E) {}
554 // Implement isa/cast/dyncast.
555 static bool classof(const DIEntry *) { return true; }
556 static bool classof(const DIEValue *E) { return E->Type == isEntry; }
558 /// EmitValue - Emit debug information entry offset.
560 virtual void EmitValue(const DwarfDebug &DD, unsigned Form) const;
562 /// SizeOf - Determine size of debug information entry in bytes.
564 virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const {
565 return sizeof(int32_t);
568 /// Profile - Used to gather unique data for the value folding set.
570 static void Profile(FoldingSetNodeID &ID, DIE *Entry) {
571 ID.AddInteger(isEntry);
572 ID.AddPointer(Entry);
574 virtual void Profile(FoldingSetNodeID &ID) {
575 ID.AddInteger(isEntry);
578 ID.AddPointer(Entry);
585 virtual void print(std::ostream &O) {
586 O << "Die: 0x" << std::hex << (intptr_t)Entry << std::dec;
591 //===----------------------------------------------------------------------===//
592 /// DIEBlock - A block of values. Primarily used for location expressions.
594 class DIEBlock : public DIEValue, public DIE {
596 unsigned Size; // Size in bytes excluding size header.
606 // Implement isa/cast/dyncast.
607 static bool classof(const DIEBlock *) { return true; }
608 static bool classof(const DIEValue *E) { return E->Type == isBlock; }
610 /// ComputeSize - calculate the size of the block.
612 unsigned ComputeSize(DwarfDebug &DD);
614 /// BestForm - Choose the best form for data.
616 unsigned BestForm() const {
617 if ((unsigned char)Size == Size) return DW_FORM_block1;
618 if ((unsigned short)Size == Size) return DW_FORM_block2;
619 if ((unsigned int)Size == Size) return DW_FORM_block4;
620 return DW_FORM_block;
623 /// EmitValue - Emit block data.
625 virtual void EmitValue(const DwarfDebug &DD, unsigned Form) const;
627 /// SizeOf - Determine size of block data in bytes.
629 virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const;
632 /// Profile - Used to gather unique data for the value folding set.
634 virtual void Profile(FoldingSetNodeID &ID) {
635 ID.AddInteger(isBlock);
640 virtual void print(std::ostream &O) {
647 //===----------------------------------------------------------------------===//
648 /// CompileUnit - This dwarf writer support class manages information associate
649 /// with a source file.
652 /// Desc - Compile unit debug descriptor.
654 CompileUnitDesc *Desc;
656 /// ID - File identifier for source.
660 /// Die - Compile unit debug information entry.
664 /// DescToDieMap - Tracks the mapping of unit level debug informaton
665 /// descriptors to debug information entries.
666 std::map<DebugInfoDesc *, DIE *> DescToDieMap;
668 /// DescToDIEntryMap - Tracks the mapping of unit level debug informaton
669 /// descriptors to debug information entries using a DIEntry proxy.
670 std::map<DebugInfoDesc *, DIEntry *> DescToDIEntryMap;
672 /// Globals - A map of globally visible named entities for this unit.
674 std::map<std::string, DIE *> Globals;
676 /// DiesSet - Used to uniquely define dies within the compile unit.
678 FoldingSet<DIE> DiesSet;
680 /// Dies - List of all dies in the compile unit.
682 std::vector<DIE *> Dies;
685 CompileUnit(CompileUnitDesc *CUD, unsigned I, DIE *D)
692 , DiesSet(InitDiesSetSize)
699 for (unsigned i = 0, N = Dies.size(); i < N; ++i)
704 CompileUnitDesc *getDesc() const { return Desc; }
705 unsigned getID() const { return ID; }
706 DIE* getDie() const { return Die; }
707 std::map<std::string, DIE *> &getGlobals() { return Globals; }
709 /// hasContent - Return true if this compile unit has something to write out.
711 bool hasContent() const {
712 return !Die->getChildren().empty();
715 /// AddGlobal - Add a new global entity to the compile unit.
717 void AddGlobal(const std::string &Name, DIE *Die) {
721 /// getDieMapSlotFor - Returns the debug information entry map slot for the
722 /// specified debug descriptor.
723 DIE *&getDieMapSlotFor(DebugInfoDesc *DID) {
724 return DescToDieMap[DID];
727 /// getDIEntrySlotFor - Returns the debug information entry proxy slot for the
728 /// specified debug descriptor.
729 DIEntry *&getDIEntrySlotFor(DebugInfoDesc *DID) {
730 return DescToDIEntryMap[DID];
733 /// AddDie - Adds or interns the DIE to the compile unit.
735 DIE *AddDie(DIE &Buffer) {
739 DIE *Die = DiesSet.FindNodeOrInsertPos(ID, Where);
742 Die = new DIE(Buffer);
743 DiesSet.InsertNode(Die, Where);
744 this->Die->AddChild(Die);
752 //===----------------------------------------------------------------------===//
753 /// Dwarf - Emits general Dwarf directives.
759 //===--------------------------------------------------------------------===//
760 // Core attributes used by the Dwarf writer.
764 /// O - Stream to .s file.
768 /// Asm - Target of Dwarf emission.
772 /// TAI - Target Asm Printer.
773 const TargetAsmInfo *TAI;
775 /// TD - Target data.
776 const TargetData *TD;
778 /// RI - Register Information.
779 const MRegisterInfo *RI;
781 /// M - Current module.
785 /// MF - Current machine function.
789 /// MMI - Collected machine module information.
791 MachineModuleInfo *MMI;
793 /// didInitial - Flag to indicate if initial emission has been done.
797 /// shouldEmit - Flag to indicate if debug information should be emitted.
801 /// SubprogramCount - The running count of functions being compiled.
803 unsigned SubprogramCount;
805 Dwarf(std::ostream &OS, AsmPrinter *A, const TargetAsmInfo *T)
809 , TD(Asm->TM.getTargetData())
810 , RI(Asm->TM.getRegisterInfo())
822 //===--------------------------------------------------------------------===//
825 AsmPrinter *getAsm() const { return Asm; }
826 const TargetAsmInfo *getTargetAsmInfo() const { return TAI; }
828 /// ShouldEmitDwarf - Returns true if Dwarf declarations should be made.
830 bool ShouldEmitDwarf() const { return shouldEmit; }
834 //===----------------------------------------------------------------------===//
835 /// DwarfDebug - Emits Dwarf debug directives.
837 class DwarfDebug : public Dwarf {
840 //===--------------------------------------------------------------------===//
841 // Attributes used to construct specific Dwarf sections.
844 /// CompileUnits - All the compile units involved in this build. The index
845 /// of each entry in this vector corresponds to the sources in MMI.
846 std::vector<CompileUnit *> CompileUnits;
848 /// AbbreviationsSet - Used to uniquely define abbreviations.
850 FoldingSet<DIEAbbrev> AbbreviationsSet;
852 /// Abbreviations - A list of all the unique abbreviations in use.
854 std::vector<DIEAbbrev *> Abbreviations;
856 /// ValuesSet - Used to uniquely define values.
858 FoldingSet<DIEValue> ValuesSet;
860 /// Values - A list of all the unique values in use.
862 std::vector<DIEValue *> Values;
864 /// StringPool - A UniqueVector of strings used by indirect references.
866 UniqueVector<std::string> StringPool;
868 /// UnitMap - Map debug information descriptor to compile unit.
870 std::map<DebugInfoDesc *, CompileUnit *> DescToUnitMap;
872 /// SectionMap - Provides a unique id per text section.
874 UniqueVector<std::string> SectionMap;
876 /// SectionSourceLines - Tracks line numbers per text section.
878 std::vector<std::vector<SourceLineInfo> > SectionSourceLines;
883 /// PrintLabelName - Print label name in form used by Dwarf writer.
885 void PrintLabelName(DWLabel Label) const {
886 PrintLabelName(Label.Tag, Label.Number);
888 void PrintLabelName(const char *Tag, unsigned Number) const {
889 O << TAI->getPrivateGlobalPrefix()
892 if (Number) O << Number;
895 /// EmitLabel - Emit location label for internal use by Dwarf.
897 void EmitLabel(DWLabel Label) const {
898 EmitLabel(Label.Tag, Label.Number);
900 void EmitLabel(const char *Tag, unsigned Number) const {
901 PrintLabelName(Tag, Number);
905 /// EmitReference - Emit a reference to a label.
907 void EmitReference(DWLabel Label) const {
908 EmitReference(Label.Tag, Label.Number);
910 void EmitReference(const char *Tag, unsigned Number) const {
911 if (TAI->getAddressSize() == sizeof(int32_t))
912 O << TAI->getData32bitsDirective();
914 O << TAI->getData64bitsDirective();
916 PrintLabelName(Tag, Number);
918 void EmitReference(const std::string &Name) const {
919 if (TAI->getAddressSize() == sizeof(int32_t))
920 O << TAI->getData32bitsDirective();
922 O << TAI->getData64bitsDirective();
927 /// EmitDifference - Emit the difference between two labels. Some
928 /// assemblers do not behave with absolute expressions with data directives,
929 /// so there is an option (needsSet) to use an intermediary set expression.
930 void EmitDifference(DWLabel LabelHi, DWLabel LabelLo,
931 bool IsSmall = false) const {
932 EmitDifference(LabelHi.Tag, LabelHi.Number,
933 LabelLo.Tag, LabelLo.Number,
936 void EmitDifference(const char *TagHi, unsigned NumberHi,
937 const char *TagLo, unsigned NumberLo,
938 bool IsSmall = false) const {
939 if (TAI->needsSet()) {
940 static unsigned SetCounter = 0;
943 PrintLabelName("set", SetCounter);
945 PrintLabelName(TagHi, NumberHi);
947 PrintLabelName(TagLo, NumberLo);
950 if (IsSmall || TAI->getAddressSize() == sizeof(int32_t))
951 O << TAI->getData32bitsDirective();
953 O << TAI->getData64bitsDirective();
955 PrintLabelName("set", SetCounter);
959 if (IsSmall || TAI->getAddressSize() == sizeof(int32_t))
960 O << TAI->getData32bitsDirective();
962 O << TAI->getData64bitsDirective();
964 PrintLabelName(TagHi, NumberHi);
966 PrintLabelName(TagLo, NumberLo);
970 /// AssignAbbrevNumber - Define a unique number for the abbreviation.
972 void AssignAbbrevNumber(DIEAbbrev &Abbrev) {
973 // Profile the node so that we can make it unique.
977 // Check the set for priors.
978 DIEAbbrev *InSet = AbbreviationsSet.GetOrInsertNode(&Abbrev);
980 // If it's newly added.
981 if (InSet == &Abbrev) {
982 // Add to abbreviation list.
983 Abbreviations.push_back(&Abbrev);
984 // Assign the vector position + 1 as its number.
985 Abbrev.setNumber(Abbreviations.size());
987 // Assign existing abbreviation number.
988 Abbrev.setNumber(InSet->getNumber());
992 /// NewString - Add a string to the constant pool and returns a label.
994 DWLabel NewString(const std::string &String) {
995 unsigned StringID = StringPool.insert(String);
996 return DWLabel("string", StringID);
999 /// NewDIEntry - Creates a new DIEntry to be a proxy for a debug information
1001 DIEntry *NewDIEntry(DIE *Entry = NULL) {
1005 FoldingSetNodeID ID;
1006 DIEntry::Profile(ID, Entry);
1008 Value = static_cast<DIEntry *>(ValuesSet.FindNodeOrInsertPos(ID, Where));
1010 if (Value) return Value;
1012 Value = new DIEntry(Entry);
1013 ValuesSet.InsertNode(Value, Where);
1015 Value = new DIEntry(Entry);
1018 Values.push_back(Value);
1022 /// SetDIEntry - Set a DIEntry once the debug information entry is defined.
1024 void SetDIEntry(DIEntry *Value, DIE *Entry) {
1025 Value->Entry = Entry;
1026 // Add to values set if not already there. If it is, we merely have a
1027 // duplicate in the values list (no harm.)
1028 ValuesSet.GetOrInsertNode(Value);
1031 /// AddUInt - Add an unsigned integer attribute data and value.
1033 void AddUInt(DIE *Die, unsigned Attribute, unsigned Form, uint64_t Integer) {
1034 if (!Form) Form = DIEInteger::BestForm(false, Integer);
1036 FoldingSetNodeID ID;
1037 DIEInteger::Profile(ID, Integer);
1039 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
1041 Value = new DIEInteger(Integer);
1042 ValuesSet.InsertNode(Value, Where);
1043 Values.push_back(Value);
1046 Die->AddValue(Attribute, Form, Value);
1049 /// AddSInt - Add an signed integer attribute data and value.
1051 void AddSInt(DIE *Die, unsigned Attribute, unsigned Form, int64_t Integer) {
1052 if (!Form) Form = DIEInteger::BestForm(true, Integer);
1054 FoldingSetNodeID ID;
1055 DIEInteger::Profile(ID, (uint64_t)Integer);
1057 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
1059 Value = new DIEInteger(Integer);
1060 ValuesSet.InsertNode(Value, Where);
1061 Values.push_back(Value);
1064 Die->AddValue(Attribute, Form, Value);
1067 /// AddString - Add a std::string attribute data and value.
1069 void AddString(DIE *Die, unsigned Attribute, unsigned Form,
1070 const std::string &String) {
1071 FoldingSetNodeID ID;
1072 DIEString::Profile(ID, String);
1074 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
1076 Value = new DIEString(String);
1077 ValuesSet.InsertNode(Value, Where);
1078 Values.push_back(Value);
1081 Die->AddValue(Attribute, Form, Value);
1084 /// AddLabel - Add a Dwarf label attribute data and value.
1086 void AddLabel(DIE *Die, unsigned Attribute, unsigned Form,
1087 const DWLabel &Label) {
1088 FoldingSetNodeID ID;
1089 DIEDwarfLabel::Profile(ID, Label);
1091 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
1093 Value = new DIEDwarfLabel(Label);
1094 ValuesSet.InsertNode(Value, Where);
1095 Values.push_back(Value);
1098 Die->AddValue(Attribute, Form, Value);
1101 /// AddObjectLabel - Add an non-Dwarf label attribute data and value.
1103 void AddObjectLabel(DIE *Die, unsigned Attribute, unsigned Form,
1104 const std::string &Label) {
1105 FoldingSetNodeID ID;
1106 DIEObjectLabel::Profile(ID, Label);
1108 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
1110 Value = new DIEObjectLabel(Label);
1111 ValuesSet.InsertNode(Value, Where);
1112 Values.push_back(Value);
1115 Die->AddValue(Attribute, Form, Value);
1118 /// AddDelta - Add a label delta attribute data and value.
1120 void AddDelta(DIE *Die, unsigned Attribute, unsigned Form,
1121 const DWLabel &Hi, const DWLabel &Lo) {
1122 FoldingSetNodeID ID;
1123 DIEDelta::Profile(ID, Hi, Lo);
1125 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
1127 Value = new DIEDelta(Hi, Lo);
1128 ValuesSet.InsertNode(Value, Where);
1129 Values.push_back(Value);
1132 Die->AddValue(Attribute, Form, Value);
1135 /// AddDIEntry - Add a DIE attribute data and value.
1137 void AddDIEntry(DIE *Die, unsigned Attribute, unsigned Form, DIE *Entry) {
1138 Die->AddValue(Attribute, Form, NewDIEntry(Entry));
1141 /// AddBlock - Add block data.
1143 void AddBlock(DIE *Die, unsigned Attribute, unsigned Form, DIEBlock *Block) {
1144 Block->ComputeSize(*this);
1145 FoldingSetNodeID ID;
1148 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
1151 ValuesSet.InsertNode(Value, Where);
1152 Values.push_back(Value);
1157 Die->AddValue(Attribute, Block->BestForm(), Value);
1162 /// AddSourceLine - Add location information to specified debug information
1164 void AddSourceLine(DIE *Die, CompileUnitDesc *File, unsigned Line) {
1166 CompileUnit *FileUnit = FindCompileUnit(File);
1167 unsigned FileID = FileUnit->getID();
1168 AddUInt(Die, DW_AT_decl_file, 0, FileID);
1169 AddUInt(Die, DW_AT_decl_line, 0, Line);
1173 /// AddAddress - Add an address attribute to a die based on the location
1175 void AddAddress(DIE *Die, unsigned Attribute,
1176 const MachineLocation &Location) {
1177 unsigned Reg = RI->getDwarfRegNum(Location.getRegister());
1178 DIEBlock *Block = new DIEBlock();
1180 if (Location.isRegister()) {
1182 AddUInt(Block, 0, DW_FORM_data1, DW_OP_reg0 + Reg);
1184 AddUInt(Block, 0, DW_FORM_data1, DW_OP_regx);
1185 AddUInt(Block, 0, DW_FORM_udata, Reg);
1189 AddUInt(Block, 0, DW_FORM_data1, DW_OP_breg0 + Reg);
1191 AddUInt(Block, 0, DW_FORM_data1, DW_OP_bregx);
1192 AddUInt(Block, 0, DW_FORM_udata, Reg);
1194 AddUInt(Block, 0, DW_FORM_sdata, Location.getOffset());
1197 AddBlock(Die, Attribute, 0, Block);
1200 /// AddBasicType - Add a new basic type attribute to the specified entity.
1202 void AddBasicType(DIE *Entity, CompileUnit *Unit,
1203 const std::string &Name,
1204 unsigned Encoding, unsigned Size) {
1205 DIE *Die = ConstructBasicType(Unit, Name, Encoding, Size);
1206 AddDIEntry(Entity, DW_AT_type, DW_FORM_ref4, Die);
1209 /// ConstructBasicType - Construct a new basic type.
1211 DIE *ConstructBasicType(CompileUnit *Unit,
1212 const std::string &Name,
1213 unsigned Encoding, unsigned Size) {
1214 DIE Buffer(DW_TAG_base_type);
1215 AddUInt(&Buffer, DW_AT_byte_size, 0, Size);
1216 AddUInt(&Buffer, DW_AT_encoding, DW_FORM_data1, Encoding);
1217 if (!Name.empty()) AddString(&Buffer, DW_AT_name, DW_FORM_string, Name);
1218 return Unit->AddDie(Buffer);
1221 /// AddPointerType - Add a new pointer type attribute to the specified entity.
1223 void AddPointerType(DIE *Entity, CompileUnit *Unit, const std::string &Name) {
1224 DIE *Die = ConstructPointerType(Unit, Name);
1225 AddDIEntry(Entity, DW_AT_type, DW_FORM_ref4, Die);
1228 /// ConstructPointerType - Construct a new pointer type.
1230 DIE *ConstructPointerType(CompileUnit *Unit, const std::string &Name) {
1231 DIE Buffer(DW_TAG_pointer_type);
1232 AddUInt(&Buffer, DW_AT_byte_size, 0, TAI->getAddressSize());
1233 if (!Name.empty()) AddString(&Buffer, DW_AT_name, DW_FORM_string, Name);
1234 return Unit->AddDie(Buffer);
1237 /// AddType - Add a new type attribute to the specified entity.
1239 void AddType(DIE *Entity, TypeDesc *TyDesc, CompileUnit *Unit) {
1241 AddBasicType(Entity, Unit, "", DW_ATE_signed, sizeof(int32_t));
1243 // Check for pre-existence.
1244 DIEntry *&Slot = Unit->getDIEntrySlotFor(TyDesc);
1246 // If it exists then use the existing value.
1248 Entity->AddValue(DW_AT_type, DW_FORM_ref4, Slot);
1252 if (SubprogramDesc *SubprogramTy = dyn_cast<SubprogramDesc>(TyDesc)) {
1253 // FIXME - Not sure why programs and variables are coming through here.
1254 // Short cut for handling subprogram types (not really a TyDesc.)
1255 AddPointerType(Entity, Unit, SubprogramTy->getName());
1256 } else if (GlobalVariableDesc *GlobalTy =
1257 dyn_cast<GlobalVariableDesc>(TyDesc)) {
1258 // FIXME - Not sure why programs and variables are coming through here.
1259 // Short cut for handling global variable types (not really a TyDesc.)
1260 AddPointerType(Entity, Unit, GlobalTy->getName());
1263 Slot = NewDIEntry();
1266 DIE Buffer(DW_TAG_base_type);
1267 ConstructType(Buffer, TyDesc, Unit);
1269 // Add debug information entry to entity and unit.
1270 DIE *Die = Unit->AddDie(Buffer);
1271 SetDIEntry(Slot, Die);
1272 Entity->AddValue(DW_AT_type, DW_FORM_ref4, Slot);
1277 /// ConstructType - Adds all the required attributes to the type.
1279 void ConstructType(DIE &Buffer, TypeDesc *TyDesc, CompileUnit *Unit) {
1280 // Get core information.
1281 const std::string &Name = TyDesc->getName();
1282 uint64_t Size = TyDesc->getSize() >> 3;
1284 if (BasicTypeDesc *BasicTy = dyn_cast<BasicTypeDesc>(TyDesc)) {
1285 // Fundamental types like int, float, bool
1286 Buffer.setTag(DW_TAG_base_type);
1287 AddUInt(&Buffer, DW_AT_encoding, DW_FORM_data1, BasicTy->getEncoding());
1288 } else if (DerivedTypeDesc *DerivedTy = dyn_cast<DerivedTypeDesc>(TyDesc)) {
1290 unsigned Tag = DerivedTy->getTag();
1291 // FIXME - Workaround for templates.
1292 if (Tag == DW_TAG_inheritance) Tag = DW_TAG_reference_type;
1293 // Pointers, typedefs et al.
1295 // Map to main type, void will not have a type.
1296 if (TypeDesc *FromTy = DerivedTy->getFromType())
1297 AddType(&Buffer, FromTy, Unit);
1298 } else if (CompositeTypeDesc *CompTy = dyn_cast<CompositeTypeDesc>(TyDesc)){
1300 unsigned Tag = CompTy->getTag();
1302 // Set tag accordingly.
1303 if (Tag == DW_TAG_vector_type)
1304 Buffer.setTag(DW_TAG_array_type);
1308 std::vector<DebugInfoDesc *> &Elements = CompTy->getElements();
1311 case DW_TAG_vector_type:
1312 AddUInt(&Buffer, DW_AT_GNU_vector, DW_FORM_flag, 1);
1314 case DW_TAG_array_type: {
1315 // Add element type.
1316 if (TypeDesc *FromTy = CompTy->getFromType())
1317 AddType(&Buffer, FromTy, Unit);
1319 // Don't emit size attribute.
1322 // Construct an anonymous type for index type.
1323 DIE *IndexTy = ConstructBasicType(Unit, "", DW_ATE_signed,
1326 // Add subranges to array type.
1327 for(unsigned i = 0, N = Elements.size(); i < N; ++i) {
1328 SubrangeDesc *SRD = cast<SubrangeDesc>(Elements[i]);
1329 int64_t Lo = SRD->getLo();
1330 int64_t Hi = SRD->getHi();
1331 DIE *Subrange = new DIE(DW_TAG_subrange_type);
1333 // If a range is available.
1335 AddDIEntry(Subrange, DW_AT_type, DW_FORM_ref4, IndexTy);
1336 // Only add low if non-zero.
1337 if (Lo) AddSInt(Subrange, DW_AT_lower_bound, 0, Lo);
1338 AddSInt(Subrange, DW_AT_upper_bound, 0, Hi);
1341 Buffer.AddChild(Subrange);
1345 case DW_TAG_structure_type:
1346 case DW_TAG_union_type: {
1347 // Add elements to structure type.
1348 for(unsigned i = 0, N = Elements.size(); i < N; ++i) {
1349 DebugInfoDesc *Element = Elements[i];
1351 if (DerivedTypeDesc *MemberDesc = dyn_cast<DerivedTypeDesc>(Element)){
1352 // Add field or base class.
1354 unsigned Tag = MemberDesc->getTag();
1356 // Extract the basic information.
1357 const std::string &Name = MemberDesc->getName();
1358 uint64_t Size = MemberDesc->getSize();
1359 uint64_t Align = MemberDesc->getAlign();
1360 uint64_t Offset = MemberDesc->getOffset();
1362 // Construct member debug information entry.
1363 DIE *Member = new DIE(Tag);
1365 // Add name if not "".
1367 AddString(Member, DW_AT_name, DW_FORM_string, Name);
1368 // Add location if available.
1369 AddSourceLine(Member, MemberDesc->getFile(), MemberDesc->getLine());
1371 // Most of the time the field info is the same as the members.
1372 uint64_t FieldSize = Size;
1373 uint64_t FieldAlign = Align;
1374 uint64_t FieldOffset = Offset;
1376 // Set the member type.
1377 TypeDesc *FromTy = MemberDesc->getFromType();
1378 AddType(Member, FromTy, Unit);
1380 // Walk up typedefs until a real size is found.
1382 if (FromTy->getTag() != DW_TAG_typedef) {
1383 FieldSize = FromTy->getSize();
1384 FieldAlign = FromTy->getSize();
1388 FromTy = dyn_cast<DerivedTypeDesc>(FromTy)->getFromType();
1391 // Unless we have a bit field.
1392 if (Tag == DW_TAG_member && FieldSize != Size) {
1393 // Construct the alignment mask.
1394 uint64_t AlignMask = ~(FieldAlign - 1);
1395 // Determine the high bit + 1 of the declared size.
1396 uint64_t HiMark = (Offset + FieldSize) & AlignMask;
1397 // Work backwards to determine the base offset of the field.
1398 FieldOffset = HiMark - FieldSize;
1399 // Now normalize offset to the field.
1400 Offset -= FieldOffset;
1402 // Maybe we need to work from the other end.
1403 if (TD->isLittleEndian()) Offset = FieldSize - (Offset + Size);
1405 // Add size and offset.
1406 AddUInt(Member, DW_AT_byte_size, 0, FieldSize >> 3);
1407 AddUInt(Member, DW_AT_bit_size, 0, Size);
1408 AddUInt(Member, DW_AT_bit_offset, 0, Offset);
1411 // Add computation for offset.
1412 DIEBlock *Block = new DIEBlock();
1413 AddUInt(Block, 0, DW_FORM_data1, DW_OP_plus_uconst);
1414 AddUInt(Block, 0, DW_FORM_udata, FieldOffset >> 3);
1415 AddBlock(Member, DW_AT_data_member_location, 0, Block);
1417 // Add accessibility (public default unless is base class.
1418 if (MemberDesc->isProtected()) {
1419 AddUInt(Member, DW_AT_accessibility, 0, DW_ACCESS_protected);
1420 } else if (MemberDesc->isPrivate()) {
1421 AddUInt(Member, DW_AT_accessibility, 0, DW_ACCESS_private);
1422 } else if (Tag == DW_TAG_inheritance) {
1423 AddUInt(Member, DW_AT_accessibility, 0, DW_ACCESS_public);
1426 Buffer.AddChild(Member);
1427 } else if (GlobalVariableDesc *StaticDesc =
1428 dyn_cast<GlobalVariableDesc>(Element)) {
1429 // Add static member.
1431 // Construct member debug information entry.
1432 DIE *Static = new DIE(DW_TAG_variable);
1434 // Add name and mangled name.
1435 const std::string &Name = StaticDesc->getName();
1436 const std::string &LinkageName = StaticDesc->getLinkageName();
1437 AddString(Static, DW_AT_name, DW_FORM_string, Name);
1438 if (!LinkageName.empty()) {
1439 AddString(Static, DW_AT_MIPS_linkage_name, DW_FORM_string,
1444 AddSourceLine(Static, StaticDesc->getFile(), StaticDesc->getLine());
1447 if (TypeDesc *StaticTy = StaticDesc->getType())
1448 AddType(Static, StaticTy, Unit);
1451 if (!StaticDesc->isStatic())
1452 AddUInt(Static, DW_AT_external, DW_FORM_flag, 1);
1453 AddUInt(Static, DW_AT_declaration, DW_FORM_flag, 1);
1455 Buffer.AddChild(Static);
1456 } else if (SubprogramDesc *MethodDesc =
1457 dyn_cast<SubprogramDesc>(Element)) {
1458 // Add member function.
1460 // Construct member debug information entry.
1461 DIE *Method = new DIE(DW_TAG_subprogram);
1463 // Add name and mangled name.
1464 const std::string &Name = MethodDesc->getName();
1465 const std::string &LinkageName = MethodDesc->getLinkageName();
1467 AddString(Method, DW_AT_name, DW_FORM_string, Name);
1468 bool IsCTor = TyDesc->getName() == Name;
1470 if (!LinkageName.empty()) {
1471 AddString(Method, DW_AT_MIPS_linkage_name, DW_FORM_string,
1476 AddSourceLine(Method, MethodDesc->getFile(), MethodDesc->getLine());
1479 if (CompositeTypeDesc *MethodTy =
1480 dyn_cast_or_null<CompositeTypeDesc>(MethodDesc->getType())) {
1481 // Get argument information.
1482 std::vector<DebugInfoDesc *> &Args = MethodTy->getElements();
1487 AddType(Method, dyn_cast<TypeDesc>(Args[0]), Unit);
1491 for(unsigned i = 1, N = Args.size(); i < N; ++i) {
1492 DIE *Arg = new DIE(DW_TAG_formal_parameter);
1493 AddType(Arg, cast<TypeDesc>(Args[i]), Unit);
1494 AddUInt(Arg, DW_AT_artificial, DW_FORM_flag, 1);
1495 Method->AddChild(Arg);
1500 if (!MethodDesc->isStatic())
1501 AddUInt(Method, DW_AT_external, DW_FORM_flag, 1);
1502 AddUInt(Method, DW_AT_declaration, DW_FORM_flag, 1);
1504 Buffer.AddChild(Method);
1509 case DW_TAG_enumeration_type: {
1510 // Add enumerators to enumeration type.
1511 for(unsigned i = 0, N = Elements.size(); i < N; ++i) {
1512 EnumeratorDesc *ED = cast<EnumeratorDesc>(Elements[i]);
1513 const std::string &Name = ED->getName();
1514 int64_t Value = ED->getValue();
1515 DIE *Enumerator = new DIE(DW_TAG_enumerator);
1516 AddString(Enumerator, DW_AT_name, DW_FORM_string, Name);
1517 AddSInt(Enumerator, DW_AT_const_value, DW_FORM_sdata, Value);
1518 Buffer.AddChild(Enumerator);
1523 case DW_TAG_subroutine_type: {
1524 // Add prototype flag.
1525 AddUInt(&Buffer, DW_AT_prototyped, DW_FORM_flag, 1);
1527 AddType(&Buffer, dyn_cast<TypeDesc>(Elements[0]), Unit);
1530 for(unsigned i = 1, N = Elements.size(); i < N; ++i) {
1531 DIE *Arg = new DIE(DW_TAG_formal_parameter);
1532 AddType(Arg, cast<TypeDesc>(Elements[i]), Unit);
1533 Buffer.AddChild(Arg);
1542 // Add size if non-zero (derived types don't have a size.)
1543 if (Size) AddUInt(&Buffer, DW_AT_byte_size, 0, Size);
1544 // Add name if not anonymous or intermediate type.
1545 if (!Name.empty()) AddString(&Buffer, DW_AT_name, DW_FORM_string, Name);
1546 // Add source line info if available.
1547 AddSourceLine(&Buffer, TyDesc->getFile(), TyDesc->getLine());
1550 /// NewCompileUnit - Create new compile unit and it's debug information entry.
1552 CompileUnit *NewCompileUnit(CompileUnitDesc *UnitDesc, unsigned ID) {
1553 // Construct debug information entry.
1554 DIE *Die = new DIE(DW_TAG_compile_unit);
1555 AddDelta(Die, DW_AT_stmt_list, DW_FORM_data4, DWLabel("section_line", 0),
1556 DWLabel("section_line", 0));
1557 AddString(Die, DW_AT_producer, DW_FORM_string, UnitDesc->getProducer());
1558 AddUInt (Die, DW_AT_language, DW_FORM_data1, UnitDesc->getLanguage());
1559 AddString(Die, DW_AT_name, DW_FORM_string, UnitDesc->getFileName());
1560 AddString(Die, DW_AT_comp_dir, DW_FORM_string, UnitDesc->getDirectory());
1562 // Construct compile unit.
1563 CompileUnit *Unit = new CompileUnit(UnitDesc, ID, Die);
1565 // Add Unit to compile unit map.
1566 DescToUnitMap[UnitDesc] = Unit;
1571 /// GetBaseCompileUnit - Get the main compile unit.
1573 CompileUnit *GetBaseCompileUnit() const {
1574 CompileUnit *Unit = CompileUnits[0];
1575 assert(Unit && "Missing compile unit.");
1579 /// FindCompileUnit - Get the compile unit for the given descriptor.
1581 CompileUnit *FindCompileUnit(CompileUnitDesc *UnitDesc) {
1582 CompileUnit *Unit = DescToUnitMap[UnitDesc];
1583 assert(Unit && "Missing compile unit.");
1587 /// NewGlobalVariable - Add a new global variable DIE.
1589 DIE *NewGlobalVariable(GlobalVariableDesc *GVD) {
1590 // Get the compile unit context.
1591 CompileUnitDesc *UnitDesc =
1592 static_cast<CompileUnitDesc *>(GVD->getContext());
1593 CompileUnit *Unit = GetBaseCompileUnit();
1595 // Check for pre-existence.
1596 DIE *&Slot = Unit->getDieMapSlotFor(GVD);
1597 if (Slot) return Slot;
1599 // Get the global variable itself.
1600 GlobalVariable *GV = GVD->getGlobalVariable();
1602 const std::string &Name = GVD->getName();
1603 const std::string &FullName = GVD->getFullName();
1604 const std::string &LinkageName = GVD->getLinkageName();
1605 // Create the global's variable DIE.
1606 DIE *VariableDie = new DIE(DW_TAG_variable);
1607 AddString(VariableDie, DW_AT_name, DW_FORM_string, Name);
1608 if (!LinkageName.empty()) {
1609 AddString(VariableDie, DW_AT_MIPS_linkage_name, DW_FORM_string,
1612 AddType(VariableDie, GVD->getType(), Unit);
1613 if (!GVD->isStatic())
1614 AddUInt(VariableDie, DW_AT_external, DW_FORM_flag, 1);
1616 // Add source line info if available.
1617 AddSourceLine(VariableDie, UnitDesc, GVD->getLine());
1620 DIEBlock *Block = new DIEBlock();
1621 AddUInt(Block, 0, DW_FORM_data1, DW_OP_addr);
1622 AddObjectLabel(Block, 0, DW_FORM_udata, Asm->getGlobalLinkName(GV));
1623 AddBlock(VariableDie, DW_AT_location, 0, Block);
1628 // Add to context owner.
1629 Unit->getDie()->AddChild(VariableDie);
1631 // Expose as global.
1632 // FIXME - need to check external flag.
1633 Unit->AddGlobal(FullName, VariableDie);
1638 /// NewSubprogram - Add a new subprogram DIE.
1640 DIE *NewSubprogram(SubprogramDesc *SPD) {
1641 // Get the compile unit context.
1642 CompileUnitDesc *UnitDesc =
1643 static_cast<CompileUnitDesc *>(SPD->getContext());
1644 CompileUnit *Unit = GetBaseCompileUnit();
1646 // Check for pre-existence.
1647 DIE *&Slot = Unit->getDieMapSlotFor(SPD);
1648 if (Slot) return Slot;
1650 // Gather the details (simplify add attribute code.)
1651 const std::string &Name = SPD->getName();
1652 const std::string &FullName = SPD->getFullName();
1653 const std::string &LinkageName = SPD->getLinkageName();
1655 DIE *SubprogramDie = new DIE(DW_TAG_subprogram);
1656 AddString(SubprogramDie, DW_AT_name, DW_FORM_string, Name);
1657 if (!LinkageName.empty()) {
1658 AddString(SubprogramDie, DW_AT_MIPS_linkage_name, DW_FORM_string,
1661 if (SPD->getType()) AddType(SubprogramDie, SPD->getType(), Unit);
1662 if (!SPD->isStatic())
1663 AddUInt(SubprogramDie, DW_AT_external, DW_FORM_flag, 1);
1664 AddUInt(SubprogramDie, DW_AT_prototyped, DW_FORM_flag, 1);
1666 // Add source line info if available.
1667 AddSourceLine(SubprogramDie, UnitDesc, SPD->getLine());
1670 Slot = SubprogramDie;
1672 // Add to context owner.
1673 Unit->getDie()->AddChild(SubprogramDie);
1675 // Expose as global.
1676 Unit->AddGlobal(FullName, SubprogramDie);
1678 return SubprogramDie;
1681 /// NewScopeVariable - Create a new scope variable.
1683 DIE *NewScopeVariable(DebugVariable *DV, CompileUnit *Unit) {
1684 // Get the descriptor.
1685 VariableDesc *VD = DV->getDesc();
1687 // Translate tag to proper Dwarf tag. The result variable is dropped for
1690 switch (VD->getTag()) {
1691 case DW_TAG_return_variable: return NULL;
1692 case DW_TAG_arg_variable: Tag = DW_TAG_formal_parameter; break;
1693 case DW_TAG_auto_variable: // fall thru
1694 default: Tag = DW_TAG_variable; break;
1697 // Define variable debug information entry.
1698 DIE *VariableDie = new DIE(Tag);
1699 AddString(VariableDie, DW_AT_name, DW_FORM_string, VD->getName());
1701 // Add source line info if available.
1702 AddSourceLine(VariableDie, VD->getFile(), VD->getLine());
1704 // Add variable type.
1705 AddType(VariableDie, VD->getType(), Unit);
1707 // Add variable address.
1708 MachineLocation Location;
1709 RI->getLocation(*MF, DV->getFrameIndex(), Location);
1710 AddAddress(VariableDie, DW_AT_location, Location);
1715 /// ConstructScope - Construct the components of a scope.
1717 void ConstructScope(DebugScope *ParentScope,
1718 unsigned ParentStartID, unsigned ParentEndID,
1719 DIE *ParentDie, CompileUnit *Unit) {
1720 // Add variables to scope.
1721 std::vector<DebugVariable *> &Variables = ParentScope->getVariables();
1722 for (unsigned i = 0, N = Variables.size(); i < N; ++i) {
1723 DIE *VariableDie = NewScopeVariable(Variables[i], Unit);
1724 if (VariableDie) ParentDie->AddChild(VariableDie);
1727 // Add nested scopes.
1728 std::vector<DebugScope *> &Scopes = ParentScope->getScopes();
1729 for (unsigned j = 0, M = Scopes.size(); j < M; ++j) {
1730 // Define the Scope debug information entry.
1731 DebugScope *Scope = Scopes[j];
1732 // FIXME - Ignore inlined functions for the time being.
1733 if (!Scope->getParent()) continue;
1735 unsigned StartID = MMI->MappedLabel(Scope->getStartLabelID());
1736 unsigned EndID = MMI->MappedLabel(Scope->getEndLabelID());
1738 // Ignore empty scopes.
1739 if (StartID == EndID && StartID != 0) continue;
1740 if (Scope->getScopes().empty() && Scope->getVariables().empty()) continue;
1742 if (StartID == ParentStartID && EndID == ParentEndID) {
1743 // Just add stuff to the parent scope.
1744 ConstructScope(Scope, ParentStartID, ParentEndID, ParentDie, Unit);
1746 DIE *ScopeDie = new DIE(DW_TAG_lexical_block);
1748 // Add the scope bounds.
1750 AddLabel(ScopeDie, DW_AT_low_pc, DW_FORM_addr,
1751 DWLabel("loc", StartID));
1753 AddLabel(ScopeDie, DW_AT_low_pc, DW_FORM_addr,
1754 DWLabel("func_begin", SubprogramCount));
1757 AddLabel(ScopeDie, DW_AT_high_pc, DW_FORM_addr,
1758 DWLabel("loc", EndID));
1760 AddLabel(ScopeDie, DW_AT_high_pc, DW_FORM_addr,
1761 DWLabel("func_end", SubprogramCount));
1764 // Add the scope contents.
1765 ConstructScope(Scope, StartID, EndID, ScopeDie, Unit);
1766 ParentDie->AddChild(ScopeDie);
1771 /// ConstructRootScope - Construct the scope for the subprogram.
1773 void ConstructRootScope(DebugScope *RootScope) {
1774 // Exit if there is no root scope.
1775 if (!RootScope) return;
1777 // Get the subprogram debug information entry.
1778 SubprogramDesc *SPD = cast<SubprogramDesc>(RootScope->getDesc());
1780 // Get the compile unit context.
1781 CompileUnit *Unit = GetBaseCompileUnit();
1783 // Get the subprogram die.
1784 DIE *SPDie = Unit->getDieMapSlotFor(SPD);
1785 assert(SPDie && "Missing subprogram descriptor");
1787 // Add the function bounds.
1788 AddLabel(SPDie, DW_AT_low_pc, DW_FORM_addr,
1789 DWLabel("func_begin", SubprogramCount));
1790 AddLabel(SPDie, DW_AT_high_pc, DW_FORM_addr,
1791 DWLabel("func_end", SubprogramCount));
1792 MachineLocation Location(RI->getFrameRegister(*MF));
1793 AddAddress(SPDie, DW_AT_frame_base, Location);
1795 ConstructScope(RootScope, 0, 0, SPDie, Unit);
1798 /// EmitInitial - Emit initial Dwarf declarations. This is necessary for cc
1799 /// tools to recognize the object file contains Dwarf information.
1800 void EmitInitial() {
1801 // Check to see if we already emitted intial headers.
1802 if (didInitial) return;
1805 // Dwarf sections base addresses.
1806 if (TAI->getDwarfRequiresFrameSection()) {
1807 Asm->SwitchToDataSection(TAI->getDwarfFrameSection());
1808 EmitLabel("section_frame", 0);
1810 Asm->SwitchToDataSection(TAI->getDwarfInfoSection());
1811 EmitLabel("section_info", 0);
1812 Asm->SwitchToDataSection(TAI->getDwarfAbbrevSection());
1813 EmitLabel("section_abbrev", 0);
1814 Asm->SwitchToDataSection(TAI->getDwarfARangesSection());
1815 EmitLabel("section_aranges", 0);
1816 Asm->SwitchToDataSection(TAI->getDwarfMacInfoSection());
1817 EmitLabel("section_macinfo", 0);
1818 Asm->SwitchToDataSection(TAI->getDwarfLineSection());
1819 EmitLabel("section_line", 0);
1820 Asm->SwitchToDataSection(TAI->getDwarfLocSection());
1821 EmitLabel("section_loc", 0);
1822 Asm->SwitchToDataSection(TAI->getDwarfPubNamesSection());
1823 EmitLabel("section_pubnames", 0);
1824 Asm->SwitchToDataSection(TAI->getDwarfStrSection());
1825 EmitLabel("section_str", 0);
1826 Asm->SwitchToDataSection(TAI->getDwarfRangesSection());
1827 EmitLabel("section_ranges", 0);
1829 Asm->SwitchToTextSection(TAI->getTextSection());
1830 EmitLabel("text_begin", 0);
1831 Asm->SwitchToDataSection(TAI->getDataSection());
1832 EmitLabel("data_begin", 0);
1834 // Emit common frame information.
1835 EmitInitialDebugFrame();
1838 /// EmitDIE - Recusively Emits a debug information entry.
1840 void EmitDIE(DIE *Die) const {
1841 // Get the abbreviation for this DIE.
1842 unsigned AbbrevNumber = Die->getAbbrevNumber();
1843 const DIEAbbrev *Abbrev = Abbreviations[AbbrevNumber - 1];
1847 // Emit the code (index) for the abbreviation.
1848 Asm->EmitULEB128Bytes(AbbrevNumber);
1849 Asm->EOL(std::string("Abbrev [" +
1850 utostr(AbbrevNumber) +
1851 "] 0x" + utohexstr(Die->getOffset()) +
1852 ":0x" + utohexstr(Die->getSize()) + " " +
1853 TagString(Abbrev->getTag())));
1855 const std::vector<DIEValue *> &Values = Die->getValues();
1856 const std::vector<DIEAbbrevData> &AbbrevData = Abbrev->getData();
1858 // Emit the DIE attribute values.
1859 for (unsigned i = 0, N = Values.size(); i < N; ++i) {
1860 unsigned Attr = AbbrevData[i].getAttribute();
1861 unsigned Form = AbbrevData[i].getForm();
1862 assert(Form && "Too many attributes for DIE (check abbreviation)");
1865 case DW_AT_sibling: {
1866 Asm->EmitInt32(Die->SiblingOffset());
1870 // Emit an attribute using the defined form.
1871 Values[i]->EmitValue(*this, Form);
1876 Asm->EOL(AttributeString(Attr));
1879 // Emit the DIE children if any.
1880 if (Abbrev->getChildrenFlag() == DW_CHILDREN_yes) {
1881 const std::vector<DIE *> &Children = Die->getChildren();
1883 for (unsigned j = 0, M = Children.size(); j < M; ++j) {
1884 EmitDIE(Children[j]);
1887 Asm->EmitInt8(0); Asm->EOL("End Of Children Mark");
1891 /// SizeAndOffsetDie - Compute the size and offset of a DIE.
1893 unsigned SizeAndOffsetDie(DIE *Die, unsigned Offset, bool Last) {
1894 // Get the children.
1895 const std::vector<DIE *> &Children = Die->getChildren();
1897 // If not last sibling and has children then add sibling offset attribute.
1898 if (!Last && !Children.empty()) Die->AddSiblingOffset();
1900 // Record the abbreviation.
1901 AssignAbbrevNumber(Die->getAbbrev());
1903 // Get the abbreviation for this DIE.
1904 unsigned AbbrevNumber = Die->getAbbrevNumber();
1905 const DIEAbbrev *Abbrev = Abbreviations[AbbrevNumber - 1];
1908 Die->setOffset(Offset);
1910 // Start the size with the size of abbreviation code.
1911 Offset += Asm->SizeULEB128(AbbrevNumber);
1913 const std::vector<DIEValue *> &Values = Die->getValues();
1914 const std::vector<DIEAbbrevData> &AbbrevData = Abbrev->getData();
1916 // Size the DIE attribute values.
1917 for (unsigned i = 0, N = Values.size(); i < N; ++i) {
1918 // Size attribute value.
1919 Offset += Values[i]->SizeOf(*this, AbbrevData[i].getForm());
1922 // Size the DIE children if any.
1923 if (!Children.empty()) {
1924 assert(Abbrev->getChildrenFlag() == DW_CHILDREN_yes &&
1925 "Children flag not set");
1927 for (unsigned j = 0, M = Children.size(); j < M; ++j) {
1928 Offset = SizeAndOffsetDie(Children[j], Offset, (j + 1) == M);
1931 // End of children marker.
1932 Offset += sizeof(int8_t);
1935 Die->setSize(Offset - Die->getOffset());
1939 /// SizeAndOffsets - Compute the size and offset of all the DIEs.
1941 void SizeAndOffsets() {
1942 // Process base compile unit.
1943 CompileUnit *Unit = GetBaseCompileUnit();
1944 // Compute size of compile unit header
1945 unsigned Offset = sizeof(int32_t) + // Length of Compilation Unit Info
1946 sizeof(int16_t) + // DWARF version number
1947 sizeof(int32_t) + // Offset Into Abbrev. Section
1948 sizeof(int8_t); // Pointer Size (in bytes)
1949 SizeAndOffsetDie(Unit->getDie(), Offset, true);
1952 /// EmitFrameMoves - Emit frame instructions to describe the layout of the
1954 void EmitFrameMoves(const char *BaseLabel, unsigned BaseLabelID,
1955 std::vector<MachineMove> &Moves) {
1957 Asm->TM.getFrameInfo()->getStackGrowthDirection() ==
1958 TargetFrameInfo::StackGrowsUp ?
1959 TAI->getAddressSize() : -TAI->getAddressSize();
1961 for (unsigned i = 0, N = Moves.size(); i < N; ++i) {
1962 MachineMove &Move = Moves[i];
1963 unsigned LabelID = Move.getLabelID();
1966 LabelID = MMI->MappedLabel(LabelID);
1968 // Throw out move if the label is invalid.
1969 if (!LabelID) continue;
1972 const MachineLocation &Dst = Move.getDestination();
1973 const MachineLocation &Src = Move.getSource();
1975 // Advance row if new location.
1976 if (BaseLabel && LabelID && BaseLabelID != LabelID) {
1977 Asm->EmitInt8(DW_CFA_advance_loc4);
1978 Asm->EOL("DW_CFA_advance_loc4");
1979 EmitDifference("loc", LabelID, BaseLabel, BaseLabelID, true);
1982 BaseLabelID = LabelID;
1986 // If advancing cfa.
1987 if (Dst.isRegister() && Dst.getRegister() == MachineLocation::VirtualFP) {
1988 if (!Src.isRegister()) {
1989 if (Src.getRegister() == MachineLocation::VirtualFP) {
1990 Asm->EmitInt8(DW_CFA_def_cfa_offset);
1991 Asm->EOL("DW_CFA_def_cfa_offset");
1993 Asm->EmitInt8(DW_CFA_def_cfa);
1994 Asm->EOL("DW_CFA_def_cfa");
1995 Asm->EmitULEB128Bytes(RI->getDwarfRegNum(Src.getRegister()));
1996 Asm->EOL("Register");
1999 int Offset = Src.getOffset() / stackGrowth;
2001 Asm->EmitULEB128Bytes(Offset);
2004 assert(0 && "Machine move no supported yet.");
2006 } else if (Src.isRegister() &&
2007 Src.getRegister() == MachineLocation::VirtualFP) {
2008 if (Dst.isRegister()) {
2009 Asm->EmitInt8(DW_CFA_def_cfa_register);
2010 Asm->EOL("DW_CFA_def_cfa_register");
2011 Asm->EmitULEB128Bytes(RI->getDwarfRegNum(Dst.getRegister()));
2012 Asm->EOL("Register");
2014 assert(0 && "Machine move no supported yet.");
2017 unsigned Reg = RI->getDwarfRegNum(Src.getRegister());
2018 int Offset = Dst.getOffset() / stackGrowth;
2021 Asm->EmitInt8(DW_CFA_offset_extended_sf);
2022 Asm->EOL("DW_CFA_offset_extended_sf");
2023 Asm->EmitULEB128Bytes(Reg);
2025 Asm->EmitSLEB128Bytes(Offset);
2027 } else if (Reg < 64) {
2028 Asm->EmitInt8(DW_CFA_offset + Reg);
2029 Asm->EOL("DW_CFA_offset + Reg");
2030 Asm->EmitULEB128Bytes(Offset);
2033 Asm->EmitInt8(DW_CFA_offset_extended);
2034 Asm->EOL("DW_CFA_offset_extended");
2035 Asm->EmitULEB128Bytes(Reg);
2037 Asm->EmitULEB128Bytes(Offset);
2044 /// EmitDebugInfo - Emit the debug info section.
2046 void EmitDebugInfo() const {
2047 // Start debug info section.
2048 Asm->SwitchToDataSection(TAI->getDwarfInfoSection());
2050 CompileUnit *Unit = GetBaseCompileUnit();
2051 DIE *Die = Unit->getDie();
2052 // Emit the compile units header.
2053 EmitLabel("info_begin", Unit->getID());
2054 // Emit size of content not including length itself
2055 unsigned ContentSize = Die->getSize() +
2056 sizeof(int16_t) + // DWARF version number
2057 sizeof(int32_t) + // Offset Into Abbrev. Section
2058 sizeof(int8_t) + // Pointer Size (in bytes)
2059 sizeof(int32_t); // FIXME - extra pad for gdb bug.
2061 Asm->EmitInt32(ContentSize); Asm->EOL("Length of Compilation Unit Info");
2062 Asm->EmitInt16(DWARF_VERSION); Asm->EOL("DWARF version number");
2063 EmitDifference("abbrev_begin", 0, "section_abbrev", 0, true);
2064 Asm->EOL("Offset Into Abbrev. Section");
2065 Asm->EmitInt8(TAI->getAddressSize()); Asm->EOL("Address Size (in bytes)");
2068 // FIXME - extra padding for gdb bug.
2069 Asm->EmitInt8(0); Asm->EOL("Extra Pad For GDB");
2070 Asm->EmitInt8(0); Asm->EOL("Extra Pad For GDB");
2071 Asm->EmitInt8(0); Asm->EOL("Extra Pad For GDB");
2072 Asm->EmitInt8(0); Asm->EOL("Extra Pad For GDB");
2073 EmitLabel("info_end", Unit->getID());
2078 /// EmitAbbreviations - Emit the abbreviation section.
2080 void EmitAbbreviations() const {
2081 // Check to see if it is worth the effort.
2082 if (!Abbreviations.empty()) {
2083 // Start the debug abbrev section.
2084 Asm->SwitchToDataSection(TAI->getDwarfAbbrevSection());
2086 EmitLabel("abbrev_begin", 0);
2088 // For each abbrevation.
2089 for (unsigned i = 0, N = Abbreviations.size(); i < N; ++i) {
2090 // Get abbreviation data
2091 const DIEAbbrev *Abbrev = Abbreviations[i];
2093 // Emit the abbrevations code (base 1 index.)
2094 Asm->EmitULEB128Bytes(Abbrev->getNumber());
2095 Asm->EOL("Abbreviation Code");
2097 // Emit the abbreviations data.
2098 Abbrev->Emit(*this);
2103 EmitLabel("abbrev_end", 0);
2109 /// EmitDebugLines - Emit source line information.
2111 void EmitDebugLines() const {
2112 // Minimum line delta, thus ranging from -10..(255-10).
2113 const int MinLineDelta = -(DW_LNS_fixed_advance_pc + 1);
2114 // Maximum line delta, thus ranging from -10..(255-10).
2115 const int MaxLineDelta = 255 + MinLineDelta;
2117 // Start the dwarf line section.
2118 Asm->SwitchToDataSection(TAI->getDwarfLineSection());
2120 // Construct the section header.
2122 EmitDifference("line_end", 0, "line_begin", 0, true);
2123 Asm->EOL("Length of Source Line Info");
2124 EmitLabel("line_begin", 0);
2126 Asm->EmitInt16(DWARF_VERSION); Asm->EOL("DWARF version number");
2128 EmitDifference("line_prolog_end", 0, "line_prolog_begin", 0, true);
2129 Asm->EOL("Prolog Length");
2130 EmitLabel("line_prolog_begin", 0);
2132 Asm->EmitInt8(1); Asm->EOL("Minimum Instruction Length");
2134 Asm->EmitInt8(1); Asm->EOL("Default is_stmt_start flag");
2136 Asm->EmitInt8(MinLineDelta); Asm->EOL("Line Base Value (Special Opcodes)");
2138 Asm->EmitInt8(MaxLineDelta); Asm->EOL("Line Range Value (Special Opcodes)");
2140 Asm->EmitInt8(-MinLineDelta); Asm->EOL("Special Opcode Base");
2142 // Line number standard opcode encodings argument count
2143 Asm->EmitInt8(0); Asm->EOL("DW_LNS_copy arg count");
2144 Asm->EmitInt8(1); Asm->EOL("DW_LNS_advance_pc arg count");
2145 Asm->EmitInt8(1); Asm->EOL("DW_LNS_advance_line arg count");
2146 Asm->EmitInt8(1); Asm->EOL("DW_LNS_set_file arg count");
2147 Asm->EmitInt8(1); Asm->EOL("DW_LNS_set_column arg count");
2148 Asm->EmitInt8(0); Asm->EOL("DW_LNS_negate_stmt arg count");
2149 Asm->EmitInt8(0); Asm->EOL("DW_LNS_set_basic_block arg count");
2150 Asm->EmitInt8(0); Asm->EOL("DW_LNS_const_add_pc arg count");
2151 Asm->EmitInt8(1); Asm->EOL("DW_LNS_fixed_advance_pc arg count");
2153 const UniqueVector<std::string> &Directories = MMI->getDirectories();
2154 const UniqueVector<SourceFileInfo>
2155 &SourceFiles = MMI->getSourceFiles();
2157 // Emit directories.
2158 for (unsigned DirectoryID = 1, NDID = Directories.size();
2159 DirectoryID <= NDID; ++DirectoryID) {
2160 Asm->EmitString(Directories[DirectoryID]); Asm->EOL("Directory");
2162 Asm->EmitInt8(0); Asm->EOL("End of directories");
2165 for (unsigned SourceID = 1, NSID = SourceFiles.size();
2166 SourceID <= NSID; ++SourceID) {
2167 const SourceFileInfo &SourceFile = SourceFiles[SourceID];
2168 Asm->EmitString(SourceFile.getName());
2170 Asm->EmitULEB128Bytes(SourceFile.getDirectoryID());
2171 Asm->EOL("Directory #");
2172 Asm->EmitULEB128Bytes(0);
2173 Asm->EOL("Mod date");
2174 Asm->EmitULEB128Bytes(0);
2175 Asm->EOL("File size");
2177 Asm->EmitInt8(0); Asm->EOL("End of files");
2179 EmitLabel("line_prolog_end", 0);
2181 // A sequence for each text section.
2182 for (unsigned j = 0, M = SectionSourceLines.size(); j < M; ++j) {
2183 // Isolate current sections line info.
2184 const std::vector<SourceLineInfo> &LineInfos = SectionSourceLines[j];
2186 Asm->EOL(std::string("Section ") + SectionMap[j + 1]);
2188 // Dwarf assumes we start with first line of first source file.
2189 unsigned Source = 1;
2192 // Construct rows of the address, source, line, column matrix.
2193 for (unsigned i = 0, N = LineInfos.size(); i < N; ++i) {
2194 const SourceLineInfo &LineInfo = LineInfos[i];
2195 unsigned LabelID = MMI->MappedLabel(LineInfo.getLabelID());
2196 if (!LabelID) continue;
2198 unsigned SourceID = LineInfo.getSourceID();
2199 const SourceFileInfo &SourceFile = SourceFiles[SourceID];
2200 unsigned DirectoryID = SourceFile.getDirectoryID();
2201 Asm->EOL(Directories[DirectoryID]
2202 + SourceFile.getName()
2204 + utostr_32(LineInfo.getLine()));
2206 // Define the line address.
2207 Asm->EmitInt8(0); Asm->EOL("Extended Op");
2208 Asm->EmitInt8(TAI->getAddressSize() + 1); Asm->EOL("Op size");
2209 Asm->EmitInt8(DW_LNE_set_address); Asm->EOL("DW_LNE_set_address");
2210 EmitReference("loc", LabelID); Asm->EOL("Location label");
2212 // If change of source, then switch to the new source.
2213 if (Source != LineInfo.getSourceID()) {
2214 Source = LineInfo.getSourceID();
2215 Asm->EmitInt8(DW_LNS_set_file); Asm->EOL("DW_LNS_set_file");
2216 Asm->EmitULEB128Bytes(Source); Asm->EOL("New Source");
2219 // If change of line.
2220 if (Line != LineInfo.getLine()) {
2221 // Determine offset.
2222 int Offset = LineInfo.getLine() - Line;
2223 int Delta = Offset - MinLineDelta;
2226 Line = LineInfo.getLine();
2228 // If delta is small enough and in range...
2229 if (Delta >= 0 && Delta < (MaxLineDelta - 1)) {
2230 // ... then use fast opcode.
2231 Asm->EmitInt8(Delta - MinLineDelta); Asm->EOL("Line Delta");
2233 // ... otherwise use long hand.
2234 Asm->EmitInt8(DW_LNS_advance_line); Asm->EOL("DW_LNS_advance_line");
2235 Asm->EmitSLEB128Bytes(Offset); Asm->EOL("Line Offset");
2236 Asm->EmitInt8(DW_LNS_copy); Asm->EOL("DW_LNS_copy");
2239 // Copy the previous row (different address or source)
2240 Asm->EmitInt8(DW_LNS_copy); Asm->EOL("DW_LNS_copy");
2244 // Define last address of section.
2245 Asm->EmitInt8(0); Asm->EOL("Extended Op");
2246 Asm->EmitInt8(TAI->getAddressSize() + 1); Asm->EOL("Op size");
2247 Asm->EmitInt8(DW_LNE_set_address); Asm->EOL("DW_LNE_set_address");
2248 EmitReference("section_end", j + 1); Asm->EOL("Section end label");
2250 // Mark end of matrix.
2251 Asm->EmitInt8(0); Asm->EOL("DW_LNE_end_sequence");
2252 Asm->EmitULEB128Bytes(1); Asm->EOL("");
2253 Asm->EmitInt8(1); Asm->EOL("");
2256 EmitLabel("line_end", 0);
2261 /// EmitInitialDebugFrame - Emit common frame info into a debug frame section.
2263 void EmitInitialDebugFrame() {
2264 if (!TAI->getDwarfRequiresFrameSection())
2268 Asm->TM.getFrameInfo()->getStackGrowthDirection() ==
2269 TargetFrameInfo::StackGrowsUp ?
2270 TAI->getAddressSize() : -TAI->getAddressSize();
2272 // Start the dwarf frame section.
2273 Asm->SwitchToDataSection(TAI->getDwarfFrameSection());
2275 EmitLabel("frame_common", 0);
2276 EmitDifference("frame_common_end", 0,
2277 "frame_common_begin", 0, true);
2278 Asm->EOL("Length of Common Information Entry");
2280 EmitLabel("frame_common_begin", 0);
2281 Asm->EmitInt32((int)DW_CIE_ID);
2282 Asm->EOL("CIE Identifier Tag");
2283 Asm->EmitInt8(DW_CIE_VERSION);
2284 Asm->EOL("CIE Version");
2285 Asm->EmitString("");
2286 Asm->EOL("CIE Augmentation");
2287 Asm->EmitULEB128Bytes(1);
2288 Asm->EOL("CIE Code Alignment Factor");
2289 Asm->EmitSLEB128Bytes(stackGrowth);
2290 Asm->EOL("CIE Data Alignment Factor");
2291 Asm->EmitInt8(RI->getDwarfRegNum(RI->getRARegister()));
2292 Asm->EOL("CIE RA Column");
2294 std::vector<MachineMove> Moves;
2295 RI->getInitialFrameState(Moves);
2296 EmitFrameMoves(NULL, 0, Moves);
2298 Asm->EmitAlignment(2);
2299 EmitLabel("frame_common_end", 0);
2304 /// EmitFunctionDebugFrame - Emit per function frame info into a debug frame
2306 void EmitFunctionDebugFrame() {
2307 if (!TAI->getDwarfRequiresFrameSection())
2310 // Start the dwarf frame section.
2311 Asm->SwitchToDataSection(TAI->getDwarfFrameSection());
2313 EmitDifference("frame_end", SubprogramCount,
2314 "frame_begin", SubprogramCount, true);
2315 Asm->EOL("Length of Frame Information Entry");
2317 EmitLabel("frame_begin", SubprogramCount);
2319 EmitDifference("frame_common", 0, "section_frame", 0, true);
2320 Asm->EOL("FDE CIE offset");
2322 EmitReference("func_begin", SubprogramCount);
2323 Asm->EOL("FDE initial location");
2324 EmitDifference("func_end", SubprogramCount,
2325 "func_begin", SubprogramCount);
2326 Asm->EOL("FDE address range");
2328 std::vector<MachineMove> &Moves = MMI->getFrameMoves();
2330 EmitFrameMoves("func_begin", SubprogramCount, Moves);
2332 Asm->EmitAlignment(2);
2333 EmitLabel("frame_end", SubprogramCount);
2338 /// EmitDebugPubNames - Emit visible names into a debug pubnames section.
2340 void EmitDebugPubNames() {
2341 // Start the dwarf pubnames section.
2342 Asm->SwitchToDataSection(TAI->getDwarfPubNamesSection());
2344 CompileUnit *Unit = GetBaseCompileUnit();
2346 EmitDifference("pubnames_end", Unit->getID(),
2347 "pubnames_begin", Unit->getID(), true);
2348 Asm->EOL("Length of Public Names Info");
2350 EmitLabel("pubnames_begin", Unit->getID());
2352 Asm->EmitInt16(DWARF_VERSION); Asm->EOL("DWARF Version");
2354 EmitDifference("info_begin", Unit->getID(), "section_info", 0, true);
2355 Asm->EOL("Offset of Compilation Unit Info");
2357 EmitDifference("info_end", Unit->getID(), "info_begin", Unit->getID(),true);
2358 Asm->EOL("Compilation Unit Length");
2360 std::map<std::string, DIE *> &Globals = Unit->getGlobals();
2362 for (std::map<std::string, DIE *>::iterator GI = Globals.begin(),
2365 const std::string &Name = GI->first;
2366 DIE * Entity = GI->second;
2368 Asm->EmitInt32(Entity->getOffset()); Asm->EOL("DIE offset");
2369 Asm->EmitString(Name); Asm->EOL("External Name");
2372 Asm->EmitInt32(0); Asm->EOL("End Mark");
2373 EmitLabel("pubnames_end", Unit->getID());
2378 /// EmitDebugStr - Emit visible names into a debug str section.
2380 void EmitDebugStr() {
2381 // Check to see if it is worth the effort.
2382 if (!StringPool.empty()) {
2383 // Start the dwarf str section.
2384 Asm->SwitchToDataSection(TAI->getDwarfStrSection());
2386 // For each of strings in the string pool.
2387 for (unsigned StringID = 1, N = StringPool.size();
2388 StringID <= N; ++StringID) {
2389 // Emit a label for reference from debug information entries.
2390 EmitLabel("string", StringID);
2391 // Emit the string itself.
2392 const std::string &String = StringPool[StringID];
2393 Asm->EmitString(String); Asm->EOL("");
2400 /// EmitDebugLoc - Emit visible names into a debug loc section.
2402 void EmitDebugLoc() {
2403 // Start the dwarf loc section.
2404 Asm->SwitchToDataSection(TAI->getDwarfLocSection());
2409 /// EmitDebugARanges - Emit visible names into a debug aranges section.
2411 void EmitDebugARanges() {
2412 // Start the dwarf aranges section.
2413 Asm->SwitchToDataSection(TAI->getDwarfARangesSection());
2417 CompileUnit *Unit = GetBaseCompileUnit();
2419 // Don't include size of length
2420 Asm->EmitInt32(0x1c); Asm->EOL("Length of Address Ranges Info");
2422 Asm->EmitInt16(DWARF_VERSION); Asm->EOL("Dwarf Version");
2424 EmitReference("info_begin", Unit->getID());
2425 Asm->EOL("Offset of Compilation Unit Info");
2427 Asm->EmitInt8(TAI->getAddressSize()); Asm->EOL("Size of Address");
2429 Asm->EmitInt8(0); Asm->EOL("Size of Segment Descriptor");
2431 Asm->EmitInt16(0); Asm->EOL("Pad (1)");
2432 Asm->EmitInt16(0); Asm->EOL("Pad (2)");
2435 EmitReference("text_begin", 0); Asm->EOL("Address");
2436 EmitDifference("text_end", 0, "text_begin", 0, true); Asm->EOL("Length");
2438 Asm->EmitInt32(0); Asm->EOL("EOM (1)");
2439 Asm->EmitInt32(0); Asm->EOL("EOM (2)");
2445 /// EmitDebugRanges - Emit visible names into a debug ranges section.
2447 void EmitDebugRanges() {
2448 // Start the dwarf ranges section.
2449 Asm->SwitchToDataSection(TAI->getDwarfRangesSection());
2454 /// EmitDebugMacInfo - Emit visible names into a debug macinfo section.
2456 void EmitDebugMacInfo() {
2457 // Start the dwarf macinfo section.
2458 Asm->SwitchToDataSection(TAI->getDwarfMacInfoSection());
2463 /// ConstructCompileUnitDIEs - Create a compile unit DIE for each source and
2465 void ConstructCompileUnitDIEs() {
2466 const UniqueVector<CompileUnitDesc *> CUW = MMI->getCompileUnits();
2468 for (unsigned i = 1, N = CUW.size(); i <= N; ++i) {
2469 unsigned ID = MMI->RecordSource(CUW[i]);
2470 CompileUnit *Unit = NewCompileUnit(CUW[i], ID);
2471 CompileUnits.push_back(Unit);
2475 /// ConstructGlobalDIEs - Create DIEs for each of the externally visible
2476 /// global variables.
2477 void ConstructGlobalDIEs() {
2478 std::vector<GlobalVariableDesc *> GlobalVariables =
2479 MMI->getAnchoredDescriptors<GlobalVariableDesc>(*M);
2481 for (unsigned i = 0, N = GlobalVariables.size(); i < N; ++i) {
2482 GlobalVariableDesc *GVD = GlobalVariables[i];
2483 NewGlobalVariable(GVD);
2487 /// ConstructSubprogramDIEs - Create DIEs for each of the externally visible
2489 void ConstructSubprogramDIEs() {
2490 std::vector<SubprogramDesc *> Subprograms =
2491 MMI->getAnchoredDescriptors<SubprogramDesc>(*M);
2493 for (unsigned i = 0, N = Subprograms.size(); i < N; ++i) {
2494 SubprogramDesc *SPD = Subprograms[i];
2500 //===--------------------------------------------------------------------===//
2501 // Main entry points.
2503 DwarfDebug(std::ostream &OS, AsmPrinter *A, const TargetAsmInfo *T)
2506 , AbbreviationsSet(InitAbbreviationsSetSize)
2508 , ValuesSet(InitValuesSetSize)
2513 , SectionSourceLines()
2516 virtual ~DwarfDebug() {
2517 for (unsigned i = 0, N = CompileUnits.size(); i < N; ++i)
2518 delete CompileUnits[i];
2519 for (unsigned j = 0, M = Values.size(); j < M; ++j)
2523 /// SetModuleInfo - Set machine module information when it's known that pass
2524 /// manager has created it. Set by the target AsmPrinter.
2525 void SetModuleInfo(MachineModuleInfo *mmi) {
2526 // Make sure initial declarations are made.
2527 if (!MMI && mmi->hasDebugInfo()) {
2531 // Emit initial sections
2534 // Create all the compile unit DIEs.
2535 ConstructCompileUnitDIEs();
2537 // Create DIEs for each of the externally visible global variables.
2538 ConstructGlobalDIEs();
2540 // Create DIEs for each of the externally visible subprograms.
2541 ConstructSubprogramDIEs();
2543 // Prime section data.
2544 SectionMap.insert(TAI->getTextSection());
2548 /// BeginModule - Emit all Dwarf sections that should come prior to the
2550 void BeginModule(Module *M) {
2553 if (!ShouldEmitDwarf()) return;
2556 /// EndModule - Emit all Dwarf sections that should come after the content.
2559 if (!ShouldEmitDwarf()) return;
2561 // Standard sections final addresses.
2562 Asm->SwitchToTextSection(TAI->getTextSection());
2563 EmitLabel("text_end", 0);
2564 Asm->SwitchToDataSection(TAI->getDataSection());
2565 EmitLabel("data_end", 0);
2567 // End text sections.
2568 for (unsigned i = 1, N = SectionMap.size(); i <= N; ++i) {
2569 Asm->SwitchToTextSection(SectionMap[i].c_str());
2570 EmitLabel("section_end", i);
2573 // Compute DIE offsets and sizes.
2576 // Emit all the DIEs into a debug info section
2579 // Corresponding abbreviations into a abbrev section.
2580 EmitAbbreviations();
2582 // Emit source line correspondence into a debug line section.
2585 // Emit info into a debug pubnames section.
2586 EmitDebugPubNames();
2588 // Emit info into a debug str section.
2591 // Emit info into a debug loc section.
2594 // Emit info into a debug aranges section.
2597 // Emit info into a debug ranges section.
2600 // Emit info into a debug macinfo section.
2604 /// BeginFunction - Gather pre-function debug information. Assumes being
2605 /// emitted immediately after the function entry point.
2606 void BeginFunction(MachineFunction *MF) {
2609 if (!ShouldEmitDwarf()) return;
2611 // Begin accumulating function debug information.
2612 MMI->BeginFunction(MF);
2614 // Assumes in correct section after the entry point.
2615 EmitLabel("func_begin", ++SubprogramCount);
2618 /// PreExceptionEndFunction - Close off function before exception handling
2620 void PreExceptionEndFunction() {
2621 if (!ShouldEmitDwarf()) return;
2623 // Define end label for subprogram.
2624 EmitLabel("func_end", SubprogramCount);
2627 /// EndFunction - Gather and emit post-function debug information.
2629 void EndFunction() {
2630 if (!ShouldEmitDwarf()) return;
2632 // Get function line info.
2633 const std::vector<SourceLineInfo> &LineInfos = MMI->getSourceLines();
2635 if (!LineInfos.empty()) {
2636 // Get section line info.
2637 unsigned ID = SectionMap.insert(Asm->CurrentSection);
2638 if (SectionSourceLines.size() < ID) SectionSourceLines.resize(ID);
2639 std::vector<SourceLineInfo> &SectionLineInfos = SectionSourceLines[ID-1];
2640 // Append the function info to section info.
2641 SectionLineInfos.insert(SectionLineInfos.end(),
2642 LineInfos.begin(), LineInfos.end());
2645 // Construct scopes for subprogram.
2646 ConstructRootScope(MMI->getRootScope());
2648 // Emit function frame information.
2649 EmitFunctionDebugFrame();
2651 // Reset the line numbers for the next function.
2652 MMI->ClearLineInfo();
2654 // Clear function debug information.
2659 //===----------------------------------------------------------------------===//
2660 /// DwarfException - Emits Dwarf exception handling directives.
2662 class DwarfException : public Dwarf {
2665 //===--------------------------------------------------------------------===//
2666 // Main entry points.
2668 DwarfException(std::ostream &OS, AsmPrinter *A, const TargetAsmInfo *T)
2672 virtual ~DwarfException() {}
2674 /// SetModuleInfo - Set machine module information when it's known that pass
2675 /// manager has created it. Set by the target AsmPrinter.
2676 void SetModuleInfo(MachineModuleInfo *mmi) {
2677 // Make sure initial declarations are made.
2678 if (!MMI && ExceptionHandling && TAI->getSupportsExceptionHandling()) {
2684 /// BeginModule - Emit all exception information that should come prior to the
2686 void BeginModule(Module *M) {
2689 if (!ShouldEmitDwarf()) return;
2692 /// EndModule - Emit all exception information that should come after the
2695 if (!ShouldEmitDwarf()) return;
2698 /// BeginFunction - Gather pre-function exception information. Assumes being
2699 /// emitted immediately after the function entry point.
2700 void BeginFunction(MachineFunction *MF) {
2703 if (!ShouldEmitDwarf()) return;
2706 /// EndFunction - Gather and emit post-function exception information.
2708 void EndFunction() {
2709 if (!ShouldEmitDwarf()) return;
2711 if (const char *GlobalDirective = TAI->getGlobalDirective())
2712 O << GlobalDirective << getAsm()->CurrentFnName << ".eh\n";
2714 O << getAsm()->CurrentFnName << ".eh = 0\n";
2716 if (const char *UsedDirective = TAI->getUsedDirective())
2717 O << UsedDirective << getAsm()->CurrentFnName << ".eh\n";
2722 } // End of namespace llvm
2724 //===----------------------------------------------------------------------===//
2726 /// Emit - Print the abbreviation using the specified Dwarf writer.
2728 void DIEAbbrev::Emit(const DwarfDebug &DD) const {
2729 // Emit its Dwarf tag type.
2730 DD.getAsm()->EmitULEB128Bytes(Tag);
2731 DD.getAsm()->EOL(TagString(Tag));
2733 // Emit whether it has children DIEs.
2734 DD.getAsm()->EmitULEB128Bytes(ChildrenFlag);
2735 DD.getAsm()->EOL(ChildrenString(ChildrenFlag));
2737 // For each attribute description.
2738 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
2739 const DIEAbbrevData &AttrData = Data[i];
2741 // Emit attribute type.
2742 DD.getAsm()->EmitULEB128Bytes(AttrData.getAttribute());
2743 DD.getAsm()->EOL(AttributeString(AttrData.getAttribute()));
2746 DD.getAsm()->EmitULEB128Bytes(AttrData.getForm());
2747 DD.getAsm()->EOL(FormEncodingString(AttrData.getForm()));
2750 // Mark end of abbreviation.
2751 DD.getAsm()->EmitULEB128Bytes(0); DD.getAsm()->EOL("EOM(1)");
2752 DD.getAsm()->EmitULEB128Bytes(0); DD.getAsm()->EOL("EOM(2)");
2756 void DIEAbbrev::print(std::ostream &O) {
2757 O << "Abbreviation @"
2758 << std::hex << (intptr_t)this << std::dec
2762 << ChildrenString(ChildrenFlag)
2765 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
2767 << AttributeString(Data[i].getAttribute())
2769 << FormEncodingString(Data[i].getForm())
2773 void DIEAbbrev::dump() { print(cerr); }
2776 //===----------------------------------------------------------------------===//
2779 void DIEValue::dump() {
2784 //===----------------------------------------------------------------------===//
2786 /// EmitValue - Emit integer of appropriate size.
2788 void DIEInteger::EmitValue(const DwarfDebug &DD, unsigned Form) const {
2790 case DW_FORM_flag: // Fall thru
2791 case DW_FORM_ref1: // Fall thru
2792 case DW_FORM_data1: DD.getAsm()->EmitInt8(Integer); break;
2793 case DW_FORM_ref2: // Fall thru
2794 case DW_FORM_data2: DD.getAsm()->EmitInt16(Integer); break;
2795 case DW_FORM_ref4: // Fall thru
2796 case DW_FORM_data4: DD.getAsm()->EmitInt32(Integer); break;
2797 case DW_FORM_ref8: // Fall thru
2798 case DW_FORM_data8: DD.getAsm()->EmitInt64(Integer); break;
2799 case DW_FORM_udata: DD.getAsm()->EmitULEB128Bytes(Integer); break;
2800 case DW_FORM_sdata: DD.getAsm()->EmitSLEB128Bytes(Integer); break;
2801 default: assert(0 && "DIE Value form not supported yet"); break;
2805 /// SizeOf - Determine size of integer value in bytes.
2807 unsigned DIEInteger::SizeOf(const DwarfDebug &DD, unsigned Form) const {
2809 case DW_FORM_flag: // Fall thru
2810 case DW_FORM_ref1: // Fall thru
2811 case DW_FORM_data1: return sizeof(int8_t);
2812 case DW_FORM_ref2: // Fall thru
2813 case DW_FORM_data2: return sizeof(int16_t);
2814 case DW_FORM_ref4: // Fall thru
2815 case DW_FORM_data4: return sizeof(int32_t);
2816 case DW_FORM_ref8: // Fall thru
2817 case DW_FORM_data8: return sizeof(int64_t);
2818 case DW_FORM_udata: return DD.getAsm()->SizeULEB128(Integer);
2819 case DW_FORM_sdata: return DD.getAsm()->SizeSLEB128(Integer);
2820 default: assert(0 && "DIE Value form not supported yet"); break;
2825 //===----------------------------------------------------------------------===//
2827 /// EmitValue - Emit string value.
2829 void DIEString::EmitValue(const DwarfDebug &DD, unsigned Form) const {
2830 DD.getAsm()->EmitString(String);
2833 //===----------------------------------------------------------------------===//
2835 /// EmitValue - Emit label value.
2837 void DIEDwarfLabel::EmitValue(const DwarfDebug &DD, unsigned Form) const {
2838 DD.EmitReference(Label);
2841 /// SizeOf - Determine size of label value in bytes.
2843 unsigned DIEDwarfLabel::SizeOf(const DwarfDebug &DD, unsigned Form) const {
2844 return DD.getTargetAsmInfo()->getAddressSize();
2847 //===----------------------------------------------------------------------===//
2849 /// EmitValue - Emit label value.
2851 void DIEObjectLabel::EmitValue(const DwarfDebug &DD, unsigned Form) const {
2852 DD.EmitReference(Label);
2855 /// SizeOf - Determine size of label value in bytes.
2857 unsigned DIEObjectLabel::SizeOf(const DwarfDebug &DD, unsigned Form) const {
2858 return DD.getTargetAsmInfo()->getAddressSize();
2861 //===----------------------------------------------------------------------===//
2863 /// EmitValue - Emit delta value.
2865 void DIEDelta::EmitValue(const DwarfDebug &DD, unsigned Form) const {
2866 bool IsSmall = Form == DW_FORM_data4;
2867 DD.EmitDifference(LabelHi, LabelLo, IsSmall);
2870 /// SizeOf - Determine size of delta value in bytes.
2872 unsigned DIEDelta::SizeOf(const DwarfDebug &DD, unsigned Form) const {
2873 if (Form == DW_FORM_data4) return 4;
2874 return DD.getTargetAsmInfo()->getAddressSize();
2877 //===----------------------------------------------------------------------===//
2879 /// EmitValue - Emit debug information entry offset.
2881 void DIEntry::EmitValue(const DwarfDebug &DD, unsigned Form) const {
2882 DD.getAsm()->EmitInt32(Entry->getOffset());
2885 //===----------------------------------------------------------------------===//
2887 /// ComputeSize - calculate the size of the block.
2889 unsigned DIEBlock::ComputeSize(DwarfDebug &DD) {
2891 const std::vector<DIEAbbrevData> &AbbrevData = Abbrev.getData();
2893 for (unsigned i = 0, N = Values.size(); i < N; ++i) {
2894 Size += Values[i]->SizeOf(DD, AbbrevData[i].getForm());
2900 /// EmitValue - Emit block data.
2902 void DIEBlock::EmitValue(const DwarfDebug &DD, unsigned Form) const {
2904 case DW_FORM_block1: DD.getAsm()->EmitInt8(Size); break;
2905 case DW_FORM_block2: DD.getAsm()->EmitInt16(Size); break;
2906 case DW_FORM_block4: DD.getAsm()->EmitInt32(Size); break;
2907 case DW_FORM_block: DD.getAsm()->EmitULEB128Bytes(Size); break;
2908 default: assert(0 && "Improper form for block"); break;
2911 const std::vector<DIEAbbrevData> &AbbrevData = Abbrev.getData();
2913 for (unsigned i = 0, N = Values.size(); i < N; ++i) {
2914 DD.getAsm()->EOL("");
2915 Values[i]->EmitValue(DD, AbbrevData[i].getForm());
2919 /// SizeOf - Determine size of block data in bytes.
2921 unsigned DIEBlock::SizeOf(const DwarfDebug &DD, unsigned Form) const {
2923 case DW_FORM_block1: return Size + sizeof(int8_t);
2924 case DW_FORM_block2: return Size + sizeof(int16_t);
2925 case DW_FORM_block4: return Size + sizeof(int32_t);
2926 case DW_FORM_block: return Size + DD.getAsm()->SizeULEB128(Size);
2927 default: assert(0 && "Improper form for block"); break;
2932 //===----------------------------------------------------------------------===//
2933 /// DIE Implementation
2936 for (unsigned i = 0, N = Children.size(); i < N; ++i)
2940 /// AddSiblingOffset - Add a sibling offset field to the front of the DIE.
2942 void DIE::AddSiblingOffset() {
2943 DIEInteger *DI = new DIEInteger(0);
2944 Values.insert(Values.begin(), DI);
2945 Abbrev.AddFirstAttribute(DW_AT_sibling, DW_FORM_ref4);
2948 /// Profile - Used to gather unique data for the value folding set.
2950 void DIE::Profile(FoldingSetNodeID &ID) {
2953 for (unsigned i = 0, N = Children.size(); i < N; ++i)
2954 ID.AddPointer(Children[i]);
2956 for (unsigned j = 0, M = Values.size(); j < M; ++j)
2957 ID.AddPointer(Values[j]);
2961 void DIE::print(std::ostream &O, unsigned IncIndent) {
2962 static unsigned IndentCount = 0;
2963 IndentCount += IncIndent;
2964 const std::string Indent(IndentCount, ' ');
2965 bool isBlock = Abbrev.getTag() == 0;
2970 << "0x" << std::hex << (intptr_t)this << std::dec
2971 << ", Offset: " << Offset
2972 << ", Size: " << Size
2976 << TagString(Abbrev.getTag())
2978 << ChildrenString(Abbrev.getChildrenFlag());
2980 O << "Size: " << Size;
2984 const std::vector<DIEAbbrevData> &Data = Abbrev.getData();
2987 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
2990 O << AttributeString(Data[i].getAttribute());
2992 O << "Blk[" << i << "]";
2995 << FormEncodingString(Data[i].getForm())
2997 Values[i]->print(O);
3002 for (unsigned j = 0, M = Children.size(); j < M; ++j) {
3003 Children[j]->print(O, 4);
3006 if (!isBlock) O << "\n";
3007 IndentCount -= IncIndent;
3015 //===----------------------------------------------------------------------===//
3016 /// DwarfWriter Implementation
3019 DwarfWriter::DwarfWriter(std::ostream &OS, AsmPrinter *A,
3020 const TargetAsmInfo *T) {
3021 DE = new DwarfException(OS, A, T);
3022 DD = new DwarfDebug(OS, A, T);
3025 DwarfWriter::~DwarfWriter() {
3030 /// SetModuleInfo - Set machine module info when it's known that pass manager
3031 /// has created it. Set by the target AsmPrinter.
3032 void DwarfWriter::SetModuleInfo(MachineModuleInfo *MMI) {
3033 DE->SetModuleInfo(MMI);
3034 DD->SetModuleInfo(MMI);
3037 /// BeginModule - Emit all Dwarf sections that should come prior to the
3039 void DwarfWriter::BeginModule(Module *M) {
3044 /// EndModule - Emit all Dwarf sections that should come after the content.
3046 void DwarfWriter::EndModule() {
3051 /// BeginFunction - Gather pre-function debug information. Assumes being
3052 /// emitted immediately after the function entry point.
3053 void DwarfWriter::BeginFunction(MachineFunction *MF) {
3054 DE->BeginFunction(MF);
3055 DD->BeginFunction(MF);
3058 /// EndFunction - Gather and emit post-function debug information.
3060 void DwarfWriter::EndFunction() {
3061 DD->PreExceptionEndFunction();