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 debug 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/MachineDebugInfo.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/TargetMachine.h"
33 #include "llvm/Target/TargetFrameInfo.h"
37 using namespace llvm::dwarf;
40 DwarfVerbose("dwarf-verbose", cl::Hidden,
41 cl::desc("Add comments to Dwarf directives."));
45 //===----------------------------------------------------------------------===//
47 /// Configuration values for initial hash set sizes (log2).
49 static const unsigned InitDiesSetSize = 9; // 512
50 static const unsigned InitAbbreviationsSetSize = 9; // 512
51 static const unsigned InitValuesSetSize = 9; // 512
53 //===----------------------------------------------------------------------===//
54 /// Forward declarations.
59 //===----------------------------------------------------------------------===//
60 /// LEB 128 number encoding.
62 /// PrintULEB128 - Print a series of hexidecimal values (separated by commas)
63 /// representing an unsigned leb128 value.
64 static void PrintULEB128(std::ostream &O, unsigned Value) {
66 unsigned Byte = Value & 0x7f;
68 if (Value) Byte |= 0x80;
69 O << "0x" << std::hex << Byte << std::dec;
74 /// SizeULEB128 - Compute the number of bytes required for an unsigned leb128
76 static unsigned SizeULEB128(unsigned Value) {
80 Size += sizeof(int8_t);
85 /// PrintSLEB128 - Print a series of hexidecimal values (separated by commas)
86 /// representing a signed leb128 value.
87 static void PrintSLEB128(std::ostream &O, int Value) {
88 int Sign = Value >> (8 * sizeof(Value) - 1);
92 unsigned Byte = Value & 0x7f;
94 IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
95 if (IsMore) Byte |= 0x80;
96 O << "0x" << std::hex << Byte << std::dec;
97 if (IsMore) O << ", ";
101 /// SizeSLEB128 - Compute the number of bytes required for a signed leb128
103 static unsigned SizeSLEB128(int Value) {
105 int Sign = Value >> (8 * sizeof(Value) - 1);
109 unsigned Byte = Value & 0x7f;
111 IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
112 Size += sizeof(int8_t);
117 //===----------------------------------------------------------------------===//
118 /// DWLabel - Labels are used to track locations in the assembler file.
119 /// Labels appear in the form <prefix>debug_<Tag><Number>, where the tag is a
120 /// category of label (Ex. location) and number is a value unique in that
124 /// Tag - Label category tag. Should always be a staticly declared C string.
128 /// Number - Value to make label unique.
132 DWLabel(const char *T, unsigned N) : Tag(T), Number(N) {}
134 void Profile(FoldingSetNodeID &ID) const {
135 ID.AddString(std::string(Tag));
136 ID.AddInteger(Number);
140 void print(OStream &O) const {
141 if (O.stream()) print(*O.stream());
143 void print(std::ostream &O) const {
144 O << ".debug_" << Tag;
145 if (Number) O << Number;
150 //===----------------------------------------------------------------------===//
151 /// DIEAbbrevData - Dwarf abbreviation data, describes the one attribute of a
152 /// Dwarf abbreviation.
153 class DIEAbbrevData {
155 /// Attribute - Dwarf attribute code.
159 /// Form - Dwarf form code.
164 DIEAbbrevData(unsigned A, unsigned F)
170 unsigned getAttribute() const { return Attribute; }
171 unsigned getForm() const { return Form; }
173 /// Profile - Used to gather unique data for the abbreviation folding set.
175 void Profile(FoldingSetNodeID &ID)const {
176 ID.AddInteger(Attribute);
181 //===----------------------------------------------------------------------===//
182 /// DIEAbbrev - Dwarf abbreviation, describes the organization of a debug
183 /// information object.
184 class DIEAbbrev : public FoldingSetNode {
186 /// Tag - Dwarf tag code.
190 /// Unique number for node.
194 /// ChildrenFlag - Dwarf children flag.
196 unsigned ChildrenFlag;
198 /// Data - Raw data bytes for abbreviation.
200 std::vector<DIEAbbrevData> Data;
204 DIEAbbrev(unsigned T, unsigned C)
212 unsigned getTag() const { return Tag; }
213 unsigned getNumber() const { return Number; }
214 unsigned getChildrenFlag() const { return ChildrenFlag; }
215 const std::vector<DIEAbbrevData> &getData() const { return Data; }
216 void setTag(unsigned T) { Tag = T; }
217 void setChildrenFlag(unsigned CF) { ChildrenFlag = CF; }
218 void setNumber(unsigned N) { Number = N; }
220 /// AddAttribute - Adds another set of attribute information to the
222 void AddAttribute(unsigned Attribute, unsigned Form) {
223 Data.push_back(DIEAbbrevData(Attribute, Form));
226 /// AddFirstAttribute - Adds a set of attribute information to the front
227 /// of the abbreviation.
228 void AddFirstAttribute(unsigned Attribute, unsigned Form) {
229 Data.insert(Data.begin(), DIEAbbrevData(Attribute, Form));
232 /// Profile - Used to gather unique data for the abbreviation folding set.
234 void Profile(FoldingSetNodeID &ID) {
236 ID.AddInteger(ChildrenFlag);
238 // For each attribute description.
239 for (unsigned i = 0, N = Data.size(); i < N; ++i)
243 /// Emit - Print the abbreviation using the specified Dwarf writer.
245 void Emit(const Dwarf &DW) const;
248 void print(OStream &O) {
249 if (O.stream()) print(*O.stream());
251 void print(std::ostream &O);
256 //===----------------------------------------------------------------------===//
257 /// DIE - A structured debug information entry. Has an abbreviation which
258 /// describes it's organization.
259 class DIE : public FoldingSetNode {
261 /// Abbrev - Buffer for constructing abbreviation.
265 /// Offset - Offset in debug info section.
269 /// Size - Size of instance + children.
275 std::vector<DIE *> Children;
277 /// Attributes values.
279 std::vector<DIEValue *> Values;
283 : Abbrev(Tag, DW_CHILDREN_no)
292 DIEAbbrev &getAbbrev() { return Abbrev; }
293 unsigned getAbbrevNumber() const {
294 return Abbrev.getNumber();
296 unsigned getTag() const { return Abbrev.getTag(); }
297 unsigned getOffset() const { return Offset; }
298 unsigned getSize() const { return Size; }
299 const std::vector<DIE *> &getChildren() const { return Children; }
300 const std::vector<DIEValue *> &getValues() const { return Values; }
301 void setTag(unsigned Tag) { Abbrev.setTag(Tag); }
302 void setOffset(unsigned O) { Offset = O; }
303 void setSize(unsigned S) { Size = S; }
305 /// AddValue - Add a value and attributes to a DIE.
307 void AddValue(unsigned Attribute, unsigned Form, DIEValue *Value) {
308 Abbrev.AddAttribute(Attribute, Form);
309 Values.push_back(Value);
312 /// SiblingOffset - Return the offset of the debug information entry's
314 unsigned SiblingOffset() const { return Offset + Size; }
316 /// AddSiblingOffset - Add a sibling offset field to the front of the DIE.
318 void AddSiblingOffset();
320 /// AddChild - Add a child to the DIE.
322 void AddChild(DIE *Child) {
323 Abbrev.setChildrenFlag(DW_CHILDREN_yes);
324 Children.push_back(Child);
327 /// Detach - Detaches objects connected to it after copying.
333 /// Profile - Used to gather unique data for the value folding set.
335 void Profile(FoldingSetNodeID &ID) ;
338 void print(OStream &O, unsigned IncIndent = 0) {
339 if (O.stream()) print(*O.stream(), IncIndent);
341 void print(std::ostream &O, unsigned IncIndent = 0);
346 //===----------------------------------------------------------------------===//
347 /// DIEValue - A debug information entry value.
349 class DIEValue : public FoldingSetNode {
361 /// Type - Type of data stored in the value.
368 virtual ~DIEValue() {}
371 unsigned getType() const { return Type; }
373 // Implement isa/cast/dyncast.
374 static bool classof(const DIEValue *) { return true; }
376 /// EmitValue - Emit value via the Dwarf writer.
378 virtual void EmitValue(const Dwarf &DW, unsigned Form) const = 0;
380 /// SizeOf - Return the size of a value in bytes.
382 virtual unsigned SizeOf(const Dwarf &DW, unsigned Form) const = 0;
384 /// Profile - Used to gather unique data for the value folding set.
386 virtual void Profile(FoldingSetNodeID &ID) = 0;
389 void print(OStream &O) {
390 if (O.stream()) print(*O.stream());
392 virtual void print(std::ostream &O) = 0;
397 //===----------------------------------------------------------------------===//
398 /// DWInteger - An integer value DIE.
400 class DIEInteger : public DIEValue {
405 DIEInteger(uint64_t I) : DIEValue(isInteger), Integer(I) {}
407 // Implement isa/cast/dyncast.
408 static bool classof(const DIEInteger *) { return true; }
409 static bool classof(const DIEValue *I) { return I->Type == isInteger; }
411 /// BestForm - Choose the best form for integer.
413 static unsigned BestForm(bool IsSigned, uint64_t Integer) {
415 if ((char)Integer == (signed)Integer) return DW_FORM_data1;
416 if ((short)Integer == (signed)Integer) return DW_FORM_data2;
417 if ((int)Integer == (signed)Integer) return DW_FORM_data4;
419 if ((unsigned char)Integer == Integer) return DW_FORM_data1;
420 if ((unsigned short)Integer == Integer) return DW_FORM_data2;
421 if ((unsigned int)Integer == Integer) return DW_FORM_data4;
423 return DW_FORM_data8;
426 /// EmitValue - Emit integer of appropriate size.
428 virtual void EmitValue(const Dwarf &DW, unsigned Form) const;
430 /// SizeOf - Determine size of integer value in bytes.
432 virtual unsigned SizeOf(const Dwarf &DW, unsigned Form) const {
434 case DW_FORM_flag: // Fall thru
435 case DW_FORM_ref1: // Fall thru
436 case DW_FORM_data1: return sizeof(int8_t);
437 case DW_FORM_ref2: // Fall thru
438 case DW_FORM_data2: return sizeof(int16_t);
439 case DW_FORM_ref4: // Fall thru
440 case DW_FORM_data4: return sizeof(int32_t);
441 case DW_FORM_ref8: // Fall thru
442 case DW_FORM_data8: return sizeof(int64_t);
443 case DW_FORM_udata: return SizeULEB128(Integer);
444 case DW_FORM_sdata: return SizeSLEB128(Integer);
445 default: assert(0 && "DIE Value form not supported yet"); break;
450 /// Profile - Used to gather unique data for the value folding set.
452 static void Profile(FoldingSetNodeID &ID, unsigned Integer) {
453 ID.AddInteger(isInteger);
454 ID.AddInteger(Integer);
456 virtual void Profile(FoldingSetNodeID &ID) { Profile(ID, Integer); }
459 virtual void print(std::ostream &O) {
460 O << "Int: " << (int64_t)Integer
461 << " 0x" << std::hex << Integer << std::dec;
466 //===----------------------------------------------------------------------===//
467 /// DIEString - A string value DIE.
469 class DIEString : public DIEValue {
471 const std::string String;
473 DIEString(const std::string &S) : DIEValue(isString), String(S) {}
475 // Implement isa/cast/dyncast.
476 static bool classof(const DIEString *) { return true; }
477 static bool classof(const DIEValue *S) { return S->Type == isString; }
479 /// EmitValue - Emit string value.
481 virtual void EmitValue(const Dwarf &DW, unsigned Form) const;
483 /// SizeOf - Determine size of string value in bytes.
485 virtual unsigned SizeOf(const Dwarf &DW, unsigned Form) const {
486 return String.size() + sizeof(char); // sizeof('\0');
489 /// Profile - Used to gather unique data for the value folding set.
491 static void Profile(FoldingSetNodeID &ID, const std::string &String) {
492 ID.AddInteger(isString);
493 ID.AddString(String);
495 virtual void Profile(FoldingSetNodeID &ID) { Profile(ID, String); }
498 virtual void print(std::ostream &O) {
499 O << "Str: \"" << String << "\"";
504 //===----------------------------------------------------------------------===//
505 /// DIEDwarfLabel - A Dwarf internal label expression DIE.
507 class DIEDwarfLabel : public DIEValue {
512 DIEDwarfLabel(const DWLabel &L) : DIEValue(isLabel), Label(L) {}
514 // Implement isa/cast/dyncast.
515 static bool classof(const DIEDwarfLabel *) { return true; }
516 static bool classof(const DIEValue *L) { return L->Type == isLabel; }
518 /// EmitValue - Emit label value.
520 virtual void EmitValue(const Dwarf &DW, unsigned Form) const;
522 /// SizeOf - Determine size of label value in bytes.
524 virtual unsigned SizeOf(const Dwarf &DW, unsigned Form) const;
526 /// Profile - Used to gather unique data for the value folding set.
528 static void Profile(FoldingSetNodeID &ID, const DWLabel &Label) {
529 ID.AddInteger(isLabel);
532 virtual void Profile(FoldingSetNodeID &ID) { Profile(ID, Label); }
535 virtual void print(std::ostream &O) {
543 //===----------------------------------------------------------------------===//
544 /// DIEObjectLabel - A label to an object in code or data.
546 class DIEObjectLabel : public DIEValue {
548 const std::string Label;
550 DIEObjectLabel(const std::string &L) : DIEValue(isAsIsLabel), Label(L) {}
552 // Implement isa/cast/dyncast.
553 static bool classof(const DIEObjectLabel *) { return true; }
554 static bool classof(const DIEValue *L) { return L->Type == isAsIsLabel; }
556 /// EmitValue - Emit label value.
558 virtual void EmitValue(const Dwarf &DW, unsigned Form) const;
560 /// SizeOf - Determine size of label value in bytes.
562 virtual unsigned SizeOf(const Dwarf &DW, unsigned Form) const;
564 /// Profile - Used to gather unique data for the value folding set.
566 static void Profile(FoldingSetNodeID &ID, const std::string &Label) {
567 ID.AddInteger(isAsIsLabel);
570 virtual void Profile(FoldingSetNodeID &ID) { Profile(ID, Label); }
573 virtual void print(std::ostream &O) {
574 O << "Obj: " << Label;
579 //===----------------------------------------------------------------------===//
580 /// DIEDelta - A simple label difference DIE.
582 class DIEDelta : public DIEValue {
584 const DWLabel LabelHi;
585 const DWLabel LabelLo;
587 DIEDelta(const DWLabel &Hi, const DWLabel &Lo)
588 : DIEValue(isDelta), LabelHi(Hi), LabelLo(Lo) {}
590 // Implement isa/cast/dyncast.
591 static bool classof(const DIEDelta *) { return true; }
592 static bool classof(const DIEValue *D) { return D->Type == isDelta; }
594 /// EmitValue - Emit delta value.
596 virtual void EmitValue(const Dwarf &DW, unsigned Form) const;
598 /// SizeOf - Determine size of delta value in bytes.
600 virtual unsigned SizeOf(const Dwarf &DW, unsigned Form) const;
602 /// Profile - Used to gather unique data for the value folding set.
604 static void Profile(FoldingSetNodeID &ID, const DWLabel &LabelHi,
605 const DWLabel &LabelLo) {
606 ID.AddInteger(isDelta);
610 virtual void Profile(FoldingSetNodeID &ID) { Profile(ID, LabelHi, LabelLo); }
613 virtual void print(std::ostream &O) {
622 //===----------------------------------------------------------------------===//
623 /// DIEntry - A pointer to another debug information entry. An instance of this
624 /// class can also be used as a proxy for a debug information entry not yet
625 /// defined (ie. types.)
626 class DIEntry : public DIEValue {
630 DIEntry(DIE *E) : DIEValue(isEntry), Entry(E) {}
632 // Implement isa/cast/dyncast.
633 static bool classof(const DIEntry *) { return true; }
634 static bool classof(const DIEValue *E) { return E->Type == isEntry; }
636 /// EmitValue - Emit debug information entry offset.
638 virtual void EmitValue(const Dwarf &DW, unsigned Form) const;
640 /// SizeOf - Determine size of debug information entry in bytes.
642 virtual unsigned SizeOf(const Dwarf &DW, unsigned Form) const {
643 return sizeof(int32_t);
646 /// Profile - Used to gather unique data for the value folding set.
648 static void Profile(FoldingSetNodeID &ID, DIE *Entry) {
649 ID.AddInteger(isEntry);
650 ID.AddPointer(Entry);
652 virtual void Profile(FoldingSetNodeID &ID) {
653 ID.AddInteger(isEntry);
656 ID.AddPointer(Entry);
663 virtual void print(std::ostream &O) {
664 O << "Die: 0x" << std::hex << (intptr_t)Entry << std::dec;
669 //===----------------------------------------------------------------------===//
670 /// DIEBlock - A block of values. Primarily used for location expressions.
672 class DIEBlock : public DIEValue, public DIE {
674 unsigned Size; // Size in bytes excluding size header.
684 // Implement isa/cast/dyncast.
685 static bool classof(const DIEBlock *) { return true; }
686 static bool classof(const DIEValue *E) { return E->Type == isBlock; }
688 /// ComputeSize - calculate the size of the block.
690 unsigned ComputeSize(Dwarf &DW);
692 /// BestForm - Choose the best form for data.
694 unsigned BestForm() const {
695 if ((unsigned char)Size == Size) return DW_FORM_block1;
696 if ((unsigned short)Size == Size) return DW_FORM_block2;
697 if ((unsigned int)Size == Size) return DW_FORM_block4;
698 return DW_FORM_block;
701 /// EmitValue - Emit block data.
703 virtual void EmitValue(const Dwarf &DW, unsigned Form) const;
705 /// SizeOf - Determine size of block data in bytes.
707 virtual unsigned SizeOf(const Dwarf &DW, unsigned Form) const;
710 /// Profile - Used to gather unique data for the value folding set.
712 virtual void Profile(FoldingSetNodeID &ID) {
713 ID.AddInteger(isBlock);
718 virtual void print(std::ostream &O) {
725 //===----------------------------------------------------------------------===//
726 /// CompileUnit - This dwarf writer support class manages information associate
727 /// with a source file.
730 /// Desc - Compile unit debug descriptor.
732 CompileUnitDesc *Desc;
734 /// ID - File identifier for source.
738 /// Die - Compile unit debug information entry.
742 /// DescToDieMap - Tracks the mapping of unit level debug informaton
743 /// descriptors to debug information entries.
744 std::map<DebugInfoDesc *, DIE *> DescToDieMap;
746 /// DescToDIEntryMap - Tracks the mapping of unit level debug informaton
747 /// descriptors to debug information entries using a DIEntry proxy.
748 std::map<DebugInfoDesc *, DIEntry *> DescToDIEntryMap;
750 /// Globals - A map of globally visible named entities for this unit.
752 std::map<std::string, DIE *> Globals;
754 /// DiesSet - Used to uniquely define dies within the compile unit.
756 FoldingSet<DIE> DiesSet;
758 /// Dies - List of all dies in the compile unit.
760 std::vector<DIE *> Dies;
763 CompileUnit(CompileUnitDesc *CUD, unsigned I, DIE *D)
770 , DiesSet(InitDiesSetSize)
777 for (unsigned i = 0, N = Dies.size(); i < N; ++i)
782 CompileUnitDesc *getDesc() const { return Desc; }
783 unsigned getID() const { return ID; }
784 DIE* getDie() const { return Die; }
785 std::map<std::string, DIE *> &getGlobals() { return Globals; }
787 /// hasContent - Return true if this compile unit has something to write out.
789 bool hasContent() const {
790 return !Die->getChildren().empty();
793 /// AddGlobal - Add a new global entity to the compile unit.
795 void AddGlobal(const std::string &Name, DIE *Die) {
799 /// getDieMapSlotFor - Returns the debug information entry map slot for the
800 /// specified debug descriptor.
801 DIE *&getDieMapSlotFor(DebugInfoDesc *DD) {
802 return DescToDieMap[DD];
805 /// getDIEntrySlotFor - Returns the debug information entry proxy slot for the
806 /// specified debug descriptor.
807 DIEntry *&getDIEntrySlotFor(DebugInfoDesc *DD) {
808 return DescToDIEntryMap[DD];
811 /// AddDie - Adds or interns the DIE to the compile unit.
813 DIE *AddDie(DIE &Buffer) {
817 DIE *Die = DiesSet.FindNodeOrInsertPos(ID, Where);
820 Die = new DIE(Buffer);
821 DiesSet.InsertNode(Die, Where);
822 this->Die->AddChild(Die);
830 //===----------------------------------------------------------------------===//
831 /// Dwarf - Emits Dwarf debug and exception handling directives.
837 //===--------------------------------------------------------------------===//
838 // Core attributes used by the Dwarf writer.
842 /// O - Stream to .s file.
846 /// Asm - Target of Dwarf emission.
850 /// TAI - Target Asm Printer.
851 const TargetAsmInfo *TAI;
853 /// TD - Target data.
854 const TargetData *TD;
856 /// RI - Register Information.
857 const MRegisterInfo *RI;
859 /// M - Current module.
863 /// MF - Current machine function.
867 /// DebugInfo - Collected debug information.
869 MachineDebugInfo *DebugInfo;
871 /// didInitial - Flag to indicate if initial emission has been done.
875 /// shouldEmit - Flag to indicate if debug information should be emitted.
879 /// SubprogramCount - The running count of functions being compiled.
881 unsigned SubprogramCount;
883 //===--------------------------------------------------------------------===//
884 // Attributes used to construct specific Dwarf sections.
887 /// CompileUnits - All the compile units involved in this build. The index
888 /// of each entry in this vector corresponds to the sources in DebugInfo.
889 std::vector<CompileUnit *> CompileUnits;
891 /// AbbreviationsSet - Used to uniquely define abbreviations.
893 FoldingSet<DIEAbbrev> AbbreviationsSet;
895 /// Abbreviations - A list of all the unique abbreviations in use.
897 std::vector<DIEAbbrev *> Abbreviations;
899 /// ValuesSet - Used to uniquely define values.
901 FoldingSet<DIEValue> ValuesSet;
903 /// Values - A list of all the unique values in use.
905 std::vector<DIEValue *> Values;
907 /// StringPool - A UniqueVector of strings used by indirect references.
909 UniqueVector<std::string> StringPool;
911 /// UnitMap - Map debug information descriptor to compile unit.
913 std::map<DebugInfoDesc *, CompileUnit *> DescToUnitMap;
915 /// SectionMap - Provides a unique id per text section.
917 UniqueVector<std::string> SectionMap;
919 /// SectionSourceLines - Tracks line numbers per text section.
921 std::vector<std::vector<SourceLineInfo> > SectionSourceLines;
926 //===--------------------------------------------------------------------===//
927 // Emission and print routines
930 /// PrintHex - Print a value as a hexidecimal value.
932 void PrintHex(int Value) const {
933 O << "0x" << std::hex << Value << std::dec;
936 /// EOL - Print a newline character to asm stream. If a comment is present
937 /// then it will be printed first. Comments should not contain '\n'.
938 void EOL(const std::string &Comment) const {
939 if (DwarfVerbose && !Comment.empty()) {
941 << TAI->getCommentString()
948 /// EmitAlign - Print a align directive.
950 void EmitAlign(unsigned Alignment) const {
951 O << TAI->getAlignDirective() << Alignment << "\n";
954 /// EmitULEB128Bytes - Emit an assembler byte data directive to compose an
955 /// unsigned leb128 value.
956 void EmitULEB128Bytes(unsigned Value) const {
957 if (TAI->hasLEB128()) {
961 O << TAI->getData8bitsDirective();
962 PrintULEB128(O, Value);
966 /// EmitSLEB128Bytes - print an assembler byte data directive to compose a
967 /// signed leb128 value.
968 void EmitSLEB128Bytes(int Value) const {
969 if (TAI->hasLEB128()) {
973 O << TAI->getData8bitsDirective();
974 PrintSLEB128(O, Value);
978 /// EmitInt8 - Emit a byte directive and value.
980 void EmitInt8(int Value) const {
981 O << TAI->getData8bitsDirective();
982 PrintHex(Value & 0xFF);
985 /// EmitInt16 - Emit a short directive and value.
987 void EmitInt16(int Value) const {
988 O << TAI->getData16bitsDirective();
989 PrintHex(Value & 0xFFFF);
992 /// EmitInt32 - Emit a long directive and value.
994 void EmitInt32(int Value) const {
995 O << TAI->getData32bitsDirective();
999 /// EmitInt64 - Emit a long long directive and value.
1001 void EmitInt64(uint64_t Value) const {
1002 if (TAI->getData64bitsDirective()) {
1003 O << TAI->getData64bitsDirective();
1006 if (TD->isBigEndian()) {
1007 EmitInt32(unsigned(Value >> 32)); O << "\n";
1008 EmitInt32(unsigned(Value));
1010 EmitInt32(unsigned(Value)); O << "\n";
1011 EmitInt32(unsigned(Value >> 32));
1016 /// EmitString - Emit a string with quotes and a null terminator.
1017 /// Special characters are emitted properly.
1018 /// \literal (Eg. '\t') \endliteral
1019 void EmitString(const std::string &String) const {
1020 O << TAI->getAsciiDirective()
1022 for (unsigned i = 0, N = String.size(); i < N; ++i) {
1023 unsigned char C = String[i];
1025 if (!isascii(C) || iscntrl(C)) {
1027 case '\b': O << "\\b"; break;
1028 case '\f': O << "\\f"; break;
1029 case '\n': O << "\\n"; break;
1030 case '\r': O << "\\r"; break;
1031 case '\t': O << "\\t"; break;
1034 O << char('0' + ((C >> 6) & 7));
1035 O << char('0' + ((C >> 3) & 7));
1036 O << char('0' + ((C >> 0) & 7));
1039 } else if (C == '\"') {
1041 } else if (C == '\'') {
1050 /// PrintLabelName - Print label name in form used by Dwarf writer.
1052 void PrintLabelName(DWLabel Label) const {
1053 PrintLabelName(Label.Tag, Label.Number);
1055 void PrintLabelName(const char *Tag, unsigned Number) const {
1056 O << TAI->getPrivateGlobalPrefix()
1059 if (Number) O << Number;
1062 /// EmitLabel - Emit location label for internal use by Dwarf.
1064 void EmitLabel(DWLabel Label) const {
1065 EmitLabel(Label.Tag, Label.Number);
1067 void EmitLabel(const char *Tag, unsigned Number) const {
1068 PrintLabelName(Tag, Number);
1072 /// EmitReference - Emit a reference to a label.
1074 void EmitReference(DWLabel Label) const {
1075 EmitReference(Label.Tag, Label.Number);
1077 void EmitReference(const char *Tag, unsigned Number) const {
1078 if (TAI->getAddressSize() == 4)
1079 O << TAI->getData32bitsDirective();
1081 O << TAI->getData64bitsDirective();
1083 PrintLabelName(Tag, Number);
1085 void EmitReference(const std::string &Name) const {
1086 if (TAI->getAddressSize() == 4)
1087 O << TAI->getData32bitsDirective();
1089 O << TAI->getData64bitsDirective();
1094 /// EmitDifference - Emit the difference between two labels. Some
1095 /// assemblers do not behave with absolute expressions with data directives,
1096 /// so there is an option (needsSet) to use an intermediary set expression.
1097 void EmitDifference(DWLabel LabelHi, DWLabel LabelLo,
1098 bool IsSmall = false) const {
1099 EmitDifference(LabelHi.Tag, LabelHi.Number,
1100 LabelLo.Tag, LabelLo.Number,
1103 void EmitDifference(const char *TagHi, unsigned NumberHi,
1104 const char *TagLo, unsigned NumberLo,
1105 bool IsSmall = false) const {
1106 if (TAI->needsSet()) {
1107 static unsigned SetCounter = 0;
1110 PrintLabelName("set", SetCounter);
1112 PrintLabelName(TagHi, NumberHi);
1114 PrintLabelName(TagLo, NumberLo);
1117 if (IsSmall || TAI->getAddressSize() == sizeof(int32_t))
1118 O << TAI->getData32bitsDirective();
1120 O << TAI->getData64bitsDirective();
1122 PrintLabelName("set", SetCounter);
1126 if (IsSmall || TAI->getAddressSize() == sizeof(int32_t))
1127 O << TAI->getData32bitsDirective();
1129 O << TAI->getData64bitsDirective();
1131 PrintLabelName(TagHi, NumberHi);
1133 PrintLabelName(TagLo, NumberLo);
1137 /// AssignAbbrevNumber - Define a unique number for the abbreviation.
1139 void AssignAbbrevNumber(DIEAbbrev &Abbrev) {
1140 // Profile the node so that we can make it unique.
1141 FoldingSetNodeID ID;
1144 // Check the set for priors.
1145 DIEAbbrev *InSet = AbbreviationsSet.GetOrInsertNode(&Abbrev);
1147 // If it's newly added.
1148 if (InSet == &Abbrev) {
1149 // Add to abbreviation list.
1150 Abbreviations.push_back(&Abbrev);
1151 // Assign the vector position + 1 as its number.
1152 Abbrev.setNumber(Abbreviations.size());
1154 // Assign existing abbreviation number.
1155 Abbrev.setNumber(InSet->getNumber());
1159 /// NewString - Add a string to the constant pool and returns a label.
1161 DWLabel NewString(const std::string &String) {
1162 unsigned StringID = StringPool.insert(String);
1163 return DWLabel("string", StringID);
1166 /// NewDIEntry - Creates a new DIEntry to be a proxy for a debug information
1168 DIEntry *NewDIEntry(DIE *Entry = NULL) {
1172 FoldingSetNodeID ID;
1173 DIEntry::Profile(ID, Entry);
1175 Value = static_cast<DIEntry *>(ValuesSet.FindNodeOrInsertPos(ID, Where));
1177 if (Value) return Value;
1179 Value = new DIEntry(Entry);
1180 ValuesSet.InsertNode(Value, Where);
1182 Value = new DIEntry(Entry);
1185 Values.push_back(Value);
1189 /// SetDIEntry - Set a DIEntry once the debug information entry is defined.
1191 void SetDIEntry(DIEntry *Value, DIE *Entry) {
1192 Value->Entry = Entry;
1193 // Add to values set if not already there. If it is, we merely have a
1194 // duplicate in the values list (no harm.)
1195 ValuesSet.GetOrInsertNode(Value);
1198 /// AddUInt - Add an unsigned integer attribute data and value.
1200 void AddUInt(DIE *Die, unsigned Attribute, unsigned Form, uint64_t Integer) {
1201 if (!Form) Form = DIEInteger::BestForm(false, Integer);
1203 FoldingSetNodeID ID;
1204 DIEInteger::Profile(ID, Integer);
1206 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
1208 Value = new DIEInteger(Integer);
1209 ValuesSet.InsertNode(Value, Where);
1210 Values.push_back(Value);
1213 Die->AddValue(Attribute, Form, Value);
1216 /// AddSInt - Add an signed integer attribute data and value.
1218 void AddSInt(DIE *Die, unsigned Attribute, unsigned Form, int64_t Integer) {
1219 if (!Form) Form = DIEInteger::BestForm(true, Integer);
1221 FoldingSetNodeID ID;
1222 DIEInteger::Profile(ID, (uint64_t)Integer);
1224 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
1226 Value = new DIEInteger(Integer);
1227 ValuesSet.InsertNode(Value, Where);
1228 Values.push_back(Value);
1231 Die->AddValue(Attribute, Form, Value);
1234 /// AddString - Add a std::string attribute data and value.
1236 void AddString(DIE *Die, unsigned Attribute, unsigned Form,
1237 const std::string &String) {
1238 FoldingSetNodeID ID;
1239 DIEString::Profile(ID, String);
1241 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
1243 Value = new DIEString(String);
1244 ValuesSet.InsertNode(Value, Where);
1245 Values.push_back(Value);
1248 Die->AddValue(Attribute, Form, Value);
1251 /// AddLabel - Add a Dwarf label attribute data and value.
1253 void AddLabel(DIE *Die, unsigned Attribute, unsigned Form,
1254 const DWLabel &Label) {
1255 FoldingSetNodeID ID;
1256 DIEDwarfLabel::Profile(ID, Label);
1258 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
1260 Value = new DIEDwarfLabel(Label);
1261 ValuesSet.InsertNode(Value, Where);
1262 Values.push_back(Value);
1265 Die->AddValue(Attribute, Form, Value);
1268 /// AddObjectLabel - Add an non-Dwarf label attribute data and value.
1270 void AddObjectLabel(DIE *Die, unsigned Attribute, unsigned Form,
1271 const std::string &Label) {
1272 FoldingSetNodeID ID;
1273 DIEObjectLabel::Profile(ID, Label);
1275 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
1277 Value = new DIEObjectLabel(Label);
1278 ValuesSet.InsertNode(Value, Where);
1279 Values.push_back(Value);
1282 Die->AddValue(Attribute, Form, Value);
1285 /// AddDelta - Add a label delta attribute data and value.
1287 void AddDelta(DIE *Die, unsigned Attribute, unsigned Form,
1288 const DWLabel &Hi, const DWLabel &Lo) {
1289 FoldingSetNodeID ID;
1290 DIEDelta::Profile(ID, Hi, Lo);
1292 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
1294 Value = new DIEDelta(Hi, Lo);
1295 ValuesSet.InsertNode(Value, Where);
1296 Values.push_back(Value);
1299 Die->AddValue(Attribute, Form, Value);
1302 /// AddDIEntry - Add a DIE attribute data and value.
1304 void AddDIEntry(DIE *Die, unsigned Attribute, unsigned Form, DIE *Entry) {
1305 Die->AddValue(Attribute, Form, NewDIEntry(Entry));
1308 /// AddBlock - Add block data.
1310 void AddBlock(DIE *Die, unsigned Attribute, unsigned Form, DIEBlock *Block) {
1311 Block->ComputeSize(*this);
1312 FoldingSetNodeID ID;
1315 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
1318 ValuesSet.InsertNode(Value, Where);
1319 Values.push_back(Value);
1324 Die->AddValue(Attribute, Block->BestForm(), Value);
1329 /// AddSourceLine - Add location information to specified debug information
1331 void AddSourceLine(DIE *Die, CompileUnitDesc *File, unsigned Line) {
1333 CompileUnit *FileUnit = FindCompileUnit(File);
1334 unsigned FileID = FileUnit->getID();
1335 AddUInt(Die, DW_AT_decl_file, 0, FileID);
1336 AddUInt(Die, DW_AT_decl_line, 0, Line);
1340 /// AddAddress - Add an address attribute to a die based on the location
1342 void AddAddress(DIE *Die, unsigned Attribute,
1343 const MachineLocation &Location) {
1344 unsigned Reg = RI->getDwarfRegNum(Location.getRegister());
1345 DIEBlock *Block = new DIEBlock();
1347 if (Location.isRegister()) {
1349 AddUInt(Block, 0, DW_FORM_data1, DW_OP_reg0 + Reg);
1351 AddUInt(Block, 0, DW_FORM_data1, DW_OP_regx);
1352 AddUInt(Block, 0, DW_FORM_udata, Reg);
1356 AddUInt(Block, 0, DW_FORM_data1, DW_OP_breg0 + Reg);
1358 AddUInt(Block, 0, DW_FORM_data1, DW_OP_bregx);
1359 AddUInt(Block, 0, DW_FORM_udata, Reg);
1361 AddUInt(Block, 0, DW_FORM_sdata, Location.getOffset());
1364 AddBlock(Die, Attribute, 0, Block);
1367 /// AddBasicType - Add a new basic type attribute to the specified entity.
1369 void AddBasicType(DIE *Entity, CompileUnit *Unit,
1370 const std::string &Name,
1371 unsigned Encoding, unsigned Size) {
1372 DIE *Die = ConstructBasicType(Unit, Name, Encoding, Size);
1373 AddDIEntry(Entity, DW_AT_type, DW_FORM_ref4, Die);
1376 /// ConstructBasicType - Construct a new basic type.
1378 DIE *ConstructBasicType(CompileUnit *Unit,
1379 const std::string &Name,
1380 unsigned Encoding, unsigned Size) {
1381 DIE Buffer(DW_TAG_base_type);
1382 AddUInt(&Buffer, DW_AT_byte_size, 0, Size);
1383 AddUInt(&Buffer, DW_AT_encoding, DW_FORM_data1, Encoding);
1384 if (!Name.empty()) AddString(&Buffer, DW_AT_name, DW_FORM_string, Name);
1385 return Unit->AddDie(Buffer);
1388 /// AddPointerType - Add a new pointer type attribute to the specified entity.
1390 void AddPointerType(DIE *Entity, CompileUnit *Unit, const std::string &Name) {
1391 DIE *Die = ConstructPointerType(Unit, Name);
1392 AddDIEntry(Entity, DW_AT_type, DW_FORM_ref4, Die);
1395 /// ConstructPointerType - Construct a new pointer type.
1397 DIE *ConstructPointerType(CompileUnit *Unit, const std::string &Name) {
1398 DIE Buffer(DW_TAG_pointer_type);
1399 AddUInt(&Buffer, DW_AT_byte_size, 0, TAI->getAddressSize());
1400 if (!Name.empty()) AddString(&Buffer, DW_AT_name, DW_FORM_string, Name);
1401 return Unit->AddDie(Buffer);
1404 /// AddType - Add a new type attribute to the specified entity.
1406 void AddType(DIE *Entity, TypeDesc *TyDesc, CompileUnit *Unit) {
1408 AddBasicType(Entity, Unit, "", DW_ATE_signed, 4);
1410 // Check for pre-existence.
1411 DIEntry *&Slot = Unit->getDIEntrySlotFor(TyDesc);
1413 // If it exists then use the existing value.
1415 Entity->AddValue(DW_AT_type, DW_FORM_ref4, Slot);
1419 if (SubprogramDesc *SubprogramTy = dyn_cast<SubprogramDesc>(TyDesc)) {
1420 // FIXME - Not sure why programs and variables are coming through here.
1421 // Short cut for handling subprogram types (not really a TyDesc.)
1422 AddPointerType(Entity, Unit, SubprogramTy->getName());
1423 } else if (GlobalVariableDesc *GlobalTy =
1424 dyn_cast<GlobalVariableDesc>(TyDesc)) {
1425 // FIXME - Not sure why programs and variables are coming through here.
1426 // Short cut for handling global variable types (not really a TyDesc.)
1427 AddPointerType(Entity, Unit, GlobalTy->getName());
1430 Slot = NewDIEntry();
1433 DIE Buffer(DW_TAG_base_type);
1434 ConstructType(Buffer, TyDesc, Unit);
1436 // Add debug information entry to entity and unit.
1437 DIE *Die = Unit->AddDie(Buffer);
1438 SetDIEntry(Slot, Die);
1439 Entity->AddValue(DW_AT_type, DW_FORM_ref4, Slot);
1444 /// ConstructType - Adds all the required attributes to the type.
1446 void ConstructType(DIE &Buffer, TypeDesc *TyDesc, CompileUnit *Unit) {
1447 // Get core information.
1448 const std::string &Name = TyDesc->getName();
1449 uint64_t Size = TyDesc->getSize() >> 3;
1451 if (BasicTypeDesc *BasicTy = dyn_cast<BasicTypeDesc>(TyDesc)) {
1452 // Fundamental types like int, float, bool
1453 Buffer.setTag(DW_TAG_base_type);
1454 AddUInt(&Buffer, DW_AT_encoding, DW_FORM_data1, BasicTy->getEncoding());
1455 } else if (DerivedTypeDesc *DerivedTy = dyn_cast<DerivedTypeDesc>(TyDesc)) {
1457 unsigned Tag = DerivedTy->getTag();
1458 // FIXME - Workaround for templates.
1459 if (Tag == DW_TAG_inheritance) Tag = DW_TAG_reference_type;
1460 // Pointers, typedefs et al.
1462 // Map to main type, void will not have a type.
1463 if (TypeDesc *FromTy = DerivedTy->getFromType())
1464 AddType(&Buffer, FromTy, Unit);
1465 } else if (CompositeTypeDesc *CompTy = dyn_cast<CompositeTypeDesc>(TyDesc)){
1467 unsigned Tag = CompTy->getTag();
1469 // Set tag accordingly.
1470 if (Tag == DW_TAG_vector_type)
1471 Buffer.setTag(DW_TAG_array_type);
1475 std::vector<DebugInfoDesc *> &Elements = CompTy->getElements();
1478 case DW_TAG_vector_type:
1479 AddUInt(&Buffer, DW_AT_GNU_vector, DW_FORM_flag, 1);
1481 case DW_TAG_array_type: {
1482 // Add element type.
1483 if (TypeDesc *FromTy = CompTy->getFromType())
1484 AddType(&Buffer, FromTy, Unit);
1486 // Don't emit size attribute.
1489 // Construct an anonymous type for index type.
1490 DIE *IndexTy = ConstructBasicType(Unit, "", DW_ATE_signed, 4);
1492 // Add subranges to array type.
1493 for(unsigned i = 0, N = Elements.size(); i < N; ++i) {
1494 SubrangeDesc *SRD = cast<SubrangeDesc>(Elements[i]);
1495 int64_t Lo = SRD->getLo();
1496 int64_t Hi = SRD->getHi();
1497 DIE *Subrange = new DIE(DW_TAG_subrange_type);
1499 // If a range is available.
1501 AddDIEntry(Subrange, DW_AT_type, DW_FORM_ref4, IndexTy);
1502 // Only add low if non-zero.
1503 if (Lo) AddSInt(Subrange, DW_AT_lower_bound, 0, Lo);
1504 AddSInt(Subrange, DW_AT_upper_bound, 0, Hi);
1507 Buffer.AddChild(Subrange);
1511 case DW_TAG_structure_type:
1512 case DW_TAG_union_type: {
1513 // Add elements to structure type.
1514 for(unsigned i = 0, N = Elements.size(); i < N; ++i) {
1515 DebugInfoDesc *Element = Elements[i];
1517 if (DerivedTypeDesc *MemberDesc = dyn_cast<DerivedTypeDesc>(Element)){
1518 // Add field or base class.
1520 unsigned Tag = MemberDesc->getTag();
1522 // Extract the basic information.
1523 const std::string &Name = MemberDesc->getName();
1524 uint64_t Size = MemberDesc->getSize();
1525 uint64_t Align = MemberDesc->getAlign();
1526 uint64_t Offset = MemberDesc->getOffset();
1528 // Construct member debug information entry.
1529 DIE *Member = new DIE(Tag);
1531 // Add name if not "".
1533 AddString(Member, DW_AT_name, DW_FORM_string, Name);
1534 // Add location if available.
1535 AddSourceLine(Member, MemberDesc->getFile(), MemberDesc->getLine());
1537 // Most of the time the field info is the same as the members.
1538 uint64_t FieldSize = Size;
1539 uint64_t FieldAlign = Align;
1540 uint64_t FieldOffset = Offset;
1542 if (TypeDesc *FromTy = MemberDesc->getFromType()) {
1543 AddType(Member, FromTy, Unit);
1544 FieldSize = FromTy->getSize();
1545 FieldAlign = FromTy->getSize();
1548 // Unless we have a bit field.
1549 if (Tag == DW_TAG_member && FieldSize != Size) {
1550 // Construct the alignment mask.
1551 uint64_t AlignMask = ~(FieldAlign - 1);
1552 // Determine the high bit + 1 of the declared size.
1553 uint64_t HiMark = (Offset + FieldSize) & AlignMask;
1554 // Work backwards to determine the base offset of the field.
1555 FieldOffset = HiMark - FieldSize;
1556 // Now normalize offset to the field.
1557 Offset -= FieldOffset;
1559 // Maybe we need to work from the other end.
1560 if (TD->isLittleEndian()) Offset = FieldSize - (Offset + Size);
1562 // Add size and offset.
1563 AddUInt(Member, DW_AT_byte_size, 0, FieldSize >> 3);
1564 AddUInt(Member, DW_AT_bit_size, 0, Size);
1565 AddUInt(Member, DW_AT_bit_offset, 0, Offset);
1568 // Add computation for offset.
1569 DIEBlock *Block = new DIEBlock();
1570 AddUInt(Block, 0, DW_FORM_data1, DW_OP_plus_uconst);
1571 AddUInt(Block, 0, DW_FORM_udata, FieldOffset >> 3);
1572 AddBlock(Member, DW_AT_data_member_location, 0, Block);
1574 // Add accessibility (public default unless is base class.
1575 if (MemberDesc->isProtected()) {
1576 AddUInt(Member, DW_AT_accessibility, 0, DW_ACCESS_protected);
1577 } else if (MemberDesc->isPrivate()) {
1578 AddUInt(Member, DW_AT_accessibility, 0, DW_ACCESS_private);
1579 } else if (Tag == DW_TAG_inheritance) {
1580 AddUInt(Member, DW_AT_accessibility, 0, DW_ACCESS_public);
1583 Buffer.AddChild(Member);
1584 } else if (GlobalVariableDesc *StaticDesc =
1585 dyn_cast<GlobalVariableDesc>(Element)) {
1586 // Add static member.
1588 // Construct member debug information entry.
1589 DIE *Static = new DIE(DW_TAG_variable);
1591 // Add name and mangled name.
1592 const std::string &Name = StaticDesc->getName();
1593 const std::string &LinkageName = StaticDesc->getLinkageName();
1594 AddString(Static, DW_AT_name, DW_FORM_string, Name);
1595 if (!LinkageName.empty()) {
1596 AddString(Static, DW_AT_MIPS_linkage_name, DW_FORM_string,
1601 AddSourceLine(Static, StaticDesc->getFile(), StaticDesc->getLine());
1604 if (TypeDesc *StaticTy = StaticDesc->getType())
1605 AddType(Static, StaticTy, Unit);
1608 AddUInt(Static, DW_AT_external, DW_FORM_flag, 1);
1609 AddUInt(Static, DW_AT_declaration, DW_FORM_flag, 1);
1611 Buffer.AddChild(Static);
1612 } else if (SubprogramDesc *MethodDesc =
1613 dyn_cast<SubprogramDesc>(Element)) {
1614 // Add member function.
1616 // Construct member debug information entry.
1617 DIE *Method = new DIE(DW_TAG_subprogram);
1619 // Add name and mangled name.
1620 const std::string &Name = MethodDesc->getName();
1621 const std::string &LinkageName = MethodDesc->getLinkageName();
1623 AddString(Method, DW_AT_name, DW_FORM_string, Name);
1624 bool IsCTor = TyDesc->getName() == Name;
1626 if (!LinkageName.empty()) {
1627 AddString(Method, DW_AT_MIPS_linkage_name, DW_FORM_string,
1632 AddSourceLine(Method, MethodDesc->getFile(), MethodDesc->getLine());
1635 if (CompositeTypeDesc *MethodTy =
1636 dyn_cast_or_null<CompositeTypeDesc>(MethodDesc->getType())) {
1637 // Get argument information.
1638 std::vector<DebugInfoDesc *> &Args = MethodTy->getElements();
1643 AddType(Method, dyn_cast<TypeDesc>(Args[0]), Unit);
1647 for(unsigned i = 1, N = Args.size(); i < N; ++i) {
1648 DIE *Arg = new DIE(DW_TAG_formal_parameter);
1649 AddType(Arg, cast<TypeDesc>(Args[i]), Unit);
1650 AddUInt(Arg, DW_AT_artificial, DW_FORM_flag, 1);
1651 Method->AddChild(Arg);
1656 AddUInt(Method, DW_AT_external, DW_FORM_flag, 1);
1657 AddUInt(Method, DW_AT_declaration, DW_FORM_flag, 1);
1659 Buffer.AddChild(Method);
1664 case DW_TAG_enumeration_type: {
1665 // Add enumerators to enumeration type.
1666 for(unsigned i = 0, N = Elements.size(); i < N; ++i) {
1667 EnumeratorDesc *ED = cast<EnumeratorDesc>(Elements[i]);
1668 const std::string &Name = ED->getName();
1669 int64_t Value = ED->getValue();
1670 DIE *Enumerator = new DIE(DW_TAG_enumerator);
1671 AddString(Enumerator, DW_AT_name, DW_FORM_string, Name);
1672 AddSInt(Enumerator, DW_AT_const_value, DW_FORM_sdata, Value);
1673 Buffer.AddChild(Enumerator);
1678 case DW_TAG_subroutine_type: {
1679 // Add prototype flag.
1680 AddUInt(&Buffer, DW_AT_prototyped, DW_FORM_flag, 1);
1682 AddType(&Buffer, dyn_cast<TypeDesc>(Elements[0]), Unit);
1685 for(unsigned i = 1, N = Elements.size(); i < N; ++i) {
1686 DIE *Arg = new DIE(DW_TAG_formal_parameter);
1687 AddType(Arg, cast<TypeDesc>(Elements[i]), Unit);
1688 Buffer.AddChild(Arg);
1697 // Add size if non-zero (derived types don't have a size.)
1698 if (Size) AddUInt(&Buffer, DW_AT_byte_size, 0, Size);
1699 // Add name if not anonymous or intermediate type.
1700 if (!Name.empty()) AddString(&Buffer, DW_AT_name, DW_FORM_string, Name);
1701 // Add source line info if available.
1702 AddSourceLine(&Buffer, TyDesc->getFile(), TyDesc->getLine());
1705 /// NewCompileUnit - Create new compile unit and it's debug information entry.
1707 CompileUnit *NewCompileUnit(CompileUnitDesc *UnitDesc, unsigned ID) {
1708 // Construct debug information entry.
1709 DIE *Die = new DIE(DW_TAG_compile_unit);
1710 AddDelta(Die, DW_AT_stmt_list, DW_FORM_data4, DWLabel("section_line", 0),
1711 DWLabel("section_line", 0));
1712 AddString(Die, DW_AT_producer, DW_FORM_string, UnitDesc->getProducer());
1713 AddUInt (Die, DW_AT_language, DW_FORM_data1, UnitDesc->getLanguage());
1714 AddString(Die, DW_AT_name, DW_FORM_string, UnitDesc->getFileName());
1715 AddString(Die, DW_AT_comp_dir, DW_FORM_string, UnitDesc->getDirectory());
1717 // Construct compile unit.
1718 CompileUnit *Unit = new CompileUnit(UnitDesc, ID, Die);
1720 // Add Unit to compile unit map.
1721 DescToUnitMap[UnitDesc] = Unit;
1726 /// GetBaseCompileUnit - Get the main compile unit.
1728 CompileUnit *GetBaseCompileUnit() const {
1729 CompileUnit *Unit = CompileUnits[0];
1730 assert(Unit && "Missing compile unit.");
1734 /// FindCompileUnit - Get the compile unit for the given descriptor.
1736 CompileUnit *FindCompileUnit(CompileUnitDesc *UnitDesc) {
1737 CompileUnit *Unit = DescToUnitMap[UnitDesc];
1738 assert(Unit && "Missing compile unit.");
1742 /// NewGlobalVariable - Add a new global variable DIE.
1744 DIE *NewGlobalVariable(GlobalVariableDesc *GVD) {
1745 // Get the compile unit context.
1746 CompileUnitDesc *UnitDesc =
1747 static_cast<CompileUnitDesc *>(GVD->getContext());
1748 CompileUnit *Unit = GetBaseCompileUnit();
1750 // Check for pre-existence.
1751 DIE *&Slot = Unit->getDieMapSlotFor(GVD);
1752 if (Slot) return Slot;
1754 // Get the global variable itself.
1755 GlobalVariable *GV = GVD->getGlobalVariable();
1757 const std::string &Name = GVD->getName();
1758 const std::string &FullName = GVD->getFullName();
1759 const std::string &LinkageName = GVD->getLinkageName();
1760 // Create the global's variable DIE.
1761 DIE *VariableDie = new DIE(DW_TAG_variable);
1762 AddString(VariableDie, DW_AT_name, DW_FORM_string, Name);
1763 if (!LinkageName.empty()) {
1764 AddString(VariableDie, DW_AT_MIPS_linkage_name, DW_FORM_string,
1767 AddType(VariableDie, GVD->getType(), Unit);
1768 AddUInt(VariableDie, DW_AT_external, DW_FORM_flag, 1);
1770 // Add source line info if available.
1771 AddSourceLine(VariableDie, UnitDesc, GVD->getLine());
1774 DIEBlock *Block = new DIEBlock();
1775 AddUInt(Block, 0, DW_FORM_data1, DW_OP_addr);
1776 AddObjectLabel(Block, 0, DW_FORM_udata, Asm->getGlobalLinkName(GV));
1777 AddBlock(VariableDie, DW_AT_location, 0, Block);
1782 // Add to context owner.
1783 Unit->getDie()->AddChild(VariableDie);
1785 // Expose as global.
1786 // FIXME - need to check external flag.
1787 Unit->AddGlobal(FullName, VariableDie);
1792 /// NewSubprogram - Add a new subprogram DIE.
1794 DIE *NewSubprogram(SubprogramDesc *SPD) {
1795 // Get the compile unit context.
1796 CompileUnitDesc *UnitDesc =
1797 static_cast<CompileUnitDesc *>(SPD->getContext());
1798 CompileUnit *Unit = GetBaseCompileUnit();
1800 // Check for pre-existence.
1801 DIE *&Slot = Unit->getDieMapSlotFor(SPD);
1802 if (Slot) return Slot;
1804 // Gather the details (simplify add attribute code.)
1805 const std::string &Name = SPD->getName();
1806 const std::string &FullName = SPD->getFullName();
1807 const std::string &LinkageName = SPD->getLinkageName();
1808 unsigned IsExternal = SPD->isStatic() ? 0 : 1;
1810 DIE *SubprogramDie = new DIE(DW_TAG_subprogram);
1811 AddString(SubprogramDie, DW_AT_name, DW_FORM_string, Name);
1812 if (!LinkageName.empty()) {
1813 AddString(SubprogramDie, DW_AT_MIPS_linkage_name, DW_FORM_string,
1816 if (SPD->getType()) AddType(SubprogramDie, SPD->getType(), Unit);
1817 AddUInt(SubprogramDie, DW_AT_external, DW_FORM_flag, IsExternal);
1818 AddUInt(SubprogramDie, DW_AT_prototyped, DW_FORM_flag, 1);
1820 // Add source line info if available.
1821 AddSourceLine(SubprogramDie, UnitDesc, SPD->getLine());
1824 Slot = SubprogramDie;
1826 // Add to context owner.
1827 Unit->getDie()->AddChild(SubprogramDie);
1829 // Expose as global.
1830 Unit->AddGlobal(FullName, SubprogramDie);
1832 return SubprogramDie;
1835 /// NewScopeVariable - Create a new scope variable.
1837 DIE *NewScopeVariable(DebugVariable *DV, CompileUnit *Unit) {
1838 // Get the descriptor.
1839 VariableDesc *VD = DV->getDesc();
1841 // Translate tag to proper Dwarf tag. The result variable is dropped for
1844 switch (VD->getTag()) {
1845 case DW_TAG_return_variable: return NULL;
1846 case DW_TAG_arg_variable: Tag = DW_TAG_formal_parameter; break;
1847 case DW_TAG_auto_variable: // fall thru
1848 default: Tag = DW_TAG_variable; break;
1851 // Define variable debug information entry.
1852 DIE *VariableDie = new DIE(Tag);
1853 AddString(VariableDie, DW_AT_name, DW_FORM_string, VD->getName());
1855 // Add source line info if available.
1856 AddSourceLine(VariableDie, VD->getFile(), VD->getLine());
1858 // Add variable type.
1859 AddType(VariableDie, VD->getType(), Unit);
1861 // Add variable address.
1862 MachineLocation Location;
1863 RI->getLocation(*MF, DV->getFrameIndex(), Location);
1864 AddAddress(VariableDie, DW_AT_location, Location);
1869 /// ConstructScope - Construct the components of a scope.
1871 void ConstructScope(DebugScope *ParentScope,
1872 unsigned ParentStartID, unsigned ParentEndID,
1873 DIE *ParentDie, CompileUnit *Unit) {
1874 // Add variables to scope.
1875 std::vector<DebugVariable *> &Variables = ParentScope->getVariables();
1876 for (unsigned i = 0, N = Variables.size(); i < N; ++i) {
1877 DIE *VariableDie = NewScopeVariable(Variables[i], Unit);
1878 if (VariableDie) ParentDie->AddChild(VariableDie);
1881 // Add nested scopes.
1882 std::vector<DebugScope *> &Scopes = ParentScope->getScopes();
1883 for (unsigned j = 0, M = Scopes.size(); j < M; ++j) {
1884 // Define the Scope debug information entry.
1885 DebugScope *Scope = Scopes[j];
1886 // FIXME - Ignore inlined functions for the time being.
1887 if (!Scope->getParent()) continue;
1889 unsigned StartID = DebugInfo->MappedLabel(Scope->getStartLabelID());
1890 unsigned EndID = DebugInfo->MappedLabel(Scope->getEndLabelID());
1892 // Ignore empty scopes.
1893 if (StartID == EndID && StartID != 0) continue;
1894 if (Scope->getScopes().empty() && Scope->getVariables().empty()) continue;
1896 if (StartID == ParentStartID && EndID == ParentEndID) {
1897 // Just add stuff to the parent scope.
1898 ConstructScope(Scope, ParentStartID, ParentEndID, ParentDie, Unit);
1900 DIE *ScopeDie = new DIE(DW_TAG_lexical_block);
1902 // Add the scope bounds.
1904 AddLabel(ScopeDie, DW_AT_low_pc, DW_FORM_addr,
1905 DWLabel("loc", StartID));
1907 AddLabel(ScopeDie, DW_AT_low_pc, DW_FORM_addr,
1908 DWLabel("func_begin", SubprogramCount));
1911 AddLabel(ScopeDie, DW_AT_high_pc, DW_FORM_addr,
1912 DWLabel("loc", EndID));
1914 AddLabel(ScopeDie, DW_AT_high_pc, DW_FORM_addr,
1915 DWLabel("func_end", SubprogramCount));
1918 // Add the scope contents.
1919 ConstructScope(Scope, StartID, EndID, ScopeDie, Unit);
1920 ParentDie->AddChild(ScopeDie);
1925 /// ConstructRootScope - Construct the scope for the subprogram.
1927 void ConstructRootScope(DebugScope *RootScope) {
1928 // Exit if there is no root scope.
1929 if (!RootScope) return;
1931 // Get the subprogram debug information entry.
1932 SubprogramDesc *SPD = cast<SubprogramDesc>(RootScope->getDesc());
1934 // Get the compile unit context.
1935 CompileUnit *Unit = GetBaseCompileUnit();
1937 // Get the subprogram die.
1938 DIE *SPDie = Unit->getDieMapSlotFor(SPD);
1939 assert(SPDie && "Missing subprogram descriptor");
1941 // Add the function bounds.
1942 AddLabel(SPDie, DW_AT_low_pc, DW_FORM_addr,
1943 DWLabel("func_begin", SubprogramCount));
1944 AddLabel(SPDie, DW_AT_high_pc, DW_FORM_addr,
1945 DWLabel("func_end", SubprogramCount));
1946 MachineLocation Location(RI->getFrameRegister(*MF));
1947 AddAddress(SPDie, DW_AT_frame_base, Location);
1949 ConstructScope(RootScope, 0, 0, SPDie, Unit);
1952 /// EmitInitial - Emit initial Dwarf declarations. This is necessary for cc
1953 /// tools to recognize the object file contains Dwarf information.
1954 void EmitInitial() {
1955 // Check to see if we already emitted intial headers.
1956 if (didInitial) return;
1959 // Dwarf sections base addresses.
1960 if (TAI->getDwarfRequiresFrameSection()) {
1961 Asm->SwitchToDataSection(TAI->getDwarfFrameSection());
1962 EmitLabel("section_frame", 0);
1964 Asm->SwitchToDataSection(TAI->getDwarfInfoSection());
1965 EmitLabel("section_info", 0);
1966 Asm->SwitchToDataSection(TAI->getDwarfAbbrevSection());
1967 EmitLabel("section_abbrev", 0);
1968 Asm->SwitchToDataSection(TAI->getDwarfARangesSection());
1969 EmitLabel("section_aranges", 0);
1970 Asm->SwitchToDataSection(TAI->getDwarfMacInfoSection());
1971 EmitLabel("section_macinfo", 0);
1972 Asm->SwitchToDataSection(TAI->getDwarfLineSection());
1973 EmitLabel("section_line", 0);
1974 Asm->SwitchToDataSection(TAI->getDwarfLocSection());
1975 EmitLabel("section_loc", 0);
1976 Asm->SwitchToDataSection(TAI->getDwarfPubNamesSection());
1977 EmitLabel("section_pubnames", 0);
1978 Asm->SwitchToDataSection(TAI->getDwarfStrSection());
1979 EmitLabel("section_str", 0);
1980 Asm->SwitchToDataSection(TAI->getDwarfRangesSection());
1981 EmitLabel("section_ranges", 0);
1983 Asm->SwitchToTextSection(TAI->getTextSection());
1984 EmitLabel("text_begin", 0);
1985 Asm->SwitchToDataSection(TAI->getDataSection());
1986 EmitLabel("data_begin", 0);
1988 // Emit common frame information.
1989 EmitInitialDebugFrame();
1992 /// EmitDIE - Recusively Emits a debug information entry.
1994 void EmitDIE(DIE *Die) const {
1995 // Get the abbreviation for this DIE.
1996 unsigned AbbrevNumber = Die->getAbbrevNumber();
1997 const DIEAbbrev *Abbrev = Abbreviations[AbbrevNumber - 1];
2001 // Emit the code (index) for the abbreviation.
2002 EmitULEB128Bytes(AbbrevNumber);
2003 EOL(std::string("Abbrev [" +
2004 utostr(AbbrevNumber) +
2005 "] 0x" + utohexstr(Die->getOffset()) +
2006 ":0x" + utohexstr(Die->getSize()) + " " +
2007 TagString(Abbrev->getTag())));
2009 const std::vector<DIEValue *> &Values = Die->getValues();
2010 const std::vector<DIEAbbrevData> &AbbrevData = Abbrev->getData();
2012 // Emit the DIE attribute values.
2013 for (unsigned i = 0, N = Values.size(); i < N; ++i) {
2014 unsigned Attr = AbbrevData[i].getAttribute();
2015 unsigned Form = AbbrevData[i].getForm();
2016 assert(Form && "Too many attributes for DIE (check abbreviation)");
2019 case DW_AT_sibling: {
2020 EmitInt32(Die->SiblingOffset());
2024 // Emit an attribute using the defined form.
2025 Values[i]->EmitValue(*this, Form);
2030 EOL(AttributeString(Attr));
2033 // Emit the DIE children if any.
2034 if (Abbrev->getChildrenFlag() == DW_CHILDREN_yes) {
2035 const std::vector<DIE *> &Children = Die->getChildren();
2037 for (unsigned j = 0, M = Children.size(); j < M; ++j) {
2038 EmitDIE(Children[j]);
2041 EmitInt8(0); EOL("End Of Children Mark");
2045 /// SizeAndOffsetDie - Compute the size and offset of a DIE.
2047 unsigned SizeAndOffsetDie(DIE *Die, unsigned Offset, bool Last) {
2048 // Get the children.
2049 const std::vector<DIE *> &Children = Die->getChildren();
2051 // If not last sibling and has children then add sibling offset attribute.
2052 if (!Last && !Children.empty()) Die->AddSiblingOffset();
2054 // Record the abbreviation.
2055 AssignAbbrevNumber(Die->getAbbrev());
2057 // Get the abbreviation for this DIE.
2058 unsigned AbbrevNumber = Die->getAbbrevNumber();
2059 const DIEAbbrev *Abbrev = Abbreviations[AbbrevNumber - 1];
2062 Die->setOffset(Offset);
2064 // Start the size with the size of abbreviation code.
2065 Offset += SizeULEB128(AbbrevNumber);
2067 const std::vector<DIEValue *> &Values = Die->getValues();
2068 const std::vector<DIEAbbrevData> &AbbrevData = Abbrev->getData();
2070 // Size the DIE attribute values.
2071 for (unsigned i = 0, N = Values.size(); i < N; ++i) {
2072 // Size attribute value.
2073 Offset += Values[i]->SizeOf(*this, AbbrevData[i].getForm());
2076 // Size the DIE children if any.
2077 if (!Children.empty()) {
2078 assert(Abbrev->getChildrenFlag() == DW_CHILDREN_yes &&
2079 "Children flag not set");
2081 for (unsigned j = 0, M = Children.size(); j < M; ++j) {
2082 Offset = SizeAndOffsetDie(Children[j], Offset, (j + 1) == M);
2085 // End of children marker.
2086 Offset += sizeof(int8_t);
2089 Die->setSize(Offset - Die->getOffset());
2093 /// SizeAndOffsets - Compute the size and offset of all the DIEs.
2095 void SizeAndOffsets() {
2096 // Process base compile unit.
2097 CompileUnit *Unit = GetBaseCompileUnit();
2098 // Compute size of compile unit header
2099 unsigned Offset = sizeof(int32_t) + // Length of Compilation Unit Info
2100 sizeof(int16_t) + // DWARF version number
2101 sizeof(int32_t) + // Offset Into Abbrev. Section
2102 sizeof(int8_t); // Pointer Size (in bytes)
2103 SizeAndOffsetDie(Unit->getDie(), Offset, true);
2106 /// EmitFrameMoves - Emit frame instructions to describe the layout of the
2108 void EmitFrameMoves(const char *BaseLabel, unsigned BaseLabelID,
2109 std::vector<MachineMove *> &Moves) {
2110 for (unsigned i = 0, N = Moves.size(); i < N; ++i) {
2111 MachineMove *Move = Moves[i];
2112 unsigned LabelID = DebugInfo->MappedLabel(Move->getLabelID());
2114 // Throw out move if the label is invalid.
2115 if (!LabelID) continue;
2117 const MachineLocation &Dst = Move->getDestination();
2118 const MachineLocation &Src = Move->getSource();
2120 // Advance row if new location.
2121 if (BaseLabel && LabelID && BaseLabelID != LabelID) {
2122 EmitInt8(DW_CFA_advance_loc4);
2123 EOL("DW_CFA_advance_loc4");
2124 EmitDifference("loc", LabelID, BaseLabel, BaseLabelID, true);
2127 BaseLabelID = LabelID;
2132 Asm->TM.getFrameInfo()->getStackGrowthDirection() ==
2133 TargetFrameInfo::StackGrowsUp ?
2134 TAI->getAddressSize() : -TAI->getAddressSize();
2136 // If advancing cfa.
2137 if (Dst.isRegister() && Dst.getRegister() == MachineLocation::VirtualFP) {
2138 if (!Src.isRegister()) {
2139 if (Src.getRegister() == MachineLocation::VirtualFP) {
2140 EmitInt8(DW_CFA_def_cfa_offset);
2141 EOL("DW_CFA_def_cfa_offset");
2143 EmitInt8(DW_CFA_def_cfa);
2144 EOL("DW_CFA_def_cfa");
2145 EmitULEB128Bytes(RI->getDwarfRegNum(Src.getRegister()));
2149 int Offset = Src.getOffset() / stackGrowth;
2151 EmitULEB128Bytes(Offset);
2154 assert(0 && "Machine move no supported yet.");
2157 unsigned Reg = RI->getDwarfRegNum(Src.getRegister());
2158 int Offset = Dst.getOffset() / stackGrowth;
2161 EmitInt8(DW_CFA_offset_extended_sf);
2162 EOL("DW_CFA_offset_extended_sf");
2163 EmitULEB128Bytes(Reg);
2165 EmitSLEB128Bytes(Offset);
2167 } else if (Reg < 64) {
2168 EmitInt8(DW_CFA_offset + Reg);
2169 EOL("DW_CFA_offset + Reg");
2170 EmitULEB128Bytes(Offset);
2173 EmitInt8(DW_CFA_offset_extended);
2174 EOL("DW_CFA_offset_extended");
2175 EmitULEB128Bytes(Reg);
2177 EmitULEB128Bytes(Offset);
2184 /// EmitDebugInfo - Emit the debug info section.
2186 void EmitDebugInfo() const {
2187 // Start debug info section.
2188 Asm->SwitchToDataSection(TAI->getDwarfInfoSection());
2190 CompileUnit *Unit = GetBaseCompileUnit();
2191 DIE *Die = Unit->getDie();
2192 // Emit the compile units header.
2193 EmitLabel("info_begin", Unit->getID());
2194 // Emit size of content not including length itself
2195 unsigned ContentSize = Die->getSize() +
2196 sizeof(int16_t) + // DWARF version number
2197 sizeof(int32_t) + // Offset Into Abbrev. Section
2198 sizeof(int8_t) + // Pointer Size (in bytes)
2199 sizeof(int32_t); // FIXME - extra pad for gdb bug.
2201 EmitInt32(ContentSize); EOL("Length of Compilation Unit Info");
2202 EmitInt16(DWARF_VERSION); EOL("DWARF version number");
2203 EmitDifference("abbrev_begin", 0, "section_abbrev", 0, true);
2204 EOL("Offset Into Abbrev. Section");
2205 EmitInt8(TAI->getAddressSize()); EOL("Address Size (in bytes)");
2208 EmitInt8(0); EOL("Extra Pad For GDB"); // FIXME - extra pad for gdb bug.
2209 EmitInt8(0); EOL("Extra Pad For GDB"); // FIXME - extra pad for gdb bug.
2210 EmitInt8(0); EOL("Extra Pad For GDB"); // FIXME - extra pad for gdb bug.
2211 EmitInt8(0); EOL("Extra Pad For GDB"); // FIXME - extra pad for gdb bug.
2212 EmitLabel("info_end", Unit->getID());
2217 /// EmitAbbreviations - Emit the abbreviation section.
2219 void EmitAbbreviations() const {
2220 // Check to see if it is worth the effort.
2221 if (!Abbreviations.empty()) {
2222 // Start the debug abbrev section.
2223 Asm->SwitchToDataSection(TAI->getDwarfAbbrevSection());
2225 EmitLabel("abbrev_begin", 0);
2227 // For each abbrevation.
2228 for (unsigned i = 0, N = Abbreviations.size(); i < N; ++i) {
2229 // Get abbreviation data
2230 const DIEAbbrev *Abbrev = Abbreviations[i];
2232 // Emit the abbrevations code (base 1 index.)
2233 EmitULEB128Bytes(Abbrev->getNumber()); EOL("Abbreviation Code");
2235 // Emit the abbreviations data.
2236 Abbrev->Emit(*this);
2241 EmitLabel("abbrev_end", 0);
2247 /// EmitDebugLines - Emit source line information.
2249 void EmitDebugLines() const {
2250 // Minimum line delta, thus ranging from -10..(255-10).
2251 const int MinLineDelta = -(DW_LNS_fixed_advance_pc + 1);
2252 // Maximum line delta, thus ranging from -10..(255-10).
2253 const int MaxLineDelta = 255 + MinLineDelta;
2255 // Start the dwarf line section.
2256 Asm->SwitchToDataSection(TAI->getDwarfLineSection());
2258 // Construct the section header.
2260 EmitDifference("line_end", 0, "line_begin", 0, true);
2261 EOL("Length of Source Line Info");
2262 EmitLabel("line_begin", 0);
2264 EmitInt16(DWARF_VERSION); EOL("DWARF version number");
2266 EmitDifference("line_prolog_end", 0, "line_prolog_begin", 0, true);
2267 EOL("Prolog Length");
2268 EmitLabel("line_prolog_begin", 0);
2270 EmitInt8(1); EOL("Minimum Instruction Length");
2272 EmitInt8(1); EOL("Default is_stmt_start flag");
2274 EmitInt8(MinLineDelta); EOL("Line Base Value (Special Opcodes)");
2276 EmitInt8(MaxLineDelta); EOL("Line Range Value (Special Opcodes)");
2278 EmitInt8(-MinLineDelta); EOL("Special Opcode Base");
2280 // Line number standard opcode encodings argument count
2281 EmitInt8(0); EOL("DW_LNS_copy arg count");
2282 EmitInt8(1); EOL("DW_LNS_advance_pc arg count");
2283 EmitInt8(1); EOL("DW_LNS_advance_line arg count");
2284 EmitInt8(1); EOL("DW_LNS_set_file arg count");
2285 EmitInt8(1); EOL("DW_LNS_set_column arg count");
2286 EmitInt8(0); EOL("DW_LNS_negate_stmt arg count");
2287 EmitInt8(0); EOL("DW_LNS_set_basic_block arg count");
2288 EmitInt8(0); EOL("DW_LNS_const_add_pc arg count");
2289 EmitInt8(1); EOL("DW_LNS_fixed_advance_pc arg count");
2291 const UniqueVector<std::string> &Directories = DebugInfo->getDirectories();
2292 const UniqueVector<SourceFileInfo>
2293 &SourceFiles = DebugInfo->getSourceFiles();
2295 // Emit directories.
2296 for (unsigned DirectoryID = 1, NDID = Directories.size();
2297 DirectoryID <= NDID; ++DirectoryID) {
2298 EmitString(Directories[DirectoryID]); EOL("Directory");
2300 EmitInt8(0); EOL("End of directories");
2303 for (unsigned SourceID = 1, NSID = SourceFiles.size();
2304 SourceID <= NSID; ++SourceID) {
2305 const SourceFileInfo &SourceFile = SourceFiles[SourceID];
2306 EmitString(SourceFile.getName()); EOL("Source");
2307 EmitULEB128Bytes(SourceFile.getDirectoryID()); EOL("Directory #");
2308 EmitULEB128Bytes(0); EOL("Mod date");
2309 EmitULEB128Bytes(0); EOL("File size");
2311 EmitInt8(0); EOL("End of files");
2313 EmitLabel("line_prolog_end", 0);
2315 // A sequence for each text section.
2316 for (unsigned j = 0, M = SectionSourceLines.size(); j < M; ++j) {
2317 // Isolate current sections line info.
2318 const std::vector<SourceLineInfo> &LineInfos = SectionSourceLines[j];
2322 << TAI->getCommentString() << " "
2324 << SectionMap[j + 1].c_str() << "\n";
2327 // Dwarf assumes we start with first line of first source file.
2328 unsigned Source = 1;
2331 // Construct rows of the address, source, line, column matrix.
2332 for (unsigned i = 0, N = LineInfos.size(); i < N; ++i) {
2333 const SourceLineInfo &LineInfo = LineInfos[i];
2334 unsigned LabelID = DebugInfo->MappedLabel(LineInfo.getLabelID());
2335 if (!LabelID) continue;
2338 unsigned SourceID = LineInfo.getSourceID();
2339 const SourceFileInfo &SourceFile = SourceFiles[SourceID];
2340 unsigned DirectoryID = SourceFile.getDirectoryID();
2342 << TAI->getCommentString() << " "
2343 << Directories[DirectoryID]
2344 << SourceFile.getName() << ":"
2345 << LineInfo.getLine() << "\n";
2348 // Define the line address.
2349 EmitInt8(0); EOL("Extended Op");
2350 EmitInt8(TAI->getAddressSize() + 1); EOL("Op size");
2351 EmitInt8(DW_LNE_set_address); EOL("DW_LNE_set_address");
2352 EmitReference("loc", LabelID); EOL("Location label");
2354 // If change of source, then switch to the new source.
2355 if (Source != LineInfo.getSourceID()) {
2356 Source = LineInfo.getSourceID();
2357 EmitInt8(DW_LNS_set_file); EOL("DW_LNS_set_file");
2358 EmitULEB128Bytes(Source); EOL("New Source");
2361 // If change of line.
2362 if (Line != LineInfo.getLine()) {
2363 // Determine offset.
2364 int Offset = LineInfo.getLine() - Line;
2365 int Delta = Offset - MinLineDelta;
2368 Line = LineInfo.getLine();
2370 // If delta is small enough and in range...
2371 if (Delta >= 0 && Delta < (MaxLineDelta - 1)) {
2372 // ... then use fast opcode.
2373 EmitInt8(Delta - MinLineDelta); EOL("Line Delta");
2375 // ... otherwise use long hand.
2376 EmitInt8(DW_LNS_advance_line); EOL("DW_LNS_advance_line");
2377 EmitSLEB128Bytes(Offset); EOL("Line Offset");
2378 EmitInt8(DW_LNS_copy); EOL("DW_LNS_copy");
2381 // Copy the previous row (different address or source)
2382 EmitInt8(DW_LNS_copy); EOL("DW_LNS_copy");
2386 // Define last address of section.
2387 EmitInt8(0); EOL("Extended Op");
2388 EmitInt8(TAI->getAddressSize() + 1); EOL("Op size");
2389 EmitInt8(DW_LNE_set_address); EOL("DW_LNE_set_address");
2390 EmitReference("section_end", j + 1); EOL("Section end label");
2392 // Mark end of matrix.
2393 EmitInt8(0); EOL("DW_LNE_end_sequence");
2394 EmitULEB128Bytes(1); O << "\n";
2395 EmitInt8(1); O << "\n";
2398 EmitLabel("line_end", 0);
2403 /// EmitInitialDebugFrame - Emit common frame info into a debug frame section.
2405 void EmitInitialDebugFrame() {
2406 if (!TAI->getDwarfRequiresFrameSection())
2410 Asm->TM.getFrameInfo()->getStackGrowthDirection() ==
2411 TargetFrameInfo::StackGrowsUp ?
2412 TAI->getAddressSize() : -TAI->getAddressSize();
2414 // Start the dwarf frame section.
2415 Asm->SwitchToDataSection(TAI->getDwarfFrameSection());
2417 EmitLabel("frame_common", 0);
2418 EmitDifference("frame_common_end", 0,
2419 "frame_common_begin", 0, true);
2420 EOL("Length of Common Information Entry");
2422 EmitLabel("frame_common_begin", 0);
2423 EmitInt32(DW_CIE_ID); EOL("CIE Identifier Tag");
2424 EmitInt8(DW_CIE_VERSION); EOL("CIE Version");
2425 EmitString(""); EOL("CIE Augmentation");
2426 EmitULEB128Bytes(1); EOL("CIE Code Alignment Factor");
2427 EmitSLEB128Bytes(stackGrowth); EOL("CIE Data Alignment Factor");
2428 EmitInt8(RI->getDwarfRegNum(RI->getRARegister())); EOL("CIE RA Column");
2430 std::vector<MachineMove *> Moves;
2431 RI->getInitialFrameState(Moves);
2432 EmitFrameMoves(NULL, 0, Moves);
2433 for (unsigned i = 0, N = Moves.size(); i < N; ++i) delete Moves[i];
2436 EmitLabel("frame_common_end", 0);
2441 /// EmitFunctionDebugFrame - Emit per function frame info into a debug frame
2443 void EmitFunctionDebugFrame() {
2444 if (!TAI->getDwarfRequiresFrameSection())
2447 // Start the dwarf frame section.
2448 Asm->SwitchToDataSection(TAI->getDwarfFrameSection());
2450 EmitDifference("frame_end", SubprogramCount,
2451 "frame_begin", SubprogramCount, true);
2452 EOL("Length of Frame Information Entry");
2454 EmitLabel("frame_begin", SubprogramCount);
2456 EmitDifference("frame_common", 0, "section_frame", 0, true);
2457 EOL("FDE CIE offset");
2459 EmitReference("func_begin", SubprogramCount); EOL("FDE initial location");
2460 EmitDifference("func_end", SubprogramCount,
2461 "func_begin", SubprogramCount);
2462 EOL("FDE address range");
2464 std::vector<MachineMove *> &Moves = DebugInfo->getFrameMoves();
2466 EmitFrameMoves("func_begin", SubprogramCount, Moves);
2469 EmitLabel("frame_end", SubprogramCount);
2474 /// EmitDebugPubNames - Emit visible names into a debug pubnames section.
2476 void EmitDebugPubNames() {
2477 // Start the dwarf pubnames section.
2478 Asm->SwitchToDataSection(TAI->getDwarfPubNamesSection());
2480 CompileUnit *Unit = GetBaseCompileUnit();
2482 EmitDifference("pubnames_end", Unit->getID(),
2483 "pubnames_begin", Unit->getID(), true);
2484 EOL("Length of Public Names Info");
2486 EmitLabel("pubnames_begin", Unit->getID());
2488 EmitInt16(DWARF_VERSION); EOL("DWARF Version");
2490 EmitDifference("info_begin", Unit->getID(), "section_info", 0, true);
2491 EOL("Offset of Compilation Unit Info");
2493 EmitDifference("info_end", Unit->getID(), "info_begin", Unit->getID(),true);
2494 EOL("Compilation Unit Length");
2496 std::map<std::string, DIE *> &Globals = Unit->getGlobals();
2498 for (std::map<std::string, DIE *>::iterator GI = Globals.begin(),
2501 const std::string &Name = GI->first;
2502 DIE * Entity = GI->second;
2504 EmitInt32(Entity->getOffset()); EOL("DIE offset");
2505 EmitString(Name); EOL("External Name");
2508 EmitInt32(0); EOL("End Mark");
2509 EmitLabel("pubnames_end", Unit->getID());
2514 /// EmitDebugStr - Emit visible names into a debug str section.
2516 void EmitDebugStr() {
2517 // Check to see if it is worth the effort.
2518 if (!StringPool.empty()) {
2519 // Start the dwarf str section.
2520 Asm->SwitchToDataSection(TAI->getDwarfStrSection());
2522 // For each of strings in the string pool.
2523 for (unsigned StringID = 1, N = StringPool.size();
2524 StringID <= N; ++StringID) {
2525 // Emit a label for reference from debug information entries.
2526 EmitLabel("string", StringID);
2527 // Emit the string itself.
2528 const std::string &String = StringPool[StringID];
2529 EmitString(String); O << "\n";
2536 /// EmitDebugLoc - Emit visible names into a debug loc section.
2538 void EmitDebugLoc() {
2539 // Start the dwarf loc section.
2540 Asm->SwitchToDataSection(TAI->getDwarfLocSection());
2545 /// EmitDebugARanges - Emit visible names into a debug aranges section.
2547 void EmitDebugARanges() {
2548 // Start the dwarf aranges section.
2549 Asm->SwitchToDataSection(TAI->getDwarfARangesSection());
2553 CompileUnit *Unit = GetBaseCompileUnit();
2555 // Don't include size of length
2556 EmitInt32(0x1c); EOL("Length of Address Ranges Info");
2558 EmitInt16(DWARF_VERSION); EOL("Dwarf Version");
2560 EmitReference("info_begin", Unit->getID());
2561 EOL("Offset of Compilation Unit Info");
2563 EmitInt8(TAI->getAddressSize()); EOL("Size of Address");
2565 EmitInt8(0); EOL("Size of Segment Descriptor");
2567 EmitInt16(0); EOL("Pad (1)");
2568 EmitInt16(0); EOL("Pad (2)");
2571 EmitReference("text_begin", 0); EOL("Address");
2572 EmitDifference("text_end", 0, "text_begin", 0, true); EOL("Length");
2574 EmitInt32(0); EOL("EOM (1)");
2575 EmitInt32(0); EOL("EOM (2)");
2581 /// EmitDebugRanges - Emit visible names into a debug ranges section.
2583 void EmitDebugRanges() {
2584 // Start the dwarf ranges section.
2585 Asm->SwitchToDataSection(TAI->getDwarfRangesSection());
2590 /// EmitDebugMacInfo - Emit visible names into a debug macinfo section.
2592 void EmitDebugMacInfo() {
2593 // Start the dwarf macinfo section.
2594 Asm->SwitchToDataSection(TAI->getDwarfMacInfoSection());
2599 /// ConstructCompileUnitDIEs - Create a compile unit DIE for each source and
2601 void ConstructCompileUnitDIEs() {
2602 const UniqueVector<CompileUnitDesc *> CUW = DebugInfo->getCompileUnits();
2604 for (unsigned i = 1, N = CUW.size(); i <= N; ++i) {
2605 unsigned ID = DebugInfo->RecordSource(CUW[i]);
2606 CompileUnit *Unit = NewCompileUnit(CUW[i], ID);
2607 CompileUnits.push_back(Unit);
2611 /// ConstructGlobalDIEs - Create DIEs for each of the externally visible
2612 /// global variables.
2613 void ConstructGlobalDIEs() {
2614 std::vector<GlobalVariableDesc *> GlobalVariables =
2615 DebugInfo->getAnchoredDescriptors<GlobalVariableDesc>(*M);
2617 for (unsigned i = 0, N = GlobalVariables.size(); i < N; ++i) {
2618 GlobalVariableDesc *GVD = GlobalVariables[i];
2619 NewGlobalVariable(GVD);
2623 /// ConstructSubprogramDIEs - Create DIEs for each of the externally visible
2625 void ConstructSubprogramDIEs() {
2626 std::vector<SubprogramDesc *> Subprograms =
2627 DebugInfo->getAnchoredDescriptors<SubprogramDesc>(*M);
2629 for (unsigned i = 0, N = Subprograms.size(); i < N; ++i) {
2630 SubprogramDesc *SPD = Subprograms[i];
2635 /// ShouldEmitDwarf - Returns true if Dwarf declarations should be made.
2637 bool ShouldEmitDwarf() const { return shouldEmit; }
2640 //===--------------------------------------------------------------------===//
2641 // Main entry points.
2643 Dwarf(std::ostream &OS, AsmPrinter *A, const TargetAsmInfo *T)
2647 , TD(Asm->TM.getTargetData())
2648 , RI(Asm->TM.getRegisterInfo())
2654 , SubprogramCount(0)
2656 , AbbreviationsSet(InitAbbreviationsSetSize)
2658 , ValuesSet(InitValuesSetSize)
2663 , SectionSourceLines()
2667 for (unsigned i = 0, N = CompileUnits.size(); i < N; ++i)
2668 delete CompileUnits[i];
2669 for (unsigned j = 0, M = Values.size(); j < M; ++j)
2675 const TargetAsmInfo *getTargetAsmInfo() const { return TAI; }
2677 /// SetDebugInfo - Set DebugInfo when it's known that pass manager has
2678 /// created it. Set by the target AsmPrinter.
2679 void SetDebugInfo(MachineDebugInfo *DI) {
2680 // Make sure initial declarations are made.
2681 if (!DebugInfo && DI->hasInfo()) {
2685 // Emit initial sections
2688 // Create all the compile unit DIEs.
2689 ConstructCompileUnitDIEs();
2691 // Create DIEs for each of the externally visible global variables.
2692 ConstructGlobalDIEs();
2694 // Create DIEs for each of the externally visible subprograms.
2695 ConstructSubprogramDIEs();
2697 // Prime section data.
2698 SectionMap.insert(TAI->getTextSection());
2702 /// BeginModule - Emit all Dwarf sections that should come prior to the
2704 void BeginModule(Module *M) {
2707 if (!ShouldEmitDwarf()) return;
2708 EOL("Dwarf Begin Module");
2711 /// EndModule - Emit all Dwarf sections that should come after the content.
2714 if (!ShouldEmitDwarf()) return;
2715 EOL("Dwarf End Module");
2717 // Standard sections final addresses.
2718 Asm->SwitchToTextSection(TAI->getTextSection());
2719 EmitLabel("text_end", 0);
2720 Asm->SwitchToDataSection(TAI->getDataSection());
2721 EmitLabel("data_end", 0);
2723 // End text sections.
2724 for (unsigned i = 1, N = SectionMap.size(); i <= N; ++i) {
2725 Asm->SwitchToTextSection(SectionMap[i].c_str());
2726 EmitLabel("section_end", i);
2729 // Compute DIE offsets and sizes.
2732 // Emit all the DIEs into a debug info section
2735 // Corresponding abbreviations into a abbrev section.
2736 EmitAbbreviations();
2738 // Emit source line correspondence into a debug line section.
2741 // Emit info into a debug pubnames section.
2742 EmitDebugPubNames();
2744 // Emit info into a debug str section.
2747 // Emit info into a debug loc section.
2750 // Emit info into a debug aranges section.
2753 // Emit info into a debug ranges section.
2756 // Emit info into a debug macinfo section.
2760 /// BeginFunction - Gather pre-function debug information. Assumes being
2761 /// emitted immediately after the function entry point.
2762 void BeginFunction(MachineFunction *MF) {
2765 if (!ShouldEmitDwarf()) return;
2766 EOL("Dwarf Begin Function");
2768 // Begin accumulating function debug information.
2769 DebugInfo->BeginFunction(MF);
2771 // Assumes in correct section after the entry point.
2772 EmitLabel("func_begin", ++SubprogramCount);
2775 /// EndFunction - Gather and emit post-function debug information.
2777 void EndFunction() {
2778 if (!ShouldEmitDwarf()) return;
2779 EOL("Dwarf End Function");
2781 // Define end label for subprogram.
2782 EmitLabel("func_end", SubprogramCount);
2784 // Get function line info.
2785 const std::vector<SourceLineInfo> &LineInfos = DebugInfo->getSourceLines();
2787 if (!LineInfos.empty()) {
2788 // Get section line info.
2789 unsigned ID = SectionMap.insert(Asm->CurrentSection);
2790 if (SectionSourceLines.size() < ID) SectionSourceLines.resize(ID);
2791 std::vector<SourceLineInfo> &SectionLineInfos = SectionSourceLines[ID-1];
2792 // Append the function info to section info.
2793 SectionLineInfos.insert(SectionLineInfos.end(),
2794 LineInfos.begin(), LineInfos.end());
2797 // Construct scopes for subprogram.
2798 ConstructRootScope(DebugInfo->getRootScope());
2800 // Emit function frame information.
2801 EmitFunctionDebugFrame();
2803 // Reset the line numbers for the next function.
2804 DebugInfo->ClearLineInfo();
2806 // Clear function debug information.
2807 DebugInfo->EndFunction();
2811 } // End of namespace llvm
2813 //===----------------------------------------------------------------------===//
2815 /// Emit - Print the abbreviation using the specified Dwarf writer.
2817 void DIEAbbrev::Emit(const Dwarf &DW) const {
2818 // Emit its Dwarf tag type.
2819 DW.EmitULEB128Bytes(Tag);
2820 DW.EOL(TagString(Tag));
2822 // Emit whether it has children DIEs.
2823 DW.EmitULEB128Bytes(ChildrenFlag);
2824 DW.EOL(ChildrenString(ChildrenFlag));
2826 // For each attribute description.
2827 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
2828 const DIEAbbrevData &AttrData = Data[i];
2830 // Emit attribute type.
2831 DW.EmitULEB128Bytes(AttrData.getAttribute());
2832 DW.EOL(AttributeString(AttrData.getAttribute()));
2835 DW.EmitULEB128Bytes(AttrData.getForm());
2836 DW.EOL(FormEncodingString(AttrData.getForm()));
2839 // Mark end of abbreviation.
2840 DW.EmitULEB128Bytes(0); DW.EOL("EOM(1)");
2841 DW.EmitULEB128Bytes(0); DW.EOL("EOM(2)");
2845 void DIEAbbrev::print(std::ostream &O) {
2846 O << "Abbreviation @"
2847 << std::hex << (intptr_t)this << std::dec
2851 << ChildrenString(ChildrenFlag)
2854 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
2856 << AttributeString(Data[i].getAttribute())
2858 << FormEncodingString(Data[i].getForm())
2862 void DIEAbbrev::dump() { print(cerr); }
2865 //===----------------------------------------------------------------------===//
2868 void DIEValue::dump() {
2873 //===----------------------------------------------------------------------===//
2875 /// EmitValue - Emit integer of appropriate size.
2877 void DIEInteger::EmitValue(const Dwarf &DW, unsigned Form) const {
2879 case DW_FORM_flag: // Fall thru
2880 case DW_FORM_ref1: // Fall thru
2881 case DW_FORM_data1: DW.EmitInt8(Integer); break;
2882 case DW_FORM_ref2: // Fall thru
2883 case DW_FORM_data2: DW.EmitInt16(Integer); break;
2884 case DW_FORM_ref4: // Fall thru
2885 case DW_FORM_data4: DW.EmitInt32(Integer); break;
2886 case DW_FORM_ref8: // Fall thru
2887 case DW_FORM_data8: DW.EmitInt64(Integer); break;
2888 case DW_FORM_udata: DW.EmitULEB128Bytes(Integer); break;
2889 case DW_FORM_sdata: DW.EmitSLEB128Bytes(Integer); break;
2890 default: assert(0 && "DIE Value form not supported yet"); break;
2894 //===----------------------------------------------------------------------===//
2896 /// EmitValue - Emit string value.
2898 void DIEString::EmitValue(const Dwarf &DW, unsigned Form) const {
2899 DW.EmitString(String);
2902 //===----------------------------------------------------------------------===//
2904 /// EmitValue - Emit label value.
2906 void DIEDwarfLabel::EmitValue(const Dwarf &DW, unsigned Form) const {
2907 DW.EmitReference(Label);
2910 /// SizeOf - Determine size of label value in bytes.
2912 unsigned DIEDwarfLabel::SizeOf(const Dwarf &DW, unsigned Form) const {
2913 return DW.getTargetAsmInfo()->getAddressSize();
2916 //===----------------------------------------------------------------------===//
2918 /// EmitValue - Emit label value.
2920 void DIEObjectLabel::EmitValue(const Dwarf &DW, unsigned Form) const {
2921 DW.EmitReference(Label);
2924 /// SizeOf - Determine size of label value in bytes.
2926 unsigned DIEObjectLabel::SizeOf(const Dwarf &DW, unsigned Form) const {
2927 return DW.getTargetAsmInfo()->getAddressSize();
2930 //===----------------------------------------------------------------------===//
2932 /// EmitValue - Emit delta value.
2934 void DIEDelta::EmitValue(const Dwarf &DW, unsigned Form) const {
2935 bool IsSmall = Form == DW_FORM_data4;
2936 DW.EmitDifference(LabelHi, LabelLo, IsSmall);
2939 /// SizeOf - Determine size of delta value in bytes.
2941 unsigned DIEDelta::SizeOf(const Dwarf &DW, unsigned Form) const {
2942 if (Form == DW_FORM_data4) return 4;
2943 return DW.getTargetAsmInfo()->getAddressSize();
2946 //===----------------------------------------------------------------------===//
2948 /// EmitValue - Emit debug information entry offset.
2950 void DIEntry::EmitValue(const Dwarf &DW, unsigned Form) const {
2951 DW.EmitInt32(Entry->getOffset());
2954 //===----------------------------------------------------------------------===//
2956 /// ComputeSize - calculate the size of the block.
2958 unsigned DIEBlock::ComputeSize(Dwarf &DW) {
2960 const std::vector<DIEAbbrevData> &AbbrevData = Abbrev.getData();
2962 for (unsigned i = 0, N = Values.size(); i < N; ++i) {
2963 Size += Values[i]->SizeOf(DW, AbbrevData[i].getForm());
2969 /// EmitValue - Emit block data.
2971 void DIEBlock::EmitValue(const Dwarf &DW, unsigned Form) const {
2973 case DW_FORM_block1: DW.EmitInt8(Size); break;
2974 case DW_FORM_block2: DW.EmitInt16(Size); break;
2975 case DW_FORM_block4: DW.EmitInt32(Size); break;
2976 case DW_FORM_block: DW.EmitULEB128Bytes(Size); break;
2977 default: assert(0 && "Improper form for block"); break;
2980 const std::vector<DIEAbbrevData> &AbbrevData = Abbrev.getData();
2982 for (unsigned i = 0, N = Values.size(); i < N; ++i) {
2984 Values[i]->EmitValue(DW, AbbrevData[i].getForm());
2988 /// SizeOf - Determine size of block data in bytes.
2990 unsigned DIEBlock::SizeOf(const Dwarf &DW, unsigned Form) const {
2992 case DW_FORM_block1: return Size + sizeof(int8_t);
2993 case DW_FORM_block2: return Size + sizeof(int16_t);
2994 case DW_FORM_block4: return Size + sizeof(int32_t);
2995 case DW_FORM_block: return Size + SizeULEB128(Size);
2996 default: assert(0 && "Improper form for block"); break;
3001 //===----------------------------------------------------------------------===//
3002 /// DIE Implementation
3005 for (unsigned i = 0, N = Children.size(); i < N; ++i)
3009 /// AddSiblingOffset - Add a sibling offset field to the front of the DIE.
3011 void DIE::AddSiblingOffset() {
3012 DIEInteger *DI = new DIEInteger(0);
3013 Values.insert(Values.begin(), DI);
3014 Abbrev.AddFirstAttribute(DW_AT_sibling, DW_FORM_ref4);
3017 /// Profile - Used to gather unique data for the value folding set.
3019 void DIE::Profile(FoldingSetNodeID &ID) {
3022 for (unsigned i = 0, N = Children.size(); i < N; ++i)
3023 ID.AddPointer(Children[i]);
3025 for (unsigned j = 0, M = Values.size(); j < M; ++j)
3026 ID.AddPointer(Values[j]);
3030 void DIE::print(std::ostream &O, unsigned IncIndent) {
3031 static unsigned IndentCount = 0;
3032 IndentCount += IncIndent;
3033 const std::string Indent(IndentCount, ' ');
3034 bool isBlock = Abbrev.getTag() == 0;
3039 << "0x" << std::hex << (intptr_t)this << std::dec
3040 << ", Offset: " << Offset
3041 << ", Size: " << Size
3045 << TagString(Abbrev.getTag())
3047 << ChildrenString(Abbrev.getChildrenFlag());
3049 O << "Size: " << Size;
3053 const std::vector<DIEAbbrevData> &Data = Abbrev.getData();
3056 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
3059 O << AttributeString(Data[i].getAttribute());
3061 O << "Blk[" << i << "]";
3064 << FormEncodingString(Data[i].getForm())
3066 Values[i]->print(O);
3071 for (unsigned j = 0, M = Children.size(); j < M; ++j) {
3072 Children[j]->print(O, 4);
3075 if (!isBlock) O << "\n";
3076 IndentCount -= IncIndent;
3084 //===----------------------------------------------------------------------===//
3085 /// DwarfWriter Implementation
3088 DwarfWriter::DwarfWriter(std::ostream &OS, AsmPrinter *A,
3089 const TargetAsmInfo *T) {
3090 DW = new Dwarf(OS, A, T);
3093 DwarfWriter::~DwarfWriter() {
3097 /// SetDebugInfo - Set DebugInfo when it's known that pass manager has
3098 /// created it. Set by the target AsmPrinter.
3099 void DwarfWriter::SetDebugInfo(MachineDebugInfo *DI) {
3100 DW->SetDebugInfo(DI);
3103 /// BeginModule - Emit all Dwarf sections that should come prior to the
3105 void DwarfWriter::BeginModule(Module *M) {
3109 /// EndModule - Emit all Dwarf sections that should come after the content.
3111 void DwarfWriter::EndModule() {
3115 /// BeginFunction - Gather pre-function debug information. Assumes being
3116 /// emitted immediately after the function entry point.
3117 void DwarfWriter::BeginFunction(MachineFunction *MF) {
3118 DW->BeginFunction(MF);
3121 /// EndFunction - Gather and emit post-function debug information.
3123 void DwarfWriter::EndFunction() {