diff options
| author | Devang Patel <dpatel@apple.com> | 2009-01-05 22:35:52 +0000 |
|---|---|---|
| committer | Devang Patel <dpatel@apple.com> | 2009-01-05 22:35:52 +0000 |
| commit | ced65244371fd516b7c450954e098576406b3a06 (patch) | |
| tree | afe4059ecc9684d39b4e2a60defe5030dbbde358 /llvm/lib/CodeGen | |
| parent | a1f3441d50678ebd0034f33da710f534dc01cd54 (diff) | |
| download | bcm5719-llvm-ced65244371fd516b7c450954e098576406b3a06.tar.gz bcm5719-llvm-ced65244371fd516b7c450954e098576406b3a06.zip | |
Extract source location info from DebugInfo.
Add methods to add source location info in a DIE.
llvm-svn: 61761
Diffstat (limited to 'llvm/lib/CodeGen')
| -rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/DwarfWriter.cpp | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfWriter.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfWriter.cpp index 56d9ec371ea..d5ae56efeb7 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfWriter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfWriter.cpp @@ -1124,6 +1124,33 @@ public: }; //===----------------------------------------------------------------------===// +/// SrcFileInfo - This class is used to track source information. +/// +class SrcFileInfo { + unsigned DirectoryID; // Directory ID number. + std::string Name; // File name (not including directory.) +public: + SrcFileInfo(unsigned D, const std::string &N) : DirectoryID(D), Name(N) {} + + // Accessors + unsigned getDirectoryID() const { return DirectoryID; } + const std::string &getName() const { return Name; } + + /// operator== - Used by UniqueVector to locate entry. + /// + bool operator==(const SourceFileInfo &SI) const { + return getDirectoryID() == SI.getDirectoryID() && getName() == SI.getName(); + } + + /// operator< - Used by UniqueVector to locate entry. + /// + bool operator<(const SrcFileInfo &SI) const { + return getDirectoryID() < SI.getDirectoryID() || + (getDirectoryID() == SI.getDirectoryID() && getName() < SI.getName()); + } +}; + +//===----------------------------------------------------------------------===// /// DwarfDebug - Emits Dwarf debug directives. /// class DwarfDebug : public Dwarf { @@ -1136,6 +1163,7 @@ private: /// CompileUnits - All the compile units involved in this build. The index /// of each entry in this vector corresponds to the sources in MMI. std::vector<CompileUnit *> CompileUnits; + DenseMap<GlobalVariable *, CompileUnit *> DW_CUs; /// AbbreviationsSet - Used to uniquely define abbreviations. /// @@ -1147,6 +1175,12 @@ private: /// ValuesSet - Used to uniquely define values. /// + // Directories - Uniquing vector for directories. + UniqueVector<std::string> Directories; + + // SourceFiles - Uniquing vector for source files. + UniqueVector<SrcFileInfo> SrcFiles; + FoldingSet<DIEValue> ValuesSet; /// Values - A list of all the unique values in use. @@ -1416,6 +1450,42 @@ private: } } + /// AddSourceLine - Add location information to specified debug information + /// entry. + void AddSourceLine(DIE *Die, DIGlobal *G) { + unsigned FileID = 0; + unsigned Line = G->getLineNumber(); + if (G->getVersion() < DIDescriptor::Version7) { + // Version6 or earlier. Use compile unit info to get file id. + CompileUnit *Unit = FindCompileUnit(G->getCompileUnit()); + FileID = Unit->getID(); + } else { + // Version7 or newer, use filename and directory info from DIGlobal + // directly. + unsigned DID = Directories.idFor(G->getDirectory()); + FileID = SrcFiles.idFor(SrcFileInfo(DID, G->getFilename())); + } + AddUInt(Die, DW_AT_decl_file, 0, FileID); + AddUInt(Die, DW_AT_decl_line, 0, Line); + } + + void AddSourceLine(DIE *Die, DIType *G) { + unsigned FileID = 0; + unsigned Line = G->getLineNumber(); + if (G->getVersion() < DIDescriptor::Version7) { + // Version6 or earlier. Use compile unit info to get file id. + CompileUnit *Unit = FindCompileUnit(G->getCompileUnit()); + FileID = Unit->getID(); + } else { + // Version7 or newer, use filename and directory info from DIGlobal + // directly. + unsigned DID = Directories.idFor(G->getDirectory()); + FileID = SrcFiles.idFor(SrcFileInfo(DID, G->getFilename())); + } + AddUInt(Die, DW_AT_decl_file, 0, FileID); + AddUInt(Die, DW_AT_decl_line, 0, Line); + } + /// AddAddress - Add an address attribute to a die based on the location /// provided. void AddAddress(DIE *Die, unsigned Attribute, @@ -2144,6 +2214,14 @@ private: return Unit; } + /// FindCompileUnit - Get the compile unit for the given descriptor. + /// + CompileUnit *FindCompileUnit(DICompileUnit Unit) { + CompileUnit *DW_Unit = DW_CUs[Unit.getGV()]; + assert(DW_Unit && "Missing compile unit."); + return DW_Unit; + } + /// NewGlobalVariable - Add a new global variable DIE. /// DIE *NewGlobalVariable(GlobalVariableDesc *GVD) { |

