[PATCH] D66425: [llvm-readobj] Prepend argv[0] to error messages
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 20 03:25:43 PDT 2019
MaskRay updated this revision to Diff 216091.
MaskRay added a comment.
Add a warning test
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D66425/new/
https://reviews.llvm.org/D66425
Files:
test/tools/llvm-readobj/error-format.test
tools/llvm-readobj/llvm-readobj.cpp
Index: tools/llvm-readobj/llvm-readobj.cpp
===================================================================
--- tools/llvm-readobj/llvm-readobj.cpp
+++ tools/llvm-readobj/llvm-readobj.cpp
@@ -373,6 +373,8 @@
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 @@
// proper place.
fouts().flush();
errs() << "\n";
- WithColor::error(errs()) << Msg << "\n";
+ WithColor::error(errs(), ToolName) << Msg << "\n";
exit(1);
}
@@ -401,11 +403,11 @@
// 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 @@
int main(int argc, const char *argv[]) {
InitLLVM X(argc, argv);
+ ToolName = argv[0];
// Register the target printer for --version.
cl::AddExtraVersionPrinter(TargetRegistry::printRegisteredTargetsForVersion);
Index: test/tools/llvm-readobj/error-format.test
===================================================================
--- /dev/null
+++ test/tools/llvm-readobj/error-format.test
@@ -0,0 +1,15 @@
+## 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-READELF %s
+# RUN: not llvm-readobj %S/non-existent 2>&1 | FileCheck --check-prefix=ERR-READOBJ %s
+
+# ERR-READELF: llvm-readelf{{(\.exe)?}}: error: '{{.*}}': {{[Nn]}}o such file or directory
+# ERR-READOBJ: llvm-readobj{{(\.exe)?}}: error: '{{.*}}': {{[Nn]}}o such file or directory
+
+# RUN: llvm-readelf -x 10 %S/Inputs/trivial.obj.elf-x86-64 2>&1 | \
+# RUN: FileCheck --check-prefix=WARN-READELF %s
+# RUN: llvm-readobj -x 10 %S/Inputs/trivial.obj.elf-x86-64 2>&1 | \
+# RUN: FileCheck --check-prefix=WARN-READOBJ %s
+
+# WARN-READELF: llvm-readelf{{(\.exe)?}}: warning: '{{.*}}': could not find section 10
+# WARN-READOBJ: llvm-readobj{{(\.exe)?}}: warning: '{{.*}}': could not find section 10
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66425.216091.patch
Type: text/x-patch
Size: 2566 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190820/f011f510/attachment.bin>
More information about the llvm-commits
mailing list