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"
39 using namespace llvm::dwarf;
42 DwarfVerbose("dwarf-verbose", cl::Hidden,
43 cl::desc("Add comments to Dwarf directives."));
47 //===----------------------------------------------------------------------===//
49 /// Configuration values for initial hash set sizes (log2).
51 static const unsigned InitDiesSetSize = 9; // 512
52 static const unsigned InitAbbreviationsSetSize = 9; // 512
53 static const unsigned InitValuesSetSize = 9; // 512
55 //===----------------------------------------------------------------------===//
56 /// Forward declarations.
61 //===----------------------------------------------------------------------===//
62 /// LEB 128 number encoding.
64 /// PrintULEB128 - Print a series of hexidecimal values (separated by commas)
65 /// representing an unsigned leb128 value.
66 static void PrintULEB128(std::ostream &O, unsigned Value) {
68 unsigned Byte = Value & 0x7f;
70 if (Value) Byte |= 0x80;
71 O << "0x" << std::hex << Byte << std::dec;
76 /// SizeULEB128 - Compute the number of bytes required for an unsigned leb128
78 static unsigned SizeULEB128(unsigned Value) {
82 Size += sizeof(int8_t);
87 /// PrintSLEB128 - Print a series of hexidecimal values (separated by commas)
88 /// representing a signed leb128 value.
89 static void PrintSLEB128(std::ostream &O, int Value) {
90 int Sign = Value >> (8 * sizeof(Value) - 1);
94 unsigned Byte = Value & 0x7f;
96 IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
97 if (IsMore) Byte |= 0x80;
98 O << "0x" << std::hex << Byte << std::dec;
99 if (IsMore) O << ", ";
103 /// SizeSLEB128 - Compute the number of bytes required for a signed leb128
105 static unsigned SizeSLEB128(int Value) {
107 int Sign = Value >> (8 * sizeof(Value) - 1);
111 unsigned Byte = Value & 0x7f;
113 IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
114 Size += sizeof(int8_t);
119 //===----------------------------------------------------------------------===//
120 /// DWLabel - Labels are used to track locations in the assembler file.
121 /// Labels appear in the form <prefix>debug_<Tag><Number>, where the tag is a
122 /// category of label (Ex. location) and number is a value unique in that
126 /// Tag - Label category tag. Should always be a staticly declared C string.
130 /// Number - Value to make label unique.
134 DWLabel(const char *T, unsigned N) : Tag(T), Number(N) {}
136 void Profile(FoldingSetNodeID &ID) const {
137 ID.AddString(std::string(Tag));
138 ID.AddInteger(Number);
142 void print(std::ostream &O) const {
143 O << ".debug_" << Tag;
144 if (Number) O << Number;
149 //===----------------------------------------------------------------------===//
150 /// DIEAbbrevData - Dwarf abbreviation data, describes the one attribute of a
151 /// Dwarf abbreviation.
152 class DIEAbbrevData {
154 /// Attribute - Dwarf attribute code.
158 /// Form - Dwarf form code.
163 DIEAbbrevData(unsigned A, unsigned F)
169 unsigned getAttribute() const { return Attribute; }
170 unsigned getForm() const { return Form; }
172 /// Profile - Used to gather unique data for the abbreviation folding set.
174 void Profile(FoldingSetNodeID &ID)const {
175 ID.AddInteger(Attribute);
180 //===----------------------------------------------------------------------===//
181 /// DIEAbbrev - Dwarf abbreviation, describes the organization of a debug
182 /// information object.
183 class DIEAbbrev : public FoldingSetNode {
185 /// Tag - Dwarf tag code.
189 /// Unique number for node.
193 /// ChildrenFlag - Dwarf children flag.
195 unsigned ChildrenFlag;
197 /// Data - Raw data bytes for abbreviation.
199 std::vector<DIEAbbrevData> Data;
203 DIEAbbrev(unsigned T, unsigned C)
211 unsigned getTag() const { return Tag; }
212 unsigned getNumber() const { return Number; }
213 unsigned getChildrenFlag() const { return ChildrenFlag; }
214 const std::vector<DIEAbbrevData> &getData() const { return Data; }
215 void setTag(unsigned T) { Tag = T; }
216 void setChildrenFlag(unsigned CF) { ChildrenFlag = CF; }
217 void setNumber(unsigned N) { Number = N; }
219 /// AddAttribute - Adds another set of attribute information to the
221 void AddAttribute(unsigned Attribute, unsigned Form) {
222 Data.push_back(DIEAbbrevData(Attribute, Form));
225 /// AddFirstAttribute - Adds a set of attribute information to the front
226 /// of the abbreviation.
227 void AddFirstAttribute(unsigned Attribute, unsigned Form) {
228 Data.insert(Data.begin(), DIEAbbrevData(Attribute, Form));
231 /// Profile - Used to gather unique data for the abbreviation folding set.
233 void Profile(FoldingSetNodeID &ID) {
235 ID.AddInteger(ChildrenFlag);
237 // For each attribute description.
238 for (unsigned i = 0, N = Data.size(); i < N; ++i)
242 /// Emit - Print the abbreviation using the specified Dwarf writer.
244 void Emit(const Dwarf &DW) const;
247 void print(std::ostream &O);
252 //===----------------------------------------------------------------------===//
253 /// DIE - A structured debug information entry. Has an abbreviation which
254 /// describes it's organization.
255 class DIE : public FoldingSetNode {
257 /// Abbrev - Buffer for constructing abbreviation.
261 /// Offset - Offset in debug info section.
265 /// Size - Size of instance + children.
271 std::vector<DIE *> Children;
273 /// Attributes values.
275 std::vector<DIEValue *> Values;
279 : Abbrev(Tag, DW_CHILDREN_no)
288 DIEAbbrev &getAbbrev() { return Abbrev; }
289 unsigned getAbbrevNumber() const {
290 return Abbrev.getNumber();
292 unsigned getOffset() const { return Offset; }
293 unsigned getSize() const { return Size; }
294 const std::vector<DIE *> &getChildren() const { return Children; }
295 const std::vector<DIEValue *> &getValues() const { return Values; }
296 void setTag(unsigned Tag) { Abbrev.setTag(Tag); }
297 void setOffset(unsigned O) { Offset = O; }
298 void setSize(unsigned S) { Size = S; }
300 /// AddValue - Add a value and attributes to a DIE.
302 void AddValue(unsigned Attribute, unsigned Form, DIEValue *Value) {
303 Abbrev.AddAttribute(Attribute, Form);
304 Values.push_back(Value);
307 /// SiblingOffset - Return the offset of the debug information entry's
309 unsigned SiblingOffset() const { return Offset + Size; }
311 /// AddSiblingOffset - Add a sibling offset field to the front of the DIE.
313 void AddSiblingOffset();
315 /// AddChild - Add a child to the DIE.
317 void AddChild(DIE *Child) {
318 Abbrev.setChildrenFlag(DW_CHILDREN_yes);
319 Children.push_back(Child);
322 /// Detach - Detaches objects connected to it after copying.
328 /// Profile - Used to gather unique data for the value folding set.
330 void Profile(FoldingSetNodeID &ID) ;
333 void print(std::ostream &O, unsigned IncIndent = 0);
338 //===----------------------------------------------------------------------===//
339 /// DIEValue - A debug information entry value.
341 class DIEValue : public FoldingSetNode {
353 /// Type - Type of data stored in the value.
360 virtual ~DIEValue() {}
363 unsigned getType() const { return Type; }
365 // Implement isa/cast/dyncast.
366 static bool classof(const DIEValue *) { return true; }
368 /// EmitValue - Emit value via the Dwarf writer.
370 virtual void EmitValue(const Dwarf &DW, unsigned Form) const = 0;
372 /// SizeOf - Return the size of a value in bytes.
374 virtual unsigned SizeOf(const Dwarf &DW, unsigned Form) const = 0;
376 /// Profile - Used to gather unique data for the value folding set.
378 virtual void Profile(FoldingSetNodeID &ID) = 0;
381 virtual void print(std::ostream &O) = 0;
386 //===----------------------------------------------------------------------===//
387 /// DWInteger - An integer value DIE.
389 class DIEInteger : public DIEValue {
394 DIEInteger(uint64_t I) : DIEValue(isInteger), Integer(I) {}
396 // Implement isa/cast/dyncast.
397 static bool classof(const DIEInteger *) { return true; }
398 static bool classof(const DIEValue *I) { return I->Type == isInteger; }
400 /// BestForm - Choose the best form for integer.
402 static unsigned BestForm(bool IsSigned, uint64_t Integer) {
404 if ((char)Integer == (signed)Integer) return DW_FORM_data1;
405 if ((short)Integer == (signed)Integer) return DW_FORM_data2;
406 if ((int)Integer == (signed)Integer) return DW_FORM_data4;
408 if ((unsigned char)Integer == Integer) return DW_FORM_data1;
409 if ((unsigned short)Integer == Integer) return DW_FORM_data2;
410 if ((unsigned int)Integer == Integer) return DW_FORM_data4;
412 return DW_FORM_data8;
415 /// EmitValue - Emit integer of appropriate size.
417 virtual void EmitValue(const Dwarf &DW, unsigned Form) const;
419 /// SizeOf - Determine size of integer value in bytes.
421 virtual unsigned SizeOf(const Dwarf &DW, unsigned Form) const {
423 case DW_FORM_flag: // Fall thru
424 case DW_FORM_ref1: // Fall thru
425 case DW_FORM_data1: return sizeof(int8_t);
426 case DW_FORM_ref2: // Fall thru
427 case DW_FORM_data2: return sizeof(int16_t);
428 case DW_FORM_ref4: // Fall thru
429 case DW_FORM_data4: return sizeof(int32_t);
430 case DW_FORM_ref8: // Fall thru
431 case DW_FORM_data8: return sizeof(int64_t);
432 case DW_FORM_udata: return SizeULEB128(Integer);
433 case DW_FORM_sdata: return SizeSLEB128(Integer);
434 default: assert(0 && "DIE Value form not supported yet"); break;
439 /// Profile - Used to gather unique data for the value folding set.
441 virtual void Profile(FoldingSetNodeID &ID) {
442 ID.AddInteger(isInteger);
443 ID.AddInteger(Integer);
447 virtual void print(std::ostream &O) {
448 O << "Int: " << (int64_t)Integer
449 << " 0x" << std::hex << Integer << std::dec;
454 //===----------------------------------------------------------------------===//
455 /// DIEString - A string value DIE.
457 class DIEString : public DIEValue {
459 const std::string String;
461 DIEString(const std::string &S) : DIEValue(isString), String(S) {}
463 // Implement isa/cast/dyncast.
464 static bool classof(const DIEString *) { return true; }
465 static bool classof(const DIEValue *S) { return S->Type == isString; }
467 /// EmitValue - Emit string value.
469 virtual void EmitValue(const Dwarf &DW, unsigned Form) const;
471 /// SizeOf - Determine size of string value in bytes.
473 virtual unsigned SizeOf(const Dwarf &DW, unsigned Form) const {
474 return String.size() + sizeof(char); // sizeof('\0');
477 /// Profile - Used to gather unique data for the value folding set.
479 virtual void Profile(FoldingSetNodeID &ID) {
480 ID.AddInteger(isString);
481 ID.AddString(String);
485 virtual void print(std::ostream &O) {
486 O << "Str: \"" << String << "\"";
491 //===----------------------------------------------------------------------===//
492 /// DIEDwarfLabel - A Dwarf internal label expression DIE.
494 class DIEDwarfLabel : public DIEValue {
499 DIEDwarfLabel(const DWLabel &L) : DIEValue(isLabel), Label(L) {}
501 // Implement isa/cast/dyncast.
502 static bool classof(const DIEDwarfLabel *) { return true; }
503 static bool classof(const DIEValue *L) { return L->Type == isLabel; }
505 /// EmitValue - Emit label value.
507 virtual void EmitValue(const Dwarf &DW, unsigned Form) const;
509 /// SizeOf - Determine size of label value in bytes.
511 virtual unsigned SizeOf(const Dwarf &DW, unsigned Form) const;
513 /// Profile - Used to gather unique data for the value folding set.
515 virtual void Profile(FoldingSetNodeID &ID) {
516 ID.AddInteger(isLabel);
521 virtual void print(std::ostream &O) {
529 //===----------------------------------------------------------------------===//
530 /// DIEObjectLabel - A label to an object in code or data.
532 class DIEObjectLabel : public DIEValue {
534 const std::string Label;
536 DIEObjectLabel(const std::string &L) : DIEValue(isAsIsLabel), Label(L) {}
538 // Implement isa/cast/dyncast.
539 static bool classof(const DIEObjectLabel *) { return true; }
540 static bool classof(const DIEValue *L) { return L->Type == isAsIsLabel; }
542 /// EmitValue - Emit label value.
544 virtual void EmitValue(const Dwarf &DW, unsigned Form) const;
546 /// SizeOf - Determine size of label value in bytes.
548 virtual unsigned SizeOf(const Dwarf &DW, unsigned Form) const;
550 /// Profile - Used to gather unique data for the value folding set.
552 virtual void Profile(FoldingSetNodeID &ID) {
553 ID.AddInteger(isAsIsLabel);
558 virtual void print(std::ostream &O) {
559 O << "Obj: " << Label;
564 //===----------------------------------------------------------------------===//
565 /// DIEDelta - A simple label difference DIE.
567 class DIEDelta : public DIEValue {
569 const DWLabel LabelHi;
570 const DWLabel LabelLo;
572 DIEDelta(const DWLabel &Hi, const DWLabel &Lo)
573 : DIEValue(isDelta), LabelHi(Hi), LabelLo(Lo) {}
575 // Implement isa/cast/dyncast.
576 static bool classof(const DIEDelta *) { return true; }
577 static bool classof(const DIEValue *D) { return D->Type == isDelta; }
579 /// EmitValue - Emit delta value.
581 virtual void EmitValue(const Dwarf &DW, unsigned Form) const;
583 /// SizeOf - Determine size of delta value in bytes.
585 virtual unsigned SizeOf(const Dwarf &DW, unsigned Form) const;
587 /// Profile - Used to gather unique data for the value folding set.
589 virtual void Profile(FoldingSetNodeID &ID){
590 ID.AddInteger(isDelta);
596 virtual void print(std::ostream &O) {
605 //===----------------------------------------------------------------------===//
606 /// DIEntry - A pointer to another debug information entry. An instance of this
607 /// class can also be used as a proxy for a debug information entry not yet
608 /// defined (ie. types.)
609 class DIEntry : public DIEValue {
613 DIEntry(DIE *E) : DIEValue(isEntry), Entry(E) {}
615 // Implement isa/cast/dyncast.
616 static bool classof(const DIEntry *) { return true; }
617 static bool classof(const DIEValue *E) { return E->Type == isEntry; }
619 /// EmitValue - Emit debug information entry offset.
621 virtual void EmitValue(const Dwarf &DW, unsigned Form) const;
623 /// SizeOf - Determine size of debug information entry in bytes.
625 virtual unsigned SizeOf(const Dwarf &DW, unsigned Form) const {
626 return sizeof(int32_t);
629 /// Profile - Used to gather unique data for the value folding set.
631 virtual void Profile(FoldingSetNodeID &ID) {
632 ID.AddInteger(isEntry);
635 ID.AddPointer(Entry);
642 virtual void print(std::ostream &O) {
643 O << "Die: 0x" << std::hex << (intptr_t)Entry << std::dec;
648 //===----------------------------------------------------------------------===//
649 /// DIEBlock - A block of values. Primarily used for location expressions.
651 class DIEBlock : public DIEValue, public DIE {
653 unsigned Size; // Size in bytes excluding size header.
663 // Implement isa/cast/dyncast.
664 static bool classof(const DIEBlock *) { return true; }
665 static bool classof(const DIEValue *E) { return E->Type == isBlock; }
667 /// ComputeSize - calculate the size of the block.
669 unsigned ComputeSize(Dwarf &DW);
671 /// BestForm - Choose the best form for data.
673 unsigned BestForm() const {
674 if ((unsigned char)Size == Size) return DW_FORM_block1;
675 if ((unsigned short)Size == Size) return DW_FORM_block2;
676 if ((unsigned int)Size == Size) return DW_FORM_block4;
677 return DW_FORM_block;
680 /// EmitValue - Emit block data.
682 virtual void EmitValue(const Dwarf &DW, unsigned Form) const;
684 /// SizeOf - Determine size of block data in bytes.
686 virtual unsigned SizeOf(const Dwarf &DW, unsigned Form) const;
689 /// Profile - Used to gather unique data for the value folding set.
691 virtual void Profile(FoldingSetNodeID &ID) {
692 ID.AddInteger(isBlock);
697 virtual void print(std::ostream &O) {
704 //===----------------------------------------------------------------------===//
705 /// CompileUnit - This dwarf writer support class manages information associate
706 /// with a source file.
709 /// Desc - Compile unit debug descriptor.
711 CompileUnitDesc *Desc;
713 /// ID - File identifier for source.
717 /// Die - Compile unit debug information entry.
721 /// DescToDieMap - Tracks the mapping of unit level debug informaton
722 /// descriptors to debug information entries.
723 std::map<DebugInfoDesc *, DIE *> DescToDieMap;
725 /// DescToDIEntryMap - Tracks the mapping of unit level debug informaton
726 /// descriptors to debug information entries using a DIEntry proxy.
727 std::map<DebugInfoDesc *, DIEntry *> DescToDIEntryMap;
729 /// Globals - A map of globally visible named entities for this unit.
731 std::map<std::string, DIE *> Globals;
733 /// DiesSet - Used to uniquely define dies within the compile unit.
735 FoldingSet<DIE> DiesSet;
737 /// Dies - List of all dies in the compile unit.
739 std::vector<DIE *> Dies;
742 CompileUnit(CompileUnitDesc *CUD, unsigned I, DIE *D)
749 , DiesSet(InitDiesSetSize)
756 for (unsigned i = 0, N = Dies.size(); i < N; ++i)
761 CompileUnitDesc *getDesc() const { return Desc; }
762 unsigned getID() const { return ID; }
763 DIE* getDie() const { return Die; }
764 std::map<std::string, DIE *> &getGlobals() { return Globals; }
766 /// hasContent - Return true if this compile unit has something to write out.
768 bool hasContent() const {
769 return !Die->getChildren().empty();
772 /// AddGlobal - Add a new global entity to the compile unit.
774 void AddGlobal(const std::string &Name, DIE *Die) {
778 /// getDieMapSlotFor - Returns the debug information entry map slot for the
779 /// specified debug descriptor.
780 DIE *&getDieMapSlotFor(DebugInfoDesc *DD) {
781 return DescToDieMap[DD];
784 /// getDIEntrySlotFor - Returns the debug information entry proxy slot for the
785 /// specified debug descriptor.
786 DIEntry *&getDIEntrySlotFor(DebugInfoDesc *DD) {
787 return DescToDIEntryMap[DD];
790 /// AddDie - Adds or interns the DIE to the compile unit.
792 DIE *AddDie(DIE &Buffer) {
796 DIE *Die = DiesSet.FindNodeOrInsertPos(ID, Where);
799 Die = new DIE(Buffer);
800 DiesSet.InsertNode(Die, Where);
801 this->Die->AddChild(Die);
809 //===----------------------------------------------------------------------===//
810 /// Dwarf - Emits Dwarf debug and exception handling directives.
816 //===--------------------------------------------------------------------===//
817 // Core attributes used by the Dwarf writer.
821 /// O - Stream to .s file.
825 /// Asm - Target of Dwarf emission.
829 /// TAI - Target Asm Printer.
830 const TargetAsmInfo *TAI;
832 /// TD - Target data.
833 const TargetData *TD;
835 /// RI - Register Information.
836 const MRegisterInfo *RI;
838 /// M - Current module.
842 /// MF - Current machine function.
846 /// DebugInfo - Collected debug information.
848 MachineDebugInfo *DebugInfo;
850 /// didInitial - Flag to indicate if initial emission has been done.
854 /// shouldEmit - Flag to indicate if debug information should be emitted.
858 /// SubprogramCount - The running count of functions being compiled.
860 unsigned SubprogramCount;
862 //===--------------------------------------------------------------------===//
863 // Attributes used to construct specific Dwarf sections.
866 /// CompileUnits - All the compile units involved in this build. The index
867 /// of each entry in this vector corresponds to the sources in DebugInfo.
868 std::vector<CompileUnit *> CompileUnits;
870 /// AbbreviationsSet - Used to uniquely define abbreviations.
872 FoldingSet<DIEAbbrev> AbbreviationsSet;
874 /// Abbreviations - A list of all the unique abbreviations in use.
876 std::vector<DIEAbbrev *> Abbreviations;
878 /// ValuesSet - Used to uniquely define values.
880 FoldingSet<DIEValue> ValuesSet;
882 /// Values - A list of all the unique values in use.
884 std::vector<DIEValue *> Values;
886 /// StringPool - A UniqueVector of strings used by indirect references.
888 UniqueVector<std::string> StringPool;
890 /// UnitMap - Map debug information descriptor to compile unit.
892 std::map<DebugInfoDesc *, CompileUnit *> DescToUnitMap;
894 /// SectionMap - Provides a unique id per text section.
896 UniqueVector<std::string> SectionMap;
898 /// SectionSourceLines - Tracks line numbers per text section.
900 std::vector<std::vector<SourceLineInfo> > SectionSourceLines;
905 //===--------------------------------------------------------------------===//
906 // Emission and print routines
909 /// PrintHex - Print a value as a hexidecimal value.
911 void PrintHex(int Value) const {
912 O << "0x" << std::hex << Value << std::dec;
915 /// EOL - Print a newline character to asm stream. If a comment is present
916 /// then it will be printed first. Comments should not contain '\n'.
917 void EOL(const std::string &Comment) const {
918 if (DwarfVerbose && !Comment.empty()) {
920 << TAI->getCommentString()
927 /// EmitAlign - Print a align directive.
929 void EmitAlign(unsigned Alignment) const {
930 O << TAI->getAlignDirective() << Alignment << "\n";
933 /// EmitULEB128Bytes - Emit an assembler byte data directive to compose an
934 /// unsigned leb128 value.
935 void EmitULEB128Bytes(unsigned Value) const {
936 if (TAI->hasLEB128()) {
940 O << TAI->getData8bitsDirective();
941 PrintULEB128(O, Value);
945 /// EmitSLEB128Bytes - print an assembler byte data directive to compose a
946 /// signed leb128 value.
947 void EmitSLEB128Bytes(int Value) const {
948 if (TAI->hasLEB128()) {
952 O << TAI->getData8bitsDirective();
953 PrintSLEB128(O, Value);
957 /// EmitInt8 - Emit a byte directive and value.
959 void EmitInt8(int Value) const {
960 O << TAI->getData8bitsDirective();
961 PrintHex(Value & 0xFF);
964 /// EmitInt16 - Emit a short directive and value.
966 void EmitInt16(int Value) const {
967 O << TAI->getData16bitsDirective();
968 PrintHex(Value & 0xFFFF);
971 /// EmitInt32 - Emit a long directive and value.
973 void EmitInt32(int Value) const {
974 O << TAI->getData32bitsDirective();
978 /// EmitInt64 - Emit a long long directive and value.
980 void EmitInt64(uint64_t Value) const {
981 if (TAI->getData64bitsDirective()) {
982 O << TAI->getData64bitsDirective();
985 if (TD->isBigEndian()) {
986 EmitInt32(unsigned(Value >> 32)); O << "\n";
987 EmitInt32(unsigned(Value));
989 EmitInt32(unsigned(Value)); O << "\n";
990 EmitInt32(unsigned(Value >> 32));
995 /// EmitString - Emit a string with quotes and a null terminator.
996 /// Special characters are emitted properly.
997 /// \literal (Eg. '\t') \endliteral
998 void EmitString(const std::string &String) const {
999 O << TAI->getAsciiDirective()
1001 for (unsigned i = 0, N = String.size(); i < N; ++i) {
1002 unsigned char C = String[i];
1004 if (!isascii(C) || iscntrl(C)) {
1006 case '\b': O << "\\b"; break;
1007 case '\f': O << "\\f"; break;
1008 case '\n': O << "\\n"; break;
1009 case '\r': O << "\\r"; break;
1010 case '\t': O << "\\t"; break;
1013 O << char('0' + ((C >> 6) & 7));
1014 O << char('0' + ((C >> 3) & 7));
1015 O << char('0' + ((C >> 0) & 7));
1018 } else if (C == '\"') {
1020 } else if (C == '\'') {
1029 /// PrintLabelName - Print label name in form used by Dwarf writer.
1031 void PrintLabelName(DWLabel Label) const {
1032 PrintLabelName(Label.Tag, Label.Number);
1034 void PrintLabelName(const char *Tag, unsigned Number) const {
1035 O << TAI->getPrivateGlobalPrefix()
1038 if (Number) O << Number;
1041 /// EmitLabel - Emit location label for internal use by Dwarf.
1043 void EmitLabel(DWLabel Label) const {
1044 EmitLabel(Label.Tag, Label.Number);
1046 void EmitLabel(const char *Tag, unsigned Number) const {
1047 PrintLabelName(Tag, Number);
1051 /// EmitReference - Emit a reference to a label.
1053 void EmitReference(DWLabel Label) const {
1054 EmitReference(Label.Tag, Label.Number);
1056 void EmitReference(const char *Tag, unsigned Number) const {
1057 if (TAI->getAddressSize() == 4)
1058 O << TAI->getData32bitsDirective();
1060 O << TAI->getData64bitsDirective();
1062 PrintLabelName(Tag, Number);
1064 void EmitReference(const std::string &Name) const {
1065 if (TAI->getAddressSize() == 4)
1066 O << TAI->getData32bitsDirective();
1068 O << TAI->getData64bitsDirective();
1073 /// EmitDifference - Emit the difference between two labels. Some
1074 /// assemblers do not behave with absolute expressions with data directives,
1075 /// so there is an option (needsSet) to use an intermediary set expression.
1076 void EmitDifference(DWLabel LabelHi, DWLabel LabelLo) const {
1077 EmitDifference(LabelHi.Tag, LabelHi.Number, LabelLo.Tag, LabelLo.Number);
1079 void EmitDifference(const char *TagHi, unsigned NumberHi,
1080 const char *TagLo, unsigned NumberLo) const {
1081 if (TAI->needsSet()) {
1082 static unsigned SetCounter = 0;
1085 PrintLabelName("set", SetCounter);
1087 PrintLabelName(TagHi, NumberHi);
1089 PrintLabelName(TagLo, NumberLo);
1092 if (TAI->getAddressSize() == sizeof(int32_t))
1093 O << TAI->getData32bitsDirective();
1095 O << TAI->getData64bitsDirective();
1097 PrintLabelName("set", SetCounter);
1101 if (TAI->getAddressSize() == sizeof(int32_t))
1102 O << TAI->getData32bitsDirective();
1104 O << TAI->getData64bitsDirective();
1106 PrintLabelName(TagHi, NumberHi);
1108 PrintLabelName(TagLo, NumberLo);
1112 /// AssignAbbrevNumber - Define a unique number for the abbreviation.
1114 void AssignAbbrevNumber(DIEAbbrev &Abbrev) {
1115 // Profile the node so that we can make it unique.
1116 FoldingSetNodeID ID;
1119 // Check the set for priors.
1120 DIEAbbrev *InSet = AbbreviationsSet.GetOrInsertNode(&Abbrev);
1122 // If it's newly added.
1123 if (InSet == &Abbrev) {
1124 // Add to abbreviation list.
1125 Abbreviations.push_back(&Abbrev);
1126 // Assign the vector position + 1 as its number.
1127 Abbrev.setNumber(Abbreviations.size());
1129 // Assign existing abbreviation number.
1130 Abbrev.setNumber(InSet->getNumber());
1134 /// NewString - Add a string to the constant pool and returns a label.
1136 DWLabel NewString(const std::string &String) {
1137 unsigned StringID = StringPool.insert(String);
1138 return DWLabel("string", StringID);
1141 /// NewDIEntry - Creates a new DIEntry to be a proxy for a debug information
1143 DIEntry *NewDIEntry(DIE *Entry = NULL) {
1147 FoldingSetNodeID ID;
1148 ID.AddPointer(Entry);
1150 Value = static_cast<DIEntry *>(ValuesSet.FindNodeOrInsertPos(ID, Where));
1152 if (Value) return Value;
1154 Value = new DIEntry(Entry);
1155 ValuesSet.InsertNode(Value, Where);
1157 Value = new DIEntry(Entry);
1160 Values.push_back(Value);
1164 /// SetDIEntry - Set a DIEntry once the debug information entry is defined.
1166 void SetDIEntry(DIEntry *Value, DIE *Entry) {
1167 Value->Entry = Entry;
1168 // Add to values set if not already there. If it is, we merely have a
1169 // duplicate in the values list (no harm.)
1170 ValuesSet.GetOrInsertNode(Value);
1173 /// AddUInt - Add an unsigned integer attribute data and value.
1175 void AddUInt(DIE *Die, unsigned Attribute, unsigned Form, uint64_t Integer) {
1176 if (!Form) Form = DIEInteger::BestForm(false, Integer);
1178 FoldingSetNodeID ID;
1179 ID.AddInteger(Integer);
1181 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
1183 Value = new DIEInteger(Integer);
1184 ValuesSet.InsertNode(Value, Where);
1185 Values.push_back(Value);
1188 Die->AddValue(Attribute, Form, Value);
1191 /// AddSInt - Add an signed integer attribute data and value.
1193 void AddSInt(DIE *Die, unsigned Attribute, unsigned Form, int64_t Integer) {
1194 if (!Form) Form = DIEInteger::BestForm(true, Integer);
1196 FoldingSetNodeID ID;
1197 ID.AddInteger((uint64_t)Integer);
1199 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
1201 Value = new DIEInteger(Integer);
1202 ValuesSet.InsertNode(Value, Where);
1203 Values.push_back(Value);
1206 Die->AddValue(Attribute, Form, Value);
1209 /// AddString - Add a std::string attribute data and value.
1211 void AddString(DIE *Die, unsigned Attribute, unsigned Form,
1212 const std::string &String) {
1213 FoldingSetNodeID ID;
1214 ID.AddString(String);
1216 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
1218 Value = new DIEString(String);
1219 ValuesSet.InsertNode(Value, Where);
1220 Values.push_back(Value);
1223 Die->AddValue(Attribute, Form, Value);
1226 /// AddLabel - Add a Dwarf label attribute data and value.
1228 void AddLabel(DIE *Die, unsigned Attribute, unsigned Form,
1229 const DWLabel &Label) {
1230 FoldingSetNodeID ID;
1233 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
1235 Value = new DIEDwarfLabel(Label);
1236 ValuesSet.InsertNode(Value, Where);
1237 Values.push_back(Value);
1240 Die->AddValue(Attribute, Form, Value);
1243 /// AddObjectLabel - Add an non-Dwarf label attribute data and value.
1245 void AddObjectLabel(DIE *Die, unsigned Attribute, unsigned Form,
1246 const std::string &Label) {
1247 FoldingSetNodeID ID;
1248 ID.AddString(Label);
1250 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
1252 Value = new DIEObjectLabel(Label);
1253 ValuesSet.InsertNode(Value, Where);
1254 Values.push_back(Value);
1257 Die->AddValue(Attribute, Form, Value);
1260 /// AddDelta - Add a label delta attribute data and value.
1262 void AddDelta(DIE *Die, unsigned Attribute, unsigned Form,
1263 const DWLabel &Hi, const DWLabel &Lo) {
1264 FoldingSetNodeID ID;
1268 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
1270 Value = new DIEDelta(Hi, Lo);
1271 ValuesSet.InsertNode(Value, Where);
1272 Values.push_back(Value);
1275 Die->AddValue(Attribute, Form, Value);
1278 /// AddDIEntry - Add a DIE attribute data and value.
1280 void AddDIEntry(DIE *Die, unsigned Attribute, unsigned Form, DIE *Entry) {
1281 Die->AddValue(Attribute, Form, NewDIEntry(Entry));
1284 /// AddBlock - Add block data.
1286 void AddBlock(DIE *Die, unsigned Attribute, unsigned Form, DIEBlock *Block) {
1287 Block->ComputeSize(*this);
1288 FoldingSetNodeID ID;
1291 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
1294 ValuesSet.InsertNode(Value, Where);
1295 Values.push_back(Value);
1300 Die->AddValue(Attribute, Block->BestForm(), Value);
1305 /// AddSourceLine - Add location information to specified debug information
1307 void AddSourceLine(DIE *Die, CompileUnitDesc *File, unsigned Line) {
1309 CompileUnit *FileUnit = FindCompileUnit(File);
1310 unsigned FileID = FileUnit->getID();
1311 AddUInt(Die, DW_AT_decl_file, 0, FileID);
1312 AddUInt(Die, DW_AT_decl_line, 0, Line);
1316 /// AddAddress - Add an address attribute to a die based on the location
1318 void AddAddress(DIE *Die, unsigned Attribute,
1319 const MachineLocation &Location) {
1320 unsigned Reg = RI->getDwarfRegNum(Location.getRegister());
1321 DIEBlock *Block = new DIEBlock();
1323 if (Location.isRegister()) {
1325 AddUInt(Block, 0, DW_FORM_data1, DW_OP_reg0 + Reg);
1327 AddUInt(Block, 0, DW_FORM_data1, DW_OP_regx);
1328 AddUInt(Block, 0, DW_FORM_udata, Reg);
1332 AddUInt(Block, 0, DW_FORM_data1, DW_OP_breg0 + Reg);
1334 AddUInt(Block, 0, DW_FORM_data1, DW_OP_bregx);
1335 AddUInt(Block, 0, DW_FORM_udata, Reg);
1337 AddUInt(Block, 0, DW_FORM_sdata, Location.getOffset());
1340 AddBlock(Die, Attribute, 0, Block);
1343 /// AddBasicType - Add a new basic type attribute to the specified entity.
1345 void AddBasicType(DIE *Entity, CompileUnit *Unit,
1346 const std::string &Name,
1347 unsigned Encoding, unsigned Size) {
1348 DIE *Die = ConstructBasicType(Unit, Name, Encoding, Size);
1349 AddDIEntry(Entity, DW_AT_type, DW_FORM_ref4, Die);
1352 /// ConstructBasicType - Construct a new basic type.
1354 DIE *ConstructBasicType(CompileUnit *Unit,
1355 const std::string &Name,
1356 unsigned Encoding, unsigned Size) {
1357 DIE Buffer(DW_TAG_base_type);
1358 AddUInt(&Buffer, DW_AT_byte_size, 0, Size);
1359 AddUInt(&Buffer, DW_AT_encoding, DW_FORM_data1, Encoding);
1360 if (!Name.empty()) AddString(&Buffer, DW_AT_name, DW_FORM_string, Name);
1361 return Unit->AddDie(Buffer);
1364 /// AddPointerType - Add a new pointer type attribute to the specified entity.
1366 void AddPointerType(DIE *Entity, CompileUnit *Unit, const std::string &Name) {
1367 DIE *Die = ConstructPointerType(Unit, Name);
1368 AddDIEntry(Entity, DW_AT_type, DW_FORM_ref4, Die);
1371 /// ConstructPointerType - Construct a new pointer type.
1373 DIE *ConstructPointerType(CompileUnit *Unit, const std::string &Name) {
1374 DIE Buffer(DW_TAG_pointer_type);
1375 AddUInt(&Buffer, DW_AT_byte_size, 0, TAI->getAddressSize());
1376 if (!Name.empty()) AddString(&Buffer, DW_AT_name, DW_FORM_string, Name);
1377 return Unit->AddDie(Buffer);
1380 /// AddType - Add a new type attribute to the specified entity.
1382 void AddType(DIE *Entity, TypeDesc *TyDesc, CompileUnit *Unit) {
1384 AddBasicType(Entity, Unit, "", DW_ATE_signed, 4);
1386 // Check for pre-existence.
1387 DIEntry *&Slot = Unit->getDIEntrySlotFor(TyDesc);
1389 // If it exists then use the existing value.
1391 Entity->AddValue(DW_AT_type, DW_FORM_ref4, Slot);
1395 if (SubprogramDesc *SubprogramTy = dyn_cast<SubprogramDesc>(TyDesc)) {
1396 // FIXME - Not sure why programs and variables are coming through here.
1397 // Short cut for handling subprogram types (not really a TyDesc.)
1398 AddPointerType(Entity, Unit, SubprogramTy->getName());
1399 } else if (GlobalVariableDesc *GlobalTy =
1400 dyn_cast<GlobalVariableDesc>(TyDesc)) {
1401 // FIXME - Not sure why programs and variables are coming through here.
1402 // Short cut for handling global variable types (not really a TyDesc.)
1403 AddPointerType(Entity, Unit, GlobalTy->getName());
1406 Slot = NewDIEntry();
1409 DIE Buffer(DW_TAG_base_type);
1410 ConstructType(Buffer, TyDesc, Unit);
1412 // Add debug information entry to entity and unit.
1413 DIE *Die = Unit->AddDie(Buffer);
1414 SetDIEntry(Slot, Die);
1415 Entity->AddValue(DW_AT_type, DW_FORM_ref4, Slot);
1420 /// ConstructType - Adds all the required attributes to the type.
1422 void ConstructType(DIE &Buffer, TypeDesc *TyDesc, CompileUnit *Unit) {
1423 // Get core information.
1424 const std::string &Name = TyDesc->getName();
1425 uint64_t Size = TyDesc->getSize() >> 3;
1427 if (BasicTypeDesc *BasicTy = dyn_cast<BasicTypeDesc>(TyDesc)) {
1428 // Fundamental types like int, float, bool
1429 Buffer.setTag(DW_TAG_base_type);
1430 AddUInt(&Buffer, DW_AT_encoding, DW_FORM_data1, BasicTy->getEncoding());
1431 } else if (DerivedTypeDesc *DerivedTy = dyn_cast<DerivedTypeDesc>(TyDesc)) {
1432 // Pointers, tyepdefs et al.
1433 Buffer.setTag(DerivedTy->getTag());
1434 // Map to main type, void will not have a type.
1435 if (TypeDesc *FromTy = DerivedTy->getFromType())
1436 AddType(&Buffer, FromTy, Unit);
1437 } else if (CompositeTypeDesc *CompTy = dyn_cast<CompositeTypeDesc>(TyDesc)){
1439 unsigned Tag = CompTy->getTag();
1441 // Set tag accordingly.
1442 if (Tag == DW_TAG_vector_type)
1443 Buffer.setTag(DW_TAG_array_type);
1447 std::vector<DebugInfoDesc *> &Elements = CompTy->getElements();
1450 case DW_TAG_vector_type:
1451 AddUInt(&Buffer, DW_AT_GNU_vector, DW_FORM_flag, 1);
1453 case DW_TAG_array_type: {
1454 // Add element type.
1455 if (TypeDesc *FromTy = CompTy->getFromType())
1456 AddType(&Buffer, FromTy, Unit);
1458 // Don't emit size attribute.
1461 // Construct an anonymous type for index type.
1462 DIE *IndexTy = ConstructBasicType(Unit, "", DW_ATE_signed, 4);
1464 // Add subranges to array type.
1465 for(unsigned i = 0, N = Elements.size(); i < N; ++i) {
1466 SubrangeDesc *SRD = cast<SubrangeDesc>(Elements[i]);
1467 int64_t Lo = SRD->getLo();
1468 int64_t Hi = SRD->getHi();
1469 DIE *Subrange = new DIE(DW_TAG_subrange_type);
1471 // If a range is available.
1473 AddDIEntry(Subrange, DW_AT_type, DW_FORM_ref4, IndexTy);
1474 // Only add low if non-zero.
1475 if (Lo) AddSInt(Subrange, DW_AT_lower_bound, 0, Lo);
1476 AddSInt(Subrange, DW_AT_upper_bound, 0, Hi);
1479 Buffer.AddChild(Subrange);
1483 case DW_TAG_structure_type:
1484 case DW_TAG_union_type: {
1485 // Add elements to structure type.
1486 for(unsigned i = 0, N = Elements.size(); i < N; ++i) {
1487 DebugInfoDesc *Element = Elements[i];
1489 if (DerivedTypeDesc *MemberDesc = dyn_cast<DerivedTypeDesc>(Element)){
1490 // Add field or base class.
1492 unsigned Tag = MemberDesc->getTag();
1494 // Extract the basic information.
1495 const std::string &Name = MemberDesc->getName();
1496 uint64_t Size = MemberDesc->getSize();
1497 uint64_t Align = MemberDesc->getAlign();
1498 uint64_t Offset = MemberDesc->getOffset();
1500 // Construct member debug information entry.
1501 DIE *Member = new DIE(Tag);
1503 // Add name if not "".
1505 AddString(Member, DW_AT_name, DW_FORM_string, Name);
1506 // Add location if available.
1507 AddSourceLine(Member, MemberDesc->getFile(), MemberDesc->getLine());
1509 // Most of the time the field info is the same as the members.
1510 uint64_t FieldSize = Size;
1511 uint64_t FieldAlign = Align;
1512 uint64_t FieldOffset = Offset;
1514 if (TypeDesc *FromTy = MemberDesc->getFromType()) {
1515 AddType(Member, FromTy, Unit);
1516 FieldSize = FromTy->getSize();
1517 FieldAlign = FromTy->getSize();
1520 // Unless we have a bit field.
1521 if (Tag == DW_TAG_member && FieldSize != Size) {
1522 // Construct the alignment mask.
1523 uint64_t AlignMask = ~(FieldAlign - 1);
1524 // Determine the high bit + 1 of the declared size.
1525 uint64_t HiMark = (Offset + FieldSize) & AlignMask;
1526 // Work backwards to determine the base offset of the field.
1527 FieldOffset = HiMark - FieldSize;
1528 // Now normalize offset to the field.
1529 Offset -= FieldOffset;
1531 // Maybe we need to work from the other end.
1532 if (TD->isLittleEndian()) Offset = FieldSize - (Offset + Size);
1534 // Add size and offset.
1535 AddUInt(Member, DW_AT_byte_size, 0, FieldSize >> 3);
1536 AddUInt(Member, DW_AT_bit_size, 0, Size);
1537 AddUInt(Member, DW_AT_bit_offset, 0, Offset);
1540 // Add computation for offset.
1541 DIEBlock *Block = new DIEBlock();
1542 AddUInt(Block, 0, DW_FORM_data1, DW_OP_plus_uconst);
1543 AddUInt(Block, 0, DW_FORM_udata, FieldOffset >> 3);
1544 AddBlock(Member, DW_AT_data_member_location, 0, Block);
1546 // Add accessibility (public default unless is base class.
1547 if (MemberDesc->isProtected()) {
1548 AddUInt(Member, DW_AT_accessibility, 0, DW_ACCESS_protected);
1549 } else if (MemberDesc->isPrivate()) {
1550 AddUInt(Member, DW_AT_accessibility, 0, DW_ACCESS_private);
1551 } else if (Tag == DW_TAG_inheritance) {
1552 AddUInt(Member, DW_AT_accessibility, 0, DW_ACCESS_public);
1555 Buffer.AddChild(Member);
1556 } else if (GlobalVariableDesc *StaticDesc =
1557 dyn_cast<GlobalVariableDesc>(Element)) {
1558 // Add static member.
1560 // Construct member debug information entry.
1561 DIE *Static = new DIE(DW_TAG_variable);
1563 // Add name and mangled name.
1564 const std::string &Name = StaticDesc->getDisplayName();
1565 const std::string &MangledName = StaticDesc->getName();
1566 AddString(Static, DW_AT_name, DW_FORM_string, Name);
1567 AddString(Static, DW_AT_MIPS_linkage_name, DW_FORM_string,
1571 AddSourceLine(Static, StaticDesc->getFile(), StaticDesc->getLine());
1574 if (TypeDesc *StaticTy = StaticDesc->getType())
1575 AddType(Static, StaticTy, Unit);
1578 AddUInt(Static, DW_AT_external, DW_FORM_flag, 1);
1579 AddUInt(Static, DW_AT_declaration, DW_FORM_flag, 1);
1581 Buffer.AddChild(Static);
1582 } else if (SubprogramDesc *MethodDesc =
1583 dyn_cast<SubprogramDesc>(Element)) {
1584 // Add member function.
1586 // Construct member debug information entry.
1587 DIE *Method = new DIE(DW_TAG_subprogram);
1589 // Add name and mangled name.
1590 const std::string &Name = MethodDesc->getDisplayName();
1591 const std::string &MangledName = MethodDesc->getName();
1592 bool IsCTor = false;
1595 AddString(Method, DW_AT_name, DW_FORM_string, MangledName);
1596 IsCTor = TyDesc->getName() == MangledName;
1598 AddString(Method, DW_AT_name, DW_FORM_string, Name);
1599 AddString(Method, DW_AT_MIPS_linkage_name, DW_FORM_string,
1604 AddSourceLine(Method, MethodDesc->getFile(), MethodDesc->getLine());
1607 if (CompositeTypeDesc *MethodTy =
1608 dyn_cast_or_null<CompositeTypeDesc>(MethodDesc->getType())) {
1609 // Get argument information.
1610 std::vector<DebugInfoDesc *> &Args = MethodTy->getElements();
1615 AddType(Method, dyn_cast<TypeDesc>(Args[0]), Unit);
1619 for(unsigned i = 1, N = Args.size(); i < N; ++i) {
1620 DIE *Arg = new DIE(DW_TAG_formal_parameter);
1621 AddType(Arg, cast<TypeDesc>(Args[i]), Unit);
1622 AddUInt(Arg, DW_AT_artificial, DW_FORM_flag, 1);
1623 Method->AddChild(Arg);
1628 AddUInt(Method, DW_AT_external, DW_FORM_flag, 1);
1629 AddUInt(Method, DW_AT_declaration, DW_FORM_flag, 1);
1631 Buffer.AddChild(Method);
1636 case DW_TAG_enumeration_type: {
1637 // Add enumerators to enumeration type.
1638 for(unsigned i = 0, N = Elements.size(); i < N; ++i) {
1639 EnumeratorDesc *ED = cast<EnumeratorDesc>(Elements[i]);
1640 const std::string &Name = ED->getName();
1641 int64_t Value = ED->getValue();
1642 DIE *Enumerator = new DIE(DW_TAG_enumerator);
1643 AddString(Enumerator, DW_AT_name, DW_FORM_string, Name);
1644 AddSInt(Enumerator, DW_AT_const_value, DW_FORM_sdata, Value);
1645 Buffer.AddChild(Enumerator);
1650 case DW_TAG_subroutine_type: {
1651 // Add prototype flag.
1652 AddUInt(&Buffer, DW_AT_prototyped, DW_FORM_flag, 1);
1654 AddType(&Buffer, dyn_cast<TypeDesc>(Elements[0]), Unit);
1657 for(unsigned i = 1, N = Elements.size(); i < N; ++i) {
1658 DIE *Arg = new DIE(DW_TAG_formal_parameter);
1659 AddType(Arg, cast<TypeDesc>(Elements[i]), Unit);
1660 Buffer.AddChild(Arg);
1669 // Add size if non-zero (derived types don't have a size.)
1670 if (Size) AddUInt(&Buffer, DW_AT_byte_size, 0, Size);
1671 // Add name if not anonymous or intermediate type.
1672 if (!Name.empty()) AddString(&Buffer, DW_AT_name, DW_FORM_string, Name);
1673 // Add source line info if available.
1674 AddSourceLine(&Buffer, TyDesc->getFile(), TyDesc->getLine());
1677 /// NewCompileUnit - Create new compile unit and it's debug information entry.
1679 CompileUnit *NewCompileUnit(CompileUnitDesc *UnitDesc, unsigned ID) {
1680 // Construct debug information entry.
1681 DIE *Die = new DIE(DW_TAG_compile_unit);
1682 AddDelta(Die, DW_AT_stmt_list, DW_FORM_data4, DWLabel("section_line", 0),
1683 DWLabel("section_line", 0));
1684 AddString(Die, DW_AT_producer, DW_FORM_string, UnitDesc->getProducer());
1685 AddUInt (Die, DW_AT_language, DW_FORM_data1, UnitDesc->getLanguage());
1686 AddString(Die, DW_AT_name, DW_FORM_string, UnitDesc->getFileName());
1687 AddString(Die, DW_AT_comp_dir, DW_FORM_string, UnitDesc->getDirectory());
1689 // Construct compile unit.
1690 CompileUnit *Unit = new CompileUnit(UnitDesc, ID, Die);
1692 // Add Unit to compile unit map.
1693 DescToUnitMap[UnitDesc] = Unit;
1698 /// FindCompileUnit - Get the compile unit for the given descriptor.
1700 CompileUnit *FindCompileUnit(CompileUnitDesc *UnitDesc) {
1702 // FIXME - Using only one compile unit. Needs to me fixed at the FE.
1703 CompileUnit *Unit = CompileUnits[0];
1705 CompileUnit *Unit = DescToUnitMap[UnitDesc];
1707 assert(Unit && "Missing compile unit.");
1711 /// NewGlobalVariable - Add a new global variable DIE.
1713 DIE *NewGlobalVariable(GlobalVariableDesc *GVD) {
1714 // Get the compile unit context.
1715 CompileUnitDesc *UnitDesc =
1716 static_cast<CompileUnitDesc *>(GVD->getContext());
1717 CompileUnit *Unit = FindCompileUnit(UnitDesc);
1719 // Check for pre-existence.
1720 DIE *&Slot = Unit->getDieMapSlotFor(GVD);
1721 if (Slot) return Slot;
1723 // Get the global variable itself.
1724 GlobalVariable *GV = GVD->getGlobalVariable();
1726 const std::string &Name = GVD->hasMangledName() ? GVD->getDisplayName()
1728 const std::string &MangledName = GVD->hasMangledName() ? GVD->getName()
1730 // Create the global's variable DIE.
1731 DIE *VariableDie = new DIE(DW_TAG_variable);
1732 AddString(VariableDie, DW_AT_name, DW_FORM_string, Name);
1733 if (!MangledName.empty()) {
1734 AddString(VariableDie, DW_AT_MIPS_linkage_name, DW_FORM_string,
1737 AddType(VariableDie, GVD->getType(), Unit);
1738 AddUInt(VariableDie, DW_AT_external, DW_FORM_flag, 1);
1740 // Add source line info if available.
1741 AddSourceLine(VariableDie, UnitDesc, GVD->getLine());
1743 // Work up linkage name.
1744 const std::string LinkageName = Asm->getGlobalLinkName(GV);
1747 DIEBlock *Block = new DIEBlock();
1748 AddUInt(Block, 0, DW_FORM_data1, DW_OP_addr);
1749 AddObjectLabel(Block, 0, DW_FORM_udata, LinkageName);
1750 AddBlock(VariableDie, DW_AT_location, 0, Block);
1755 // Add to context owner.
1756 Unit->getDie()->AddChild(VariableDie);
1758 // Expose as global.
1759 // FIXME - need to check external flag.
1760 Unit->AddGlobal(Name, VariableDie);
1765 /// NewSubprogram - Add a new subprogram DIE.
1767 DIE *NewSubprogram(SubprogramDesc *SPD) {
1768 // Get the compile unit context.
1769 CompileUnitDesc *UnitDesc =
1770 static_cast<CompileUnitDesc *>(SPD->getContext());
1771 CompileUnit *Unit = FindCompileUnit(UnitDesc);
1773 // Check for pre-existence.
1774 DIE *&Slot = Unit->getDieMapSlotFor(SPD);
1775 if (Slot) return Slot;
1777 // Gather the details (simplify add attribute code.)
1778 const std::string &Name = SPD->hasMangledName() ? SPD->getDisplayName()
1780 const std::string &MangledName = SPD->hasMangledName() ? SPD->getName()
1782 unsigned IsExternal = SPD->isStatic() ? 0 : 1;
1784 DIE *SubprogramDie = new DIE(DW_TAG_subprogram);
1785 AddString(SubprogramDie, DW_AT_name, DW_FORM_string, Name);
1786 if (!MangledName.empty()) {
1787 AddString(SubprogramDie, DW_AT_MIPS_linkage_name, DW_FORM_string,
1790 if (SPD->getType()) AddType(SubprogramDie, SPD->getType(), Unit);
1791 AddUInt(SubprogramDie, DW_AT_external, DW_FORM_flag, IsExternal);
1792 AddUInt(SubprogramDie, DW_AT_prototyped, DW_FORM_flag, 1);
1794 // Add source line info if available.
1795 AddSourceLine(SubprogramDie, UnitDesc, SPD->getLine());
1798 Slot = SubprogramDie;
1800 // Add to context owner.
1801 Unit->getDie()->AddChild(SubprogramDie);
1803 // Expose as global.
1804 Unit->AddGlobal(Name, SubprogramDie);
1806 return SubprogramDie;
1809 /// NewScopeVariable - Create a new scope variable.
1811 DIE *NewScopeVariable(DebugVariable *DV, CompileUnit *Unit) {
1812 // Get the descriptor.
1813 VariableDesc *VD = DV->getDesc();
1815 // Translate tag to proper Dwarf tag. The result variable is dropped for
1818 switch (VD->getTag()) {
1819 case DW_TAG_return_variable: return NULL;
1820 case DW_TAG_arg_variable: Tag = DW_TAG_formal_parameter; break;
1821 case DW_TAG_auto_variable: // fall thru
1822 default: Tag = DW_TAG_variable; break;
1825 // Define variable debug information entry.
1826 DIE *VariableDie = new DIE(Tag);
1827 AddString(VariableDie, DW_AT_name, DW_FORM_string, VD->getName());
1829 // Add source line info if available.
1830 AddSourceLine(VariableDie, VD->getFile(), VD->getLine());
1832 // Add variable type.
1833 AddType(VariableDie, VD->getType(), Unit);
1835 // Add variable address.
1836 MachineLocation Location;
1837 RI->getLocation(*MF, DV->getFrameIndex(), Location);
1838 AddAddress(VariableDie, DW_AT_location, Location);
1843 /// ConstructScope - Construct the components of a scope.
1845 void ConstructScope(DebugScope *ParentScope,
1846 DIE *ParentDie, CompileUnit *Unit) {
1847 // Add variables to scope.
1848 std::vector<DebugVariable *> &Variables = ParentScope->getVariables();
1849 for (unsigned i = 0, N = Variables.size(); i < N; ++i) {
1850 DIE *VariableDie = NewScopeVariable(Variables[i], Unit);
1851 if (VariableDie) ParentDie->AddChild(VariableDie);
1854 // Add nested scopes.
1855 std::vector<DebugScope *> &Scopes = ParentScope->getScopes();
1856 for (unsigned j = 0, M = Scopes.size(); j < M; ++j) {
1857 // Define the Scope debug information entry.
1858 DebugScope *Scope = Scopes[j];
1859 // FIXME - Ignore inlined functions for the time being.
1860 if (!Scope->getParent()) continue;
1862 unsigned StartID = Scope->getStartLabelID();
1863 unsigned EndID = Scope->getEndLabelID();
1865 // Widen scope if label is discarded.
1866 // FIXME - really need to find a GOOD label if a block is dead.
1867 if (StartID && !DebugInfo->isLabelValid(StartID)) StartID = 0;
1868 if (EndID && !DebugInfo->isLabelValid(EndID)) EndID = 0;
1870 DIE *ScopeDie = new DIE(DW_TAG_lexical_block);
1872 // Add the scope bounds.
1874 AddLabel(ScopeDie, DW_AT_low_pc, DW_FORM_addr,
1875 DWLabel("loc", StartID));
1877 AddLabel(ScopeDie, DW_AT_low_pc, DW_FORM_addr,
1878 DWLabel("func_begin", SubprogramCount));
1881 AddLabel(ScopeDie, DW_AT_high_pc, DW_FORM_addr,
1882 DWLabel("loc", EndID));
1884 AddLabel(ScopeDie, DW_AT_high_pc, DW_FORM_addr,
1885 DWLabel("func_end", SubprogramCount));
1888 // Add the scope contents.
1889 ConstructScope(Scope, ScopeDie, Unit);
1890 ParentDie->AddChild(ScopeDie);
1894 /// ConstructRootScope - Construct the scope for the subprogram.
1896 void ConstructRootScope(DebugScope *RootScope) {
1897 // Exit if there is no root scope.
1898 if (!RootScope) return;
1900 // Get the subprogram debug information entry.
1901 SubprogramDesc *SPD = cast<SubprogramDesc>(RootScope->getDesc());
1903 // Get the compile unit context.
1904 CompileUnitDesc *UnitDesc =
1905 static_cast<CompileUnitDesc *>(SPD->getContext());
1906 CompileUnit *Unit = FindCompileUnit(UnitDesc);
1908 // Get the subprogram die.
1909 DIE *SPDie = Unit->getDieMapSlotFor(SPD);
1910 assert(SPDie && "Missing subprogram descriptor");
1912 // Add the function bounds.
1913 AddLabel(SPDie, DW_AT_low_pc, DW_FORM_addr,
1914 DWLabel("func_begin", SubprogramCount));
1915 AddLabel(SPDie, DW_AT_high_pc, DW_FORM_addr,
1916 DWLabel("func_end", SubprogramCount));
1917 MachineLocation Location(RI->getFrameRegister(*MF));
1918 AddAddress(SPDie, DW_AT_frame_base, Location);
1920 ConstructScope(RootScope, SPDie, Unit);
1923 /// EmitInitial - Emit initial Dwarf declarations. This is necessary for cc
1924 /// tools to recognize the object file contains Dwarf information.
1925 void EmitInitial() {
1926 // Check to see if we already emitted intial headers.
1927 if (didInitial) return;
1930 // Dwarf sections base addresses.
1931 if (TAI->getDwarfRequiresFrameSection()) {
1932 Asm->SwitchToDataSection(TAI->getDwarfFrameSection());
1933 EmitLabel("section_frame", 0);
1935 Asm->SwitchToDataSection(TAI->getDwarfInfoSection());
1936 EmitLabel("section_info", 0);
1937 Asm->SwitchToDataSection(TAI->getDwarfAbbrevSection());
1938 EmitLabel("section_abbrev", 0);
1939 Asm->SwitchToDataSection(TAI->getDwarfARangesSection());
1940 EmitLabel("section_aranges", 0);
1941 Asm->SwitchToDataSection(TAI->getDwarfMacInfoSection());
1942 EmitLabel("section_macinfo", 0);
1943 Asm->SwitchToDataSection(TAI->getDwarfLineSection());
1944 EmitLabel("section_line", 0);
1945 Asm->SwitchToDataSection(TAI->getDwarfLocSection());
1946 EmitLabel("section_loc", 0);
1947 Asm->SwitchToDataSection(TAI->getDwarfPubNamesSection());
1948 EmitLabel("section_pubnames", 0);
1949 Asm->SwitchToDataSection(TAI->getDwarfStrSection());
1950 EmitLabel("section_str", 0);
1951 Asm->SwitchToDataSection(TAI->getDwarfRangesSection());
1952 EmitLabel("section_ranges", 0);
1954 Asm->SwitchToTextSection(TAI->getTextSection());
1955 EmitLabel("text_begin", 0);
1956 Asm->SwitchToDataSection(TAI->getDataSection());
1957 EmitLabel("data_begin", 0);
1959 // Emit common frame information.
1960 EmitInitialDebugFrame();
1963 /// EmitDIE - Recusively Emits a debug information entry.
1965 void EmitDIE(DIE *Die) const {
1966 // Get the abbreviation for this DIE.
1967 unsigned AbbrevNumber = Die->getAbbrevNumber();
1968 const DIEAbbrev *Abbrev = Abbreviations[AbbrevNumber - 1];
1972 // Emit the code (index) for the abbreviation.
1973 EmitULEB128Bytes(AbbrevNumber);
1974 EOL(std::string("Abbrev [" +
1975 utostr(AbbrevNumber) +
1976 "] 0x" + utohexstr(Die->getOffset()) +
1977 ":0x" + utohexstr(Die->getSize()) + " " +
1978 TagString(Abbrev->getTag())));
1980 const std::vector<DIEValue *> &Values = Die->getValues();
1981 const std::vector<DIEAbbrevData> &AbbrevData = Abbrev->getData();
1983 // Emit the DIE attribute values.
1984 for (unsigned i = 0, N = Values.size(); i < N; ++i) {
1985 unsigned Attr = AbbrevData[i].getAttribute();
1986 unsigned Form = AbbrevData[i].getForm();
1987 assert(Form && "Too many attributes for DIE (check abbreviation)");
1990 case DW_AT_sibling: {
1991 EmitInt32(Die->SiblingOffset());
1995 // Emit an attribute using the defined form.
1996 Values[i]->EmitValue(*this, Form);
2001 EOL(AttributeString(Attr));
2004 // Emit the DIE children if any.
2005 if (Abbrev->getChildrenFlag() == DW_CHILDREN_yes) {
2006 const std::vector<DIE *> &Children = Die->getChildren();
2008 for (unsigned j = 0, M = Children.size(); j < M; ++j) {
2009 EmitDIE(Children[j]);
2012 EmitInt8(0); EOL("End Of Children Mark");
2016 /// SizeAndOffsetDie - Compute the size and offset of a DIE.
2018 unsigned SizeAndOffsetDie(DIE *Die, unsigned Offset, bool Last) {
2019 // Get the children.
2020 const std::vector<DIE *> &Children = Die->getChildren();
2022 // If not last sibling and has children then add sibling offset attribute.
2023 if (!Last && !Children.empty()) Die->AddSiblingOffset();
2025 // Record the abbreviation.
2026 AssignAbbrevNumber(Die->getAbbrev());
2028 // Get the abbreviation for this DIE.
2029 unsigned AbbrevNumber = Die->getAbbrevNumber();
2030 const DIEAbbrev *Abbrev = Abbreviations[AbbrevNumber - 1];
2033 Die->setOffset(Offset);
2035 // Start the size with the size of abbreviation code.
2036 Offset += SizeULEB128(AbbrevNumber);
2038 const std::vector<DIEValue *> &Values = Die->getValues();
2039 const std::vector<DIEAbbrevData> &AbbrevData = Abbrev->getData();
2041 // Size the DIE attribute values.
2042 for (unsigned i = 0, N = Values.size(); i < N; ++i) {
2043 // Size attribute value.
2044 Offset += Values[i]->SizeOf(*this, AbbrevData[i].getForm());
2047 // Size the DIE children if any.
2048 if (!Children.empty()) {
2049 assert(Abbrev->getChildrenFlag() == DW_CHILDREN_yes &&
2050 "Children flag not set");
2052 for (unsigned j = 0, M = Children.size(); j < M; ++j) {
2053 Offset = SizeAndOffsetDie(Children[j], Offset, (j + 1) == M);
2056 // End of children marker.
2057 Offset += sizeof(int8_t);
2060 Die->setSize(Offset - Die->getOffset());
2064 /// SizeAndOffsets - Compute the size and offset of all the DIEs.
2066 void SizeAndOffsets() {
2067 // Process each compile unit.
2068 for (unsigned i = 0, N = CompileUnits.size(); i < N; ++i) {
2069 CompileUnit *Unit = CompileUnits[i];
2070 if (Unit->hasContent()) {
2071 // Compute size of compile unit header
2072 unsigned Offset = sizeof(int32_t) + // Length of Compilation Unit Info
2073 sizeof(int16_t) + // DWARF version number
2074 sizeof(int32_t) + // Offset Into Abbrev. Section
2075 sizeof(int8_t); // Pointer Size (in bytes)
2076 SizeAndOffsetDie(Unit->getDie(), Offset, (i + 1) == N);
2081 /// EmitFrameMoves - Emit frame instructions to describe the layout of the
2083 void EmitFrameMoves(const char *BaseLabel, unsigned BaseLabelID,
2084 std::vector<MachineMove *> &Moves) {
2085 for (unsigned i = 0, N = Moves.size(); i < N; ++i) {
2086 MachineMove *Move = Moves[i];
2087 unsigned LabelID = Move->getLabelID();
2089 // Throw out move if the label is invalid.
2090 if (LabelID && !DebugInfo->isLabelValid(LabelID)) continue;
2092 const MachineLocation &Dst = Move->getDestination();
2093 const MachineLocation &Src = Move->getSource();
2095 // Advance row if new location.
2096 if (BaseLabel && LabelID && BaseLabelID != LabelID) {
2097 EmitInt8(DW_CFA_advance_loc4);
2098 EOL("DW_CFA_advance_loc4");
2099 EmitDifference("loc", LabelID, BaseLabel, BaseLabelID);
2102 BaseLabelID = LabelID;
2107 Asm->TM.getFrameInfo()->getStackGrowthDirection() ==
2108 TargetFrameInfo::StackGrowsUp ?
2109 TAI->getAddressSize() : -TAI->getAddressSize();
2111 // If advancing cfa.
2112 if (Dst.isRegister() && Dst.getRegister() == MachineLocation::VirtualFP) {
2113 if (!Src.isRegister()) {
2114 if (Src.getRegister() == MachineLocation::VirtualFP) {
2115 EmitInt8(DW_CFA_def_cfa_offset);
2116 EOL("DW_CFA_def_cfa_offset");
2118 EmitInt8(DW_CFA_def_cfa);
2119 EOL("DW_CFA_def_cfa");
2120 EmitULEB128Bytes(RI->getDwarfRegNum(Src.getRegister()));
2124 int Offset = Src.getOffset() / stackGrowth;
2126 EmitULEB128Bytes(Offset);
2129 assert(0 && "Machine move no supported yet.");
2132 unsigned Reg = RI->getDwarfRegNum(Src.getRegister());
2133 int Offset = Dst.getOffset() / stackGrowth;
2136 EmitInt8(DW_CFA_offset_extended_sf);
2137 EOL("DW_CFA_offset_extended_sf");
2138 EmitULEB128Bytes(Reg);
2140 EmitSLEB128Bytes(Offset);
2142 } else if (Reg < 64) {
2143 EmitInt8(DW_CFA_offset + Reg);
2144 EOL("DW_CFA_offset + Reg");
2145 EmitULEB128Bytes(Offset);
2148 EmitInt8(DW_CFA_offset_extended);
2149 EOL("DW_CFA_offset_extended");
2150 EmitULEB128Bytes(Reg);
2152 EmitULEB128Bytes(Offset);
2159 /// EmitDebugInfo - Emit the debug info section.
2161 void EmitDebugInfo() const {
2162 // Start debug info section.
2163 Asm->SwitchToDataSection(TAI->getDwarfInfoSection());
2165 // Process each compile unit.
2166 for (unsigned i = 0, N = CompileUnits.size(); i < N; ++i) {
2167 CompileUnit *Unit = CompileUnits[i];
2169 if (Unit->hasContent()) {
2170 DIE *Die = Unit->getDie();
2171 // Emit the compile units header.
2172 EmitLabel("info_begin", Unit->getID());
2173 // Emit size of content not including length itself
2174 unsigned ContentSize = Die->getSize() +
2175 sizeof(int16_t) + // DWARF version number
2176 sizeof(int32_t) + // Offset Into Abbrev. Section
2177 sizeof(int8_t); // Pointer Size (in bytes)
2179 EmitInt32(ContentSize); EOL("Length of Compilation Unit Info");
2180 EmitInt16(DWARF_VERSION); EOL("DWARF version number");
2181 EmitDifference("abbrev_begin", 0, "section_abbrev", 0);
2182 EOL("Offset Into Abbrev. Section");
2183 EmitInt8(TAI->getAddressSize()); EOL("Address Size (in bytes)");
2186 EmitLabel("info_end", Unit->getID());
2193 /// EmitAbbreviations - Emit the abbreviation section.
2195 void EmitAbbreviations() const {
2196 // Check to see if it is worth the effort.
2197 if (!Abbreviations.empty()) {
2198 // Start the debug abbrev section.
2199 Asm->SwitchToDataSection(TAI->getDwarfAbbrevSection());
2201 EmitLabel("abbrev_begin", 0);
2203 // For each abbrevation.
2204 for (unsigned i = 0, N = Abbreviations.size(); i < N; ++i) {
2205 // Get abbreviation data
2206 const DIEAbbrev *Abbrev = Abbreviations[i];
2208 // Emit the abbrevations code (base 1 index.)
2209 EmitULEB128Bytes(Abbrev->getNumber()); EOL("Abbreviation Code");
2211 // Emit the abbreviations data.
2212 Abbrev->Emit(*this);
2217 EmitLabel("abbrev_end", 0);
2223 /// EmitDebugLines - Emit source line information.
2225 void EmitDebugLines() const {
2226 // Minimum line delta, thus ranging from -10..(255-10).
2227 const int MinLineDelta = -(DW_LNS_fixed_advance_pc + 1);
2228 // Maximum line delta, thus ranging from -10..(255-10).
2229 const int MaxLineDelta = 255 + MinLineDelta;
2231 // Start the dwarf line section.
2232 Asm->SwitchToDataSection(TAI->getDwarfLineSection());
2234 // Construct the section header.
2236 EmitDifference("line_end", 0, "line_begin", 0);
2237 EOL("Length of Source Line Info");
2238 EmitLabel("line_begin", 0);
2240 EmitInt16(DWARF_VERSION); EOL("DWARF version number");
2242 EmitDifference("line_prolog_end", 0, "line_prolog_begin", 0);
2243 EOL("Prolog Length");
2244 EmitLabel("line_prolog_begin", 0);
2246 EmitInt8(1); EOL("Minimum Instruction Length");
2248 EmitInt8(1); EOL("Default is_stmt_start flag");
2250 EmitInt8(MinLineDelta); EOL("Line Base Value (Special Opcodes)");
2252 EmitInt8(MaxLineDelta); EOL("Line Range Value (Special Opcodes)");
2254 EmitInt8(-MinLineDelta); EOL("Special Opcode Base");
2256 // Line number standard opcode encodings argument count
2257 EmitInt8(0); EOL("DW_LNS_copy arg count");
2258 EmitInt8(1); EOL("DW_LNS_advance_pc arg count");
2259 EmitInt8(1); EOL("DW_LNS_advance_line arg count");
2260 EmitInt8(1); EOL("DW_LNS_set_file arg count");
2261 EmitInt8(1); EOL("DW_LNS_set_column arg count");
2262 EmitInt8(0); EOL("DW_LNS_negate_stmt arg count");
2263 EmitInt8(0); EOL("DW_LNS_set_basic_block arg count");
2264 EmitInt8(0); EOL("DW_LNS_const_add_pc arg count");
2265 EmitInt8(1); EOL("DW_LNS_fixed_advance_pc arg count");
2267 const UniqueVector<std::string> &Directories = DebugInfo->getDirectories();
2268 const UniqueVector<SourceFileInfo>
2269 &SourceFiles = DebugInfo->getSourceFiles();
2271 // Emit directories.
2272 for (unsigned DirectoryID = 1, NDID = Directories.size();
2273 DirectoryID <= NDID; ++DirectoryID) {
2274 EmitString(Directories[DirectoryID]); EOL("Directory");
2276 EmitInt8(0); EOL("End of directories");
2279 for (unsigned SourceID = 1, NSID = SourceFiles.size();
2280 SourceID <= NSID; ++SourceID) {
2281 const SourceFileInfo &SourceFile = SourceFiles[SourceID];
2282 EmitString(SourceFile.getName()); EOL("Source");
2283 EmitULEB128Bytes(SourceFile.getDirectoryID()); EOL("Directory #");
2284 EmitULEB128Bytes(0); EOL("Mod date");
2285 EmitULEB128Bytes(0); EOL("File size");
2287 EmitInt8(0); EOL("End of files");
2289 EmitLabel("line_prolog_end", 0);
2291 // A sequence for each text section.
2292 for (unsigned j = 0, M = SectionSourceLines.size(); j < M; ++j) {
2293 // Isolate current sections line info.
2294 const std::vector<SourceLineInfo> &LineInfos = SectionSourceLines[j];
2298 << TAI->getCommentString() << " "
2300 << SectionMap[j + 1].c_str() << "\n";
2303 // Dwarf assumes we start with first line of first source file.
2304 unsigned Source = 1;
2307 // Construct rows of the address, source, line, column matrix.
2308 for (unsigned i = 0, N = LineInfos.size(); i < N; ++i) {
2309 const SourceLineInfo &LineInfo = LineInfos[i];
2310 unsigned LabelID = LineInfo.getLabelID();
2312 // Source line labels are validated at the MachineDebugInfo level.
2315 unsigned SourceID = LineInfo.getSourceID();
2316 const SourceFileInfo &SourceFile = SourceFiles[SourceID];
2317 unsigned DirectoryID = SourceFile.getDirectoryID();
2319 << TAI->getCommentString() << " "
2320 << Directories[DirectoryID]
2321 << SourceFile.getName() << ":"
2322 << LineInfo.getLine() << "\n";
2325 // Define the line address.
2326 EmitInt8(0); EOL("Extended Op");
2327 EmitInt8(4 + 1); EOL("Op size");
2328 EmitInt8(DW_LNE_set_address); EOL("DW_LNE_set_address");
2329 EmitReference("loc", LabelID); EOL("Location label");
2331 // If change of source, then switch to the new source.
2332 if (Source != LineInfo.getSourceID()) {
2333 Source = LineInfo.getSourceID();
2334 EmitInt8(DW_LNS_set_file); EOL("DW_LNS_set_file");
2335 EmitULEB128Bytes(Source); EOL("New Source");
2338 // If change of line.
2339 if (Line != LineInfo.getLine()) {
2340 // Determine offset.
2341 int Offset = LineInfo.getLine() - Line;
2342 int Delta = Offset - MinLineDelta;
2345 Line = LineInfo.getLine();
2347 // If delta is small enough and in range...
2348 if (Delta >= 0 && Delta < (MaxLineDelta - 1)) {
2349 // ... then use fast opcode.
2350 EmitInt8(Delta - MinLineDelta); EOL("Line Delta");
2352 // ... otherwise use long hand.
2353 EmitInt8(DW_LNS_advance_line); EOL("DW_LNS_advance_line");
2354 EmitSLEB128Bytes(Offset); EOL("Line Offset");
2355 EmitInt8(DW_LNS_copy); EOL("DW_LNS_copy");
2358 // Copy the previous row (different address or source)
2359 EmitInt8(DW_LNS_copy); EOL("DW_LNS_copy");
2363 // Define last address of section.
2364 EmitInt8(0); EOL("Extended Op");
2365 EmitInt8(4 + 1); EOL("Op size");
2366 EmitInt8(DW_LNE_set_address); EOL("DW_LNE_set_address");
2367 EmitReference("section_end", j + 1); EOL("Section end label");
2369 // Mark end of matrix.
2370 EmitInt8(0); EOL("DW_LNE_end_sequence");
2371 EmitULEB128Bytes(1); O << "\n";
2372 EmitInt8(1); O << "\n";
2375 EmitLabel("line_end", 0);
2380 /// EmitInitialDebugFrame - Emit common frame info into a debug frame section.
2382 void EmitInitialDebugFrame() {
2383 if (!TAI->getDwarfRequiresFrameSection())
2387 Asm->TM.getFrameInfo()->getStackGrowthDirection() ==
2388 TargetFrameInfo::StackGrowsUp ?
2389 TAI->getAddressSize() : -TAI->getAddressSize();
2391 // Start the dwarf frame section.
2392 Asm->SwitchToDataSection(TAI->getDwarfFrameSection());
2394 EmitLabel("frame_common", 0);
2395 EmitDifference("frame_common_end", 0,
2396 "frame_common_begin", 0);
2397 EOL("Length of Common Information Entry");
2399 EmitLabel("frame_common_begin", 0);
2400 EmitInt32(DW_CIE_ID); EOL("CIE Identifier Tag");
2401 EmitInt8(DW_CIE_VERSION); EOL("CIE Version");
2402 EmitString(""); EOL("CIE Augmentation");
2403 EmitULEB128Bytes(1); EOL("CIE Code Alignment Factor");
2404 EmitSLEB128Bytes(stackGrowth); EOL("CIE Data Alignment Factor");
2405 EmitInt8(RI->getDwarfRegNum(RI->getRARegister())); EOL("CIE RA Column");
2407 std::vector<MachineMove *> Moves;
2408 RI->getInitialFrameState(Moves);
2409 EmitFrameMoves(NULL, 0, Moves);
2410 for (unsigned i = 0, N = Moves.size(); i < N; ++i) delete Moves[i];
2413 EmitLabel("frame_common_end", 0);
2418 /// EmitFunctionDebugFrame - Emit per function frame info into a debug frame
2420 void EmitFunctionDebugFrame() {
2421 // Start the dwarf frame section.
2422 Asm->SwitchToDataSection(TAI->getDwarfFrameSection());
2424 EmitDifference("frame_end", SubprogramCount,
2425 "frame_begin", SubprogramCount);
2426 EOL("Length of Frame Information Entry");
2428 EmitLabel("frame_begin", SubprogramCount);
2430 EmitDifference("frame_common", 0, "section_frame", 0);
2431 EOL("FDE CIE offset");
2433 EmitReference("func_begin", SubprogramCount); EOL("FDE initial location");
2434 EmitDifference("func_end", SubprogramCount,
2435 "func_begin", SubprogramCount);
2436 EOL("FDE address range");
2438 std::vector<MachineMove *> &Moves = DebugInfo->getFrameMoves();
2440 EmitFrameMoves("func_begin", SubprogramCount, Moves);
2443 EmitLabel("frame_end", SubprogramCount);
2448 /// EmitDebugPubNames - Emit visible names into a debug pubnames section.
2450 void EmitDebugPubNames() {
2451 // Start the dwarf pubnames section.
2452 Asm->SwitchToDataSection(TAI->getDwarfPubNamesSection());
2454 // Process each compile unit.
2455 for (unsigned i = 0, N = CompileUnits.size(); i < N; ++i) {
2456 CompileUnit *Unit = CompileUnits[i];
2458 if (Unit->hasContent()) {
2459 EmitDifference("pubnames_end", Unit->getID(),
2460 "pubnames_begin", Unit->getID());
2461 EOL("Length of Public Names Info");
2463 EmitLabel("pubnames_begin", Unit->getID());
2465 EmitInt16(DWARF_VERSION); EOL("DWARF Version");
2467 EmitDifference("info_begin", Unit->getID(), "section_info", 0);
2468 EOL("Offset of Compilation Unit Info");
2470 EmitDifference("info_end", Unit->getID(), "info_begin", Unit->getID());
2471 EOL("Compilation Unit Length");
2473 std::map<std::string, DIE *> &Globals = Unit->getGlobals();
2475 for (std::map<std::string, DIE *>::iterator GI = Globals.begin(),
2478 const std::string &Name = GI->first;
2479 DIE * Entity = GI->second;
2481 EmitInt32(Entity->getOffset()); EOL("DIE offset");
2482 EmitString(Name); EOL("External Name");
2485 EmitInt32(0); EOL("End Mark");
2486 EmitLabel("pubnames_end", Unit->getID());
2493 /// EmitDebugStr - Emit visible names into a debug str section.
2495 void EmitDebugStr() {
2496 // Check to see if it is worth the effort.
2497 if (!StringPool.empty()) {
2498 // Start the dwarf str section.
2499 Asm->SwitchToDataSection(TAI->getDwarfStrSection());
2501 // For each of strings in the string pool.
2502 for (unsigned StringID = 1, N = StringPool.size();
2503 StringID <= N; ++StringID) {
2504 // Emit a label for reference from debug information entries.
2505 EmitLabel("string", StringID);
2506 // Emit the string itself.
2507 const std::string &String = StringPool[StringID];
2508 EmitString(String); O << "\n";
2515 /// EmitDebugLoc - Emit visible names into a debug loc section.
2517 void EmitDebugLoc() {
2518 // Start the dwarf loc section.
2519 Asm->SwitchToDataSection(TAI->getDwarfLocSection());
2524 /// EmitDebugARanges - Emit visible names into a debug aranges section.
2526 void EmitDebugARanges() {
2527 // Start the dwarf aranges section.
2528 Asm->SwitchToDataSection(TAI->getDwarfARangesSection());
2532 // Process each compile unit.
2533 for (unsigned i = 0, N = CompileUnits.size(); i < N; ++i) {
2534 CompileUnit *Unit = CompileUnits[i];
2536 if (Unit->hasContent()) {
2537 // Don't include size of length
2538 EmitInt32(0x1c); EOL("Length of Address Ranges Info");
2540 EmitInt16(DWARF_VERSION); EOL("Dwarf Version");
2542 EmitReference("info_begin", Unit->getID());
2543 EOL("Offset of Compilation Unit Info");
2545 EmitInt8(TAI->getAddressSize()); EOL("Size of Address");
2547 EmitInt8(0); EOL("Size of Segment Descriptor");
2549 EmitInt16(0); EOL("Pad (1)");
2550 EmitInt16(0); EOL("Pad (2)");
2553 EmitReference("text_begin", 0); EOL("Address");
2554 EmitDifference("text_end", 0, "text_begin", 0); EOL("Length");
2556 EmitInt32(0); EOL("EOM (1)");
2557 EmitInt32(0); EOL("EOM (2)");
2565 /// EmitDebugRanges - Emit visible names into a debug ranges section.
2567 void EmitDebugRanges() {
2568 // Start the dwarf ranges section.
2569 Asm->SwitchToDataSection(TAI->getDwarfRangesSection());
2574 /// EmitDebugMacInfo - Emit visible names into a debug macinfo section.
2576 void EmitDebugMacInfo() {
2577 // Start the dwarf macinfo section.
2578 Asm->SwitchToDataSection(TAI->getDwarfMacInfoSection());
2583 /// ConstructCompileUnitDIEs - Create a compile unit DIE for each source and
2585 void ConstructCompileUnitDIEs() {
2586 const UniqueVector<CompileUnitDesc *> CUW = DebugInfo->getCompileUnits();
2588 for (unsigned i = 1, N = CUW.size(); i <= N; ++i) {
2589 CompileUnit *Unit = NewCompileUnit(CUW[i], i);
2590 CompileUnits.push_back(Unit);
2594 /// ConstructGlobalDIEs - Create DIEs for each of the externally visible
2595 /// global variables.
2596 void ConstructGlobalDIEs() {
2597 std::vector<GlobalVariableDesc *> GlobalVariables =
2598 DebugInfo->getAnchoredDescriptors<GlobalVariableDesc>(*M);
2600 for (unsigned i = 0, N = GlobalVariables.size(); i < N; ++i) {
2601 GlobalVariableDesc *GVD = GlobalVariables[i];
2602 NewGlobalVariable(GVD);
2606 /// ConstructSubprogramDIEs - Create DIEs for each of the externally visible
2608 void ConstructSubprogramDIEs() {
2609 std::vector<SubprogramDesc *> Subprograms =
2610 DebugInfo->getAnchoredDescriptors<SubprogramDesc>(*M);
2612 for (unsigned i = 0, N = Subprograms.size(); i < N; ++i) {
2613 SubprogramDesc *SPD = Subprograms[i];
2618 /// ShouldEmitDwarf - Returns true if Dwarf declarations should be made.
2620 bool ShouldEmitDwarf() const { return shouldEmit; }
2623 //===--------------------------------------------------------------------===//
2624 // Main entry points.
2626 Dwarf(std::ostream &OS, AsmPrinter *A, const TargetAsmInfo *T)
2630 , TD(Asm->TM.getTargetData())
2631 , RI(Asm->TM.getRegisterInfo())
2637 , SubprogramCount(0)
2639 , AbbreviationsSet(InitAbbreviationsSetSize)
2641 , ValuesSet(InitValuesSetSize)
2646 , SectionSourceLines()
2650 for (unsigned i = 0, N = CompileUnits.size(); i < N; ++i)
2651 delete CompileUnits[i];
2652 for (unsigned j = 0, M = Values.size(); j < M; ++j)
2658 const TargetAsmInfo *getTargetAsmInfo() const { return TAI; }
2660 /// SetDebugInfo - Set DebugInfo when it's known that pass manager has
2661 /// created it. Set by the target AsmPrinter.
2662 void SetDebugInfo(MachineDebugInfo *DI) {
2663 // Make sure initial declarations are made.
2664 if (!DebugInfo && DI->hasInfo()) {
2668 // Emit initial sections
2671 // Create all the compile unit DIEs.
2672 ConstructCompileUnitDIEs();
2674 // Create DIEs for each of the externally visible global variables.
2675 ConstructGlobalDIEs();
2677 // Create DIEs for each of the externally visible subprograms.
2678 ConstructSubprogramDIEs();
2680 // Prime section data.
2681 SectionMap.insert(TAI->getTextSection());
2685 /// BeginModule - Emit all Dwarf sections that should come prior to the
2687 void BeginModule(Module *M) {
2690 if (!ShouldEmitDwarf()) return;
2691 EOL("Dwarf Begin Module");
2694 /// EndModule - Emit all Dwarf sections that should come after the content.
2697 if (!ShouldEmitDwarf()) return;
2698 EOL("Dwarf End Module");
2700 // Standard sections final addresses.
2701 Asm->SwitchToTextSection(TAI->getTextSection());
2702 EmitLabel("text_end", 0);
2703 Asm->SwitchToDataSection(TAI->getDataSection());
2704 EmitLabel("data_end", 0);
2706 // End text sections.
2707 for (unsigned i = 1, N = SectionMap.size(); i <= N; ++i) {
2708 Asm->SwitchToTextSection(SectionMap[i].c_str());
2709 EmitLabel("section_end", i);
2712 // Compute DIE offsets and sizes.
2715 // Emit all the DIEs into a debug info section
2718 // Corresponding abbreviations into a abbrev section.
2719 EmitAbbreviations();
2721 // Emit source line correspondence into a debug line section.
2724 // Emit info into a debug pubnames section.
2725 EmitDebugPubNames();
2727 // Emit info into a debug str section.
2730 // Emit info into a debug loc section.
2733 // Emit info into a debug aranges section.
2736 // Emit info into a debug ranges section.
2739 // Emit info into a debug macinfo section.
2743 /// BeginFunction - Gather pre-function debug information. Assumes being
2744 /// emitted immediately after the function entry point.
2745 void BeginFunction(MachineFunction *MF) {
2748 if (!ShouldEmitDwarf()) return;
2749 EOL("Dwarf Begin Function");
2751 // Begin accumulating function debug information.
2752 DebugInfo->BeginFunction(MF);
2754 // Assumes in correct section after the entry point.
2755 EmitLabel("func_begin", ++SubprogramCount);
2758 /// EndFunction - Gather and emit post-function debug information.
2760 void EndFunction() {
2761 if (!ShouldEmitDwarf()) return;
2762 EOL("Dwarf End Function");
2764 // Define end label for subprogram.
2765 EmitLabel("func_end", SubprogramCount);
2767 // Get function line info.
2768 const std::vector<SourceLineInfo> &LineInfos = DebugInfo->getSourceLines();
2770 if (!LineInfos.empty()) {
2771 // Get section line info.
2772 unsigned ID = SectionMap.insert(Asm->CurrentSection);
2773 if (SectionSourceLines.size() < ID) SectionSourceLines.resize(ID);
2774 std::vector<SourceLineInfo> &SectionLineInfos = SectionSourceLines[ID-1];
2775 // Append the function info to section info.
2776 SectionLineInfos.insert(SectionLineInfos.end(),
2777 LineInfos.begin(), LineInfos.end());
2780 // Construct scopes for subprogram.
2781 ConstructRootScope(DebugInfo->getRootScope());
2783 // Emit function frame information.
2784 EmitFunctionDebugFrame();
2786 // Reset the line numbers for the next function.
2787 DebugInfo->ClearLineInfo();
2789 // Clear function debug information.
2790 DebugInfo->EndFunction();
2794 } // End of namespace llvm
2796 //===----------------------------------------------------------------------===//
2798 /// Emit - Print the abbreviation using the specified Dwarf writer.
2800 void DIEAbbrev::Emit(const Dwarf &DW) const {
2801 // Emit its Dwarf tag type.
2802 DW.EmitULEB128Bytes(Tag);
2803 DW.EOL(TagString(Tag));
2805 // Emit whether it has children DIEs.
2806 DW.EmitULEB128Bytes(ChildrenFlag);
2807 DW.EOL(ChildrenString(ChildrenFlag));
2809 // For each attribute description.
2810 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
2811 const DIEAbbrevData &AttrData = Data[i];
2813 // Emit attribute type.
2814 DW.EmitULEB128Bytes(AttrData.getAttribute());
2815 DW.EOL(AttributeString(AttrData.getAttribute()));
2818 DW.EmitULEB128Bytes(AttrData.getForm());
2819 DW.EOL(FormEncodingString(AttrData.getForm()));
2822 // Mark end of abbreviation.
2823 DW.EmitULEB128Bytes(0); DW.EOL("EOM(1)");
2824 DW.EmitULEB128Bytes(0); DW.EOL("EOM(2)");
2828 void DIEAbbrev::print(std::ostream &O) {
2829 O << "Abbreviation @"
2830 << std::hex << (intptr_t)this << std::dec
2834 << ChildrenString(ChildrenFlag)
2837 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
2839 << AttributeString(Data[i].getAttribute())
2841 << FormEncodingString(Data[i].getForm())
2845 void DIEAbbrev::dump() { print(std::cerr); }
2848 //===----------------------------------------------------------------------===//
2851 void DIEValue::dump() {
2856 //===----------------------------------------------------------------------===//
2858 /// EmitValue - Emit integer of appropriate size.
2860 void DIEInteger::EmitValue(const Dwarf &DW, unsigned Form) const {
2862 case DW_FORM_flag: // Fall thru
2863 case DW_FORM_ref1: // Fall thru
2864 case DW_FORM_data1: DW.EmitInt8(Integer); break;
2865 case DW_FORM_ref2: // Fall thru
2866 case DW_FORM_data2: DW.EmitInt16(Integer); break;
2867 case DW_FORM_ref4: // Fall thru
2868 case DW_FORM_data4: DW.EmitInt32(Integer); break;
2869 case DW_FORM_ref8: // Fall thru
2870 case DW_FORM_data8: DW.EmitInt64(Integer); break;
2871 case DW_FORM_udata: DW.EmitULEB128Bytes(Integer); break;
2872 case DW_FORM_sdata: DW.EmitSLEB128Bytes(Integer); break;
2873 default: assert(0 && "DIE Value form not supported yet"); break;
2877 //===----------------------------------------------------------------------===//
2879 /// EmitValue - Emit string value.
2881 void DIEString::EmitValue(const Dwarf &DW, unsigned Form) const {
2882 DW.EmitString(String);
2885 //===----------------------------------------------------------------------===//
2887 /// EmitValue - Emit label value.
2889 void DIEDwarfLabel::EmitValue(const Dwarf &DW, unsigned Form) const {
2890 DW.EmitReference(Label);
2893 /// SizeOf - Determine size of label value in bytes.
2895 unsigned DIEDwarfLabel::SizeOf(const Dwarf &DW, unsigned Form) const {
2896 return DW.getTargetAsmInfo()->getAddressSize();
2899 //===----------------------------------------------------------------------===//
2901 /// EmitValue - Emit label value.
2903 void DIEObjectLabel::EmitValue(const Dwarf &DW, unsigned Form) const {
2904 DW.EmitReference(Label);
2907 /// SizeOf - Determine size of label value in bytes.
2909 unsigned DIEObjectLabel::SizeOf(const Dwarf &DW, unsigned Form) const {
2910 return DW.getTargetAsmInfo()->getAddressSize();
2913 //===----------------------------------------------------------------------===//
2915 /// EmitValue - Emit delta value.
2917 void DIEDelta::EmitValue(const Dwarf &DW, unsigned Form) const {
2918 DW.EmitDifference(LabelHi, LabelLo);
2921 /// SizeOf - Determine size of delta value in bytes.
2923 unsigned DIEDelta::SizeOf(const Dwarf &DW, unsigned Form) const {
2924 return DW.getTargetAsmInfo()->getAddressSize();
2927 //===----------------------------------------------------------------------===//
2929 /// EmitValue - Emit debug information entry offset.
2931 void DIEntry::EmitValue(const Dwarf &DW, unsigned Form) const {
2932 DW.EmitInt32(Entry->getOffset());
2935 //===----------------------------------------------------------------------===//
2937 /// ComputeSize - calculate the size of the block.
2939 unsigned DIEBlock::ComputeSize(Dwarf &DW) {
2941 const std::vector<DIEAbbrevData> &AbbrevData = Abbrev.getData();
2943 for (unsigned i = 0, N = Values.size(); i < N; ++i) {
2944 Size += Values[i]->SizeOf(DW, AbbrevData[i].getForm());
2950 /// EmitValue - Emit block data.
2952 void DIEBlock::EmitValue(const Dwarf &DW, unsigned Form) const {
2954 case DW_FORM_block1: DW.EmitInt8(Size); break;
2955 case DW_FORM_block2: DW.EmitInt16(Size); break;
2956 case DW_FORM_block4: DW.EmitInt32(Size); break;
2957 case DW_FORM_block: DW.EmitULEB128Bytes(Size); break;
2958 default: assert(0 && "Improper form for block"); break;
2961 const std::vector<DIEAbbrevData> &AbbrevData = Abbrev.getData();
2963 for (unsigned i = 0, N = Values.size(); i < N; ++i) {
2965 Values[i]->EmitValue(DW, AbbrevData[i].getForm());
2969 /// SizeOf - Determine size of block data in bytes.
2971 unsigned DIEBlock::SizeOf(const Dwarf &DW, unsigned Form) const {
2973 case DW_FORM_block1: return Size + sizeof(int8_t);
2974 case DW_FORM_block2: return Size + sizeof(int16_t);
2975 case DW_FORM_block4: return Size + sizeof(int32_t);
2976 case DW_FORM_block: return Size + SizeULEB128(Size);
2977 default: assert(0 && "Improper form for block"); break;
2982 //===----------------------------------------------------------------------===//
2983 /// DIE Implementation
2986 for (unsigned i = 0, N = Children.size(); i < N; ++i)
2990 /// AddSiblingOffset - Add a sibling offset field to the front of the DIE.
2992 void DIE::AddSiblingOffset() {
2993 DIEInteger *DI = new DIEInteger(0);
2994 Values.insert(Values.begin(), DI);
2995 Abbrev.AddFirstAttribute(DW_AT_sibling, DW_FORM_ref4);
2998 /// Profile - Used to gather unique data for the value folding set.
3000 void DIE::Profile(FoldingSetNodeID &ID) {
3003 for (unsigned i = 0, N = Children.size(); i < N; ++i)
3004 ID.AddPointer(Children[i]);
3006 for (unsigned j = 0, M = Values.size(); j < M; ++j)
3007 ID.AddPointer(Values[j]);
3011 void DIE::print(std::ostream &O, unsigned IncIndent) {
3012 static unsigned IndentCount = 0;
3013 IndentCount += IncIndent;
3014 const std::string Indent(IndentCount, ' ');
3015 bool isBlock = Abbrev.getTag() == 0;
3020 << "0x" << std::hex << (intptr_t)this << std::dec
3021 << ", Offset: " << Offset
3022 << ", Size: " << Size
3026 << TagString(Abbrev.getTag())
3028 << ChildrenString(Abbrev.getChildrenFlag());
3030 O << "Size: " << Size;
3034 const std::vector<DIEAbbrevData> &Data = Abbrev.getData();
3037 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
3040 O << AttributeString(Data[i].getAttribute());
3042 O << "Blk[" << i << "]";
3045 << FormEncodingString(Data[i].getForm())
3047 Values[i]->print(O);
3052 for (unsigned j = 0, M = Children.size(); j < M; ++j) {
3053 Children[j]->print(O, 4);
3056 if (!isBlock) O << "\n";
3057 IndentCount -= IncIndent;
3065 //===----------------------------------------------------------------------===//
3066 /// DwarfWriter Implementation
3069 DwarfWriter::DwarfWriter(std::ostream &OS, AsmPrinter *A,
3070 const TargetAsmInfo *T) {
3071 DW = new Dwarf(OS, A, T);
3074 DwarfWriter::~DwarfWriter() {
3078 /// SetDebugInfo - Set DebugInfo when it's known that pass manager has
3079 /// created it. Set by the target AsmPrinter.
3080 void DwarfWriter::SetDebugInfo(MachineDebugInfo *DI) {
3081 DW->SetDebugInfo(DI);
3084 /// BeginModule - Emit all Dwarf sections that should come prior to the
3086 void DwarfWriter::BeginModule(Module *M) {
3090 /// EndModule - Emit all Dwarf sections that should come after the content.
3092 void DwarfWriter::EndModule() {
3096 /// BeginFunction - Gather pre-function debug information. Assumes being
3097 /// emitted immediately after the function entry point.
3098 void DwarfWriter::BeginFunction(MachineFunction *MF) {
3099 DW->BeginFunction(MF);
3102 /// EndFunction - Gather and emit post-function debug information.
3104 void DwarfWriter::EndFunction() {