diff options
author | Scott Linder <scott@scottlinder.com> | 2018-02-23 23:01:06 +0000 |
---|---|---|
committer | Scott Linder <scott@scottlinder.com> | 2018-02-23 23:01:06 +0000 |
commit | 16c7bdaf3245d23b9b441144f5efb610e2044927 (patch) | |
tree | 870f3b5c5c606b19951cb4433f3887825bc61e56 /llvm/tools/llvm-objdump/llvm-objdump.cpp | |
parent | 5e2f6ba51e89c9b9625902f0c36493ad46e46a3b (diff) | |
download | bcm5719-llvm-16c7bdaf3245d23b9b441144f5efb610e2044927.tar.gz bcm5719-llvm-16c7bdaf3245d23b9b441144f5efb610e2044927.zip |
[DebugInfo] Support DWARF v5 source code embedding extension
In DWARF v5 the Line Number Program Header is extensible, allowing values with
new content types. In this extension a content type is added,
DW_LNCT_LLVM_source, which contains the embedded source code of the file.
Add new optional attribute for !DIFile IR metadata called source which contains
source text. Use this to output the source to the DWARF line table of code
objects. Analogously extend METADATA_FILE in Bitcode and .file directive in ASM
to support optional source.
Teach llvm-dwarfdump and llvm-objdump about the new values. Update the output
format of llvm-dwarfdump to make room for the new attribute on file_names
entries, and support embedded sources for the -source option in llvm-objdump.
Differential Revision: https://reviews.llvm.org/D42765
llvm-svn: 325970
Diffstat (limited to 'llvm/tools/llvm-objdump/llvm-objdump.cpp')
-rw-r--r-- | llvm/tools/llvm-objdump/llvm-objdump.cpp | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp index 9d44ee49726..3be2c423bb5 100644 --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -408,7 +408,7 @@ protected: std::unordered_map<std::string, std::vector<StringRef>> LineCache; private: - bool cacheSource(const std::string& File); + bool cacheSource(const DILineInfo& LineInfoFile); public: SourcePrinter() = default; @@ -423,23 +423,29 @@ public: StringRef Delimiter = "; "); }; -bool SourcePrinter::cacheSource(const std::string& File) { - auto BufferOrError = MemoryBuffer::getFile(File); - if (!BufferOrError) - return false; +bool SourcePrinter::cacheSource(const DILineInfo &LineInfo) { + std::unique_ptr<MemoryBuffer> Buffer; + if (LineInfo.Source) { + Buffer = MemoryBuffer::getMemBuffer(*LineInfo.Source); + } else { + auto BufferOrError = MemoryBuffer::getFile(LineInfo.FileName); + if (!BufferOrError) + return false; + Buffer = std::move(*BufferOrError); + } // Chomp the file to get lines - size_t BufferSize = (*BufferOrError)->getBufferSize(); - const char *BufferStart = (*BufferOrError)->getBufferStart(); + size_t BufferSize = Buffer->getBufferSize(); + const char *BufferStart = Buffer->getBufferStart(); for (const char *Start = BufferStart, *End = BufferStart; End < BufferStart + BufferSize; End++) if (*End == '\n' || End == BufferStart + BufferSize - 1 || (*End == '\r' && *(End + 1) == '\n')) { - LineCache[File].push_back(StringRef(Start, End - Start)); + LineCache[LineInfo.FileName].push_back(StringRef(Start, End - Start)); if (*End == '\r') End++; Start = End + 1; } - SourceCache[File] = std::move(*BufferOrError); + SourceCache[LineInfo.FileName] = std::move(Buffer); return true; } @@ -463,7 +469,7 @@ void SourcePrinter::printSourceLine(raw_ostream &OS, uint64_t Address, OS << Delimiter << LineInfo.FileName << ":" << LineInfo.Line << "\n"; if (PrintSource) { if (SourceCache.find(LineInfo.FileName) == SourceCache.end()) - if (!cacheSource(LineInfo.FileName)) + if (!cacheSource(LineInfo)) return; auto FileBuffer = SourceCache.find(LineInfo.FileName); if (FileBuffer != SourceCache.end()) { |