mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-15 21:24:00 +00:00
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:
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user