aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/DebugInfo/DWARFDebugLine.cpp
diff options
context:
space:
mode:
authorAlexey Samsonov <samsonov@google.com>2012-08-30 07:49:50 +0000
committerAlexey Samsonov <samsonov@google.com>2012-08-30 07:49:50 +0000
commit45be793e3ad08129a38db307b3110e3a57149e40 (patch)
treea43353324273838648f619cc7028d2828998e785 /llvm/lib/DebugInfo/DWARFDebugLine.cpp
parent2da13f9ef8d49bfaca065bd78ff1f2e139c2422f (diff)
downloadllvm-45be793e3ad08129a38db307b3110e3a57149e40.zip
llvm-45be793e3ad08129a38db307b3110e3a57149e40.tar.gz
llvm-45be793e3ad08129a38db307b3110e3a57149e40.tar.bz2
Refactor fetching file/line info from DWARFContext to simplify the
code and allow better code reuse. Make the code a bit more conforming to LLVM code style. No functionality change. llvm-svn: 162895
Diffstat (limited to 'llvm/lib/DebugInfo/DWARFDebugLine.cpp')
-rw-r--r--llvm/lib/DebugInfo/DWARFDebugLine.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/llvm/lib/DebugInfo/DWARFDebugLine.cpp b/llvm/lib/DebugInfo/DWARFDebugLine.cpp
index d99575d..267364a 100644
--- a/llvm/lib/DebugInfo/DWARFDebugLine.cpp
+++ b/llvm/lib/DebugInfo/DWARFDebugLine.cpp
@@ -10,6 +10,7 @@
#include "DWARFDebugLine.h"
#include "llvm/Support/Dwarf.h"
#include "llvm/Support/Format.h"
+#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
using namespace llvm;
@@ -513,3 +514,29 @@ DWARFDebugLine::LineTable::lookupAddress(uint64_t address) const {
}
return index;
}
+
+bool
+DWARFDebugLine::LineTable::getFileNameByIndex(uint64_t FileIndex,
+ bool NeedsAbsoluteFilePath,
+ std::string &Result) const {
+ if (FileIndex == 0 || FileIndex > Prologue.FileNames.size())
+ return false;
+ const FileNameEntry &Entry = Prologue.FileNames[FileIndex - 1];
+ const char *FileName = Entry.Name;
+ if (!NeedsAbsoluteFilePath ||
+ sys::path::is_absolute(FileName)) {
+ Result = FileName;
+ return true;
+ }
+ SmallString<16> FilePath;
+ uint64_t IncludeDirIndex = Entry.DirIdx;
+ // 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);
+ Result = FilePath.str();
+ return true;
+}