summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2021-02-04 09:07:44 -0800
committerTom Stellard <tstellar@redhat.com>2021-02-19 22:09:42 -0800
commitee7eaf860cde24a91a5b17390b8ad5eddd05f7f9 (patch)
tree499bfb80e7609bb205c51051e0b1b962b15b4dc8
parentbdafd284b291436d3fa4644f585efe3b06363554 (diff)
downloadllvm-ee7eaf860cde24a91a5b17390b8ad5eddd05f7f9.tar.gz
[llvm-objdump] --source: drop the warning when there is no debug info
Warnings have been added for three cases (PR41905): (1) missing debug info, (2) the source file cannot be found, (3) the debug info points at a line beyond the end of the file. (1) is probably less useful. This was brought up once on http://lists.llvm.org/pipermail/llvm-dev/2020-April/141264.html and two internal users mentioned it to me that it was annoying. (I personally find the warning confusing, too.) Users specify --source to get additional information if sources happen to be available. If sources are not available, it should be obvious as the output will have no interleaved source lines. The warning can be especially annoying when using llvm-objdump -S on a bunch of files. This patch drops the warning when there is no debug info. (If LLVMSymbolizer::symbolizeCode returns an `Error`, there will still be an error. There is currently no test for an `Error` return value. The only code path is probably a broken symbol table, but we probably already emit a warning in that case) `source-interleave-prefix.test` has an inappropriate "malformed" test - the test simply has no .debug_* because new llc does not produce debug info when the filename is empty (invalid). I have tried tampering the header of .debug_info/.debug_line but llvm-symbolizer does not warn. This patch does not intend to add the missing test coverage. Differential Revision: https://reviews.llvm.org/D88715 (cherry picked from commit eecbb1c77655d38c06e47cf32e2dcc72da45c517)
-rw-r--r--llvm/test/tools/llvm-objdump/X86/source-interleave-no-debug-info.test6
-rw-r--r--llvm/test/tools/llvm-objdump/X86/source-interleave-prefix.test9
-rw-r--r--llvm/tools/llvm-objdump/llvm-objdump.cpp30
3 files changed, 14 insertions, 31 deletions
diff --git a/llvm/test/tools/llvm-objdump/X86/source-interleave-no-debug-info.test b/llvm/test/tools/llvm-objdump/X86/source-interleave-no-debug-info.test
index 25deaa00243c..89b03d429bfa 100644
--- a/llvm/test/tools/llvm-objdump/X86/source-interleave-no-debug-info.test
+++ b/llvm/test/tools/llvm-objdump/X86/source-interleave-no-debug-info.test
@@ -1,15 +1,13 @@
## Test that if an object has no debug information, only the disassembly is
-## printed when --source is specified, and that we emit a warning.
+## printed when --source is specified, and that we do not emit a warning.
# RUN: sed -e "s,SRC_COMPDIR,%/p/Inputs,g" %p/Inputs/source-interleave.ll > %t.ll
# RUN: llc -o %t.o -filetype=obj -mtriple=x86_64-pc-linux %t.ll
# RUN: llvm-objcopy --strip-debug %t.o %t2.o
# RUN: llvm-objdump --source %t.o | FileCheck %s --check-prefixes=CHECK,SOURCE
-# RUN: llvm-objdump --source %t2.o 2> %t2.e | FileCheck %s --check-prefixes=CHECK --implicit-check-not='main()'
-# RUN: FileCheck %s --input-file %t2.e --check-prefixes=WARN
+# RUN: llvm-objdump --source %t2.o 2>&1 | FileCheck %s --check-prefixes=CHECK --implicit-check-not='main()' --implicit-check-not=warning:
-# WARN: warning: '{{.*}}2.o': failed to parse debug information
# CHECK: 0000000000000010 <main>:
# SOURCE-NEXT: ; int main() {
# CHECK-NEXT: 10: 55 pushq %rbp
diff --git a/llvm/test/tools/llvm-objdump/X86/source-interleave-prefix.test b/llvm/test/tools/llvm-objdump/X86/source-interleave-prefix.test
index b384c49b350e..23ce55a329ac 100644
--- a/llvm/test/tools/llvm-objdump/X86/source-interleave-prefix.test
+++ b/llvm/test/tools/llvm-objdump/X86/source-interleave-prefix.test
@@ -24,15 +24,6 @@
; RUN: llvm-objdump --prefix myprefix --source %t-correct-prefix.o 2>&1 | \
; RUN: FileCheck %s --check-prefix=CHECK-BROKEN-PREFIX -DFILE=%t-correct-prefix.o -DPREFIX=myprefix%/p
-;; Test malformed input.
-
-; RUN: sed -e "s,SRC_COMPDIR,,g" -e "s,filename: \"source-interleave-x86_64.c\",filename: \"\",g" \
-; RUN: %p/Inputs/source-interleave.ll > %t-malformed.ll
-; RUN: llc -o %t-malformed.o -filetype=obj -mtriple=x86_64-pc-linux %t-malformed.ll
-; RUN: llvm-objdump --prefix myprefix --source %t-malformed.o 2>&1 | \
-; RUN: FileCheck %s --check-prefix=CHECK-MALFORMED -DFILE=%t-malformed.o
-; CHECK-MALFORMED: warning: '[[FILE]]': failed to parse debug information for [[FILE]]
-
;; Using only a prefix separator is the same as not using the `--prefix` option.
; RUN: llvm-objdump --prefix / --source %t-missing-prefix.o 2>&1 | \
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 3134f989603a..17128e95727f 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -947,8 +947,8 @@ protected:
std::unordered_map<std::string, std::vector<StringRef>> LineCache;
// Keep track of missing sources.
StringSet<> MissingSources;
- // Only emit 'no debug info' warning once.
- bool WarnedNoDebugInfo;
+ // Only emit 'invalid debug info' warning once.
+ bool WarnedInvalidDebugInfo = false;
private:
bool cacheSource(const DILineInfo& LineInfoFile);
@@ -962,8 +962,7 @@ private:
public:
SourcePrinter() = default;
- SourcePrinter(const ObjectFile *Obj, StringRef DefaultArch)
- : Obj(Obj), WarnedNoDebugInfo(false) {
+ SourcePrinter(const ObjectFile *Obj, StringRef DefaultArch) : Obj(Obj) {
symbolize::LLVMSymbolizer::Options SymbolizerOpts;
SymbolizerOpts.PrintFunctions =
DILineInfoSpecifier::FunctionNameKind::LinkageName;
@@ -1018,22 +1017,17 @@ void SourcePrinter::printSourceLine(formatted_raw_ostream &OS,
return;
DILineInfo LineInfo = DILineInfo();
- auto ExpectedLineInfo = Symbolizer->symbolizeCode(*Obj, Address);
+ Expected<DILineInfo> ExpectedLineInfo =
+ Symbolizer->symbolizeCode(*Obj, Address);
std::string ErrorMessage;
- if (!ExpectedLineInfo)
- ErrorMessage = toString(ExpectedLineInfo.takeError());
- else
+ if (ExpectedLineInfo) {
LineInfo = *ExpectedLineInfo;
-
- if (LineInfo.FileName == DILineInfo::BadString) {
- if (!WarnedNoDebugInfo) {
- std::string Warning =
- "failed to parse debug information for " + ObjectFilename.str();
- if (!ErrorMessage.empty())
- Warning += ": " + ErrorMessage;
- reportWarning(Warning, ObjectFilename);
- WarnedNoDebugInfo = true;
- }
+ } else if (!WarnedInvalidDebugInfo) {
+ WarnedInvalidDebugInfo = true;
+ // TODO Untested.
+ reportWarning("failed to parse debug information: " +
+ toString(ExpectedLineInfo.takeError()),
+ ObjectFilename);
}
if (!Prefix.empty() && sys::path::is_absolute_gnu(LineInfo.FileName)) {