Index: llvm/lib/DebugInfo/DWARF/DWARFDebugMacro.cpp =================================================================== --- llvm/lib/DebugInfo/DWARF/DWARFDebugMacro.cpp +++ llvm/lib/DebugInfo/DWARF/DWARFDebugMacro.cpp @@ -8,8 +8,8 @@ //===----------------------------------------------------------------------===// #include "llvm/DebugInfo/DWARF/DWARFDebugMacro.h" -#include "SyntaxHighlighting.h" #include "llvm/BinaryFormat/Dwarf.h" +#include "llvm/DebugInfo/DWARF/SyntaxHighlighting.h" #include "llvm/Support/raw_ostream.h" #include Index: llvm/lib/DebugInfo/DWARF/DWARFDie.cpp =================================================================== --- llvm/lib/DebugInfo/DWARF/DWARFDie.cpp +++ llvm/lib/DebugInfo/DWARF/DWARFDie.cpp @@ -8,7 +8,6 @@ //===----------------------------------------------------------------------===// #include "llvm/DebugInfo/DWARF/DWARFDie.h" -#include "SyntaxHighlighting.h" #include "llvm/ADT/None.h" #include "llvm/ADT/Optional.h" #include "llvm/ADT/StringRef.h" @@ -19,6 +18,7 @@ #include "llvm/DebugInfo/DWARF/DWARFExpression.h" #include "llvm/DebugInfo/DWARF/DWARFFormValue.h" #include "llvm/DebugInfo/DWARF/DWARFUnit.h" +#include "llvm/DebugInfo/DWARF/SyntaxHighlighting.h" #include "llvm/Object/ObjectFile.h" #include "llvm/Support/DataExtractor.h" #include "llvm/Support/Format.h" Index: llvm/lib/DebugInfo/DWARF/DWARFFormValue.cpp =================================================================== --- llvm/lib/DebugInfo/DWARF/DWARFFormValue.cpp +++ llvm/lib/DebugInfo/DWARF/DWARFFormValue.cpp @@ -8,7 +8,6 @@ //===----------------------------------------------------------------------===// #include "llvm/DebugInfo/DWARF/DWARFFormValue.h" -#include "SyntaxHighlighting.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/None.h" #include "llvm/ADT/Optional.h" @@ -17,6 +16,7 @@ #include "llvm/DebugInfo/DWARF/DWARFContext.h" #include "llvm/DebugInfo/DWARF/DWARFRelocMap.h" #include "llvm/DebugInfo/DWARF/DWARFUnit.h" +#include "llvm/DebugInfo/DWARF/SyntaxHighlighting.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/Format.h" #include "llvm/Support/raw_ostream.h" Index: llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp =================================================================== --- llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp +++ llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#include "SyntaxHighlighting.h" #include "llvm/DebugInfo/DWARF/DWARFVerifier.h" +#include "llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h" #include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h" #include "llvm/DebugInfo/DWARF/DWARFContext.h" #include "llvm/DebugInfo/DWARF/DWARFDebugLine.h" @@ -16,7 +16,7 @@ #include "llvm/DebugInfo/DWARF/DWARFExpression.h" #include "llvm/DebugInfo/DWARF/DWARFFormValue.h" #include "llvm/DebugInfo/DWARF/DWARFSection.h" -#include "llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h" +#include "llvm/DebugInfo/DWARF/SyntaxHighlighting.h" #include "llvm/Support/FormatVariadic.h" #include "llvm/Support/raw_ostream.h" #include Index: llvm/lib/DebugInfo/DWARF/SyntaxHighlighting.cpp =================================================================== --- llvm/lib/DebugInfo/DWARF/SyntaxHighlighting.cpp +++ llvm/lib/DebugInfo/DWARF/SyntaxHighlighting.cpp @@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// -#include "SyntaxHighlighting.h" +#include "llvm/DebugInfo/DWARF/SyntaxHighlighting.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/raw_ostream.h" Index: llvm/test/tools/dsymutil/X86/module-warnings.test =================================================================== --- llvm/test/tools/dsymutil/X86/module-warnings.test +++ llvm/test/tools/dsymutil/X86/module-warnings.test @@ -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' Index: llvm/test/tools/dsymutil/X86/swift-ast-x86_64.test =================================================================== --- llvm/test/tools/dsymutil/X86/swift-ast-x86_64.test +++ llvm/test/tools/dsymutil/X86/swift-ast-x86_64.test @@ -16,4 +16,4 @@ 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 Index: llvm/tools/dsymutil/DwarfLinker.cpp =================================================================== --- llvm/tools/dsymutil/DwarfLinker.cpp +++ llvm/tools/dsymutil/DwarfLinker.cpp @@ -44,6 +44,7 @@ #include "llvm/DebugInfo/DWARF/DWARFFormValue.h" #include "llvm/DebugInfo/DWARF/DWARFSection.h" #include "llvm/DebugInfo/DWARF/DWARFUnit.h" +#include "llvm/DebugInfo/DWARF/SyntaxHighlighting.h" #include "llvm/MC/MCAsmBackend.h" #include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/MCCodeEmitter.h" @@ -564,8 +565,36 @@ return false; } +static raw_ostream &error_ostream() { + return dwarf::syntax::WithColor(errs(), dwarf::syntax::Error).get() + << "error: "; +} + +static raw_ostream &warn_ostream() { + return dwarf::syntax::WithColor(errs(), dwarf::syntax::Warning).get() + << "warning: "; +} + +static raw_ostream ¬e_ostream() { + return dwarf::syntax::WithColor(errs(), dwarf::syntax::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 +2121,7 @@ DumpOpts.RecurseDepth = 0; DumpOpts.Verbose = Options.Verbose; - errs() << " in DIE:\n"; + note_ostream() << " in DIE:\n"; DIE->dump(errs(), 6 /* Indent */, DumpOpts); } @@ -3882,9 +3911,9 @@ // 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 +3922,12 @@ // 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 +3951,7 @@ (Filename + ": Clang modules are expected to have exactly 1 compile unit.\n") .str(); - errs() << Err; + error(Err); return make_error(Err, inconvertibleErrorCode()); } // FIXME: Until PR27449 (https://llvm.org/bugs/show_bug.cgi?id=27449) is @@ -4030,19 +4060,20 @@ StringRef File = Obj->getObjectFilename(); auto ErrorOrMem = MemoryBuffer::getFile(File); if (!ErrorOrMem) { - errs() << "Warning: Could not open " << File << "\n"; + warn("Could not open " + File); 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; } @@ -4137,17 +4168,6 @@ return Options.NoOutput ? true : Streamer->finish(Map); } -void warn(const Twine &Warning, const Twine &Context) { - errs() << Twine("while processing ") + Context + ":\n"; - errs() << Twine("warning: ") + Warning + "\n"; -} - -bool error(const Twine &Error, const Twine &Context) { - errs() << Twine("while processing ") + Context + ":\n"; - errs() << Twine("error: ") + Error + "\n"; - return false; -} - bool linkDwarf(raw_fd_ostream &OutFile, const DebugMap &DM, const LinkOptions &Options) { DwarfLinker Linker(OutFile, Options); Index: llvm/tools/dsymutil/dsymutil.h =================================================================== --- llvm/tools/dsymutil/dsymutil.h +++ llvm/tools/dsymutil/dsymutil.h @@ -70,8 +70,8 @@ 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