diff options
author | Alexey Samsonov <samsonov@google.com> | 2012-07-19 07:03:58 +0000 |
---|---|---|
committer | Alexey Samsonov <samsonov@google.com> | 2012-07-19 07:03:58 +0000 |
commit | 71d94f805514f28730bf39143ee227648d521d09 (patch) | |
tree | 2c1f82b94b4c75f9736128b9734872d03a9ec0fc /lib/DebugInfo/DWARFContext.cpp | |
parent | 72ea0c9ffaa1700730c8ce36e9b73aef4b914988 (diff) | |
download | external_llvm-71d94f805514f28730bf39143ee227648d521d09.zip external_llvm-71d94f805514f28730bf39143ee227648d521d09.tar.gz external_llvm-71d94f805514f28730bf39143ee227648d521d09.tar.bz2 |
DebugInfo library: add support for fetching absolute paths to source files
(instead of basenames) from DWARF. Use this behavior in llvm-dwarfdump tool.
Reviewed by Benjamin Kramer.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@160496 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/DebugInfo/DWARFContext.cpp')
-rw-r--r-- | lib/DebugInfo/DWARFContext.cpp | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/lib/DebugInfo/DWARFContext.cpp b/lib/DebugInfo/DWARFContext.cpp index 08e5db2..a4e0d8e 100644 --- a/lib/DebugInfo/DWARFContext.cpp +++ b/lib/DebugInfo/DWARFContext.cpp @@ -8,8 +8,10 @@ //===----------------------------------------------------------------------===// #include "DWARFContext.h" +#include "llvm/ADT/SmallString.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; @@ -148,8 +150,8 @@ DILineInfo DWARFContext::getLineInfoForAddress(uint64_t address, DWARFCompileUnit *cu = getCompileUnitForOffset(cuOffset); if (!cu) return DILineInfo(); - const char *fileName = "<invalid>"; - const char *functionName = "<invalid>"; + SmallString<16> fileName("<invalid>"); + SmallString<16> functionName("<invalid>"); uint32_t line = 0; uint32_t column = 0; if (specifier.needs(DILineInfoSpecifier::FunctionName)) { @@ -171,7 +173,29 @@ DILineInfo DWARFContext::getLineInfoForAddress(uint64_t address, if (rowIndex != -1U) { const DWARFDebugLine::Row &row = lineTable->Rows[rowIndex]; // Take file/line info from the line table. - fileName = lineTable->Prologue.FileNames[row.File - 1].Name.c_str(); + const DWARFDebugLine::FileNameEntry &fileNameEntry = + lineTable->Prologue.FileNames[row.File - 1]; + fileName = fileNameEntry.Name; + if (specifier.needs(DILineInfoSpecifier::AbsoluteFilePath) && + sys::path::is_relative(fileName.str())) { + // Append include directory of file (if it is present in line table) + // and compilation directory of compile unit to make path absolute. + const char *includeDir = 0; + if (uint64_t includeDirIndex = fileNameEntry.DirIdx) { + includeDir = lineTable->Prologue + .IncludeDirectories[includeDirIndex - 1]; + } + SmallString<16> absFileName; + if (includeDir == 0 || sys::path::is_relative(includeDir)) { + if (const char *compilationDir = cu->getCompilationDir()) + sys::path::append(absFileName, compilationDir); + } + if (includeDir) { + sys::path::append(absFileName, includeDir); + } + sys::path::append(absFileName, fileName.str()); + fileName = absFileName; + } line = row.Line; column = row.Column; } |