Index: llvm/trunk/docs/AMDGPUUsage.rst =================================================================== --- llvm/trunk/docs/AMDGPUUsage.rst +++ llvm/trunk/docs/AMDGPUUsage.rst @@ -780,7 +780,7 @@ DWARF ----- -Standard DWARF [DWARF]_ Version 2 sections can be generated. These contain +Standard DWARF [DWARF]_ Version 5 sections can be generated. These contain information that maps the code object executable code and data to the source language constructs. It can be used by tools such as debuggers and profilers. @@ -836,10 +836,60 @@ Source Text ~~~~~~~~~~~ -*This section is WIP.* +Source text for online-compiled programs (e.g. those compiled by the OpenCL +runtime) may be embedded into the DWARF v5 line table using the ``clang +-gembed-source`` option, described in table :ref:`amdgpu-debug-options`. -.. TODO - DWARF extension to include runtime generated source text. +For example: + +``-gembed-source`` + Enable the embedded source DWARF v5 extension. +``-gno-embed-source`` + Disable the embedded source DWARF v5 extension. + + .. table:: AMDGPU Debug Options + :name: amdgpu-debug-options + + ==================== ================================================== + Debug Flag Description + ==================== ================================================== + -g[no-]embed-source Enable/disable embedding source text in DWARF + debug sections. Useful for environments where + source cannot be written to disk, such as + when performing online compilation. + ==================== ================================================== + +This option enables one extended content types in the DWARF v5 Line Number +Program Header, which is used to encode embedded source. + + .. table:: AMDGPU DWARF Line Number Program Header Extended Content Types + :name: amdgpu-dwarf-extended-content-types + + ============================ ====================== + Content Type Form + ============================ ====================== + ``DW_LNCT_LLVM_source`` ``DW_FORM_line_strp`` + ============================ ====================== + +The source field will contain the UTF-8 encoded, null-terminated source text +with ``'\n'`` line endings. When the source field is present, consumers can use +the embedded source instead of attempting to discover the source on disk. When +the source field is absent, consumers can access the file to get the source +text. + +The above content type appears in the ``file_name_entry_format`` field of the +line table prologue, and its corresponding value appear in the ``file_names`` +field. The current encoding of the content type is documented in table +:ref:`amdgpu-dwarf-extended-content-types-encoding` + + .. table:: AMDGPU DWARF Line Number Program Header Extended Content Types Encoding + :name: amdgpu-dwarf-extended-content-types-encoding + + ============================ ==================== + Content Type Value + ============================ ==================== + ``DW_LNCT_LLVM_source`` 0x2001 + ============================ ==================== .. _amdgpu-code-conventions: Index: llvm/trunk/include/llvm/BinaryFormat/Dwarf.def =================================================================== --- llvm/trunk/include/llvm/BinaryFormat/Dwarf.def +++ llvm/trunk/include/llvm/BinaryFormat/Dwarf.def @@ -747,6 +747,9 @@ HANDLE_DW_LNCT(0x03, timestamp) HANDLE_DW_LNCT(0x04, size) HANDLE_DW_LNCT(0x05, MD5) +// A vendor extension until http://dwarfstd.org/ShowIssue.php?issue=180201.1 is +// accepted and incorporated into the next DWARF standard. +HANDLE_DW_LNCT(0x2001, LLVM_source) // DWARF v5 Macro information. HANDLE_DW_MACRO(0x01, define) Index: llvm/trunk/include/llvm/DebugInfo/DIContext.h =================================================================== --- llvm/trunk/include/llvm/DebugInfo/DIContext.h +++ llvm/trunk/include/llvm/DebugInfo/DIContext.h @@ -31,6 +31,7 @@ struct DILineInfo { std::string FileName; std::string FunctionName; + Optional Source; uint32_t Line = 0; uint32_t Column = 0; uint32_t StartLine = 0; Index: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h =================================================================== --- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h +++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h @@ -10,6 +10,7 @@ #ifndef LLVM_DEBUGINFO_DWARFDEBUGLINE_H #define LLVM_DEBUGINFO_DWARFDEBUGLINE_H +#include "llvm/ADT/Optional.h" #include "llvm/ADT/StringRef.h" #include "llvm/DebugInfo/DIContext.h" #include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h" @@ -36,6 +37,25 @@ uint64_t ModTime = 0; uint64_t Length = 0; MD5::MD5Result Checksum; + DWARFFormValue Source; + }; + + /// Tracks which optional content types are present in a DWARF file name + /// entry format. + struct ContentTypeTracker { + ContentTypeTracker() = default; + + /// Whether filename entries provide a modification timestamp. + bool HasModTime = false; + /// Whether filename entries provide a file size. + bool HasLength = false; + /// For v5, whether filename entries provide an MD5 checksum. + bool HasMD5 = false; + /// For v5, whether filename entries provide source text. + bool HasSource = false; + + /// Update tracked content types with \p ContentType. + void trackContentType(dwarf::LineNumberEntryFormat ContentType); }; struct Prologue { @@ -68,8 +88,8 @@ uint8_t LineRange; /// The number assigned to the first special opcode. uint8_t OpcodeBase; - /// For v5, whether filename entries provide an MD5 checksum. - bool HasMD5; + /// This tracks which optional file format content types are present. + ContentTypeTracker ContentTypes; std::vector StandardOpcodeLengths; std::vector IncludeDirectories; std::vector FileNames; @@ -239,6 +259,8 @@ private: uint32_t findRowInSeq(const DWARFDebugLine::Sequence &Seq, uint64_t Address) const; + Optional getSourceByIndex(uint64_t FileIndex, + DILineInfoSpecifier::FileLineInfoKind Kind) const; }; const LineTable *getLineTable(uint32_t Offset) const; Index: llvm/trunk/include/llvm/IR/DIBuilder.h =================================================================== --- llvm/trunk/include/llvm/IR/DIBuilder.h +++ llvm/trunk/include/llvm/IR/DIBuilder.h @@ -18,7 +18,7 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/MapVector.h" -#include "llvm/ADT/None.h" +#include "llvm/ADT/Optional.h" #include "llvm/ADT/SetVector.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" @@ -141,10 +141,13 @@ /// Create a file descriptor to hold debugging information for a file. /// \param Filename File name. /// \param Directory Directory. - /// \param Checksum Checksum kind (e.g. CSK_MD5, CSK_SHA1, etc.) and value. + /// \param Checksum Optional checksum kind (e.g. CSK_MD5, CSK_SHA1, etc.) + /// and value. + /// \param Source Optional source text. DIFile * createFile(StringRef Filename, StringRef Directory, - Optional> Checksum = None); + Optional> Checksum = None, + Optional Source = None); /// Create debugging information entry for a macro. /// \param Parent Macro parent (could be nullptr). Index: llvm/trunk/include/llvm/IR/DebugInfoMetadata.h =================================================================== --- llvm/trunk/include/llvm/IR/DebugInfoMetadata.h +++ llvm/trunk/include/llvm/IR/DebugInfoMetadata.h @@ -455,6 +455,7 @@ inline StringRef getFilename() const; inline StringRef getDirectory() const; + inline Optional getSource() const; StringRef getName() const; DIScopeRef getScope() const; @@ -532,42 +533,48 @@ private: Optional> Checksum; + Optional Source; DIFile(LLVMContext &C, StorageType Storage, - Optional> CS, + Optional> CS, Optional Src, ArrayRef Ops) : DIScope(C, DIFileKind, Storage, dwarf::DW_TAG_file_type, Ops), - Checksum(CS) {} + Checksum(CS), Source(Src) {} ~DIFile() = default; static DIFile *getImpl(LLVMContext &Context, StringRef Filename, StringRef Directory, Optional> CS, + Optional Source, StorageType Storage, bool ShouldCreate = true) { Optional> MDChecksum; if (CS) MDChecksum.emplace(CS->Kind, getCanonicalMDString(Context, CS->Value)); return getImpl(Context, getCanonicalMDString(Context, Filename), getCanonicalMDString(Context, Directory), MDChecksum, + Source ? Optional(getCanonicalMDString(Context, *Source)) : None, Storage, ShouldCreate); } static DIFile *getImpl(LLVMContext &Context, MDString *Filename, MDString *Directory, Optional> CS, - StorageType Storage, bool ShouldCreate = true); + Optional Source, StorageType Storage, + bool ShouldCreate = true); TempDIFile cloneImpl() const { return getTemporary(getContext(), getFilename(), getDirectory(), - getChecksum()); + getChecksum(), getSource()); } public: DEFINE_MDNODE_GET(DIFile, (StringRef Filename, StringRef Directory, - Optional> CS = None), - (Filename, Directory, CS)) + Optional> CS = None, + Optional Source = None), + (Filename, Directory, CS, Source)) DEFINE_MDNODE_GET(DIFile, (MDString * Filename, MDString *Directory, - Optional> CS = None), - (Filename, Directory, CS)) + Optional> CS = None, + Optional Source = None), + (Filename, Directory, CS, Source)) TempDIFile clone() const { return cloneImpl(); } @@ -579,10 +586,14 @@ StringRefChecksum.emplace(Checksum->Kind, Checksum->Value->getString()); return StringRefChecksum; } + Optional getSource() const { + return Source ? Optional((*Source)->getString()) : None; + } MDString *getRawFilename() const { return getOperandAs(0); } MDString *getRawDirectory() const { return getOperandAs(1); } Optional> getRawChecksum() const { return Checksum; } + Optional getRawSource() const { return Source; } static StringRef getChecksumKindAsString(ChecksumKind CSKind); static Optional getChecksumKind(StringRef CSKindStr); @@ -604,6 +615,12 @@ return ""; } +Optional DIScope::getSource() const { + if (auto *F = getFile()) + return F->getSource(); + return None; +} + /// Base class for types. /// /// TODO: Remove the hardcoded name and context, since many types don't use @@ -1408,6 +1425,7 @@ DIFile *getFile() const { return getScope()->getFile(); } StringRef getFilename() const { return getScope()->getFilename(); } StringRef getDirectory() const { return getScope()->getDirectory(); } + Optional getSource() const { return getScope()->getSource(); } /// Get the scope where this is inlined. /// @@ -2177,6 +2195,12 @@ return ""; } + Optional getSource() const { + if (auto *F = getFile()) + return F->getSource(); + return None; + } + Metadata *getRawScope() const { return getOperand(0); } MDString *getRawName() const { return getOperandAs(1); } Metadata *getRawFile() const { return getOperand(2); } @@ -2624,6 +2648,12 @@ return ""; } + Optional getSource() const { + if (auto *F = getFile()) + return F->getSource(); + return None; + } + MDString *getRawName() const { return getOperandAs(0); } Metadata *getRawFile() const { return getOperand(1); } MDString *getRawGetterName() const { return getOperandAs(2); } Index: llvm/trunk/include/llvm/MC/MCContext.h =================================================================== --- llvm/trunk/include/llvm/MC/MCContext.h +++ llvm/trunk/include/llvm/MC/MCContext.h @@ -11,6 +11,7 @@ #define LLVM_MC_MCCONTEXT_H #include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/Optional.h" #include "llvm/ADT/SetVector.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallVector.h" @@ -496,7 +497,8 @@ /// Creates an entry in the dwarf file and directory tables. Expected getDwarfFile(StringRef Directory, StringRef FileName, unsigned FileNumber, - MD5::MD5Result *Checksum, unsigned CUID); + MD5::MD5Result *Checksum, + Optional Source, unsigned CUID); bool isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID = 0); Index: llvm/trunk/include/llvm/MC/MCDwarf.h =================================================================== --- llvm/trunk/include/llvm/MC/MCDwarf.h +++ llvm/trunk/include/llvm/MC/MCDwarf.h @@ -16,6 +16,7 @@ #define LLVM_MC_MCDWARF_H #include "llvm/ADT/MapVector.h" +#include "llvm/ADT/Optional.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" @@ -48,7 +49,6 @@ /// index 0 is not used and not a valid dwarf file number). struct MCDwarfFile { // \brief The base name of the file without its directory path. - // The StringRef references memory allocated in the MCContext. std::string Name; // \brief The index into the list of directory names for this file name. @@ -57,6 +57,10 @@ /// The MD5 checksum, if there is one. Non-owning pointer to data allocated /// in MCContext. MD5::MD5Result *Checksum = nullptr; + + /// The source code of the file. Non-owning reference to data allocated in + /// MCContext. + Optional Source; }; /// \brief Instances of this class represent the information from a @@ -211,11 +215,13 @@ StringMap SourceIdMap; StringRef CompilationDir; bool HasMD5 = false; + bool HasSource = false; MCDwarfLineTableHeader() = default; Expected tryGetFile(StringRef &Directory, StringRef &FileName, MD5::MD5Result *Checksum, + Optional &Source, unsigned FileNumber = 0); std::pair Emit(MCStreamer *MCOS, MCDwarfLineTableParams Params, @@ -240,8 +246,8 @@ } unsigned getFile(StringRef Directory, StringRef FileName, - MD5::MD5Result *Checksum) { - return cantFail(Header.tryGetFile(Directory, FileName, Checksum)); + MD5::MD5Result *Checksum, Optional Source) { + return cantFail(Header.tryGetFile(Directory, FileName, Checksum, Source)); } void Emit(MCStreamer &MCOS, MCDwarfLineTableParams Params) const; @@ -261,10 +267,13 @@ Expected tryGetFile(StringRef &Directory, StringRef &FileName, MD5::MD5Result *Checksum, + Optional Source, unsigned FileNumber = 0); unsigned getFile(StringRef &Directory, StringRef &FileName, - MD5::MD5Result *Checksum, unsigned FileNumber = 0) { - return cantFail(tryGetFile(Directory, FileName, Checksum, FileNumber)); + MD5::MD5Result *Checksum, Optional &Source, + unsigned FileNumber = 0) { + return cantFail(tryGetFile(Directory, FileName, Checksum, Source, + FileNumber)); } MCSymbol *getLabel() const { Index: llvm/trunk/include/llvm/MC/MCStreamer.h =================================================================== --- llvm/trunk/include/llvm/MC/MCStreamer.h +++ llvm/trunk/include/llvm/MC/MCStreamer.h @@ -16,6 +16,7 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/Optional.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" #include "llvm/MC/MCDirectives.h" @@ -756,17 +757,22 @@ unsigned EmitDwarfFileDirective(unsigned FileNo, StringRef Directory, StringRef Filename, MD5::MD5Result *Checksum = nullptr, + Optional Source = None, unsigned CUID = 0) { return cantFail( - tryEmitDwarfFileDirective(FileNo, Directory, Filename, Checksum, CUID)); + tryEmitDwarfFileDirective(FileNo, Directory, Filename, Checksum, + Source, CUID)); } - /// Associate a filename with a specified logical file number. Returns a - /// StringError for any problem, or the file number. This implements the - /// DWARF2 '.file 4 "foo.c"' assembler directive. + /// Associate a filename with a specified logical file number. + /// Also associate a directory, optional checksum, and optional source + /// text with the logical file. This implements the DWARF2 + /// '.file 4 "dir/foo.c"' assembler directive, and the DWARF5 + /// '.file 4 "dir/foo.c" md5 "..." source "..."' assembler directive. virtual Expected tryEmitDwarfFileDirective( unsigned FileNo, StringRef Directory, StringRef Filename, - MD5::MD5Result *Checksum = nullptr, unsigned CUID = 0); + MD5::MD5Result *Checksum = nullptr, Optional Source = None, + unsigned CUID = 0); /// \brief This implements the DWARF2 '.loc fileno lineno ...' assembler /// directive. Index: llvm/trunk/lib/AsmParser/LLParser.cpp =================================================================== --- llvm/trunk/lib/AsmParser/LLParser.cpp +++ llvm/trunk/lib/AsmParser/LLParser.cpp @@ -4243,9 +4243,10 @@ } /// ParseDIFileType: -/// ::= !DIFileType(filename: "path/to/file", directory: "/path/to/dir" +/// ::= !DIFileType(filename: "path/to/file", directory: "/path/to/dir", /// checksumkind: CSK_MD5, -/// checksum: "000102030405060708090a0b0c0d0e0f") +/// checksum: "000102030405060708090a0b0c0d0e0f", +/// source: "source file contents") bool LLParser::ParseDIFile(MDNode *&Result, bool IsDistinct) { // The default constructed value for checksumkind is required, but will never // be used, as the parser checks if the field was actually Seen before using @@ -4254,7 +4255,8 @@ REQUIRED(filename, MDStringField, ); \ REQUIRED(directory, MDStringField, ); \ OPTIONAL(checksumkind, ChecksumKindField, (DIFile::CSK_MD5)); \ - OPTIONAL(checksum, MDStringField, ); + OPTIONAL(checksum, MDStringField, ); \ + OPTIONAL(source, MDStringField, ); PARSE_MD_FIELDS(); #undef VISIT_MD_FIELDS @@ -4264,8 +4266,11 @@ else if (checksumkind.Seen || checksum.Seen) return Lex.Error("'checksumkind' and 'checksum' must be provided together"); + Optional OptSource; + if (source.Seen) + OptSource = source.Val; Result = GET_OR_DISTINCT(DIFile, (Context, filename.Val, directory.Val, - OptChecksum)); + OptChecksum, OptSource)); return false; } Index: llvm/trunk/lib/Bitcode/Reader/MetadataLoader.cpp =================================================================== --- llvm/trunk/lib/Bitcode/Reader/MetadataLoader.cpp +++ llvm/trunk/lib/Bitcode/Reader/MetadataLoader.cpp @@ -1350,7 +1350,7 @@ } case bitc::METADATA_FILE: { - if (Record.size() != 3 && Record.size() != 5) + if (Record.size() != 3 && Record.size() != 5 && Record.size() != 6) return error("Invalid record"); IsDistinct = Record[0]; @@ -1360,14 +1360,15 @@ // and the old encoding for CSK_None in the ChecksumKind. The new // representation reserves the value 0 in the ChecksumKind to continue to // encode None in a backwards-compatible way. - if (Record.size() == 5 && Record[3] && Record[4]) + if (Record.size() > 4 && Record[3] && Record[4]) Checksum.emplace(static_cast(Record[3]), getMDString(Record[4])); MetadataList.assignValue( GET_OR_DISTINCT( DIFile, - (Context, getMDString(Record[1]), getMDString(Record[2]), - Checksum)), + (Context, getMDString(Record[1]), getMDString(Record[2]), Checksum, + Record.size() > 5 ? Optional(getMDString(Record[5])) + : None)), NextMetadataNo); NextMetadataNo++; break; Index: llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp =================================================================== --- llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp +++ llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -1560,6 +1560,9 @@ Record.push_back(0); Record.push_back(VE.getMetadataOrNullID(nullptr)); } + auto Source = N->getRawSource(); + if (Source) + Record.push_back(VE.getMetadataOrNullID(*Source)); Stream.EmitRecord(bitc::METADATA_FILE, Record, Abbrev); Record.clear(); Index: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp =================================================================== --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp @@ -102,9 +102,10 @@ // extend .file to support this. unsigned CUID = Asm->OutStreamer->hasRawTextSupport() ? 0 : getUniqueID(); if (!File) - return Asm->OutStreamer->EmitDwarfFileDirective(0, "", "", nullptr, CUID); + return Asm->OutStreamer->EmitDwarfFileDirective(0, "", "", nullptr, None, CUID); return Asm->OutStreamer->EmitDwarfFileDirective( - 0, File->getDirectory(), File->getFilename(), getMD5AsBytes(File), CUID); + 0, File->getDirectory(), File->getFilename(), getMD5AsBytes(File), + File->getSource(), CUID); } DIE *DwarfCompileUnit::getOrCreateGlobalVariableDIE( Index: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp =================================================================== --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -1384,7 +1384,7 @@ void DwarfDebug::recordSourceLine(unsigned Line, unsigned Col, const MDNode *S, unsigned Flags) { StringRef Fn; - unsigned Src = 1; + unsigned FileNo = 1; unsigned Discriminator = 0; if (auto *Scope = cast_or_null(S)) { Fn = Scope->getFilename(); @@ -1393,10 +1393,10 @@ Discriminator = LBF->getDiscriminator(); unsigned CUID = Asm->OutStreamer->getContext().getDwarfCompileUnitID(); - Src = static_cast(*InfoHolder.getUnits()[CUID]) + FileNo = static_cast(*InfoHolder.getUnits()[CUID]) .getOrCreateSourceID(Scope->getFile()); } - Asm->OutStreamer->EmitDwarfLocDirective(Src, Line, Col, Flags, 0, + Asm->OutStreamer->EmitDwarfLocDirective(FileNo, Line, Col, Flags, 0, Discriminator, Fn); } Index: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp =================================================================== --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp @@ -302,7 +302,9 @@ unsigned DwarfTypeUnit::getOrCreateSourceID(const DIFile *File) { return SplitLineTable ? SplitLineTable->getFile(File->getDirectory(), - File->getFilename(), getMD5AsBytes(File)) + File->getFilename(), + getMD5AsBytes(File), + File->getSource()) : getCU().getOrCreateSourceID(File); } Index: llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp =================================================================== --- llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp +++ llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp @@ -466,7 +466,9 @@ uint32_t offset = 0; uint32_t strOffset = 0; while (const char *s = strData.getCStr(&offset)) { - OS << format("0x%8.8x: \"%s\"\n", strOffset, s); + OS << format("0x%8.8x: \"", strOffset); + OS.write_escaped(s); + OS << "\"\n"; strOffset = offset; } } Index: llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLine.cpp =================================================================== --- llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLine.cpp +++ llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLine.cpp @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// #include "llvm/DebugInfo/DWARF/DWARFDebugLine.h" +#include "llvm/ADT/Optional.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" @@ -40,6 +41,28 @@ } // end anonmyous namespace +void DWARFDebugLine::ContentTypeTracker::trackContentType( + dwarf::LineNumberEntryFormat ContentType) { + switch (ContentType) { + case dwarf::DW_LNCT_timestamp: + HasModTime = true; + break; + case dwarf::DW_LNCT_size: + HasLength = true; + break; + case dwarf::DW_LNCT_MD5: + HasMD5 = true; + break; + case dwarf::DW_LNCT_LLVM_source: + HasSource = true; + break; + default: + // We only care about values we consider optional, and new values may be + // added in the vendor extension range, so we do not match exhaustively. + break; + } +} + DWARFDebugLine::Prologue::Prologue() { clear(); } void DWARFDebugLine::Prologue::clear() { @@ -48,7 +71,7 @@ MinInstLength = MaxOpsPerInst = DefaultIsStmt = LineBase = LineRange = 0; OpcodeBase = 0; FormParams = DWARFFormParams({0, 0, DWARF32}); - HasMD5 = false; + ContentTypes = ContentTypeTracker(); StandardOpcodeLengths.clear(); IncludeDirectories.clear(); FileNames.clear(); @@ -85,28 +108,26 @@ } if (!FileNames.empty()) { - if (HasMD5) - OS << " Dir MD5 Checksum File Name\n" - << " ---- -------------------------------- -----------" - "---------------\n"; - else - OS << " Dir Mod Time File Len File Name\n" - << " ---- ---------- ---------- -----------" - "----------------\n"; // DWARF v5 starts file indexes at 0. uint32_t FileBase = getVersion() >= 5 ? 0 : 1; for (uint32_t I = 0; I != FileNames.size(); ++I) { const FileNameEntry &FileEntry = FileNames[I]; - OS << format("file_names[%3u] %4" PRIu64 " ", I + FileBase, - FileEntry.DirIdx); - if (HasMD5) - OS << FileEntry.Checksum.digest(); - else - OS << format("0x%8.8" PRIx64 " 0x%8.8" PRIx64, FileEntry.ModTime, - FileEntry.Length); - OS << ' '; + OS << format("file_names[%3u]:\n", I + FileBase); + OS << " name: "; FileEntry.Name.dump(OS, DumpOptions); - OS << '\n'; + OS << '\n' + << format(" dir_index: %" PRIu64 "\n", FileEntry.DirIdx); + if (ContentTypes.HasMD5) + OS << " md5_checksum: " << FileEntry.Checksum.digest() << '\n'; + if (ContentTypes.HasModTime) + OS << format(" mod_time: 0x%8.8" PRIx64 "\n", FileEntry.ModTime); + if (ContentTypes.HasLength) + OS << format(" length: 0x%8.8" PRIx64 "\n", FileEntry.Length); + if (ContentTypes.HasSource) { + OS << " source: "; + FileEntry.Source.dump(OS, DumpOptions); + OS << '\n'; + } } } } @@ -115,6 +136,7 @@ static void parseV2DirFileTables(const DWARFDataExtractor &DebugLineData, uint32_t *OffsetPtr, uint64_t EndPrologueOffset, + DWARFDebugLine::ContentTypeTracker &ContentTypes, std::vector &IncludeDirectories, std::vector &FileNames) { while (*OffsetPtr < EndPrologueOffset) { @@ -138,14 +160,18 @@ FileEntry.Length = DebugLineData.getULEB128(OffsetPtr); FileNames.push_back(FileEntry); } + + ContentTypes.HasModTime = true; + ContentTypes.HasLength = true; } // Parse v5 directory/file entry content descriptions. // Returns the descriptors, or an empty vector if we did not find a path or // ran off the end of the prologue. static ContentDescriptors -parseV5EntryFormat(const DWARFDataExtractor &DebugLineData, uint32_t *OffsetPtr, - uint64_t EndPrologueOffset, bool *HasMD5) { +parseV5EntryFormat(const DWARFDataExtractor &DebugLineData, uint32_t + *OffsetPtr, uint64_t EndPrologueOffset, DWARFDebugLine::ContentTypeTracker + *ContentTypes) { ContentDescriptors Descriptors; int FormatCount = DebugLineData.getU8(OffsetPtr); bool HasPath = false; @@ -158,8 +184,8 @@ Descriptor.Form = dwarf::Form(DebugLineData.getULEB128(OffsetPtr)); if (Descriptor.Type == dwarf::DW_LNCT_path) HasPath = true; - else if (Descriptor.Type == dwarf::DW_LNCT_MD5 && HasMD5) - *HasMD5 = true; + if (ContentTypes) + ContentTypes->trackContentType(Descriptor.Type); Descriptors.push_back(Descriptor); } return HasPath ? Descriptors : ContentDescriptors(); @@ -168,8 +194,9 @@ static bool parseV5DirFileTables(const DWARFDataExtractor &DebugLineData, uint32_t *OffsetPtr, uint64_t EndPrologueOffset, - const DWARFFormParams &FormParams, const DWARFContext &Ctx, - const DWARFUnit *U, bool &HasMD5, + const DWARFFormParams &FormParams, const DWARFContext + &Ctx, const DWARFUnit *U, + DWARFDebugLine::ContentTypeTracker &ContentTypes, std::vector &IncludeDirectories, std::vector &FileNames) { // Get the directory entry description. @@ -200,7 +227,8 @@ // Get the file entry description. ContentDescriptors FileDescriptors = - parseV5EntryFormat(DebugLineData, OffsetPtr, EndPrologueOffset, &HasMD5); + parseV5EntryFormat(DebugLineData, OffsetPtr, EndPrologueOffset, + &ContentTypes); if (FileDescriptors.empty()) return false; @@ -218,6 +246,9 @@ case DW_LNCT_path: FileEntry.Name = Value; break; + case DW_LNCT_LLVM_source: + FileEntry.Source = Value; + break; case DW_LNCT_directory_index: FileEntry.DirIdx = Value.getAsUnsignedConstant().getValue(); break; @@ -285,8 +316,8 @@ if (getVersion() >= 5) { if (!parseV5DirFileTables(DebugLineData, OffsetPtr, EndPrologueOffset, - FormParams, Ctx, U, HasMD5, IncludeDirectories, - FileNames)) { + FormParams, Ctx, U, ContentTypes, + IncludeDirectories, FileNames)) { fprintf(stderr, "warning: parsing line table prologue at 0x%8.8" PRIx64 " found an invalid directory or file table description at" @@ -295,7 +326,7 @@ } } else parseV2DirFileTables(DebugLineData, OffsetPtr, EndPrologueOffset, - IncludeDirectories, FileNames); + ContentTypes, IncludeDirectories, FileNames); if (*OffsetPtr != EndPrologueOffset) { fprintf(stderr, @@ -912,6 +943,16 @@ return FileIndex != 0 && FileIndex <= Prologue.FileNames.size(); } +Optional DWARFDebugLine::LineTable::getSourceByIndex(uint64_t FileIndex, + FileLineInfoKind Kind) const { + if (Kind == FileLineInfoKind::None || !hasFileAtIndex(FileIndex)) + return None; + const FileNameEntry &Entry = Prologue.FileNames[FileIndex - 1]; + if (Optional source = Entry.Source.getAsCString()) + return StringRef(*source); + return None; +} + bool DWARFDebugLine::LineTable::getFileNameByIndex(uint64_t FileIndex, const char *CompDir, FileLineInfoKind Kind, @@ -963,5 +1004,6 @@ Result.Line = Row.Line; Result.Column = Row.Column; Result.Discriminator = Row.Discriminator; + Result.Source = getSourceByIndex(Row.File, Kind); return true; } Index: llvm/trunk/lib/IR/AsmWriter.cpp =================================================================== --- llvm/trunk/lib/IR/AsmWriter.cpp +++ llvm/trunk/lib/IR/AsmWriter.cpp @@ -1723,6 +1723,8 @@ // Print all values for checksum together, or not at all. if (N->getChecksum()) Printer.printChecksum(*N->getChecksum()); + Printer.printString("source", N->getSource().getValueOr(StringRef()), + /* ShouldSkipEmpty */ true); Out << ")"; } Index: llvm/trunk/lib/IR/DIBuilder.cpp =================================================================== --- llvm/trunk/lib/IR/DIBuilder.cpp +++ llvm/trunk/lib/IR/DIBuilder.cpp @@ -14,6 +14,7 @@ #include "llvm/IR/DIBuilder.h" #include "llvm/IR/IRBuilder.h" #include "LLVMContextImpl.h" +#include "llvm/ADT/Optional.h" #include "llvm/ADT/STLExtras.h" #include "llvm/BinaryFormat/Dwarf.h" #include "llvm/IR/Constants.h" @@ -204,8 +205,9 @@ } DIFile *DIBuilder::createFile(StringRef Filename, StringRef Directory, - Optional> CS) { - return DIFile::get(VMContext, Filename, Directory, CS); + Optional> CS, + Optional Source) { + return DIFile::get(VMContext, Filename, Directory, CS, Source); } DIMacro *DIBuilder::createMacro(DIMacroFile *Parent, unsigned LineNumber, Index: llvm/trunk/lib/IR/DebugInfoMetadata.cpp =================================================================== --- llvm/trunk/lib/IR/DebugInfoMetadata.cpp +++ llvm/trunk/lib/IR/DebugInfoMetadata.cpp @@ -417,13 +417,16 @@ DIFile *DIFile::getImpl(LLVMContext &Context, MDString *Filename, MDString *Directory, Optional> CS, - StorageType Storage, bool ShouldCreate) { + Optional Source, StorageType Storage, + bool ShouldCreate) { assert(isCanonical(Filename) && "Expected canonical MDString"); assert(isCanonical(Directory) && "Expected canonical MDString"); assert((!CS || isCanonical(CS->Value)) && "Expected canonical MDString"); - DEFINE_GETIMPL_LOOKUP(DIFile, (Filename, Directory, CS)); - Metadata *Ops[] = {Filename, Directory, CS ? CS->Value : nullptr}; - DEFINE_GETIMPL_STORE(DIFile, (CS), Ops); + assert((!Source || isCanonical(*Source)) && "Expected canonical MDString"); + DEFINE_GETIMPL_LOOKUP(DIFile, (Filename, Directory, CS, Source)); + Metadata *Ops[] = {Filename, Directory, CS ? CS->Value : nullptr, + Source.getValueOr(nullptr)}; + DEFINE_GETIMPL_STORE(DIFile, (CS, Source), Ops); } DICompileUnit *DICompileUnit::getImpl( Index: llvm/trunk/lib/IR/LLVMContextImpl.h =================================================================== --- llvm/trunk/lib/IR/LLVMContextImpl.h +++ llvm/trunk/lib/IR/LLVMContextImpl.h @@ -575,24 +575,28 @@ MDString *Filename; MDString *Directory; Optional> Checksum; + Optional Source; MDNodeKeyImpl(MDString *Filename, MDString *Directory, - Optional> Checksum) - : Filename(Filename), Directory(Directory), Checksum(Checksum) {} + Optional> Checksum, + Optional Source) + : Filename(Filename), Directory(Directory), Checksum(Checksum), + Source(Source) {} MDNodeKeyImpl(const DIFile *N) : Filename(N->getRawFilename()), Directory(N->getRawDirectory()), - Checksum(N->getRawChecksum()) {} + Checksum(N->getRawChecksum()), Source(N->getRawSource()) {} bool isKeyOf(const DIFile *RHS) const { return Filename == RHS->getRawFilename() && Directory == RHS->getRawDirectory() && - Checksum == RHS->getRawChecksum(); + Checksum == RHS->getRawChecksum() && + Source == RHS->getRawSource(); } unsigned getHashValue() const { - if (Checksum) - return hash_combine(Filename, Directory, Checksum->Kind, Checksum->Value); - return hash_combine(Filename, Directory); + return hash_combine( + Filename, Directory, Checksum ? Checksum->Kind : 0, + Checksum ? Checksum->Value : nullptr, Source.getValueOr(nullptr)); } }; Index: llvm/trunk/lib/MC/MCAsmStreamer.cpp =================================================================== --- llvm/trunk/lib/MC/MCAsmStreamer.cpp +++ llvm/trunk/lib/MC/MCAsmStreamer.cpp @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +#include "llvm/ADT/Optional.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringExtras.h" @@ -215,6 +216,7 @@ StringRef Directory, StringRef Filename, MD5::MD5Result *Checksum = 0, + Optional Source = None, unsigned CUID = 0) override; void EmitDwarfLocDirective(unsigned FileNo, unsigned Line, unsigned Column, unsigned Flags, @@ -1076,13 +1078,13 @@ Expected MCAsmStreamer::tryEmitDwarfFileDirective( unsigned FileNo, StringRef Directory, StringRef Filename, - MD5::MD5Result *Checksum, unsigned CUID) { + MD5::MD5Result *Checksum, Optional Source, unsigned CUID) { assert(CUID == 0); MCDwarfLineTable &Table = getContext().getMCDwarfLineTable(CUID); unsigned NumFiles = Table.getMCDwarfFiles().size(); Expected FileNoOrErr = - Table.tryGetFile(Directory, Filename, Checksum, FileNo); + Table.tryGetFile(Directory, Filename, Checksum, Source, FileNo); if (!FileNoOrErr) return FileNoOrErr.takeError(); FileNo = FileNoOrErr.get(); @@ -1114,6 +1116,10 @@ OS1 << " md5 "; PrintQuotedString(Checksum->digest(), OS1); } + if (Source) { + OS1 << " source "; + PrintQuotedString(*Source, OS1); + } if (MCTargetStreamer *TS = getTargetStreamer()) { TS->emitDwarfFileDirective(OS1.str()); } else { Index: llvm/trunk/lib/MC/MCContext.cpp =================================================================== --- llvm/trunk/lib/MC/MCContext.cpp +++ llvm/trunk/lib/MC/MCContext.cpp @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// #include "llvm/MC/MCContext.h" +#include "llvm/ADT/Optional.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringMap.h" @@ -532,7 +533,7 @@ // Dwarf Management //===----------------------------------------------------------------------===// -/// getDwarfFile - takes a file name an number to place in the dwarf file and +/// getDwarfFile - takes a file name and number to place in the dwarf file and /// directory tables. If the file number has already been allocated it is an /// error and zero is returned and the client reports the error, else the /// allocated file number is returned. The file numbers may be in any order. @@ -540,9 +541,10 @@ StringRef FileName, unsigned FileNumber, MD5::MD5Result *Checksum, + Optional Source, unsigned CUID) { MCDwarfLineTable &Table = MCDwarfLineTablesCUMap[CUID]; - return Table.tryGetFile(Directory, FileName, Checksum, FileNumber); + return Table.tryGetFile(Directory, FileName, Checksum, Source, FileNumber); } /// isValidDwarfFileNumber - takes a dwarf file number and returns true if it Index: llvm/trunk/lib/MC/MCDwarf.cpp =================================================================== --- llvm/trunk/lib/MC/MCDwarf.cpp +++ llvm/trunk/lib/MC/MCDwarf.cpp @@ -11,7 +11,7 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/Hashing.h" -#include "llvm/ADT/None.h" +#include "llvm/ADT/Optional.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallVector.h" @@ -373,8 +373,13 @@ // The file format, which is the inline null-terminated filename and a // directory index. We don't track file size/timestamp so don't emit them - // in the v5 table. Emit MD5 checksums if we have them. - MCOS->EmitIntValue(HasMD5 ? 3 : 2, 1); + // in the v5 table. Emit MD5 checksums and source if we have them. + uint64_t Entries = 2; + if (HasMD5) + Entries += 1; + if (HasSource) + Entries += 1; + MCOS->EmitIntValue(Entries, 1); MCOS->EmitULEB128IntValue(dwarf::DW_LNCT_path); MCOS->EmitULEB128IntValue(LineStr ? dwarf::DW_FORM_line_strp : dwarf::DW_FORM_string); @@ -384,6 +389,11 @@ MCOS->EmitULEB128IntValue(dwarf::DW_LNCT_MD5); MCOS->EmitULEB128IntValue(dwarf::DW_FORM_data16); } + if (HasSource) { + MCOS->EmitULEB128IntValue(dwarf::DW_LNCT_LLVM_source); + MCOS->EmitULEB128IntValue(LineStr ? dwarf::DW_FORM_line_strp + : dwarf::DW_FORM_string); + } // Then the list of file names. These start at 1. MCOS->EmitULEB128IntValue(MCDwarfFiles.size() - 1); for (unsigned i = 1; i < MCDwarfFiles.size(); ++i) { @@ -401,6 +411,15 @@ StringRef(reinterpret_cast(Cksum->Bytes.data()), Cksum->Bytes.size())); } + if (HasSource) { + if (LineStr) + LineStr->emitRef(MCOS, MCDwarfFiles[i].Source.getValueOr(StringRef())); + else { + MCOS->EmitBytes( + MCDwarfFiles[i].Source.getValueOr(StringRef())); // Source and... + MCOS->EmitBytes(StringRef("\0", 1)); // its null terminator. + } + } } } @@ -500,14 +519,17 @@ Expected MCDwarfLineTable::tryGetFile(StringRef &Directory, StringRef &FileName, MD5::MD5Result *Checksum, + Optional Source, unsigned FileNumber) { - return Header.tryGetFile(Directory, FileName, Checksum, FileNumber); + return Header.tryGetFile(Directory, FileName, Checksum, Source, FileNumber); } -Expected MCDwarfLineTableHeader::tryGetFile(StringRef &Directory, - StringRef &FileName, - MD5::MD5Result *Checksum, - unsigned FileNumber) { +Expected +MCDwarfLineTableHeader::tryGetFile(StringRef &Directory, + StringRef &FileName, + MD5::MD5Result *Checksum, + Optional &Source, + unsigned FileNumber) { if (Directory == CompilationDir) Directory = ""; if (FileName.empty()) { @@ -515,9 +537,11 @@ Directory = ""; } assert(!FileName.empty()); - // If any files have an MD5 checksum, they all must. - if (MCDwarfFiles.empty()) + // If any files have an MD5 checksum or embedded source, they all must. + if (MCDwarfFiles.empty()) { HasMD5 = (Checksum != nullptr); + HasSource = (Source != None); + } if (FileNumber == 0) { // File numbers start with 1 and/or after any file numbers // allocated by inline-assembler .file directives. @@ -545,6 +569,10 @@ if (HasMD5 != (Checksum != nullptr)) return make_error("inconsistent use of MD5 checksums", inconvertibleErrorCode()); + // If any files have embedded source, they all must. + if (HasSource != (Source != None)) + return make_error("inconsistent use of embedded source", + inconvertibleErrorCode()); if (Directory.empty()) { // Separate the directory part from the basename of the FileName. @@ -582,6 +610,9 @@ File.Checksum = Checksum; if (Checksum) HasMD5 = true; + File.Source = Source; + if (Source) + HasSource = true; // return the allocated FileNumber. return FileNumber; Index: llvm/trunk/lib/MC/MCParser/AsmParser.cpp =================================================================== --- llvm/trunk/lib/MC/MCParser/AsmParser.cpp +++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp @@ -3250,7 +3250,7 @@ /// parseDirectiveFile /// ::= .file filename -/// ::= .file number [directory] filename [md5 checksum] +/// ::= .file number [directory] filename [md5 checksum] [source source-text] bool AsmParser::parseDirectiveFile(SMLoc DirectiveLoc) { // FIXME: I'm not sure what this is. int64_t FileNumber = -1; @@ -3286,23 +3286,36 @@ } std::string Checksum; - if (!parseOptionalToken(AsmToken::EndOfStatement)) { + + Optional Source; + bool HasSource = false; + std::string SourceString; + + while (!parseOptionalToken(AsmToken::EndOfStatement)) { StringRef Keyword; if (check(getTok().isNot(AsmToken::Identifier), "unexpected token in '.file' directive") || - parseIdentifier(Keyword) || - check(Keyword != "md5", "unexpected token in '.file' directive")) - return true; - if (getLexer().is(AsmToken::String) && - check(FileNumber == -1, "MD5 checksum specified, but no file number")) - return true; - if (check(getTok().isNot(AsmToken::String), - "unexpected token in '.file' directive") || - parseEscapedString(Checksum) || - check(Checksum.size() != 32, "invalid MD5 checksum specified") || - parseToken(AsmToken::EndOfStatement, - "unexpected token in '.file' directive")) + parseIdentifier(Keyword)) return true; + if (Keyword == "md5") { + if (check(FileNumber == -1, + "MD5 checksum specified, but no file number") || + check(getTok().isNot(AsmToken::String), + "unexpected token in '.file' directive") || + parseEscapedString(Checksum) || + check(Checksum.size() != 32, "invalid MD5 checksum specified")) + return true; + } else if (Keyword == "source") { + HasSource = true; + if (check(FileNumber == -1, + "source specified, but no file number") || + check(getTok().isNot(AsmToken::String), + "unexpected token in '.file' directive") || + parseEscapedString(SourceString)) + return true; + } else { + return TokError("unexpected token in '.file' directive"); + } } if (FileNumber == -1) @@ -3316,13 +3329,18 @@ CKMem = (MD5::MD5Result *)Ctx.allocate(sizeof(MD5::MD5Result), 1); memcpy(&CKMem->Bytes, Checksum.data(), 16); } + if (HasSource) { + char *SourceBuf = static_cast(Ctx.allocate(SourceString.size())); + memcpy(SourceBuf, SourceString.data(), SourceString.size()); + Source = StringRef(SourceBuf, SourceString.size()); + } // If there is -g option as well as debug info from directive file, // we turn off -g option, directly use the existing debug info instead. if (getContext().getGenDwarfForAssembly()) getContext().setGenDwarfForAssembly(false); else { Expected FileNumOrErr = getStreamer().tryEmitDwarfFileDirective( - FileNumber, Directory, Filename, CKMem); + FileNumber, Directory, Filename, CKMem, Source); if (!FileNumOrErr) return Error(DirectiveLoc, toString(FileNumOrErr.takeError())); FileNumber = FileNumOrErr.get(); Index: llvm/trunk/lib/MC/MCStreamer.cpp =================================================================== --- llvm/trunk/lib/MC/MCStreamer.cpp +++ llvm/trunk/lib/MC/MCStreamer.cpp @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// #include "llvm/MC/MCStreamer.h" +#include "llvm/ADT/Optional.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/Twine.h" @@ -191,8 +192,11 @@ Expected MCStreamer::tryEmitDwarfFileDirective(unsigned FileNo, StringRef Directory, StringRef Filename, - MD5::MD5Result *Checksum, unsigned CUID) { - return getContext().getDwarfFile(Directory, Filename, FileNo, Checksum, CUID); + MD5::MD5Result *Checksum, + Optional Source, + unsigned CUID) { + return getContext().getDwarfFile(Directory, Filename, FileNo, Checksum, + Source, CUID); } void MCStreamer::EmitDwarfLocDirective(unsigned FileNo, unsigned Line, Index: llvm/trunk/test/Assembler/debug-info.ll =================================================================== --- llvm/trunk/test/Assembler/debug-info.ll +++ llvm/trunk/test/Assembler/debug-info.ll @@ -1,8 +1,8 @@ ; RUN: llvm-as < %s | llvm-dis | llvm-as | llvm-dis | FileCheck %s ; RUN: verify-uselistorder %s -; CHECK: !named = !{!0, !0, !1, !2, !3, !4, !5, !6, !7, !8, !8, !9, !10, !11, !12, !13, !14, !15, !16, !17, !18, !19, !20, !21, !22, !23, !24, !25, !26, !27, !27, !28, !29, !30, !31, !32, !33, !34, !35} -!named = !{!0, !1, !2, !3, !4, !5, !6, !7, !8, !9, !10, !11, !12, !13, !14, !15, !16, !17, !18, !19, !20, !21, !22, !23, !24, !25, !26, !27, !28, !29, !30, !31, !32, !33, !34, !35, !36, !37, !38} +; CHECK: !named = !{!0, !0, !1, !2, !3, !4, !5, !6, !7, !8, !8, !9, !10, !11, !12, !13, !14, !15, !16, !17, !18, !19, !20, !21, !22, !23, !24, !25, !26, !27, !27, !28, !29, !30, !31, !32, !33, !34, !35, !36, !37} +!named = !{!0, !1, !2, !3, !4, !5, !6, !7, !8, !9, !10, !11, !12, !13, !14, !15, !16, !17, !18, !19, !20, !21, !22, !23, !24, !25, !26, !27, !28, !29, !30, !31, !32, !33, !34, !35, !36, !37, !38, !39, !40} ; CHECK: !0 = !DISubrange(count: 3) ; CHECK-NEXT: !1 = !DISubrange(count: 3, lowerBound: 4) @@ -89,3 +89,8 @@ !36 = !DICompositeType(tag: DW_TAG_variant_part, name: "A", scope: !16, size: 64, discriminator: !37) !37 = !DIDerivedType(tag: DW_TAG_member, scope: !36, baseType: !38, size: 64, align: 64, flags: DIFlagArtificial) !38 = !DIBasicType(name: "u64", size: 64, encoding: DW_ATE_unsigned) + +; CHECK-NEXT: !36 = !DIFile(filename: "file", directory: "dir", source: "int source() { }\0A") +; CHECK-NEXT: !37 = !DIFile(filename: "file", directory: "dir", checksumkind: CSK_MD5, checksum: "3a420e2646916a475e68de8d48f779f5", source: "int source() { }\0A") +!39 = !DIFile(filename: "file", directory: "dir", source: "int source() { }\0A") +!40 = !DIFile(filename: "file", directory: "dir", checksumkind: CSK_MD5, checksum: "3a420e2646916a475e68de8d48f779f5", source: "int source() { }\0A") Index: llvm/trunk/test/CodeGen/BPF/dwarfdump.ll =================================================================== --- llvm/trunk/test/CodeGen/BPF/dwarfdump.ll +++ llvm/trunk/test/CodeGen/BPF/dwarfdump.ll @@ -59,6 +59,8 @@ !26 = !DILocation(line: 7, column: 17, scope: !2) !27 = !DILocation(line: 9, column: 9, scope: !2) -; CHECK: file_names[ 1] 0 0x00000000 0x00000000 "testprog.c" +; CHECK: file_names[ 1]: +; CHECK-NEXT: name: "testprog.c" +; CHECK-NEXT: dir_index: 0 ; CHECK: 0x0000000000000000 2 ; CHECK: 0x0000000000000028 7 Index: llvm/trunk/test/CodeGen/Generic/dwarf-md5.ll =================================================================== --- llvm/trunk/test/CodeGen/Generic/dwarf-md5.ll +++ llvm/trunk/test/CodeGen/Generic/dwarf-md5.ll @@ -16,13 +16,21 @@ ; ASM: .file 1 ".{{/|\\\\}}t1.h" md5 "11111111111111111111111111111111" ; ASM: .file 2 ".{{/|\\\\}}t2.h" md5 "22222222222222222222222222222222" -; OBJ-4: Dir Mod Time File Len File Name -; OBJ-4: file_names[ 1] 1 0x00000000 0x00000000 "t1.h" -; OBJ-4: file_names[ 2] 1 0x00000000 0x00000000 "t2.h" - -; OBJ-5: Dir MD5 Checksum File Name -; OBJ-5: file_names[ 0] 1 11111111111111111111111111111111 "t1.h" -; OBJ-5: file_names[ 1] 1 22222222222222222222222222222222 "t2.h" +; OBJ-4: file_names[ 1]: +; OBJ-4-NEXT: name: "t1.h" +; OBJ-4-NEXT: dir_index: 1 +; OBJ-4: file_names[ 2]: +; OBJ-4-NEXT: name: "t2.h" +; OBJ-4-NEXT: dir_index: 1 + +; OBJ-5: file_names[ 0]: +; OBJ-5-NEXT: name: "t1.h" +; OBJ-5-NEXT: dir_index: 1 +; OBJ-5-NEXT: md5_checksum: 11111111111111111111111111111111 +; OBJ-5: file_names[ 1]: +; OBJ-5-NEXT: name: "t2.h" +; OBJ-5-NEXT: dir_index: 1 +; OBJ-5-NEXT: md5_checksum: 22222222222222222222222222222222 ; ModuleID = 't.c' source_filename = "t.c" Index: llvm/trunk/test/CodeGen/X86/dwarf-comp-dir.ll =================================================================== --- llvm/trunk/test/CodeGen/X86/dwarf-comp-dir.ll +++ llvm/trunk/test/CodeGen/X86/dwarf-comp-dir.ll @@ -15,7 +15,7 @@ !7 = !{!6} ; The important part of the following check is that dir = #0. -; Dir Mod Time File Len File Name -; ---- ---------- ---------- --------------------------- -; CHECK: file_names[ 1] 0 0x00000000 0x00000000 "empty.c" +; CHECK: file_names[ 1]: +; CHECK-NEXT: name: "empty.c" +; CHECK-NEXT: dir_index: 0 !5 = !{i32 1, !"Debug Info Version", i32 3} Index: llvm/trunk/test/DebugInfo/AMDGPU/dwarfdump-relocs.ll =================================================================== --- llvm/trunk/test/DebugInfo/AMDGPU/dwarfdump-relocs.ll +++ llvm/trunk/test/DebugInfo/AMDGPU/dwarfdump-relocs.ll @@ -13,7 +13,9 @@ ; } ; CHECK-NOT: failed to compute relocation -; CHECK: file_names[ 1] 0 0x00000000 0x00000000 "dwarfdump-relocs.cl" +; CHECK: file_names[ 1]: +; CHECK-NEXT: name: "dwarfdump-relocs.cl" +; CHECK-NEXT: dir_index: 0 declare void @llvm.dbg.declare(metadata, metadata, metadata) Index: llvm/trunk/test/DebugInfo/Generic/lto-comp-dir.ll =================================================================== --- llvm/trunk/test/DebugInfo/Generic/lto-comp-dir.ll +++ llvm/trunk/test/DebugInfo/Generic/lto-comp-dir.ll @@ -11,13 +11,17 @@ ; CHECK-NEXT: debug_line[{{.*}}] ; CHECK-NEXT: Line table prologue: ; CHECK-NOT: include_directories -; CHECK: file_names[ 1] 0 {{.*}} "a.cpp" +; CHECK: file_names[ 1] +; CHECK: name: "a.cpp" +; CHECK-NEXT: dir_index: 0 ; CHECK-NOT: file_names ; CHECK: debug_line[{{.*}}] ; CHECK-NEXT: Line table prologue: ; CHECK-NOT: include_directories -; CHECK: file_names[ 1] 0 {{.*}} "b.cpp" +; CHECK: file_names[ 1] +; CHECK: name: "b.cpp" +; CHECK-NEXT: dir_index: 0 ; CHECK-NOT: file_names ; However, if a single line table is emitted and shared between CUs, the Index: llvm/trunk/test/DebugInfo/X86/debug-macro.ll =================================================================== --- llvm/trunk/test/DebugInfo/X86/debug-macro.ll +++ llvm/trunk/test/DebugInfo/X86/debug-macro.ll @@ -28,11 +28,12 @@ ; CHECK-NEXT: DW_MACINFO_end_file ; CHECK-LABEL: .debug_line contents: -; CHECK: Dir Mod Time File Len File Name -; CHECK: file_names[ 1] {{.*}}debug-macro.cpp -; CHECK: file_names[ 2] {{.*}}debug-macro.h -; CHECK: Dir Mod Time File Len File Name -; CHECK: file_names[ 1] {{.*}}debug-macro1.cpp +; CHECK: file_names[ 1]: +; CHECK: name: "debug-macro.cpp" +; CHECK: file_names[ 2]: +; CHECK: name: "debug-macro.h" +; CHECK: file_names[ 1]: +; CHECK: name: "debug-macro1.cpp" !llvm.dbg.cu = !{!0, !16, !20} !llvm.module.flags = !{!13, !14} Index: llvm/trunk/test/DebugInfo/X86/dwarfdump-header-64.s =================================================================== --- llvm/trunk/test/DebugInfo/X86/dwarfdump-header-64.s +++ llvm/trunk/test/DebugInfo/X86/dwarfdump-header-64.s @@ -144,6 +144,14 @@ # CHECK: include_directories[ 0] = .debug_str[0x00000028] = "Directory5a" # CHECK: include_directories[ 1] = .debug_str[0x00000034] = "Directory5b" # CHECK-NOT: include_directories -# CHECK: file_names[ 0] 0 0x00000051 0x00000052 "File5a" -# CHECK: file_names[ 1] 1 0x00000053 0x00000054 "File5b" +# CHECK: file_names[ 0]: +# CHECK-NEXT: name: "File5a" +# CHECK-NEXT: dir_index: 0 +# CHECK-NEXT: mod_time: 0x00000051 +# CHECK-NEXT: length: 0x00000052 +# CHECK: file_names[ 1]: +# CHECK-NEXT: name: "File5b" +# CHECK-NEXT: dir_index: 1 +# CHECK-NEXT: mod_time: 0x00000053 +# CHECK-NEXT: length: 0x00000054 # CHECK-NOT: file_names Index: llvm/trunk/test/DebugInfo/X86/dwarfdump-header.s =================================================================== --- llvm/trunk/test/DebugInfo/X86/dwarfdump-header.s +++ llvm/trunk/test/DebugInfo/X86/dwarfdump-header.s @@ -258,8 +258,16 @@ # CHECK: include_directories[ 1] = "Directory4a" # CHECK: include_directories[ 2] = "Directory4b" # CHECK-NOT: include_directories -# CHECK: file_names[ 1] 1 0x00000041 0x00000042 "File4a" -# CHECK: file_names[ 2] 0 0x00000043 0x00000044 "File4b" +# CHECK: file_names[ 1]: +# CHECK-NEXT: name: "File4a" +# CHECK-NEXT: dir_index: 1 +# CHECK-NEXT: mod_time: 0x00000041 +# CHECK-NEXT: length: 0x00000042 +# CHECK: file_names[ 2]: +# CHECK-NEXT: name: "File4b" +# CHECK-NEXT: dir_index: 0 +# CHECK-NEXT: mod_time: 0x00000043 +# CHECK-NEXT: length: 0x00000044 # CHECK-NOT: file_names # DWARF v5 line-table header. @@ -329,9 +337,14 @@ # CHECK: include_directories[ 0] = .debug_str[0x00000045] = "Directory5a" # CHECK: include_directories[ 1] = .debug_str[0x00000051] = "Directory5b" # CHECK-NOT: include_directories -# CHECK: MD5 Checksum -# CHECK: file_names[ 0] 0 00112233445566778899aabbccddeeff .debug_line_str[0x00000000] = "File5a" -# CHECK: file_names[ 1] 1 ffeeddccbbaa99887766554433221100 .debug_line_str[0x00000007] = "File5b" +# CHECK: file_names[ 0]: +# CHECK-NEXT: name: .debug_line_str[0x00000000] = "File5a" +# CHECK-NEXT: dir_index: 0 +# CHECK-NEXT: md5_checksum: 00112233445566778899aabbccddeeff +# CHECK: file_names[ 1]: +# CHECK-NEXT: name: .debug_line_str[0x00000007] = "File5b" +# CHECK-NEXT: dir_index: 1 +# CHECK-NEXT: md5_checksum: ffeeddccbbaa99887766554433221100 # CHECK-NOT: file_names .section .debug_line_str,"MS",@progbits,1 @@ -410,6 +423,14 @@ # CHECK: include_directories[ 0] = .debug_str[0x0000003d] = "DWODirectory5a" # CHECK: include_directories[ 1] = .debug_str[0x0000004c] = "DWODirectory5b" # CHECK-NOT: include_directories -# CHECK: file_names[ 0] 0 0x00000015 0x00000025 "DWOFile5a" -# CHECK: file_names[ 1] 1 0x00000035 0x00000045 "DWOFile5b" +# CHECK: file_names[ 0]: +# CHECK-NEXT: name: "DWOFile5a" +# CHECK-NEXT: dir_index: 0 +# CHECK-NEXT: mod_time: 0x00000015 +# CHECK-NEXT: length: 0x00000025 +# CHECK: file_names[ 1]: +# CHECK-NEXT: name: "DWOFile5b" +# CHECK-NEXT: dir_index: 1 +# CHECK-NEXT: mod_time: 0x00000035 +# CHECK-NEXT: length: 0x00000045 # CHECK-NOT: file_names Index: llvm/trunk/test/DebugInfo/X86/dwarfdump-line-dwo.s =================================================================== --- llvm/trunk/test/DebugInfo/X86/dwarfdump-line-dwo.s +++ llvm/trunk/test/DebugInfo/X86/dwarfdump-line-dwo.s @@ -47,7 +47,8 @@ # PART1-NEXT: version: 4 # PART1-NEXT: prologue_length: 0x00000028 # PART1: include_directories[ 1] = "Directory1" -# PART1: file_names[ 1] {{.*}} "File1" +# PART1: file_names[ 1] +# PART1: name: "File1" # Second line table. LH_2_start: @@ -93,5 +94,6 @@ # PART2-NEXT: prologue_length: 0x00000022 # PART2-NOT: prologue: # PART2: include_directories[ 1] = "Dir2" -# PART2: file_names[ 1] {{.*}} "File2" +# PART2: file_names[ 1] +# PART2: name: "File2" # PART2-NOT: prologue: Index: llvm/trunk/test/DebugInfo/X86/dwarfdump-line-only.s =================================================================== --- llvm/trunk/test/DebugInfo/X86/dwarfdump-line-only.s +++ llvm/trunk/test/DebugInfo/X86/dwarfdump-line-only.s @@ -94,7 +94,15 @@ # CHECK: include_directories[ 0] = .debug_str[0x00000000] = "Directory1" # CHECK: include_directories[ 1] = .debug_str[0x0000000b] = "Directory2" # CHECK-NOT: include_directories -# CHECK: file_names[ 0] 1 0x00000051 0x00000052 .debug_line_str[0x00000000] = "File1" -# CHECK: file_names[ 1] 0 0x00000053 0x00000054 .debug_line_str[0x00000006] = "File2" +# CHECK: file_names[ 0]: +# CHECK-NEXT: name: .debug_line_str[0x00000000] = "File1" +# CHECK-NEXT: dir_index: 1 +# CHECK-NEXT: mod_time: 0x00000051 +# CHECK-NEXT: length: 0x00000052 +# CHECK: file_names[ 1]: +# CHECK-NEXT: name: .debug_line_str[0x00000006] = "File2" +# CHECK-NEXT: dir_index: 0 +# CHECK-NEXT: mod_time: 0x00000053 +# CHECK-NEXT: length: 0x00000054 # CHECK-NOT: file_names # CHECK: 0x0000000000000000 {{.*}} is_stmt end_sequence Index: llvm/trunk/test/DebugInfo/X86/generate-odr-hash.ll =================================================================== --- llvm/trunk/test/DebugInfo/X86/generate-odr-hash.ll +++ llvm/trunk/test/DebugInfo/X86/generate-odr-hash.ll @@ -122,8 +122,10 @@ ; CHECK-LABEL: .debug_line contents: ; CHECK: Line table prologue ; CHECK-NOT: file_names[ -; SINGLE: file_names{{.*}} "bar.h" -; CHECK: file_names{{.*}} "bar.cpp" +; SINGLE: file_names[ +; SINGLE-NEXT: name: "bar.h" +; CHECK: file_names[ +; CHECK-NEXT: name: "bar.cpp" ; CHECK-NOT: file_names[ ; FISSION: .debug_line.dwo contents: @@ -133,8 +135,10 @@ ; FISSION-NOT: standard_opcode_lengths ; FISSION-NOT: include_directories ; FISSION-NOT: file_names[ -; FISSION: file_names{{.*}} "bar.h" -; FISSION: file_names{{.*}} "bar.cpp" +; FISSION: file_names[ +; FISSION-NEXT: name: "bar.h" +; FISSION: file_names[ +; FISSION-NEXT: name: "bar.cpp" ; FISSION-NOT: file_names[ ; CHECK-LABEL: .debug_str contents: Index: llvm/trunk/test/DebugInfo/X86/stmt-list-multiple-compile-units.ll =================================================================== --- llvm/trunk/test/DebugInfo/X86/stmt-list-multiple-compile-units.ll +++ llvm/trunk/test/DebugInfo/X86/stmt-list-multiple-compile-units.ll @@ -27,11 +27,15 @@ ; CHECK-NEXT: debug_line[{{.*}}] ; CHECK-NEXT: Line table prologue: ; CHECK-NEXT: total_length: 0x00000038 -; CHECK: file_names[ 1] 0 0x00000000 0x00000000 "simple.c" +; CHECK: file_names[ 1]: +; CHECK-NEXT: name: "simple.c" +; CHECK-NEXT: dir_index: 0 ; CHECK: debug_line[{{.*}}] ; CHECK-NEXT: Line table prologue: ; CHECK-NEXT: total_length: 0x00000039 -; CHECK: file_names[ 1] 0 0x00000000 0x00000000 "simple2.c" +; CHECK: file_names[ 1]: +; CHECK-NEXT: name: "simple2.c" +; CHECK-NEXT: dir_index: 0 ; CHECK-NOT: file_names ; DWARF3: .debug_info contents: @@ -46,11 +50,15 @@ ; DWARF3-NEXT: debug_line[{{.*}}] ; DWARF3-NEXT: Line table prologue: ; DWARF3-NEXT: total_length: 0x00000038 -; DWARF3: file_names[ 1] 0 0x00000000 0x00000000 "simple.c" +; DWARF3: file_names[ 1]: +; DWARF3-NEXT: name: "simple.c" +; DWARF3-NEXT: dir_index: 0 ; DWARF3: debug_line[{{.*}}] ; DWARF3-NEXT: Line table prologue: ; DWARF3-NEXT: total_length: 0x00000039 -; DWARF3: file_names[ 1] 0 0x00000000 0x00000000 "simple2.c" +; DWARF3: file_names[ 1]: +; DWARF3-NEXT: name: "simple2.c" +; DWARF3-NEXT: dir_index: 0 ; DWARF3-NOT: file_names ; PR15408 Index: llvm/trunk/test/DebugInfo/debugmacinfo.test =================================================================== --- llvm/trunk/test/DebugInfo/debugmacinfo.test +++ llvm/trunk/test/DebugInfo/debugmacinfo.test @@ -22,6 +22,12 @@ TEST_MACINFO: DW_MACINFO_end_file TEST_LINE: .debug_line contents: -TEST_LINE: file_names[ 1] 0 0x00000000 0x00000000 "dwarfdump-macro.cc" -TEST_LINE: file_names[ 2] 1 0x00000000 0x00000000 "dwarfdump-macro-cmd.h" -TEST_LINE: file_names[ 3] 0 0x00000000 0x00000000 "dwarfdump-macro.h" +TEST_LINE: file_names[ 1]: +TEST_LINE-NEXT: name: "dwarfdump-macro.cc" +TEST_LINE-NEXT: dir_index: 0 +TEST_LINE: file_names[ 2]: +TEST_LINE-NEXT: name: "dwarfdump-macro-cmd.h" +TEST_LINE-NEXT: dir_index: 1 +TEST_LINE: file_names[ 3]: +TEST_LINE-NEXT: name: "dwarfdump-macro.h" +TEST_LINE-NEXT: dir_index: 0 Index: llvm/trunk/test/Linker/subprogram-linkonce-weak.ll =================================================================== --- llvm/trunk/test/Linker/subprogram-linkonce-weak.ll +++ llvm/trunk/test/Linker/subprogram-linkonce-weak.ll @@ -147,14 +147,18 @@ ; DW-LABEL: .debug_line contents: ; Check that we have the right things in the line table as well. -; DWLW-LABEL: file_names[{{ *}}1]{{.*}} "bar.c" +; DWLW-LABEL: file_names[ 1]: +; DWLW-NEXT: name: "bar.c" ; DWLW: 2 0 1 0 0 is_stmt prologue_end -; DWLW-LABEL: file_names[{{ *}}1]{{.*}} "foo.c" +; DWLW-LABEL: file_names[ 1]: +; DWLW-NEXT: name: "foo.c" ; DWLW: 52 0 1 0 0 is_stmt prologue_end ; DWLW-NOT: prologue_end -; DWWL-LABEL: file_names[{{ *}}1]{{.*}} "foo.c" +; DWWL-LABEL: file_names[ 1]: +; DWWL-NEXT: name: "foo.c" ; DWWL: 52 0 1 0 0 is_stmt prologue_end -; DWWL-LABEL: file_names[{{ *}}1]{{.*}} "bar.c" +; DWWL-LABEL: file_names[ 1]: +; DWWL-NEXT: name: "bar.c" ; DWWL: 2 0 1 0 0 is_stmt prologue_end ; DWWL-NOT: prologue_end Index: llvm/trunk/test/MC/ARM/dwarf-asm-multiple-sections.s =================================================================== --- llvm/trunk/test/MC/ARM/dwarf-asm-multiple-sections.s +++ llvm/trunk/test/MC/ARM/dwarf-asm-multiple-sections.s @@ -55,7 +55,8 @@ // DWARF-DL: version: [[DWVER]] // DWARF-DL-5: address_size: 4 // DWARF-DL-5: include_directories[ 0] = "" -// DWARF-DL: file_names[ [[DWFILE]]] {{.*}} "" +// DWARF-DL: file_names[ [[DWFILE]]]: +// DWARF-DL: name: "" // DWARF-DL: 0x0000000000000000 17 0 1 0 0 is_stmt // DWARF-DL-NEXT: 0x0000000000000004 17 0 1 0 0 is_stmt end_sequence // DWARF-DL-NEXT: 0x0000000000000000 21 0 1 0 0 is_stmt Index: llvm/trunk/test/MC/ELF/debug-md5.s =================================================================== --- llvm/trunk/test/MC/ELF/debug-md5.s +++ llvm/trunk/test/MC/ELF/debug-md5.s @@ -13,9 +13,14 @@ # CHECK: include_directories[ 1] = .debug_line_str[0x[[DIR1:[0-9a-f]+]]] = "dir1" # CHECK: include_directories[ 2] = .debug_line_str[0x[[DIR2:[0-9a-f]+]]] = "dir2" # CHECK-NOT: include_directories -# CHECK: Dir MD5 Checksum File Name -# CHECK: file_names[ 0] 1 00112233445566778899aabbccddeeff .debug_line_str[0x[[FILE1:[0-9a-f]+]]] = "foo" -# CHECK: file_names[ 1] 2 ffeeddccbbaa99887766554433221100 .debug_line_str[0x[[FILE2:[0-9a-f]+]]] = "bar" +# CHECK: file_names[ 0]: +# CHECK-NEXT: name: .debug_line_str[0x[[FILE1:[0-9a-f]+]]] = "foo" +# CHECK-NEXT: dir_index: 1 +# CHECK-NEXT: md5_checksum: 00112233445566778899aabbccddeeff +# CHECK: file_names[ 1]: +# CHECK-NEXT: name: .debug_line_str[0x[[FILE2:[0-9a-f]+]]] = "bar" +# CHECK-NEXT: dir_index: 2 +# CHECK-NEXT: md5_checksum: ffeeddccbbaa99887766554433221100 # CHECK: .debug_line_str contents: # CHECK-NEXT: 0x[[DIR0]]: "" Index: llvm/trunk/test/MC/MachO/gen-dwarf-cpp.s =================================================================== --- llvm/trunk/test/MC/MachO/gen-dwarf-cpp.s +++ llvm/trunk/test/MC/MachO/gen-dwarf-cpp.s @@ -16,11 +16,15 @@ // We check that the source name "t.s" is picked up // CHECK: include_directories[ 1] = "{{.*(/|\\\\)}}test{{(/|\\\\)}}MC{{(/|\\\\)}}MachO" // CHECK: include_directories[ 2] = "inc" -// CHECK: Dir Mod Time File Len File Name -// CHECK: ---- ---------- ---------- --------------------------- -// CHECK: file_names[ 1] 1 0x00000000 0x00000000 "gen-dwarf-cpp.s" -// CHECK: file_names[ 2] 0 0x00000000 0x00000000 "t.s" -// CHECK: file_names[ 3] 2 0x00000000 0x00000000 "g.s" +// CHECK: file_names[ 1]: +// CHECK-NEXT: name: "gen-dwarf-cpp.s" +// CHECK-NEXT: dir_index: 1 +// CHECK: file_names[ 2]: +// CHECK-NEXT: name: "t.s" +// CHECK-NEXT: dir_index: 0 +// CHECK: file_names[ 3]: +// CHECK-NEXT: name: "g.s" +// CHECK-NEXT: dir_index: 2 // CHECK-NOT: file_names // We check that the source line number 100 is picked up before the "movl" Index: llvm/trunk/test/MC/MachO/gen-dwarf-macro-cpp.s =================================================================== --- llvm/trunk/test/MC/MachO/gen-dwarf-macro-cpp.s +++ llvm/trunk/test/MC/MachO/gen-dwarf-macro-cpp.s @@ -11,7 +11,9 @@ // rdar://12637628 // We check that the source name "foo.S" is picked up -// CHECK: Dir Mod Time File Len File Name -// CHECK: ---- ---------- ---------- --------------------------- -// CHECK: file_names[ 1] 1 0x00000000 0x00000000 "gen-dwarf-macro-cpp.s" -// CHECK: file_names[ 2] 0 0x00000000 0x00000000 "foo.S" +// CHECK: file_names[ 1]: +// CHECK-NEXT: name: "gen-dwarf-macro-cpp.s" +// CHECK-NEXT: dir_index: 1 +// CHECK: file_names[ 2]: +// CHECK-NEXT: name: "foo.S" +// CHECK-NEXT: dir_index: 0 Index: llvm/trunk/test/MC/MachO/gen-dwarf.s =================================================================== --- llvm/trunk/test/MC/MachO/gen-dwarf.s +++ llvm/trunk/test/MC/MachO/gen-dwarf.s @@ -109,9 +109,9 @@ // CHECK: standard_opcode_lengths[DW_LNS_set_epilogue_begin] = 0 // CHECK: standard_opcode_lengths[DW_LNS_set_isa] = 1 // We don't check include_directories as it has a temp path -// CHECK: Dir Mod Time File Len File Name -// CHECK: ---- ---------- ---------- --------------------------- -// CHECK: file_names[ 1] 1 0x00000000 0x00000000 "gen-dwarf.s" +// CHECK: file_names[ 1]: +// CHECK-NEXT: name: "gen-dwarf.s" +// CHECK-NEXT: dir_index: 1 // CHECK: Address Line Column File ISA Discriminator Flags // CHECK: ------------------ ------ ------ ------ --- ------------- ------------- Index: llvm/trunk/test/tools/dsymutil/X86/basic-linking-x86.test =================================================================== --- llvm/trunk/test/tools/dsymutil/X86/basic-linking-x86.test +++ llvm/trunk/test/tools/dsymutil/X86/basic-linking-x86.test @@ -153,18 +153,18 @@ CHECK-NEXT:[0x0000000100000f90, 0x0000000100000fa9) CHECK: .debug_line contents: -CHECK: Dir Mod Time File Len File Name -CHECK-NEXT: ---- ---------- ---------- --------------------------- -CHECK-NEXT: file_names[ 1] 0 0x00000000 0x00000000 "basic1.c" +CHECK: file_names[ 1]: +CHECK-NEXT: name: "basic1.c" +CHECK-NEXT: dir_index: 0 CHECK: Address Line Column File ISA Discriminator Flags CHECK-NEXT: ------------------ ------ ------ ------ --- ------------- ------------- CHECK-NEXT: 0x0000000100000ea0 23 0 1 0 0 is_stmt CHECK-NEXT: 0x0000000100000eb6 24 0 1 0 0 is_stmt prologue_end CHECK-NEXT: 0x0000000100000ec4 24 0 1 0 0 is_stmt end_sequence -CHECK: Dir Mod Time File Len File Name -CHECK-NEXT: ---- ---------- ---------- --------------------------- -CHECK-NEXT: file_names[ 1] 0 0x00000000 0x00000000 "basic2.c" +CHECK: file_names[ 1]: +CHECK-NEXT: name: "basic2.c" +CHECK-NEXT: dir_index: 0 CHECK: Address Line Column File ISA Discriminator Flags CHECK-NEXT: ------------------ ------ ------ ------ --- ------------- ------------- CHECK-NEXT: 0x0000000100000ed0 19 0 1 0 0 is_stmt @@ -174,9 +174,9 @@ CHECK-NEXT: 0x0000000100000f24 15 0 1 0 0 is_stmt prologue_end CHECK-NEXT: 0x0000000100000f37 15 0 1 0 0 is_stmt end_sequence -CHECK: Dir Mod Time File Len File Name -CHECK-NEXT: ---- ---------- ---------- --------------------------- -CHECK-NEXT: file_names[ 1] 0 0x00000000 0x00000000 "basic3.c" +CHECK: file_names[ 1]: +CHECK-NEXT: name: "basic3.c" +CHECK-NEXT: dir_index: 0 CHECK: Address Line Column File ISA Discriminator Flags CHECK-NEXT: ------------------ ------ ------ ------ --- ------------- ------------- CHECK-NEXT: 0x0000000100000f40 16 0 1 0 0 is_stmt Index: llvm/trunk/test/tools/dsymutil/X86/basic-lto-dw4-linking-x86.test =================================================================== --- llvm/trunk/test/tools/dsymutil/X86/basic-lto-dw4-linking-x86.test +++ llvm/trunk/test/tools/dsymutil/X86/basic-lto-dw4-linking-x86.test @@ -138,9 +138,9 @@ CHECK-NEXT: [0x0000000100000f90, 0x0000000100000fb4) CHECK: .debug_line contents: -CHECK: Dir Mod Time File Len File Name -CHECK-NEXT: ---- ---------- ---------- --------------------------- -CHECK-NEXT: file_names[ 1] 0 0x00000000 0x00000000 "basic1.c" +CHECK: file_names[ 1]: +CHECK-NEXT: name: "basic1.c" +CHECK-NEXT: dir_index: 0 CHECK: Address Line Column File ISA Discriminator Flags CHECK-NEXT: ------------------ ------ ------ ------ --- ------------- ------------- CHECK-NEXT: 0x0000000100000f40 26 0 1 0 0 is_stmt @@ -148,9 +148,9 @@ CHECK-NEXT: 0x0000000100000f49 27 3 1 0 0 CHECK-NEXT: 0x0000000100000f4b 27 3 1 0 0 end_sequence -CHECK: Dir Mod Time File Len File Name -CHECK-NEXT: ---- ---------- ---------- --------------------------- -CHECK-NEXT: file_names[ 1] 0 0x00000000 0x00000000 "basic2.c" +CHECK: file_names[ 1]: +CHECK-NEXT: name: "basic2.c" +CHECK-NEXT: dir_index: 0 CHECK: Address Line Column File ISA Discriminator Flags CHECK-NEXT: ------------------ ------ ------ ------ --- ------------- ------------- CHECK-NEXT: 0x0000000100000f50 19 0 1 0 0 is_stmt @@ -164,9 +164,9 @@ CHECK-NEXT: 0x0000000100000f85 20 3 1 0 0 CHECK-NEXT: 0x0000000100000f87 20 3 1 0 0 end_sequence -CHECK: Dir Mod Time File Len File Name -CHECK-NEXT: ---- ---------- ---------- --------------------------- -CHECK-NEXT: file_names[ 1] 0 0x00000000 0x00000000 "basic3.c" +CHECK: file_names[ 1]: +CHECK-NEXT: name: "basic3.c" +CHECK-NEXT: dir_index: 0 CHECK: Address Line Column File ISA Discriminator Flags CHECK-NEXT: ------------------ ------ ------ ------ --- ------------- ------------- CHECK-NEXT: 0x0000000100000f90 16 0 1 0 0 is_stmt Index: llvm/trunk/test/tools/dsymutil/X86/basic-lto-linking-x86.test =================================================================== --- llvm/trunk/test/tools/dsymutil/X86/basic-lto-linking-x86.test +++ llvm/trunk/test/tools/dsymutil/X86/basic-lto-linking-x86.test @@ -150,25 +150,25 @@ CHECK: .debug_line contents -CHECK: Dir Mod Time File Len File Name -CHECK-NEXT: ---- ---------- ---------- --------------------------- -CHECK-NEXT: file_names[ 1] 0 0x00000000 0x00000000 "basic1.c" +CHECK: file_names[ 1]: +CHECK-NEXT: name: "basic1.c" +CHECK-NEXT: dir_index: 0 CHECK: 0x0000000100000f40 23 0 1 0 0 is_stmt CHECK: 0x0000000100000f44 24 0 1 0 0 is_stmt prologue_end CHECK: 0x0000000100000f4b 24 0 1 0 0 is_stmt end_sequence -CHECK: Dir Mod Time File Len File Name -CHECK-NEXT: ---- ---------- ---------- --------------------------- -CHECK-NEXT: file_names[ 1] 0 0x00000000 0x00000000 "basic2.c" +CHECK: file_names[ 1]: +CHECK-NEXT: name: "basic2.c" +CHECK-NEXT: dir_index: 0 CHECK: 0x0000000100000f50 19 0 1 0 0 is_stmt CHECK: 0x0000000100000f54 20 0 1 0 0 is_stmt prologue_end CHECK: 0x0000000100000f63 15 0 1 0 0 is_stmt CHECK: 0x0000000100000f72 20 0 1 0 0 is_stmt CHECK: 0x0000000100000f89 20 0 1 0 0 is_stmt end_sequence -CHECK: Dir Mod Time File Len File Name -CHECK-NEXT: ---- ---------- ---------- --------------------------- -CHECK-NEXT: file_names[ 1] 0 0x00000000 0x00000000 "basic3.c" +CHECK: file_names[ 1]: +CHECK-NEXT: name: "basic3.c" +CHECK-NEXT: dir_index: 0 CHECK: 0x0000000100000f90 16 0 1 0 0 is_stmt CHECK: 0x0000000100000f94 12 0 1 0 0 is_stmt prologue_end CHECK: 0x0000000100000f9a 17 0 1 0 0 is_stmt Index: llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp =================================================================== --- llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp +++ llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp @@ -408,7 +408,7 @@ std::unordered_map> LineCache; private: - bool cacheSource(const std::string& File); + bool cacheSource(const DILineInfo& LineInfoFile); public: SourcePrinter() = default; @@ -423,23 +423,29 @@ 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 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 @@ 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()) { Index: llvm/trunk/unittests/IR/MetadataTest.cpp =================================================================== --- llvm/trunk/unittests/IR/MetadataTest.cpp +++ llvm/trunk/unittests/IR/MetadataTest.cpp @@ -1450,19 +1450,24 @@ DIFile::ChecksumKind CSKind = DIFile::ChecksumKind::CSK_MD5; StringRef ChecksumString = "000102030405060708090a0b0c0d0e0f"; DIFile::ChecksumInfo Checksum(CSKind, ChecksumString); - auto *N = DIFile::get(Context, Filename, Directory, Checksum); + StringRef Source = "source"; + auto *N = DIFile::get(Context, Filename, Directory, Checksum, Source); EXPECT_EQ(dwarf::DW_TAG_file_type, N->getTag()); EXPECT_EQ(Filename, N->getFilename()); EXPECT_EQ(Directory, N->getDirectory()); EXPECT_EQ(Checksum, N->getChecksum()); - EXPECT_EQ(N, DIFile::get(Context, Filename, Directory, Checksum)); + EXPECT_EQ(Source, N->getSource()); + EXPECT_EQ(N, DIFile::get(Context, Filename, Directory, Checksum, Source)); - EXPECT_NE(N, DIFile::get(Context, "other", Directory, Checksum)); - EXPECT_NE(N, DIFile::get(Context, Filename, "other", Checksum)); + EXPECT_NE(N, DIFile::get(Context, "other", Directory, Checksum, Source)); + EXPECT_NE(N, DIFile::get(Context, Filename, "other", Checksum, Source)); DIFile::ChecksumInfo OtherChecksum(DIFile::ChecksumKind::CSK_SHA1, ChecksumString); EXPECT_NE( N, DIFile::get(Context, Filename, Directory, OtherChecksum)); + StringRef OtherSource = "other"; + EXPECT_NE(N, DIFile::get(Context, Filename, Directory, Checksum, OtherSource)); + EXPECT_NE(N, DIFile::get(Context, Filename, Directory, Checksum)); EXPECT_NE(N, DIFile::get(Context, Filename, Directory)); TempDIFile Temp = N->clone();