1 //===-- llvm/CodeGen/DwarfWriter.cpp - Dwarf Framework ----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains support for writing dwarf info into asm files.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/CodeGen/DwarfWriter.h"
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/DerivedTypes.h"
22 #include "llvm/Constants.h"
23 #include "llvm/CodeGen/AsmPrinter.h"
24 #include "llvm/CodeGen/MachineModuleInfo.h"
25 #include "llvm/CodeGen/MachineFrameInfo.h"
26 #include "llvm/CodeGen/MachineLocation.h"
27 #include "llvm/Analysis/DebugInfo.h"
28 #include "llvm/Support/Debug.h"
29 #include "llvm/Support/Dwarf.h"
30 #include "llvm/Support/CommandLine.h"
31 #include "llvm/Support/DataTypes.h"
32 #include "llvm/Support/Mangler.h"
33 #include "llvm/Support/raw_ostream.h"
34 #include "llvm/System/Path.h"
35 #include "llvm/Target/TargetAsmInfo.h"
36 #include "llvm/Target/TargetRegisterInfo.h"
37 #include "llvm/Target/TargetData.h"
38 #include "llvm/Target/TargetFrameInfo.h"
39 #include "llvm/Target/TargetInstrInfo.h"
40 #include "llvm/Target/TargetMachine.h"
41 #include "llvm/Target/TargetOptions.h"
45 using namespace llvm::dwarf;
47 static RegisterPass<DwarfWriter>
48 X("dwarfwriter", "DWARF Information Writer");
49 char DwarfWriter::ID = 0;
53 //===----------------------------------------------------------------------===//
55 /// Configuration values for initial hash set sizes (log2).
57 static const unsigned InitDiesSetSize = 9; // 512
58 static const unsigned InitAbbreviationsSetSize = 9; // 512
59 static const unsigned InitValuesSetSize = 9; // 512
61 //===----------------------------------------------------------------------===//
62 /// Forward declarations.
67 //===----------------------------------------------------------------------===//
70 /// getGlobalVariablesUsing - Return all of the GlobalVariables which have the
71 /// specified value in their initializer somewhere.
73 getGlobalVariablesUsing(Value *V, std::vector<GlobalVariable*> &Result) {
74 // Scan though value users.
75 for (Value::use_iterator I = V->use_begin(), E = V->use_end(); I != E; ++I) {
76 if (GlobalVariable *GV = dyn_cast<GlobalVariable>(*I)) {
77 // If the user is a GlobalVariable then add to result.
79 } else if (Constant *C = dyn_cast<Constant>(*I)) {
80 // If the user is a constant variable then scan its users.
81 getGlobalVariablesUsing(C, Result);
86 /// getGlobalVariablesUsing - Return all of the GlobalVariables that use the
87 /// named GlobalVariable.
89 getGlobalVariablesUsing(Module &M, const std::string &RootName,
90 std::vector<GlobalVariable*> &Result) {
91 std::vector<const Type*> FieldTypes;
92 FieldTypes.push_back(Type::Int32Ty);
93 FieldTypes.push_back(Type::Int32Ty);
95 // Get the GlobalVariable root.
96 GlobalVariable *UseRoot = M.getGlobalVariable(RootName,
97 StructType::get(FieldTypes));
99 // If present and linkonce then scan for users.
100 if (UseRoot && UseRoot->hasLinkOnceLinkage())
101 getGlobalVariablesUsing(UseRoot, Result);
104 /// getGlobalVariable - Return either a direct or cast Global value.
106 static GlobalVariable *getGlobalVariable(Value *V) {
107 if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) {
109 } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) {
110 if (CE->getOpcode() == Instruction::BitCast) {
111 return dyn_cast<GlobalVariable>(CE->getOperand(0));
112 } else if (CE->getOpcode() == Instruction::GetElementPtr) {
113 for (unsigned int i=1; i<CE->getNumOperands(); i++) {
114 if (!CE->getOperand(i)->isNullValue())
117 return dyn_cast<GlobalVariable>(CE->getOperand(0));
123 //===----------------------------------------------------------------------===//
124 /// DWLabel - Labels are used to track locations in the assembler file.
125 /// Labels appear in the form @verbatim <prefix><Tag><Number> @endverbatim,
126 /// where the tag is a category of label (Ex. location) and number is a value
127 /// unique in that category.
130 /// Tag - Label category tag. Should always be a staticly declared C string.
134 /// Number - Value to make label unique.
138 DWLabel(const char *T, unsigned N) : Tag(T), Number(N) {}
140 void Profile(FoldingSetNodeID &ID) const {
141 ID.AddString(std::string(Tag));
142 ID.AddInteger(Number);
146 void print(std::ostream *O) const {
149 void print(std::ostream &O) const {
151 if (Number) O << Number;
156 //===----------------------------------------------------------------------===//
157 /// DIEAbbrevData - Dwarf abbreviation data, describes the one attribute of a
158 /// Dwarf abbreviation.
159 class DIEAbbrevData {
161 /// Attribute - Dwarf attribute code.
165 /// Form - Dwarf form code.
170 DIEAbbrevData(unsigned A, unsigned F)
176 unsigned getAttribute() const { return Attribute; }
177 unsigned getForm() const { return Form; }
179 /// Profile - Used to gather unique data for the abbreviation folding set.
181 void Profile(FoldingSetNodeID &ID)const {
182 ID.AddInteger(Attribute);
187 //===----------------------------------------------------------------------===//
188 /// DIEAbbrev - Dwarf abbreviation, describes the organization of a debug
189 /// information object.
190 class DIEAbbrev : public FoldingSetNode {
192 /// Tag - Dwarf tag code.
196 /// Unique number for node.
200 /// ChildrenFlag - Dwarf children flag.
202 unsigned ChildrenFlag;
204 /// Data - Raw data bytes for abbreviation.
206 SmallVector<DIEAbbrevData, 8> Data;
210 DIEAbbrev(unsigned T, unsigned C)
218 unsigned getTag() const { return Tag; }
219 unsigned getNumber() const { return Number; }
220 unsigned getChildrenFlag() const { return ChildrenFlag; }
221 const SmallVector<DIEAbbrevData, 8> &getData() const { return Data; }
222 void setTag(unsigned T) { Tag = T; }
223 void setChildrenFlag(unsigned CF) { ChildrenFlag = CF; }
224 void setNumber(unsigned N) { Number = N; }
226 /// AddAttribute - Adds another set of attribute information to the
228 void AddAttribute(unsigned Attribute, unsigned Form) {
229 Data.push_back(DIEAbbrevData(Attribute, Form));
232 /// AddFirstAttribute - Adds a set of attribute information to the front
233 /// of the abbreviation.
234 void AddFirstAttribute(unsigned Attribute, unsigned Form) {
235 Data.insert(Data.begin(), DIEAbbrevData(Attribute, Form));
238 /// Profile - Used to gather unique data for the abbreviation folding set.
240 void Profile(FoldingSetNodeID &ID) {
242 ID.AddInteger(ChildrenFlag);
244 // For each attribute description.
245 for (unsigned i = 0, N = Data.size(); i < N; ++i)
249 /// Emit - Print the abbreviation using the specified Dwarf writer.
251 void Emit(const DwarfDebug &DD) const;
254 void print(std::ostream *O) {
257 void print(std::ostream &O);
262 //===----------------------------------------------------------------------===//
263 /// DIE - A structured debug information entry. Has an abbreviation which
264 /// describes it's organization.
265 class DIE : public FoldingSetNode {
267 /// Abbrev - Buffer for constructing abbreviation.
271 /// Offset - Offset in debug info section.
275 /// Size - Size of instance + children.
281 std::vector<DIE *> Children;
283 /// Attributes values.
285 SmallVector<DIEValue*, 32> Values;
288 explicit DIE(unsigned Tag)
289 : Abbrev(Tag, DW_CHILDREN_no)
298 DIEAbbrev &getAbbrev() { return Abbrev; }
299 unsigned getAbbrevNumber() const {
300 return Abbrev.getNumber();
302 unsigned getTag() const { return Abbrev.getTag(); }
303 unsigned getOffset() const { return Offset; }
304 unsigned getSize() const { return Size; }
305 const std::vector<DIE *> &getChildren() const { return Children; }
306 SmallVector<DIEValue*, 32> &getValues() { return Values; }
307 void setTag(unsigned Tag) { Abbrev.setTag(Tag); }
308 void setOffset(unsigned O) { Offset = O; }
309 void setSize(unsigned S) { Size = S; }
311 /// AddValue - Add a value and attributes to a DIE.
313 void AddValue(unsigned Attribute, unsigned Form, DIEValue *Value) {
314 Abbrev.AddAttribute(Attribute, Form);
315 Values.push_back(Value);
318 /// SiblingOffset - Return the offset of the debug information entry's
320 unsigned SiblingOffset() const { return Offset + Size; }
322 /// AddSiblingOffset - Add a sibling offset field to the front of the DIE.
324 void AddSiblingOffset();
326 /// AddChild - Add a child to the DIE.
328 void AddChild(DIE *Child) {
329 Abbrev.setChildrenFlag(DW_CHILDREN_yes);
330 Children.push_back(Child);
333 /// Detach - Detaches objects connected to it after copying.
339 /// Profile - Used to gather unique data for the value folding set.
341 void Profile(FoldingSetNodeID &ID) ;
344 void print(std::ostream *O, unsigned IncIndent = 0) {
345 if (O) print(*O, IncIndent);
347 void print(std::ostream &O, unsigned IncIndent = 0);
352 //===----------------------------------------------------------------------===//
353 /// DIEValue - A debug information entry value.
355 class DIEValue : public FoldingSetNode {
368 /// Type - Type of data stored in the value.
372 explicit DIEValue(unsigned T)
375 virtual ~DIEValue() {}
378 unsigned getType() const { return Type; }
380 // Implement isa/cast/dyncast.
381 static bool classof(const DIEValue *) { return true; }
383 /// EmitValue - Emit value via the Dwarf writer.
385 virtual void EmitValue(DwarfDebug &DD, unsigned Form) = 0;
387 /// SizeOf - Return the size of a value in bytes.
389 virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const = 0;
391 /// Profile - Used to gather unique data for the value folding set.
393 virtual void Profile(FoldingSetNodeID &ID) = 0;
396 void print(std::ostream *O) {
399 virtual void print(std::ostream &O) = 0;
404 //===----------------------------------------------------------------------===//
405 /// DWInteger - An integer value DIE.
407 class DIEInteger : public DIEValue {
412 explicit DIEInteger(uint64_t I) : DIEValue(isInteger), Integer(I) {}
414 // Implement isa/cast/dyncast.
415 static bool classof(const DIEInteger *) { return true; }
416 static bool classof(const DIEValue *I) { return I->Type == isInteger; }
418 /// BestForm - Choose the best form for integer.
420 static unsigned BestForm(bool IsSigned, uint64_t Integer) {
422 if ((char)Integer == (signed)Integer) return DW_FORM_data1;
423 if ((short)Integer == (signed)Integer) return DW_FORM_data2;
424 if ((int)Integer == (signed)Integer) return DW_FORM_data4;
426 if ((unsigned char)Integer == Integer) return DW_FORM_data1;
427 if ((unsigned short)Integer == Integer) return DW_FORM_data2;
428 if ((unsigned int)Integer == Integer) return DW_FORM_data4;
430 return DW_FORM_data8;
433 /// EmitValue - Emit integer of appropriate size.
435 virtual void EmitValue(DwarfDebug &DD, unsigned Form);
437 /// SizeOf - Determine size of integer value in bytes.
439 virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const;
441 /// Profile - Used to gather unique data for the value folding set.
443 static void Profile(FoldingSetNodeID &ID, unsigned Integer) {
444 ID.AddInteger(isInteger);
445 ID.AddInteger(Integer);
447 virtual void Profile(FoldingSetNodeID &ID) { Profile(ID, Integer); }
450 virtual void print(std::ostream &O) {
451 O << "Int: " << (int64_t)Integer
452 << " 0x" << std::hex << Integer << std::dec;
457 //===----------------------------------------------------------------------===//
458 /// DIEString - A string value DIE.
460 class DIEString : public DIEValue {
462 const std::string String;
464 explicit DIEString(const std::string &S) : DIEValue(isString), String(S) {}
466 // Implement isa/cast/dyncast.
467 static bool classof(const DIEString *) { return true; }
468 static bool classof(const DIEValue *S) { return S->Type == isString; }
470 /// EmitValue - Emit string value.
472 virtual void EmitValue(DwarfDebug &DD, unsigned Form);
474 /// SizeOf - Determine size of string value in bytes.
476 virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const {
477 return String.size() + sizeof(char); // sizeof('\0');
480 /// Profile - Used to gather unique data for the value folding set.
482 static void Profile(FoldingSetNodeID &ID, const std::string &String) {
483 ID.AddInteger(isString);
484 ID.AddString(String);
486 virtual void Profile(FoldingSetNodeID &ID) { Profile(ID, String); }
489 virtual void print(std::ostream &O) {
490 O << "Str: \"" << String << "\"";
495 //===----------------------------------------------------------------------===//
496 /// DIEDwarfLabel - A Dwarf internal label expression DIE.
498 class DIEDwarfLabel : public DIEValue {
503 explicit DIEDwarfLabel(const DWLabel &L) : DIEValue(isLabel), Label(L) {}
505 // Implement isa/cast/dyncast.
506 static bool classof(const DIEDwarfLabel *) { return true; }
507 static bool classof(const DIEValue *L) { return L->Type == isLabel; }
509 /// EmitValue - Emit label value.
511 virtual void EmitValue(DwarfDebug &DD, unsigned Form);
513 /// SizeOf - Determine size of label value in bytes.
515 virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const;
517 /// Profile - Used to gather unique data for the value folding set.
519 static void Profile(FoldingSetNodeID &ID, const DWLabel &Label) {
520 ID.AddInteger(isLabel);
523 virtual void Profile(FoldingSetNodeID &ID) { Profile(ID, Label); }
526 virtual void print(std::ostream &O) {
534 //===----------------------------------------------------------------------===//
535 /// DIEObjectLabel - A label to an object in code or data.
537 class DIEObjectLabel : public DIEValue {
539 const std::string Label;
541 explicit DIEObjectLabel(const std::string &L)
542 : DIEValue(isAsIsLabel), Label(L) {}
544 // Implement isa/cast/dyncast.
545 static bool classof(const DIEObjectLabel *) { return true; }
546 static bool classof(const DIEValue *L) { return L->Type == isAsIsLabel; }
548 /// EmitValue - Emit label value.
550 virtual void EmitValue(DwarfDebug &DD, unsigned Form);
552 /// SizeOf - Determine size of label value in bytes.
554 virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const;
556 /// Profile - Used to gather unique data for the value folding set.
558 static void Profile(FoldingSetNodeID &ID, const std::string &Label) {
559 ID.AddInteger(isAsIsLabel);
562 virtual void Profile(FoldingSetNodeID &ID) { Profile(ID, Label); }
565 virtual void print(std::ostream &O) {
566 O << "Obj: " << Label;
571 //===----------------------------------------------------------------------===//
572 /// DIESectionOffset - A section offset DIE.
574 class DIESectionOffset : public DIEValue {
577 const DWLabel Section;
581 DIESectionOffset(const DWLabel &Lab, const DWLabel &Sec,
582 bool isEH = false, bool useSet = true)
583 : DIEValue(isSectionOffset), Label(Lab), Section(Sec),
584 IsEH(isEH), UseSet(useSet) {}
586 // Implement isa/cast/dyncast.
587 static bool classof(const DIESectionOffset *) { return true; }
588 static bool classof(const DIEValue *D) { return D->Type == isSectionOffset; }
590 /// EmitValue - Emit section offset.
592 virtual void EmitValue(DwarfDebug &DD, unsigned Form);
594 /// SizeOf - Determine size of section offset value in bytes.
596 virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const;
598 /// Profile - Used to gather unique data for the value folding set.
600 static void Profile(FoldingSetNodeID &ID, const DWLabel &Label,
601 const DWLabel &Section) {
602 ID.AddInteger(isSectionOffset);
605 // IsEH and UseSet are specific to the Label/Section that we will emit
606 // the offset for; so Label/Section are enough for uniqueness.
608 virtual void Profile(FoldingSetNodeID &ID) { Profile(ID, Label, Section); }
611 virtual void print(std::ostream &O) {
616 O << "-" << IsEH << "-" << UseSet;
621 //===----------------------------------------------------------------------===//
622 /// DIEDelta - A simple label difference DIE.
624 class DIEDelta : public DIEValue {
626 const DWLabel LabelHi;
627 const DWLabel LabelLo;
629 DIEDelta(const DWLabel &Hi, const DWLabel &Lo)
630 : DIEValue(isDelta), LabelHi(Hi), LabelLo(Lo) {}
632 // Implement isa/cast/dyncast.
633 static bool classof(const DIEDelta *) { return true; }
634 static bool classof(const DIEValue *D) { return D->Type == isDelta; }
636 /// EmitValue - Emit delta value.
638 virtual void EmitValue(DwarfDebug &DD, unsigned Form);
640 /// SizeOf - Determine size of delta value in bytes.
642 virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const;
644 /// Profile - Used to gather unique data for the value folding set.
646 static void Profile(FoldingSetNodeID &ID, const DWLabel &LabelHi,
647 const DWLabel &LabelLo) {
648 ID.AddInteger(isDelta);
652 virtual void Profile(FoldingSetNodeID &ID) { Profile(ID, LabelHi, LabelLo); }
655 virtual void print(std::ostream &O) {
664 //===----------------------------------------------------------------------===//
665 /// DIEntry - A pointer to another debug information entry. An instance of this
666 /// class can also be used as a proxy for a debug information entry not yet
667 /// defined (ie. types.)
668 class DIEntry : public DIEValue {
672 explicit DIEntry(DIE *E) : DIEValue(isEntry), Entry(E) {}
674 // Implement isa/cast/dyncast.
675 static bool classof(const DIEntry *) { return true; }
676 static bool classof(const DIEValue *E) { return E->Type == isEntry; }
678 /// EmitValue - Emit debug information entry offset.
680 virtual void EmitValue(DwarfDebug &DD, unsigned Form);
682 /// SizeOf - Determine size of debug information entry in bytes.
684 virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const {
685 return sizeof(int32_t);
688 /// Profile - Used to gather unique data for the value folding set.
690 static void Profile(FoldingSetNodeID &ID, DIE *Entry) {
691 ID.AddInteger(isEntry);
692 ID.AddPointer(Entry);
694 virtual void Profile(FoldingSetNodeID &ID) {
695 ID.AddInteger(isEntry);
698 ID.AddPointer(Entry);
705 virtual void print(std::ostream &O) {
706 O << "Die: 0x" << std::hex << (intptr_t)Entry << std::dec;
711 //===----------------------------------------------------------------------===//
712 /// DIEBlock - A block of values. Primarily used for location expressions.
714 class DIEBlock : public DIEValue, public DIE {
716 unsigned Size; // Size in bytes excluding size header.
726 // Implement isa/cast/dyncast.
727 static bool classof(const DIEBlock *) { return true; }
728 static bool classof(const DIEValue *E) { return E->Type == isBlock; }
730 /// ComputeSize - calculate the size of the block.
732 unsigned ComputeSize(DwarfDebug &DD);
734 /// BestForm - Choose the best form for data.
736 unsigned BestForm() const {
737 if ((unsigned char)Size == Size) return DW_FORM_block1;
738 if ((unsigned short)Size == Size) return DW_FORM_block2;
739 if ((unsigned int)Size == Size) return DW_FORM_block4;
740 return DW_FORM_block;
743 /// EmitValue - Emit block data.
745 virtual void EmitValue(DwarfDebug &DD, unsigned Form);
747 /// SizeOf - Determine size of block data in bytes.
749 virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const;
752 /// Profile - Used to gather unique data for the value folding set.
754 virtual void Profile(FoldingSetNodeID &ID) {
755 ID.AddInteger(isBlock);
760 virtual void print(std::ostream &O) {
767 //===----------------------------------------------------------------------===//
768 /// CompileUnit - This dwarf writer support class manages information associate
769 /// with a source file.
772 /// ID - File identifier for source.
776 /// Die - Compile unit debug information entry.
780 /// GVToDieMap - Tracks the mapping of unit level debug informaton
781 /// variables to debug information entries.
782 DenseMap<GlobalVariable *, DIE *> GVToDieMap;
784 /// GVToDIEntryMap - Tracks the mapping of unit level debug informaton
785 /// descriptors to debug information entries using a DIEntry proxy.
786 DenseMap<GlobalVariable *, DIEntry *> GVToDIEntryMap;
788 /// Globals - A map of globally visible named entities for this unit.
790 std::map<std::string, DIE *> Globals;
792 /// DiesSet - Used to uniquely define dies within the compile unit.
794 FoldingSet<DIE> DiesSet;
797 CompileUnit(unsigned I, DIE *D)
798 : ID(I), Die(D), GVToDieMap(),
799 GVToDIEntryMap(), Globals(), DiesSet(InitDiesSetSize)
807 unsigned getID() const { return ID; }
808 DIE* getDie() const { return Die; }
809 std::map<std::string, DIE *> &getGlobals() { return Globals; }
811 /// hasContent - Return true if this compile unit has something to write out.
813 bool hasContent() const {
814 return !Die->getChildren().empty();
817 /// AddGlobal - Add a new global entity to the compile unit.
819 void AddGlobal(const std::string &Name, DIE *Die) {
823 /// getDieMapSlotFor - Returns the debug information entry map slot for the
824 /// specified debug variable.
825 DIE *&getDieMapSlotFor(GlobalVariable *GV) {
826 return GVToDieMap[GV];
829 /// getDIEntrySlotFor - Returns the debug information entry proxy slot for the
830 /// specified debug variable.
831 DIEntry *&getDIEntrySlotFor(GlobalVariable *GV) {
832 return GVToDIEntryMap[GV];
835 /// AddDie - Adds or interns the DIE to the compile unit.
837 DIE *AddDie(DIE &Buffer) {
841 DIE *Die = DiesSet.FindNodeOrInsertPos(ID, Where);
844 Die = new DIE(Buffer);
845 DiesSet.InsertNode(Die, Where);
846 this->Die->AddChild(Die);
854 //===----------------------------------------------------------------------===//
855 /// Dwarf - Emits general Dwarf directives.
861 //===--------------------------------------------------------------------===//
862 // Core attributes used by the Dwarf writer.
866 /// O - Stream to .s file.
870 /// Asm - Target of Dwarf emission.
874 /// TAI - Target asm information.
875 const TargetAsmInfo *TAI;
877 /// TD - Target data.
878 const TargetData *TD;
880 /// RI - Register Information.
881 const TargetRegisterInfo *RI;
883 /// M - Current module.
887 /// MF - Current machine function.
891 /// MMI - Collected machine module information.
893 MachineModuleInfo *MMI;
895 /// SubprogramCount - The running count of functions being compiled.
897 unsigned SubprogramCount;
899 /// Flavor - A unique string indicating what dwarf producer this is, used to
901 const char * const Flavor;
904 Dwarf(raw_ostream &OS, AsmPrinter *A, const TargetAsmInfo *T,
909 , TD(Asm->TM.getTargetData())
910 , RI(Asm->TM.getRegisterInfo())
922 //===--------------------------------------------------------------------===//
925 AsmPrinter *getAsm() const { return Asm; }
926 MachineModuleInfo *getMMI() const { return MMI; }
927 const TargetAsmInfo *getTargetAsmInfo() const { return TAI; }
928 const TargetData *getTargetData() const { return TD; }
930 void PrintRelDirective(bool Force32Bit = false, bool isInSection = false)
932 if (isInSection && TAI->getDwarfSectionOffsetDirective())
933 O << TAI->getDwarfSectionOffsetDirective();
934 else if (Force32Bit || TD->getPointerSize() == sizeof(int32_t))
935 O << TAI->getData32bitsDirective();
937 O << TAI->getData64bitsDirective();
940 /// PrintLabelName - Print label name in form used by Dwarf writer.
942 void PrintLabelName(DWLabel Label) const {
943 PrintLabelName(Label.Tag, Label.Number);
945 void PrintLabelName(const char *Tag, unsigned Number) const {
946 O << TAI->getPrivateGlobalPrefix() << Tag;
947 if (Number) O << Number;
950 void PrintLabelName(const char *Tag, unsigned Number,
951 const char *Suffix) const {
952 O << TAI->getPrivateGlobalPrefix() << Tag;
953 if (Number) O << Number;
957 /// EmitLabel - Emit location label for internal use by Dwarf.
959 void EmitLabel(DWLabel Label) const {
960 EmitLabel(Label.Tag, Label.Number);
962 void EmitLabel(const char *Tag, unsigned Number) const {
963 PrintLabelName(Tag, Number);
967 /// EmitReference - Emit a reference to a label.
969 void EmitReference(DWLabel Label, bool IsPCRelative = false,
970 bool Force32Bit = false) const {
971 EmitReference(Label.Tag, Label.Number, IsPCRelative, Force32Bit);
973 void EmitReference(const char *Tag, unsigned Number,
974 bool IsPCRelative = false, bool Force32Bit = false) const {
975 PrintRelDirective(Force32Bit);
976 PrintLabelName(Tag, Number);
978 if (IsPCRelative) O << "-" << TAI->getPCSymbol();
980 void EmitReference(const std::string &Name, bool IsPCRelative = false,
981 bool Force32Bit = false) const {
982 PrintRelDirective(Force32Bit);
986 if (IsPCRelative) O << "-" << TAI->getPCSymbol();
989 /// EmitDifference - Emit the difference between two labels. Some
990 /// assemblers do not behave with absolute expressions with data directives,
991 /// so there is an option (needsSet) to use an intermediary set expression.
992 void EmitDifference(DWLabel LabelHi, DWLabel LabelLo,
993 bool IsSmall = false) {
994 EmitDifference(LabelHi.Tag, LabelHi.Number,
995 LabelLo.Tag, LabelLo.Number,
998 void EmitDifference(const char *TagHi, unsigned NumberHi,
999 const char *TagLo, unsigned NumberLo,
1000 bool IsSmall = false) {
1001 if (TAI->needsSet()) {
1003 PrintLabelName("set", SetCounter, Flavor);
1005 PrintLabelName(TagHi, NumberHi);
1007 PrintLabelName(TagLo, NumberLo);
1010 PrintRelDirective(IsSmall);
1011 PrintLabelName("set", SetCounter, Flavor);
1014 PrintRelDirective(IsSmall);
1016 PrintLabelName(TagHi, NumberHi);
1018 PrintLabelName(TagLo, NumberLo);
1022 void EmitSectionOffset(const char* Label, const char* Section,
1023 unsigned LabelNumber, unsigned SectionNumber,
1024 bool IsSmall = false, bool isEH = false,
1025 bool useSet = true) {
1026 bool printAbsolute = false;
1028 printAbsolute = TAI->isAbsoluteEHSectionOffsets();
1030 printAbsolute = TAI->isAbsoluteDebugSectionOffsets();
1032 if (TAI->needsSet() && useSet) {
1034 PrintLabelName("set", SetCounter, Flavor);
1036 PrintLabelName(Label, LabelNumber);
1038 if (!printAbsolute) {
1040 PrintLabelName(Section, SectionNumber);
1044 PrintRelDirective(IsSmall);
1046 PrintLabelName("set", SetCounter, Flavor);
1049 PrintRelDirective(IsSmall, true);
1051 PrintLabelName(Label, LabelNumber);
1053 if (!printAbsolute) {
1055 PrintLabelName(Section, SectionNumber);
1060 /// EmitFrameMoves - Emit frame instructions to describe the layout of the
1062 void EmitFrameMoves(const char *BaseLabel, unsigned BaseLabelID,
1063 const std::vector<MachineMove> &Moves, bool isEH) {
1065 Asm->TM.getFrameInfo()->getStackGrowthDirection() ==
1066 TargetFrameInfo::StackGrowsUp ?
1067 TD->getPointerSize() : -TD->getPointerSize();
1068 bool IsLocal = BaseLabel && strcmp(BaseLabel, "label") == 0;
1070 for (unsigned i = 0, N = Moves.size(); i < N; ++i) {
1071 const MachineMove &Move = Moves[i];
1072 unsigned LabelID = Move.getLabelID();
1075 LabelID = MMI->MappedLabel(LabelID);
1077 // Throw out move if the label is invalid.
1078 if (!LabelID) continue;
1081 const MachineLocation &Dst = Move.getDestination();
1082 const MachineLocation &Src = Move.getSource();
1084 // Advance row if new location.
1085 if (BaseLabel && LabelID && (BaseLabelID != LabelID || !IsLocal)) {
1086 Asm->EmitInt8(DW_CFA_advance_loc4);
1087 Asm->EOL("DW_CFA_advance_loc4");
1088 EmitDifference("label", LabelID, BaseLabel, BaseLabelID, true);
1091 BaseLabelID = LabelID;
1092 BaseLabel = "label";
1096 // If advancing cfa.
1097 if (Dst.isReg() && Dst.getReg() == MachineLocation::VirtualFP) {
1099 if (Src.getReg() == MachineLocation::VirtualFP) {
1100 Asm->EmitInt8(DW_CFA_def_cfa_offset);
1101 Asm->EOL("DW_CFA_def_cfa_offset");
1103 Asm->EmitInt8(DW_CFA_def_cfa);
1104 Asm->EOL("DW_CFA_def_cfa");
1105 Asm->EmitULEB128Bytes(RI->getDwarfRegNum(Src.getReg(), isEH));
1106 Asm->EOL("Register");
1109 int Offset = -Src.getOffset();
1111 Asm->EmitULEB128Bytes(Offset);
1114 assert(0 && "Machine move no supported yet.");
1116 } else if (Src.isReg() &&
1117 Src.getReg() == MachineLocation::VirtualFP) {
1119 Asm->EmitInt8(DW_CFA_def_cfa_register);
1120 Asm->EOL("DW_CFA_def_cfa_register");
1121 Asm->EmitULEB128Bytes(RI->getDwarfRegNum(Dst.getReg(), isEH));
1122 Asm->EOL("Register");
1124 assert(0 && "Machine move no supported yet.");
1127 unsigned Reg = RI->getDwarfRegNum(Src.getReg(), isEH);
1128 int Offset = Dst.getOffset() / stackGrowth;
1131 Asm->EmitInt8(DW_CFA_offset_extended_sf);
1132 Asm->EOL("DW_CFA_offset_extended_sf");
1133 Asm->EmitULEB128Bytes(Reg);
1135 Asm->EmitSLEB128Bytes(Offset);
1137 } else if (Reg < 64) {
1138 Asm->EmitInt8(DW_CFA_offset + Reg);
1140 Asm->EOL("DW_CFA_offset + Reg (" + utostr(Reg) + ")");
1143 Asm->EmitULEB128Bytes(Offset);
1146 Asm->EmitInt8(DW_CFA_offset_extended);
1147 Asm->EOL("DW_CFA_offset_extended");
1148 Asm->EmitULEB128Bytes(Reg);
1150 Asm->EmitULEB128Bytes(Offset);
1159 //===----------------------------------------------------------------------===//
1160 /// SrcLineInfo - This class is used to record source line correspondence.
1163 unsigned Line; // Source line number.
1164 unsigned Column; // Source column.
1165 unsigned SourceID; // Source ID number.
1166 unsigned LabelID; // Label in code ID number.
1168 SrcLineInfo(unsigned L, unsigned C, unsigned S, unsigned I)
1169 : Line(L), Column(C), SourceID(S), LabelID(I) {}
1172 unsigned getLine() const { return Line; }
1173 unsigned getColumn() const { return Column; }
1174 unsigned getSourceID() const { return SourceID; }
1175 unsigned getLabelID() const { return LabelID; }
1179 //===----------------------------------------------------------------------===//
1180 /// SrcFileInfo - This class is used to track source information.
1183 unsigned DirectoryID; // Directory ID number.
1184 std::string Name; // File name (not including directory.)
1186 SrcFileInfo(unsigned D, const std::string &N) : DirectoryID(D), Name(N) {}
1189 unsigned getDirectoryID() const { return DirectoryID; }
1190 const std::string &getName() const { return Name; }
1192 /// operator== - Used by UniqueVector to locate entry.
1194 bool operator==(const SrcFileInfo &SI) const {
1195 return getDirectoryID() == SI.getDirectoryID() && getName() == SI.getName();
1198 /// operator< - Used by UniqueVector to locate entry.
1200 bool operator<(const SrcFileInfo &SI) const {
1201 return getDirectoryID() < SI.getDirectoryID() ||
1202 (getDirectoryID() == SI.getDirectoryID() && getName() < SI.getName());
1206 //===----------------------------------------------------------------------===//
1207 /// DbgVariable - This class is used to track local variable information.
1211 DIVariable Var; // Variable Descriptor.
1212 unsigned FrameIndex; // Variable frame index.
1215 DbgVariable(DIVariable V, unsigned I) : Var(V), FrameIndex(I) {}
1218 DIVariable getVariable() const { return Var; }
1219 unsigned getFrameIndex() const { return FrameIndex; }
1222 //===----------------------------------------------------------------------===//
1223 /// DbgScope - This class is used to track scope information.
1227 DbgScope *Parent; // Parent to this scope.
1228 DIDescriptor Desc; // Debug info descriptor for scope.
1229 // Either subprogram or block.
1230 unsigned StartLabelID; // Label ID of the beginning of scope.
1231 unsigned EndLabelID; // Label ID of the end of scope.
1232 SmallVector<DbgScope *, 4> Scopes; // Scopes defined in scope.
1233 SmallVector<DbgVariable *, 8> Variables;// Variables declared in scope.
1236 DbgScope(DbgScope *P, DIDescriptor D)
1237 : Parent(P), Desc(D), StartLabelID(0), EndLabelID(0), Scopes(), Variables()
1240 for (unsigned i = 0, N = Scopes.size(); i < N; ++i) delete Scopes[i];
1241 for (unsigned j = 0, M = Variables.size(); j < M; ++j) delete Variables[j];
1245 DbgScope *getParent() const { return Parent; }
1246 DIDescriptor getDesc() const { return Desc; }
1247 unsigned getStartLabelID() const { return StartLabelID; }
1248 unsigned getEndLabelID() const { return EndLabelID; }
1249 SmallVector<DbgScope *, 4> &getScopes() { return Scopes; }
1250 SmallVector<DbgVariable *, 8> &getVariables() { return Variables; }
1251 void setStartLabelID(unsigned S) { StartLabelID = S; }
1252 void setEndLabelID(unsigned E) { EndLabelID = E; }
1254 /// AddScope - Add a scope to the scope.
1256 void AddScope(DbgScope *S) { Scopes.push_back(S); }
1258 /// AddVariable - Add a variable to the scope.
1260 void AddVariable(DbgVariable *V) { Variables.push_back(V); }
1263 //===----------------------------------------------------------------------===//
1264 /// DwarfDebug - Emits Dwarf debug directives.
1266 class DwarfDebug : public Dwarf {
1269 //===--------------------------------------------------------------------===//
1270 // Attributes used to construct specific Dwarf sections.
1273 /// DW_CUs - All the compile units involved in this build. The index
1274 /// of each entry in this vector corresponds to the sources in MMI.
1275 DenseMap<Value *, CompileUnit *> DW_CUs;
1277 /// AbbreviationsSet - Used to uniquely define abbreviations.
1279 FoldingSet<DIEAbbrev> AbbreviationsSet;
1281 /// Abbreviations - A list of all the unique abbreviations in use.
1283 std::vector<DIEAbbrev *> Abbreviations;
1285 /// Directories - Uniquing vector for directories.
1286 UniqueVector<std::string> Directories;
1288 /// SourceFiles - Uniquing vector for source files.
1289 UniqueVector<SrcFileInfo> SrcFiles;
1291 /// Lines - List of of source line correspondence.
1292 std::vector<SrcLineInfo> Lines;
1294 /// ValuesSet - Used to uniquely define values.
1296 FoldingSet<DIEValue> ValuesSet;
1298 /// Values - A list of all the unique values in use.
1300 std::vector<DIEValue *> Values;
1302 /// StringPool - A UniqueVector of strings used by indirect references.
1304 UniqueVector<std::string> StringPool;
1306 /// SectionMap - Provides a unique id per text section.
1308 UniqueVector<const Section*> SectionMap;
1310 /// SectionSourceLines - Tracks line numbers per text section.
1312 std::vector<std::vector<SrcLineInfo> > SectionSourceLines;
1314 /// didInitial - Flag to indicate if initial emission has been done.
1318 /// shouldEmit - Flag to indicate if debug information should be emitted.
1322 // RootDbgScope - Top level scope for the current function.
1324 DbgScope *RootDbgScope;
1326 // DbgScopeMap - Tracks the scopes in the current function.
1327 DenseMap<GlobalVariable *, DbgScope *> DbgScopeMap;
1329 struct FunctionDebugFrameInfo {
1331 std::vector<MachineMove> Moves;
1333 FunctionDebugFrameInfo(unsigned Num, const std::vector<MachineMove> &M):
1334 Number(Num), Moves(M) { }
1337 std::vector<FunctionDebugFrameInfo> DebugFrames;
1341 /// ShouldEmitDwarf - Returns true if Dwarf declarations should be made.
1343 bool ShouldEmitDwarf() const { return shouldEmit; }
1345 /// AssignAbbrevNumber - Define a unique number for the abbreviation.
1347 void AssignAbbrevNumber(DIEAbbrev &Abbrev) {
1348 // Profile the node so that we can make it unique.
1349 FoldingSetNodeID ID;
1352 // Check the set for priors.
1353 DIEAbbrev *InSet = AbbreviationsSet.GetOrInsertNode(&Abbrev);
1355 // If it's newly added.
1356 if (InSet == &Abbrev) {
1357 // Add to abbreviation list.
1358 Abbreviations.push_back(&Abbrev);
1359 // Assign the vector position + 1 as its number.
1360 Abbrev.setNumber(Abbreviations.size());
1362 // Assign existing abbreviation number.
1363 Abbrev.setNumber(InSet->getNumber());
1367 /// NewString - Add a string to the constant pool and returns a label.
1369 DWLabel NewString(const std::string &String) {
1370 unsigned StringID = StringPool.insert(String);
1371 return DWLabel("string", StringID);
1374 /// NewDIEntry - Creates a new DIEntry to be a proxy for a debug information
1376 DIEntry *NewDIEntry(DIE *Entry = NULL) {
1380 FoldingSetNodeID ID;
1381 DIEntry::Profile(ID, Entry);
1383 Value = static_cast<DIEntry *>(ValuesSet.FindNodeOrInsertPos(ID, Where));
1385 if (Value) return Value;
1387 Value = new DIEntry(Entry);
1388 ValuesSet.InsertNode(Value, Where);
1390 Value = new DIEntry(Entry);
1393 Values.push_back(Value);
1397 /// SetDIEntry - Set a DIEntry once the debug information entry is defined.
1399 void SetDIEntry(DIEntry *Value, DIE *Entry) {
1400 Value->Entry = Entry;
1401 // Add to values set if not already there. If it is, we merely have a
1402 // duplicate in the values list (no harm.)
1403 ValuesSet.GetOrInsertNode(Value);
1406 /// AddUInt - Add an unsigned integer attribute data and value.
1408 void AddUInt(DIE *Die, unsigned Attribute, unsigned Form, uint64_t Integer) {
1409 if (!Form) Form = DIEInteger::BestForm(false, Integer);
1411 FoldingSetNodeID ID;
1412 DIEInteger::Profile(ID, Integer);
1414 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
1416 Value = new DIEInteger(Integer);
1417 ValuesSet.InsertNode(Value, Where);
1418 Values.push_back(Value);
1421 Die->AddValue(Attribute, Form, Value);
1424 /// AddSInt - Add an signed integer attribute data and value.
1426 void AddSInt(DIE *Die, unsigned Attribute, unsigned Form, int64_t Integer) {
1427 if (!Form) Form = DIEInteger::BestForm(true, Integer);
1429 FoldingSetNodeID ID;
1430 DIEInteger::Profile(ID, (uint64_t)Integer);
1432 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
1434 Value = new DIEInteger(Integer);
1435 ValuesSet.InsertNode(Value, Where);
1436 Values.push_back(Value);
1439 Die->AddValue(Attribute, Form, Value);
1442 /// AddString - Add a std::string attribute data and value.
1444 void AddString(DIE *Die, unsigned Attribute, unsigned Form,
1445 const std::string &String) {
1446 FoldingSetNodeID ID;
1447 DIEString::Profile(ID, String);
1449 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
1451 Value = new DIEString(String);
1452 ValuesSet.InsertNode(Value, Where);
1453 Values.push_back(Value);
1456 Die->AddValue(Attribute, Form, Value);
1459 /// AddLabel - Add a Dwarf label attribute data and value.
1461 void AddLabel(DIE *Die, unsigned Attribute, unsigned Form,
1462 const DWLabel &Label) {
1463 FoldingSetNodeID ID;
1464 DIEDwarfLabel::Profile(ID, Label);
1466 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
1468 Value = new DIEDwarfLabel(Label);
1469 ValuesSet.InsertNode(Value, Where);
1470 Values.push_back(Value);
1473 Die->AddValue(Attribute, Form, Value);
1476 /// AddObjectLabel - Add an non-Dwarf label attribute data and value.
1478 void AddObjectLabel(DIE *Die, unsigned Attribute, unsigned Form,
1479 const std::string &Label) {
1480 FoldingSetNodeID ID;
1481 DIEObjectLabel::Profile(ID, Label);
1483 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
1485 Value = new DIEObjectLabel(Label);
1486 ValuesSet.InsertNode(Value, Where);
1487 Values.push_back(Value);
1490 Die->AddValue(Attribute, Form, Value);
1493 /// AddSectionOffset - Add a section offset label attribute data and value.
1495 void AddSectionOffset(DIE *Die, unsigned Attribute, unsigned Form,
1496 const DWLabel &Label, const DWLabel &Section,
1497 bool isEH = false, bool useSet = true) {
1498 FoldingSetNodeID ID;
1499 DIESectionOffset::Profile(ID, Label, Section);
1501 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
1503 Value = new DIESectionOffset(Label, Section, isEH, useSet);
1504 ValuesSet.InsertNode(Value, Where);
1505 Values.push_back(Value);
1508 Die->AddValue(Attribute, Form, Value);
1511 /// AddDelta - Add a label delta attribute data and value.
1513 void AddDelta(DIE *Die, unsigned Attribute, unsigned Form,
1514 const DWLabel &Hi, const DWLabel &Lo) {
1515 FoldingSetNodeID ID;
1516 DIEDelta::Profile(ID, Hi, Lo);
1518 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
1520 Value = new DIEDelta(Hi, Lo);
1521 ValuesSet.InsertNode(Value, Where);
1522 Values.push_back(Value);
1525 Die->AddValue(Attribute, Form, Value);
1528 /// AddDIEntry - Add a DIE attribute data and value.
1530 void AddDIEntry(DIE *Die, unsigned Attribute, unsigned Form, DIE *Entry) {
1531 Die->AddValue(Attribute, Form, NewDIEntry(Entry));
1534 /// AddBlock - Add block data.
1536 void AddBlock(DIE *Die, unsigned Attribute, unsigned Form, DIEBlock *Block) {
1537 Block->ComputeSize(*this);
1538 FoldingSetNodeID ID;
1541 DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where);
1544 ValuesSet.InsertNode(Value, Where);
1545 Values.push_back(Value);
1547 // Already exists, reuse the previous one.
1549 Block = cast<DIEBlock>(Value);
1552 Die->AddValue(Attribute, Block->BestForm(), Value);
1557 /// AddSourceLine - Add location information to specified debug information
1559 void AddSourceLine(DIE *Die, const DIVariable *V) {
1560 unsigned FileID = 0;
1561 unsigned Line = V->getLineNumber();
1562 if (V->getVersion() < DIDescriptor::Version7) {
1563 // Version6 or earlier. Use compile unit info to get file id.
1564 CompileUnit *Unit = FindCompileUnit(V->getCompileUnit());
1565 FileID = Unit->getID();
1567 // Version7 or newer, use filename and directory info from DIVariable
1569 unsigned DID = Directories.idFor(V->getDirectory());
1570 FileID = SrcFiles.idFor(SrcFileInfo(DID, V->getFilename()));
1572 AddUInt(Die, DW_AT_decl_file, 0, FileID);
1573 AddUInt(Die, DW_AT_decl_line, 0, Line);
1576 /// AddSourceLine - Add location information to specified debug information
1578 void AddSourceLine(DIE *Die, const DIGlobal *G) {
1579 unsigned FileID = 0;
1580 unsigned Line = G->getLineNumber();
1581 if (G->getVersion() < DIDescriptor::Version7) {
1582 // Version6 or earlier. Use compile unit info to get file id.
1583 CompileUnit *Unit = FindCompileUnit(G->getCompileUnit());
1584 FileID = Unit->getID();
1586 // Version7 or newer, use filename and directory info from DIGlobal
1588 unsigned DID = Directories.idFor(G->getDirectory());
1589 FileID = SrcFiles.idFor(SrcFileInfo(DID, G->getFilename()));
1591 AddUInt(Die, DW_AT_decl_file, 0, FileID);
1592 AddUInt(Die, DW_AT_decl_line, 0, Line);
1595 void AddSourceLine(DIE *Die, const DIType *Ty) {
1596 unsigned FileID = 0;
1597 unsigned Line = Ty->getLineNumber();
1598 if (Ty->getVersion() < DIDescriptor::Version7) {
1599 // Version6 or earlier. Use compile unit info to get file id.
1600 CompileUnit *Unit = FindCompileUnit(Ty->getCompileUnit());
1601 FileID = Unit->getID();
1603 // Version7 or newer, use filename and directory info from DIType
1605 unsigned DID = Directories.idFor(Ty->getDirectory());
1606 FileID = SrcFiles.idFor(SrcFileInfo(DID, Ty->getFilename()));
1608 AddUInt(Die, DW_AT_decl_file, 0, FileID);
1609 AddUInt(Die, DW_AT_decl_line, 0, Line);
1612 /// AddAddress - Add an address attribute to a die based on the location
1614 void AddAddress(DIE *Die, unsigned Attribute,
1615 const MachineLocation &Location) {
1616 unsigned Reg = RI->getDwarfRegNum(Location.getReg(), false);
1617 DIEBlock *Block = new DIEBlock();
1619 if (Location.isReg()) {
1621 AddUInt(Block, 0, DW_FORM_data1, DW_OP_reg0 + Reg);
1623 AddUInt(Block, 0, DW_FORM_data1, DW_OP_regx);
1624 AddUInt(Block, 0, DW_FORM_udata, Reg);
1628 AddUInt(Block, 0, DW_FORM_data1, DW_OP_breg0 + Reg);
1630 AddUInt(Block, 0, DW_FORM_data1, DW_OP_bregx);
1631 AddUInt(Block, 0, DW_FORM_udata, Reg);
1633 AddUInt(Block, 0, DW_FORM_sdata, Location.getOffset());
1636 AddBlock(Die, Attribute, 0, Block);
1639 /// AddBasicType - Add a new basic type attribute to the specified entity.
1641 void AddBasicType(DIE *Entity, CompileUnit *Unit,
1642 const std::string &Name,
1643 unsigned Encoding, unsigned Size) {
1645 DIE Buffer(DW_TAG_base_type);
1646 AddUInt(&Buffer, DW_AT_byte_size, 0, Size);
1647 AddUInt(&Buffer, DW_AT_encoding, DW_FORM_data1, Encoding);
1648 if (!Name.empty()) AddString(&Buffer, DW_AT_name, DW_FORM_string, Name);
1649 DIE *BasicTypeDie = Unit->AddDie(Buffer);
1650 AddDIEntry(Entity, DW_AT_type, DW_FORM_ref4, BasicTypeDie);
1653 /// AddPointerType - Add a new pointer type attribute to the specified entity.
1655 void AddPointerType(DIE *Entity, CompileUnit *Unit, const std::string &Name) {
1656 DIE Buffer(DW_TAG_pointer_type);
1657 AddUInt(&Buffer, DW_AT_byte_size, 0, TD->getPointerSize());
1658 if (!Name.empty()) AddString(&Buffer, DW_AT_name, DW_FORM_string, Name);
1659 DIE *PointerTypeDie = Unit->AddDie(Buffer);
1660 AddDIEntry(Entity, DW_AT_type, DW_FORM_ref4, PointerTypeDie);
1663 /// AddType - Add a new type attribute to the specified entity.
1664 void AddType(CompileUnit *DW_Unit, DIE *Entity, DIType Ty) {
1666 AddBasicType(Entity, DW_Unit, "", DW_ATE_signed, sizeof(int32_t));
1670 // Check for pre-existence.
1671 DIEntry *&Slot = DW_Unit->getDIEntrySlotFor(Ty.getGV());
1672 // If it exists then use the existing value.
1674 Entity->AddValue(DW_AT_type, DW_FORM_ref4, Slot);
1679 Slot = NewDIEntry();
1682 DIE Buffer(DW_TAG_base_type);
1683 if (Ty.isBasicType(Ty.getTag()))
1684 ConstructTypeDIE(DW_Unit, Buffer, DIBasicType(Ty.getGV()));
1685 else if (Ty.isDerivedType(Ty.getTag()))
1686 ConstructTypeDIE(DW_Unit, Buffer, DIDerivedType(Ty.getGV()));
1688 assert (Ty.isCompositeType(Ty.getTag()) && "Unknown kind of DIType");
1689 ConstructTypeDIE(DW_Unit, Buffer, DICompositeType(Ty.getGV()));
1692 // Add debug information entry to entity and unit.
1693 DIE *Die = DW_Unit->AddDie(Buffer);
1694 SetDIEntry(Slot, Die);
1695 Entity->AddValue(DW_AT_type, DW_FORM_ref4, Slot);
1698 /// ConstructTypeDIE - Construct basic type die from DIBasicType.
1699 void ConstructTypeDIE(CompileUnit *DW_Unit, DIE &Buffer,
1702 // Get core information.
1703 const std::string &Name = BTy.getName();
1704 Buffer.setTag(DW_TAG_base_type);
1705 AddUInt(&Buffer, DW_AT_encoding, DW_FORM_data1, BTy.getEncoding());
1706 // Add name if not anonymous or intermediate type.
1708 AddString(&Buffer, DW_AT_name, DW_FORM_string, Name);
1709 uint64_t Size = BTy.getSizeInBits() >> 3;
1710 AddUInt(&Buffer, DW_AT_byte_size, 0, Size);
1713 /// ConstructTypeDIE - Construct derived type die from DIDerivedType.
1714 void ConstructTypeDIE(CompileUnit *DW_Unit, DIE &Buffer,
1715 DIDerivedType DTy) {
1717 // Get core information.
1718 const std::string &Name = DTy.getName();
1719 uint64_t Size = DTy.getSizeInBits() >> 3;
1720 unsigned Tag = DTy.getTag();
1721 // FIXME - Workaround for templates.
1722 if (Tag == DW_TAG_inheritance) Tag = DW_TAG_reference_type;
1725 // Map to main type, void will not have a type.
1726 DIType FromTy = DTy.getTypeDerivedFrom();
1727 AddType(DW_Unit, &Buffer, FromTy);
1729 // Add name if not anonymous or intermediate type.
1730 if (!Name.empty()) AddString(&Buffer, DW_AT_name, DW_FORM_string, Name);
1732 // Add size if non-zero (derived types might be zero-sized.)
1734 AddUInt(&Buffer, DW_AT_byte_size, 0, Size);
1736 // Add source line info if available and TyDesc is not a forward
1738 // FIXME - Enable this. if (!DTy.isForwardDecl())
1739 // FIXME - Enable this. AddSourceLine(&Buffer, *DTy);
1742 /// ConstructTypeDIE - Construct type DIE from DICompositeType.
1743 void ConstructTypeDIE(CompileUnit *DW_Unit, DIE &Buffer,
1744 DICompositeType CTy) {
1746 /// FIXME - Enable this asap.
1749 // Get core information.
1750 const std::string &Name = CTy.getName();
1751 uint64_t Size = CTy.getSizeInBits() >> 3;
1752 unsigned Tag = CTy.getTag();
1754 case DW_TAG_vector_type:
1755 case DW_TAG_array_type:
1756 ConstructArrayTypeDIE(DW_Unit, Buffer, &CTy);
1758 //FIXME - Enable this.
1759 // case DW_TAG_enumeration_type:
1760 // DIArray Elements = CTy.getTypeArray();
1761 // // Add enumerators to enumeration type.
1762 // for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i)
1763 // ConstructEnumTypeDIE(Buffer, &Elements.getElement(i));
1765 case DW_TAG_subroutine_type:
1767 // Add prototype flag.
1768 AddUInt(&Buffer, DW_AT_prototyped, DW_FORM_flag, 1);
1769 DIArray Elements = CTy.getTypeArray();
1771 DIDescriptor RTy = Elements.getElement(0);
1772 AddType(DW_Unit, &Buffer, DIType(RTy.getGV()));
1775 for (unsigned i = 1, N = Elements.getNumElements(); i < N; ++i) {
1776 DIE *Arg = new DIE(DW_TAG_formal_parameter);
1777 DIDescriptor Ty = Elements.getElement(i);
1778 AddType(DW_Unit, Arg, DIType(Ty.getGV()));
1779 Buffer.AddChild(Arg);
1783 case DW_TAG_structure_type:
1784 case DW_TAG_union_type:
1786 // Add elements to structure type.
1787 DIArray Elements = CTy.getTypeArray();
1789 // A forward struct declared type may not have elements available.
1790 if (Elements.isNull())
1793 // Add elements to structure type.
1794 for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
1795 DIDescriptor Element = Elements.getElement(i);
1796 DIE *ElemDie = NULL;
1797 if (Element.getTag() == dwarf::DW_TAG_subprogram)
1798 ElemDie = CreateSubprogramDIE(DW_Unit,
1799 DISubprogram(Element.getGV()));
1800 else if (Element.getTag() == dwarf::DW_TAG_variable) // ???
1801 ElemDie = CreateGlobalVariableDIE(DW_Unit,
1802 DIGlobalVariable(Element.getGV()));
1804 DIDerivedType DT = DIDerivedType(Element.getGV());
1805 assert (DT.isDerivedType(DT.getTag())
1806 && "Unexpected struct element type");
1807 ElemDie = new DIE(DT.getTag());
1808 AddType(DW_Unit, ElemDie, DT);
1810 Buffer.AddChild(ElemDie);
1818 // Add name if not anonymous or intermediate type.
1819 if (!Name.empty()) AddString(&Buffer, DW_AT_name, DW_FORM_string, Name);
1821 // Add size if non-zero (derived types might be zero-sized.)
1823 AddUInt(&Buffer, DW_AT_byte_size, 0, Size);
1825 // Add zero size even if it is not a forward declaration.
1826 // FIXME - Enable this.
1827 // if (!CTy.isDefinition())
1828 // AddUInt(&Buffer, DW_AT_declaration, DW_FORM_flag, 1);
1830 // AddUInt(&Buffer, DW_AT_byte_size, 0, 0);
1833 // Add source line info if available and TyDesc is not a forward
1835 // FIXME - Enable this.
1836 // if (CTy.isForwardDecl())
1837 // AddSourceLine(&Buffer, *CTy);
1840 // ConstructSubrangeDIE - Construct subrange DIE from DISubrange.
1841 void ConstructSubrangeDIE (DIE &Buffer, DISubrange SR, DIE *IndexTy) {
1842 int64_t L = SR.getLo();
1843 int64_t H = SR.getHi();
1844 DIE *DW_Subrange = new DIE(DW_TAG_subrange_type);
1846 AddDIEntry(DW_Subrange, DW_AT_type, DW_FORM_ref4, IndexTy);
1848 AddSInt(DW_Subrange, DW_AT_lower_bound, 0, L);
1849 AddSInt(DW_Subrange, DW_AT_upper_bound, 0, H);
1851 Buffer.AddChild(DW_Subrange);
1854 /// ConstructArrayTypeDIE - Construct array type DIE from DICompositeType.
1855 void ConstructArrayTypeDIE(CompileUnit *DW_Unit, DIE &Buffer,
1856 DICompositeType *CTy) {
1857 Buffer.setTag(DW_TAG_array_type);
1858 if (CTy->getTag() == DW_TAG_vector_type)
1859 AddUInt(&Buffer, DW_AT_GNU_vector, DW_FORM_flag, 1);
1861 DIArray Elements = CTy->getTypeArray();
1862 // FIXME - Enable this.
1863 AddType(DW_Unit, &Buffer, CTy->getTypeDerivedFrom());
1865 // Construct an anonymous type for index type.
1866 DIE IdxBuffer(DW_TAG_base_type);
1867 AddUInt(&IdxBuffer, DW_AT_byte_size, 0, sizeof(int32_t));
1868 AddUInt(&IdxBuffer, DW_AT_encoding, DW_FORM_data1, DW_ATE_signed);
1869 DIE *IndexTy = DW_Unit->AddDie(IdxBuffer);
1871 // Add subranges to array type.
1872 for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
1873 DIDescriptor Element = Elements.getElement(i);
1874 if (Element.getTag() == dwarf::DW_TAG_subrange_type)
1875 ConstructSubrangeDIE(Buffer, DISubrange(Element.getGV()), IndexTy);
1879 /// ConstructEnumTypeDIE - Construct enum type DIE from
1881 void ConstructEnumTypeDIE(CompileUnit *DW_Unit,
1882 DIE &Buffer, DIEnumerator *ETy) {
1884 DIE *Enumerator = new DIE(DW_TAG_enumerator);
1885 AddString(Enumerator, DW_AT_name, DW_FORM_string, ETy->getName());
1886 int64_t Value = ETy->getEnumValue();
1887 AddSInt(Enumerator, DW_AT_const_value, DW_FORM_sdata, Value);
1888 Buffer.AddChild(Enumerator);
1891 /// CreateGlobalVariableDIE - Create new DIE using GV.
1892 DIE *CreateGlobalVariableDIE(CompileUnit *DW_Unit, const DIGlobalVariable &GV)
1894 DIE *GVDie = new DIE(DW_TAG_variable);
1895 AddString(GVDie, DW_AT_name, DW_FORM_string, GV.getName());
1896 const std::string &LinkageName = GV.getLinkageName();
1897 if (!LinkageName.empty())
1898 AddString(GVDie, DW_AT_MIPS_linkage_name, DW_FORM_string, LinkageName);
1899 AddType(DW_Unit, GVDie, GV.getType());
1900 if (!GV.isLocalToUnit())
1901 AddUInt(GVDie, DW_AT_external, DW_FORM_flag, 1);
1902 AddSourceLine(GVDie, &GV);
1906 /// CreateSubprogramDIE - Create new DIE using SP.
1907 DIE *CreateSubprogramDIE(CompileUnit *DW_Unit,
1908 const DISubprogram &SP,
1909 bool IsConstructor = false) {
1910 DIE *SPDie = new DIE(DW_TAG_subprogram);
1911 AddString(SPDie, DW_AT_name, DW_FORM_string, SP.getName());
1912 const std::string &LinkageName = SP.getLinkageName();
1913 if (!LinkageName.empty())
1914 AddString(SPDie, DW_AT_MIPS_linkage_name, DW_FORM_string,
1916 AddSourceLine(SPDie, &SP);
1918 DICompositeType SPTy = SP.getType();
1919 DIArray Args = SPTy.getTypeArray();
1923 AddType(DW_Unit, SPDie, DIType(Args.getElement(0).getGV()));
1927 for (unsigned i = 1, N = Args.getNumElements(); i < N; ++i) {
1928 DIE *Arg = new DIE(DW_TAG_formal_parameter);
1929 AddType(DW_Unit, Arg, DIType(Args.getElement(i).getGV()));
1930 AddUInt(Arg, DW_AT_artificial, DW_FORM_flag, 1); // ???
1931 SPDie->AddChild(Arg);
1934 if (!SP.isLocalToUnit())
1935 AddUInt(SPDie, DW_AT_external, DW_FORM_flag, 1);
1939 /// FindCompileUnit - Get the compile unit for the given descriptor.
1941 CompileUnit *FindCompileUnit(DICompileUnit Unit) {
1942 CompileUnit *DW_Unit = DW_CUs[Unit.getGV()];
1943 assert(DW_Unit && "Missing compile unit.");
1947 /// NewDbgScopeVariable - Create a new scope variable.
1949 DIE *NewDbgScopeVariable(DbgVariable *DV, CompileUnit *Unit) {
1950 // Get the descriptor.
1951 const DIVariable &VD = DV->getVariable();
1953 // Translate tag to proper Dwarf tag. The result variable is dropped for
1956 switch (VD.getTag()) {
1957 case DW_TAG_return_variable: return NULL;
1958 case DW_TAG_arg_variable: Tag = DW_TAG_formal_parameter; break;
1959 case DW_TAG_auto_variable: // fall thru
1960 default: Tag = DW_TAG_variable; break;
1963 // Define variable debug information entry.
1964 DIE *VariableDie = new DIE(Tag);
1965 AddString(VariableDie, DW_AT_name, DW_FORM_string, VD.getName());
1967 // Add source line info if available.
1968 AddSourceLine(VariableDie, &VD);
1970 // Add variable type.
1971 AddType(Unit, VariableDie, VD.getType());
1973 // Add variable address.
1974 MachineLocation Location;
1975 Location.set(RI->getFrameRegister(*MF),
1976 RI->getFrameIndexOffset(*MF, DV->getFrameIndex()));
1977 AddAddress(VariableDie, DW_AT_location, Location);
1982 /// getOrCreateScope - Returns the scope associated with the given descriptor.
1984 DbgScope *getOrCreateScope(GlobalVariable *V) {
1985 DbgScope *&Slot = DbgScopeMap[V];
1987 // FIXME - breaks down when the context is an inlined function.
1988 DIDescriptor ParentDesc;
1989 DIDescriptor Desc(V);
1990 if (Desc.getTag() == dwarf::DW_TAG_lexical_block) {
1992 ParentDesc = Block.getContext();
1994 DbgScope *Parent = ParentDesc.isNull() ?
1995 NULL : getOrCreateScope(ParentDesc.getGV());
1996 Slot = new DbgScope(Parent, Desc);
1998 Parent->AddScope(Slot);
1999 } else if (RootDbgScope) {
2000 // FIXME - Add inlined function scopes to the root so we can delete
2001 // them later. Long term, handle inlined functions properly.
2002 RootDbgScope->AddScope(Slot);
2004 // First function is top level function.
2005 RootDbgScope = Slot;
2011 /// ConstructDbgScope - Construct the components of a scope.
2013 void ConstructDbgScope(DbgScope *ParentScope,
2014 unsigned ParentStartID, unsigned ParentEndID,
2015 DIE *ParentDie, CompileUnit *Unit) {
2016 // Add variables to scope.
2017 SmallVector<DbgVariable *, 8> &Variables = ParentScope->getVariables();
2018 for (unsigned i = 0, N = Variables.size(); i < N; ++i) {
2019 DIE *VariableDie = NewDbgScopeVariable(Variables[i], Unit);
2020 if (VariableDie) ParentDie->AddChild(VariableDie);
2023 // Add nested scopes.
2024 SmallVector<DbgScope *, 4> &Scopes = ParentScope->getScopes();
2025 for (unsigned j = 0, M = Scopes.size(); j < M; ++j) {
2026 // Define the Scope debug information entry.
2027 DbgScope *Scope = Scopes[j];
2028 // FIXME - Ignore inlined functions for the time being.
2029 if (!Scope->getParent()) continue;
2031 unsigned StartID = MMI->MappedLabel(Scope->getStartLabelID());
2032 unsigned EndID = MMI->MappedLabel(Scope->getEndLabelID());
2034 // Ignore empty scopes.
2035 if (StartID == EndID && StartID != 0) continue;
2036 if (Scope->getScopes().empty() && Scope->getVariables().empty()) continue;
2038 if (StartID == ParentStartID && EndID == ParentEndID) {
2039 // Just add stuff to the parent scope.
2040 ConstructDbgScope(Scope, ParentStartID, ParentEndID, ParentDie, Unit);
2042 DIE *ScopeDie = new DIE(DW_TAG_lexical_block);
2044 // Add the scope bounds.
2046 AddLabel(ScopeDie, DW_AT_low_pc, DW_FORM_addr,
2047 DWLabel("label", StartID));
2049 AddLabel(ScopeDie, DW_AT_low_pc, DW_FORM_addr,
2050 DWLabel("func_begin", SubprogramCount));
2053 AddLabel(ScopeDie, DW_AT_high_pc, DW_FORM_addr,
2054 DWLabel("label", EndID));
2056 AddLabel(ScopeDie, DW_AT_high_pc, DW_FORM_addr,
2057 DWLabel("func_end", SubprogramCount));
2060 // Add the scope contents.
2061 ConstructDbgScope(Scope, StartID, EndID, ScopeDie, Unit);
2062 ParentDie->AddChild(ScopeDie);
2067 /// ConstructRootDbgScope - Construct the scope for the subprogram.
2069 void ConstructRootDbgScope(DbgScope *RootScope) {
2070 // Exit if there is no root scope.
2071 if (!RootScope) return;
2072 DIDescriptor Desc = RootScope->getDesc();
2076 // Get the subprogram debug information entry.
2077 DISubprogram SPD(Desc.getGV());
2079 // Get the compile unit context.
2080 CompileUnit *Unit = FindCompileUnit(SPD.getCompileUnit());
2082 // Get the subprogram die.
2083 DIE *SPDie = Unit->getDieMapSlotFor(SPD.getGV());
2084 assert(SPDie && "Missing subprogram descriptor");
2086 // Add the function bounds.
2087 AddLabel(SPDie, DW_AT_low_pc, DW_FORM_addr,
2088 DWLabel("func_begin", SubprogramCount));
2089 AddLabel(SPDie, DW_AT_high_pc, DW_FORM_addr,
2090 DWLabel("func_end", SubprogramCount));
2091 MachineLocation Location(RI->getFrameRegister(*MF));
2092 AddAddress(SPDie, DW_AT_frame_base, Location);
2094 ConstructDbgScope(RootScope, 0, 0, SPDie, Unit);
2097 /// ConstructDefaultDbgScope - Construct a default scope for the subprogram.
2099 void ConstructDefaultDbgScope(MachineFunction *MF) {
2100 // Find the correct subprogram descriptor.
2101 std::string SPName = "llvm.dbg.subprograms";
2102 std::vector<GlobalVariable*> Result;
2103 getGlobalVariablesUsing(*M, SPName, Result);
2104 for (std::vector<GlobalVariable *>::iterator I = Result.begin(),
2105 E = Result.end(); I != E; ++I) {
2107 DISubprogram SPD(*I);
2109 if (SPD.getName() == MF->getFunction()->getName()) {
2110 // Get the compile unit context.
2111 CompileUnit *Unit = FindCompileUnit(SPD.getCompileUnit());
2113 // Get the subprogram die.
2114 DIE *SPDie = Unit->getDieMapSlotFor(SPD.getGV());
2115 assert(SPDie && "Missing subprogram descriptor");
2117 // Add the function bounds.
2118 AddLabel(SPDie, DW_AT_low_pc, DW_FORM_addr,
2119 DWLabel("func_begin", SubprogramCount));
2120 AddLabel(SPDie, DW_AT_high_pc, DW_FORM_addr,
2121 DWLabel("func_end", SubprogramCount));
2123 MachineLocation Location(RI->getFrameRegister(*MF));
2124 AddAddress(SPDie, DW_AT_frame_base, Location);
2129 // FIXME: This is causing an abort because C++ mangled names are compared
2130 // with their unmangled counterparts. See PR2885. Don't do this assert.
2131 assert(0 && "Couldn't find DIE for machine function!");
2135 /// EmitInitial - Emit initial Dwarf declarations. This is necessary for cc
2136 /// tools to recognize the object file contains Dwarf information.
2137 void EmitInitial() {
2138 // Check to see if we already emitted intial headers.
2139 if (didInitial) return;
2142 // Dwarf sections base addresses.
2143 if (TAI->doesDwarfRequireFrameSection()) {
2144 Asm->SwitchToDataSection(TAI->getDwarfFrameSection());
2145 EmitLabel("section_debug_frame", 0);
2147 Asm->SwitchToDataSection(TAI->getDwarfInfoSection());
2148 EmitLabel("section_info", 0);
2149 Asm->SwitchToDataSection(TAI->getDwarfAbbrevSection());
2150 EmitLabel("section_abbrev", 0);
2151 Asm->SwitchToDataSection(TAI->getDwarfARangesSection());
2152 EmitLabel("section_aranges", 0);
2153 Asm->SwitchToDataSection(TAI->getDwarfMacInfoSection());
2154 EmitLabel("section_macinfo", 0);
2155 Asm->SwitchToDataSection(TAI->getDwarfLineSection());
2156 EmitLabel("section_line", 0);
2157 Asm->SwitchToDataSection(TAI->getDwarfLocSection());
2158 EmitLabel("section_loc", 0);
2159 Asm->SwitchToDataSection(TAI->getDwarfPubNamesSection());
2160 EmitLabel("section_pubnames", 0);
2161 Asm->SwitchToDataSection(TAI->getDwarfStrSection());
2162 EmitLabel("section_str", 0);
2163 Asm->SwitchToDataSection(TAI->getDwarfRangesSection());
2164 EmitLabel("section_ranges", 0);
2166 Asm->SwitchToSection(TAI->getTextSection());
2167 EmitLabel("text_begin", 0);
2168 Asm->SwitchToSection(TAI->getDataSection());
2169 EmitLabel("data_begin", 0);
2172 /// EmitDIE - Recusively Emits a debug information entry.
2174 void EmitDIE(DIE *Die) {
2175 // Get the abbreviation for this DIE.
2176 unsigned AbbrevNumber = Die->getAbbrevNumber();
2177 const DIEAbbrev *Abbrev = Abbreviations[AbbrevNumber - 1];
2181 // Emit the code (index) for the abbreviation.
2182 Asm->EmitULEB128Bytes(AbbrevNumber);
2185 Asm->EOL(std::string("Abbrev [" +
2186 utostr(AbbrevNumber) +
2187 "] 0x" + utohexstr(Die->getOffset()) +
2188 ":0x" + utohexstr(Die->getSize()) + " " +
2189 TagString(Abbrev->getTag())));
2193 SmallVector<DIEValue*, 32> &Values = Die->getValues();
2194 const SmallVector<DIEAbbrevData, 8> &AbbrevData = Abbrev->getData();
2196 // Emit the DIE attribute values.
2197 for (unsigned i = 0, N = Values.size(); i < N; ++i) {
2198 unsigned Attr = AbbrevData[i].getAttribute();
2199 unsigned Form = AbbrevData[i].getForm();
2200 assert(Form && "Too many attributes for DIE (check abbreviation)");
2203 case DW_AT_sibling: {
2204 Asm->EmitInt32(Die->SiblingOffset());
2208 // Emit an attribute using the defined form.
2209 Values[i]->EmitValue(*this, Form);
2214 Asm->EOL(AttributeString(Attr));
2217 // Emit the DIE children if any.
2218 if (Abbrev->getChildrenFlag() == DW_CHILDREN_yes) {
2219 const std::vector<DIE *> &Children = Die->getChildren();
2221 for (unsigned j = 0, M = Children.size(); j < M; ++j) {
2222 EmitDIE(Children[j]);
2225 Asm->EmitInt8(0); Asm->EOL("End Of Children Mark");
2229 /// SizeAndOffsetDie - Compute the size and offset of a DIE.
2231 unsigned SizeAndOffsetDie(DIE *Die, unsigned Offset, bool Last) {
2232 // Get the children.
2233 const std::vector<DIE *> &Children = Die->getChildren();
2235 // If not last sibling and has children then add sibling offset attribute.
2236 if (!Last && !Children.empty()) Die->AddSiblingOffset();
2238 // Record the abbreviation.
2239 AssignAbbrevNumber(Die->getAbbrev());
2241 // Get the abbreviation for this DIE.
2242 unsigned AbbrevNumber = Die->getAbbrevNumber();
2243 const DIEAbbrev *Abbrev = Abbreviations[AbbrevNumber - 1];
2246 Die->setOffset(Offset);
2248 // Start the size with the size of abbreviation code.
2249 Offset += TargetAsmInfo::getULEB128Size(AbbrevNumber);
2251 const SmallVector<DIEValue*, 32> &Values = Die->getValues();
2252 const SmallVector<DIEAbbrevData, 8> &AbbrevData = Abbrev->getData();
2254 // Size the DIE attribute values.
2255 for (unsigned i = 0, N = Values.size(); i < N; ++i) {
2256 // Size attribute value.
2257 Offset += Values[i]->SizeOf(*this, AbbrevData[i].getForm());
2260 // Size the DIE children if any.
2261 if (!Children.empty()) {
2262 assert(Abbrev->getChildrenFlag() == DW_CHILDREN_yes &&
2263 "Children flag not set");
2265 for (unsigned j = 0, M = Children.size(); j < M; ++j) {
2266 Offset = SizeAndOffsetDie(Children[j], Offset, (j + 1) == M);
2269 // End of children marker.
2270 Offset += sizeof(int8_t);
2273 Die->setSize(Offset - Die->getOffset());
2277 /// SizeAndOffsets - Compute the size and offset of all the DIEs.
2279 void SizeAndOffsets() {
2280 // Process base compile unit.
2281 for (DenseMap<Value *, CompileUnit *>::iterator CI = DW_CUs.begin(),
2282 CE = DW_CUs.end(); CI != CE; ++CI) {
2283 CompileUnit *Unit = CI->second;
2284 // Compute size of compile unit header
2285 unsigned Offset = sizeof(int32_t) + // Length of Compilation Unit Info
2286 sizeof(int16_t) + // DWARF version number
2287 sizeof(int32_t) + // Offset Into Abbrev. Section
2288 sizeof(int8_t); // Pointer Size (in bytes)
2289 SizeAndOffsetDie(Unit->getDie(), Offset, true);
2293 /// EmitDebugInfo - Emit the debug info section.
2295 void EmitDebugInfo() {
2296 // Start debug info section.
2297 Asm->SwitchToDataSection(TAI->getDwarfInfoSection());
2299 for (DenseMap<Value *, CompileUnit *>::iterator CI = DW_CUs.begin(),
2300 CE = DW_CUs.end(); CI != CE; ++CI) {
2301 CompileUnit *Unit = CI->second;
2302 DIE *Die = Unit->getDie();
2303 // Emit the compile units header.
2304 EmitLabel("info_begin", Unit->getID());
2305 // Emit size of content not including length itself
2306 unsigned ContentSize = Die->getSize() +
2307 sizeof(int16_t) + // DWARF version number
2308 sizeof(int32_t) + // Offset Into Abbrev. Section
2309 sizeof(int8_t) + // Pointer Size (in bytes)
2310 sizeof(int32_t); // FIXME - extra pad for gdb bug.
2312 Asm->EmitInt32(ContentSize); Asm->EOL("Length of Compilation Unit Info");
2313 Asm->EmitInt16(DWARF_VERSION); Asm->EOL("DWARF version number");
2314 EmitSectionOffset("abbrev_begin", "section_abbrev", 0, 0, true, false);
2315 Asm->EOL("Offset Into Abbrev. Section");
2316 Asm->EmitInt8(TD->getPointerSize()); Asm->EOL("Address Size (in bytes)");
2319 // FIXME - extra padding for gdb bug.
2320 Asm->EmitInt8(0); Asm->EOL("Extra Pad For GDB");
2321 Asm->EmitInt8(0); Asm->EOL("Extra Pad For GDB");
2322 Asm->EmitInt8(0); Asm->EOL("Extra Pad For GDB");
2323 Asm->EmitInt8(0); Asm->EOL("Extra Pad For GDB");
2324 EmitLabel("info_end", Unit->getID());
2330 /// EmitAbbreviations - Emit the abbreviation section.
2332 void EmitAbbreviations() const {
2333 // Check to see if it is worth the effort.
2334 if (!Abbreviations.empty()) {
2335 // Start the debug abbrev section.
2336 Asm->SwitchToDataSection(TAI->getDwarfAbbrevSection());
2338 EmitLabel("abbrev_begin", 0);
2340 // For each abbrevation.
2341 for (unsigned i = 0, N = Abbreviations.size(); i < N; ++i) {
2342 // Get abbreviation data
2343 const DIEAbbrev *Abbrev = Abbreviations[i];
2345 // Emit the abbrevations code (base 1 index.)
2346 Asm->EmitULEB128Bytes(Abbrev->getNumber());
2347 Asm->EOL("Abbreviation Code");
2349 // Emit the abbreviations data.
2350 Abbrev->Emit(*this);
2355 // Mark end of abbreviations.
2356 Asm->EmitULEB128Bytes(0); Asm->EOL("EOM(3)");
2358 EmitLabel("abbrev_end", 0);
2364 /// EmitEndOfLineMatrix - Emit the last address of the section and the end of
2365 /// the line matrix.
2367 void EmitEndOfLineMatrix(unsigned SectionEnd) {
2368 // Define last address of section.
2369 Asm->EmitInt8(0); Asm->EOL("Extended Op");
2370 Asm->EmitInt8(TD->getPointerSize() + 1); Asm->EOL("Op size");
2371 Asm->EmitInt8(DW_LNE_set_address); Asm->EOL("DW_LNE_set_address");
2372 EmitReference("section_end", SectionEnd); Asm->EOL("Section end label");
2374 // Mark end of matrix.
2375 Asm->EmitInt8(0); Asm->EOL("DW_LNE_end_sequence");
2376 Asm->EmitULEB128Bytes(1); Asm->EOL();
2377 Asm->EmitInt8(1); Asm->EOL();
2380 /// EmitDebugLines - Emit source line information.
2382 void EmitDebugLines() {
2383 // If the target is using .loc/.file, the assembler will be emitting the
2384 // .debug_line table automatically.
2385 if (TAI->hasDotLocAndDotFile())
2388 // Minimum line delta, thus ranging from -10..(255-10).
2389 const int MinLineDelta = -(DW_LNS_fixed_advance_pc + 1);
2390 // Maximum line delta, thus ranging from -10..(255-10).
2391 const int MaxLineDelta = 255 + MinLineDelta;
2393 // Start the dwarf line section.
2394 Asm->SwitchToDataSection(TAI->getDwarfLineSection());
2396 // Construct the section header.
2398 EmitDifference("line_end", 0, "line_begin", 0, true);
2399 Asm->EOL("Length of Source Line Info");
2400 EmitLabel("line_begin", 0);
2402 Asm->EmitInt16(DWARF_VERSION); Asm->EOL("DWARF version number");
2404 EmitDifference("line_prolog_end", 0, "line_prolog_begin", 0, true);
2405 Asm->EOL("Prolog Length");
2406 EmitLabel("line_prolog_begin", 0);
2408 Asm->EmitInt8(1); Asm->EOL("Minimum Instruction Length");
2410 Asm->EmitInt8(1); Asm->EOL("Default is_stmt_start flag");
2412 Asm->EmitInt8(MinLineDelta); Asm->EOL("Line Base Value (Special Opcodes)");
2414 Asm->EmitInt8(MaxLineDelta); Asm->EOL("Line Range Value (Special Opcodes)");
2416 Asm->EmitInt8(-MinLineDelta); Asm->EOL("Special Opcode Base");
2418 // Line number standard opcode encodings argument count
2419 Asm->EmitInt8(0); Asm->EOL("DW_LNS_copy arg count");
2420 Asm->EmitInt8(1); Asm->EOL("DW_LNS_advance_pc arg count");
2421 Asm->EmitInt8(1); Asm->EOL("DW_LNS_advance_line arg count");
2422 Asm->EmitInt8(1); Asm->EOL("DW_LNS_set_file arg count");
2423 Asm->EmitInt8(1); Asm->EOL("DW_LNS_set_column arg count");
2424 Asm->EmitInt8(0); Asm->EOL("DW_LNS_negate_stmt arg count");
2425 Asm->EmitInt8(0); Asm->EOL("DW_LNS_set_basic_block arg count");
2426 Asm->EmitInt8(0); Asm->EOL("DW_LNS_const_add_pc arg count");
2427 Asm->EmitInt8(1); Asm->EOL("DW_LNS_fixed_advance_pc arg count");
2429 // Emit directories.
2430 for (unsigned DirectoryID = 1, NDID = Directories.size();
2431 DirectoryID <= NDID; ++DirectoryID) {
2432 Asm->EmitString(Directories[DirectoryID]); Asm->EOL("Directory");
2434 Asm->EmitInt8(0); Asm->EOL("End of directories");
2437 for (unsigned SourceID = 1, NSID = SrcFiles.size();
2438 SourceID <= NSID; ++SourceID) {
2439 const SrcFileInfo &SourceFile = SrcFiles[SourceID];
2440 Asm->EmitString(SourceFile.getName());
2442 Asm->EmitULEB128Bytes(SourceFile.getDirectoryID());
2443 Asm->EOL("Directory #");
2444 Asm->EmitULEB128Bytes(0);
2445 Asm->EOL("Mod date");
2446 Asm->EmitULEB128Bytes(0);
2447 Asm->EOL("File size");
2449 Asm->EmitInt8(0); Asm->EOL("End of files");
2451 EmitLabel("line_prolog_end", 0);
2453 // A sequence for each text section.
2454 unsigned SecSrcLinesSize = SectionSourceLines.size();
2456 for (unsigned j = 0; j < SecSrcLinesSize; ++j) {
2457 // Isolate current sections line info.
2458 const std::vector<SrcLineInfo> &LineInfos = SectionSourceLines[j];
2461 const Section* S = SectionMap[j + 1];
2462 Asm->EOL(std::string("Section ") + S->getName());
2466 // Dwarf assumes we start with first line of first source file.
2467 unsigned Source = 1;
2470 // Construct rows of the address, source, line, column matrix.
2471 for (unsigned i = 0, N = LineInfos.size(); i < N; ++i) {
2472 const SrcLineInfo &LineInfo = LineInfos[i];
2473 unsigned LabelID = MMI->MappedLabel(LineInfo.getLabelID());
2474 if (!LabelID) continue;
2476 unsigned SourceID = LineInfo.getSourceID();
2477 const SrcFileInfo &SourceFile = SrcFiles[SourceID];
2478 unsigned DirectoryID = SourceFile.getDirectoryID();
2480 Asm->EOL(Directories[DirectoryID]
2481 + SourceFile.getName()
2483 + utostr_32(LineInfo.getLine()));
2487 // Define the line address.
2488 Asm->EmitInt8(0); Asm->EOL("Extended Op");
2489 Asm->EmitInt8(TD->getPointerSize() + 1); Asm->EOL("Op size");
2490 Asm->EmitInt8(DW_LNE_set_address); Asm->EOL("DW_LNE_set_address");
2491 EmitReference("label", LabelID); Asm->EOL("Location label");
2493 // If change of source, then switch to the new source.
2494 if (Source != LineInfo.getSourceID()) {
2495 Source = LineInfo.getSourceID();
2496 Asm->EmitInt8(DW_LNS_set_file); Asm->EOL("DW_LNS_set_file");
2497 Asm->EmitULEB128Bytes(Source); Asm->EOL("New Source");
2500 // If change of line.
2501 if (Line != LineInfo.getLine()) {
2502 // Determine offset.
2503 int Offset = LineInfo.getLine() - Line;
2504 int Delta = Offset - MinLineDelta;
2507 Line = LineInfo.getLine();
2509 // If delta is small enough and in range...
2510 if (Delta >= 0 && Delta < (MaxLineDelta - 1)) {
2511 // ... then use fast opcode.
2512 Asm->EmitInt8(Delta - MinLineDelta); Asm->EOL("Line Delta");
2514 // ... otherwise use long hand.
2515 Asm->EmitInt8(DW_LNS_advance_line); Asm->EOL("DW_LNS_advance_line");
2516 Asm->EmitSLEB128Bytes(Offset); Asm->EOL("Line Offset");
2517 Asm->EmitInt8(DW_LNS_copy); Asm->EOL("DW_LNS_copy");
2520 // Copy the previous row (different address or source)
2521 Asm->EmitInt8(DW_LNS_copy); Asm->EOL("DW_LNS_copy");
2525 EmitEndOfLineMatrix(j + 1);
2528 if (SecSrcLinesSize == 0)
2529 // Because we're emitting a debug_line section, we still need a line
2530 // table. The linker and friends expect it to exist. If there's nothing to
2531 // put into it, emit an empty table.
2532 EmitEndOfLineMatrix(1);
2534 EmitLabel("line_end", 0);
2539 /// EmitCommonDebugFrame - Emit common frame info into a debug frame section.
2541 void EmitCommonDebugFrame() {
2542 if (!TAI->doesDwarfRequireFrameSection())
2546 Asm->TM.getFrameInfo()->getStackGrowthDirection() ==
2547 TargetFrameInfo::StackGrowsUp ?
2548 TD->getPointerSize() : -TD->getPointerSize();
2550 // Start the dwarf frame section.
2551 Asm->SwitchToDataSection(TAI->getDwarfFrameSection());
2553 EmitLabel("debug_frame_common", 0);
2554 EmitDifference("debug_frame_common_end", 0,
2555 "debug_frame_common_begin", 0, true);
2556 Asm->EOL("Length of Common Information Entry");
2558 EmitLabel("debug_frame_common_begin", 0);
2559 Asm->EmitInt32((int)DW_CIE_ID);
2560 Asm->EOL("CIE Identifier Tag");
2561 Asm->EmitInt8(DW_CIE_VERSION);
2562 Asm->EOL("CIE Version");
2563 Asm->EmitString("");
2564 Asm->EOL("CIE Augmentation");
2565 Asm->EmitULEB128Bytes(1);
2566 Asm->EOL("CIE Code Alignment Factor");
2567 Asm->EmitSLEB128Bytes(stackGrowth);
2568 Asm->EOL("CIE Data Alignment Factor");
2569 Asm->EmitInt8(RI->getDwarfRegNum(RI->getRARegister(), false));
2570 Asm->EOL("CIE RA Column");
2572 std::vector<MachineMove> Moves;
2573 RI->getInitialFrameState(Moves);
2575 EmitFrameMoves(NULL, 0, Moves, false);
2577 Asm->EmitAlignment(2, 0, 0, false);
2578 EmitLabel("debug_frame_common_end", 0);
2583 /// EmitFunctionDebugFrame - Emit per function frame info into a debug frame
2585 void EmitFunctionDebugFrame(const FunctionDebugFrameInfo &DebugFrameInfo) {
2586 if (!TAI->doesDwarfRequireFrameSection())
2589 // Start the dwarf frame section.
2590 Asm->SwitchToDataSection(TAI->getDwarfFrameSection());
2592 EmitDifference("debug_frame_end", DebugFrameInfo.Number,
2593 "debug_frame_begin", DebugFrameInfo.Number, true);
2594 Asm->EOL("Length of Frame Information Entry");
2596 EmitLabel("debug_frame_begin", DebugFrameInfo.Number);
2598 EmitSectionOffset("debug_frame_common", "section_debug_frame",
2600 Asm->EOL("FDE CIE offset");
2602 EmitReference("func_begin", DebugFrameInfo.Number);
2603 Asm->EOL("FDE initial location");
2604 EmitDifference("func_end", DebugFrameInfo.Number,
2605 "func_begin", DebugFrameInfo.Number);
2606 Asm->EOL("FDE address range");
2608 EmitFrameMoves("func_begin", DebugFrameInfo.Number, DebugFrameInfo.Moves,
2611 Asm->EmitAlignment(2, 0, 0, false);
2612 EmitLabel("debug_frame_end", DebugFrameInfo.Number);
2617 /// EmitDebugPubNames - Emit visible names into a debug pubnames section.
2619 void EmitDebugPubNames() {
2620 // Start the dwarf pubnames section.
2621 Asm->SwitchToDataSection(TAI->getDwarfPubNamesSection());
2623 for (DenseMap<Value *, CompileUnit *>::iterator CI = DW_CUs.begin(),
2624 CE = DW_CUs.end(); CI != CE; ++CI) {
2625 CompileUnit *Unit = CI->second;
2627 EmitDifference("pubnames_end", Unit->getID(),
2628 "pubnames_begin", Unit->getID(), true);
2629 Asm->EOL("Length of Public Names Info");
2631 EmitLabel("pubnames_begin", Unit->getID());
2633 Asm->EmitInt16(DWARF_VERSION); Asm->EOL("DWARF Version");
2635 EmitSectionOffset("info_begin", "section_info",
2636 Unit->getID(), 0, true, false);
2637 Asm->EOL("Offset of Compilation Unit Info");
2639 EmitDifference("info_end", Unit->getID(), "info_begin", Unit->getID(),
2641 Asm->EOL("Compilation Unit Length");
2643 std::map<std::string, DIE *> &Globals = Unit->getGlobals();
2645 for (std::map<std::string, DIE *>::iterator GI = Globals.begin(),
2648 const std::string &Name = GI->first;
2649 DIE * Entity = GI->second;
2651 Asm->EmitInt32(Entity->getOffset()); Asm->EOL("DIE offset");
2652 Asm->EmitString(Name); Asm->EOL("External Name");
2655 Asm->EmitInt32(0); Asm->EOL("End Mark");
2656 EmitLabel("pubnames_end", Unit->getID());
2662 /// EmitDebugStr - Emit visible names into a debug str section.
2664 void EmitDebugStr() {
2665 // Check to see if it is worth the effort.
2666 if (!StringPool.empty()) {
2667 // Start the dwarf str section.
2668 Asm->SwitchToDataSection(TAI->getDwarfStrSection());
2670 // For each of strings in the string pool.
2671 for (unsigned StringID = 1, N = StringPool.size();
2672 StringID <= N; ++StringID) {
2673 // Emit a label for reference from debug information entries.
2674 EmitLabel("string", StringID);
2675 // Emit the string itself.
2676 const std::string &String = StringPool[StringID];
2677 Asm->EmitString(String); Asm->EOL();
2684 /// EmitDebugLoc - Emit visible names into a debug loc section.
2686 void EmitDebugLoc() {
2687 // Start the dwarf loc section.
2688 Asm->SwitchToDataSection(TAI->getDwarfLocSection());
2693 /// EmitDebugARanges - Emit visible names into a debug aranges section.
2695 void EmitDebugARanges() {
2696 // Start the dwarf aranges section.
2697 Asm->SwitchToDataSection(TAI->getDwarfARangesSection());
2701 CompileUnit *Unit = GetBaseCompileUnit();
2703 // Don't include size of length
2704 Asm->EmitInt32(0x1c); Asm->EOL("Length of Address Ranges Info");
2706 Asm->EmitInt16(DWARF_VERSION); Asm->EOL("Dwarf Version");
2708 EmitReference("info_begin", Unit->getID());
2709 Asm->EOL("Offset of Compilation Unit Info");
2711 Asm->EmitInt8(TD->getPointerSize()); Asm->EOL("Size of Address");
2713 Asm->EmitInt8(0); Asm->EOL("Size of Segment Descriptor");
2715 Asm->EmitInt16(0); Asm->EOL("Pad (1)");
2716 Asm->EmitInt16(0); Asm->EOL("Pad (2)");
2719 EmitReference("text_begin", 0); Asm->EOL("Address");
2720 EmitDifference("text_end", 0, "text_begin", 0, true); Asm->EOL("Length");
2722 Asm->EmitInt32(0); Asm->EOL("EOM (1)");
2723 Asm->EmitInt32(0); Asm->EOL("EOM (2)");
2729 /// EmitDebugRanges - Emit visible names into a debug ranges section.
2731 void EmitDebugRanges() {
2732 // Start the dwarf ranges section.
2733 Asm->SwitchToDataSection(TAI->getDwarfRangesSection());
2738 /// EmitDebugMacInfo - Emit visible names into a debug macinfo section.
2740 void EmitDebugMacInfo() {
2741 // Start the dwarf macinfo section.
2742 Asm->SwitchToDataSection(TAI->getDwarfMacInfoSection());
2747 /// ConstructCompileUnits - Create a compile unit DIEs.
2748 void ConstructCompileUnits() {
2749 std::string CUName = "llvm.dbg.compile_units";
2750 std::vector<GlobalVariable*> Result;
2751 getGlobalVariablesUsing(*M, CUName, Result);
2752 for (std::vector<GlobalVariable *>::iterator RI = Result.begin(),
2753 RE = Result.end(); RI != RE; ++RI) {
2754 DICompileUnit DIUnit(*RI);
2755 unsigned ID = RecordSource(DIUnit.getDirectory(),
2756 DIUnit.getFilename());
2758 DIE *Die = new DIE(DW_TAG_compile_unit);
2759 AddSectionOffset(Die, DW_AT_stmt_list, DW_FORM_data4,
2760 DWLabel("section_line", 0), DWLabel("section_line", 0),
2762 AddString(Die, DW_AT_producer, DW_FORM_string, DIUnit.getProducer());
2763 AddUInt(Die, DW_AT_language, DW_FORM_data1, DIUnit.getLanguage());
2764 AddString(Die, DW_AT_name, DW_FORM_string, DIUnit.getFilename());
2765 if (!DIUnit.getDirectory().empty())
2766 AddString(Die, DW_AT_comp_dir, DW_FORM_string, DIUnit.getDirectory());
2768 CompileUnit *Unit = new CompileUnit(ID, Die);
2769 DW_CUs[DIUnit.getGV()] = Unit;
2773 /// ConstructGlobalVariableDIEs - Create DIEs for each of the externally
2774 /// visible global variables.
2775 void ConstructGlobalVariableDIEs() {
2776 std::string GVName = "llvm.dbg.global_variables";
2777 std::vector<GlobalVariable*> Result;
2778 getGlobalVariablesUsing(*M, GVName, Result);
2779 for (std::vector<GlobalVariable *>::iterator GVI = Result.begin(),
2780 GVE = Result.end(); GVI != GVE; ++GVI) {
2781 DIGlobalVariable DI_GV(*GVI);
2782 CompileUnit *DW_Unit = FindCompileUnit(DI_GV.getCompileUnit());
2784 // Check for pre-existence.
2785 DIE *&Slot = DW_Unit->getDieMapSlotFor(DI_GV.getGV());
2788 DIE *VariableDie = CreateGlobalVariableDIE(DW_Unit, DI_GV);
2791 DIEBlock *Block = new DIEBlock();
2792 AddUInt(Block, 0, DW_FORM_data1, DW_OP_addr);
2793 AddObjectLabel(Block, 0, DW_FORM_udata,
2794 Asm->getGlobalLinkName(DI_GV.getGV()));
2795 AddBlock(VariableDie, DW_AT_location, 0, Block);
2800 //Add to context owner.
2801 DW_Unit->getDie()->AddChild(VariableDie);
2803 //Expose as global. FIXME - need to check external flag.
2804 DW_Unit->AddGlobal(DI_GV.getName(), VariableDie);
2808 /// ConstructSubprograms - Create DIEs for each of the externally visible
2810 void ConstructSubprograms() {
2812 std::string SPName = "llvm.dbg.subprograms";
2813 std::vector<GlobalVariable*> Result;
2814 getGlobalVariablesUsing(*M, SPName, Result);
2815 for (std::vector<GlobalVariable *>::iterator RI = Result.begin(),
2816 RE = Result.end(); RI != RE; ++RI) {
2818 DISubprogram SP(*RI);
2819 CompileUnit *Unit = FindCompileUnit(SP.getCompileUnit());
2821 // Check for pre-existence.
2822 DIE *&Slot = Unit->getDieMapSlotFor(SP.getGV());
2825 DIE *SubprogramDie = CreateSubprogramDIE(Unit, SP);
2828 Slot = SubprogramDie;
2829 //Add to context owner.
2830 Unit->getDie()->AddChild(SubprogramDie);
2832 Unit->AddGlobal(SP.getName(), SubprogramDie);
2837 //===--------------------------------------------------------------------===//
2838 // Main entry points.
2840 DwarfDebug(raw_ostream &OS, AsmPrinter *A, const TargetAsmInfo *T)
2841 : Dwarf(OS, A, T, "dbg")
2842 , AbbreviationsSet(InitAbbreviationsSetSize)
2844 , ValuesSet(InitValuesSetSize)
2848 , SectionSourceLines()
2851 , RootDbgScope(NULL)
2854 virtual ~DwarfDebug() {
2855 for (unsigned j = 0, M = Values.size(); j < M; ++j)
2859 /// SetDebugInfo - Create global DIEs and emit initial debug info sections.
2860 /// This is inovked by the target AsmPrinter.
2861 void SetDebugInfo(MachineModuleInfo *mmi) {
2863 // Create all the compile unit DIEs.
2864 ConstructCompileUnits();
2871 MMI->setDebugInfoAvailability(true);
2873 // Create DIEs for each of the externally visible global variables.
2874 ConstructGlobalVariableDIEs();
2876 // Create DIEs for each of the externally visible subprograms.
2877 ConstructSubprograms();
2879 // Prime section data.
2880 SectionMap.insert(TAI->getTextSection());
2882 // Print out .file directives to specify files for .loc directives. These
2883 // are printed out early so that they precede any .loc directives.
2884 if (TAI->hasDotLocAndDotFile()) {
2885 for (unsigned i = 1, e = SrcFiles.size(); i <= e; ++i) {
2886 sys::Path FullPath(Directories[SrcFiles[i].getDirectoryID()]);
2887 bool AppendOk = FullPath.appendComponent(SrcFiles[i].getName());
2888 assert(AppendOk && "Could not append filename to directory!");
2890 Asm->EmitFile(i, FullPath.toString());
2895 // Emit initial sections
2899 /// BeginModule - Emit all Dwarf sections that should come prior to the
2901 void BeginModule(Module *M) {
2905 /// EndModule - Emit all Dwarf sections that should come after the content.
2908 if (!ShouldEmitDwarf()) return;
2910 // Standard sections final addresses.
2911 Asm->SwitchToSection(TAI->getTextSection());
2912 EmitLabel("text_end", 0);
2913 Asm->SwitchToSection(TAI->getDataSection());
2914 EmitLabel("data_end", 0);
2916 // End text sections.
2917 for (unsigned i = 1, N = SectionMap.size(); i <= N; ++i) {
2918 Asm->SwitchToSection(SectionMap[i]);
2919 EmitLabel("section_end", i);
2922 // Emit common frame information.
2923 EmitCommonDebugFrame();
2925 // Emit function debug frame information
2926 for (std::vector<FunctionDebugFrameInfo>::iterator I = DebugFrames.begin(),
2927 E = DebugFrames.end(); I != E; ++I)
2928 EmitFunctionDebugFrame(*I);
2930 // Compute DIE offsets and sizes.
2933 // Emit all the DIEs into a debug info section
2936 // Corresponding abbreviations into a abbrev section.
2937 EmitAbbreviations();
2939 // Emit source line correspondence into a debug line section.
2942 // Emit info into a debug pubnames section.
2943 EmitDebugPubNames();
2945 // Emit info into a debug str section.
2948 // Emit info into a debug loc section.
2951 // Emit info into a debug aranges section.
2954 // Emit info into a debug ranges section.
2957 // Emit info into a debug macinfo section.
2961 /// BeginFunction - Gather pre-function debug information. Assumes being
2962 /// emitted immediately after the function entry point.
2963 void BeginFunction(MachineFunction *MF) {
2966 if (!ShouldEmitDwarf()) return;
2968 // Begin accumulating function debug information.
2969 MMI->BeginFunction(MF);
2971 // Assumes in correct section after the entry point.
2972 EmitLabel("func_begin", ++SubprogramCount);
2974 // Emit label for the implicitly defined dbg.stoppoint at the start of
2976 if (!Lines.empty()) {
2977 const SrcLineInfo &LineInfo = Lines[0];
2978 Asm->printLabel(LineInfo.getLabelID());
2982 /// EndFunction - Gather and emit post-function debug information.
2984 void EndFunction(MachineFunction *MF) {
2985 if (!ShouldEmitDwarf()) return;
2987 // Define end label for subprogram.
2988 EmitLabel("func_end", SubprogramCount);
2990 // Get function line info.
2991 if (!Lines.empty()) {
2992 // Get section line info.
2993 unsigned ID = SectionMap.insert(Asm->CurrentSection_);
2994 if (SectionSourceLines.size() < ID) SectionSourceLines.resize(ID);
2995 std::vector<SrcLineInfo> &SectionLineInfos = SectionSourceLines[ID-1];
2996 // Append the function info to section info.
2997 SectionLineInfos.insert(SectionLineInfos.end(),
2998 Lines.begin(), Lines.end());
3001 // Construct scopes for subprogram.
3003 ConstructRootDbgScope(RootDbgScope);
3005 // FIXME: This is wrong. We are essentially getting past a problem with
3006 // debug information not being able to handle unreachable blocks that have
3007 // debug information in them. In particular, those unreachable blocks that
3008 // have "region end" info in them. That situation results in the "root
3009 // scope" not being created. If that's the case, then emit a "default"
3010 // scope, i.e., one that encompasses the whole function. This isn't
3011 // desirable. And a better way of handling this (and all of the debugging
3012 // information) needs to be explored.
3013 ConstructDefaultDbgScope(MF);
3015 DebugFrames.push_back(FunctionDebugFrameInfo(SubprogramCount,
3016 MMI->getFrameMoves()));
3020 delete RootDbgScope;
3021 DbgScopeMap.clear();
3022 RootDbgScope = NULL;
3029 /// ValidDebugInfo - Return true if V represents valid debug info value.
3030 bool ValidDebugInfo(Value *V) {
3035 GlobalVariable *GV = getGlobalVariable(V);
3039 if (GV->getLinkage() != GlobalValue::InternalLinkage
3040 && GV->getLinkage() != GlobalValue::LinkOnceLinkage)
3043 DIDescriptor DI(GV);
3044 // Check current version. Allow Version6 for now.
3045 unsigned Version = DI.getVersion();
3046 if (Version != DIDescriptor::Version7 && Version != DIDescriptor::Version6)
3049 //FIXME - Check individual descriptors.
3053 /// RecordSourceLine - Records location information and associates it with a
3054 /// label. Returns a unique label ID used to generate a label and provide
3055 /// correspondence to the source line list.
3056 unsigned RecordSourceLine(Value *V, unsigned Line, unsigned Col) {
3057 CompileUnit *Unit = DW_CUs[V];
3058 assert (Unit && "Unable to find CompileUnit");
3059 unsigned ID = MMI->NextLabelID();
3060 Lines.push_back(SrcLineInfo(Line, Col, Unit->getID(), ID));
3064 /// RecordSourceLine - Records location information and associates it with a
3065 /// label. Returns a unique label ID used to generate a label and provide
3066 /// correspondence to the source line list.
3067 unsigned RecordSourceLine(unsigned Line, unsigned Col, unsigned Src) {
3068 unsigned ID = MMI->NextLabelID();
3069 Lines.push_back(SrcLineInfo(Line, Col, Src, ID));
3073 unsigned getRecordSourceLineCount() {
3074 return Lines.size();
3077 /// RecordSource - Register a source file with debug info. Returns an source
3079 unsigned RecordSource(const std::string &Directory,
3080 const std::string &File) {
3081 unsigned DID = Directories.insert(Directory);
3082 return SrcFiles.insert(SrcFileInfo(DID,File));
3085 /// RecordRegionStart - Indicate the start of a region.
3087 unsigned RecordRegionStart(GlobalVariable *V) {
3088 DbgScope *Scope = getOrCreateScope(V);
3089 unsigned ID = MMI->NextLabelID();
3090 if (!Scope->getStartLabelID()) Scope->setStartLabelID(ID);
3094 /// RecordRegionEnd - Indicate the end of a region.
3096 unsigned RecordRegionEnd(GlobalVariable *V) {
3097 DbgScope *Scope = getOrCreateScope(V);
3098 unsigned ID = MMI->NextLabelID();
3099 Scope->setEndLabelID(ID);
3103 /// RecordVariable - Indicate the declaration of a local variable.
3105 void RecordVariable(GlobalVariable *GV, unsigned FrameIndex) {
3106 DIDescriptor Desc(GV);
3107 DbgScope *Scope = NULL;
3108 if (Desc.getTag() == DW_TAG_variable) {
3109 // GV is a global variable.
3110 DIGlobalVariable DG(GV);
3111 Scope = getOrCreateScope(DG.getContext().getGV());
3113 // or GV is a local variable.
3115 Scope = getOrCreateScope(DV.getContext().getGV());
3117 assert (Scope && "Unable to find variable' scope");
3118 DbgVariable *DV = new DbgVariable(DIVariable(GV), FrameIndex);
3119 Scope->AddVariable(DV);
3123 //===----------------------------------------------------------------------===//
3124 /// DwarfException - Emits Dwarf exception handling directives.
3126 class DwarfException : public Dwarf {
3129 struct FunctionEHFrameInfo {
3132 unsigned PersonalityIndex;
3134 bool hasLandingPads;
3135 std::vector<MachineMove> Moves;
3136 const Function * function;
3138 FunctionEHFrameInfo(const std::string &FN, unsigned Num, unsigned P,
3140 const std::vector<MachineMove> &M,
3142 FnName(FN), Number(Num), PersonalityIndex(P),
3143 hasCalls(hC), hasLandingPads(hL), Moves(M), function (f) { }
3146 std::vector<FunctionEHFrameInfo> EHFrames;
3148 /// shouldEmitTable - Per-function flag to indicate if EH tables should
3150 bool shouldEmitTable;
3152 /// shouldEmitMoves - Per-function flag to indicate if frame moves info
3153 /// should be emitted.
3154 bool shouldEmitMoves;
3156 /// shouldEmitTableModule - Per-module flag to indicate if EH tables
3157 /// should be emitted.
3158 bool shouldEmitTableModule;
3160 /// shouldEmitFrameModule - Per-module flag to indicate if frame moves
3161 /// should be emitted.
3162 bool shouldEmitMovesModule;
3164 /// EmitCommonEHFrame - Emit the common eh unwind frame.
3166 void EmitCommonEHFrame(const Function *Personality, unsigned Index) {
3167 // Size and sign of stack growth.
3169 Asm->TM.getFrameInfo()->getStackGrowthDirection() ==
3170 TargetFrameInfo::StackGrowsUp ?
3171 TD->getPointerSize() : -TD->getPointerSize();
3173 // Begin eh frame section.
3174 Asm->SwitchToTextSection(TAI->getDwarfEHFrameSection());
3176 if (!TAI->doesRequireNonLocalEHFrameLabel())
3177 O << TAI->getEHGlobalPrefix();
3178 O << "EH_frame" << Index << ":\n";
3179 EmitLabel("section_eh_frame", Index);
3181 // Define base labels.
3182 EmitLabel("eh_frame_common", Index);
3184 // Define the eh frame length.
3185 EmitDifference("eh_frame_common_end", Index,
3186 "eh_frame_common_begin", Index, true);
3187 Asm->EOL("Length of Common Information Entry");
3190 EmitLabel("eh_frame_common_begin", Index);
3191 Asm->EmitInt32((int)0);
3192 Asm->EOL("CIE Identifier Tag");
3193 Asm->EmitInt8(DW_CIE_VERSION);
3194 Asm->EOL("CIE Version");
3196 // The personality presence indicates that language specific information
3197 // will show up in the eh frame.
3198 Asm->EmitString(Personality ? "zPLR" : "zR");
3199 Asm->EOL("CIE Augmentation");
3201 // Round out reader.
3202 Asm->EmitULEB128Bytes(1);
3203 Asm->EOL("CIE Code Alignment Factor");
3204 Asm->EmitSLEB128Bytes(stackGrowth);
3205 Asm->EOL("CIE Data Alignment Factor");
3206 Asm->EmitInt8(RI->getDwarfRegNum(RI->getRARegister(), true));
3207 Asm->EOL("CIE Return Address Column");
3209 // If there is a personality, we need to indicate the functions location.
3211 Asm->EmitULEB128Bytes(7);
3212 Asm->EOL("Augmentation Size");
3214 if (TAI->getNeedsIndirectEncoding()) {
3215 Asm->EmitInt8(DW_EH_PE_pcrel | DW_EH_PE_sdata4 | DW_EH_PE_indirect);
3216 Asm->EOL("Personality (pcrel sdata4 indirect)");
3218 Asm->EmitInt8(DW_EH_PE_pcrel | DW_EH_PE_sdata4);
3219 Asm->EOL("Personality (pcrel sdata4)");
3222 PrintRelDirective(true);
3223 O << TAI->getPersonalityPrefix();
3224 Asm->EmitExternalGlobal((const GlobalVariable *)(Personality));
3225 O << TAI->getPersonalitySuffix();
3226 if (strcmp(TAI->getPersonalitySuffix(), "+4@GOTPCREL"))
3227 O << "-" << TAI->getPCSymbol();
3228 Asm->EOL("Personality");
3230 Asm->EmitInt8(DW_EH_PE_pcrel | DW_EH_PE_sdata4);
3231 Asm->EOL("LSDA Encoding (pcrel sdata4)");
3233 Asm->EmitInt8(DW_EH_PE_pcrel | DW_EH_PE_sdata4);
3234 Asm->EOL("FDE Encoding (pcrel sdata4)");
3236 Asm->EmitULEB128Bytes(1);
3237 Asm->EOL("Augmentation Size");
3239 Asm->EmitInt8(DW_EH_PE_pcrel | DW_EH_PE_sdata4);
3240 Asm->EOL("FDE Encoding (pcrel sdata4)");
3243 // Indicate locations of general callee saved registers in frame.
3244 std::vector<MachineMove> Moves;
3245 RI->getInitialFrameState(Moves);
3246 EmitFrameMoves(NULL, 0, Moves, true);
3248 // On Darwin the linker honors the alignment of eh_frame, which means it
3249 // must be 8-byte on 64-bit targets to match what gcc does. Otherwise
3250 // you get holes which confuse readers of eh_frame.
3251 Asm->EmitAlignment(TD->getPointerSize() == sizeof(int32_t) ? 2 : 3,
3253 EmitLabel("eh_frame_common_end", Index);
3258 /// EmitEHFrame - Emit function exception frame information.
3260 void EmitEHFrame(const FunctionEHFrameInfo &EHFrameInfo) {
3261 Function::LinkageTypes linkage = EHFrameInfo.function->getLinkage();
3263 Asm->SwitchToTextSection(TAI->getDwarfEHFrameSection());
3265 // Externally visible entry into the functions eh frame info.
3266 // If the corresponding function is static, this should not be
3267 // externally visible.
3268 if (linkage != Function::InternalLinkage &&
3269 linkage != Function::PrivateLinkage) {
3270 if (const char *GlobalEHDirective = TAI->getGlobalEHDirective())
3271 O << GlobalEHDirective << EHFrameInfo.FnName << "\n";
3274 // If corresponding function is weak definition, this should be too.
3275 if ((linkage == Function::WeakLinkage ||
3276 linkage == Function::LinkOnceLinkage) &&
3277 TAI->getWeakDefDirective())
3278 O << TAI->getWeakDefDirective() << EHFrameInfo.FnName << "\n";
3280 // If there are no calls then you can't unwind. This may mean we can
3281 // omit the EH Frame, but some environments do not handle weak absolute
3283 // If UnwindTablesMandatory is set we cannot do this optimization; the
3284 // unwind info is to be available for non-EH uses.
3285 if (!EHFrameInfo.hasCalls &&
3286 !UnwindTablesMandatory &&
3287 ((linkage != Function::WeakLinkage &&
3288 linkage != Function::LinkOnceLinkage) ||
3289 !TAI->getWeakDefDirective() ||
3290 TAI->getSupportsWeakOmittedEHFrame()))
3292 O << EHFrameInfo.FnName << " = 0\n";
3293 // This name has no connection to the function, so it might get
3294 // dead-stripped when the function is not, erroneously. Prohibit
3295 // dead-stripping unconditionally.
3296 if (const char *UsedDirective = TAI->getUsedDirective())
3297 O << UsedDirective << EHFrameInfo.FnName << "\n\n";
3299 O << EHFrameInfo.FnName << ":\n";
3302 EmitDifference("eh_frame_end", EHFrameInfo.Number,
3303 "eh_frame_begin", EHFrameInfo.Number, true);
3304 Asm->EOL("Length of Frame Information Entry");
3306 EmitLabel("eh_frame_begin", EHFrameInfo.Number);
3308 if (TAI->doesRequireNonLocalEHFrameLabel()) {
3309 PrintRelDirective(true, true);
3310 PrintLabelName("eh_frame_begin", EHFrameInfo.Number);
3312 if (!TAI->isAbsoluteEHSectionOffsets())
3313 O << "-EH_frame" << EHFrameInfo.PersonalityIndex;
3315 EmitSectionOffset("eh_frame_begin", "eh_frame_common",
3316 EHFrameInfo.Number, EHFrameInfo.PersonalityIndex,
3320 Asm->EOL("FDE CIE offset");
3322 EmitReference("eh_func_begin", EHFrameInfo.Number, true, true);
3323 Asm->EOL("FDE initial location");
3324 EmitDifference("eh_func_end", EHFrameInfo.Number,
3325 "eh_func_begin", EHFrameInfo.Number, true);
3326 Asm->EOL("FDE address range");
3328 // If there is a personality and landing pads then point to the language
3329 // specific data area in the exception table.
3330 if (EHFrameInfo.PersonalityIndex) {
3331 Asm->EmitULEB128Bytes(4);
3332 Asm->EOL("Augmentation size");
3334 if (EHFrameInfo.hasLandingPads)
3335 EmitReference("exception", EHFrameInfo.Number, true, true);
3337 Asm->EmitInt32((int)0);
3338 Asm->EOL("Language Specific Data Area");
3340 Asm->EmitULEB128Bytes(0);
3341 Asm->EOL("Augmentation size");
3344 // Indicate locations of function specific callee saved registers in
3346 EmitFrameMoves("eh_func_begin", EHFrameInfo.Number, EHFrameInfo.Moves,
3349 // On Darwin the linker honors the alignment of eh_frame, which means it
3350 // must be 8-byte on 64-bit targets to match what gcc does. Otherwise
3351 // you get holes which confuse readers of eh_frame.
3352 Asm->EmitAlignment(TD->getPointerSize() == sizeof(int32_t) ? 2 : 3,
3354 EmitLabel("eh_frame_end", EHFrameInfo.Number);
3356 // If the function is marked used, this table should be also. We cannot
3357 // make the mark unconditional in this case, since retaining the table
3358 // also retains the function in this case, and there is code around
3359 // that depends on unused functions (calling undefined externals) being
3360 // dead-stripped to link correctly. Yes, there really is.
3361 if (MMI->getUsedFunctions().count(EHFrameInfo.function))
3362 if (const char *UsedDirective = TAI->getUsedDirective())
3363 O << UsedDirective << EHFrameInfo.FnName << "\n\n";
3367 /// EmitExceptionTable - Emit landing pads and actions.
3369 /// The general organization of the table is complex, but the basic concepts
3370 /// are easy. First there is a header which describes the location and
3371 /// organization of the three components that follow.
3372 /// 1. The landing pad site information describes the range of code covered
3373 /// by the try. In our case it's an accumulation of the ranges covered
3374 /// by the invokes in the try. There is also a reference to the landing
3375 /// pad that handles the exception once processed. Finally an index into
3376 /// the actions table.
3377 /// 2. The action table, in our case, is composed of pairs of type ids
3378 /// and next action offset. Starting with the action index from the
3379 /// landing pad site, each type Id is checked for a match to the current
3380 /// exception. If it matches then the exception and type id are passed
3381 /// on to the landing pad. Otherwise the next action is looked up. This
3382 /// chain is terminated with a next action of zero. If no type id is
3383 /// found the the frame is unwound and handling continues.
3384 /// 3. Type id table contains references to all the C++ typeinfo for all
3385 /// catches in the function. This tables is reversed indexed base 1.
3387 /// SharedTypeIds - How many leading type ids two landing pads have in common.
3388 static unsigned SharedTypeIds(const LandingPadInfo *L,
3389 const LandingPadInfo *R) {
3390 const std::vector<int> &LIds = L->TypeIds, &RIds = R->TypeIds;
3391 unsigned LSize = LIds.size(), RSize = RIds.size();
3392 unsigned MinSize = LSize < RSize ? LSize : RSize;
3395 for (; Count != MinSize; ++Count)
3396 if (LIds[Count] != RIds[Count])
3402 /// PadLT - Order landing pads lexicographically by type id.
3403 static bool PadLT(const LandingPadInfo *L, const LandingPadInfo *R) {
3404 const std::vector<int> &LIds = L->TypeIds, &RIds = R->TypeIds;
3405 unsigned LSize = LIds.size(), RSize = RIds.size();
3406 unsigned MinSize = LSize < RSize ? LSize : RSize;
3408 for (unsigned i = 0; i != MinSize; ++i)
3409 if (LIds[i] != RIds[i])
3410 return LIds[i] < RIds[i];
3412 return LSize < RSize;
3416 static inline unsigned getEmptyKey() { return -1U; }
3417 static inline unsigned getTombstoneKey() { return -2U; }
3418 static unsigned getHashValue(const unsigned &Key) { return Key; }
3419 static bool isEqual(unsigned LHS, unsigned RHS) { return LHS == RHS; }
3420 static bool isPod() { return true; }
3423 /// ActionEntry - Structure describing an entry in the actions table.
3424 struct ActionEntry {
3425 int ValueForTypeID; // The value to write - may not be equal to the type id.
3427 struct ActionEntry *Previous;
3430 /// PadRange - Structure holding a try-range and the associated landing pad.
3432 // The index of the landing pad.
3434 // The index of the begin and end labels in the landing pad's label lists.
3435 unsigned RangeIndex;
3438 typedef DenseMap<unsigned, PadRange, KeyInfo> RangeMapType;
3440 /// CallSiteEntry - Structure describing an entry in the call-site table.
3441 struct CallSiteEntry {
3442 // The 'try-range' is BeginLabel .. EndLabel.
3443 unsigned BeginLabel; // zero indicates the start of the function.
3444 unsigned EndLabel; // zero indicates the end of the function.
3445 // The landing pad starts at PadLabel.
3446 unsigned PadLabel; // zero indicates that there is no landing pad.
3450 void EmitExceptionTable() {
3451 const std::vector<GlobalVariable *> &TypeInfos = MMI->getTypeInfos();
3452 const std::vector<unsigned> &FilterIds = MMI->getFilterIds();
3453 const std::vector<LandingPadInfo> &PadInfos = MMI->getLandingPads();
3454 if (PadInfos.empty()) return;
3456 // Sort the landing pads in order of their type ids. This is used to fold
3457 // duplicate actions.
3458 SmallVector<const LandingPadInfo *, 64> LandingPads;
3459 LandingPads.reserve(PadInfos.size());
3460 for (unsigned i = 0, N = PadInfos.size(); i != N; ++i)
3461 LandingPads.push_back(&PadInfos[i]);
3462 std::sort(LandingPads.begin(), LandingPads.end(), PadLT);
3464 // Negative type ids index into FilterIds, positive type ids index into
3465 // TypeInfos. The value written for a positive type id is just the type
3466 // id itself. For a negative type id, however, the value written is the
3467 // (negative) byte offset of the corresponding FilterIds entry. The byte
3468 // offset is usually equal to the type id, because the FilterIds entries
3469 // are written using a variable width encoding which outputs one byte per
3470 // entry as long as the value written is not too large, but can differ.
3471 // This kind of complication does not occur for positive type ids because
3472 // type infos are output using a fixed width encoding.
3473 // FilterOffsets[i] holds the byte offset corresponding to FilterIds[i].
3474 SmallVector<int, 16> FilterOffsets;
3475 FilterOffsets.reserve(FilterIds.size());
3477 for(std::vector<unsigned>::const_iterator I = FilterIds.begin(),
3478 E = FilterIds.end(); I != E; ++I) {
3479 FilterOffsets.push_back(Offset);
3480 Offset -= TargetAsmInfo::getULEB128Size(*I);
3483 // Compute the actions table and gather the first action index for each
3484 // landing pad site.
3485 SmallVector<ActionEntry, 32> Actions;
3486 SmallVector<unsigned, 64> FirstActions;
3487 FirstActions.reserve(LandingPads.size());
3489 int FirstAction = 0;
3490 unsigned SizeActions = 0;
3491 for (unsigned i = 0, N = LandingPads.size(); i != N; ++i) {
3492 const LandingPadInfo *LP = LandingPads[i];
3493 const std::vector<int> &TypeIds = LP->TypeIds;
3494 const unsigned NumShared = i ? SharedTypeIds(LP, LandingPads[i-1]) : 0;
3495 unsigned SizeSiteActions = 0;
3497 if (NumShared < TypeIds.size()) {
3498 unsigned SizeAction = 0;
3499 ActionEntry *PrevAction = 0;
3502 const unsigned SizePrevIds = LandingPads[i-1]->TypeIds.size();
3503 assert(Actions.size());
3504 PrevAction = &Actions.back();
3505 SizeAction = TargetAsmInfo::getSLEB128Size(PrevAction->NextAction) +
3506 TargetAsmInfo::getSLEB128Size(PrevAction->ValueForTypeID);
3507 for (unsigned j = NumShared; j != SizePrevIds; ++j) {
3509 TargetAsmInfo::getSLEB128Size(PrevAction->ValueForTypeID);
3510 SizeAction += -PrevAction->NextAction;
3511 PrevAction = PrevAction->Previous;
3515 // Compute the actions.
3516 for (unsigned I = NumShared, M = TypeIds.size(); I != M; ++I) {
3517 int TypeID = TypeIds[I];
3518 assert(-1-TypeID < (int)FilterOffsets.size() && "Unknown filter id!");
3519 int ValueForTypeID = TypeID < 0 ? FilterOffsets[-1 - TypeID] : TypeID;
3520 unsigned SizeTypeID = TargetAsmInfo::getSLEB128Size(ValueForTypeID);
3522 int NextAction = SizeAction ? -(SizeAction + SizeTypeID) : 0;
3523 SizeAction = SizeTypeID + TargetAsmInfo::getSLEB128Size(NextAction);
3524 SizeSiteActions += SizeAction;
3526 ActionEntry Action = {ValueForTypeID, NextAction, PrevAction};
3527 Actions.push_back(Action);
3529 PrevAction = &Actions.back();
3532 // Record the first action of the landing pad site.
3533 FirstAction = SizeActions + SizeSiteActions - SizeAction + 1;
3534 } // else identical - re-use previous FirstAction
3536 FirstActions.push_back(FirstAction);
3538 // Compute this sites contribution to size.
3539 SizeActions += SizeSiteActions;
3542 // Compute the call-site table. The entry for an invoke has a try-range
3543 // containing the call, a non-zero landing pad and an appropriate action.
3544 // The entry for an ordinary call has a try-range containing the call and
3545 // zero for the landing pad and the action. Calls marked 'nounwind' have
3546 // no entry and must not be contained in the try-range of any entry - they
3547 // form gaps in the table. Entries must be ordered by try-range address.
3548 SmallVector<CallSiteEntry, 64> CallSites;
3550 RangeMapType PadMap;
3551 // Invokes and nounwind calls have entries in PadMap (due to being bracketed
3552 // by try-range labels when lowered). Ordinary calls do not, so appropriate
3553 // try-ranges for them need be deduced.
3554 for (unsigned i = 0, N = LandingPads.size(); i != N; ++i) {
3555 const LandingPadInfo *LandingPad = LandingPads[i];
3556 for (unsigned j = 0, E = LandingPad->BeginLabels.size(); j != E; ++j) {
3557 unsigned BeginLabel = LandingPad->BeginLabels[j];
3558 assert(!PadMap.count(BeginLabel) && "Duplicate landing pad labels!");
3559 PadRange P = { i, j };
3560 PadMap[BeginLabel] = P;
3564 // The end label of the previous invoke or nounwind try-range.
3565 unsigned LastLabel = 0;
3567 // Whether there is a potentially throwing instruction (currently this means
3568 // an ordinary call) between the end of the previous try-range and now.
3569 bool SawPotentiallyThrowing = false;
3571 // Whether the last callsite entry was for an invoke.
3572 bool PreviousIsInvoke = false;
3574 // Visit all instructions in order of address.
3575 for (MachineFunction::const_iterator I = MF->begin(), E = MF->end();
3577 for (MachineBasicBlock::const_iterator MI = I->begin(), E = I->end();
3579 if (!MI->isLabel()) {
3580 SawPotentiallyThrowing |= MI->getDesc().isCall();
3584 unsigned BeginLabel = MI->getOperand(0).getImm();
3585 assert(BeginLabel && "Invalid label!");
3587 // End of the previous try-range?
3588 if (BeginLabel == LastLabel)
3589 SawPotentiallyThrowing = false;
3591 // Beginning of a new try-range?
3592 RangeMapType::iterator L = PadMap.find(BeginLabel);
3593 if (L == PadMap.end())
3594 // Nope, it was just some random label.
3597 PadRange P = L->second;
3598 const LandingPadInfo *LandingPad = LandingPads[P.PadIndex];
3600 assert(BeginLabel == LandingPad->BeginLabels[P.RangeIndex] &&
3601 "Inconsistent landing pad map!");
3603 // If some instruction between the previous try-range and this one may
3604 // throw, create a call-site entry with no landing pad for the region
3605 // between the try-ranges.
3606 if (SawPotentiallyThrowing) {
3607 CallSiteEntry Site = {LastLabel, BeginLabel, 0, 0};
3608 CallSites.push_back(Site);
3609 PreviousIsInvoke = false;
3612 LastLabel = LandingPad->EndLabels[P.RangeIndex];
3613 assert(BeginLabel && LastLabel && "Invalid landing pad!");
3615 if (LandingPad->LandingPadLabel) {
3616 // This try-range is for an invoke.
3617 CallSiteEntry Site = {BeginLabel, LastLabel,
3618 LandingPad->LandingPadLabel, FirstActions[P.PadIndex]};
3620 // Try to merge with the previous call-site.
3621 if (PreviousIsInvoke) {
3622 CallSiteEntry &Prev = CallSites.back();
3623 if (Site.PadLabel == Prev.PadLabel && Site.Action == Prev.Action) {
3624 // Extend the range of the previous entry.
3625 Prev.EndLabel = Site.EndLabel;
3630 // Otherwise, create a new call-site.
3631 CallSites.push_back(Site);
3632 PreviousIsInvoke = true;
3635 PreviousIsInvoke = false;
3639 // If some instruction between the previous try-range and the end of the
3640 // function may throw, create a call-site entry with no landing pad for the
3641 // region following the try-range.
3642 if (SawPotentiallyThrowing) {
3643 CallSiteEntry Site = {LastLabel, 0, 0, 0};
3644 CallSites.push_back(Site);
3650 const unsigned SiteStartSize = sizeof(int32_t); // DW_EH_PE_udata4
3651 const unsigned SiteLengthSize = sizeof(int32_t); // DW_EH_PE_udata4
3652 const unsigned LandingPadSize = sizeof(int32_t); // DW_EH_PE_udata4
3653 unsigned SizeSites = CallSites.size() * (SiteStartSize +
3656 for (unsigned i = 0, e = CallSites.size(); i < e; ++i)
3657 SizeSites += TargetAsmInfo::getULEB128Size(CallSites[i].Action);
3660 const unsigned TypeInfoSize = TD->getPointerSize(); // DW_EH_PE_absptr
3661 unsigned SizeTypes = TypeInfos.size() * TypeInfoSize;
3663 unsigned TypeOffset = sizeof(int8_t) + // Call site format
3664 TargetAsmInfo::getULEB128Size(SizeSites) + // Call-site table length
3665 SizeSites + SizeActions + SizeTypes;
3667 unsigned TotalSize = sizeof(int8_t) + // LPStart format
3668 sizeof(int8_t) + // TType format
3669 TargetAsmInfo::getULEB128Size(TypeOffset) + // TType base offset
3672 unsigned SizeAlign = (4 - TotalSize) & 3;
3674 // Begin the exception table.
3675 Asm->SwitchToDataSection(TAI->getDwarfExceptionSection());
3676 Asm->EmitAlignment(2, 0, 0, false);
3677 O << "GCC_except_table" << SubprogramCount << ":\n";
3678 for (unsigned i = 0; i != SizeAlign; ++i) {
3680 Asm->EOL("Padding");
3682 EmitLabel("exception", SubprogramCount);
3685 Asm->EmitInt8(DW_EH_PE_omit);
3686 Asm->EOL("LPStart format (DW_EH_PE_omit)");
3687 Asm->EmitInt8(DW_EH_PE_absptr);
3688 Asm->EOL("TType format (DW_EH_PE_absptr)");
3689 Asm->EmitULEB128Bytes(TypeOffset);
3690 Asm->EOL("TType base offset");
3691 Asm->EmitInt8(DW_EH_PE_udata4);
3692 Asm->EOL("Call site format (DW_EH_PE_udata4)");
3693 Asm->EmitULEB128Bytes(SizeSites);
3694 Asm->EOL("Call-site table length");
3696 // Emit the landing pad site information.
3697 for (unsigned i = 0; i < CallSites.size(); ++i) {
3698 CallSiteEntry &S = CallSites[i];
3699 const char *BeginTag;
3700 unsigned BeginNumber;
3702 if (!S.BeginLabel) {
3703 BeginTag = "eh_func_begin";
3704 BeginNumber = SubprogramCount;
3707 BeginNumber = S.BeginLabel;
3710 EmitSectionOffset(BeginTag, "eh_func_begin", BeginNumber, SubprogramCount,
3712 Asm->EOL("Region start");
3715 EmitDifference("eh_func_end", SubprogramCount, BeginTag, BeginNumber,
3718 EmitDifference("label", S.EndLabel, BeginTag, BeginNumber, true);
3720 Asm->EOL("Region length");
3725 EmitSectionOffset("label", "eh_func_begin", S.PadLabel, SubprogramCount,
3727 Asm->EOL("Landing pad");
3729 Asm->EmitULEB128Bytes(S.Action);
3733 // Emit the actions.
3734 for (unsigned I = 0, N = Actions.size(); I != N; ++I) {
3735 ActionEntry &Action = Actions[I];
3737 Asm->EmitSLEB128Bytes(Action.ValueForTypeID);
3738 Asm->EOL("TypeInfo index");
3739 Asm->EmitSLEB128Bytes(Action.NextAction);
3740 Asm->EOL("Next action");
3743 // Emit the type ids.
3744 for (unsigned M = TypeInfos.size(); M; --M) {
3745 GlobalVariable *GV = TypeInfos[M - 1];
3747 PrintRelDirective();
3750 O << Asm->getGlobalLinkName(GV);
3754 Asm->EOL("TypeInfo");
3757 // Emit the filter typeids.
3758 for (unsigned j = 0, M = FilterIds.size(); j < M; ++j) {
3759 unsigned TypeID = FilterIds[j];
3760 Asm->EmitULEB128Bytes(TypeID);
3761 Asm->EOL("Filter TypeInfo index");
3764 Asm->EmitAlignment(2, 0, 0, false);
3768 //===--------------------------------------------------------------------===//
3769 // Main entry points.
3771 DwarfException(raw_ostream &OS, AsmPrinter *A, const TargetAsmInfo *T)
3772 : Dwarf(OS, A, T, "eh")
3773 , shouldEmitTable(false)
3774 , shouldEmitMoves(false)
3775 , shouldEmitTableModule(false)
3776 , shouldEmitMovesModule(false)
3779 virtual ~DwarfException() {}
3781 /// SetModuleInfo - Set machine module information when it's known that pass
3782 /// manager has created it. Set by the target AsmPrinter.
3783 void SetModuleInfo(MachineModuleInfo *mmi) {
3787 /// BeginModule - Emit all exception information that should come prior to the
3789 void BeginModule(Module *M) {
3793 /// EndModule - Emit all exception information that should come after the
3796 if (shouldEmitMovesModule || shouldEmitTableModule) {
3797 const std::vector<Function *> Personalities = MMI->getPersonalities();
3798 for (unsigned i =0; i < Personalities.size(); ++i)
3799 EmitCommonEHFrame(Personalities[i], i);
3801 for (std::vector<FunctionEHFrameInfo>::iterator I = EHFrames.begin(),
3802 E = EHFrames.end(); I != E; ++I)
3807 /// BeginFunction - Gather pre-function exception information. Assumes being
3808 /// emitted immediately after the function entry point.
3809 void BeginFunction(MachineFunction *MF) {
3811 shouldEmitTable = shouldEmitMoves = false;
3812 if (MMI && TAI->doesSupportExceptionHandling()) {
3814 // Map all labels and get rid of any dead landing pads.
3815 MMI->TidyLandingPads();
3816 // If any landing pads survive, we need an EH table.
3817 if (MMI->getLandingPads().size())
3818 shouldEmitTable = true;
3820 // See if we need frame move info.
3821 if (!MF->getFunction()->doesNotThrow() || UnwindTablesMandatory)
3822 shouldEmitMoves = true;
3824 if (shouldEmitMoves || shouldEmitTable)
3825 // Assumes in correct section after the entry point.
3826 EmitLabel("eh_func_begin", ++SubprogramCount);
3828 shouldEmitTableModule |= shouldEmitTable;
3829 shouldEmitMovesModule |= shouldEmitMoves;
3832 /// EndFunction - Gather and emit post-function exception information.
3834 void EndFunction() {
3835 if (shouldEmitMoves || shouldEmitTable) {
3836 EmitLabel("eh_func_end", SubprogramCount);
3837 EmitExceptionTable();
3839 // Save EH frame information
3841 push_back(FunctionEHFrameInfo(getAsm()->getCurrentFunctionEHName(MF),
3843 MMI->getPersonalityIndex(),
3844 MF->getFrameInfo()->hasCalls(),
3845 !MMI->getLandingPads().empty(),
3846 MMI->getFrameMoves(),
3847 MF->getFunction()));
3852 } // End of namespace llvm
3854 //===----------------------------------------------------------------------===//
3856 /// Emit - Print the abbreviation using the specified Dwarf writer.
3858 void DIEAbbrev::Emit(const DwarfDebug &DD) const {
3859 // Emit its Dwarf tag type.
3860 DD.getAsm()->EmitULEB128Bytes(Tag);
3861 DD.getAsm()->EOL(TagString(Tag));
3863 // Emit whether it has children DIEs.
3864 DD.getAsm()->EmitULEB128Bytes(ChildrenFlag);
3865 DD.getAsm()->EOL(ChildrenString(ChildrenFlag));
3867 // For each attribute description.
3868 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
3869 const DIEAbbrevData &AttrData = Data[i];
3871 // Emit attribute type.
3872 DD.getAsm()->EmitULEB128Bytes(AttrData.getAttribute());
3873 DD.getAsm()->EOL(AttributeString(AttrData.getAttribute()));
3876 DD.getAsm()->EmitULEB128Bytes(AttrData.getForm());
3877 DD.getAsm()->EOL(FormEncodingString(AttrData.getForm()));
3880 // Mark end of abbreviation.
3881 DD.getAsm()->EmitULEB128Bytes(0); DD.getAsm()->EOL("EOM(1)");
3882 DD.getAsm()->EmitULEB128Bytes(0); DD.getAsm()->EOL("EOM(2)");
3886 void DIEAbbrev::print(std::ostream &O) {
3887 O << "Abbreviation @"
3888 << std::hex << (intptr_t)this << std::dec
3892 << ChildrenString(ChildrenFlag)
3895 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
3897 << AttributeString(Data[i].getAttribute())
3899 << FormEncodingString(Data[i].getForm())
3903 void DIEAbbrev::dump() { print(cerr); }
3906 //===----------------------------------------------------------------------===//
3909 void DIEValue::dump() {
3914 //===----------------------------------------------------------------------===//
3916 /// EmitValue - Emit integer of appropriate size.
3918 void DIEInteger::EmitValue(DwarfDebug &DD, unsigned Form) {
3920 case DW_FORM_flag: // Fall thru
3921 case DW_FORM_ref1: // Fall thru
3922 case DW_FORM_data1: DD.getAsm()->EmitInt8(Integer); break;
3923 case DW_FORM_ref2: // Fall thru
3924 case DW_FORM_data2: DD.getAsm()->EmitInt16(Integer); break;
3925 case DW_FORM_ref4: // Fall thru
3926 case DW_FORM_data4: DD.getAsm()->EmitInt32(Integer); break;
3927 case DW_FORM_ref8: // Fall thru
3928 case DW_FORM_data8: DD.getAsm()->EmitInt64(Integer); break;
3929 case DW_FORM_udata: DD.getAsm()->EmitULEB128Bytes(Integer); break;
3930 case DW_FORM_sdata: DD.getAsm()->EmitSLEB128Bytes(Integer); break;
3931 default: assert(0 && "DIE Value form not supported yet"); break;
3935 /// SizeOf - Determine size of integer value in bytes.
3937 unsigned DIEInteger::SizeOf(const DwarfDebug &DD, unsigned Form) const {
3939 case DW_FORM_flag: // Fall thru
3940 case DW_FORM_ref1: // Fall thru
3941 case DW_FORM_data1: return sizeof(int8_t);
3942 case DW_FORM_ref2: // Fall thru
3943 case DW_FORM_data2: return sizeof(int16_t);
3944 case DW_FORM_ref4: // Fall thru
3945 case DW_FORM_data4: return sizeof(int32_t);
3946 case DW_FORM_ref8: // Fall thru
3947 case DW_FORM_data8: return sizeof(int64_t);
3948 case DW_FORM_udata: return TargetAsmInfo::getULEB128Size(Integer);
3949 case DW_FORM_sdata: return TargetAsmInfo::getSLEB128Size(Integer);
3950 default: assert(0 && "DIE Value form not supported yet"); break;
3955 //===----------------------------------------------------------------------===//
3957 /// EmitValue - Emit string value.
3959 void DIEString::EmitValue(DwarfDebug &DD, unsigned Form) {
3960 DD.getAsm()->EmitString(String);
3963 //===----------------------------------------------------------------------===//
3965 /// EmitValue - Emit label value.
3967 void DIEDwarfLabel::EmitValue(DwarfDebug &DD, unsigned Form) {
3968 bool IsSmall = Form == DW_FORM_data4;
3969 DD.EmitReference(Label, false, IsSmall);
3972 /// SizeOf - Determine size of label value in bytes.
3974 unsigned DIEDwarfLabel::SizeOf(const DwarfDebug &DD, unsigned Form) const {
3975 if (Form == DW_FORM_data4) return 4;
3976 return DD.getTargetData()->getPointerSize();
3979 //===----------------------------------------------------------------------===//
3981 /// EmitValue - Emit label value.
3983 void DIEObjectLabel::EmitValue(DwarfDebug &DD, unsigned Form) {
3984 bool IsSmall = Form == DW_FORM_data4;
3985 DD.EmitReference(Label, false, IsSmall);
3988 /// SizeOf - Determine size of label value in bytes.
3990 unsigned DIEObjectLabel::SizeOf(const DwarfDebug &DD, unsigned Form) const {
3991 if (Form == DW_FORM_data4) return 4;
3992 return DD.getTargetData()->getPointerSize();
3995 //===----------------------------------------------------------------------===//
3997 /// EmitValue - Emit delta value.
3999 void DIESectionOffset::EmitValue(DwarfDebug &DD, unsigned Form) {
4000 bool IsSmall = Form == DW_FORM_data4;
4001 DD.EmitSectionOffset(Label.Tag, Section.Tag,
4002 Label.Number, Section.Number, IsSmall, IsEH, UseSet);
4005 /// SizeOf - Determine size of delta value in bytes.
4007 unsigned DIESectionOffset::SizeOf(const DwarfDebug &DD, unsigned Form) const {
4008 if (Form == DW_FORM_data4) return 4;
4009 return DD.getTargetData()->getPointerSize();
4012 //===----------------------------------------------------------------------===//
4014 /// EmitValue - Emit delta value.
4016 void DIEDelta::EmitValue(DwarfDebug &DD, unsigned Form) {
4017 bool IsSmall = Form == DW_FORM_data4;
4018 DD.EmitDifference(LabelHi, LabelLo, IsSmall);
4021 /// SizeOf - Determine size of delta value in bytes.
4023 unsigned DIEDelta::SizeOf(const DwarfDebug &DD, unsigned Form) const {
4024 if (Form == DW_FORM_data4) return 4;
4025 return DD.getTargetData()->getPointerSize();
4028 //===----------------------------------------------------------------------===//
4030 /// EmitValue - Emit debug information entry offset.
4032 void DIEntry::EmitValue(DwarfDebug &DD, unsigned Form) {
4033 DD.getAsm()->EmitInt32(Entry->getOffset());
4036 //===----------------------------------------------------------------------===//
4038 /// ComputeSize - calculate the size of the block.
4040 unsigned DIEBlock::ComputeSize(DwarfDebug &DD) {
4042 const SmallVector<DIEAbbrevData, 8> &AbbrevData = Abbrev.getData();
4044 for (unsigned i = 0, N = Values.size(); i < N; ++i) {
4045 Size += Values[i]->SizeOf(DD, AbbrevData[i].getForm());
4051 /// EmitValue - Emit block data.
4053 void DIEBlock::EmitValue(DwarfDebug &DD, unsigned Form) {
4055 case DW_FORM_block1: DD.getAsm()->EmitInt8(Size); break;
4056 case DW_FORM_block2: DD.getAsm()->EmitInt16(Size); break;
4057 case DW_FORM_block4: DD.getAsm()->EmitInt32(Size); break;
4058 case DW_FORM_block: DD.getAsm()->EmitULEB128Bytes(Size); break;
4059 default: assert(0 && "Improper form for block"); break;
4062 const SmallVector<DIEAbbrevData, 8> &AbbrevData = Abbrev.getData();
4064 for (unsigned i = 0, N = Values.size(); i < N; ++i) {
4066 Values[i]->EmitValue(DD, AbbrevData[i].getForm());
4070 /// SizeOf - Determine size of block data in bytes.
4072 unsigned DIEBlock::SizeOf(const DwarfDebug &DD, unsigned Form) const {
4074 case DW_FORM_block1: return Size + sizeof(int8_t);
4075 case DW_FORM_block2: return Size + sizeof(int16_t);
4076 case DW_FORM_block4: return Size + sizeof(int32_t);
4077 case DW_FORM_block: return Size + TargetAsmInfo::getULEB128Size(Size);
4078 default: assert(0 && "Improper form for block"); break;
4083 //===----------------------------------------------------------------------===//
4084 /// DIE Implementation
4087 for (unsigned i = 0, N = Children.size(); i < N; ++i)
4091 /// AddSiblingOffset - Add a sibling offset field to the front of the DIE.
4093 void DIE::AddSiblingOffset() {
4094 DIEInteger *DI = new DIEInteger(0);
4095 Values.insert(Values.begin(), DI);
4096 Abbrev.AddFirstAttribute(DW_AT_sibling, DW_FORM_ref4);
4099 /// Profile - Used to gather unique data for the value folding set.
4101 void DIE::Profile(FoldingSetNodeID &ID) {
4104 for (unsigned i = 0, N = Children.size(); i < N; ++i)
4105 ID.AddPointer(Children[i]);
4107 for (unsigned j = 0, M = Values.size(); j < M; ++j)
4108 ID.AddPointer(Values[j]);
4112 void DIE::print(std::ostream &O, unsigned IncIndent) {
4113 static unsigned IndentCount = 0;
4114 IndentCount += IncIndent;
4115 const std::string Indent(IndentCount, ' ');
4116 bool isBlock = Abbrev.getTag() == 0;
4121 << "0x" << std::hex << (intptr_t)this << std::dec
4122 << ", Offset: " << Offset
4123 << ", Size: " << Size
4127 << TagString(Abbrev.getTag())
4129 << ChildrenString(Abbrev.getChildrenFlag());
4131 O << "Size: " << Size;
4135 const SmallVector<DIEAbbrevData, 8> &Data = Abbrev.getData();
4138 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
4142 O << AttributeString(Data[i].getAttribute());
4144 O << "Blk[" << i << "]";
4147 << FormEncodingString(Data[i].getForm())
4149 Values[i]->print(O);
4154 for (unsigned j = 0, M = Children.size(); j < M; ++j) {
4155 Children[j]->print(O, 4);
4158 if (!isBlock) O << "\n";
4159 IndentCount -= IncIndent;
4167 //===----------------------------------------------------------------------===//
4168 /// DwarfWriter Implementation
4171 DwarfWriter::DwarfWriter() : ImmutablePass(&ID), DD(NULL), DE(NULL) {
4174 DwarfWriter::~DwarfWriter() {
4179 /// BeginModule - Emit all Dwarf sections that should come prior to the
4181 void DwarfWriter::BeginModule(Module *M,
4182 MachineModuleInfo *MMI,
4183 raw_ostream &OS, AsmPrinter *A,
4184 const TargetAsmInfo *T) {
4185 DE = new DwarfException(OS, A, T);
4186 DD = new DwarfDebug(OS, A, T);
4189 DD->SetDebugInfo(MMI);
4190 DE->SetModuleInfo(MMI);
4193 /// EndModule - Emit all Dwarf sections that should come after the content.
4195 void DwarfWriter::EndModule() {
4200 /// BeginFunction - Gather pre-function debug information. Assumes being
4201 /// emitted immediately after the function entry point.
4202 void DwarfWriter::BeginFunction(MachineFunction *MF) {
4203 DE->BeginFunction(MF);
4204 DD->BeginFunction(MF);
4207 /// EndFunction - Gather and emit post-function debug information.
4209 void DwarfWriter::EndFunction(MachineFunction *MF) {
4210 DD->EndFunction(MF);
4213 if (MachineModuleInfo *MMI = DD->getMMI() ? DD->getMMI() : DE->getMMI())
4214 // Clear function debug information.
4218 /// ValidDebugInfo - Return true if V represents valid debug info value.
4219 bool DwarfWriter::ValidDebugInfo(Value *V) {
4220 return DD && DD->ValidDebugInfo(V);
4223 /// RecordSourceLine - Records location information and associates it with a
4224 /// label. Returns a unique label ID used to generate a label and provide
4225 /// correspondence to the source line list.
4226 unsigned DwarfWriter::RecordSourceLine(unsigned Line, unsigned Col,
4228 return DD->RecordSourceLine(Line, Col, Src);
4231 /// RecordSource - Register a source file with debug info. Returns an source
4233 unsigned DwarfWriter::RecordSource(const std::string &Dir,
4234 const std::string &File) {
4235 return DD->RecordSource(Dir, File);
4238 /// RecordRegionStart - Indicate the start of a region.
4239 unsigned DwarfWriter::RecordRegionStart(GlobalVariable *V) {
4240 return DD->RecordRegionStart(V);
4243 /// RecordRegionEnd - Indicate the end of a region.
4244 unsigned DwarfWriter::RecordRegionEnd(GlobalVariable *V) {
4245 return DD->RecordRegionEnd(V);
4248 /// getRecordSourceLineCount - Count source lines.
4249 unsigned DwarfWriter::getRecordSourceLineCount() {
4250 return DD->getRecordSourceLineCount();
4253 /// RecordVariable - Indicate the declaration of a local variable.
4255 void DwarfWriter::RecordVariable(GlobalVariable *GV, unsigned FrameIndex) {
4256 DD->RecordVariable(GV, FrameIndex);