Index: include/llvm/DebugInfo/DWARF/DWARFDebugLine.h =================================================================== --- include/llvm/DebugInfo/DWARF/DWARFDebugLine.h +++ include/llvm/DebugInfo/DWARF/DWARFDebugLine.h @@ -188,6 +188,9 @@ bool lookupAddressRange(uint64_t address, uint64_t size, std::vector &result) const; + bool hasFileNameByIndex(uint64_t FileIndex, + DILineInfoSpecifier::FileLineInfoKind Kind) const; + // Extracts filename by its index in filename table in prologue. // Returns true on success. bool getFileNameByIndex(uint64_t FileIndex, const char *CompDir, Index: lib/DebugInfo/DWARF/DWARFDebugLine.cpp =================================================================== --- lib/DebugInfo/DWARF/DWARFDebugLine.cpp +++ lib/DebugInfo/DWARF/DWARFDebugLine.cpp @@ -624,13 +624,22 @@ return true; } -bool DWARFDebugLine::LineTable::getFileNameByIndex(uint64_t FileIndex, - const char *CompDir, - FileLineInfoKind Kind, - std::string &Result) const { +bool +DWARFDebugLine::LineTable::hasFileNameByIndex(uint64_t FileIndex, + FileLineInfoKind Kind) const { if (FileIndex == 0 || FileIndex > Prologue.FileNames.size() || Kind == FileLineInfoKind::None) return false; + return true; +} + +bool +DWARFDebugLine::LineTable::getFileNameByIndex(uint64_t FileIndex, + const char *CompDir, + FileLineInfoKind Kind, + std::string &Result) const { + if (!hasFileNameByIndex(FileIndex, Kind)) + return false; const FileNameEntry &Entry = Prologue.FileNames[FileIndex - 1]; const char *FileName = Entry.Name; if (Kind != FileLineInfoKind::AbsoluteFilePath || Index: tools/dsymutil/DwarfLinker.cpp =================================================================== --- tools/dsymutil/DwarfLinker.cpp +++ tools/dsymutil/DwarfLinker.cpp @@ -1633,11 +1633,8 @@ // FIXME: Passing U.getOrigUnit().getCompilationDir() // instead of "" would allow more uniquing, but for now, do // it this way to match dsymutil-classic. - std::string File; - if (LT->getFileNameByIndex( - FileNum, "", - DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath, - File)) { + if (LT->hasFileNameByIndex(FileNum, + DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath)) { Line = DIE->getAttributeValueAsUnsignedConstant( &U.getOrigUnit(), dwarf::DW_AT_decl_line, 0); // Cache the resolved paths, because calling realpath is expansive. @@ -1646,6 +1643,13 @@ FileRef = ResolvedPath; } else { #ifdef HAVE_REALPATH + std::string File; + bool gotFileName = + LT->getFileNameByIndex(FileNum, "", + DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath, + File); + (void)gotFileName; + assert(gotFileName && "Must get file name from line table"); char RealPath[PATH_MAX + 1]; RealPath[PATH_MAX] = 0; if (::realpath(File.c_str(), RealPath))