raw_ostream &get() { return OS; }
operator raw_ostream &() { return OS; }
+
+ /// Convenience method for printing "error: " to stderr.
+ static raw_ostream &error();
+
+ /// Convenience method for printing "warning: " to stderr.
+ static raw_ostream &warning();
+
+ /// Convenience method for printing "note: " to stderr.
+ static raw_ostream ¬e();
};
} // end namespace llvm
}
}
+raw_ostream &WithColor::error() {
+ return WithColor(errs(), HighlightColor::Error).get() << "error: ";
+}
+
+raw_ostream &WithColor::warning() {
+ return WithColor(errs(), HighlightColor::Warning).get() << "warning: ";
+}
+
+raw_ostream &WithColor::note() {
+ return WithColor(errs(), HighlightColor::Note).get() << "note: ";
+}
+
WithColor::~WithColor() {
if (colorsEnabled(OS))
OS.resetColor();
#include "DebugMap.h"
#include "BinaryHolder.h"
-#include "ErrorReporting.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
+#include "llvm/Support/WithColor.h"
#include "llvm/Support/YAMLTraits.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
Entries.reserve(Symbols.getNumItems());
for (const auto &Sym : make_range(Symbols.begin(), Symbols.end()))
Entries.push_back(std::make_pair(Sym.getKey(), Sym.getValue()));
- llvm::sort(Entries.begin(), Entries.end(),
- [](const Entry &LHS, const Entry &RHS) {
- return LHS.first < RHS.first;
- });
+ llvm::sort(
+ Entries.begin(), Entries.end(),
+ [](const Entry &LHS, const Entry &RHS) { return LHS.first < RHS.first; });
for (const auto &Sym : Entries) {
if (Sym.second.ObjectAddress)
OS << format("\t%016" PRIx64, uint64_t(*Sym.second.ObjectAddress));
sys::path::append(Path, Filename);
auto ErrOrObjectFiles = BinHolder.GetObjectFiles(Path);
if (auto EC = ErrOrObjectFiles.getError()) {
- warn_ostream() << "Unable to open " << Path << " " << EC.message() << '\n';
+ WithColor::warning() << "Unable to open " << Path << " " << EC.message()
+ << '\n';
} else if (auto ErrOrObjectFile = BinHolder.Get(Ctxt.BinaryTriple)) {
// Rewrite the object file symbol addresses in the debug map. The YAML
// input is mainly used to test dsymutil without requiring binaries
#include "BinaryHolder.h"
#include "DebugMap.h"
-#include "ErrorReporting.h"
#include "MachOUtils.h"
#include "NonRelocatableStringpool.h"
#include "dsymutil.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/ThreadPool.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"
} // namespace
void warn(Twine Warning, Twine Context) {
- warn_ostream() << Warning + "\n";
+ WithColor::warning() << Warning + "\n";
if (!Context.isTriviallyEmpty())
- note_ostream() << Twine("while processing ") + Context + "\n";
+ WithColor::note() << Twine("while processing ") + Context + "\n";
}
bool error(Twine Error, Twine Context) {
- error_ostream() << Error + "\n";
+ WithColor::error() << Error + "\n";
if (!Context.isTriviallyEmpty())
- note_ostream() << Twine("while processing ") + Context + "\n";
+ WithColor::note() << Twine("while processing ") + Context + "\n";
return false;
}
DumpOpts.RecurseDepth = 0;
DumpOpts.Verbose = Options.Verbose;
- note_ostream() << " in DIE:\n";
+ WithColor::note() << " in DIE:\n";
DIE->dump(errs(), 6 /* Indent */, DumpOpts);
}
// cache has expired and was pruned by clang. A more adventurous
// dsymutil would invoke clang to rebuild the module now.
if (!ModuleCacheHintDisplayed) {
- 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";
+ WithColor::note() << "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) {
// was built on a different machine. We don't want to discourage module
// debugging for convenience libraries within a project though.
if (!ArchiveHintDisplayed) {
- 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";
+ WithColor::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";
ArchiveHintDisplayed = true;
}
}
Stat.getLastModificationTime() !=
sys::TimePoint<>(LinkContext.DMO.getTimestamp())) {
// Not using the helper here as we can easily stream TimePoint<>.
- warn_ostream() << "Timestamp mismatch for " << File << ": "
- << Stat.getLastModificationTime() << " and "
- << sys::TimePoint<>(LinkContext.DMO.getTimestamp())
- << "\n";
+ WithColor::warning()
+ << "Timestamp mismatch for " << File << ": "
+ << Stat.getLastModificationTime() << " and "
+ << sys::TimePoint<>(LinkContext.DMO.getTimestamp()) << "\n";
continue;
}
+++ /dev/null
-//===- ErrorReporting.h - dsymutil error reporting -------------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_TOOLS_DSYMUTIL_ERRORREPORTING_H
-#define LLVM_TOOLS_DSYMUTIL_ERRORREPORTING_H
-#include "llvm/Support/WithColor.h"
-#include "llvm/Support/raw_ostream.h"
-
-namespace llvm {
-namespace dsymutil {
-
-inline raw_ostream &error_ostream() {
- return WithColor(errs(), HighlightColor::Error).get() << "error: ";
-}
-
-inline raw_ostream &warn_ostream() {
- return WithColor(errs(), HighlightColor::Warning).get() << "warning: ";
-}
-
-inline raw_ostream ¬e_ostream() {
- return WithColor(errs(), HighlightColor::Note).get() << "note: ";
-}
-
-} // namespace dsymutil
-} // end namespace llvm
-
-#endif // LLVM_TOOLS_DSYMUTIL_ERRORREPORTING_H
#include "BinaryHolder.h"
#include "DebugMap.h"
-#include "ErrorReporting.h"
#include "MachOUtils.h"
#include "llvm/ADT/Optional.h"
#include "llvm/Object/MachO.h"
#include "llvm/Support/Path.h"
+#include "llvm/Support/WithColor.h"
#include "llvm/Support/raw_ostream.h"
namespace {
StringRef BinaryPath);
void Warning(const Twine &Msg, StringRef File = StringRef()) {
- warn_ostream() << "("
- << MachOUtils::getArchName(Result->getTriple().getArchName())
- << ") " << File << " " << Msg << "\n";
+ WithColor::warning() << "("
+ << MachOUtils::getArchName(
+ Result->getTriple().getArchName())
+ << ") " << File << " " << Msg << "\n";
if (PaperTrailWarnings) {
if (!File.empty())
#include "MachOUtils.h"
#include "BinaryHolder.h"
#include "DebugMap.h"
-#include "ErrorReporting.h"
#include "NonRelocatableStringpool.h"
#include "dsymutil.h"
#include "llvm/MC/MCAsmLayout.h"
#include "llvm/Object/MachO.h"
#include "llvm/Support/FileUtilities.h"
#include "llvm/Support/Program.h"
+#include "llvm/Support/WithColor.h"
#include "llvm/Support/raw_ostream.h"
namespace llvm {
Path = sys::findProgramByName("lipo");
if (!Path) {
- error_ostream() << "lipo: " << Path.getError().message() << "\n";
+ WithColor::error() << "lipo: " << Path.getError().message() << "\n";
return false;
}
int result =
sys::ExecuteAndWait(*Path, Args.data(), nullptr, {}, 0, 0, &ErrMsg);
if (result) {
- error_ostream() << "lipo: " << ErrMsg << "\n";
+ WithColor::error() << "lipo: " << ErrMsg << "\n";
return false;
}
StringRef From(ArchFiles.front().Path);
if (sys::fs::rename(From, OutputFileName)) {
if (std::error_code EC = sys::fs::copy_file(From, OutputFileName)) {
- error_ostream() << "while copying " << From << " to " << OutputFileName
- << ": " << EC.message() << "\n";
+ WithColor::error() << "while copying " << From << " to "
+ << OutputFileName << ": " << EC.message() << "\n";
return false;
}
sys::fs::remove(From);
#include "dsymutil.h"
#include "CFBundle.h"
#include "DebugMap.h"
-#include "ErrorReporting.h"
#include "MachOUtils.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Support/ThreadPool.h"
+#include "llvm/Support/WithColor.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/thread.h"
#include <algorithm>
std::error_code EC;
llvm::raw_fd_ostream PL(InfoPlist, EC, llvm::sys::fs::F_Text);
if (EC) {
- error_ostream() << "cannot create plist file " << InfoPlist << ": "
- << EC.message() << '\n';
+ WithColor::error() << "cannot create plist file " << InfoPlist << ": "
+ << EC.message() << '\n';
return false;
}
llvm::sys::path::append(Bundle, "Contents", "Resources", "DWARF");
if (std::error_code EC = create_directories(Bundle.str(), true,
llvm::sys::fs::perms::all_all)) {
- error_ostream() << "cannot create directory " << Bundle << ": "
- << EC.message() << "\n";
+ WithColor::error() << "cannot create directory " << Bundle << ": "
+ << EC.message() << "\n";
return false;
}
return true;
static bool verify(llvm::StringRef OutputFile, llvm::StringRef Arch) {
if (OutputFile == "-") {
- warn_ostream() << "verification skipped for " << Arch
- << "because writing to stdout.\n";
+ WithColor::warning() << "verification skipped for " << Arch
+ << "because writing to stdout.\n";
return true;
}
DIDumpOptions DumpOpts;
bool success = DICtx->verify(os, DumpOpts.noImplicitRecursion());
if (!success)
- error_ostream() << "verification failed for " << Arch << '\n';
+ WithColor::error() << "verification failed for " << Arch << '\n';
return success;
}
auto OptionsOrErr = getOptions();
if (!OptionsOrErr) {
- error_ostream() << toString(OptionsOrErr.takeError());
+ WithColor::error() << toString(OptionsOrErr.takeError());
return 1;
}
auto InputsOrErr = getInputs(OptionsOrErr->Update);
if (!InputsOrErr) {
- error_ostream() << toString(InputsOrErr.takeError()) << '\n';
+ WithColor::error() << toString(InputsOrErr.takeError()) << '\n';
return 1;
}
if (!FlatOut && OutputFileOpt == "-") {
- error_ostream() << "cannot emit to standard output without --flat\n";
+ WithColor::error() << "cannot emit to standard output without --flat\n";
return 1;
}
if (InputsOrErr->size() > 1 && FlatOut && !OutputFileOpt.empty()) {
- error_ostream() << "cannot use -o with multiple inputs in flat mode\n";
+ WithColor::error() << "cannot use -o with multiple inputs in flat mode\n";
return 1;
}
PaperTrailWarnings = true;
if (PaperTrailWarnings && InputIsYAMLDebugMap)
- warn_ostream() << "Paper trail warnings are not supported for YAML input";
+ WithColor::warning()
+ << "Paper trail warnings are not supported for YAML input";
for (const auto &Arch : ArchFlags)
if (Arch != "*" && Arch != "all" &&
!llvm::object::MachOObjectFile::isValidArch(Arch)) {
- error_ostream() << "unsupported cpu architecture: '" << Arch << "'\n";
+ WithColor::error() << "unsupported cpu architecture: '" << Arch << "'\n";
return 1;
}
Verbose, InputIsYAMLDebugMap);
if (auto EC = DebugMapPtrsOrErr.getError()) {
- error_ostream() << "cannot parse the debug map for '" << InputFile
- << "': " << EC.message() << '\n';
+ WithColor::error() << "cannot parse the debug map for '" << InputFile
+ << "': " << EC.message() << '\n';
return 1;
}
// Ensure that the debug map is not empty (anymore).
if (DebugMapPtrsOrErr->empty()) {
- error_ostream() << "no architecture to link\n";
+ WithColor::error() << "no architecture to link\n";
return 1;
}
continue;
if (Map->begin() == Map->end())
- warn_ostream() << "no debug symbols in executable (-arch "
- << MachOUtils::getArchName(
- Map->getTriple().getArchName())
- << ")\n";
+ WithColor::warning()
+ << "no debug symbols in executable (-arch "
+ << MachOUtils::getArchName(Map->getTriple().getArchName()) << ")\n";
// Using a std::shared_ptr rather than std::unique_ptr because move-only
// types don't work with std::bind in the ThreadPool implementation.