1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 19:12:56 +02:00

Turn local DWARFContext helpers getFileNameForUnit() and getFileLineInfoForCompileUnit() into full-blowm DWARFDebugLine::LineTable methods.

Summary:
getFileNameForUnit() is basically a wrapper around LineTable::getFileNameByIndex().
Fold its additional functionality (adding the DWARFUnit compilation dir) into
LineTable::getFileNameByIndex().

getFileLineInfoForCompileUnit() is a wrapper around getFileNameForUnit(). As
a function to search the line information by address, it seems natural to put
it in the LineTable also.

Before this commit only the Context with its private helpers could do Linetable
lookups. This newly exposed feature will be used by the DIE dumping code to
get access to file information referenced in DIE attributes.

This commit has already been partly reviewed in D5192 and contained an
additional and a bit controversial 'realpath' call that is left out of this
patch. We can reinstate that realpath code later if it is desirable.

Test Plan:
The patch contains no tests as it should be functionally equivalent to the
previous code. As requested in the last review, I checked if the relative
path handling copied from the Context to LineTable::getFileNameByIndex()
was covered, and indeed the symbolizer tests fail if it is removed.

Reviewers: dblaikie, echristo, aprantl, samsonov

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D5354

llvm-svn: 218125
This commit is contained in:
Frederic Riss 2014-09-19 15:11:51 +00:00
parent eb485df97e
commit 166468a68e
3 changed files with 54 additions and 58 deletions

View File

@ -401,47 +401,6 @@ DWARFCompileUnit *DWARFContext::getCompileUnitForAddress(uint64_t Address) {
return getCompileUnitForOffset(CUOffset); return getCompileUnitForOffset(CUOffset);
} }
static bool getFileNameForUnit(DWARFCompileUnit *U,
const DWARFLineTable *LineTable,
uint64_t FileIndex, FileLineInfoKind Kind,
std::string &FileName) {
if (!U || !LineTable || Kind == FileLineInfoKind::None ||
!LineTable->getFileNameByIndex(FileIndex, Kind, FileName))
return false;
if (Kind == FileLineInfoKind::AbsoluteFilePath &&
sys::path::is_relative(FileName)) {
// We may still need to append compilation directory of compile unit.
SmallString<16> AbsolutePath;
if (const char *CompilationDir = U->getCompilationDir()) {
sys::path::append(AbsolutePath, CompilationDir);
}
sys::path::append(AbsolutePath, FileName);
FileName = AbsolutePath.str();
}
return true;
}
static bool getFileLineInfoForCompileUnit(DWARFCompileUnit *CU,
const DWARFLineTable *LineTable,
uint64_t Address,
FileLineInfoKind Kind,
DILineInfo &Result) {
if (!CU || !LineTable)
return false;
// Get the index of row we're looking for in the line table.
uint32_t RowIndex = LineTable->lookupAddress(Address);
if (RowIndex == -1U)
return false;
// Take file number and line/column from the row.
const DWARFDebugLine::Row &Row = LineTable->Rows[RowIndex];
if (!getFileNameForUnit(CU, LineTable, Row.File, Kind,
Result.FileName))
return false;
Result.Line = Row.Line;
Result.Column = Row.Column;
return true;
}
static bool getFunctionNameForAddress(DWARFCompileUnit *CU, uint64_t Address, static bool getFunctionNameForAddress(DWARFCompileUnit *CU, uint64_t Address,
FunctionNameKind Kind, FunctionNameKind Kind,
std::string &FunctionName) { std::string &FunctionName) {
@ -472,8 +431,9 @@ DILineInfo DWARFContext::getLineInfoForAddress(uint64_t Address,
return Result; return Result;
getFunctionNameForAddress(CU, Address, Spec.FNKind, Result.FunctionName); getFunctionNameForAddress(CU, Address, Spec.FNKind, Result.FunctionName);
if (Spec.FLIKind != FileLineInfoKind::None) { if (Spec.FLIKind != FileLineInfoKind::None) {
const DWARFLineTable *LineTable = getLineTableForUnit(CU); if (const DWARFLineTable *LineTable = getLineTableForUnit(CU))
getFileLineInfoForCompileUnit(CU, LineTable, Address, Spec.FLIKind, Result); LineTable->getFileLineInfoForAddress(Address, CU->getCompilationDir(),
Spec.FLIKind, Result);
} }
return Result; return Result;
} }
@ -509,8 +469,8 @@ DWARFContext::getLineInfoForAddressRange(uint64_t Address, uint64_t Size,
// Take file number and line/column from the row. // Take file number and line/column from the row.
const DWARFDebugLine::Row &Row = LineTable->Rows[RowIndex]; const DWARFDebugLine::Row &Row = LineTable->Rows[RowIndex];
DILineInfo Result; DILineInfo Result;
getFileNameForUnit(CU, LineTable, Row.File, Spec.FLIKind, LineTable->getFileNameByIndex(Row.File, CU->getCompilationDir(),
Result.FileName); Spec.FLIKind, Result.FileName);
Result.FunctionName = FunctionName; Result.FunctionName = FunctionName;
Result.Line = Row.Line; Result.Line = Row.Line;
Result.Column = Row.Column; Result.Column = Row.Column;
@ -538,10 +498,10 @@ DWARFContext::getInliningInfoForAddress(uint64_t Address,
if (Spec.FLIKind != FileLineInfoKind::None) { if (Spec.FLIKind != FileLineInfoKind::None) {
DILineInfo Frame; DILineInfo Frame;
LineTable = getLineTableForUnit(CU); LineTable = getLineTableForUnit(CU);
if (getFileLineInfoForCompileUnit(CU, LineTable, Address, Spec.FLIKind, if (LineTable &&
Frame)) { LineTable->getFileLineInfoForAddress(Address, CU->getCompilationDir(),
Spec.FLIKind, Frame))
InliningInfo.addFrame(Frame); InliningInfo.addFrame(Frame);
}
} }
return InliningInfo; return InliningInfo;
} }
@ -560,13 +520,15 @@ DWARFContext::getInliningInfoForAddress(uint64_t Address,
// compile unit and fetch file/line info from it. // compile unit and fetch file/line info from it.
LineTable = getLineTableForUnit(CU); LineTable = getLineTableForUnit(CU);
// For the topmost routine, get file/line info from line table. // For the topmost routine, get file/line info from line table.
getFileLineInfoForCompileUnit(CU, LineTable, Address, Spec.FLIKind, if (LineTable)
Frame); LineTable->getFileLineInfoForAddress(Address, CU->getCompilationDir(),
Spec.FLIKind, Frame);
} else { } else {
// Otherwise, use call file, call line and call column from // Otherwise, use call file, call line and call column from
// previous DIE in inlined chain. // previous DIE in inlined chain.
getFileNameForUnit(CU, LineTable, CallFile, Spec.FLIKind, if (LineTable)
Frame.FileName); LineTable->getFileNameByIndex(CallFile, CU->getCompilationDir(),
Spec.FLIKind, Frame.FileName);
Frame.Line = CallLine; Frame.Line = CallLine;
Frame.Column = CallColumn; Frame.Column = CallColumn;
} }

View File

@ -644,6 +644,7 @@ bool DWARFDebugLine::LineTable::lookupAddressRange(
bool bool
DWARFDebugLine::LineTable::getFileNameByIndex(uint64_t FileIndex, DWARFDebugLine::LineTable::getFileNameByIndex(uint64_t FileIndex,
const char *CompDir,
FileLineInfoKind Kind, FileLineInfoKind Kind,
std::string &Result) const { std::string &Result) const {
if (FileIndex == 0 || FileIndex > Prologue.FileNames.size() || if (FileIndex == 0 || FileIndex > Prologue.FileNames.size() ||
@ -656,15 +657,42 @@ DWARFDebugLine::LineTable::getFileNameByIndex(uint64_t FileIndex,
Result = FileName; Result = FileName;
return true; return true;
} }
SmallString<16> FilePath; SmallString<16> FilePath;
uint64_t IncludeDirIndex = Entry.DirIdx; uint64_t IncludeDirIndex = Entry.DirIdx;
const char *IncludeDir = "";
// Be defensive about the contents of Entry. // Be defensive about the contents of Entry.
if (IncludeDirIndex > 0 && if (IncludeDirIndex > 0 &&
IncludeDirIndex <= Prologue.IncludeDirectories.size()) { IncludeDirIndex <= Prologue.IncludeDirectories.size())
const char *IncludeDir = Prologue.IncludeDirectories[IncludeDirIndex - 1]; IncludeDir = Prologue.IncludeDirectories[IncludeDirIndex - 1];
sys::path::append(FilePath, IncludeDir);
} // We may still need to append compilation directory of compile unit.
sys::path::append(FilePath, FileName); // 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 && Kind == FileLineInfoKind::AbsoluteFilePath &&
sys::path::is_relative(IncludeDir))
sys::path::append(FilePath, CompDir);
// sys::path::append skips empty strings.
sys::path::append(FilePath, IncludeDir, FileName);
Result = FilePath.str(); Result = FilePath.str();
return true; return true;
} }
bool
DWARFDebugLine::LineTable::getFileLineInfoForAddress(uint64_t Address,
const char *CompDir,
FileLineInfoKind Kind,
DILineInfo &Result) const {
// Get the index of row we're looking for in the line table.
uint32_t RowIndex = lookupAddress(Address);
if (RowIndex == -1U)
return false;
// Take file number and line/column from the row.
const auto &Row = Rows[RowIndex];
if (!getFileNameByIndex(Row.File, CompDir, Kind, Result.FileName))
return false;
Result.Line = Row.Line;
Result.Column = Row.Column;
return true;
}

View File

@ -179,10 +179,16 @@ public:
// Extracts filename by its index in filename table in prologue. // Extracts filename by its index in filename table in prologue.
// Returns true on success. // Returns true on success.
bool getFileNameByIndex(uint64_t FileIndex, bool getFileNameByIndex(uint64_t FileIndex, const char *CompDir,
DILineInfoSpecifier::FileLineInfoKind Kind, DILineInfoSpecifier::FileLineInfoKind Kind,
std::string &Result) const; std::string &Result) const;
// Fills the Result argument with the file and line information
// corresponding to Address. Returns true on success.
bool getFileLineInfoForAddress(uint64_t Address, const char *CompDir,
DILineInfoSpecifier::FileLineInfoKind Kind,
DILineInfo &Result) const;
void dump(raw_ostream &OS) const; void dump(raw_ostream &OS) const;
void clear(); void clear();