From 7e55672b225640fa19f92e9ae73f53d0718b3ad6 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Mon, 6 May 2019 08:03:46 +0000 Subject: DWARF v5: fix directory index in the line table Summary: Prior to DWARF v5, a directory index of 0 represents DW_AT_comp_dir. In DWARF v5, the index starts with 0 and Entry.DirIdx is the index into Prologue.IncludeDirectories. Reviewed By: labath Differential Revision: https://reviews.llvm.org/D61253 llvm-svn: 360015 --- llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp') diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp index 1f18973f1d4..9f9aaabf1e8 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp @@ -1020,20 +1020,24 @@ bool DWARFDebugLine::LineTable::getFileNameByIndex(uint64_t FileIndex, } SmallString<16> FilePath; - uint64_t IncludeDirIndex = Entry.DirIdx; StringRef IncludeDir; // Be defensive about the contents of Entry. - if (IncludeDirIndex > 0 && - IncludeDirIndex <= Prologue.IncludeDirectories.size()) - IncludeDir = Prologue.IncludeDirectories[IncludeDirIndex - 1] - .getAsCString() - .getValue(); - - // We may still need to append compilation directory of compile unit. - // We know that FileName is not absolute, the only way to have an - // absolute path at this point would be if IncludeDir is absolute. - if (CompDir && !isPathAbsoluteOnWindowsOrPosix(IncludeDir)) - sys::path::append(FilePath, CompDir); + if (Prologue.getVersion() >= 5) { + if (Entry.DirIdx < Prologue.IncludeDirectories.size()) + IncludeDir = + Prologue.IncludeDirectories[Entry.DirIdx].getAsCString().getValue(); + } else { + if (0 < Entry.DirIdx && Entry.DirIdx <= Prologue.IncludeDirectories.size()) + IncludeDir = Prologue.IncludeDirectories[Entry.DirIdx - 1] + .getAsCString() + .getValue(); + + // We may still need to append compilation directory of compile unit. + // We know that FileName is not absolute, the only way to have an + // absolute path at this point would be if IncludeDir is absolute. + if (CompDir && !isPathAbsoluteOnWindowsOrPosix(IncludeDir)) + sys::path::append(FilePath, CompDir); + } // sys::path::append skips empty strings. sys::path::append(FilePath, IncludeDir, FileName); -- cgit v1.2.3