Skip to content

Commit ee7eaf8

Browse files
MaskRaytstellar
authored andcommitted
[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 eecbb1c)
1 parent bdafd28 commit ee7eaf8

File tree

3 files changed

+14
-31
lines changed

3 files changed

+14
-31
lines changed
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
## Test that if an object has no debug information, only the disassembly is
2-
## printed when --source is specified, and that we emit a warning.
2+
## printed when --source is specified, and that we do not emit a warning.
33

44
# RUN: sed -e "s,SRC_COMPDIR,%/p/Inputs,g" %p/Inputs/source-interleave.ll > %t.ll
55
# RUN: llc -o %t.o -filetype=obj -mtriple=x86_64-pc-linux %t.ll
66
# RUN: llvm-objcopy --strip-debug %t.o %t2.o
77

88
# RUN: llvm-objdump --source %t.o | FileCheck %s --check-prefixes=CHECK,SOURCE
9-
# RUN: llvm-objdump --source %t2.o 2> %t2.e | FileCheck %s --check-prefixes=CHECK --implicit-check-not='main()'
10-
# RUN: FileCheck %s --input-file %t2.e --check-prefixes=WARN
9+
# RUN: llvm-objdump --source %t2.o 2>&1 | FileCheck %s --check-prefixes=CHECK --implicit-check-not='main()' --implicit-check-not=warning:
1110

12-
# WARN: warning: '{{.*}}2.o': failed to parse debug information
1311
# CHECK: 0000000000000010 <main>:
1412
# SOURCE-NEXT: ; int main() {
1513
# CHECK-NEXT: 10: 55 pushq %rbp

llvm/test/tools/llvm-objdump/X86/source-interleave-prefix.test

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,6 @@
2424
; RUN: llvm-objdump --prefix myprefix --source %t-correct-prefix.o 2>&1 | \
2525
; RUN: FileCheck %s --check-prefix=CHECK-BROKEN-PREFIX -DFILE=%t-correct-prefix.o -DPREFIX=myprefix%/p
2626

27-
;; Test malformed input.
28-
29-
; RUN: sed -e "s,SRC_COMPDIR,,g" -e "s,filename: \"source-interleave-x86_64.c\",filename: \"\",g" \
30-
; RUN: %p/Inputs/source-interleave.ll > %t-malformed.ll
31-
; RUN: llc -o %t-malformed.o -filetype=obj -mtriple=x86_64-pc-linux %t-malformed.ll
32-
; RUN: llvm-objdump --prefix myprefix --source %t-malformed.o 2>&1 | \
33-
; RUN: FileCheck %s --check-prefix=CHECK-MALFORMED -DFILE=%t-malformed.o
34-
; CHECK-MALFORMED: warning: '[[FILE]]': failed to parse debug information for [[FILE]]
35-
3627
;; Using only a prefix separator is the same as not using the `--prefix` option.
3728

3829
; RUN: llvm-objdump --prefix / --source %t-missing-prefix.o 2>&1 | \

llvm/tools/llvm-objdump/llvm-objdump.cpp

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -947,8 +947,8 @@ class SourcePrinter {
947947
std::unordered_map<std::string, std::vector<StringRef>> LineCache;
948948
// Keep track of missing sources.
949949
StringSet<> MissingSources;
950-
// Only emit 'no debug info' warning once.
951-
bool WarnedNoDebugInfo;
950+
// Only emit 'invalid debug info' warning once.
951+
bool WarnedInvalidDebugInfo = false;
952952

953953
private:
954954
bool cacheSource(const DILineInfo& LineInfoFile);
@@ -962,8 +962,7 @@ class SourcePrinter {
962962

963963
public:
964964
SourcePrinter() = default;
965-
SourcePrinter(const ObjectFile *Obj, StringRef DefaultArch)
966-
: Obj(Obj), WarnedNoDebugInfo(false) {
965+
SourcePrinter(const ObjectFile *Obj, StringRef DefaultArch) : Obj(Obj) {
967966
symbolize::LLVMSymbolizer::Options SymbolizerOpts;
968967
SymbolizerOpts.PrintFunctions =
969968
DILineInfoSpecifier::FunctionNameKind::LinkageName;
@@ -1018,22 +1017,17 @@ void SourcePrinter::printSourceLine(formatted_raw_ostream &OS,
10181017
return;
10191018

10201019
DILineInfo LineInfo = DILineInfo();
1021-
auto ExpectedLineInfo = Symbolizer->symbolizeCode(*Obj, Address);
1020+
Expected<DILineInfo> ExpectedLineInfo =
1021+
Symbolizer->symbolizeCode(*Obj, Address);
10221022
std::string ErrorMessage;
1023-
if (!ExpectedLineInfo)
1024-
ErrorMessage = toString(ExpectedLineInfo.takeError());
1025-
else
1023+
if (ExpectedLineInfo) {
10261024
LineInfo = *ExpectedLineInfo;
1027-
1028-
if (LineInfo.FileName == DILineInfo::BadString) {
1029-
if (!WarnedNoDebugInfo) {
1030-
std::string Warning =
1031-
"failed to parse debug information for " + ObjectFilename.str();
1032-
if (!ErrorMessage.empty())
1033-
Warning += ": " + ErrorMessage;
1034-
reportWarning(Warning, ObjectFilename);
1035-
WarnedNoDebugInfo = true;
1036-
}
1025+
} else if (!WarnedInvalidDebugInfo) {
1026+
WarnedInvalidDebugInfo = true;
1027+
// TODO Untested.
1028+
reportWarning("failed to parse debug information: " +
1029+
toString(ExpectedLineInfo.takeError()),
1030+
ObjectFilename);
10371031
}
10381032

10391033
if (!Prefix.empty() && sys::path::is_absolute_gnu(LineInfo.FileName)) {

0 commit comments

Comments
 (0)