[llvm] 69da27c - llvm-symbolizer: Add optional "start file" to match "start line"
David Blaikie via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 8 15:41:10 PDT 2020
Author: David Blaikie
Date: 2020-09-08T15:40:58-07:00
New Revision: 69da27c7496ea373567ce5121e6fe8613846e7a5
URL: https://github.com/llvm/llvm-project/commit/69da27c7496ea373567ce5121e6fe8613846e7a5
DIFF: https://github.com/llvm/llvm-project/commit/69da27c7496ea373567ce5121e6fe8613846e7a5.diff
LOG: llvm-symbolizer: Add optional "start file" to match "start line"
Since a function might have portions of its code coming from multiple
different files, "start line" is ambiguous (it can't just be resolved
relative to the file/line specified). Add start file to disambiguate it.
Added:
Modified:
llvm/include/llvm/DebugInfo/DIContext.h
llvm/include/llvm/DebugInfo/DWARF/DWARFDie.h
llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp
llvm/test/tools/llvm-dwarfdump/X86/lookup.s
llvm/test/tools/llvm-symbolizer/sym-verbose.test
Removed:
################################################################################
diff --git a/llvm/include/llvm/DebugInfo/DIContext.h b/llvm/include/llvm/DebugInfo/DIContext.h
index 661d30d04c94..ae78fe912188 100644
--- a/llvm/include/llvm/DebugInfo/DIContext.h
+++ b/llvm/include/llvm/DebugInfo/DIContext.h
@@ -35,6 +35,7 @@ struct DILineInfo {
static constexpr const char *const Addr2LineBadString = "??";
std::string FileName;
std::string FunctionName;
+ std::string StartFileName;
Optional<StringRef> Source;
uint32_t Line = 0;
uint32_t Column = 0;
@@ -43,12 +44,15 @@ struct DILineInfo {
// DWARF-specific.
uint32_t Discriminator = 0;
- DILineInfo() : FileName(BadString), FunctionName(BadString) {}
+ DILineInfo()
+ : FileName(BadString), FunctionName(BadString), StartFileName(BadString) {
+ }
bool operator==(const DILineInfo &RHS) const {
return Line == RHS.Line && Column == RHS.Column &&
FileName == RHS.FileName && FunctionName == RHS.FunctionName &&
- StartLine == RHS.StartLine && Discriminator == RHS.Discriminator;
+ StartFileName == RHS.StartFileName && StartLine == RHS.StartLine &&
+ Discriminator == RHS.Discriminator;
}
bool operator!=(const DILineInfo &RHS) const {
@@ -56,10 +60,10 @@ struct DILineInfo {
}
bool operator<(const DILineInfo &RHS) const {
- return std::tie(FileName, FunctionName, Line, Column, StartLine,
- Discriminator) <
- std::tie(RHS.FileName, RHS.FunctionName, RHS.Line, RHS.Column,
- RHS.StartLine, RHS.Discriminator);
+ return std::tie(FileName, FunctionName, StartFileName, Line, Column,
+ StartLine, Discriminator) <
+ std::tie(RHS.FileName, RHS.FunctionName, RHS.StartFileName, RHS.Line,
+ RHS.Column, RHS.StartLine, RHS.Discriminator);
}
explicit operator bool() const { return *this != DILineInfo(); }
@@ -72,6 +76,8 @@ struct DILineInfo {
OS << "function '" << FunctionName << "', ";
OS << "line " << Line << ", ";
OS << "column " << Column << ", ";
+ if (StartFileName != BadString)
+ OS << "start file '" << StartFileName << "', ";
OS << "start line " << StartLine << '\n';
}
};
diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFDie.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFDie.h
index 05a6056e8e21..5789421e5304 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFDie.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFDie.h
@@ -262,6 +262,7 @@ class DWARFDie {
/// for this subprogram by resolving DW_AT_sepcification or
/// DW_AT_abstract_origin references if necessary.
uint64_t getDeclLine() const;
+ std::string getDeclFile(DILineInfoSpecifier::FileLineInfoKind Kind) const;
/// Retrieves values of DW_AT_call_file, DW_AT_call_line and DW_AT_call_column
/// from DIE (or zeroes if they are missing). This function looks for
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
index d31c35879821..47eba48c279d 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
@@ -1036,7 +1036,9 @@ DWARFContext::DIEsForAddress DWARFContext::getDIEsForAddress(uint64_t Address) {
static bool getFunctionNameAndStartLineForAddress(DWARFCompileUnit *CU,
uint64_t Address,
FunctionNameKind Kind,
+ DILineInfoSpecifier::FileLineInfoKind FileNameKind,
std::string &FunctionName,
+ std::string &StartFile,
uint32_t &StartLine) {
// The address may correspond to instruction in some inlined function,
// so we have to build the chain of inlined functions and take the
@@ -1053,6 +1055,11 @@ static bool getFunctionNameAndStartLineForAddress(DWARFCompileUnit *CU,
FunctionName = Name;
FoundResult = true;
}
+ std::string DeclFile = DIE.getDeclFile(FileNameKind);
+ if (!DeclFile.empty()) {
+ StartFile = DeclFile;
+ FoundResult = true;
+ }
if (auto DeclLineResult = DIE.getDeclLine()) {
StartLine = DeclLineResult;
FoundResult = true;
@@ -1224,8 +1231,9 @@ DILineInfo DWARFContext::getLineInfoForAddress(object::SectionedAddress Address,
if (!CU)
return Result;
- getFunctionNameAndStartLineForAddress(CU, Address.Address, Spec.FNKind,
- Result.FunctionName, Result.StartLine);
+ getFunctionNameAndStartLineForAddress(CU, Address.Address, Spec.FNKind, Spec.FLIKind,
+ Result.FunctionName,
+ Result.StartFileName, Result.StartLine);
if (Spec.FLIKind != FileLineInfoKind::None) {
if (const DWARFLineTable *LineTable = getLineTableForUnit(CU)) {
LineTable->getFileLineInfoForAddress(
@@ -1244,15 +1252,17 @@ DILineInfoTable DWARFContext::getLineInfoForAddressRange(
return Lines;
uint32_t StartLine = 0;
+ std::string StartFileName;
std::string FunctionName(DILineInfo::BadString);
- getFunctionNameAndStartLineForAddress(CU, Address.Address, Spec.FNKind,
- FunctionName, StartLine);
+ getFunctionNameAndStartLineForAddress(CU, Address.Address, Spec.FNKind, Spec.FLIKind,
+ FunctionName, StartFileName, StartLine);
// If the Specifier says we don't need FileLineInfo, just
// return the top-most function at the starting address.
if (Spec.FLIKind == FileLineInfoKind::None) {
DILineInfo Result;
Result.FunctionName = FunctionName;
+ Result.StartFileName = StartFileName;
Result.StartLine = StartLine;
Lines.push_back(std::make_pair(Address.Address, Result));
return Lines;
@@ -1276,6 +1286,7 @@ DILineInfoTable DWARFContext::getLineInfoForAddressRange(
Result.FunctionName = FunctionName;
Result.Line = Row.Line;
Result.Column = Row.Column;
+ Result.StartFileName = StartFileName;
Result.StartLine = StartLine;
Lines.push_back(std::make_pair(Row.Address.Address, Result));
}
@@ -1318,6 +1329,7 @@ DWARFContext::getInliningInfoForAddress(object::SectionedAddress Address,
Frame.FunctionName = Name;
if (auto DeclLineResult = FunctionDIE.getDeclLine())
Frame.StartLine = DeclLineResult;
+ Frame.StartFileName = FunctionDIE.getDeclFile(Spec.FLIKind);
if (Spec.FLIKind != FileLineInfoKind::None) {
if (i == 0) {
// For the topmost frame, initialize the line table of this
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
index 116f72a1d58b..31340077a126 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
@@ -557,6 +557,17 @@ uint64_t DWARFDie::getDeclLine() const {
return toUnsigned(findRecursively(DW_AT_decl_line), 0);
}
+std::string
+DWARFDie::getDeclFile(DILineInfoSpecifier::FileLineInfoKind Kind) const {
+ std::string FileName;
+ if (auto DeclFile = toUnsigned(findRecursively(DW_AT_decl_file))) {
+ if (const auto *LT = U->getContext().getLineTableForUnit(U)) {
+ LT->getFileNameByIndex(*DeclFile, U->getCompilationDir(), Kind, FileName);
+ }
+ }
+ return FileName;
+}
+
void DWARFDie::getCallerFrame(uint32_t &CallFile, uint32_t &CallLine,
uint32_t &CallColumn,
uint32_t &CallDiscriminator) const {
diff --git a/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp b/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp
index 10352237763c..01dc31d84965 100644
--- a/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp
+++ b/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp
@@ -84,8 +84,10 @@ void DIPrinter::print(const DILineInfo &Info, bool Inlined) {
return;
}
OS << " Filename: " << Filename << "\n";
- if (Info.StartLine)
- OS << "Function start line: " << Info.StartLine << "\n";
+ if (Info.StartLine) {
+ OS << " Function start filename: " << Info.StartFileName << "\n";
+ OS << " Function start line: " << Info.StartLine << "\n";
+ }
OS << " Line: " << Info.Line << "\n";
OS << " Column: " << Info.Column << "\n";
if (Info.Discriminator)
diff --git a/llvm/test/tools/llvm-dwarfdump/X86/lookup.s b/llvm/test/tools/llvm-dwarfdump/X86/lookup.s
index 74f3314a4f4e..fed2271f70a0 100644
--- a/llvm/test/tools/llvm-dwarfdump/X86/lookup.s
+++ b/llvm/test/tools/llvm-dwarfdump/X86/lookup.s
@@ -37,9 +37,9 @@
# LEX: DW_AT_low_pc (0x0000000000000004)
# LEX: DW_AT_high_pc (0x0000000000000014)
-# A: Line info: file 'foo.c', line 3, column 9, start line 1
-# B: Line info: file 'foo.c', line 4, column 6, start line 1
-# C: Line info: file 'foo.c', line 6, column 1, start line 1
+# A: Line info: file 'foo.c', line 3, column 9, start file 'foo.c', start line 1
+# B: Line info: file 'foo.c', line 4, column 6, start file 'foo.c', start line 1
+# C: Line info: file 'foo.c', line 6, column 1, start file 'foo.c', start line 1
.section __TEXT,__text,regular,pure_instructions
.macosx_version_min 10, 13
diff --git a/llvm/test/tools/llvm-symbolizer/sym-verbose.test b/llvm/test/tools/llvm-symbolizer/sym-verbose.test
index c12eb3b530e1..152929037909 100644
--- a/llvm/test/tools/llvm-symbolizer/sym-verbose.test
+++ b/llvm/test/tools/llvm-symbolizer/sym-verbose.test
@@ -18,11 +18,13 @@ RUN: llvm-symbolizer -verbose -print-address -obj=%p/Inputs/discrim < %p/Inputs/
#CHECK: 0x400590
#CHECK-NEXT: foo
#CHECK-NEXT: Filename: /tmp{{[\\/]}}discrim.c
+#CHECK-NEXT: Function start filename: /tmp{{[\\/]}}discrim.c
#CHECK-NEXT: Function start line: 4
#CHECK-NEXT: Line: 5
#CHECK-NEXT: Column: 7
#CHECK-NEXT: main
#CHECK-NEXT: Filename: /tmp{{[\\/]}}discrim.c
+#CHECK-NEXT: Function start filename: /tmp{{[\\/]}}discrim.c
#CHECK-NEXT: Function start line: 9
#CHECK-NEXT: Line: 10
#CHECK-NEXT: Column: 0
@@ -30,12 +32,14 @@ RUN: llvm-symbolizer -verbose -print-address -obj=%p/Inputs/discrim < %p/Inputs/
#CHECK: 0x4005a5
#CHECK-NEXT: foo
#CHECK-NEXT: Filename: /tmp{{[\\/]}}discrim.c
+#CHECK-NEXT: Function start filename: /tmp{{[\\/]}}discrim.c
#CHECK-NEXT: Function start line: 4
#CHECK-NEXT: Line: 5
#CHECK-NEXT: Column: 17
#CHECK-NEXT: Discriminator: 2
#CHECK-NEXT: main
#CHECK-NEXT: Filename: /tmp{{[\\/]}}discrim.c
+#CHECK-NEXT: Function start filename: /tmp{{[\\/]}}discrim.c
#CHECK-NEXT: Function start line: 9
#CHECK-NEXT: Line: 10
#CHECK-NEXT: Column: 0
@@ -43,12 +47,14 @@ RUN: llvm-symbolizer -verbose -print-address -obj=%p/Inputs/discrim < %p/Inputs/
#CHECK: 0x4005ad
#CHECK-NEXT: foo
#CHECK-NEXT: Filename: /tmp{{[\\/]}}discrim.c
+#CHECK-NEXT: Function start filename: /tmp{{[\\/]}}discrim.c
#CHECK-NEXT: Function start line: 4
#CHECK-NEXT: Line: 0
#CHECK-NEXT: Column: 30
#CHECK-NEXT: Discriminator: 4
#CHECK-NEXT: main
#CHECK-NEXT: Filename: /tmp{{[\\/]}}discrim.c
+#CHECK-NEXT: Function start filename: /tmp{{[\\/]}}discrim.c
#CHECK-NEXT: Function start line: 9
#CHECK-NEXT: Line: 10
#CHECK-NEXT: Column: 0
@@ -56,11 +62,13 @@ RUN: llvm-symbolizer -verbose -print-address -obj=%p/Inputs/discrim < %p/Inputs/
#CHECK: 0x4005b9
#CHECK-NEXT: foo
#CHECK-NEXT: Filename: /tmp{{[\\/]}}discrim.c
+#CHECK-NEXT: Function start filename: /tmp{{[\\/]}}discrim.c
#CHECK-NEXT: Function start line: 4
#CHECK-NEXT: Line: 5
#CHECK-NEXT: Column: 7
#CHECK-NEXT: main
#CHECK-NEXT: Filename: /tmp{{[\\/]}}discrim.c
+#CHECK-NEXT: Function start filename: /tmp{{[\\/]}}discrim.c
#CHECK-NEXT: Function start line: 9
#CHECK-NEXT: Line: 10
#CHECK-NEXT: Column: 0
@@ -69,12 +77,14 @@ RUN: llvm-symbolizer -verbose -print-address -obj=%p/Inputs/discrim < %p/Inputs/
#CHECK: 0x4005ce
#CHECK-NEXT: foo
#CHECK-NEXT: Filename: /tmp{{[\\/]}}discrim.c
+#CHECK-NEXT: Function start filename: /tmp{{[\\/]}}discrim.c
#CHECK-NEXT: Function start line: 4
#CHECK-NEXT: Line: 5
#CHECK-NEXT: Column: 17
#CHECK-NEXT: Discriminator: 2
#CHECK-NEXT: main
#CHECK-NEXT: Filename: /tmp{{[\\/]}}discrim.c
+#CHECK-NEXT: Function start filename: /tmp{{[\\/]}}discrim.c
#CHECK-NEXT: Function start line: 9
#CHECK-NEXT: Line: 10
#CHECK-NEXT: Column: 0
@@ -83,12 +93,14 @@ RUN: llvm-symbolizer -verbose -print-address -obj=%p/Inputs/discrim < %p/Inputs/
#CHECK: 0x4005d4
#CHECK-NEXT: foo
#CHECK-NEXT: Filename: /tmp{{[\\/]}}discrim.c
+#CHECK-NEXT: Function start filename: /tmp{{[\\/]}}discrim.c
#CHECK-NEXT: Function start line: 4
#CHECK-NEXT: Line: 5
#CHECK-NEXT: Column: 30
#CHECK-NEXT: Discriminator: 4
#CHECK-NEXT: main
#CHECK-NEXT: Filename: /tmp{{[\\/]}}discrim.c
+#CHECK-NEXT: Function start filename: /tmp{{[\\/]}}discrim.c
#CHECK-NEXT: Function start line: 9
#CHECK-NEXT: Line: 10
#CHECK-NEXT: Column: 0
More information about the llvm-commits
mailing list