From 364e3e04c7e196b5a92d1c06410c882e621ef4b0 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Tue, 16 Jul 2019 00:59:04 +0000 Subject: [PATCH] Revert "[DebugInfo] Move function from line table to the prologue (NFC)" This broke LLD, which I didn't have enabled. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@366160 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/DebugInfo/DWARF/DWARFDebugLine.h | 26 +++---- lib/DebugInfo/DWARF/DWARFDebugLine.cpp | 67 ++++++++++--------- 2 files changed, 42 insertions(+), 51 deletions(-) diff --git a/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h b/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h index e7425c19237..9a3ad2b08c9 100644 --- a/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h +++ b/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h @@ -121,17 +121,6 @@ public: return LineBase + (int8_t)LineRange - 1; } - /// Get DWARF-version aware access to the file name entry at the provided - /// index. - const llvm::DWARFDebugLine::FileNameEntry & - getFileNameEntry(uint64_t Index) const; - - bool hasFileAtIndex(uint64_t FileIndex) const; - - bool getFileNameByIndex(uint64_t FileIndex, StringRef CompDir, - DILineInfoSpecifier::FileLineInfoKind Kind, - std::string &Result) const; - void clear(); void dump(raw_ostream &OS, DIDumpOptions DumpOptions) const; Error parse(const DWARFDataExtractor &DebugLineData, uint32_t *OffsetPtr, @@ -251,20 +240,16 @@ public: bool lookupAddressRange(object::SectionedAddress Address, uint64_t Size, std::vector &Result) const; - bool hasFileAtIndex(uint64_t FileIndex) const { - return Prologue.hasFileAtIndex(FileIndex); - } + bool hasFileAtIndex(uint64_t FileIndex) const; /// Extracts filename by its index in filename table in prologue. /// In Dwarf 4, the files are 1-indexed and the current compilation file /// name is not represented in the list. In DWARF v5, the files are /// 0-indexed and the primary source file has the index 0. /// Returns true on success. - bool getFileNameByIndex(uint64_t FileIndex, StringRef CompDir, + bool getFileNameByIndex(uint64_t FileIndex, const char *CompDir, DILineInfoSpecifier::FileLineInfoKind Kind, - std::string &Result) const { - return Prologue.getFileNameByIndex(FileIndex, CompDir, Kind, Result); - } + std::string &Result) const; /// Fills the Result argument with the file and line information /// corresponding to Address. Returns true on success. @@ -283,6 +268,11 @@ public: std::function RecoverableErrorCallback, raw_ostream *OS = nullptr); + /// Get DWARF-version aware access to the file name entry at the provided + /// index. + const llvm::DWARFDebugLine::FileNameEntry & + getFileNameEntry(uint64_t Index) const; + using RowVector = std::vector; using RowIter = RowVector::const_iterator; using SequenceVector = std::vector; diff --git a/lib/DebugInfo/DWARF/DWARFDebugLine.cpp b/lib/DebugInfo/DWARF/DWARFDebugLine.cpp index 8a621084710..9f9aaabf1e8 100644 --- a/lib/DebugInfo/DWARF/DWARFDebugLine.cpp +++ b/lib/DebugInfo/DWARF/DWARFDebugLine.cpp @@ -66,26 +66,6 @@ void DWARFDebugLine::ContentTypeTracker::trackContentType( DWARFDebugLine::Prologue::Prologue() { clear(); } -bool DWARFDebugLine::Prologue::hasFileAtIndex(uint64_t FileIndex) const { - uint16_t DwarfVersion = getVersion(); - assert(DwarfVersion != 0 && - "line table prologue has no dwarf version information"); - if (DwarfVersion >= 5) - return FileIndex < FileNames.size(); - return FileIndex != 0 && FileIndex <= FileNames.size(); -} - -const llvm::DWARFDebugLine::FileNameEntry & -DWARFDebugLine::Prologue::getFileNameEntry(uint64_t Index) const { - uint16_t DwarfVersion = getVersion(); - assert(DwarfVersion != 0 && - "line table prologue has no dwarf version information"); - // In DWARF v5 the file names are 0-indexed. - if (DwarfVersion >= 5) - return FileNames[Index]; - return FileNames[Index - 1]; -} - void DWARFDebugLine::Prologue::clear() { TotalLength = PrologueLength = 0; SegSelectorSize = 0; @@ -988,11 +968,30 @@ bool DWARFDebugLine::LineTable::lookupAddressRangeImpl( return true; } +bool DWARFDebugLine::LineTable::hasFileAtIndex(uint64_t FileIndex) const { + uint16_t DwarfVersion = Prologue.getVersion(); + assert(DwarfVersion != 0 && "LineTable has no dwarf version information"); + if (DwarfVersion >= 5) + return FileIndex < Prologue.FileNames.size(); + return FileIndex != 0 && FileIndex <= Prologue.FileNames.size(); +} + +const llvm::DWARFDebugLine::FileNameEntry & +DWARFDebugLine::LineTable::getFileNameEntry(uint64_t Index) const { + uint16_t DwarfVersion = Prologue.getVersion(); + assert(DwarfVersion != 0 && "LineTable has no dwarf version information"); + // In DWARF v5 the file names are 0-indexed. + if (DwarfVersion >= 5) + return Prologue.FileNames[Index]; + else + return Prologue.FileNames[Index - 1]; +} + Optional DWARFDebugLine::LineTable::getSourceByIndex(uint64_t FileIndex, FileLineInfoKind Kind) const { - if (Kind == FileLineInfoKind::None || !Prologue.hasFileAtIndex(FileIndex)) + if (Kind == FileLineInfoKind::None || !hasFileAtIndex(FileIndex)) return None; - const FileNameEntry &Entry = Prologue.getFileNameEntry(FileIndex); + const FileNameEntry &Entry = getFileNameEntry(FileIndex); if (Optional source = Entry.Source.getAsCString()) return StringRef(*source); return None; @@ -1006,10 +1005,10 @@ static bool isPathAbsoluteOnWindowsOrPosix(const Twine &Path) { sys::path::is_absolute(Path, sys::path::Style::windows); } -bool DWARFDebugLine::Prologue::getFileNameByIndex(uint64_t FileIndex, - StringRef CompDir, - FileLineInfoKind Kind, - std::string &Result) const { +bool DWARFDebugLine::LineTable::getFileNameByIndex(uint64_t FileIndex, + const char *CompDir, + FileLineInfoKind Kind, + std::string &Result) const { if (Kind == FileLineInfoKind::None || !hasFileAtIndex(FileIndex)) return false; const FileNameEntry &Entry = getFileNameEntry(FileIndex); @@ -1023,18 +1022,20 @@ bool DWARFDebugLine::Prologue::getFileNameByIndex(uint64_t FileIndex, SmallString<16> FilePath; StringRef IncludeDir; // Be defensive about the contents of Entry. - if (getVersion() >= 5) { - if (Entry.DirIdx < IncludeDirectories.size()) - IncludeDir = IncludeDirectories[Entry.DirIdx].getAsCString().getValue(); - } else { - if (0 < Entry.DirIdx && Entry.DirIdx <= IncludeDirectories.size()) + if (Prologue.getVersion() >= 5) { + if (Entry.DirIdx < Prologue.IncludeDirectories.size()) IncludeDir = - IncludeDirectories[Entry.DirIdx - 1].getAsCString().getValue(); + 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.empty() && !isPathAbsoluteOnWindowsOrPosix(IncludeDir)) + if (CompDir && !isPathAbsoluteOnWindowsOrPosix(IncludeDir)) sys::path::append(FilePath, CompDir); } -- 2.40.0