[llvm-commits] [llvm] r160496 - in /llvm/trunk: include/llvm/DebugInfo/DIContext.h lib/DebugInfo/DWARFCompileUnit.cpp lib/DebugInfo/DWARFCompileUnit.h lib/DebugInfo/DWARFContext.cpp lib/DebugInfo/DWARFDebugLine.h test/DebugInfo/Inputs/dwarfdump-test.elf-x86-64 test/DebugInfo/Inputs/dwarfdump-test2.elf-x86-64 test/DebugInfo/Inputs/dwarfdump-test3.elf-x86-64 test/DebugInfo/dwarfdump-test.test tools/llvm-dwarfdump/llvm-dwarfdump.cpp
Alexey Samsonov
samsonov at google.com
Thu Jul 19 00:03:59 PDT 2012
Author: samsonov
Date: Thu Jul 19 02:03:58 2012
New Revision: 160496
URL: http://llvm.org/viewvc/llvm-project?rev=160496&view=rev
Log:
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.
Modified:
llvm/trunk/include/llvm/DebugInfo/DIContext.h
llvm/trunk/lib/DebugInfo/DWARFCompileUnit.cpp
llvm/trunk/lib/DebugInfo/DWARFCompileUnit.h
llvm/trunk/lib/DebugInfo/DWARFContext.cpp
llvm/trunk/lib/DebugInfo/DWARFDebugLine.h
llvm/trunk/test/DebugInfo/Inputs/dwarfdump-test.elf-x86-64
llvm/trunk/test/DebugInfo/Inputs/dwarfdump-test2.elf-x86-64
llvm/trunk/test/DebugInfo/Inputs/dwarfdump-test3.elf-x86-64
llvm/trunk/test/DebugInfo/dwarfdump-test.test
llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
Modified: llvm/trunk/include/llvm/DebugInfo/DIContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DIContext.h?rev=160496&r1=160495&r2=160496&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/DIContext.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/DIContext.h Thu Jul 19 02:03:58 2012
@@ -15,9 +15,9 @@
#ifndef LLVM_DEBUGINFO_DICONTEXT_H
#define LLVM_DEBUGINFO_DICONTEXT_H
+#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/DataTypes.h"
-#include <cstring>
namespace llvm {
@@ -25,28 +25,29 @@
/// DILineInfo - a format-neutral container for source line information.
class DILineInfo {
- const char *FileName;
- const char *FunctionName;
+ SmallString<16> FileName;
+ SmallString<16> FunctionName;
uint32_t Line;
uint32_t Column;
public:
DILineInfo()
: FileName("<invalid>"), FunctionName("<invalid>"),
Line(0), Column(0) {}
- DILineInfo(const char *fileName, const char *functionName,
+ DILineInfo(const SmallString<16> &fileName,
+ const SmallString<16> &functionName,
uint32_t line, uint32_t column)
: FileName(fileName), FunctionName(functionName),
Line(line), Column(column) {}
- const char *getFileName() const { return FileName; }
- const char *getFunctionName() const { return FunctionName; }
+ const char *getFileName() { return FileName.c_str(); }
+ const char *getFunctionName() { return FunctionName.c_str(); }
uint32_t getLine() const { return Line; }
uint32_t getColumn() const { return Column; }
bool operator==(const DILineInfo &RHS) const {
return Line == RHS.Line && Column == RHS.Column &&
- std::strcmp(FileName, RHS.FileName) == 0 &&
- std::strcmp(FunctionName, RHS.FunctionName) == 0;
+ FileName.equals(RHS.FileName) &&
+ FunctionName.equals(RHS.FunctionName);
}
bool operator!=(const DILineInfo &RHS) const {
return !(*this == RHS);
@@ -60,7 +61,8 @@
public:
enum Specification {
FileLineInfo = 1 << 0,
- FunctionName = 1 << 1
+ AbsoluteFilePath = 1 << 1,
+ FunctionName = 1 << 2
};
// Use file/line info by default.
DILineInfoSpecifier(uint32_t flags = FileLineInfo) : Flags(flags) {}
Modified: llvm/trunk/lib/DebugInfo/DWARFCompileUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARFCompileUnit.cpp?rev=160496&r1=160495&r2=160496&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARFCompileUnit.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARFCompileUnit.cpp Thu Jul 19 02:03:58 2012
@@ -97,6 +97,13 @@
getCompileUnitDIE(false)->dump(OS, this, -1U);
}
+const char *DWARFCompileUnit::getCompilationDir() {
+ extractDIEsIfNeeded(true);
+ if (DieArray.empty())
+ return 0;
+ return DieArray[0].getAttributeValueAsString(this, DW_AT_comp_dir, 0);
+}
+
void DWARFCompileUnit::setDIERelations() {
if (DieArray.empty())
return;
Modified: llvm/trunk/lib/DebugInfo/DWARFCompileUnit.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARFCompileUnit.h?rev=160496&r1=160495&r2=160496&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARFCompileUnit.h (original)
+++ llvm/trunk/lib/DebugInfo/DWARFCompileUnit.h Thu Jul 19 02:03:58 2012
@@ -78,6 +78,8 @@
return &DieArray[0];
}
+ const char *getCompilationDir();
+
/// setDIERelations - We read in all of the DIE entries into our flat list
/// of DIE entries and now we need to go back through all of them and set the
/// parent, sibling and child pointers for quick DIE navigation.
Modified: llvm/trunk/lib/DebugInfo/DWARFContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARFContext.cpp?rev=160496&r1=160495&r2=160496&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARFContext.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARFContext.cpp Thu Jul 19 02:03:58 2012
@@ -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 @@
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 @@
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;
}
Modified: llvm/trunk/lib/DebugInfo/DWARFDebugLine.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARFDebugLine.h?rev=160496&r1=160495&r2=160496&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARFDebugLine.h (original)
+++ llvm/trunk/lib/DebugInfo/DWARFDebugLine.h Thu Jul 19 02:03:58 2012
@@ -12,7 +12,6 @@
#include "llvm/Support/DataExtractor.h"
#include <map>
-#include <string>
#include <vector>
namespace llvm {
@@ -22,9 +21,9 @@
class DWARFDebugLine {
public:
struct FileNameEntry {
- FileNameEntry() : DirIdx(0), ModTime(0), Length(0) {}
+ FileNameEntry() : Name(0), DirIdx(0), ModTime(0), Length(0) {}
- std::string Name;
+ const char *Name;
uint64_t DirIdx;
uint64_t ModTime;
uint64_t Length;
@@ -56,7 +55,7 @@
// The number assigned to the first special opcode.
uint8_t OpcodeBase;
std::vector<uint8_t> StandardOpcodeLengths;
- std::vector<std::string> IncludeDirectories;
+ std::vector<const char*> IncludeDirectories;
std::vector<FileNameEntry> FileNames;
// Length of the prologue in bytes.
Modified: llvm/trunk/test/DebugInfo/Inputs/dwarfdump-test.elf-x86-64
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/Inputs/dwarfdump-test.elf-x86-64?rev=160496&r1=160495&r2=160496&view=diff
==============================================================================
Binary files - no diff available.
Modified: llvm/trunk/test/DebugInfo/Inputs/dwarfdump-test2.elf-x86-64
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/Inputs/dwarfdump-test2.elf-x86-64?rev=160496&r1=160495&r2=160496&view=diff
==============================================================================
Binary files - no diff available.
Modified: llvm/trunk/test/DebugInfo/Inputs/dwarfdump-test3.elf-x86-64
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/Inputs/dwarfdump-test3.elf-x86-64?rev=160496&r1=160495&r2=160496&view=diff
==============================================================================
Binary files - no diff available.
Modified: llvm/trunk/test/DebugInfo/dwarfdump-test.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/dwarfdump-test.test?rev=160496&r1=160495&r2=160496&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/dwarfdump-test.test (original)
+++ llvm/trunk/test/DebugInfo/dwarfdump-test.test Thu Jul 19 02:03:58 2012
@@ -9,22 +9,32 @@
RUN: llvm-dwarfdump %p/Inputs/dwarfdump-test2.elf-x86-64 \
RUN: --address=0x4004c4 --functions | FileCheck %s -check-prefix MANY_CU_2
RUN: llvm-dwarfdump %p/Inputs/dwarfdump-test3.elf-x86-64 \
-RUN: --address=0x538 --functions | FileCheck %s -check-prefix ABS_ORIGIN_1
+RUN: --address=0x580 --functions | FileCheck %s -check-prefix ABS_ORIGIN_1
+RUN: llvm-dwarfdump %p/Inputs/dwarfdump-test3.elf-x86-64 \
+RUN: --address=0x573 --functions | FileCheck %s -check-prefix INCLUDE_TEST_1
+RUN: llvm-dwarfdump %p/Inputs/dwarfdump-test3.elf-x86-64 \
+RUN: --address=0x56d --functions | FileCheck %s -check-prefix INCLUDE_TEST_2
MAIN: main
-MAIN-NEXT: dwarfdump-test.cc:16:10
+MAIN-NEXT: /tmp/dbginfo/dwarfdump-test.cc:16:10
FUNCTION: _Z1fii
-FUNCTION-NEXT: dwarfdump-test.cc:11:18
+FUNCTION-NEXT: /tmp/dbginfo/dwarfdump-test.cc:11:18
CTOR_WITH_SPEC: _ZN10DummyClassC1Ei
-CTOR_WITH_SPEC-NEXT: dwarfdump-test.cc:4:30
+CTOR_WITH_SPEC-NEXT: /tmp/dbginfo/dwarfdump-test.cc:4:30
MANY_CU_1: a
-MANY_CU_1-NEXT: a.cc:2:0
+MANY_CU_1-NEXT: /tmp/dbginfo/a.cc:2:0
MANY_CU_2: main
-MANY_CU_2-NEXT: main.cc:4:0
+MANY_CU_2-NEXT: /tmp/dbginfo/main.cc:4:0
ABS_ORIGIN_1: C
-ABS_ORIGIN_1-NEXT: def.cc:3:0
+ABS_ORIGIN_1-NEXT: /tmp/dbginfo/def2.cc:4:0
+
+INCLUDE_TEST_1: _Z3do2v
+INCLUDE_TEST_1-NEXT: /tmp/dbginfo/include/decl2.h:1:0
+
+INCLUDE_TEST_2: _Z3do1v
+INCLUDE_TEST_2-NEXT: /tmp/include/decl.h:5:0
Modified: llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp?rev=160496&r1=160495&r2=160496&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp (original)
+++ llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp Thu Jul 19 02:03:58 2012
@@ -97,7 +97,8 @@
dictx->dump(outs());
} else {
// Print line info for the specified address.
- int spec_flags = DILineInfoSpecifier::FileLineInfo;
+ int spec_flags = DILineInfoSpecifier::FileLineInfo |
+ DILineInfoSpecifier::AbsoluteFilePath;
if (PrintFunctions)
spec_flags |= DILineInfoSpecifier::FunctionName;
DILineInfo dli = dictx->getLineInfoForAddress(Address, spec_flags);
More information about the llvm-commits
mailing list