Skip to content

Commit ca16d28

Browse files
committed
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 llvm-svn: 366164
1 parent fa52e00 commit ca16d28

File tree

3 files changed

+52
-43
lines changed

3 files changed

+52
-43
lines changed

lld/ELF/InputFiles.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ ObjFile<ELFT>::getVariableLoc(StringRef name) {
320320
// Take file name string from line table.
321321
std::string fileName;
322322
if (!it->second.lt->getFileNameByIndex(
323-
it->second.file, nullptr,
323+
it->second.file, {},
324324
DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath, fileName))
325325
return None;
326326

llvm/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h

+18-8
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,17 @@ class DWARFDebugLine {
121121
return LineBase + (int8_t)LineRange - 1;
122122
}
123123

124+
/// Get DWARF-version aware access to the file name entry at the provided
125+
/// index.
126+
const llvm::DWARFDebugLine::FileNameEntry &
127+
getFileNameEntry(uint64_t Index) const;
128+
129+
bool hasFileAtIndex(uint64_t FileIndex) const;
130+
131+
bool getFileNameByIndex(uint64_t FileIndex, StringRef CompDir,
132+
DILineInfoSpecifier::FileLineInfoKind Kind,
133+
std::string &Result) const;
134+
124135
void clear();
125136
void dump(raw_ostream &OS, DIDumpOptions DumpOptions) const;
126137
Error parse(const DWARFDataExtractor &DebugLineData, uint32_t *OffsetPtr,
@@ -240,16 +251,20 @@ class DWARFDebugLine {
240251
bool lookupAddressRange(object::SectionedAddress Address, uint64_t Size,
241252
std::vector<uint32_t> &Result) const;
242253

243-
bool hasFileAtIndex(uint64_t FileIndex) const;
254+
bool hasFileAtIndex(uint64_t FileIndex) const {
255+
return Prologue.hasFileAtIndex(FileIndex);
256+
}
244257

245258
/// Extracts filename by its index in filename table in prologue.
246259
/// In Dwarf 4, the files are 1-indexed and the current compilation file
247260
/// name is not represented in the list. In DWARF v5, the files are
248261
/// 0-indexed and the primary source file has the index 0.
249262
/// Returns true on success.
250-
bool getFileNameByIndex(uint64_t FileIndex, const char *CompDir,
263+
bool getFileNameByIndex(uint64_t FileIndex, StringRef CompDir,
251264
DILineInfoSpecifier::FileLineInfoKind Kind,
252-
std::string &Result) const;
265+
std::string &Result) const {
266+
return Prologue.getFileNameByIndex(FileIndex, CompDir, Kind, Result);
267+
}
253268

254269
/// Fills the Result argument with the file and line information
255270
/// corresponding to Address. Returns true on success.
@@ -268,11 +283,6 @@ class DWARFDebugLine {
268283
std::function<void(Error)> RecoverableErrorCallback,
269284
raw_ostream *OS = nullptr);
270285

271-
/// Get DWARF-version aware access to the file name entry at the provided
272-
/// index.
273-
const llvm::DWARFDebugLine::FileNameEntry &
274-
getFileNameEntry(uint64_t Index) const;
275-
276286
using RowVector = std::vector<Row>;
277287
using RowIter = RowVector::const_iterator;
278288
using SequenceVector = std::vector<Sequence>;

llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp

+33-34
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,26 @@ void DWARFDebugLine::ContentTypeTracker::trackContentType(
6666

6767
DWARFDebugLine::Prologue::Prologue() { clear(); }
6868

69+
bool DWARFDebugLine::Prologue::hasFileAtIndex(uint64_t FileIndex) const {
70+
uint16_t DwarfVersion = getVersion();
71+
assert(DwarfVersion != 0 &&
72+
"line table prologue has no dwarf version information");
73+
if (DwarfVersion >= 5)
74+
return FileIndex < FileNames.size();
75+
return FileIndex != 0 && FileIndex <= FileNames.size();
76+
}
77+
78+
const llvm::DWARFDebugLine::FileNameEntry &
79+
DWARFDebugLine::Prologue::getFileNameEntry(uint64_t Index) const {
80+
uint16_t DwarfVersion = getVersion();
81+
assert(DwarfVersion != 0 &&
82+
"line table prologue has no dwarf version information");
83+
// In DWARF v5 the file names are 0-indexed.
84+
if (DwarfVersion >= 5)
85+
return FileNames[Index];
86+
return FileNames[Index - 1];
87+
}
88+
6989
void DWARFDebugLine::Prologue::clear() {
7090
TotalLength = PrologueLength = 0;
7191
SegSelectorSize = 0;
@@ -968,30 +988,11 @@ bool DWARFDebugLine::LineTable::lookupAddressRangeImpl(
968988
return true;
969989
}
970990

971-
bool DWARFDebugLine::LineTable::hasFileAtIndex(uint64_t FileIndex) const {
972-
uint16_t DwarfVersion = Prologue.getVersion();
973-
assert(DwarfVersion != 0 && "LineTable has no dwarf version information");
974-
if (DwarfVersion >= 5)
975-
return FileIndex < Prologue.FileNames.size();
976-
return FileIndex != 0 && FileIndex <= Prologue.FileNames.size();
977-
}
978-
979-
const llvm::DWARFDebugLine::FileNameEntry &
980-
DWARFDebugLine::LineTable::getFileNameEntry(uint64_t Index) const {
981-
uint16_t DwarfVersion = Prologue.getVersion();
982-
assert(DwarfVersion != 0 && "LineTable has no dwarf version information");
983-
// In DWARF v5 the file names are 0-indexed.
984-
if (DwarfVersion >= 5)
985-
return Prologue.FileNames[Index];
986-
else
987-
return Prologue.FileNames[Index - 1];
988-
}
989-
990991
Optional<StringRef> DWARFDebugLine::LineTable::getSourceByIndex(uint64_t FileIndex,
991992
FileLineInfoKind Kind) const {
992-
if (Kind == FileLineInfoKind::None || !hasFileAtIndex(FileIndex))
993+
if (Kind == FileLineInfoKind::None || !Prologue.hasFileAtIndex(FileIndex))
993994
return None;
994-
const FileNameEntry &Entry = getFileNameEntry(FileIndex);
995+
const FileNameEntry &Entry = Prologue.getFileNameEntry(FileIndex);
995996
if (Optional<const char *> source = Entry.Source.getAsCString())
996997
return StringRef(*source);
997998
return None;
@@ -1005,10 +1006,10 @@ static bool isPathAbsoluteOnWindowsOrPosix(const Twine &Path) {
10051006
sys::path::is_absolute(Path, sys::path::Style::windows);
10061007
}
10071008

1008-
bool DWARFDebugLine::LineTable::getFileNameByIndex(uint64_t FileIndex,
1009-
const char *CompDir,
1010-
FileLineInfoKind Kind,
1011-
std::string &Result) const {
1009+
bool DWARFDebugLine::Prologue::getFileNameByIndex(uint64_t FileIndex,
1010+
StringRef CompDir,
1011+
FileLineInfoKind Kind,
1012+
std::string &Result) const {
10121013
if (Kind == FileLineInfoKind::None || !hasFileAtIndex(FileIndex))
10131014
return false;
10141015
const FileNameEntry &Entry = getFileNameEntry(FileIndex);
@@ -1022,20 +1023,18 @@ bool DWARFDebugLine::LineTable::getFileNameByIndex(uint64_t FileIndex,
10221023
SmallString<16> FilePath;
10231024
StringRef IncludeDir;
10241025
// Be defensive about the contents of Entry.
1025-
if (Prologue.getVersion() >= 5) {
1026-
if (Entry.DirIdx < Prologue.IncludeDirectories.size())
1027-
IncludeDir =
1028-
Prologue.IncludeDirectories[Entry.DirIdx].getAsCString().getValue();
1026+
if (getVersion() >= 5) {
1027+
if (Entry.DirIdx < IncludeDirectories.size())
1028+
IncludeDir = IncludeDirectories[Entry.DirIdx].getAsCString().getValue();
10291029
} else {
1030-
if (0 < Entry.DirIdx && Entry.DirIdx <= Prologue.IncludeDirectories.size())
1031-
IncludeDir = Prologue.IncludeDirectories[Entry.DirIdx - 1]
1032-
.getAsCString()
1033-
.getValue();
1030+
if (0 < Entry.DirIdx && Entry.DirIdx <= IncludeDirectories.size())
1031+
IncludeDir =
1032+
IncludeDirectories[Entry.DirIdx - 1].getAsCString().getValue();
10341033

10351034
// We may still need to append compilation directory of compile unit.
10361035
// We know that FileName is not absolute, the only way to have an
10371036
// absolute path at this point would be if IncludeDir is absolute.
1038-
if (CompDir && !isPathAbsoluteOnWindowsOrPosix(IncludeDir))
1037+
if (!CompDir.empty() && !isPathAbsoluteOnWindowsOrPosix(IncludeDir))
10391038
sys::path::append(FilePath, CompDir);
10401039
}
10411040

0 commit comments

Comments
 (0)