[llvm] r369377 - [llvm-readobj] Prepend argv[0] to error/warning messages
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 20 05:49:16 PDT 2019
Author: maskray
Date: Tue Aug 20 05:49:15 2019
New Revision: 369377
URL: http://llvm.org/viewvc/llvm-project?rev=369377&view=rev
Log:
[llvm-readobj] Prepend argv[0] to error/warning messages
Summary:
Currently, we report:
error: ...
Prepend argv[0] (tool name):
llvm-readobj: error: ...
This is consistent with most GNU binutils/clang/lld, and gives a bit
more context in a long build log.
Reviewed By: grimar, jhenderson, rupprecht
Differential Revision: https://reviews.llvm.org/D66425
Added:
llvm/trunk/test/tools/llvm-readobj/error-format.test
Modified:
llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp
Added: llvm/trunk/test/tools/llvm-readobj/error-format.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-readobj/error-format.test?rev=369377&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-readobj/error-format.test (added)
+++ llvm/trunk/test/tools/llvm-readobj/error-format.test Tue Aug 20 05:49:15 2019
@@ -0,0 +1,19 @@
+## This test shows that we include the tool name in error/warning messages.
+
+# RUN: not llvm-readelf %S/non-existent 2>&1 | FileCheck --check-prefix=ERR %s -DTOOL=readelf
+# RUN: not llvm-readobj %S/non-existent 2>&1 | FileCheck --check-prefix=ERR %s -DTOOL=readobj
+
+# ERR: llvm-[[TOOL]]{{(\.exe)?}}: error: '{{.*}}': {{[Nn]}}o such file or directory
+
+# RUN: yaml2obj %s -o %t
+# RUN: llvm-readelf -x 10 %t 2>&1 | FileCheck --check-prefix=WARN %s -DTOOL=readelf
+# RUN: llvm-readobj -x 10 %t 2>&1 | FileCheck --check-prefix=WARN %s -DTOOL=readobj
+
+# WARN: llvm-[[TOOL]]{{(\.exe)?}}: warning: '{{.*}}': could not find section 10
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_RISCV
Modified: llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp?rev=369377&r1=369376&r2=369377&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp Tue Aug 20 05:49:15 2019
@@ -373,6 +373,8 @@ namespace opts {
HelpResponse("\nPass @FILE as argument to read options from FILE.\n");
} // namespace opts
+static StringRef ToolName;
+
namespace llvm {
LLVM_ATTRIBUTE_NORETURN static void error(Twine Msg) {
@@ -380,7 +382,7 @@ LLVM_ATTRIBUTE_NORETURN static void erro
// proper place.
fouts().flush();
errs() << "\n";
- WithColor::error(errs()) << Msg << "\n";
+ WithColor::error(errs(), ToolName) << Msg << "\n";
exit(1);
}
@@ -401,11 +403,11 @@ void reportWarning(Error Err, StringRef
// Flush the standard output to print the warning at a
// proper place.
fouts().flush();
- handleAllErrors(createFileError(Input, std::move(Err)),
- [&](const ErrorInfoBase &EI) {
- errs() << "\n";
- WithColor::warning(errs()) << EI.message() << "\n";
- });
+ handleAllErrors(
+ createFileError(Input, std::move(Err)), [&](const ErrorInfoBase &EI) {
+ errs() << "\n";
+ WithColor::warning(errs(), ToolName) << EI.message() << "\n";
+ });
}
LLVM_ATTRIBUTE_NORETURN void reportError(std::error_code EC, StringRef Input) {
@@ -703,6 +705,7 @@ static void registerReadelfAliases() {
int main(int argc, const char *argv[]) {
InitLLVM X(argc, argv);
+ ToolName = argv[0];
// Register the target printer for --version.
cl::AddExtraVersionPrinter(TargetRegistry::printRegisteredTargetsForVersion);
More information about the llvm-commits
mailing list