1 //===-- llvm/CodeGen/DwarfWriter.cpp - Dwarf Framework ----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by James M. Laskey and is distributed under the
6 // University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains support for writing dwarf info into asm files.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/CodeGen/DwarfWriter.h"
16 #include "llvm/ADT/DenseMap.h"
17 #include "llvm/ADT/FoldingSet.h"
18 #include "llvm/ADT/StringExtras.h"
19 #include "llvm/ADT/UniqueVector.h"
20 #include "llvm/Module.h"
21 #include "llvm/Type.h"
22 #include "llvm/CodeGen/AsmPrinter.h"
23 #include "llvm/CodeGen/MachineModuleInfo.h"
24 #include "llvm/CodeGen/MachineFrameInfo.h"
25 #include "llvm/CodeGen/MachineLocation.h"
26 #include "llvm/Support/Debug.h"
27 #include "llvm/Support/Dwarf.h"
28 #include "llvm/Support/CommandLine.h"
29 #include "llvm/Support/DataTypes.h"
30 #include "llvm/Support/Mangler.h"
31 #include "llvm/Target/TargetAsmInfo.h"
32 #include "llvm/Target/MRegisterInfo.h"
33 #include "llvm/Target/TargetData.h"
34 #include "llvm/Target/TargetFrameInfo.h"
35 #include "llvm/Target/TargetInstrInfo.h"
36 #include "llvm/Target/TargetMachine.h"
37 #include "llvm/Target/TargetOptions.h"
41 using namespace llvm::dwarf;
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 /// DWLabel - Labels are used to track locations in the assembler file.
61 /// Labels appear in the form @verbatim <prefix><Tag><Number> @endverbatim,
62 /// where the tag is a category of label (Ex. location) and number is a value
63 /// unique in that category.
66 /// Tag - Label category tag. Should always be a staticly declared C string.
70 /// Number - Value to make label unique.
74 DWLabel(const char *T, unsigned N) : Tag(T), Number(N) {}
76 void Profile(FoldingSetNodeID &ID) const {
77 ID.AddString(std::string(Tag));
78 ID.AddInteger(Number);
82 void print(std::ostream *O) const {
85 void print(std::ostream &O) const {
87 if (Number) O << Number;
92 //===----------------------------------------------------------------------===//
93 /// DIEAbbrevData - Dwarf abbreviation data, describes the one attribute of a
94 /// Dwarf abbreviation.
97 /// Attribute - Dwarf attribute code.
101 /// Form - Dwarf form code.
106 DIEAbbrevData(unsigned A, unsigned F)
112 unsigned getAttribute() const { return Attribute; }
113 unsigned getForm() const { return Form; }
115 /// Profile - Used to gather unique data for the abbreviation folding set.
117 void Profile(FoldingSetNodeID &ID)const {
118 ID.AddInteger(Attribute);
123 //===----------------------------------------------------------------------===//
124 /// DIEAbbrev - Dwarf abbreviation, describes the organization of a debug
125 /// information object.
126 class DIEAbbrev : public FoldingSetNode {
128 /// Tag - Dwarf tag code.
132 /// Unique number for node.
136 /// ChildrenFlag - Dwarf children flag.
138 unsigned ChildrenFlag;
140 /// Data - Raw data bytes for abbreviation.
142 std::vector<DIEAbbrevData> Data;
146 DIEAbbrev(unsigned T, unsigned C)
154 unsigned getTag() const { return Tag; }
155 unsigned getNumber() const { return Number; }
156 unsigned getChildrenFlag() const { return ChildrenFlag; }
157 const std::vector<DIEAbbrevData> &getData() const { return Data; }
158 void setTag(unsigned T) { Tag = T; }
159 void setChildrenFlag(unsigned CF) { ChildrenFlag = CF; }
160 void setNumber(unsigned N) { Number = N; }
162 /// AddAttribute - Adds another set of attribute information to the
164 void AddAttribute(unsigned Attribute, unsigned Form) {
165 Data.push_back(DIEAbbrevData(Attribute, Form));
168 /// AddFirstAttribute - Adds a set of attribute information to the front
169 /// of the abbreviation.
170 void AddFirstAttribute(unsigned Attribute, unsigned Form) {
171 Data.insert(Data.begin(), DIEAbbrevData(Attribute, Form));
174 /// Profile - Used to gather unique data for the abbreviation folding set.
176 void Profile(FoldingSetNodeID &ID) {
178 ID.AddInteger(ChildrenFlag);
180 // For each attribute description.
181 for (unsigned i = 0, N = Data.size(); i < N; ++i)
185 /// Emit - Print the abbreviation using the specified Dwarf writer.
187 void Emit(const DwarfDebug &DD) const;
190 void print(std::ostream *O) {
193 void print(std::ostream &O);
198 //===----------------------------------------------------------------------===//
199 /// DIE - A structured debug information entry. Has an abbreviation which
200 /// describes it's organization.
201 class DIE : public FoldingSetNode {
203 /// Abbrev - Buffer for constructing abbreviation.
207 /// Offset - Offset in debug info section.
211 /// Size - Size of instance + children.
217 std::vector<DIE *> Children;
219 /// Attributes values.
221 std::vector<DIEValue *> Values;
224 explicit DIE(unsigned Tag)
225 : Abbrev(Tag, DW_CHILDREN_no)
234 DIEAbbrev &getAbbrev() { return Abbrev; }
235 unsigned getAbbrevNumber() const {
236 return Abbrev.getNumber();
238 unsigned getTag() const { return Abbrev.getTag(); }
239 unsigned getOffset() const { return Offset; }
240 unsigned getSize() const { return Size; }
241 const std::vector<DIE *> &getChildren() const { return Children; }
242 std::vector<DIEValue *> &getValues() { return Values; }
243 void setTag(unsigned Tag) { Abbrev.setTag(Tag); }
244 void setOffset(unsigned O) { Offset = O; }
245 void setSize(unsigned S) { Size = S; }
247 /// AddValue - Add a value and attributes to a DIE.
249 void AddValue(unsigned Attribute, unsigned Form, DIEValue *Value) {
250 Abbrev.AddAttribute(Attribute, Form);
251 Values.push_back(Value);
254 /// SiblingOffset - Return the offset of the debug information entry's
256 unsigned SiblingOffset() const { return Offset + Size; }
258 /// AddSiblingOffset - Add a sibling offset field to the front of the DIE.
260 void AddSiblingOffset();
262 /// AddChild - Add a child to the DIE.
264 void AddChild(DIE *Child) {
265 Abbrev.setChildrenFlag(DW_CHILDREN_yes);
266 Children.push_back(Child);
269 /// Detach - Detaches objects connected to it after copying.
275 /// Profile - Used to gather unique data for the value folding set.
277 void Profile(FoldingSetNodeID &ID) ;
280 void print(std::ostream *O, unsigned IncIndent = 0) {
281 if (O) print(*O, IncIndent);
283 void print(std::ostream &O, unsigned IncIndent = 0);
288 //===----------------------------------------------------------------------===//
289 /// DIEValue - A debug information entry value.
291 class DIEValue : public FoldingSetNode {
303 /// Type - Type of data stored in the value.
307 explicit DIEValue(unsigned T)
310 virtual ~DIEValue() {}
313 unsigned getType() const { return Type; }
315 // Implement isa/cast/dyncast.
316 static bool classof(const DIEValue *) { return true; }
318 /// EmitValue - Emit value via the Dwarf writer.
320 virtual void EmitValue(DwarfDebug &DD, unsigned Form) = 0;
322 /// SizeOf - Return the size of a value in bytes.
324 virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const = 0;
326 /// Profile - Used to gather unique data for the value folding set.
328 virtual void Profile(FoldingSetNodeID &ID) = 0;
331 void print(std::ostream *O) {
334 virtual void print(std::ostream &O) = 0;
339 //===----------------------------------------------------------------------===//
340 /// DWInteger - An integer value DIE.
342 class DIEInteger : public DIEValue {
347 explicit DIEInteger(uint64_t I) : DIEValue(isInteger), Integer(I) {}
349 // Implement isa/cast/dyncast.
350 static bool classof(const DIEInteger *) { return true; }
351 static bool classof(const DIEValue *I) { return I->Type == isInteger; }
353 /// BestForm - Choose the best form for integer.
355 static unsigned BestForm(bool IsSigned, uint64_t Integer) {
357 if ((char)Integer == (signed)Integer) return DW_FORM_data1;
358 if ((short)Integer == (signed)Integer) return DW_FORM_data2;
359 if ((int)Integer == (signed)Integer) return DW_FORM_data4;
361 if ((unsigned char)Integer == Integer) return DW_FORM_data1;
362 if ((unsigned short)Integer == Integer) return DW_FORM_data2;
363 if ((unsigned int)Integer == Integer) return DW_FORM_data4;
365 return DW_FORM_data8;
368 /// EmitValue - Emit integer of appropriate size.
370 virtual void EmitValue(DwarfDebug &DD, unsigned Form);
372 /// SizeOf - Determine size of integer value in bytes.
374 virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const;
376 /// Profile - Used to gather unique data for the value folding set.
378 static void Profile(FoldingSetNodeID &ID, unsigned Integer) {
379 ID.AddInteger(isInteger);
380 ID.AddInteger(Integer);
382 virtual void Profile(FoldingSetNodeID &ID) { Profile(ID, Integer); }
385 virtual void print(std::ostream &O) {
386 O << "Int: " << (int64_t)Integer
387 << " 0x" << std::hex << Integer << std::dec;
392 //===----------------------------------------------------------------------===//
393 /// DIEString - A string value DIE.
395 class DIEString : public DIEValue {
397 const std::string String;
399 explicit DIEString(const std::string &S) : DIEValue(isString), String(S) {}
401 // Implement isa/cast/dyncast.
402 static bool classof(const DIEString *) { return true; }
403 static bool classof(const DIEValue *S) { return S->Type == isString; }
405 /// EmitValue - Emit string value.
407 virtual void EmitValue(DwarfDebug &DD, unsigned Form);
409 /// SizeOf - Determine size of string value in bytes.
411 virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const {
412 return String.size() + sizeof(char); // sizeof('\0');
415 /// Profile - Used to gather unique data for the value folding set.
417 static void Profile(FoldingSetNodeID &ID, const std::string &String) {
418 ID.AddInteger(isString);
419 ID.AddString(String);
421 virtual void Profile(FoldingSetNodeID &ID) { Profile(ID, String); }
424 virtual void print(std::ostream &O) {
425 O << "Str: \"" << String << "\"";
430 //===----------------------------------------------------------------------===//
431 /// DIEDwarfLabel - A Dwarf internal label expression DIE.
433 class DIEDwarfLabel : public DIEValue {
438 explicit DIEDwarfLabel(const DWLabel &L) : DIEValue(isLabel), Label(L) {}
440 // Implement isa/cast/dyncast.
441 static bool classof(const DIEDwarfLabel *) { return true; }
442 static bool classof(const DIEValue *L) { return L->Type == isLabel; }
444 /// EmitValue - Emit label value.
446 virtual void EmitValue(DwarfDebug &DD, unsigned Form);
448 /// SizeOf - Determine size of label value in bytes.
450 virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const;
452 /// Profile - Used to gather unique data for the value folding set.
454 static void Profile(FoldingSetNodeID &ID, const DWLabel &Label) {
455 ID.AddInteger(isLabel);
458 virtual void Profile(FoldingSetNodeID &ID) { Profile(ID, Label); }
461 virtual void print(std::ostream &O) {
469 //===----------------------------------------------------------------------===//
470 /// DIEObjectLabel - A label to an object in code or data.
472 class DIEObjectLabel : public DIEValue {
474 const std::string Label;
476 explicit DIEObjectLabel(const std::string &L)
477 : DIEValue(isAsIsLabel), Label(L) {}
479 // Implement isa/cast/dyncast.
480 static bool classof(const DIEObjectLabel *) { return true; }
481 static bool classof(const DIEValue *L) { return L->Type == isAsIsLabel; }
483 /// EmitValue - Emit label value.
485 virtual void EmitValue(DwarfDebug &DD, unsigned Form);
487 /// SizeOf - Determine size of label value in bytes.
489 virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const;
491 /// Profile - Used to gather unique data for the value folding set.
493 static void Profile(FoldingSetNodeID &ID, const std::string &Label) {
494 ID.AddInteger(isAsIsLabel);
497 virtual void Profile(FoldingSetNodeID &ID) { Profile(ID, Label); }
500 virtual void print(std::ostream &O) {
501 O << "Obj: " << Label;
506 //===----------------------------------------------------------------------===//
507 /// DIEDelta - A simple label difference DIE.
509 class DIEDelta : public DIEValue {
511 const DWLabel LabelHi;
512 const DWLabel LabelLo;
514 DIEDelta(const DWLabel &Hi, const DWLabel &Lo)
515 : DIEValue(isDelta), LabelHi(Hi), LabelLo(Lo) {}
517 // Implement isa/cast/dyncast.
518 static bool classof(const DIEDelta *) { return true; }
519 static bool classof(const DIEValue *D) { return D->Type == isDelta; }
521 /// EmitValue - Emit delta value.
523 virtual void EmitValue(DwarfDebug &DD, unsigned Form);
525 /// SizeOf - Determine size of delta value in bytes.
527 virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const;
529 /// Profile - Used to gather unique data for the value folding set.
531 static void Profile(FoldingSetNodeID &ID, const DWLabel &LabelHi,
532 const DWLabel &LabelLo) {
533 ID.AddInteger(isDelta);
537 virtual void Profile(FoldingSetNodeID &ID) { Profile(ID, LabelHi, LabelLo); }
540 virtual void print(std::ostream &O) {
549 //===----------------------------------------------------------------------===//
550 /// DIEntry - A pointer to another debug information entry. An instance of this
551 /// class can also be used as a proxy for a debug information entry not yet
552 /// defined (ie. types.)
553 class DIEntry : public DIEValue {
557 explicit DIEntry(DIE *E) : DIEValue(isEntry), Entry(E) {}
559 // Implement isa/cast/dyncast.
560 static bool classof(const DIEntry *) { return true; }
561 static bool classof(const DIEValue *E) { return E->Type == isEntry; }
563 /// EmitValue - Emit debug information entry offset.
565 virtual void EmitValue(DwarfDebug &DD, unsigned Form);
567 /// SizeOf - Determine size of debug information entry in bytes.
569 virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const {
570 return sizeof(int32_t);
573 /// Profile - Used to gather unique data for the value folding set.
575 static void Profile(FoldingSetNodeID &ID, DIE *Entry) {
576 ID.AddInteger(isEntry);
577 ID.AddPointer(Entry);
579 virtual void Profile(FoldingSetNodeID &ID) {
580 ID.AddInteger(isEntry);
583 ID.AddPointer(Entry);
590 virtual void print(std::ostream &O) {
591 O << "Die: 0x" << std::hex << (intptr_t)Entry << std::dec;
596 //===----------------------------------------------------------------------===//
597 /// DIEBlock - A block of values. Primarily used for location expressions.
599 class DIEBlock : public DIEValue, public DIE {
601 unsigned Size; // Size in bytes excluding size header.
611 // Implement isa/cast/dyncast.
612 static bool classof(const DIEBlock *) { return true; }
613 static bool classof(const DIEValue *E) { return E->Type == isBlock; }
615 /// ComputeSize - calculate the size of the block.
617 unsigned ComputeSize(DwarfDebug &DD);
619 /// BestForm - Choose the best form for data.
621 unsigned BestForm() const {
622 if ((unsigned char)Size == Size) return DW_FORM_block1;
623 if ((unsigned short)Size == Size) return DW_FORM_block2;
624 if ((unsigned int)Size == Size) return DW_FORM_block4;
625 return DW_FORM_block;
628 /// EmitValue - Emit block data.
630 virtual void EmitValue(DwarfDebug &DD, unsigned Form);
632 /// SizeOf - Determine size of block data in bytes.
634 virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const;
637 /// Profile - Used to gather unique data for the value folding set.
639 virtual void Profile(FoldingSetNodeID &ID) {
640 ID.AddInteger(isBlock);
645 virtual void print(std::ostream &O) {
652 //===----------------------------------------------------------------------===//
653 /// CompileUnit - This dwarf writer support class manages information associate
654 /// with a source file.
657 /// Desc - Compile unit debug descriptor.
659 CompileUnitDesc *Desc;
661 /// ID - File identifier for source.
665 /// Die - Compile unit debug information entry.
669 /// DescToDieMap - Tracks the mapping of unit level debug informaton
670 /// descriptors to debug information entries.
671 std::map<DebugInfoDesc *, DIE *> DescToDieMap;
673 /// DescToDIEntryMap - Tracks the mapping of unit level debug informaton
674 /// descriptors to debug information entries using a DIEntry proxy.
675 std::map<DebugInfoDesc *, DIEntry *> DescToDIEntryMap;
677 /// Globals - A map of globally visible named entities for this unit.
679 std::map<std::string, DIE *> Globals;
681 /// DiesSet - Used to uniquely define dies within the compile unit.
683 FoldingSet<DIE> DiesSet;
685 /// Dies - List of all dies in the compile unit.
687 std::vector<DIE *> Dies;
690 CompileUnit(CompileUnitDesc *CUD, unsigned I, DIE *D)
697 , DiesSet(InitDiesSetSize)
704 for (unsigned i = 0, N = Dies.size(); i < N; ++i)
709 CompileUnitDesc *getDesc() const { return Desc; }
710 unsigned getID() const { return ID; }
711 DIE* getDie() const { return Die; }
712 std::map<std::string, DIE *> &getGlobals() { return Globals; }
714 /// hasContent - Return true if this compile unit has something to write out.
716 bool hasContent() const {
717 return !Die->getChildren().empty();
720 /// AddGlobal - Add a new global entity to the compile unit.
722 void AddGlobal(const std::string &Name, DIE *Die) {
726 /// getDieMapSlotFor - Returns the debug information entry map slot for the
727 /// specified debug descriptor.
728 DIE *&getDieMapSlotFor(DebugInfoDesc *DID) {
729 return DescToDieMap[DID];
732 /// getDIEntrySlotFor - Returns the debug information entry proxy slot for the
733 /// specified debug descriptor.
734 DIEntry *&getDIEntrySlotFor(DebugInfoDesc *DID) {
735 return DescToDIEntryMap[DID];
738 /// AddDie - Adds or interns the DIE to the compile unit.
740 DIE *AddDie(DIE &Buffer) {
744 DIE *Die = DiesSet.FindNodeOrInsertPos(ID, Where);
747 Die = new DIE(Buffer);
748 DiesSet.InsertNode(Die, Where);
749 this->Die->AddChild(Die);
757 //===----------------------------------------------------------------------===//
758 /// Dwarf - Emits general Dwarf directives.
764 //===--------------------------------------------------------------------===//
765 // Core attributes used by the Dwarf writer.
769 /// O - Stream to .s file.
773 /// Asm - Target of Dwarf emission.
777 /// TAI - Target Asm Printer.
778 const TargetAsmInfo *TAI;
780 /// TD - Target data.
781 const TargetData *TD;
783 /// RI - Register Information.
784 const MRegisterInfo *RI;
786 /// M - Current module.
790 /// MF - Current machine function.
794 /// MMI - Collected machine module information.
796 MachineModuleInfo *MMI;
798 /// SubprogramCount - The running count of functions being compiled.
800 unsigned SubprogramCount;
803 Dwarf(std::ostream &OS, AsmPrinter *A, const TargetAsmInfo *T)
807 , TD(Asm->TM.getTargetData())
808 , RI(Asm->TM.getRegisterInfo())
819 //===--------------------------------------------------------------------===//
822 AsmPrinter *getAsm() const { return Asm; }
823 MachineModuleInfo *getMMI() const { return MMI; }
824 const TargetAsmInfo *getTargetAsmInfo() const { return TAI; }
826 void PrintRelDirective(bool Force32Bit = false, bool isInSection = false)
828 if (isInSection && TAI->getDwarfSectionOffsetDirective())
829 O << TAI->getDwarfSectionOffsetDirective();
830 else if (Force32Bit || TAI->getAddressSize() == sizeof(int32_t))
831 O << TAI->getData32bitsDirective();
833 O << TAI->getData64bitsDirective();
836 /// PrintLabelName - Print label name in form used by Dwarf writer.
838 void PrintLabelName(DWLabel Label) const {
839 PrintLabelName(Label.Tag, Label.Number);
841 void PrintLabelName(const char *Tag, unsigned Number) const {
843 O << TAI->getPrivateGlobalPrefix() << Tag;
844 if (Number) O << Number;
847 /// EmitLabel - Emit location label for internal use by Dwarf.
849 void EmitLabel(DWLabel Label) const {
850 EmitLabel(Label.Tag, Label.Number);
852 void EmitLabel(const char *Tag, unsigned Number) const {
853 PrintLabelName(Tag, Number);
857 /// EmitReference - Emit a reference to a label.
859 void EmitReference(DWLabel Label, bool IsPCRelative = false) const {
860 EmitReference(Label.Tag, Label.Number, IsPCRelative);
862 void EmitReference(const char *Tag, unsigned Number,
863 bool IsPCRelative = false) const {
865 PrintLabelName(Tag, Number);
867 if (IsPCRelative) O << "-" << TAI->getPCSymbol();
869 void EmitReference(const std::string &Name, bool IsPCRelative = false) const {
874 if (IsPCRelative) O << "-" << TAI->getPCSymbol();
877 /// EmitDifference - Emit the difference between two labels. Some
878 /// assemblers do not behave with absolute expressions with data directives,
879 /// so there is an option (needsSet) to use an intermediary set expression.
880 void EmitDifference(DWLabel LabelHi, DWLabel LabelLo,
881 bool IsSmall = false) {
882 EmitDifference(LabelHi.Tag, LabelHi.Number,
883 LabelLo.Tag, LabelLo.Number,
886 void EmitDifference(const char *TagHi, unsigned NumberHi,
887 const char *TagLo, unsigned NumberLo,
888 bool IsSmall = false) {
889 if (TAI->needsSet()) {
891 PrintLabelName("set", SetCounter);
893 PrintLabelName(TagHi, NumberHi);
895 PrintLabelName(TagLo, NumberLo);
898 PrintRelDirective(IsSmall);
900 PrintLabelName("set", SetCounter);
904 PrintRelDirective(IsSmall);
906 PrintLabelName(TagHi, NumberHi);
908 PrintLabelName(TagLo, NumberLo);
912 void EmitSectionOffset(const char* Label, const char* Section,
913 unsigned LabelNumber, unsigned SectionNumber,
914 bool IsSmall = false, bool isEH = false) {
915 bool printAbsolute = false;
916 if (TAI->needsSet()) {
918 PrintLabelName("set", SetCounter);
920 PrintLabelName(Label, LabelNumber);
923 printAbsolute = TAI->isAbsoluteEHSectionOffsets();
925 printAbsolute = TAI->isAbsoluteDebugSectionOffsets();
927 if (!printAbsolute) {
929 PrintLabelName(Section, SectionNumber);
933 PrintRelDirective(IsSmall);
935 PrintLabelName("set", SetCounter);
938 PrintRelDirective(IsSmall, true);
940 PrintLabelName(Label, LabelNumber);
943 printAbsolute = TAI->isAbsoluteEHSectionOffsets();
945 printAbsolute = TAI->isAbsoluteDebugSectionOffsets();
947 if (!printAbsolute) {
949 PrintLabelName(Section, SectionNumber);
954 /// EmitFrameMoves - Emit frame instructions to describe the layout of the
956 void EmitFrameMoves(const char *BaseLabel, unsigned BaseLabelID,
957 const std::vector<MachineMove> &Moves) {
959 Asm->TM.getFrameInfo()->getStackGrowthDirection() ==
960 TargetFrameInfo::StackGrowsUp ?
961 TAI->getAddressSize() : -TAI->getAddressSize();
962 bool IsLocal = BaseLabel && strcmp(BaseLabel, "label") == 0;
964 for (unsigned i = 0, N = Moves.size(); i < N; ++i) {
965 const MachineMove &Move = Moves[i];
966 unsigned LabelID = Move.getLabelID();
969 LabelID = MMI->MappedLabel(LabelID);
971 // Throw out move if the label is invalid.
972 if (!LabelID) continue;
975 const MachineLocation &Dst = Move.getDestination();
976 const MachineLocation &Src = Move.getSource();
978 // Advance row if new location.
979 if (BaseLabel && LabelID && (BaseLabelID != LabelID || !IsLocal)) {
980 Asm->EmitInt8(DW_CFA_advance_loc4);
981 Asm->EOL("DW_CFA_advance_loc4");
982 EmitDifference("label", LabelID, BaseLabel, BaseLabelID, true);
985 BaseLabelID = LabelID;
991 if (Dst.isRegister() && Dst.getRegister() == MachineLocation::VirtualFP) {
992 if (!Src.isRegister()) {
993 if (Src.getRegister() == MachineLocation::VirtualFP) {
994 Asm->EmitInt8(DW_CFA_def_cfa_offset);
995 Asm->EOL("DW_CFA_def_cfa_offset");
997 Asm->EmitInt8(DW_CFA_def_cfa);
998 Asm->EOL("DW_CFA_def_cfa");
999 Asm->EmitULEB128Bytes(RI->getDwarfRegNum(Src.getRegister()));
1000 Asm->EOL("Register");
1003 int Offset = -Src.getOffset();
1005 Asm->EmitULEB128Bytes(Offset);
1008 assert(0 && "Machine move no supported yet.");
1010 } else if (Src.isRegister() &&
1011 Src.getRegister() == MachineLocation::VirtualFP) {
1012 if (Dst.isRegister()) {
1013 Asm->EmitInt8(DW_CFA_def_cfa_register);
1014 Asm->EOL("DW_CFA_def_cfa_register");
1015 Asm->EmitULEB128Bytes(RI->getDwarfRegNum(Dst.getRegister()));
1016 Asm->EOL("Register");
1018 assert(0 && "Machine move no supported yet.");
1021 unsigned Reg = RI->getDwarfRegNum(Src.getRegister());
1022 int Offset = Dst.getOffset() / stackGrowth;
1025 Asm->EmitInt8(DW_CFA_offset_extended_sf);
1026 Asm->EOL("DW_CFA_offset_extended_sf");
1027 Asm->EmitULEB128Bytes(Reg);
1029 Asm->EmitSLEB128Bytes(Offset);
1031 } else if (Reg < 64) {
1032 Asm->EmitInt8(DW_CFA_offset + Reg);
1033 Asm->EOL("DW_CFA_offset + Reg (" + utostr(Reg) + ")");
1034 Asm->EmitULEB128Bytes(Offset);
1037 Asm->EmitInt8(DW_CFA_offset_extended);
1038 Asm->EOL("DW_CFA_offset_extended");
1039 Asm->EmitULEB128Bytes(Reg);
1041 Asm->EmitULEB128Bytes(Offset);
1050 //===----------------------------------------------------------------------===//
1051 /// DwarfDebug - Emits Dwarf debug directives.
1053 class DwarfDebug : public Dwarf {
1056 //===--------------------------------------------------------------------===//
1057 // Attributes used to construct specific Dwarf sections.
1060 /// CompileUnits - All the compile units involved in this build. The index
1061 /// of each entry in this vector corresponds to the sources in MMI.
1062 std::vector<CompileUnit *> CompileUnits;
1064 /// AbbreviationsSet - Used to uniquely define abbreviations.
1066 FoldingSet<DIEAbbrev> AbbreviationsSet;
1068 /// Abbreviations - A list of all the unique abbreviations in use.
1070 std::vector<DIEAbbrev *> Abbreviations;
1072 /// ValuesSet - Used to uniquely define values.
1074 FoldingSet<DIEValue> ValuesSet;
1076 /// Values - A list of all the unique values in use.
1078 std::vector<DIEValue *> Values;
1080 /// StringPool - A UniqueVector of strings used by indirect references.
1082 UniqueVector<std::string> StringPool;
1084 /// UnitMap - Map debug information descriptor to compile unit.
1086 std::map<DebugInfoDesc *, CompileUnit *> DescToUnitMap;
1088 /// SectionMap - Provides a unique id per text section.
1090 UniqueVector<std::string> SectionMap;
1092 /// SectionSourceLines - Tracks line numbers per text section.
1094 std::vector<std::vector<SourceLineInfo> > SectionSourceLines;
1096 /// didInitial - Flag to indicate if initial emission has been done.
1100 /// shouldEmit - Flag to indicate if debug information should be emitted.
1104 struct FunctionDebugFrameInfo {
1106 std::vector<MachineMove> Moves;
1108 FunctionDebugFrameInfo(unsigned Num, const std::vector<MachineMove> &M):
1109 Number(Num), Moves(M) { }
1112 std::vector<FunctionDebugFrameInfo> DebugFrames;
1116 /// ShouldEmitDwarf - Returns true if Dwarf declarations should be made.
1118 bool ShouldEmitDwarf() const { return shouldEmit; }
1120 /// AssignAbbrevNumber - Define a unique number for the abbreviation.
1122 void AssignAbbrevNumber(DIEAbbrev &Abbrev) {
1123 // Profile the node so that we can make it unique.
1124 FoldingSetNodeID ID;
1127 // Check the set for priors.
1128 DIEAbbrev *InSet = AbbreviationsSet.GetOrInsertNode(&Abbrev);
1130 // If it's newly added.
1131 if (InSet == &Abbrev) {
1132 // Add to abbreviation list.
1133 Abbreviations.push_back(&Abbrev);
1134 // Assign the vector position + 1 as its number.
1135 Abbrev.setNumber(Abbreviations.size());
1137 // Assign existing abbreviation number.
1138 Abbrev.setNumber(InSet->getNumber());
1142 /// NewString - Add a string to the constant pool and returns a label.
1144 DWLabel NewString(const std::string &String) {
1145 unsigned StringID = StringPool.insert(String);
1146 return DWLabel("string", StringID);
1149 /// NewDIEntry - Creates a new DIEntry to be a proxy for a debug information
1151 DIEntry *NewDIEntry(DIE *Entry = NULL) {
1155 FoldingSetNodeID ID;
1156 DIEntry::Profile(ID, Entry);
1158 Value = static_cast<DIEntry *>(ValuesSet.FindNodeOrInsertPos(ID, Where));
1160 if (Value) return Value;
1162 Value = new DIEntry(Entry);
1163 ValuesSet.InsertNode(Value, Where);
1165 Value = new DIEntry(Entry);
1168 Values.push_back(Value);
1172 /// SetDIEntry - Set a DIEntry once the debug information entry is defined.
1174 void SetDIEntry(DIEntry *Value, DIE *Entry) {
1175 Value->Entry = Entry;
1176 // Add to values set if not already there. If it is, we merely have a
1177 // duplicate in the values list (no harm.)
1178 ValuesSet.GetOrInsertNode(Value);
1181 /// AddUInt - Add an unsigned integer attribute data and value.
1183 void AddUInt(DIE *Die, unsigned Attribute, unsigned Form, uint64_t Integer) {
1184 if (!Form) Form = DIEInteger::BestForm(false, Integer);
1186 FoldingSetNodeID ID;
1187 DIEInteger::Profile(ID, Integer);
1189 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
1191 Value = new DIEInteger(Integer);
1192 ValuesSet.InsertNode(Value, Where);
1193 Values.push_back(Value);
1196 Die->AddValue(Attribute, Form, Value);
1199 /// AddSInt - Add an signed integer attribute data and value.
1201 void AddSInt(DIE *Die, unsigned Attribute, unsigned Form, int64_t Integer) {
1202 if (!Form) Form = DIEInteger::BestForm(true, Integer);
1204 FoldingSetNodeID ID;
1205 DIEInteger::Profile(ID, (uint64_t)Integer);
1207 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
1209 Value = new DIEInteger(Integer);
1210 ValuesSet.InsertNode(Value, Where);
1211 Values.push_back(Value);
1214 Die->AddValue(Attribute, Form, Value);
1217 /// AddString - Add a std::string attribute data and value.
1219 void AddString(DIE *Die, unsigned Attribute, unsigned Form,
1220 const std::string &String) {
1221 FoldingSetNodeID ID;
1222 DIEString::Profile(ID, String);
1224 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
1226 Value = new DIEString(String);
1227 ValuesSet.InsertNode(Value, Where);
1228 Values.push_back(Value);
1231 Die->AddValue(Attribute, Form, Value);
1234 /// AddLabel - Add a Dwarf label attribute data and value.
1236 void AddLabel(DIE *Die, unsigned Attribute, unsigned Form,
1237 const DWLabel &Label) {
1238 FoldingSetNodeID ID;
1239 DIEDwarfLabel::Profile(ID, Label);
1241 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
1243 Value = new DIEDwarfLabel(Label);
1244 ValuesSet.InsertNode(Value, Where);
1245 Values.push_back(Value);
1248 Die->AddValue(Attribute, Form, Value);
1251 /// AddObjectLabel - Add an non-Dwarf label attribute data and value.
1253 void AddObjectLabel(DIE *Die, unsigned Attribute, unsigned Form,
1254 const std::string &Label) {
1255 FoldingSetNodeID ID;
1256 DIEObjectLabel::Profile(ID, Label);
1258 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
1260 Value = new DIEObjectLabel(Label);
1261 ValuesSet.InsertNode(Value, Where);
1262 Values.push_back(Value);
1265 Die->AddValue(Attribute, Form, Value);
1268 /// AddDelta - Add a label delta attribute data and value.
1270 void AddDelta(DIE *Die, unsigned Attribute, unsigned Form,
1271 const DWLabel &Hi, const DWLabel &Lo) {
1272 FoldingSetNodeID ID;
1273 DIEDelta::Profile(ID, Hi, Lo);
1275 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
1277 Value = new DIEDelta(Hi, Lo);
1278 ValuesSet.InsertNode(Value, Where);
1279 Values.push_back(Value);
1282 Die->AddValue(Attribute, Form, Value);
1285 /// AddDIEntry - Add a DIE attribute data and value.
1287 void AddDIEntry(DIE *Die, unsigned Attribute, unsigned Form, DIE *Entry) {
1288 Die->AddValue(Attribute, Form, NewDIEntry(Entry));
1291 /// AddBlock - Add block data.
1293 void AddBlock(DIE *Die, unsigned Attribute, unsigned Form, DIEBlock *Block) {
1294 Block->ComputeSize(*this);
1295 FoldingSetNodeID ID;
1298 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
1301 ValuesSet.InsertNode(Value, Where);
1302 Values.push_back(Value);
1304 // Already exists, reuse the previous one.
1306 Block = cast<DIEBlock>(Value);
1309 Die->AddValue(Attribute, Block->BestForm(), Value);
1314 /// AddSourceLine - Add location information to specified debug information
1316 void AddSourceLine(DIE *Die, CompileUnitDesc *File, unsigned Line) {
1318 CompileUnit *FileUnit = FindCompileUnit(File);
1319 unsigned FileID = FileUnit->getID();
1320 AddUInt(Die, DW_AT_decl_file, 0, FileID);
1321 AddUInt(Die, DW_AT_decl_line, 0, Line);
1325 /// AddAddress - Add an address attribute to a die based on the location
1327 void AddAddress(DIE *Die, unsigned Attribute,
1328 const MachineLocation &Location) {
1329 unsigned Reg = RI->getDwarfRegNum(Location.getRegister());
1330 DIEBlock *Block = new DIEBlock();
1332 if (Location.isRegister()) {
1334 AddUInt(Block, 0, DW_FORM_data1, DW_OP_reg0 + Reg);
1336 AddUInt(Block, 0, DW_FORM_data1, DW_OP_regx);
1337 AddUInt(Block, 0, DW_FORM_udata, Reg);
1341 AddUInt(Block, 0, DW_FORM_data1, DW_OP_breg0 + Reg);
1343 AddUInt(Block, 0, DW_FORM_data1, DW_OP_bregx);
1344 AddUInt(Block, 0, DW_FORM_udata, Reg);
1346 AddUInt(Block, 0, DW_FORM_sdata, Location.getOffset());
1349 AddBlock(Die, Attribute, 0, Block);
1352 /// AddBasicType - Add a new basic type attribute to the specified entity.
1354 void AddBasicType(DIE *Entity, CompileUnit *Unit,
1355 const std::string &Name,
1356 unsigned Encoding, unsigned Size) {
1357 DIE *Die = ConstructBasicType(Unit, Name, Encoding, Size);
1358 AddDIEntry(Entity, DW_AT_type, DW_FORM_ref4, Die);
1361 /// ConstructBasicType - Construct a new basic type.
1363 DIE *ConstructBasicType(CompileUnit *Unit,
1364 const std::string &Name,
1365 unsigned Encoding, unsigned Size) {
1366 DIE Buffer(DW_TAG_base_type);
1367 AddUInt(&Buffer, DW_AT_byte_size, 0, Size);
1368 AddUInt(&Buffer, DW_AT_encoding, DW_FORM_data1, Encoding);
1369 if (!Name.empty()) AddString(&Buffer, DW_AT_name, DW_FORM_string, Name);
1370 return Unit->AddDie(Buffer);
1373 /// AddPointerType - Add a new pointer type attribute to the specified entity.
1375 void AddPointerType(DIE *Entity, CompileUnit *Unit, const std::string &Name) {
1376 DIE *Die = ConstructPointerType(Unit, Name);
1377 AddDIEntry(Entity, DW_AT_type, DW_FORM_ref4, Die);
1380 /// ConstructPointerType - Construct a new pointer type.
1382 DIE *ConstructPointerType(CompileUnit *Unit, const std::string &Name) {
1383 DIE Buffer(DW_TAG_pointer_type);
1384 AddUInt(&Buffer, DW_AT_byte_size, 0, TAI->getAddressSize());
1385 if (!Name.empty()) AddString(&Buffer, DW_AT_name, DW_FORM_string, Name);
1386 return Unit->AddDie(Buffer);
1389 /// AddType - Add a new type attribute to the specified entity.
1391 void AddType(DIE *Entity, TypeDesc *TyDesc, CompileUnit *Unit) {
1393 AddBasicType(Entity, Unit, "", DW_ATE_signed, sizeof(int32_t));
1395 // Check for pre-existence.
1396 DIEntry *&Slot = Unit->getDIEntrySlotFor(TyDesc);
1398 // If it exists then use the existing value.
1400 Entity->AddValue(DW_AT_type, DW_FORM_ref4, Slot);
1404 if (SubprogramDesc *SubprogramTy = dyn_cast<SubprogramDesc>(TyDesc)) {
1405 // FIXME - Not sure why programs and variables are coming through here.
1406 // Short cut for handling subprogram types (not really a TyDesc.)
1407 AddPointerType(Entity, Unit, SubprogramTy->getName());
1408 } else if (GlobalVariableDesc *GlobalTy =
1409 dyn_cast<GlobalVariableDesc>(TyDesc)) {
1410 // FIXME - Not sure why programs and variables are coming through here.
1411 // Short cut for handling global variable types (not really a TyDesc.)
1412 AddPointerType(Entity, Unit, GlobalTy->getName());
1415 Slot = NewDIEntry();
1418 DIE Buffer(DW_TAG_base_type);
1419 ConstructType(Buffer, TyDesc, Unit);
1421 // Add debug information entry to entity and unit.
1422 DIE *Die = Unit->AddDie(Buffer);
1423 SetDIEntry(Slot, Die);
1424 Entity->AddValue(DW_AT_type, DW_FORM_ref4, Slot);
1429 /// ConstructType - Adds all the required attributes to the type.
1431 void ConstructType(DIE &Buffer, TypeDesc *TyDesc, CompileUnit *Unit) {
1432 // Get core information.
1433 const std::string &Name = TyDesc->getName();
1434 uint64_t Size = TyDesc->getSize() >> 3;
1436 if (BasicTypeDesc *BasicTy = dyn_cast<BasicTypeDesc>(TyDesc)) {
1437 // Fundamental types like int, float, bool
1438 Buffer.setTag(DW_TAG_base_type);
1439 AddUInt(&Buffer, DW_AT_encoding, DW_FORM_data1, BasicTy->getEncoding());
1440 } else if (DerivedTypeDesc *DerivedTy = dyn_cast<DerivedTypeDesc>(TyDesc)) {
1442 unsigned Tag = DerivedTy->getTag();
1443 // FIXME - Workaround for templates.
1444 if (Tag == DW_TAG_inheritance) Tag = DW_TAG_reference_type;
1445 // Pointers, typedefs et al.
1447 // Map to main type, void will not have a type.
1448 if (TypeDesc *FromTy = DerivedTy->getFromType())
1449 AddType(&Buffer, FromTy, Unit);
1450 } else if (CompositeTypeDesc *CompTy = dyn_cast<CompositeTypeDesc>(TyDesc)){
1452 unsigned Tag = CompTy->getTag();
1454 // Set tag accordingly.
1455 if (Tag == DW_TAG_vector_type)
1456 Buffer.setTag(DW_TAG_array_type);
1460 std::vector<DebugInfoDesc *> &Elements = CompTy->getElements();
1463 case DW_TAG_vector_type:
1464 AddUInt(&Buffer, DW_AT_GNU_vector, DW_FORM_flag, 1);
1466 case DW_TAG_array_type: {
1467 // Add element type.
1468 if (TypeDesc *FromTy = CompTy->getFromType())
1469 AddType(&Buffer, FromTy, Unit);
1471 // Don't emit size attribute.
1474 // Construct an anonymous type for index type.
1475 DIE *IndexTy = ConstructBasicType(Unit, "", DW_ATE_signed,
1478 // Add subranges to array type.
1479 for(unsigned i = 0, N = Elements.size(); i < N; ++i) {
1480 SubrangeDesc *SRD = cast<SubrangeDesc>(Elements[i]);
1481 int64_t Lo = SRD->getLo();
1482 int64_t Hi = SRD->getHi();
1483 DIE *Subrange = new DIE(DW_TAG_subrange_type);
1485 // If a range is available.
1487 AddDIEntry(Subrange, DW_AT_type, DW_FORM_ref4, IndexTy);
1488 // Only add low if non-zero.
1489 if (Lo) AddSInt(Subrange, DW_AT_lower_bound, 0, Lo);
1490 AddSInt(Subrange, DW_AT_upper_bound, 0, Hi);
1493 Buffer.AddChild(Subrange);
1497 case DW_TAG_structure_type:
1498 case DW_TAG_union_type: {
1499 // Add elements to structure type.
1500 for(unsigned i = 0, N = Elements.size(); i < N; ++i) {
1501 DebugInfoDesc *Element = Elements[i];
1503 if (DerivedTypeDesc *MemberDesc = dyn_cast<DerivedTypeDesc>(Element)){
1504 // Add field or base class.
1506 unsigned Tag = MemberDesc->getTag();
1508 // Extract the basic information.
1509 const std::string &Name = MemberDesc->getName();
1510 uint64_t Size = MemberDesc->getSize();
1511 uint64_t Align = MemberDesc->getAlign();
1512 uint64_t Offset = MemberDesc->getOffset();
1514 // Construct member debug information entry.
1515 DIE *Member = new DIE(Tag);
1517 // Add name if not "".
1519 AddString(Member, DW_AT_name, DW_FORM_string, Name);
1520 // Add location if available.
1521 AddSourceLine(Member, MemberDesc->getFile(), MemberDesc->getLine());
1523 // Most of the time the field info is the same as the members.
1524 uint64_t FieldSize = Size;
1525 uint64_t FieldAlign = Align;
1526 uint64_t FieldOffset = Offset;
1528 // Set the member type.
1529 TypeDesc *FromTy = MemberDesc->getFromType();
1530 AddType(Member, FromTy, Unit);
1532 // Walk up typedefs until a real size is found.
1534 if (FromTy->getTag() != DW_TAG_typedef) {
1535 FieldSize = FromTy->getSize();
1536 FieldAlign = FromTy->getSize();
1540 FromTy = cast<DerivedTypeDesc>(FromTy)->getFromType();
1543 // Unless we have a bit field.
1544 if (Tag == DW_TAG_member && FieldSize != Size) {
1545 // Construct the alignment mask.
1546 uint64_t AlignMask = ~(FieldAlign - 1);
1547 // Determine the high bit + 1 of the declared size.
1548 uint64_t HiMark = (Offset + FieldSize) & AlignMask;
1549 // Work backwards to determine the base offset of the field.
1550 FieldOffset = HiMark - FieldSize;
1551 // Now normalize offset to the field.
1552 Offset -= FieldOffset;
1554 // Maybe we need to work from the other end.
1555 if (TD->isLittleEndian()) Offset = FieldSize - (Offset + Size);
1557 // Add size and offset.
1558 AddUInt(Member, DW_AT_byte_size, 0, FieldSize >> 3);
1559 AddUInt(Member, DW_AT_bit_size, 0, Size);
1560 AddUInt(Member, DW_AT_bit_offset, 0, Offset);
1563 // Add computation for offset.
1564 DIEBlock *Block = new DIEBlock();
1565 AddUInt(Block, 0, DW_FORM_data1, DW_OP_plus_uconst);
1566 AddUInt(Block, 0, DW_FORM_udata, FieldOffset >> 3);
1567 AddBlock(Member, DW_AT_data_member_location, 0, Block);
1569 // Add accessibility (public default unless is base class.
1570 if (MemberDesc->isProtected()) {
1571 AddUInt(Member, DW_AT_accessibility, 0, DW_ACCESS_protected);
1572 } else if (MemberDesc->isPrivate()) {
1573 AddUInt(Member, DW_AT_accessibility, 0, DW_ACCESS_private);
1574 } else if (Tag == DW_TAG_inheritance) {
1575 AddUInt(Member, DW_AT_accessibility, 0, DW_ACCESS_public);
1578 Buffer.AddChild(Member);
1579 } else if (GlobalVariableDesc *StaticDesc =
1580 dyn_cast<GlobalVariableDesc>(Element)) {
1581 // Add static member.
1583 // Construct member debug information entry.
1584 DIE *Static = new DIE(DW_TAG_variable);
1586 // Add name and mangled name.
1587 const std::string &Name = StaticDesc->getName();
1588 const std::string &LinkageName = StaticDesc->getLinkageName();
1589 AddString(Static, DW_AT_name, DW_FORM_string, Name);
1590 if (!LinkageName.empty()) {
1591 AddString(Static, DW_AT_MIPS_linkage_name, DW_FORM_string,
1596 AddSourceLine(Static, StaticDesc->getFile(), StaticDesc->getLine());
1599 if (TypeDesc *StaticTy = StaticDesc->getType())
1600 AddType(Static, StaticTy, Unit);
1603 if (!StaticDesc->isStatic())
1604 AddUInt(Static, DW_AT_external, DW_FORM_flag, 1);
1605 AddUInt(Static, DW_AT_declaration, DW_FORM_flag, 1);
1607 Buffer.AddChild(Static);
1608 } else if (SubprogramDesc *MethodDesc =
1609 dyn_cast<SubprogramDesc>(Element)) {
1610 // Add member function.
1612 // Construct member debug information entry.
1613 DIE *Method = new DIE(DW_TAG_subprogram);
1615 // Add name and mangled name.
1616 const std::string &Name = MethodDesc->getName();
1617 const std::string &LinkageName = MethodDesc->getLinkageName();
1619 AddString(Method, DW_AT_name, DW_FORM_string, Name);
1620 bool IsCTor = TyDesc->getName() == Name;
1622 if (!LinkageName.empty()) {
1623 AddString(Method, DW_AT_MIPS_linkage_name, DW_FORM_string,
1628 AddSourceLine(Method, MethodDesc->getFile(), MethodDesc->getLine());
1631 if (CompositeTypeDesc *MethodTy =
1632 dyn_cast_or_null<CompositeTypeDesc>(MethodDesc->getType())) {
1633 // Get argument information.
1634 std::vector<DebugInfoDesc *> &Args = MethodTy->getElements();
1639 AddType(Method, dyn_cast<TypeDesc>(Args[0]), Unit);
1643 for(unsigned i = 1, N = Args.size(); i < N; ++i) {
1644 DIE *Arg = new DIE(DW_TAG_formal_parameter);
1645 AddType(Arg, cast<TypeDesc>(Args[i]), Unit);
1646 AddUInt(Arg, DW_AT_artificial, DW_FORM_flag, 1);
1647 Method->AddChild(Arg);
1652 if (!MethodDesc->isStatic())
1653 AddUInt(Method, DW_AT_external, DW_FORM_flag, 1);
1654 AddUInt(Method, DW_AT_declaration, DW_FORM_flag, 1);
1656 Buffer.AddChild(Method);
1661 case DW_TAG_enumeration_type: {
1662 // Add enumerators to enumeration type.
1663 for(unsigned i = 0, N = Elements.size(); i < N; ++i) {
1664 EnumeratorDesc *ED = cast<EnumeratorDesc>(Elements[i]);
1665 const std::string &Name = ED->getName();
1666 int64_t Value = ED->getValue();
1667 DIE *Enumerator = new DIE(DW_TAG_enumerator);
1668 AddString(Enumerator, DW_AT_name, DW_FORM_string, Name);
1669 AddSInt(Enumerator, DW_AT_const_value, DW_FORM_sdata, Value);
1670 Buffer.AddChild(Enumerator);
1675 case DW_TAG_subroutine_type: {
1676 // Add prototype flag.
1677 AddUInt(&Buffer, DW_AT_prototyped, DW_FORM_flag, 1);
1679 AddType(&Buffer, dyn_cast<TypeDesc>(Elements[0]), Unit);
1682 for(unsigned i = 1, N = Elements.size(); i < N; ++i) {
1683 DIE *Arg = new DIE(DW_TAG_formal_parameter);
1684 AddType(Arg, cast<TypeDesc>(Elements[i]), Unit);
1685 Buffer.AddChild(Arg);
1694 // Add size if non-zero (derived types don't have a size.)
1695 if (Size) AddUInt(&Buffer, DW_AT_byte_size, 0, Size);
1696 // Add name if not anonymous or intermediate type.
1697 if (!Name.empty()) AddString(&Buffer, DW_AT_name, DW_FORM_string, Name);
1698 // Add source line info if available.
1699 AddSourceLine(&Buffer, TyDesc->getFile(), TyDesc->getLine());
1702 /// NewCompileUnit - Create new compile unit and it's debug information entry.
1704 CompileUnit *NewCompileUnit(CompileUnitDesc *UnitDesc, unsigned ID) {
1705 // Construct debug information entry.
1706 DIE *Die = new DIE(DW_TAG_compile_unit);
1707 if (TAI->isAbsoluteDebugSectionOffsets())
1708 AddLabel(Die, DW_AT_stmt_list, DW_FORM_data4, DWLabel("section_line", 0));
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 if (!GVD->isStatic())
1769 AddUInt(VariableDie, DW_AT_external, DW_FORM_flag, 1);
1771 // Add source line info if available.
1772 AddSourceLine(VariableDie, UnitDesc, GVD->getLine());
1775 DIEBlock *Block = new DIEBlock();
1776 AddUInt(Block, 0, DW_FORM_data1, DW_OP_addr);
1777 AddObjectLabel(Block, 0, DW_FORM_udata, Asm->getGlobalLinkName(GV));
1778 AddBlock(VariableDie, DW_AT_location, 0, Block);
1783 // Add to context owner.
1784 Unit->getDie()->AddChild(VariableDie);
1786 // Expose as global.
1787 // FIXME - need to check external flag.
1788 Unit->AddGlobal(FullName, VariableDie);
1793 /// NewSubprogram - Add a new subprogram DIE.
1795 DIE *NewSubprogram(SubprogramDesc *SPD) {
1796 // Get the compile unit context.
1797 CompileUnitDesc *UnitDesc =
1798 static_cast<CompileUnitDesc *>(SPD->getContext());
1799 CompileUnit *Unit = GetBaseCompileUnit();
1801 // Check for pre-existence.
1802 DIE *&Slot = Unit->getDieMapSlotFor(SPD);
1803 if (Slot) return Slot;
1805 // Gather the details (simplify add attribute code.)
1806 const std::string &Name = SPD->getName();
1807 const std::string &FullName = SPD->getFullName();
1808 const std::string &LinkageName = SPD->getLinkageName();
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 if (!SPD->isStatic())
1818 AddUInt(SubprogramDie, DW_AT_external, DW_FORM_flag, 1);
1819 AddUInt(SubprogramDie, DW_AT_prototyped, DW_FORM_flag, 1);
1821 // Add source line info if available.
1822 AddSourceLine(SubprogramDie, UnitDesc, SPD->getLine());
1825 Slot = SubprogramDie;
1827 // Add to context owner.
1828 Unit->getDie()->AddChild(SubprogramDie);
1830 // Expose as global.
1831 Unit->AddGlobal(FullName, SubprogramDie);
1833 return SubprogramDie;
1836 /// NewScopeVariable - Create a new scope variable.
1838 DIE *NewScopeVariable(DebugVariable *DV, CompileUnit *Unit) {
1839 // Get the descriptor.
1840 VariableDesc *VD = DV->getDesc();
1842 // Translate tag to proper Dwarf tag. The result variable is dropped for
1845 switch (VD->getTag()) {
1846 case DW_TAG_return_variable: return NULL;
1847 case DW_TAG_arg_variable: Tag = DW_TAG_formal_parameter; break;
1848 case DW_TAG_auto_variable: // fall thru
1849 default: Tag = DW_TAG_variable; break;
1852 // Define variable debug information entry.
1853 DIE *VariableDie = new DIE(Tag);
1854 AddString(VariableDie, DW_AT_name, DW_FORM_string, VD->getName());
1856 // Add source line info if available.
1857 AddSourceLine(VariableDie, VD->getFile(), VD->getLine());
1859 // Add variable type.
1860 AddType(VariableDie, VD->getType(), Unit);
1862 // Add variable address.
1863 MachineLocation Location;
1864 RI->getLocation(*MF, DV->getFrameIndex(), Location);
1865 AddAddress(VariableDie, DW_AT_location, Location);
1870 /// ConstructScope - Construct the components of a scope.
1872 void ConstructScope(DebugScope *ParentScope,
1873 unsigned ParentStartID, unsigned ParentEndID,
1874 DIE *ParentDie, CompileUnit *Unit) {
1875 // Add variables to scope.
1876 std::vector<DebugVariable *> &Variables = ParentScope->getVariables();
1877 for (unsigned i = 0, N = Variables.size(); i < N; ++i) {
1878 DIE *VariableDie = NewScopeVariable(Variables[i], Unit);
1879 if (VariableDie) ParentDie->AddChild(VariableDie);
1882 // Add nested scopes.
1883 std::vector<DebugScope *> &Scopes = ParentScope->getScopes();
1884 for (unsigned j = 0, M = Scopes.size(); j < M; ++j) {
1885 // Define the Scope debug information entry.
1886 DebugScope *Scope = Scopes[j];
1887 // FIXME - Ignore inlined functions for the time being.
1888 if (!Scope->getParent()) continue;
1890 unsigned StartID = MMI->MappedLabel(Scope->getStartLabelID());
1891 unsigned EndID = MMI->MappedLabel(Scope->getEndLabelID());
1893 // Ignore empty scopes.
1894 if (StartID == EndID && StartID != 0) continue;
1895 if (Scope->getScopes().empty() && Scope->getVariables().empty()) continue;
1897 if (StartID == ParentStartID && EndID == ParentEndID) {
1898 // Just add stuff to the parent scope.
1899 ConstructScope(Scope, ParentStartID, ParentEndID, ParentDie, Unit);
1901 DIE *ScopeDie = new DIE(DW_TAG_lexical_block);
1903 // Add the scope bounds.
1905 AddLabel(ScopeDie, DW_AT_low_pc, DW_FORM_addr,
1906 DWLabel("label", StartID));
1908 AddLabel(ScopeDie, DW_AT_low_pc, DW_FORM_addr,
1909 DWLabel("func_begin", SubprogramCount));
1912 AddLabel(ScopeDie, DW_AT_high_pc, DW_FORM_addr,
1913 DWLabel("label", EndID));
1915 AddLabel(ScopeDie, DW_AT_high_pc, DW_FORM_addr,
1916 DWLabel("func_end", SubprogramCount));
1919 // Add the scope contents.
1920 ConstructScope(Scope, StartID, EndID, ScopeDie, Unit);
1921 ParentDie->AddChild(ScopeDie);
1926 /// ConstructRootScope - Construct the scope for the subprogram.
1928 void ConstructRootScope(DebugScope *RootScope) {
1929 // Exit if there is no root scope.
1930 if (!RootScope) return;
1932 // Get the subprogram debug information entry.
1933 SubprogramDesc *SPD = cast<SubprogramDesc>(RootScope->getDesc());
1935 // Get the compile unit context.
1936 CompileUnit *Unit = GetBaseCompileUnit();
1938 // Get the subprogram die.
1939 DIE *SPDie = Unit->getDieMapSlotFor(SPD);
1940 assert(SPDie && "Missing subprogram descriptor");
1942 // Add the function bounds.
1943 AddLabel(SPDie, DW_AT_low_pc, DW_FORM_addr,
1944 DWLabel("func_begin", SubprogramCount));
1945 AddLabel(SPDie, DW_AT_high_pc, DW_FORM_addr,
1946 DWLabel("func_end", SubprogramCount));
1947 MachineLocation Location(RI->getFrameRegister(*MF));
1948 AddAddress(SPDie, DW_AT_frame_base, Location);
1950 ConstructScope(RootScope, 0, 0, SPDie, Unit);
1953 /// EmitInitial - Emit initial Dwarf declarations. This is necessary for cc
1954 /// tools to recognize the object file contains Dwarf information.
1955 void EmitInitial() {
1956 // Check to see if we already emitted intial headers.
1957 if (didInitial) return;
1960 // Dwarf sections base addresses.
1961 if (TAI->doesDwarfRequireFrameSection()) {
1962 Asm->SwitchToDataSection(TAI->getDwarfFrameSection());
1963 EmitLabel("section_debug_frame", 0);
1965 Asm->SwitchToDataSection(TAI->getDwarfInfoSection());
1966 EmitLabel("section_info", 0);
1967 Asm->SwitchToDataSection(TAI->getDwarfAbbrevSection());
1968 EmitLabel("section_abbrev", 0);
1969 Asm->SwitchToDataSection(TAI->getDwarfARangesSection());
1970 EmitLabel("section_aranges", 0);
1971 Asm->SwitchToDataSection(TAI->getDwarfMacInfoSection());
1972 EmitLabel("section_macinfo", 0);
1973 Asm->SwitchToDataSection(TAI->getDwarfLineSection());
1974 EmitLabel("section_line", 0);
1975 Asm->SwitchToDataSection(TAI->getDwarfLocSection());
1976 EmitLabel("section_loc", 0);
1977 Asm->SwitchToDataSection(TAI->getDwarfPubNamesSection());
1978 EmitLabel("section_pubnames", 0);
1979 Asm->SwitchToDataSection(TAI->getDwarfStrSection());
1980 EmitLabel("section_str", 0);
1981 Asm->SwitchToDataSection(TAI->getDwarfRangesSection());
1982 EmitLabel("section_ranges", 0);
1984 Asm->SwitchToTextSection(TAI->getTextSection());
1985 EmitLabel("text_begin", 0);
1986 Asm->SwitchToDataSection(TAI->getDataSection());
1987 EmitLabel("data_begin", 0);
1990 /// EmitDIE - Recusively Emits a debug information entry.
1992 void EmitDIE(DIE *Die) {
1993 // Get the abbreviation for this DIE.
1994 unsigned AbbrevNumber = Die->getAbbrevNumber();
1995 const DIEAbbrev *Abbrev = Abbreviations[AbbrevNumber - 1];
1999 // Emit the code (index) for the abbreviation.
2000 Asm->EmitULEB128Bytes(AbbrevNumber);
2001 Asm->EOL(std::string("Abbrev [" +
2002 utostr(AbbrevNumber) +
2003 "] 0x" + utohexstr(Die->getOffset()) +
2004 ":0x" + utohexstr(Die->getSize()) + " " +
2005 TagString(Abbrev->getTag())));
2007 std::vector<DIEValue *> &Values = Die->getValues();
2008 const std::vector<DIEAbbrevData> &AbbrevData = Abbrev->getData();
2010 // Emit the DIE attribute values.
2011 for (unsigned i = 0, N = Values.size(); i < N; ++i) {
2012 unsigned Attr = AbbrevData[i].getAttribute();
2013 unsigned Form = AbbrevData[i].getForm();
2014 assert(Form && "Too many attributes for DIE (check abbreviation)");
2017 case DW_AT_sibling: {
2018 Asm->EmitInt32(Die->SiblingOffset());
2022 // Emit an attribute using the defined form.
2023 Values[i]->EmitValue(*this, Form);
2028 Asm->EOL(AttributeString(Attr));
2031 // Emit the DIE children if any.
2032 if (Abbrev->getChildrenFlag() == DW_CHILDREN_yes) {
2033 const std::vector<DIE *> &Children = Die->getChildren();
2035 for (unsigned j = 0, M = Children.size(); j < M; ++j) {
2036 EmitDIE(Children[j]);
2039 Asm->EmitInt8(0); Asm->EOL("End Of Children Mark");
2043 /// SizeAndOffsetDie - Compute the size and offset of a DIE.
2045 unsigned SizeAndOffsetDie(DIE *Die, unsigned Offset, bool Last) {
2046 // Get the children.
2047 const std::vector<DIE *> &Children = Die->getChildren();
2049 // If not last sibling and has children then add sibling offset attribute.
2050 if (!Last && !Children.empty()) Die->AddSiblingOffset();
2052 // Record the abbreviation.
2053 AssignAbbrevNumber(Die->getAbbrev());
2055 // Get the abbreviation for this DIE.
2056 unsigned AbbrevNumber = Die->getAbbrevNumber();
2057 const DIEAbbrev *Abbrev = Abbreviations[AbbrevNumber - 1];
2060 Die->setOffset(Offset);
2062 // Start the size with the size of abbreviation code.
2063 Offset += Asm->SizeULEB128(AbbrevNumber);
2065 const std::vector<DIEValue *> &Values = Die->getValues();
2066 const std::vector<DIEAbbrevData> &AbbrevData = Abbrev->getData();
2068 // Size the DIE attribute values.
2069 for (unsigned i = 0, N = Values.size(); i < N; ++i) {
2070 // Size attribute value.
2071 Offset += Values[i]->SizeOf(*this, AbbrevData[i].getForm());
2074 // Size the DIE children if any.
2075 if (!Children.empty()) {
2076 assert(Abbrev->getChildrenFlag() == DW_CHILDREN_yes &&
2077 "Children flag not set");
2079 for (unsigned j = 0, M = Children.size(); j < M; ++j) {
2080 Offset = SizeAndOffsetDie(Children[j], Offset, (j + 1) == M);
2083 // End of children marker.
2084 Offset += sizeof(int8_t);
2087 Die->setSize(Offset - Die->getOffset());
2091 /// SizeAndOffsets - Compute the size and offset of all the DIEs.
2093 void SizeAndOffsets() {
2094 // Process base compile unit.
2095 CompileUnit *Unit = GetBaseCompileUnit();
2096 // Compute size of compile unit header
2097 unsigned Offset = sizeof(int32_t) + // Length of Compilation Unit Info
2098 sizeof(int16_t) + // DWARF version number
2099 sizeof(int32_t) + // Offset Into Abbrev. Section
2100 sizeof(int8_t); // Pointer Size (in bytes)
2101 SizeAndOffsetDie(Unit->getDie(), Offset, true);
2104 /// EmitDebugInfo - Emit the debug info section.
2106 void EmitDebugInfo() {
2107 // Start debug info section.
2108 Asm->SwitchToDataSection(TAI->getDwarfInfoSection());
2110 CompileUnit *Unit = GetBaseCompileUnit();
2111 DIE *Die = Unit->getDie();
2112 // Emit the compile units header.
2113 EmitLabel("info_begin", Unit->getID());
2114 // Emit size of content not including length itself
2115 unsigned ContentSize = Die->getSize() +
2116 sizeof(int16_t) + // DWARF version number
2117 sizeof(int32_t) + // Offset Into Abbrev. Section
2118 sizeof(int8_t) + // Pointer Size (in bytes)
2119 sizeof(int32_t); // FIXME - extra pad for gdb bug.
2121 Asm->EmitInt32(ContentSize); Asm->EOL("Length of Compilation Unit Info");
2122 Asm->EmitInt16(DWARF_VERSION); Asm->EOL("DWARF version number");
2123 EmitSectionOffset("abbrev_begin", "section_abbrev", 0, 0, true, false);
2124 Asm->EOL("Offset Into Abbrev. Section");
2125 Asm->EmitInt8(TAI->getAddressSize()); Asm->EOL("Address Size (in bytes)");
2128 // FIXME - extra padding for gdb bug.
2129 Asm->EmitInt8(0); Asm->EOL("Extra Pad For GDB");
2130 Asm->EmitInt8(0); Asm->EOL("Extra Pad For GDB");
2131 Asm->EmitInt8(0); Asm->EOL("Extra Pad For GDB");
2132 Asm->EmitInt8(0); Asm->EOL("Extra Pad For GDB");
2133 EmitLabel("info_end", Unit->getID());
2138 /// EmitAbbreviations - Emit the abbreviation section.
2140 void EmitAbbreviations() const {
2141 // Check to see if it is worth the effort.
2142 if (!Abbreviations.empty()) {
2143 // Start the debug abbrev section.
2144 Asm->SwitchToDataSection(TAI->getDwarfAbbrevSection());
2146 EmitLabel("abbrev_begin", 0);
2148 // For each abbrevation.
2149 for (unsigned i = 0, N = Abbreviations.size(); i < N; ++i) {
2150 // Get abbreviation data
2151 const DIEAbbrev *Abbrev = Abbreviations[i];
2153 // Emit the abbrevations code (base 1 index.)
2154 Asm->EmitULEB128Bytes(Abbrev->getNumber());
2155 Asm->EOL("Abbreviation Code");
2157 // Emit the abbreviations data.
2158 Abbrev->Emit(*this);
2163 // Mark end of abbreviations.
2164 Asm->EmitULEB128Bytes(0); Asm->EOL("EOM(3)");
2166 EmitLabel("abbrev_end", 0);
2172 /// EmitDebugLines - Emit source line information.
2174 void EmitDebugLines() {
2175 // Minimum line delta, thus ranging from -10..(255-10).
2176 const int MinLineDelta = -(DW_LNS_fixed_advance_pc + 1);
2177 // Maximum line delta, thus ranging from -10..(255-10).
2178 const int MaxLineDelta = 255 + MinLineDelta;
2180 // Start the dwarf line section.
2181 Asm->SwitchToDataSection(TAI->getDwarfLineSection());
2183 // Construct the section header.
2185 EmitDifference("line_end", 0, "line_begin", 0, true);
2186 Asm->EOL("Length of Source Line Info");
2187 EmitLabel("line_begin", 0);
2189 Asm->EmitInt16(DWARF_VERSION); Asm->EOL("DWARF version number");
2191 EmitDifference("line_prolog_end", 0, "line_prolog_begin", 0, true);
2192 Asm->EOL("Prolog Length");
2193 EmitLabel("line_prolog_begin", 0);
2195 Asm->EmitInt8(1); Asm->EOL("Minimum Instruction Length");
2197 Asm->EmitInt8(1); Asm->EOL("Default is_stmt_start flag");
2199 Asm->EmitInt8(MinLineDelta); Asm->EOL("Line Base Value (Special Opcodes)");
2201 Asm->EmitInt8(MaxLineDelta); Asm->EOL("Line Range Value (Special Opcodes)");
2203 Asm->EmitInt8(-MinLineDelta); Asm->EOL("Special Opcode Base");
2205 // Line number standard opcode encodings argument count
2206 Asm->EmitInt8(0); Asm->EOL("DW_LNS_copy arg count");
2207 Asm->EmitInt8(1); Asm->EOL("DW_LNS_advance_pc arg count");
2208 Asm->EmitInt8(1); Asm->EOL("DW_LNS_advance_line arg count");
2209 Asm->EmitInt8(1); Asm->EOL("DW_LNS_set_file arg count");
2210 Asm->EmitInt8(1); Asm->EOL("DW_LNS_set_column arg count");
2211 Asm->EmitInt8(0); Asm->EOL("DW_LNS_negate_stmt arg count");
2212 Asm->EmitInt8(0); Asm->EOL("DW_LNS_set_basic_block arg count");
2213 Asm->EmitInt8(0); Asm->EOL("DW_LNS_const_add_pc arg count");
2214 Asm->EmitInt8(1); Asm->EOL("DW_LNS_fixed_advance_pc arg count");
2216 const UniqueVector<std::string> &Directories = MMI->getDirectories();
2217 const UniqueVector<SourceFileInfo>
2218 &SourceFiles = MMI->getSourceFiles();
2220 // Emit directories.
2221 for (unsigned DirectoryID = 1, NDID = Directories.size();
2222 DirectoryID <= NDID; ++DirectoryID) {
2223 Asm->EmitString(Directories[DirectoryID]); Asm->EOL("Directory");
2225 Asm->EmitInt8(0); Asm->EOL("End of directories");
2228 for (unsigned SourceID = 1, NSID = SourceFiles.size();
2229 SourceID <= NSID; ++SourceID) {
2230 const SourceFileInfo &SourceFile = SourceFiles[SourceID];
2231 Asm->EmitString(SourceFile.getName());
2233 Asm->EmitULEB128Bytes(SourceFile.getDirectoryID());
2234 Asm->EOL("Directory #");
2235 Asm->EmitULEB128Bytes(0);
2236 Asm->EOL("Mod date");
2237 Asm->EmitULEB128Bytes(0);
2238 Asm->EOL("File size");
2240 Asm->EmitInt8(0); Asm->EOL("End of files");
2242 EmitLabel("line_prolog_end", 0);
2244 // A sequence for each text section.
2245 for (unsigned j = 0, M = SectionSourceLines.size(); j < M; ++j) {
2246 // Isolate current sections line info.
2247 const std::vector<SourceLineInfo> &LineInfos = SectionSourceLines[j];
2249 Asm->EOL(std::string("Section ") + SectionMap[j + 1]);
2251 // Dwarf assumes we start with first line of first source file.
2252 unsigned Source = 1;
2255 // Construct rows of the address, source, line, column matrix.
2256 for (unsigned i = 0, N = LineInfos.size(); i < N; ++i) {
2257 const SourceLineInfo &LineInfo = LineInfos[i];
2258 unsigned LabelID = MMI->MappedLabel(LineInfo.getLabelID());
2259 if (!LabelID) continue;
2261 unsigned SourceID = LineInfo.getSourceID();
2262 const SourceFileInfo &SourceFile = SourceFiles[SourceID];
2263 unsigned DirectoryID = SourceFile.getDirectoryID();
2264 Asm->EOL(Directories[DirectoryID]
2265 + SourceFile.getName()
2267 + utostr_32(LineInfo.getLine()));
2269 // Define the line address.
2270 Asm->EmitInt8(0); Asm->EOL("Extended Op");
2271 Asm->EmitInt8(TAI->getAddressSize() + 1); Asm->EOL("Op size");
2272 Asm->EmitInt8(DW_LNE_set_address); Asm->EOL("DW_LNE_set_address");
2273 EmitReference("label", LabelID); Asm->EOL("Location label");
2275 // If change of source, then switch to the new source.
2276 if (Source != LineInfo.getSourceID()) {
2277 Source = LineInfo.getSourceID();
2278 Asm->EmitInt8(DW_LNS_set_file); Asm->EOL("DW_LNS_set_file");
2279 Asm->EmitULEB128Bytes(Source); Asm->EOL("New Source");
2282 // If change of line.
2283 if (Line != LineInfo.getLine()) {
2284 // Determine offset.
2285 int Offset = LineInfo.getLine() - Line;
2286 int Delta = Offset - MinLineDelta;
2289 Line = LineInfo.getLine();
2291 // If delta is small enough and in range...
2292 if (Delta >= 0 && Delta < (MaxLineDelta - 1)) {
2293 // ... then use fast opcode.
2294 Asm->EmitInt8(Delta - MinLineDelta); Asm->EOL("Line Delta");
2296 // ... otherwise use long hand.
2297 Asm->EmitInt8(DW_LNS_advance_line); Asm->EOL("DW_LNS_advance_line");
2298 Asm->EmitSLEB128Bytes(Offset); Asm->EOL("Line Offset");
2299 Asm->EmitInt8(DW_LNS_copy); Asm->EOL("DW_LNS_copy");
2302 // Copy the previous row (different address or source)
2303 Asm->EmitInt8(DW_LNS_copy); Asm->EOL("DW_LNS_copy");
2307 // Define last address of section.
2308 Asm->EmitInt8(0); Asm->EOL("Extended Op");
2309 Asm->EmitInt8(TAI->getAddressSize() + 1); Asm->EOL("Op size");
2310 Asm->EmitInt8(DW_LNE_set_address); Asm->EOL("DW_LNE_set_address");
2311 EmitReference("section_end", j + 1); Asm->EOL("Section end label");
2313 // Mark end of matrix.
2314 Asm->EmitInt8(0); Asm->EOL("DW_LNE_end_sequence");
2315 Asm->EmitULEB128Bytes(1); Asm->EOL();
2316 Asm->EmitInt8(1); Asm->EOL();
2319 EmitLabel("line_end", 0);
2324 /// EmitCommonDebugFrame - Emit common frame info into a debug frame section.
2326 void EmitCommonDebugFrame() {
2327 if (!TAI->doesDwarfRequireFrameSection())
2331 Asm->TM.getFrameInfo()->getStackGrowthDirection() ==
2332 TargetFrameInfo::StackGrowsUp ?
2333 TAI->getAddressSize() : -TAI->getAddressSize();
2335 // Start the dwarf frame section.
2336 Asm->SwitchToDataSection(TAI->getDwarfFrameSection());
2338 EmitLabel("debug_frame_common", 0);
2339 EmitDifference("debug_frame_common_end", 0,
2340 "debug_frame_common_begin", 0, true);
2341 Asm->EOL("Length of Common Information Entry");
2343 EmitLabel("debug_frame_common_begin", 0);
2344 Asm->EmitInt32((int)DW_CIE_ID);
2345 Asm->EOL("CIE Identifier Tag");
2346 Asm->EmitInt8(DW_CIE_VERSION);
2347 Asm->EOL("CIE Version");
2348 Asm->EmitString("");
2349 Asm->EOL("CIE Augmentation");
2350 Asm->EmitULEB128Bytes(1);
2351 Asm->EOL("CIE Code Alignment Factor");
2352 Asm->EmitSLEB128Bytes(stackGrowth);
2353 Asm->EOL("CIE Data Alignment Factor");
2354 Asm->EmitInt8(RI->getDwarfRegNum(RI->getRARegister()));
2355 Asm->EOL("CIE RA Column");
2357 std::vector<MachineMove> Moves;
2358 RI->getInitialFrameState(Moves);
2360 EmitFrameMoves(NULL, 0, Moves);
2362 Asm->EmitAlignment(2);
2363 EmitLabel("debug_frame_common_end", 0);
2368 /// EmitFunctionDebugFrame - Emit per function frame info into a debug frame
2370 void EmitFunctionDebugFrame(const FunctionDebugFrameInfo &DebugFrameInfo) {
2371 if (!TAI->doesDwarfRequireFrameSection())
2374 // Start the dwarf frame section.
2375 Asm->SwitchToDataSection(TAI->getDwarfFrameSection());
2377 EmitDifference("debug_frame_end", DebugFrameInfo.Number,
2378 "debug_frame_begin", DebugFrameInfo.Number, true);
2379 Asm->EOL("Length of Frame Information Entry");
2381 EmitLabel("debug_frame_begin", DebugFrameInfo.Number);
2383 EmitSectionOffset("debug_frame_common", "section_debug_frame",
2385 Asm->EOL("FDE CIE offset");
2387 EmitReference("func_begin", DebugFrameInfo.Number);
2388 Asm->EOL("FDE initial location");
2389 EmitDifference("func_end", DebugFrameInfo.Number,
2390 "func_begin", DebugFrameInfo.Number);
2391 Asm->EOL("FDE address range");
2393 EmitFrameMoves("func_begin", DebugFrameInfo.Number, DebugFrameInfo.Moves);
2395 Asm->EmitAlignment(2);
2396 EmitLabel("debug_frame_end", DebugFrameInfo.Number);
2401 /// EmitDebugPubNames - Emit visible names into a debug pubnames section.
2403 void EmitDebugPubNames() {
2404 // Start the dwarf pubnames section.
2405 Asm->SwitchToDataSection(TAI->getDwarfPubNamesSection());
2407 CompileUnit *Unit = GetBaseCompileUnit();
2409 EmitDifference("pubnames_end", Unit->getID(),
2410 "pubnames_begin", Unit->getID(), true);
2411 Asm->EOL("Length of Public Names Info");
2413 EmitLabel("pubnames_begin", Unit->getID());
2415 Asm->EmitInt16(DWARF_VERSION); Asm->EOL("DWARF Version");
2417 EmitSectionOffset("info_begin", "section_info",
2418 Unit->getID(), 0, true, false);
2419 Asm->EOL("Offset of Compilation Unit Info");
2421 EmitDifference("info_end", Unit->getID(), "info_begin", Unit->getID(),true);
2422 Asm->EOL("Compilation Unit Length");
2424 std::map<std::string, DIE *> &Globals = Unit->getGlobals();
2426 for (std::map<std::string, DIE *>::iterator GI = Globals.begin(),
2429 const std::string &Name = GI->first;
2430 DIE * Entity = GI->second;
2432 Asm->EmitInt32(Entity->getOffset()); Asm->EOL("DIE offset");
2433 Asm->EmitString(Name); Asm->EOL("External Name");
2436 Asm->EmitInt32(0); Asm->EOL("End Mark");
2437 EmitLabel("pubnames_end", Unit->getID());
2442 /// EmitDebugStr - Emit visible names into a debug str section.
2444 void EmitDebugStr() {
2445 // Check to see if it is worth the effort.
2446 if (!StringPool.empty()) {
2447 // Start the dwarf str section.
2448 Asm->SwitchToDataSection(TAI->getDwarfStrSection());
2450 // For each of strings in the string pool.
2451 for (unsigned StringID = 1, N = StringPool.size();
2452 StringID <= N; ++StringID) {
2453 // Emit a label for reference from debug information entries.
2454 EmitLabel("string", StringID);
2455 // Emit the string itself.
2456 const std::string &String = StringPool[StringID];
2457 Asm->EmitString(String); Asm->EOL();
2464 /// EmitDebugLoc - Emit visible names into a debug loc section.
2466 void EmitDebugLoc() {
2467 // Start the dwarf loc section.
2468 Asm->SwitchToDataSection(TAI->getDwarfLocSection());
2473 /// EmitDebugARanges - Emit visible names into a debug aranges section.
2475 void EmitDebugARanges() {
2476 // Start the dwarf aranges section.
2477 Asm->SwitchToDataSection(TAI->getDwarfARangesSection());
2481 CompileUnit *Unit = GetBaseCompileUnit();
2483 // Don't include size of length
2484 Asm->EmitInt32(0x1c); Asm->EOL("Length of Address Ranges Info");
2486 Asm->EmitInt16(DWARF_VERSION); Asm->EOL("Dwarf Version");
2488 EmitReference("info_begin", Unit->getID());
2489 Asm->EOL("Offset of Compilation Unit Info");
2491 Asm->EmitInt8(TAI->getAddressSize()); Asm->EOL("Size of Address");
2493 Asm->EmitInt8(0); Asm->EOL("Size of Segment Descriptor");
2495 Asm->EmitInt16(0); Asm->EOL("Pad (1)");
2496 Asm->EmitInt16(0); Asm->EOL("Pad (2)");
2499 EmitReference("text_begin", 0); Asm->EOL("Address");
2500 EmitDifference("text_end", 0, "text_begin", 0, true); Asm->EOL("Length");
2502 Asm->EmitInt32(0); Asm->EOL("EOM (1)");
2503 Asm->EmitInt32(0); Asm->EOL("EOM (2)");
2509 /// EmitDebugRanges - Emit visible names into a debug ranges section.
2511 void EmitDebugRanges() {
2512 // Start the dwarf ranges section.
2513 Asm->SwitchToDataSection(TAI->getDwarfRangesSection());
2518 /// EmitDebugMacInfo - Emit visible names into a debug macinfo section.
2520 void EmitDebugMacInfo() {
2521 // Start the dwarf macinfo section.
2522 Asm->SwitchToDataSection(TAI->getDwarfMacInfoSection());
2527 /// ConstructCompileUnitDIEs - Create a compile unit DIE for each source and
2529 void ConstructCompileUnitDIEs() {
2530 const UniqueVector<CompileUnitDesc *> CUW = MMI->getCompileUnits();
2532 for (unsigned i = 1, N = CUW.size(); i <= N; ++i) {
2533 unsigned ID = MMI->RecordSource(CUW[i]);
2534 CompileUnit *Unit = NewCompileUnit(CUW[i], ID);
2535 CompileUnits.push_back(Unit);
2539 /// ConstructGlobalDIEs - Create DIEs for each of the externally visible
2540 /// global variables.
2541 void ConstructGlobalDIEs() {
2542 std::vector<GlobalVariableDesc *> GlobalVariables =
2543 MMI->getAnchoredDescriptors<GlobalVariableDesc>(*M);
2545 for (unsigned i = 0, N = GlobalVariables.size(); i < N; ++i) {
2546 GlobalVariableDesc *GVD = GlobalVariables[i];
2547 NewGlobalVariable(GVD);
2551 /// ConstructSubprogramDIEs - Create DIEs for each of the externally visible
2553 void ConstructSubprogramDIEs() {
2554 std::vector<SubprogramDesc *> Subprograms =
2555 MMI->getAnchoredDescriptors<SubprogramDesc>(*M);
2557 for (unsigned i = 0, N = Subprograms.size(); i < N; ++i) {
2558 SubprogramDesc *SPD = Subprograms[i];
2564 //===--------------------------------------------------------------------===//
2565 // Main entry points.
2567 DwarfDebug(std::ostream &OS, AsmPrinter *A, const TargetAsmInfo *T)
2570 , AbbreviationsSet(InitAbbreviationsSetSize)
2572 , ValuesSet(InitValuesSetSize)
2577 , SectionSourceLines()
2582 virtual ~DwarfDebug() {
2583 for (unsigned i = 0, N = CompileUnits.size(); i < N; ++i)
2584 delete CompileUnits[i];
2585 for (unsigned j = 0, M = Values.size(); j < M; ++j)
2589 /// SetModuleInfo - Set machine module information when it's known that pass
2590 /// manager has created it. Set by the target AsmPrinter.
2591 void SetModuleInfo(MachineModuleInfo *mmi) {
2592 // Make sure initial declarations are made.
2593 if (!MMI && mmi->hasDebugInfo()) {
2597 // Emit initial sections
2600 // Create all the compile unit DIEs.
2601 ConstructCompileUnitDIEs();
2603 // Create DIEs for each of the externally visible global variables.
2604 ConstructGlobalDIEs();
2606 // Create DIEs for each of the externally visible subprograms.
2607 ConstructSubprogramDIEs();
2609 // Prime section data.
2610 SectionMap.insert(TAI->getTextSection());
2614 /// BeginModule - Emit all Dwarf sections that should come prior to the
2616 void BeginModule(Module *M) {
2619 if (!ShouldEmitDwarf()) return;
2622 /// EndModule - Emit all Dwarf sections that should come after the content.
2625 if (!ShouldEmitDwarf()) return;
2627 // Standard sections final addresses.
2628 Asm->SwitchToTextSection(TAI->getTextSection());
2629 EmitLabel("text_end", 0);
2630 Asm->SwitchToDataSection(TAI->getDataSection());
2631 EmitLabel("data_end", 0);
2633 // End text sections.
2634 for (unsigned i = 1, N = SectionMap.size(); i <= N; ++i) {
2635 Asm->SwitchToTextSection(SectionMap[i].c_str());
2636 EmitLabel("section_end", i);
2639 // Emit common frame information.
2640 EmitCommonDebugFrame();
2642 // Emit function debug frame information
2643 for (std::vector<FunctionDebugFrameInfo>::iterator I = DebugFrames.begin(),
2644 E = DebugFrames.end(); I != E; ++I)
2645 EmitFunctionDebugFrame(*I);
2647 // Compute DIE offsets and sizes.
2650 // Emit all the DIEs into a debug info section
2653 // Corresponding abbreviations into a abbrev section.
2654 EmitAbbreviations();
2656 // Emit source line correspondence into a debug line section.
2659 // Emit info into a debug pubnames section.
2660 EmitDebugPubNames();
2662 // Emit info into a debug str section.
2665 // Emit info into a debug loc section.
2668 // Emit info into a debug aranges section.
2671 // Emit info into a debug ranges section.
2674 // Emit info into a debug macinfo section.
2678 /// BeginFunction - Gather pre-function debug information. Assumes being
2679 /// emitted immediately after the function entry point.
2680 void BeginFunction(MachineFunction *MF) {
2683 if (!ShouldEmitDwarf()) return;
2685 // Begin accumulating function debug information.
2686 MMI->BeginFunction(MF);
2688 // Assumes in correct section after the entry point.
2689 EmitLabel("func_begin", ++SubprogramCount);
2692 /// EndFunction - Gather and emit post-function debug information.
2694 void EndFunction() {
2695 if (!ShouldEmitDwarf()) return;
2697 // Define end label for subprogram.
2698 EmitLabel("func_end", SubprogramCount);
2700 // Get function line info.
2701 const std::vector<SourceLineInfo> &LineInfos = MMI->getSourceLines();
2703 if (!LineInfos.empty()) {
2704 // Get section line info.
2705 unsigned ID = SectionMap.insert(Asm->CurrentSection);
2706 if (SectionSourceLines.size() < ID) SectionSourceLines.resize(ID);
2707 std::vector<SourceLineInfo> &SectionLineInfos = SectionSourceLines[ID-1];
2708 // Append the function info to section info.
2709 SectionLineInfos.insert(SectionLineInfos.end(),
2710 LineInfos.begin(), LineInfos.end());
2713 // Construct scopes for subprogram.
2714 ConstructRootScope(MMI->getRootScope());
2716 DebugFrames.push_back(FunctionDebugFrameInfo(SubprogramCount,
2717 MMI->getFrameMoves()));
2721 //===----------------------------------------------------------------------===//
2722 /// DwarfException - Emits Dwarf exception handling directives.
2724 class DwarfException : public Dwarf {
2727 struct FunctionEHFrameInfo {
2730 unsigned PersonalityIndex;
2732 bool hasLandingPads;
2733 std::vector<MachineMove> Moves;
2735 FunctionEHFrameInfo(const std::string &FN, unsigned Num, unsigned P,
2737 const std::vector<MachineMove> &M):
2738 FnName(FN), Number(Num), PersonalityIndex(P),
2739 hasCalls(hC), hasLandingPads(hL), Moves(M) { }
2742 std::vector<FunctionEHFrameInfo> EHFrames;
2744 /// shouldEmit - Flag to indicate if debug information should be emitted.
2748 /// EmitCommonEHFrame - Emit the common eh unwind frame.
2750 void EmitCommonEHFrame(const Function *Personality, unsigned Index) {
2751 // Size and sign of stack growth.
2753 Asm->TM.getFrameInfo()->getStackGrowthDirection() ==
2754 TargetFrameInfo::StackGrowsUp ?
2755 TAI->getAddressSize() : -TAI->getAddressSize();
2757 // Begin eh frame section.
2758 Asm->SwitchToTextSection(TAI->getDwarfEHFrameSection());
2759 O << "EH_frame" << Index << ":\n";
2760 EmitLabel("section_eh_frame", Index);
2762 // Define base labels.
2763 EmitLabel("eh_frame_common", Index);
2765 // Define the eh frame length.
2766 EmitDifference("eh_frame_common_end", Index,
2767 "eh_frame_common_begin", Index, true);
2768 Asm->EOL("Length of Common Information Entry");
2771 EmitLabel("eh_frame_common_begin", Index);
2772 Asm->EmitInt32((int)0);
2773 Asm->EOL("CIE Identifier Tag");
2774 Asm->EmitInt8(DW_CIE_VERSION);
2775 Asm->EOL("CIE Version");
2777 // The personality presence indicates that language specific information
2778 // will show up in the eh frame.
2779 Asm->EmitString(Personality ? "zPLR" : "zR");
2780 Asm->EOL("CIE Augmentation");
2782 // Round out reader.
2783 Asm->EmitULEB128Bytes(1);
2784 Asm->EOL("CIE Code Alignment Factor");
2785 Asm->EmitSLEB128Bytes(stackGrowth);
2786 Asm->EOL("CIE Data Alignment Factor");
2787 Asm->EmitInt8(RI->getDwarfRegNum(RI->getRARegister()));
2788 Asm->EOL("CIE RA Column");
2790 // If there is a personality, we need to indicate the functions location.
2792 Asm->EmitULEB128Bytes(7);
2793 Asm->EOL("Augmentation Size");
2795 if (TAI->getNeedsIndirectEncoding())
2796 Asm->EmitInt8(DW_EH_PE_pcrel | DW_EH_PE_sdata4 | DW_EH_PE_indirect);
2798 Asm->EmitInt8(DW_EH_PE_pcrel | DW_EH_PE_sdata4);
2800 Asm->EOL("Personality (pcrel sdata4 indirect)");
2802 PrintRelDirective();
2803 O << TAI->getPersonalityPrefix();
2804 Asm->EmitExternalGlobal((const GlobalVariable *)(Personality));
2805 O << TAI->getPersonalitySuffix();
2806 O << "-" << TAI->getPCSymbol();
2807 Asm->EOL("Personality");
2809 Asm->EmitULEB128Bytes(DW_EH_PE_pcrel);
2810 Asm->EOL("LSDA Encoding (pcrel)");
2811 Asm->EmitULEB128Bytes(DW_EH_PE_pcrel);
2812 Asm->EOL("FDE Encoding (pcrel)");
2814 Asm->EmitULEB128Bytes(1);
2815 Asm->EOL("Augmentation Size");
2816 Asm->EmitULEB128Bytes(DW_EH_PE_pcrel);
2817 Asm->EOL("FDE Encoding (pcrel)");
2820 // Indicate locations of general callee saved registers in frame.
2821 std::vector<MachineMove> Moves;
2822 RI->getInitialFrameState(Moves);
2823 EmitFrameMoves(NULL, 0, Moves);
2825 Asm->EmitAlignment(2);
2826 EmitLabel("eh_frame_common_end", Index);
2831 /// EmitEHFrame - Emit function exception frame information.
2833 void EmitEHFrame(const FunctionEHFrameInfo &EHFrameInfo) {
2834 Asm->SwitchToTextSection(TAI->getDwarfEHFrameSection());
2836 // Externally visible entry into the functions eh frame info.
2837 if (const char *GlobalDirective = TAI->getGlobalDirective())
2838 O << GlobalDirective << EHFrameInfo.FnName << "\n";
2840 // If there are no calls then you can't unwind.
2841 if (!EHFrameInfo.hasCalls) {
2842 O << EHFrameInfo.FnName << " = 0\n";
2844 O << EHFrameInfo.FnName << ":\n";
2847 EmitDifference("eh_frame_end", EHFrameInfo.Number,
2848 "eh_frame_begin", EHFrameInfo.Number, true);
2849 Asm->EOL("Length of Frame Information Entry");
2851 EmitLabel("eh_frame_begin", EHFrameInfo.Number);
2853 EmitSectionOffset("eh_frame_begin", "eh_frame_common",
2854 EHFrameInfo.Number, EHFrameInfo.PersonalityIndex,
2856 Asm->EOL("FDE CIE offset");
2858 EmitReference("eh_func_begin", EHFrameInfo.Number, true);
2859 Asm->EOL("FDE initial location");
2860 EmitDifference("eh_func_end", EHFrameInfo.Number,
2861 "eh_func_begin", EHFrameInfo.Number);
2862 Asm->EOL("FDE address range");
2864 // If there is a personality and landing pads then point to the language
2865 // specific data area in the exception table.
2866 if (EHFrameInfo.PersonalityIndex) {
2867 Asm->EmitULEB128Bytes(4);
2868 Asm->EOL("Augmentation size");
2870 if (EHFrameInfo.hasLandingPads) {
2871 EmitReference("exception", EHFrameInfo.Number, true);
2872 } else if(TAI->getAddressSize() == 8) {
2873 Asm->EmitInt64((int)0);
2875 Asm->EmitInt32((int)0);
2877 Asm->EOL("Language Specific Data Area");
2879 Asm->EmitULEB128Bytes(0);
2880 Asm->EOL("Augmentation size");
2883 // Indicate locations of function specific callee saved registers in
2885 EmitFrameMoves("eh_func_begin", EHFrameInfo.Number, EHFrameInfo.Moves);
2887 Asm->EmitAlignment(2);
2888 EmitLabel("eh_frame_end", EHFrameInfo.Number);
2891 if (const char *UsedDirective = TAI->getUsedDirective())
2892 O << UsedDirective << EHFrameInfo.FnName << "\n\n";
2895 /// EmitExceptionTable - Emit landing pads and actions.
2897 /// The general organization of the table is complex, but the basic concepts
2898 /// are easy. First there is a header which describes the location and
2899 /// organization of the three components that follow.
2900 /// 1. The landing pad site information describes the range of code covered
2901 /// by the try. In our case it's an accumulation of the ranges covered
2902 /// by the invokes in the try. There is also a reference to the landing
2903 /// pad that handles the exception once processed. Finally an index into
2904 /// the actions table.
2905 /// 2. The action table, in our case, is composed of pairs of type ids
2906 /// and next action offset. Starting with the action index from the
2907 /// landing pad site, each type Id is checked for a match to the current
2908 /// exception. If it matches then the exception and type id are passed
2909 /// on to the landing pad. Otherwise the next action is looked up. This
2910 /// chain is terminated with a next action of zero. If no type id is
2911 /// found the the frame is unwound and handling continues.
2912 /// 3. Type id table contains references to all the C++ typeinfo for all
2913 /// catches in the function. This tables is reversed indexed base 1.
2915 /// SharedTypeIds - How many leading type ids two landing pads have in common.
2916 static unsigned SharedTypeIds(const LandingPadInfo *L,
2917 const LandingPadInfo *R) {
2918 const std::vector<int> &LIds = L->TypeIds, &RIds = R->TypeIds;
2919 unsigned LSize = LIds.size(), RSize = RIds.size();
2920 unsigned MinSize = LSize < RSize ? LSize : RSize;
2923 for (; Count != MinSize; ++Count)
2924 if (LIds[Count] != RIds[Count])
2930 /// PadLT - Order landing pads lexicographically by type id.
2931 static bool PadLT(const LandingPadInfo *L, const LandingPadInfo *R) {
2932 const std::vector<int> &LIds = L->TypeIds, &RIds = R->TypeIds;
2933 unsigned LSize = LIds.size(), RSize = RIds.size();
2934 unsigned MinSize = LSize < RSize ? LSize : RSize;
2936 for (unsigned i = 0; i != MinSize; ++i)
2937 if (LIds[i] != RIds[i])
2938 return LIds[i] < RIds[i];
2940 return LSize < RSize;
2944 static inline unsigned getEmptyKey() { return -1U; }
2945 static inline unsigned getTombstoneKey() { return -2U; }
2946 static unsigned getHashValue(const unsigned &Key) { return Key; }
2947 static bool isEqual(unsigned LHS, unsigned RHS) { return LHS == RHS; }
2948 static bool isPod() { return true; }
2951 /// ActionEntry - Structure describing an entry in the actions table.
2952 struct ActionEntry {
2953 int ValueForTypeID; // The value to write - may not be equal to the type id.
2955 struct ActionEntry *Previous;
2958 /// PadRange - Structure holding a try-range and the associated landing pad.
2960 // The index of the landing pad.
2962 // The index of the begin and end labels in the landing pad's label lists.
2963 unsigned RangeIndex;
2966 typedef DenseMap<unsigned, PadRange, KeyInfo> RangeMapType;
2968 /// CallSiteEntry - Structure describing an entry in the call-site table.
2969 struct CallSiteEntry {
2970 unsigned BeginLabel; // zero indicates the start of the function.
2971 unsigned EndLabel; // zero indicates the end of the function.
2972 unsigned PadLabel; // zero indicates that there is no landing pad.
2976 void EmitExceptionTable() {
2977 // Map all labels and get rid of any dead landing pads.
2978 MMI->TidyLandingPads();
2980 const std::vector<GlobalVariable *> &TypeInfos = MMI->getTypeInfos();
2981 const std::vector<unsigned> &FilterIds = MMI->getFilterIds();
2982 const std::vector<LandingPadInfo> &PadInfos = MMI->getLandingPads();
2983 if (PadInfos.empty()) return;
2985 // Sort the landing pads in order of their type ids. This is used to fold
2986 // duplicate actions.
2987 SmallVector<const LandingPadInfo *, 64> LandingPads;
2988 LandingPads.reserve(PadInfos.size());
2989 for (unsigned i = 0, N = PadInfos.size(); i != N; ++i)
2990 LandingPads.push_back(&PadInfos[i]);
2991 std::sort(LandingPads.begin(), LandingPads.end(), PadLT);
2993 // Negative type ids index into FilterIds, positive type ids index into
2994 // TypeInfos. The value written for a positive type id is just the type
2995 // id itself. For a negative type id, however, the value written is the
2996 // (negative) byte offset of the corresponding FilterIds entry. The byte
2997 // offset is usually equal to the type id, because the FilterIds entries
2998 // are written using a variable width encoding which outputs one byte per
2999 // entry as long as the value written is not too large, but can differ.
3000 // This kind of complication does not occur for positive type ids because
3001 // type infos are output using a fixed width encoding.
3002 // FilterOffsets[i] holds the byte offset corresponding to FilterIds[i].
3003 SmallVector<int, 16> FilterOffsets;
3004 FilterOffsets.reserve(FilterIds.size());
3006 for(std::vector<unsigned>::const_iterator I = FilterIds.begin(),
3007 E = FilterIds.end(); I != E; ++I) {
3008 FilterOffsets.push_back(Offset);
3009 Offset -= Asm->SizeULEB128(*I);
3012 // Compute the actions table and gather the first action index for each
3013 // landing pad site.
3014 SmallVector<ActionEntry, 32> Actions;
3015 SmallVector<unsigned, 64> FirstActions;
3016 FirstActions.reserve(LandingPads.size());
3018 int FirstAction = 0;
3019 unsigned SizeActions = 0;
3020 for (unsigned i = 0, N = LandingPads.size(); i != N; ++i) {
3021 const LandingPadInfo *LP = LandingPads[i];
3022 const std::vector<int> &TypeIds = LP->TypeIds;
3023 const unsigned NumShared = i ? SharedTypeIds(LP, LandingPads[i-1]) : 0;
3024 unsigned SizeSiteActions = 0;
3026 if (NumShared < TypeIds.size()) {
3027 unsigned SizeAction = 0;
3028 ActionEntry *PrevAction = 0;
3031 const unsigned SizePrevIds = LandingPads[i-1]->TypeIds.size();
3032 assert(Actions.size());
3033 PrevAction = &Actions.back();
3034 SizeAction = Asm->SizeSLEB128(PrevAction->NextAction) +
3035 Asm->SizeSLEB128(PrevAction->ValueForTypeID);
3036 for (unsigned j = NumShared; j != SizePrevIds; ++j) {
3037 SizeAction -= Asm->SizeSLEB128(PrevAction->ValueForTypeID);
3038 SizeAction += -PrevAction->NextAction;
3039 PrevAction = PrevAction->Previous;
3043 // Compute the actions.
3044 for (unsigned I = NumShared, M = TypeIds.size(); I != M; ++I) {
3045 int TypeID = TypeIds[I];
3046 assert(-1-TypeID < (int)FilterOffsets.size() && "Unknown filter id!");
3047 int ValueForTypeID = TypeID < 0 ? FilterOffsets[-1 - TypeID] : TypeID;
3048 unsigned SizeTypeID = Asm->SizeSLEB128(ValueForTypeID);
3050 int NextAction = SizeAction ? -(SizeAction + SizeTypeID) : 0;
3051 SizeAction = SizeTypeID + Asm->SizeSLEB128(NextAction);
3052 SizeSiteActions += SizeAction;
3054 ActionEntry Action = {ValueForTypeID, NextAction, PrevAction};
3055 Actions.push_back(Action);
3057 PrevAction = &Actions.back();
3060 // Record the first action of the landing pad site.
3061 FirstAction = SizeActions + SizeSiteActions - SizeAction + 1;
3062 } // else identical - re-use previous FirstAction
3064 FirstActions.push_back(FirstAction);
3066 // Compute this sites contribution to size.
3067 SizeActions += SizeSiteActions;
3070 // Compute the call-site table. Entries must be ordered by address.
3071 SmallVector<CallSiteEntry, 64> CallSites;
3073 RangeMapType PadMap;
3074 for (unsigned i = 0, N = LandingPads.size(); i != N; ++i) {
3075 const LandingPadInfo *LandingPad = LandingPads[i];
3076 for (unsigned j=0, E = LandingPad->BeginLabels.size(); j != E; ++j) {
3077 unsigned BeginLabel = LandingPad->BeginLabels[j];
3078 assert(!PadMap.count(BeginLabel) && "Duplicate landing pad labels!");
3079 PadRange P = { i, j };
3080 PadMap[BeginLabel] = P;
3084 bool MayThrow = false;
3085 unsigned LastLabel = 0;
3086 const TargetInstrInfo *TII = MF->getTarget().getInstrInfo();
3087 for (MachineFunction::const_iterator I = MF->begin(), E = MF->end();
3089 for (MachineBasicBlock::const_iterator MI = I->begin(), E = I->end();
3091 if (MI->getOpcode() != TargetInstrInfo::LABEL) {
3092 MayThrow |= TII->isCall(MI->getOpcode());
3096 unsigned BeginLabel = MI->getOperand(0).getImmedValue();
3097 assert(BeginLabel && "Invalid label!");
3099 if (BeginLabel == LastLabel)
3102 RangeMapType::iterator L = PadMap.find(BeginLabel);
3104 if (L == PadMap.end())
3107 PadRange P = L->second;
3108 const LandingPadInfo *LandingPad = LandingPads[P.PadIndex];
3110 assert(BeginLabel == LandingPad->BeginLabels[P.RangeIndex] &&
3111 "Inconsistent landing pad map!");
3113 // If some instruction between the previous try-range and this one may
3114 // throw, create a call-site entry with no landing pad for the region
3115 // between the try-ranges.
3117 CallSiteEntry Site = {LastLabel, BeginLabel, 0, 0};
3118 CallSites.push_back(Site);
3121 LastLabel = LandingPad->EndLabels[P.RangeIndex];
3122 CallSiteEntry Site = {BeginLabel, LastLabel,
3123 LandingPad->LandingPadLabel, FirstActions[P.PadIndex]};
3125 assert(Site.BeginLabel && Site.EndLabel && Site.PadLabel &&
3126 "Invalid landing pad!");
3128 // Try to merge with the previous call-site.
3129 if (CallSites.size()) {
3130 CallSiteEntry &Prev = CallSites[CallSites.size()-1];
3131 if (Site.PadLabel == Prev.PadLabel && Site.Action == Prev.Action) {
3132 // Extend the range of the previous entry.
3133 Prev.EndLabel = Site.EndLabel;
3138 // Otherwise, create a new call-site.
3139 CallSites.push_back(Site);
3142 // If some instruction between the previous try-range and the end of the
3143 // function may throw, create a call-site entry with no landing pad for the
3144 // region following the try-range.
3146 CallSiteEntry Site = {LastLabel, 0, 0, 0};
3147 CallSites.push_back(Site);
3151 unsigned SizeSites = CallSites.size() * (sizeof(int32_t) + // Site start.
3152 sizeof(int32_t) + // Site length.
3153 sizeof(int32_t)); // Landing pad.
3154 for (unsigned i = 0, e = CallSites.size(); i < e; ++i)
3155 SizeSites += Asm->SizeULEB128(CallSites[i].Action);
3157 unsigned SizeTypes = TypeInfos.size() * TAI->getAddressSize();
3159 unsigned TypeOffset = sizeof(int8_t) + // Call site format
3160 Asm->SizeULEB128(SizeSites) + // Call-site table length
3161 SizeSites + SizeActions + SizeTypes;
3163 unsigned TotalSize = sizeof(int8_t) + // LPStart format
3164 sizeof(int8_t) + // TType format
3165 Asm->SizeULEB128(TypeOffset) + // TType base offset
3168 unsigned SizeAlign = (4 - TotalSize) & 3;
3170 // Begin the exception table.
3171 Asm->SwitchToDataSection(TAI->getDwarfExceptionSection());
3172 O << "GCC_except_table" << SubprogramCount << ":\n";
3173 Asm->EmitAlignment(2);
3174 for (unsigned i = 0; i != SizeAlign; ++i) {
3176 Asm->EOL("Padding");
3178 EmitLabel("exception", SubprogramCount);
3181 Asm->EmitInt8(DW_EH_PE_omit);
3182 Asm->EOL("LPStart format (DW_EH_PE_omit)");
3183 Asm->EmitInt8(DW_EH_PE_absptr);
3184 Asm->EOL("TType format (DW_EH_PE_absptr)");
3185 Asm->EmitULEB128Bytes(TypeOffset);
3186 Asm->EOL("TType base offset");
3187 Asm->EmitInt8(DW_EH_PE_udata4);
3188 Asm->EOL("Call site format (DW_EH_PE_udata4)");
3189 Asm->EmitULEB128Bytes(SizeSites);
3190 Asm->EOL("Call-site table length");
3192 // Emit the landing pad site information.
3193 for (unsigned i = 0; i < CallSites.size(); ++i) {
3194 CallSiteEntry &S = CallSites[i];
3195 const char *BeginTag;
3196 unsigned BeginNumber;
3198 if (!S.BeginLabel) {
3199 BeginTag = "eh_func_begin";
3200 BeginNumber = SubprogramCount;
3203 BeginNumber = S.BeginLabel;
3206 EmitSectionOffset(BeginTag, "eh_func_begin", BeginNumber, SubprogramCount,
3208 Asm->EOL("Region start");
3211 EmitDifference("eh_func_end", SubprogramCount, BeginTag, BeginNumber);
3213 EmitDifference("label", S.EndLabel, BeginTag, BeginNumber);
3215 Asm->EOL("Region length");
3218 if (TAI->getAddressSize() == sizeof(int32_t))
3223 EmitSectionOffset("label", "eh_func_begin", S.PadLabel, SubprogramCount,
3226 Asm->EOL("Landing pad");
3228 Asm->EmitULEB128Bytes(S.Action);
3232 // Emit the actions.
3233 for (unsigned I = 0, N = Actions.size(); I != N; ++I) {
3234 ActionEntry &Action = Actions[I];
3236 Asm->EmitSLEB128Bytes(Action.ValueForTypeID);
3237 Asm->EOL("TypeInfo index");
3238 Asm->EmitSLEB128Bytes(Action.NextAction);
3239 Asm->EOL("Next action");
3242 // Emit the type ids.
3243 for (unsigned M = TypeInfos.size(); M; --M) {
3244 GlobalVariable *GV = TypeInfos[M - 1];
3246 PrintRelDirective();
3249 O << Asm->getGlobalLinkName(GV);
3253 Asm->EOL("TypeInfo");
3256 // Emit the filter typeids.
3257 for (unsigned j = 0, M = FilterIds.size(); j < M; ++j) {
3258 unsigned TypeID = FilterIds[j];
3259 Asm->EmitULEB128Bytes(TypeID);
3260 Asm->EOL("Filter TypeInfo index");
3263 Asm->EmitAlignment(2);
3267 //===--------------------------------------------------------------------===//
3268 // Main entry points.
3270 DwarfException(std::ostream &OS, AsmPrinter *A, const TargetAsmInfo *T)
3275 virtual ~DwarfException() {}
3277 /// SetModuleInfo - Set machine module information when it's known that pass
3278 /// manager has created it. Set by the target AsmPrinter.
3279 void SetModuleInfo(MachineModuleInfo *mmi) {
3283 /// BeginModule - Emit all exception information that should come prior to the
3285 void BeginModule(Module *M) {
3289 /// EndModule - Emit all exception information that should come after the
3292 if (!shouldEmit) return;
3294 const std::vector<Function *> Personalities = MMI->getPersonalities();
3295 for (unsigned i =0; i < Personalities.size(); ++i)
3296 EmitCommonEHFrame(Personalities[i], i);
3298 for (std::vector<FunctionEHFrameInfo>::iterator I = EHFrames.begin(),
3299 E = EHFrames.end(); I != E; ++I)
3303 /// BeginFunction - Gather pre-function exception information. Assumes being
3304 /// emitted immediately after the function entry point.
3305 void BeginFunction(MachineFunction *MF) {
3309 ExceptionHandling &&
3310 TAI->doesSupportExceptionHandling()) {
3312 // Assumes in correct section after the entry point.
3313 EmitLabel("eh_func_begin", ++SubprogramCount);
3317 /// EndFunction - Gather and emit post-function exception information.
3319 void EndFunction() {
3320 if (!shouldEmit) return;
3322 EmitLabel("eh_func_end", SubprogramCount);
3323 EmitExceptionTable();
3325 // Save EH frame information
3327 push_back(FunctionEHFrameInfo(getAsm()->getCurrentFunctionEHName(MF),
3329 MMI->getPersonalityIndex(),
3330 MF->getFrameInfo()->hasCalls(),
3331 !MMI->getLandingPads().empty(),
3332 MMI->getFrameMoves()));
3336 } // End of namespace llvm
3338 //===----------------------------------------------------------------------===//
3340 /// Emit - Print the abbreviation using the specified Dwarf writer.
3342 void DIEAbbrev::Emit(const DwarfDebug &DD) const {
3343 // Emit its Dwarf tag type.
3344 DD.getAsm()->EmitULEB128Bytes(Tag);
3345 DD.getAsm()->EOL(TagString(Tag));
3347 // Emit whether it has children DIEs.
3348 DD.getAsm()->EmitULEB128Bytes(ChildrenFlag);
3349 DD.getAsm()->EOL(ChildrenString(ChildrenFlag));
3351 // For each attribute description.
3352 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
3353 const DIEAbbrevData &AttrData = Data[i];
3355 // Emit attribute type.
3356 DD.getAsm()->EmitULEB128Bytes(AttrData.getAttribute());
3357 DD.getAsm()->EOL(AttributeString(AttrData.getAttribute()));
3360 DD.getAsm()->EmitULEB128Bytes(AttrData.getForm());
3361 DD.getAsm()->EOL(FormEncodingString(AttrData.getForm()));
3364 // Mark end of abbreviation.
3365 DD.getAsm()->EmitULEB128Bytes(0); DD.getAsm()->EOL("EOM(1)");
3366 DD.getAsm()->EmitULEB128Bytes(0); DD.getAsm()->EOL("EOM(2)");
3370 void DIEAbbrev::print(std::ostream &O) {
3371 O << "Abbreviation @"
3372 << std::hex << (intptr_t)this << std::dec
3376 << ChildrenString(ChildrenFlag)
3379 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
3381 << AttributeString(Data[i].getAttribute())
3383 << FormEncodingString(Data[i].getForm())
3387 void DIEAbbrev::dump() { print(cerr); }
3390 //===----------------------------------------------------------------------===//
3393 void DIEValue::dump() {
3398 //===----------------------------------------------------------------------===//
3400 /// EmitValue - Emit integer of appropriate size.
3402 void DIEInteger::EmitValue(DwarfDebug &DD, unsigned Form) {
3404 case DW_FORM_flag: // Fall thru
3405 case DW_FORM_ref1: // Fall thru
3406 case DW_FORM_data1: DD.getAsm()->EmitInt8(Integer); break;
3407 case DW_FORM_ref2: // Fall thru
3408 case DW_FORM_data2: DD.getAsm()->EmitInt16(Integer); break;
3409 case DW_FORM_ref4: // Fall thru
3410 case DW_FORM_data4: DD.getAsm()->EmitInt32(Integer); break;
3411 case DW_FORM_ref8: // Fall thru
3412 case DW_FORM_data8: DD.getAsm()->EmitInt64(Integer); break;
3413 case DW_FORM_udata: DD.getAsm()->EmitULEB128Bytes(Integer); break;
3414 case DW_FORM_sdata: DD.getAsm()->EmitSLEB128Bytes(Integer); break;
3415 default: assert(0 && "DIE Value form not supported yet"); break;
3419 /// SizeOf - Determine size of integer value in bytes.
3421 unsigned DIEInteger::SizeOf(const DwarfDebug &DD, unsigned Form) const {
3423 case DW_FORM_flag: // Fall thru
3424 case DW_FORM_ref1: // Fall thru
3425 case DW_FORM_data1: return sizeof(int8_t);
3426 case DW_FORM_ref2: // Fall thru
3427 case DW_FORM_data2: return sizeof(int16_t);
3428 case DW_FORM_ref4: // Fall thru
3429 case DW_FORM_data4: return sizeof(int32_t);
3430 case DW_FORM_ref8: // Fall thru
3431 case DW_FORM_data8: return sizeof(int64_t);
3432 case DW_FORM_udata: return DD.getAsm()->SizeULEB128(Integer);
3433 case DW_FORM_sdata: return DD.getAsm()->SizeSLEB128(Integer);
3434 default: assert(0 && "DIE Value form not supported yet"); break;
3439 //===----------------------------------------------------------------------===//
3441 /// EmitValue - Emit string value.
3443 void DIEString::EmitValue(DwarfDebug &DD, unsigned Form) {
3444 DD.getAsm()->EmitString(String);
3447 //===----------------------------------------------------------------------===//
3449 /// EmitValue - Emit label value.
3451 void DIEDwarfLabel::EmitValue(DwarfDebug &DD, unsigned Form) {
3452 DD.EmitReference(Label);
3455 /// SizeOf - Determine size of label value in bytes.
3457 unsigned DIEDwarfLabel::SizeOf(const DwarfDebug &DD, unsigned Form) const {
3458 return DD.getTargetAsmInfo()->getAddressSize();
3461 //===----------------------------------------------------------------------===//
3463 /// EmitValue - Emit label value.
3465 void DIEObjectLabel::EmitValue(DwarfDebug &DD, unsigned Form) {
3466 DD.EmitReference(Label);
3469 /// SizeOf - Determine size of label value in bytes.
3471 unsigned DIEObjectLabel::SizeOf(const DwarfDebug &DD, unsigned Form) const {
3472 return DD.getTargetAsmInfo()->getAddressSize();
3475 //===----------------------------------------------------------------------===//
3477 /// EmitValue - Emit delta value.
3479 void DIEDelta::EmitValue(DwarfDebug &DD, unsigned Form) {
3480 bool IsSmall = Form == DW_FORM_data4;
3481 DD.EmitDifference(LabelHi, LabelLo, IsSmall);
3484 /// SizeOf - Determine size of delta value in bytes.
3486 unsigned DIEDelta::SizeOf(const DwarfDebug &DD, unsigned Form) const {
3487 if (Form == DW_FORM_data4) return 4;
3488 return DD.getTargetAsmInfo()->getAddressSize();
3491 //===----------------------------------------------------------------------===//
3493 /// EmitValue - Emit debug information entry offset.
3495 void DIEntry::EmitValue(DwarfDebug &DD, unsigned Form) {
3496 DD.getAsm()->EmitInt32(Entry->getOffset());
3499 //===----------------------------------------------------------------------===//
3501 /// ComputeSize - calculate the size of the block.
3503 unsigned DIEBlock::ComputeSize(DwarfDebug &DD) {
3505 const std::vector<DIEAbbrevData> &AbbrevData = Abbrev.getData();
3507 for (unsigned i = 0, N = Values.size(); i < N; ++i) {
3508 Size += Values[i]->SizeOf(DD, AbbrevData[i].getForm());
3514 /// EmitValue - Emit block data.
3516 void DIEBlock::EmitValue(DwarfDebug &DD, unsigned Form) {
3518 case DW_FORM_block1: DD.getAsm()->EmitInt8(Size); break;
3519 case DW_FORM_block2: DD.getAsm()->EmitInt16(Size); break;
3520 case DW_FORM_block4: DD.getAsm()->EmitInt32(Size); break;
3521 case DW_FORM_block: DD.getAsm()->EmitULEB128Bytes(Size); break;
3522 default: assert(0 && "Improper form for block"); break;
3525 const std::vector<DIEAbbrevData> &AbbrevData = Abbrev.getData();
3527 for (unsigned i = 0, N = Values.size(); i < N; ++i) {
3529 Values[i]->EmitValue(DD, AbbrevData[i].getForm());
3533 /// SizeOf - Determine size of block data in bytes.
3535 unsigned DIEBlock::SizeOf(const DwarfDebug &DD, unsigned Form) const {
3537 case DW_FORM_block1: return Size + sizeof(int8_t);
3538 case DW_FORM_block2: return Size + sizeof(int16_t);
3539 case DW_FORM_block4: return Size + sizeof(int32_t);
3540 case DW_FORM_block: return Size + DD.getAsm()->SizeULEB128(Size);
3541 default: assert(0 && "Improper form for block"); break;
3546 //===----------------------------------------------------------------------===//
3547 /// DIE Implementation
3550 for (unsigned i = 0, N = Children.size(); i < N; ++i)
3554 /// AddSiblingOffset - Add a sibling offset field to the front of the DIE.
3556 void DIE::AddSiblingOffset() {
3557 DIEInteger *DI = new DIEInteger(0);
3558 Values.insert(Values.begin(), DI);
3559 Abbrev.AddFirstAttribute(DW_AT_sibling, DW_FORM_ref4);
3562 /// Profile - Used to gather unique data for the value folding set.
3564 void DIE::Profile(FoldingSetNodeID &ID) {
3567 for (unsigned i = 0, N = Children.size(); i < N; ++i)
3568 ID.AddPointer(Children[i]);
3570 for (unsigned j = 0, M = Values.size(); j < M; ++j)
3571 ID.AddPointer(Values[j]);
3575 void DIE::print(std::ostream &O, unsigned IncIndent) {
3576 static unsigned IndentCount = 0;
3577 IndentCount += IncIndent;
3578 const std::string Indent(IndentCount, ' ');
3579 bool isBlock = Abbrev.getTag() == 0;
3584 << "0x" << std::hex << (intptr_t)this << std::dec
3585 << ", Offset: " << Offset
3586 << ", Size: " << Size
3590 << TagString(Abbrev.getTag())
3592 << ChildrenString(Abbrev.getChildrenFlag());
3594 O << "Size: " << Size;
3598 const std::vector<DIEAbbrevData> &Data = Abbrev.getData();
3601 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
3604 O << AttributeString(Data[i].getAttribute());
3606 O << "Blk[" << i << "]";
3609 << FormEncodingString(Data[i].getForm())
3611 Values[i]->print(O);
3616 for (unsigned j = 0, M = Children.size(); j < M; ++j) {
3617 Children[j]->print(O, 4);
3620 if (!isBlock) O << "\n";
3621 IndentCount -= IncIndent;
3629 //===----------------------------------------------------------------------===//
3630 /// DwarfWriter Implementation
3633 DwarfWriter::DwarfWriter(std::ostream &OS, AsmPrinter *A,
3634 const TargetAsmInfo *T) {
3635 DE = new DwarfException(OS, A, T);
3636 DD = new DwarfDebug(OS, A, T);
3639 DwarfWriter::~DwarfWriter() {
3644 /// SetModuleInfo - Set machine module info when it's known that pass manager
3645 /// has created it. Set by the target AsmPrinter.
3646 void DwarfWriter::SetModuleInfo(MachineModuleInfo *MMI) {
3647 DD->SetModuleInfo(MMI);
3648 DE->SetModuleInfo(MMI);
3651 /// BeginModule - Emit all Dwarf sections that should come prior to the
3653 void DwarfWriter::BeginModule(Module *M) {
3658 /// EndModule - Emit all Dwarf sections that should come after the content.
3660 void DwarfWriter::EndModule() {
3665 /// BeginFunction - Gather pre-function debug information. Assumes being
3666 /// emitted immediately after the function entry point.
3667 void DwarfWriter::BeginFunction(MachineFunction *MF) {
3668 DE->BeginFunction(MF);
3669 DD->BeginFunction(MF);
3672 /// EndFunction - Gather and emit post-function debug information.
3674 void DwarfWriter::EndFunction() {
3678 if (MachineModuleInfo *MMI = DD->getMMI() ? DD->getMMI() : DE->getMMI()) {
3679 // Clear function debug information.