[llvm] r327137 - [dsymutil] Unify error handling and add color

Jonas Devlieghere via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 9 07:22:42 PST 2018


Author: jdevlieghere
Date: Fri Mar  9 07:22:42 2018
New Revision: 327137

URL: http://llvm.org/viewvc/llvm-project?rev=327137&view=rev
Log:
[dsymutil] Unify error handling and add color

We improved the handling of errors and warnings in dwarfdump's verifier
in rL314498. This patch does the same thing for dsymutil.

Differential revision: https://reviews.llvm.org/D44052

Modified:
    llvm/trunk/test/tools/dsymutil/X86/module-warnings.test
    llvm/trunk/test/tools/dsymutil/X86/swift-ast-x86_64.test
    llvm/trunk/tools/dsymutil/DwarfLinker.cpp
    llvm/trunk/tools/dsymutil/dsymutil.h

Modified: llvm/trunk/test/tools/dsymutil/X86/module-warnings.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/dsymutil/X86/module-warnings.test?rev=327137&r1=327136&r2=327137&view=diff
==============================================================================
--- llvm/trunk/test/tools/dsymutil/X86/module-warnings.test (original)
+++ llvm/trunk/test/tools/dsymutil/X86/module-warnings.test Fri Mar  9 07:22:42 2018
@@ -42,7 +42,7 @@
 # STATIC: warning: {{.*}}Bar.pcm:
 # STATIC: note: Linking a static library
 # STATIC: warning: {{.*}}Foo.pcm:
-# STATIC-NOT: note:
+# STATIC-NOT: warning:
 
 ---
 triple:          'x86_64-apple-darwin'

Modified: llvm/trunk/test/tools/dsymutil/X86/swift-ast-x86_64.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/dsymutil/X86/swift-ast-x86_64.test?rev=327137&r1=327136&r2=327137&view=diff
==============================================================================
--- llvm/trunk/test/tools/dsymutil/X86/swift-ast-x86_64.test (original)
+++ llvm/trunk/test/tools/dsymutil/X86/swift-ast-x86_64.test Fri Mar  9 07:22:42 2018
@@ -16,4 +16,4 @@ READOBJ: |SWIFTMODULE DATA|
 READOBJ-NEXT: |.|
 
 RUN: llvm-dsymutil -oso-prepend-path %p/.. %p/../Inputs/swift-ast.macho.x86_64 -no-output -verbose 2>&1 | FileCheck %s --check-prefix=TIMESTAMP
-TIMESTAMP: Warning: Timestamp mismatch
+TIMESTAMP: warning: Timestamp mismatch

Modified: llvm/trunk/tools/dsymutil/DwarfLinker.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/DwarfLinker.cpp?rev=327137&r1=327136&r2=327137&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/DwarfLinker.cpp (original)
+++ llvm/trunk/tools/dsymutil/DwarfLinker.cpp Fri Mar  9 07:22:42 2018
@@ -76,6 +76,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/TargetRegistry.h"
 #include "llvm/Support/ToolOutputFile.h"
+#include "llvm/Support/WithColor.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Target/TargetOptions.h"
@@ -564,8 +565,32 @@ static bool inFunctionScope(CompileUnit
   return false;
 }
 
+static raw_ostream &error_ostream() {
+  return WithColor(errs(), HighlightColor::Error).get() << "error: ";
+}
+
+static raw_ostream &warn_ostream() {
+  return WithColor(errs(), HighlightColor::Warning).get() << "warning: ";
+}
+
+static raw_ostream &note_ostream() {
+  return WithColor(errs(), HighlightColor::Note).get() << "note: ";
+}
 } // end anonymous namespace
 
+void warn(Twine Warning, Twine Context) {
+  warn_ostream() << Warning + "\n";
+  if (!Context.isTriviallyEmpty())
+    note_ostream() << Twine("while processing ") + Context + ":\n";
+}
+
+bool error(Twine Error, Twine Context) {
+  error_ostream() << Error + "\n";
+  if (!Context.isTriviallyEmpty())
+    note_ostream() << Twine("while processing ") + Context + ":\n";
+  return false;
+}
+
 void CompileUnit::markEverythingAsKept() {
   unsigned Idx = 0;
 
@@ -2092,7 +2117,7 @@ void DwarfLinker::reportWarning(const Tw
   DumpOpts.RecurseDepth = 0;
   DumpOpts.Verbose = Options.Verbose;
 
-  errs() << "    in DIE:\n";
+  note_ostream() << "    in DIE:\n";
   DIE->dump(errs(), 6 /* Indent */, DumpOpts);
 }
 
@@ -3882,9 +3907,9 @@ Error DwarfLinker::loadClangModule(Strin
         // cache has expired and was pruned by clang.  A more adventurous
         // dsymutil would invoke clang to rebuild the module now.
         if (!ModuleCacheHintDisplayed) {
-          errs() << "note: The clang module cache may have expired since this "
-                    "object file was built. Rebuilding the object file will "
-                    "rebuild the module cache.\n";
+          note_ostream() << "The clang module cache may have expired since "
+                            "this object file was built. Rebuilding the "
+                            "object file will rebuild the module cache.\n";
           ModuleCacheHintDisplayed = true;
         }
       } else if (isArchive) {
@@ -3893,11 +3918,12 @@ Error DwarfLinker::loadClangModule(Strin
         // was built on a different machine. We don't want to discourage module
         // debugging for convenience libraries within a project though.
         if (!ArchiveHintDisplayed) {
-          errs() << "note: Linking a static library that was built with "
-                    "-gmodules, but the module cache was not found.  "
-                    "Redistributable static libraries should never be built "
-                    "with module debugging enabled.  The debug experience will "
-                    "be degraded due to incomplete debug information.\n";
+          note_ostream() << "Linking a static library that was built with "
+                            "-gmodules, but the module cache was not found.  "
+                            "Redistributable static libraries should never be "
+                            "built with module debugging enabled.  The debug "
+                            "experience will be degraded due to incomplete "
+                            "debug information.\n";
           ArchiveHintDisplayed = true;
         }
       }
@@ -3921,7 +3947,7 @@ Error DwarfLinker::loadClangModule(Strin
             (Filename +
              ": Clang modules are expected to have exactly 1 compile unit.\n")
                 .str();
-        errs() << Err;
+        error(Err);
         return make_error<StringError>(Err, inconvertibleErrorCode());
       }
       // FIXME: Until PR27449 (https://llvm.org/bugs/show_bug.cgi?id=27449) is
@@ -4034,15 +4060,16 @@ bool DwarfLinker::link(const DebugMap &M
         continue;
       }
       sys::fs::file_status Stat;
-      if (auto errc = sys::fs::status(File, Stat)) {
-        errs() << "Warning: " << errc.message() << "\n";
+      if (auto Err = sys::fs::status(File, Stat)) {
+        warn(Err.message());
         continue;
       }
       if (!Options.NoTimestamp && Stat.getLastModificationTime() !=
                                       sys::TimePoint<>(Obj->getTimestamp())) {
-        errs() << "Warning: Timestamp mismatch for " << File << ": "
-               << Stat.getLastModificationTime() << " and "
-               << sys::TimePoint<>(Obj->getTimestamp()) << "\n";
+        // Not using the helper here as we can easily stream TimePoint<>.
+        warn_ostream() << "Timestamp mismatch for " << File << ": "
+                       << Stat.getLastModificationTime() << " and "
+                       << sys::TimePoint<>(Obj->getTimestamp()) << "\n";
         continue;
       }
 

Modified: llvm/trunk/tools/dsymutil/dsymutil.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/dsymutil.h?rev=327137&r1=327136&r2=327137&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/dsymutil.h (original)
+++ llvm/trunk/tools/dsymutil/dsymutil.h Fri Mar  9 07:22:42 2018
@@ -70,8 +70,8 @@ bool dumpStab(StringRef InputFile, Array
 bool linkDwarf(raw_fd_ostream &OutFile, const DebugMap &DM,
                const LinkOptions &Options);
 
-void warn(const Twine &Warning, const Twine &Context);
-bool error(const Twine &Error, const Twine &Context);
+void warn(Twine Warning, Twine Context = {});
+bool error(Twine Error, Twine Context = {});
 
 } // end namespace dsymutil
 } // end namespace llvm




More information about the llvm-commits mailing list