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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@162895 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Alexey Samsonov
2012-08-30 07:49:50 +00:00
parent 6b1e1d8b3d
commit 38a6381c0a
4 changed files with 127 additions and 63 deletions

View File

@ -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;
}