llvm.org GIT mirror llvm / a8aec29
Re-land "[DebugInfo] Move function from line table to the prologue (NFC)" In LLDB, when parsing type units, we don't need to parse the whole line table. Instead, we only need to parse the "support files" from the line table prologue. To make that possible, this patch moves the respective functions from the LineTable into the Prologue. Because I don't think users of the LineTable should have to know that these files come from the Prologue, I've left the original methods in place, and made them redirect to the LineTable. Differential revision: https://reviews.llvm.org/D64774 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@366164 91177308-0d34-0410-b5e6-96231b3b80d8 Jonas Devlieghere 3 months ago
2 changed file(s) with 51 addition(s) and 42 deletion(s). Raw diff Collapse all Expand all
119119 int32_t getMaxLineIncrementForSpecialOpcode() const {
120120 return LineBase + (int8_t)LineRange - 1;
121121 }
122
123 /// Get DWARF-version aware access to the file name entry at the provided
124 /// index.
125 const llvm::DWARFDebugLine::FileNameEntry &
126 getFileNameEntry(uint64_t Index) const;
127
128 bool hasFileAtIndex(uint64_t FileIndex) const;
129
130 bool getFileNameByIndex(uint64_t FileIndex, StringRef CompDir,
131 DILineInfoSpecifier::FileLineInfoKind Kind,
132 std::string &Result) const;
122133
123134 void clear();
124135 void dump(raw_ostream &OS, DIDumpOptions DumpOptions) const;
239250 bool lookupAddressRange(object::SectionedAddress Address, uint64_t Size,
240251 std::vector &Result) const;
241252
242 bool hasFileAtIndex(uint64_t FileIndex) const;
253 bool hasFileAtIndex(uint64_t FileIndex) const {
254 return Prologue.hasFileAtIndex(FileIndex);
255 }
243256
244257 /// Extracts filename by its index in filename table in prologue.
245258 /// In Dwarf 4, the files are 1-indexed and the current compilation file
246259 /// name is not represented in the list. In DWARF v5, the files are
247260 /// 0-indexed and the primary source file has the index 0.
248261 /// Returns true on success.
249 bool getFileNameByIndex(uint64_t FileIndex, const char *CompDir,
262 bool getFileNameByIndex(uint64_t FileIndex, StringRef CompDir,
250263 DILineInfoSpecifier::FileLineInfoKind Kind,
251 std::string &Result) const;
264 std::string &Result) const {
265 return Prologue.getFileNameByIndex(FileIndex, CompDir, Kind, Result);
266 }
252267
253268 /// Fills the Result argument with the file and line information
254269 /// corresponding to Address. Returns true on success.
266281 const DWARFContext &Ctx, const DWARFUnit *U,
267282 std::function RecoverableErrorCallback,
268283 raw_ostream *OS = nullptr);
269
270 /// Get DWARF-version aware access to the file name entry at the provided
271 /// index.
272 const llvm::DWARFDebugLine::FileNameEntry &
273 getFileNameEntry(uint64_t Index) const;
274284
275285 using RowVector = std::vector;
276286 using RowIter = RowVector::const_iterator;
6464 }
6565
6666 DWARFDebugLine::Prologue::Prologue() { clear(); }
67
68 bool DWARFDebugLine::Prologue::hasFileAtIndex(uint64_t FileIndex) const {
69 uint16_t DwarfVersion = getVersion();
70 assert(DwarfVersion != 0 &&
71 "line table prologue has no dwarf version information");
72 if (DwarfVersion >= 5)
73 return FileIndex < FileNames.size();
74 return FileIndex != 0 && FileIndex <= FileNames.size();
75 }
76
77 const llvm::DWARFDebugLine::FileNameEntry &
78 DWARFDebugLine::Prologue::getFileNameEntry(uint64_t Index) const {
79 uint16_t DwarfVersion = getVersion();
80 assert(DwarfVersion != 0 &&
81 "line table prologue has no dwarf version information");
82 // In DWARF v5 the file names are 0-indexed.
83 if (DwarfVersion >= 5)
84 return FileNames[Index];
85 return FileNames[Index - 1];
86 }
6787
6888 void DWARFDebugLine::Prologue::clear() {
6989 TotalLength = PrologueLength = 0;
967987 return true;
968988 }
969989
970 bool DWARFDebugLine::LineTable::hasFileAtIndex(uint64_t FileIndex) const {
971 uint16_t DwarfVersion = Prologue.getVersion();
972 assert(DwarfVersion != 0 && "LineTable has no dwarf version information");
973 if (DwarfVersion >= 5)
974 return FileIndex < Prologue.FileNames.size();
975 return FileIndex != 0 && FileIndex <= Prologue.FileNames.size();
976 }
977
978 const llvm::DWARFDebugLine::FileNameEntry &
979 DWARFDebugLine::LineTable::getFileNameEntry(uint64_t Index) const {
980 uint16_t DwarfVersion = Prologue.getVersion();
981 assert(DwarfVersion != 0 && "LineTable has no dwarf version information");
982 // In DWARF v5 the file names are 0-indexed.
983 if (DwarfVersion >= 5)
984 return Prologue.FileNames[Index];
985 else
986 return Prologue.FileNames[Index - 1];
987 }
988
989990 Optional DWARFDebugLine::LineTable::getSourceByIndex(uint64_t FileIndex,
990991 FileLineInfoKind Kind) const {
991 if (Kind == FileLineInfoKind::None || !hasFileAtIndex(FileIndex))
992 if (Kind == FileLineInfoKind::None || !Prologue.hasFileAtIndex(FileIndex))
992993 return None;
993 const FileNameEntry &Entry = getFileNameEntry(FileIndex);
994 const FileNameEntry &Entry = Prologue.getFileNameEntry(FileIndex);
994995 if (Optional source = Entry.Source.getAsCString())
995996 return StringRef(*source);
996997 return None;
10041005 sys::path::is_absolute(Path, sys::path::Style::windows);
10051006 }
10061007
1007 bool DWARFDebugLine::LineTable::getFileNameByIndex(uint64_t FileIndex,
1008 const char *CompDir,
1009 FileLineInfoKind Kind,
1010 std::string &Result) const {
1008 bool DWARFDebugLine::Prologue::getFileNameByIndex(uint64_t FileIndex,
1009 StringRef CompDir,
1010 FileLineInfoKind Kind,
1011 std::string &Result) const {
10111012 if (Kind == FileLineInfoKind::None || !hasFileAtIndex(FileIndex))
10121013 return false;
10131014 const FileNameEntry &Entry = getFileNameEntry(FileIndex);
10211022 SmallString<16> FilePath;
10221023 StringRef IncludeDir;
10231024 // Be defensive about the contents of Entry.
1024 if (Prologue.getVersion() >= 5) {
1025 if (Entry.DirIdx < Prologue.IncludeDirectories.size())
1025 if (getVersion() >= 5) {
1026 if (Entry.DirIdx < IncludeDirectories.size())
1027 IncludeDir = IncludeDirectories[Entry.DirIdx].getAsCString().getValue();
1028 } else {
1029 if (0 < Entry.DirIdx && Entry.DirIdx <= IncludeDirectories.size())
10261030 IncludeDir =
1027 Prologue.IncludeDirectories[Entry.DirIdx].getAsCString().getValue();
1028 } else {
1029 if (0 < Entry.DirIdx && Entry.DirIdx <= Prologue.IncludeDirectories.size())
1030 IncludeDir = Prologue.IncludeDirectories[Entry.DirIdx - 1]
1031 .getAsCString()
1032 .getValue();
1031 IncludeDirectories[Entry.DirIdx - 1].getAsCString().getValue();
10331032
10341033 // We may still need to append compilation directory of compile unit.
10351034 // We know that FileName is not absolute, the only way to have an
10361035 // absolute path at this point would be if IncludeDir is absolute.
1037 if (CompDir && !isPathAbsoluteOnWindowsOrPosix(IncludeDir))
1036 if (!CompDir.empty() && !isPathAbsoluteOnWindowsOrPosix(IncludeDir))
10381037 sys::path::append(FilePath, CompDir);
10391038 }
10401039