aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/DebugInfo/DWARFDebugLine.cpp
diff options
context:
space:
mode:
authorFrederic Riss <friss@apple.com>2014-09-19 15:11:51 +0000
committerFrederic Riss <friss@apple.com>2014-09-19 15:11:51 +0000
commit101b5e205355bfeb0c7733c751ec3d7e5637cf9e (patch)
tree7cd665c90c5335ef8470b2252ae85dbecaafb3af /llvm/lib/DebugInfo/DWARFDebugLine.cpp
parenta5d07482d929c7a3ccf943c429d387a2369322b1 (diff)
downloadllvm-101b5e205355bfeb0c7733c751ec3d7e5637cf9e.zip
llvm-101b5e205355bfeb0c7733c751ec3d7e5637cf9e.tar.gz
llvm-101b5e205355bfeb0c7733c751ec3d7e5637cf9e.tar.bz2
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
Diffstat (limited to 'llvm/lib/DebugInfo/DWARFDebugLine.cpp')
-rw-r--r--llvm/lib/DebugInfo/DWARFDebugLine.cpp38
1 files changed, 33 insertions, 5 deletions
diff --git a/llvm/lib/DebugInfo/DWARFDebugLine.cpp b/llvm/lib/DebugInfo/DWARFDebugLine.cpp
index ce87635..a6ee461 100644
--- a/llvm/lib/DebugInfo/DWARFDebugLine.cpp
+++ b/llvm/lib/DebugInfo/DWARFDebugLine.cpp
@@ -644,6 +644,7 @@ bool DWARFDebugLine::LineTable::lookupAddressRange(
bool
DWARFDebugLine::LineTable::getFileNameByIndex(uint64_t FileIndex,
+ const char *CompDir,
FileLineInfoKind Kind,
std::string &Result) const {
if (FileIndex == 0 || FileIndex > Prologue.FileNames.size() ||
@@ -656,15 +657,42 @@ DWARFDebugLine::LineTable::getFileNameByIndex(uint64_t FileIndex,
Result = FileName;
return true;
}
+
SmallString<16> FilePath;
uint64_t IncludeDirIndex = Entry.DirIdx;
+ const char *IncludeDir = "";
// Be defensive about the contents of Entry.
if (IncludeDirIndex > 0 &&
- IncludeDirIndex <= Prologue.IncludeDirectories.size()) {
- const char *IncludeDir = Prologue.IncludeDirectories[IncludeDirIndex - 1];
- sys::path::append(FilePath, IncludeDir);
- }
- sys::path::append(FilePath, FileName);
+ IncludeDirIndex <= Prologue.IncludeDirectories.size())
+ IncludeDir = Prologue.IncludeDirectories[IncludeDirIndex - 1];
+
+ // 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 && 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();
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;
+}