llvm.org GIT mirror llvm / 71d94f8
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 Alexey Samsonov 7 years ago
10 changed file(s) with 69 addition(s) and 24 deletion(s). Raw diff Collapse all Expand all
1414 #ifndef LLVM_DEBUGINFO_DICONTEXT_H
1515 #define LLVM_DEBUGINFO_DICONTEXT_H
1616
17 #include "llvm/ADT/SmallString.h"
1718 #include "llvm/ADT/StringRef.h"
1819 #include "llvm/Support/DataTypes.h"
19 #include
2020
2121 namespace llvm {
2222
2424
2525 /// DILineInfo - a format-neutral container for source line information.
2626 class DILineInfo {
27 const char *FileName;
28 const char *FunctionName;
27 SmallString<16> FileName;
28 SmallString<16> FunctionName;
2929 uint32_t Line;
3030 uint32_t Column;
3131 public:
3232 DILineInfo()
3333 : FileName(""), FunctionName(""),
3434 Line(0), Column(0) {}
35 DILineInfo(const char *fileName, const char *functionName,
35 DILineInfo(const SmallString<16> &fileName,
36 const SmallString<16> &functionName,
3637 uint32_t line, uint32_t column)
3738 : FileName(fileName), FunctionName(functionName),
3839 Line(line), Column(column) {}
3940
40 const char *getFileName() const { return FileName; }
41 const char *getFunctionName() const { return FunctionName; }
41 const char *getFileName() { return FileName.c_str(); }
42 const char *getFunctionName() { return FunctionName.c_str(); }
4243 uint32_t getLine() const { return Line; }
4344 uint32_t getColumn() const { return Column; }
4445
4546 bool operator==(const DILineInfo &RHS) const {
4647 return Line == RHS.Line && Column == RHS.Column &&
47 std::strcmp(FileName, RHS.FileName) == 0 &&
48 std::strcmp(FunctionName, RHS.FunctionName) == 0;
48 FileName.equals(RHS.FileName) &&
49 FunctionName.equals(RHS.FunctionName);
4950 }
5051 bool operator!=(const DILineInfo &RHS) const {
5152 return !(*this == RHS);
5960 public:
6061 enum Specification {
6162 FileLineInfo = 1 << 0,
62 FunctionName = 1 << 1
63 AbsoluteFilePath = 1 << 1,
64 FunctionName = 1 << 2
6365 };
6466 // Use file/line info by default.
6567 DILineInfoSpecifier(uint32_t flags = FileLineInfo) : Flags(flags) {}
9494 << ")\n";
9595
9696 getCompileUnitDIE(false)->dump(OS, this, -1U);
97 }
98
99 const char *DWARFCompileUnit::getCompilationDir() {
100 extractDIEsIfNeeded(true);
101 if (DieArray.empty())
102 return 0;
103 return DieArray[0].getAttributeValueAsString(this, DW_AT_comp_dir, 0);
97104 }
98105
99106 void DWARFCompileUnit::setDIERelations() {
7777 return &DieArray[0];
7878 }
7979
80 const char *getCompilationDir();
81
8082 /// setDIERelations - We read in all of the DIE entries into our flat list
8183 /// of DIE entries and now we need to go back through all of them and set the
8284 /// parent, sibling and child pointers for quick DIE navigation.
77 //===----------------------------------------------------------------------===//
88
99 #include "DWARFContext.h"
10 #include "llvm/ADT/SmallString.h"
1011 #include "llvm/Support/Dwarf.h"
1112 #include "llvm/Support/Format.h"
13 #include "llvm/Support/Path.h"
1214 #include "llvm/Support/raw_ostream.h"
1315 #include
1416 using namespace llvm;
147149 DWARFCompileUnit *cu = getCompileUnitForOffset(cuOffset);
148150 if (!cu)
149151 return DILineInfo();
150 const char *fileName = "";
151 const char *functionName = "";
152 SmallString<16> fileName("");
153 SmallString<16> functionName("");
152154 uint32_t line = 0;
153155 uint32_t column = 0;
154156 if (specifier.needs(DILineInfoSpecifier::FunctionName)) {
170172 if (rowIndex != -1U) {
171173 const DWARFDebugLine::Row &row = lineTable->Rows[rowIndex];
172174 // Take file/line info from the line table.
173 fileName = lineTable->Prologue.FileNames[row.File - 1].Name.c_str();
175 const DWARFDebugLine::FileNameEntry &fileNameEntry =
176 lineTable->Prologue.FileNames[row.File - 1];
177 fileName = fileNameEntry.Name;
178 if (specifier.needs(DILineInfoSpecifier::AbsoluteFilePath) &&
179 sys::path::is_relative(fileName.str())) {
180 // Append include directory of file (if it is present in line table)
181 // and compilation directory of compile unit to make path absolute.
182 const char *includeDir = 0;
183 if (uint64_t includeDirIndex = fileNameEntry.DirIdx) {
184 includeDir = lineTable->Prologue
185 .IncludeDirectories[includeDirIndex - 1];
186 }
187 SmallString<16> absFileName;
188 if (includeDir == 0 || sys::path::is_relative(includeDir)) {
189 if (const char *compilationDir = cu->getCompilationDir())
190 sys::path::append(absFileName, compilationDir);
191 }
192 if (includeDir) {
193 sys::path::append(absFileName, includeDir);
194 }
195 sys::path::append(absFileName, fileName.str());
196 fileName = absFileName;
197 }
174198 line = row.Line;
175199 column = row.Column;
176200 }
1111
1212 #include "llvm/Support/DataExtractor.h"
1313 #include
14 #include
1514 #include
1615
1716 namespace llvm {
2120 class DWARFDebugLine {
2221 public:
2322 struct FileNameEntry {
24 FileNameEntry() : DirIdx(0), ModTime(0), Length(0) {}
23 FileNameEntry() : Name(0), DirIdx(0), ModTime(0), Length(0) {}
2524
26 std::string Name;
25 const char *Name;
2726 uint64_t DirIdx;
2827 uint64_t ModTime;
2928 uint64_t Length;
5554 // The number assigned to the first special opcode.
5655 uint8_t OpcodeBase;
5756 std::vector StandardOpcodeLengths;
58 std::vector<std::string> IncludeDirectories;
57 std::vector<const char*> IncludeDirectories;
5958 std::vector FileNames;
6059
6160 // Length of the prologue in bytes.
88 RUN: llvm-dwarfdump %p/Inputs/dwarfdump-test2.elf-x86-64 \
99 RUN: --address=0x4004c4 --functions | FileCheck %s -check-prefix MANY_CU_2
1010 RUN: llvm-dwarfdump %p/Inputs/dwarfdump-test3.elf-x86-64 \
11 RUN: --address=0x538 --functions | FileCheck %s -check-prefix ABS_ORIGIN_1
11 RUN: --address=0x580 --functions | FileCheck %s -check-prefix ABS_ORIGIN_1
12 RUN: llvm-dwarfdump %p/Inputs/dwarfdump-test3.elf-x86-64 \
13 RUN: --address=0x573 --functions | FileCheck %s -check-prefix INCLUDE_TEST_1
14 RUN: llvm-dwarfdump %p/Inputs/dwarfdump-test3.elf-x86-64 \
15 RUN: --address=0x56d --functions | FileCheck %s -check-prefix INCLUDE_TEST_2
1216
1317 MAIN: main
14 MAIN-NEXT: dwarfdump-test.cc:16:10
18 MAIN-NEXT: /tmp/dbginfo/dwarfdump-test.cc:16:10
1519
1620 FUNCTION: _Z1fii
17 FUNCTION-NEXT: dwarfdump-test.cc:11:18
21 FUNCTION-NEXT: /tmp/dbginfo/dwarfdump-test.cc:11:18
1822
1923 CTOR_WITH_SPEC: _ZN10DummyClassC1Ei
20 CTOR_WITH_SPEC-NEXT: dwarfdump-test.cc:4:30
24 CTOR_WITH_SPEC-NEXT: /tmp/dbginfo/dwarfdump-test.cc:4:30
2125
2226 MANY_CU_1: a
23 MANY_CU_1-NEXT: a.cc:2:0
27 MANY_CU_1-NEXT: /tmp/dbginfo/a.cc:2:0
2428
2529 MANY_CU_2: main
26 MANY_CU_2-NEXT: main.cc:4:0
30 MANY_CU_2-NEXT: /tmp/dbginfo/main.cc:4:0
2731
2832 ABS_ORIGIN_1: C
29 ABS_ORIGIN_1-NEXT: def.cc:3:0
33 ABS_ORIGIN_1-NEXT: /tmp/dbginfo/def2.cc:4:0
34
35 INCLUDE_TEST_1: _Z3do2v
36 INCLUDE_TEST_1-NEXT: /tmp/dbginfo/include/decl2.h:1:0
37
38 INCLUDE_TEST_2: _Z3do1v
39 INCLUDE_TEST_2-NEXT: /tmp/include/decl.h:5:0
9696 dictx->dump(outs());
9797 } else {
9898 // Print line info for the specified address.
99 int spec_flags = DILineInfoSpecifier::FileLineInfo;
99 int spec_flags = DILineInfoSpecifier::FileLineInfo |
100 DILineInfoSpecifier::AbsoluteFilePath;
100101 if (PrintFunctions)
101102 spec_flags |= DILineInfoSpecifier::FunctionName;
102103 DILineInfo dli = dictx->getLineInfoForAddress(Address, spec_flags);