diff --git a/include/llvm/CodeGen/DwarfWriter.h b/include/llvm/CodeGen/DwarfWriter.h index 841a029d60b..5fbc8d9ceef 100644 --- a/include/llvm/CodeGen/DwarfWriter.h +++ b/include/llvm/CodeGen/DwarfWriter.h @@ -34,12 +34,14 @@ namespace llvm { // class AsmPrinter; class CompileUnitDesc; + class DebugInfoDesc; class DIE; - class DwarfWriter; - class DWContext; + class DwarfWriter; + class GlobalVariableDesc; class MachineDebugInfo; class MachineFunction; class Module; + class SubprogramDesc; class Type; //===--------------------------------------------------------------------===// @@ -116,6 +118,7 @@ namespace llvm { unsigned getTag() const { return Tag; } unsigned getChildrenFlag() const { return ChildrenFlag; } const std::vector &getData() const { return Data; } + void setChildrenFlag(unsigned CF) { ChildrenFlag = CF; } /// operator== - Used by UniqueVector to locate entry. /// @@ -312,24 +315,21 @@ namespace llvm { unsigned AbbrevID; // Decribing abbreviation ID. unsigned Offset; // Offset in debug info section. unsigned Size; // Size of instance + children. - DWContext *Context; // Context for types and values. std::vector Children; // Children DIEs. std::vector Values; // Attributes values. public: - DIE(unsigned Tag, unsigned ChildrenFlag); + DIE(unsigned Tag); ~DIE(); // Accessors unsigned getAbbrevID() const { return AbbrevID; } unsigned getOffset() const { return Offset; } unsigned getSize() const { return Size; } - DWContext *getContext() const { return Context; } const std::vector &getChildren() const { return Children; } const std::vector &getValues() const { return Values; } void setOffset(unsigned O) { Offset = O; } void setSize(unsigned S) { Size = S; } - void setContext(DWContext *C) { Context = C; } /// SiblingOffset - Return the offset of the debug information entry's /// sibling. @@ -375,40 +375,6 @@ namespace llvm { void AddChild(DIE *Child); }; - //===--------------------------------------------------------------------===// - /// DWContext - Name context for types and values. - /// - class DWContext { - private: - DwarfWriter &DW; // DwarfWriter for global information. - DWContext *Parent; // Next context level searched. - DIE *Owner; // Owning debug information entry. - std::map Types; // Named types in context. - std::map Variables;// Named variables in context. - - public: - DWContext(DwarfWriter &D, DWContext *P, DIE *O) - : DW(D) - , Parent(P) - , Owner(O) - , Types() - , Variables() - { - Owner->setContext(this); - } - ~DWContext() {} - - /// NewBasicType - Creates a new basic type, if necessary, then adds to the - /// context and owner. - DIE *NewBasicType(const Type *Ty, unsigned Size, unsigned Align); - - /// NewVariable - Creates a basic variable, if necessary, then adds to the - /// context and owner. - DIE *NewGlobalVariable(const std::string &Name, - const std::string &MangledName, - DIE *Type); - }; - //===--------------------------------------------------------------------===// // DwarfWriter - Emits Dwarf debug and exception handling directives. // @@ -460,6 +426,15 @@ namespace llvm { /// UniqueVector StringPool; + /// DescToDieMap - Tracks the mapping of debug informaton descriptors to + /// DIES. + std::map DescToDieMap; + + /// TypeToDieMap - Type to DIEType map. + /// + // FIXME - Should not be needed. + std::map TypeToDieMap; + //===------------------------------------------------------------------===// // Properties to be set by the derived class ctor, used to configure the // Dwarf writer. @@ -637,6 +612,11 @@ public: /// DWLabel NewString(const std::string &String); + /// NewBasicType - Creates a new basic type if necessary, then adds to the + /// owner. + /// FIXME - Should never be needed. + DIE *NewBasicType(DIE *Owner, Type *Ty); + /// NewGlobalType - Make the type visible globally using the given name. /// void NewGlobalType(const std::string &Name, DIE *Type); @@ -644,20 +624,20 @@ public: /// NewGlobalEntity - Make the entity visible globally using the given name. /// void NewGlobalEntity(const std::string &Name, DIE *Entity); - - /// NewGlobalVariable - Add a new global variable DIE to the context. - /// - void NewGlobalVariable(DWContext *Context, - const std::string &Name, - const std::string &MangledName, - const Type *Ty, - unsigned Size, unsigned Align); private: + + /// NewGlobalVariable - Make a new global variable DIE. + /// + DIE *NewGlobalVariable(GlobalVariableDesc *GVD); + + /// NewSubprogram - Add a new subprogram DIE. + /// + DIE *NewSubprogram(SubprogramDesc *SPD); /// NewCompileUnit - Create new compile unit information. /// - DIE *NewCompileUnit(const CompileUnitDesc *CompileUnit); + DIE *NewCompileUnit(CompileUnitDesc *CompileUnit); /// EmitInitial - Emit initial Dwarf declarations. /// @@ -669,7 +649,7 @@ private: /// SizeAndOffsetDie - Compute the size and offset of a DIE. /// - unsigned SizeAndOffsetDie(DIE *Die, unsigned Offset) const; + unsigned SizeAndOffsetDie(DIE *Die, unsigned Offset); /// SizeAndOffsets - Compute the size and offset of all the DIEs. /// @@ -723,10 +703,14 @@ private: /// header file. void ConstructCompileUnitDIEs(); - /// ConstructGlobalDIEs - Create DIEs for each of the externally visible global - /// variables. + /// ConstructGlobalDIEs - Create DIEs for each of the externally visible + /// global variables. void ConstructGlobalDIEs(Module &M); + /// ConstructSubprogramDIEs - Create DIEs for each of the externally visible + /// subprograms. + void ConstructSubprogramDIEs(Module &M); + /// ShouldEmitDwarf - Returns true if Dwarf declarations should be made. /// When called it also checks to see if debug info is newly available. if /// so the initial Dwarf headers are emitted. diff --git a/include/llvm/CodeGen/MachineDebugInfo.h b/include/llvm/CodeGen/MachineDebugInfo.h index 2df9eb35ee7..60eebd9d624 100644 --- a/include/llvm/CodeGen/MachineDebugInfo.h +++ b/include/llvm/CodeGen/MachineDebugInfo.h @@ -310,18 +310,21 @@ public: class GlobalVariableDesc : public GlobalDesc { private: GlobalVariable *Global; // llvm global. + unsigned Line; // Source line number. public: GlobalVariableDesc(); // Accessors. GlobalVariable *getGlobalVariable() const { return Global; } + unsigned getLine() const { return Line; } void setGlobalVariable(GlobalVariable *GV) { Global = GV; } - + void setLine(unsigned L) { Line = L; } + // Implement isa/cast/dyncast. static bool classof(const GlobalVariableDesc *) { return true; } static bool classof(const DebugInfoDesc *D) { - return D->getTag() == DI_TAG_global_variable; + return D->getTag() == DI_TAG_global_variable; } /// ApplyToFields - Target the visitor to the fields of the @@ -350,25 +353,12 @@ public: /// subprogram/function. class SubprogramDesc : public GlobalDesc { private: - DebugInfoDesc *Context; // Context debug descriptor. - std::string Name; // Subprogram name. - // FIXME - Use a descriptor. - GlobalVariable *TyDesc; // Type debug descriptor. - bool IsStatic; // Is the subprogram a static. - bool IsDefinition; // Is the subprogram defined in context. + // FIXME - Other attributes public: SubprogramDesc(); // Accessors - DebugInfoDesc *getContext() const { return Context; } - const std::string &getName() const { return Name; } - bool isStatic() const { return IsStatic; } - bool isDefinition() const { return IsDefinition; } - void setContext(DebugInfoDesc *C) { Context = C; } - void setName(const std::string &N) { Name = N; } - void setIsStatic(bool IS) { IsStatic = IS; } - void setIsDefinition(bool ID) { IsDefinition = ID; } // FIXME - Other getters/setters. // Implement isa/cast/dyncast. @@ -604,10 +594,14 @@ public: /// RecordSource - Register a source file with debug info. Returns an source /// ID. unsigned RecordSource(const std::string &Directory, - const std::string &Source) { + const std::string &Source) { unsigned DirectoryID = Directories.insert(Directory); return SourceFiles.insert(SourceFileInfo(DirectoryID, Source)); } + unsigned RecordSource(const CompileUnitDesc *CompileUnit) { + return RecordSource(CompileUnit->getDirectory(), + CompileUnit->getFileName()); + } /// getDirectories - Return the UniqueVector of std::string representing /// directories. @@ -634,10 +628,25 @@ public: /// getCompileUnits - Return a vector of debug compile units. /// const UniqueVector getCompileUnits() const; + + /// getGlobalVariablesUsing - Return all of the GlobalVariables that use the + /// named GlobalVariable. + std::vector + getGlobalVariablesUsing(Module &M, const std::string &RootName); - /// getGlobalVariables - Return a vector of debug GlobalVariables. + /// getAnchoredDescriptors - Return a vector of anchored debug descriptors. /// - std::vector getGlobalVariables(Module &M); + template std::vector getAnchoredDescriptors(Module &M) { + T Desc; + std::vector Globals = + getGlobalVariablesUsing(M, Desc.getAnchorString()); + std::vector AnchoredDescs; + for (unsigned i = 0, N = Globals.size(); i < N; ++i) { + AnchoredDescs.push_back(static_cast(DR.Deserialize(Globals[i]))); + } + + return AnchoredDescs; + } }; // End class MachineDebugInfo diff --git a/lib/CodeGen/DwarfWriter.cpp b/lib/CodeGen/DwarfWriter.cpp index dfa02ec0d44..2a07110c6b0 100644 --- a/lib/CodeGen/DwarfWriter.cpp +++ b/lib/CodeGen/DwarfWriter.cpp @@ -774,12 +774,11 @@ unsigned DIEntry::SizeOf(const DwarfWriter &DW, unsigned Form) const { //===----------------------------------------------------------------------===// -DIE::DIE(unsigned Tag, unsigned ChildrenFlag) -: Abbrev(new DIEAbbrev(Tag, ChildrenFlag)) +DIE::DIE(unsigned Tag) +: Abbrev(new DIEAbbrev(Tag, DW_CHILDREN_no)) , AbbrevID(0) , Offset(0) , Size(0) -, Context(NULL) , Children() , Values() {} @@ -794,8 +793,6 @@ DIE::~DIE() { for (unsigned j = 0, M = Values.size(); j < M; ++j) { delete Values[j]; } - - if (Context) delete Context; } /// AddUInt - Add an unsigned integer attribute data and value. @@ -875,115 +872,14 @@ void DIE::Complete(DwarfWriter &DW) { /// AddChild - Add a child to the DIE. /// void DIE::AddChild(DIE *Child) { + assert(Abbrev && "Adding children without an abbreviation"); + Abbrev->setChildrenFlag(DW_CHILDREN_yes); Children.push_back(Child); } //===----------------------------------------------------------------------===// -/// NewBasicType - Creates a new basic type if necessary, then adds to the -/// context and owner. -DIE *DWContext::NewBasicType(const Type *Ty, unsigned Size, unsigned Align) { - DIE *TypeDie = Types[Ty]; - - // If first occurance of type. - if (!TypeDie) { - const char *Name; - unsigned Encoding = 0; - - switch (Ty->getTypeID()) { - case Type::UByteTyID: - Name = "unsigned char"; - Encoding = DW_ATE_unsigned_char; - break; - case Type::SByteTyID: - Name = "char"; - Encoding = DW_ATE_signed_char; - break; - case Type::UShortTyID: - Name = "unsigned short"; - Encoding = DW_ATE_unsigned; - break; - case Type::ShortTyID: - Name = "short"; - Encoding = DW_ATE_signed; - break; - case Type::UIntTyID: - Name = "unsigned int"; - Encoding = DW_ATE_unsigned; - break; - case Type::IntTyID: - Name = "int"; - Encoding = DW_ATE_signed; - break; - case Type::ULongTyID: - Name = "unsigned long long"; - Encoding = DW_ATE_unsigned; - break; - case Type::LongTyID: - Name = "long long"; - Encoding = DW_ATE_signed; - break; - case Type::FloatTyID: - Name = "float"; - Encoding = DW_ATE_float; - break; - case Type::DoubleTyID: - Name = "float"; - Encoding = DW_ATE_float; - break; - default: - // FIXME - handle more complex types. - Name = "unknown"; - Encoding = DW_ATE_address; - break; - } - - // construct the type DIE. - TypeDie = new DIE(DW_TAG_base_type, DW_CHILDREN_no); - TypeDie->AddString(DW_AT_name, DW_FORM_string, Name); - TypeDie->AddUInt (DW_AT_byte_size, 0, Size); - TypeDie->AddUInt (DW_AT_encoding, DW_FORM_data1, Encoding); - TypeDie->Complete(DW); - - // Add to context owner. - Owner->AddChild(TypeDie); - - // Add to map. - Types[Ty] = TypeDie; - } - - return TypeDie; -} - -/// NewGlobalVariable - Creates a global variable, if necessary, then adds in -/// the context and owner. -DIE *DWContext::NewGlobalVariable(const std::string &Name, - const std::string &MangledName, - DIE *Type) { - DIE *VariableDie = Variables[MangledName]; - - // If first occurance of variable. - if (!VariableDie) { - // FIXME - need source file name line number. - VariableDie = new DIE(DW_TAG_variable, DW_CHILDREN_no); - VariableDie->AddString (DW_AT_name, DW_FORM_string, Name); - VariableDie->AddUInt (DW_AT_decl_file, 0, 0); - VariableDie->AddUInt (DW_AT_decl_line, 0, 0); - VariableDie->AddDIEntry (DW_AT_type, DW_FORM_ref4, Type); - VariableDie->AddUInt (DW_AT_external, DW_FORM_flag, 1); - // FIXME - needs to be a proper expression. - VariableDie->AddObjectLabel(DW_AT_location, DW_FORM_block1, MangledName); - VariableDie->Complete(DW); - - // Add to context owner. - Owner->AddChild(VariableDie); - - // Add to map. - Variables[MangledName] = VariableDie; - } - - return VariableDie; -} +/// DWContext //===----------------------------------------------------------------------===// @@ -1088,14 +984,14 @@ unsigned DwarfWriter::SizeSLEB128(int Value) { /// void DwarfWriter::EmitInt8(int Value) const { O << Asm->Data8bitsDirective; - PrintHex(Value); + PrintHex(Value & 0xFF); } /// EmitInt16 - Emit a short directive and value. /// void DwarfWriter::EmitInt16(int Value) const { O << Asm->Data16bitsDirective; - PrintHex(Value); + PrintHex(Value & 0xFFFF); } /// EmitInt32 - Emit a long directive and value. @@ -1161,8 +1057,8 @@ void DwarfWriter::EmitString(const std::string &String) const { void DwarfWriter::PrintLabelName(const char *Tag, unsigned Number) const { O << Asm->PrivateGlobalPrefix << "debug_" - << Tag - << Number; + << Tag; + if (Number) O << Number; } /// EmitLabel - Emit location label for internal use by Dwarf. @@ -1240,6 +1136,88 @@ DWLabel DwarfWriter::NewString(const std::string &String) { return DWLabel("string", StringID); } +/// NewBasicType - Creates a new basic type if necessary, then adds to the +/// owner. +/// FIXME - Should never be needed. +DIE *DwarfWriter::NewBasicType(DIE *Owner, Type *Ty) { + DIE *&Slot = TypeToDieMap[Ty]; + if (Slot) return Slot; + + const char *Name; + unsigned Size; + unsigned Encoding = 0; + + switch (Ty->getTypeID()) { + case Type::UByteTyID: + Name = "unsigned char"; + Size = 1; + Encoding = DW_ATE_unsigned_char; + break; + case Type::SByteTyID: + Name = "char"; + Size = 1; + Encoding = DW_ATE_signed_char; + break; + case Type::UShortTyID: + Name = "unsigned short"; + Size = 2; + Encoding = DW_ATE_unsigned; + break; + case Type::ShortTyID: + Name = "short"; + Size = 2; + Encoding = DW_ATE_signed; + break; + case Type::UIntTyID: + Name = "unsigned int"; + Size = 4; + Encoding = DW_ATE_unsigned; + break; + case Type::IntTyID: + Name = "int"; + Size = 4; + Encoding = DW_ATE_signed; + break; + case Type::ULongTyID: + Name = "unsigned long long"; + Size = 7; + Encoding = DW_ATE_unsigned; + break; + case Type::LongTyID: + Name = "long long"; + Size = 7; + Encoding = DW_ATE_signed; + break; + case Type::FloatTyID: + Name = "float"; + Size = 4; + Encoding = DW_ATE_float; + break; + case Type::DoubleTyID: + Name = "double"; + Size = 8; + Encoding = DW_ATE_float; + break; + default: + // FIXME - handle more complex types. + Name = "unknown"; + Size = 1; + Encoding = DW_ATE_address; + break; + } + + // construct the type DIE. + Slot = new DIE(DW_TAG_base_type); + Slot->AddString(DW_AT_name, DW_FORM_string, Name); + Slot->AddUInt (DW_AT_byte_size, 0, Size); + Slot->AddUInt (DW_AT_encoding, DW_FORM_data1, Encoding); + + // Add to context owner. + Owner->AddChild(Slot); + + return Slot; +} + /// NewGlobalType - Make the type visible globally using the given name. /// void DwarfWriter::NewGlobalType(const std::string &Name, DIE *Type) { @@ -1254,49 +1232,142 @@ void DwarfWriter::NewGlobalEntity(const std::string &Name, DIE *Entity) { GlobalEntities[Name] = Entity; } -/// NewGlobalVariable - Add a new global variable DIE to the context. -/// -void DwarfWriter::NewGlobalVariable(DWContext *Context, - const std::string &Name, - const std::string &MangledName, - const Type *Ty, - unsigned Size, unsigned Align) { - // Get the DIE type for the global. - DIE *Type = Context->NewBasicType(Ty, Size, Align); - DIE *Variable = Context->NewGlobalVariable(Name, MangledName, Type); - NewGlobalEntity(Name, Variable); -} - /// NewCompileUnit - Create new compile unit information. /// -DIE *DwarfWriter::NewCompileUnit(const CompileUnitDesc *CompileUnit) { - DIE *Unit = new DIE(DW_TAG_compile_unit, DW_CHILDREN_yes); +DIE *DwarfWriter::NewCompileUnit(CompileUnitDesc *CompileUnit) { + // Check for pre-existence. + DIE *&Slot = DescToDieMap[CompileUnit]; + if (Slot) return Slot; + + DIE *Unit = new DIE(DW_TAG_compile_unit); // FIXME - use the correct line set. - Unit->AddLabel (DW_AT_stmt_list, DW_FORM_data4, DWLabel("line", 0)); + Unit->AddLabel (DW_AT_stmt_list, DW_FORM_data4, DWLabel("section_line", 0)); Unit->AddLabel (DW_AT_high_pc, DW_FORM_addr, DWLabel("text_end", 0)); Unit->AddLabel (DW_AT_low_pc, DW_FORM_addr, DWLabel("text_begin", 0)); Unit->AddString(DW_AT_producer, DW_FORM_string, CompileUnit->getProducer()); Unit->AddUInt (DW_AT_language, DW_FORM_data1, CompileUnit->getLanguage()); Unit->AddString(DW_AT_name, DW_FORM_string, CompileUnit->getFileName()); Unit->AddString(DW_AT_comp_dir, DW_FORM_string, CompileUnit->getDirectory()); - Unit->Complete(*this); + + Slot = Unit; return Unit; } +/// NewGlobalVariable - Add a new global variable DIE. +/// +DIE *DwarfWriter::NewGlobalVariable(GlobalVariableDesc *GVD) { + // Check for pre-existence. + DIE *&Slot = DescToDieMap[GVD]; + if (Slot) return Slot; + + // Get the compile unit context. + CompileUnitDesc *CompileUnit = + static_cast(GVD->getContext()); + DIE *Unit = NewCompileUnit(CompileUnit); + // Get the global variable itself. + GlobalVariable *GV = GVD->getGlobalVariable(); + // Generate the mangled name. + std::string MangledName = Asm->Mang->getValueName(GV); + + // Gather the details (simplify add attribute code.) + const std::string &Name = GVD->getName(); + unsigned FileID = DebugInfo->RecordSource(CompileUnit); + unsigned Line = GVD->getLine(); + + // FIXME - faking the type for the time being. + DIE *Type = NewBasicType(Unit, Type::IntTy); + + DIE *VariableDie = new DIE(DW_TAG_variable); + VariableDie->AddString (DW_AT_name, DW_FORM_string, Name); + VariableDie->AddUInt (DW_AT_decl_file, 0, FileID); + VariableDie->AddUInt (DW_AT_decl_line, 0, Line); + VariableDie->AddDIEntry (DW_AT_type, DW_FORM_ref4, Type); + VariableDie->AddUInt (DW_AT_external, DW_FORM_flag, 1); + // FIXME - needs to be a proper expression. + VariableDie->AddObjectLabel(DW_AT_location, DW_FORM_block1, MangledName); + + // Add to map. + Slot = VariableDie; + + // Add to context owner. + Unit->AddChild(VariableDie); + + // Expose as global. + NewGlobalEntity(Name, VariableDie); + + return VariableDie; +} + +/// NewSubprogram - Add a new subprogram DIE. +/// +DIE *DwarfWriter::NewSubprogram(SubprogramDesc *SPD) { + // Check for pre-existence. + DIE *&Slot = DescToDieMap[SPD]; + if (Slot) return Slot; + + // Get the compile unit context. + CompileUnitDesc *CompileUnit = + static_cast(SPD->getContext()); + DIE *Unit = NewCompileUnit(CompileUnit); + + // Gather the details (simplify add attribute code.) + const std::string &Name = SPD->getName(); + unsigned FileID = DebugInfo->RecordSource(CompileUnit); + // FIXME - faking the line for the time being. + unsigned Line = 1; + + // FIXME - faking the type for the time being. + DIE *Type = NewBasicType(Unit, Type::IntTy); + + DIE *SubprogramDie = new DIE(DW_TAG_variable); + SubprogramDie->AddString (DW_AT_name, DW_FORM_string, Name); + SubprogramDie->AddUInt (DW_AT_decl_file, 0, FileID); + SubprogramDie->AddUInt (DW_AT_decl_line, 0, Line); + SubprogramDie->AddDIEntry (DW_AT_type, DW_FORM_ref4, Type); + SubprogramDie->AddUInt (DW_AT_external, DW_FORM_flag, 1); + + // Add to map. + Slot = SubprogramDie; + + // Add to context owner. + Unit->AddChild(SubprogramDie); + + // Expose as global. + NewGlobalEntity(Name, SubprogramDie); + + return SubprogramDie; +} + /// EmitInitial - Emit initial Dwarf declarations. This is necessary for cc /// tools to recognize the object file contains Dwarf information. /// void DwarfWriter::EmitInitial() const { // Dwarf sections base addresses. - Asm->SwitchSection(DwarfAbbrevSection, 0); - EmitLabel("abbrev", 0); + Asm->SwitchSection(DwarfFrameSection, 0); + EmitLabel("section_frame", 0); Asm->SwitchSection(DwarfInfoSection, 0); + EmitLabel("section_info", 0); EmitLabel("info", 0); + Asm->SwitchSection(DwarfAbbrevSection, 0); + EmitLabel("section_abbrev", 0); + EmitLabel("abbrev", 0); + Asm->SwitchSection(DwarfARangesSection, 0); + EmitLabel("section_aranges", 0); + Asm->SwitchSection(DwarfMacInfoSection, 0); + EmitLabel("section_macinfo", 0); Asm->SwitchSection(DwarfLineSection, 0); + EmitLabel("section_line", 0); EmitLabel("line", 0); - - // Standard sections base addresses. + Asm->SwitchSection(DwarfLocSection, 0); + EmitLabel("section_loc", 0); + Asm->SwitchSection(DwarfPubNamesSection, 0); + EmitLabel("section_pubnames", 0); + Asm->SwitchSection(DwarfStrSection, 0); + EmitLabel("section_str", 0); + Asm->SwitchSection(DwarfRangesSection, 0); + EmitLabel("section_ranges", 0); + Asm->SwitchSection(TextSection, 0); EmitLabel("text_begin", 0); Asm->SwitchSection(DataSection, 0); @@ -1358,7 +1429,10 @@ void DwarfWriter::EmitDIE(DIE *Die) const { /// SizeAndOffsetDie - Compute the size and offset of a DIE. /// -unsigned DwarfWriter::SizeAndOffsetDie(DIE *Die, unsigned Offset) const { +unsigned DwarfWriter::SizeAndOffsetDie(DIE *Die, unsigned Offset) { + // Record the abbreviation. + Die->Complete(*this); + // Get the abbreviation for this DIE. unsigned AbbrevID = Die->getAbbrevID(); const DIEAbbrev &Abbrev = Abbreviations[AbbrevID]; @@ -1550,6 +1624,17 @@ void DwarfWriter::EmitDebugLines() const { // Construct rows of the address, source, line, column matrix. for (unsigned i = 0, N = LineInfos.size(); i < N; ++i) { SourceLineInfo *LineInfo = LineInfos[i]; + + if (DwarfVerbose) { + unsigned SourceID = LineInfo->getSourceID(); + const SourceFileInfo &SourceFile = SourceFiles[SourceID]; + unsigned DirectoryID = SourceFile.getDirectoryID(); + O << "\t" + << Asm->CommentString << " " + << Directories[DirectoryID] + << SourceFile.getName() << ":" + << LineInfo->getLine() << "\n"; + } // Define the line address. EmitInt8(0); EOL("Extended Op"); @@ -1589,6 +1674,12 @@ void DwarfWriter::EmitDebugLines() const { } } + // Define last address. + EmitInt8(0); EOL("Extended Op"); + EmitInt8(4 + 1); EOL("Op size"); + EmitInt8(DW_LNE_set_address); EOL("DW_LNE_set_address"); + EmitReference("text_end", 0); EOL("Location label"); + // Mark end of matrix. EmitInt8(0); EOL("DW_LNE_end_sequence"); EmitULEB128Bytes(1); O << "\n"; @@ -1727,7 +1818,6 @@ void DwarfWriter::ConstructCompileUnitDIEs() { for (unsigned i = 1, N = CUW.size(); i <= N; ++i) { DIE *Unit = NewCompileUnit(CUW[i]); - DWContext *Context = new DWContext(*this, NULL, Unit); CompileUnits.push_back(Unit); } } @@ -1735,39 +1825,26 @@ void DwarfWriter::ConstructCompileUnitDIEs() { /// ConstructGlobalDIEs - Create DIEs for each of the externally visible global /// variables. void DwarfWriter::ConstructGlobalDIEs(Module &M) { - const TargetData &TD = Asm->TM.getTargetData(); - std::vector GlobalVariables = - DebugInfo->getGlobalVariables(M); + DebugInfo->getAnchoredDescriptors(M); for (unsigned i = 0, N = GlobalVariables.size(); i < N; ++i) { GlobalVariableDesc *GVD = GlobalVariables[i]; - GlobalVariable *GV = GVD->getGlobalVariable(); - - if (!GV->hasInitializer()) continue; // External global require no code - - // FIXME - Use global info type information when available. - std::string Name = Asm->Mang->getValueName(GV); - Constant *C = GV->getInitializer(); - const Type *Ty = C->getType(); - unsigned Size = TD.getTypeSize(Ty); - unsigned Align = TD.getTypeAlignmentShift(Ty); - - if (C->isNullValue() && /* FIXME: Verify correct */ - (GV->hasInternalLinkage() || GV->hasWeakLinkage() || - GV->hasLinkOnceLinkage())) { - if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it. - } - - /// FIXME - Get correct compile unit context. - assert(CompileUnits.size() && "No compile units"); - DWContext *Context = CompileUnits[0]->getContext(); - - /// Create new global. - NewGlobalVariable(Context, GV->getName(), Name, Ty, Size, Align); + NewGlobalVariable(GVD); } } +/// ConstructSubprogramDIEs - Create DIEs for each of the externally visible +/// subprograms. +void DwarfWriter::ConstructSubprogramDIEs(Module &M) { + std::vector Subprograms = + DebugInfo->getAnchoredDescriptors(M); + + for (unsigned i = 0, N = Subprograms.size(); i < N; ++i) { + SubprogramDesc *SPD = Subprograms[i]; + NewSubprogram(SPD); + } +} /// ShouldEmitDwarf - Determine if Dwarf declarations should be made. /// @@ -1799,6 +1876,8 @@ DwarfWriter::DwarfWriter(std::ostream &OS, AsmPrinter *A) , GlobalTypes() , GlobalEntities() , StringPool() +, DescToDieMap() +, TypeToDieMap() , AddressSize(sizeof(int32_t)) , hasLEB128(false) , hasDotLoc(false) @@ -1849,6 +1928,9 @@ void DwarfWriter::EndModule(Module &M) { // Create DIEs for each of the externally visible global variables. ConstructGlobalDIEs(M); + // Create DIEs for each of the externally visible subprograms. + ConstructSubprogramDIEs(M); + // Compute DIE offsets and sizes. SizeAndOffsets(); diff --git a/lib/CodeGen/MachineDebugInfo.cpp b/lib/CodeGen/MachineDebugInfo.cpp index 2339e45f07e..b801cad3793 100644 --- a/lib/CodeGen/MachineDebugInfo.cpp +++ b/lib/CodeGen/MachineDebugInfo.cpp @@ -579,6 +579,7 @@ void GlobalVariableDesc::ApplyToFields(DIVisitor *Visitor) { GlobalDesc::ApplyToFields(Visitor); Visitor->Apply(Global); + Visitor->Apply(Line); } /// getDescString - Return a string used to compose global names and labels. @@ -607,7 +608,8 @@ void GlobalVariableDesc::dump() { << "Name(\"" << getName() << "\"), " << "IsStatic(" << (isStatic() ? "true" : "false") << "), " << "IsDefinition(" << (isDefinition() ? "true" : "false") << "), " - << "Global(" << Global << ")\n"; + << "Global(" << Global << "), " + << "Line(" << Line << ")\n"; } #endif @@ -910,16 +912,10 @@ void MachineDebugInfo::AnalyzeModule(Module &M) { /// SetupCompileUnits - Set up the unique vector of compile units. /// void MachineDebugInfo::SetupCompileUnits(Module &M) { - // Get vector of all debug compile units. - CompileUnitDesc CompileUnit; - std::vector Globals = - getGlobalVariablesUsing(M, CompileUnit.getAnchorString()); + std::vectorCU = getAnchoredDescriptors(M); - // Scan all compile unit globals. - for (unsigned i = 0, N = Globals.size(); i < N; ++i) { - // Add compile unit to result. - CompileUnits.insert( - static_cast(DR.Deserialize(Globals[i]))); + for (unsigned i = 0, N = CU.size(); i < N; i++) { + CompileUnits.insert(CU[i]); } } @@ -929,26 +925,10 @@ const UniqueVector MachineDebugInfo::getCompileUnits()const{ return CompileUnits; } -/// getGlobalVariables - Return a vector of debug GlobalVariables. -/// -std::vector -MachineDebugInfo::getGlobalVariables(Module &M) { - // Get vector of all debug global objects. - GlobalVariableDesc Global; - std::vector Globals = - getGlobalVariablesUsing(M, Global.getAnchorString()); - - // Accumulation of GlobalVariables. - std::vector GlobalVariables; - - // Scan all globals. - for (unsigned i = 0, N = Globals.size(); i < N; ++i) { - GlobalVariable *GV = Globals[i]; - GlobalVariableDesc *GVD = - static_cast(DR.Deserialize(GV)); - GlobalVariables.push_back(GVD); - } - - return GlobalVariables; +/// getGlobalVariablesUsing - Return all of the GlobalVariables that use the +/// named GlobalVariable. +std::vector +MachineDebugInfo::getGlobalVariablesUsing(Module &M, + const std::string &RootName) { + return ::getGlobalVariablesUsing(M, RootName); } - diff --git a/lib/Target/PowerPC/PPCAsmPrinter.cpp b/lib/Target/PowerPC/PPCAsmPrinter.cpp index 6c37c204f22..bc19f1659d9 100644 --- a/lib/Target/PowerPC/PPCAsmPrinter.cpp +++ b/lib/Target/PowerPC/PPCAsmPrinter.cpp @@ -223,18 +223,17 @@ namespace { : DwarfWriter(o, ap) { needsSet = true; - DwarfAbbrevSection = ".section __DWARF,__debug_abbrev"; - DwarfInfoSection = ".section __DWARF,__debug_info"; - DwarfLineSection = ".section __DWARF,__debug_line"; - DwarfFrameSection = - ".section __DWARF,__debug_frame,,coalesced,no_toc+strip_static_syms"; - DwarfPubNamesSection = ".section __DWARF,__debug_pubnames"; - DwarfPubTypesSection = ".section __DWARF,__debug_pubtypes"; - DwarfStrSection = ".section __DWARF,__debug_str"; - DwarfLocSection = ".section __DWARF,__debug_loc"; - DwarfARangesSection = ".section __DWARF,__debug_aranges"; - DwarfRangesSection = ".section __DWARF,__debug_ranges"; - DwarfMacInfoSection = ".section __DWARF,__debug_macinfo"; + DwarfAbbrevSection = ".section __DWARFA,__debug_abbrev"; + DwarfInfoSection = ".section __DWARFA,__debug_info"; + DwarfLineSection = ".section __DWARFA,__debug_line"; + DwarfFrameSection = ".section __DWARFA,__debug_frame"; + DwarfPubNamesSection = ".section __DWARFA,__debug_pubnames"; + DwarfPubTypesSection = ".section __DWARFA,__debug_pubtypes"; + DwarfStrSection = ".section __DWARFA,__debug_str"; + DwarfLocSection = ".section __DWARFA,__debug_loc"; + DwarfARangesSection = ".section __DWARFA,__debug_aranges"; + DwarfRangesSection = ".section __DWARFA,__debug_ranges"; + DwarfMacInfoSection = ".section __DWARFA,__debug_macinfo"; TextSection = ".text"; DataSection = ".data"; }