1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00

[dsymutil] Unify error handling outside DwarfLinker.

This is a follow-up to r327137 where we unified error handling for the
DwarfLinker. This replaces calls to errs() and outs() with the
appropriate ostream wrapper everywhere in dsymutil.

llvm-svn: 327411
This commit is contained in:
Jonas Devlieghere 2018-03-13 15:47:38 +00:00
parent 1980e1749b
commit 7aa3e9822f
8 changed files with 79 additions and 52 deletions

View File

@ -35,5 +35,5 @@ ARM64-NOT: ---
CHECK: ...
BADARCH: error: Unsupported cpu architecture: 'arm42'
BADARCH: error: unsupported cpu architecture: 'arm42'
EMPTY: error: no architecture to link

View File

@ -71,9 +71,9 @@ CHECK-ARCHIVE: ...
Check that we warn about missing object files (this presumes that the files aren't
present in the machine's /Inputs/ folder, which should be a pretty safe bet).
NOT-FOUND: cannot open{{.*}}"/Inputs/basic1.macho.x86_64.o": {{[Nn]o}} such file
NOT-FOUND: cannot open{{.*}}"/Inputs/basic2.macho.x86_64.o": {{[Nn]o}} such file
NOT-FOUND: cannot open{{.*}}"/Inputs/basic3.macho.x86_64.o": {{[Nn]o}} such file
NOT-FOUND: cannot open{{.*}}'/Inputs/basic1.macho.x86_64.o': {{[Nn]o}} such file
NOT-FOUND: cannot open{{.*}}'/Inputs/basic2.macho.x86_64.o': {{[Nn]o}} such file
NOT-FOUND: cannot open{{.*}}'/Inputs/basic3.macho.x86_64.o': {{[Nn]o}} such file
NOT-FOUND: ---
NOT-FOUND-NEXT: triple: 'x86_64-apple-darwin'
NOT-FOUND-NEXT: binary-path:{{.*}}/Inputs/basic.macho.x86_64
@ -81,5 +81,5 @@ NOT-FOUND-NEXT: ...
Check that we correctly error out on invalid executatble.
NO-EXECUTABLE: cannot parse{{.*}}/inexistant": {{[Nn]o}} such file
NO-EXECUTABLE: cannot parse{{.*}}/inexistant': {{[Nn]o}} such file
NO-EXECUTABLE-NOT: ---

View File

@ -9,6 +9,7 @@
#include "DebugMap.h"
#include "BinaryHolder.h"
#include "ErrorReporting.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringMap.h"
@ -241,7 +242,7 @@ MappingTraits<dsymutil::DebugMapObject>::YamlDMO::denormalize(IO &IO) {
sys::path::append(Path, Filename);
auto ErrOrObjectFiles = BinHolder.GetObjectFiles(Path);
if (auto EC = ErrOrObjectFiles.getError()) {
errs() << "warning: Unable to open " << Path << " " << EC.message() << '\n';
warn_ostream() << "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 llvm-dsymutil without

View File

@ -9,6 +9,7 @@
#include "BinaryHolder.h"
#include "DebugMap.h"
#include "ErrorReporting.h"
#include "MachOUtils.h"
#include "NonRelocatableStringpool.h"
#include "dsymutil.h"
@ -78,7 +79,6 @@
#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"
@ -580,19 +580,7 @@ static bool inFunctionScope(CompileUnit &U, unsigned Idx) {
}
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
} // namespace
void warn(Twine Warning, Twine Context) {
warn_ostream() << Warning + "\n";
@ -4171,7 +4159,7 @@ bool DwarfLinker::link(const DebugMap &Map) {
StringRef File = LinkContext.DMO.getObjectFilename();
auto ErrorOrMem = MemoryBuffer::getFile(File);
if (!ErrorOrMem) {
errs() << "Warning: Could not open " << File << "\n";
warn("Could not open '" + File + "'\n");
continue;
}
sys::fs::file_status Stat;
@ -4353,5 +4341,5 @@ bool linkDwarf(raw_fd_ostream &OutFile, const DebugMap &DM,
return Linker.link(DM);
}
} // end namespace dsymutil
} // end namespace llvm
} // namespace dsymutil
} // namespace llvm

View File

@ -0,0 +1,33 @@
//===- 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 &note_ostream() {
return WithColor(errs(), HighlightColor::Note).get() << "note: ";
}
} // namespace dsymutil
} // end namespace llvm
#endif // LLVM_TOOLS_DSYMUTIL_ERRORREPORTING_H

View File

@ -9,6 +9,7 @@
#include "BinaryHolder.h"
#include "DebugMap.h"
#include "ErrorReporting.h"
#include "llvm/ADT/Optional.h"
#include "llvm/Object/MachO.h"
#include "llvm/Support/Path.h"
@ -97,7 +98,7 @@ private:
StringRef BinaryPath);
};
static void Warning(const Twine &Msg) { errs() << "warning: " + Msg + "\n"; }
static void Warning(const Twine &Msg) { warn_ostream() << Msg << '\n'; }
} // anonymous namespace
/// Reset the parser state corresponding to the current object
@ -121,16 +122,17 @@ void MachODebugMapParser::switchToNewDebugMapObject(
auto MachOOrError =
CurrentObjectHolder.GetFilesAs<MachOObjectFile>(Path, Timestamp);
if (auto Error = MachOOrError.getError()) {
Warning(Twine("cannot open debug object \"") + Path.str() +
"\": " + Error.message() + "\n");
Warning(Twine("cannot open debug object '") + Path.str() +
"': " + Error.message());
return;
}
auto ErrOrAchObj =
CurrentObjectHolder.GetAs<MachOObjectFile>(Result->getTriple());
if (auto Err = ErrOrAchObj.getError()) {
return Warning(Twine("cannot open debug object \"") + Path.str() +
"\": " + Err.message() + "\n");
if (auto Error = ErrOrAchObj.getError()) {
Warning(Twine("cannot open debug object '") + Path.str() +
"': " + Error.message());
return;
}
CurrentDebugMapObject =

View File

@ -10,6 +10,7 @@
#include "MachOUtils.h"
#include "BinaryHolder.h"
#include "DebugMap.h"
#include "ErrorReporting.h"
#include "NonRelocatableStringpool.h"
#include "dsymutil.h"
#include "llvm/MC/MCAsmLayout.h"
@ -38,7 +39,7 @@ static bool runLipo(StringRef SDKPath, SmallVectorImpl<const char *> &Args) {
Path = sys::findProgramByName("lipo");
if (!Path) {
errs() << "error: lipo: " << Path.getError().message() << "\n";
error_ostream() << "lipo: " << Path.getError().message() << "\n";
return false;
}
@ -46,7 +47,7 @@ static bool runLipo(StringRef SDKPath, SmallVectorImpl<const char *> &Args) {
int result =
sys::ExecuteAndWait(*Path, Args.data(), nullptr, {}, 0, 0, &ErrMsg);
if (result) {
errs() << "error: lipo: " << ErrMsg << "\n";
error_ostream() << "lipo: " << ErrMsg << "\n";
return false;
}
@ -63,7 +64,7 @@ bool generateUniversalBinary(SmallVectorImpl<ArchAndFilename> &ArchFiles,
StringRef From(ArchFiles.front().Path);
if (sys::fs::rename(From, OutputFileName)) {
if (std::error_code EC = sys::fs::copy_file(From, OutputFileName)) {
errs() << "error: while copying " << From << " to " << OutputFileName
error_ostream() << "while copying " << From << " to " << OutputFileName
<< ": " << EC.message() << "\n";
return false;
}

View File

@ -15,6 +15,7 @@
#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"
@ -156,7 +157,7 @@ static bool createPlistFile(llvm::StringRef Bin, llvm::StringRef BundleRoot) {
std::error_code EC;
llvm::raw_fd_ostream PL(InfoPlist, EC, llvm::sys::fs::F_Text);
if (EC) {
llvm::errs() << "error: cannot create plist file " << InfoPlist << ": "
error_ostream() << "cannot create plist file " << InfoPlist << ": "
<< EC.message() << '\n';
return false;
}
@ -214,7 +215,7 @@ static bool createBundleDir(llvm::StringRef BundleBase) {
llvm::sys::path::append(Bundle, "Contents", "Resources", "DWARF");
if (std::error_code EC = create_directories(Bundle.str(), true,
llvm::sys::fs::perms::all_all)) {
llvm::errs() << "error: cannot create directory " << Bundle << ": "
error_ostream() << "cannot create directory " << Bundle << ": "
<< EC.message() << "\n";
return false;
}
@ -223,7 +224,7 @@ static bool createBundleDir(llvm::StringRef BundleBase) {
static bool verify(llvm::StringRef OutputFile, llvm::StringRef Arch) {
if (OutputFile == "-") {
llvm::errs() << "warning: verification skipped for " << Arch
warn_ostream() << "verification skipped for " << Arch
<< "because writing to stdout.\n";
return true;
}
@ -242,7 +243,7 @@ static bool verify(llvm::StringRef OutputFile, llvm::StringRef Arch) {
DIDumpOptions DumpOpts;
bool success = DICtx->verify(os, DumpOpts.noImplicitRecursion());
if (!success)
errs() << "error: verification failed for " << Arch << '\n';
error_ostream() << "verification failed for " << Arch << '\n';
return success;
}
@ -314,7 +315,7 @@ static Expected<LinkOptions> getOptions() {
// used a unique BinaryHolder object that could cache multiple
// binaries this restriction would go away.
return make_error<StringError>(
"error: standard input cannot be used as input for a dSYM update.",
"standard input cannot be used as input for a dSYM update.",
inconvertibleErrorCode());
}
@ -404,7 +405,7 @@ int main(int argc, char **argv) {
auto OptionsOrErr = getOptions();
if (!OptionsOrErr) {
errs() << "error: " << toString(OptionsOrErr.takeError());
error_ostream() << toString(OptionsOrErr.takeError());
return 1;
}
@ -415,24 +416,24 @@ int main(int argc, char **argv) {
auto InputsOrErr = getInputs(OptionsOrErr->Update);
if (!InputsOrErr) {
errs() << "error: " << toString(InputsOrErr.takeError()) << '\n';
error_ostream() << toString(InputsOrErr.takeError()) << '\n';
return 1;
}
if (!FlatOut && OutputFileOpt == "-") {
llvm::errs() << "error: cannot emit to standard output without --flat\n";
error_ostream() << "cannot emit to standard output without --flat\n";
return 1;
}
if (InputsOrErr->size() > 1 && FlatOut && !OutputFileOpt.empty()) {
llvm::errs() << "error: cannot use -o with multiple inputs in flat mode\n";
error_ostream() << "cannot use -o with multiple inputs in flat mode\n";
return 1;
}
for (const auto &Arch : ArchFlags)
if (Arch != "*" && Arch != "all" &&
!llvm::object::MachOObjectFile::isValidArch(Arch)) {
llvm::errs() << "error: Unsupported cpu architecture: '" << Arch << "'\n";
error_ostream() << "unsupported cpu architecture: '" << Arch << "'\n";
return 1;
}
@ -448,8 +449,8 @@ int main(int argc, char **argv) {
Verbose, InputIsYAMLDebugMap);
if (auto EC = DebugMapPtrsOrErr.getError()) {
llvm::errs() << "error: cannot parse the debug map for \"" << InputFile
<< "\": " << EC.message() << '\n';
error_ostream() << "cannot parse the debug map for '" << InputFile
<< "': " << EC.message() << '\n';
return 1;
}
@ -463,7 +464,7 @@ int main(int argc, char **argv) {
// Ensure that the debug map is not empty (anymore).
if (DebugMapPtrsOrErr->empty()) {
llvm::errs() << "error: no architecture to link\n";
error_ostream() << "no architecture to link\n";
return 1;
}
@ -492,8 +493,9 @@ int main(int argc, char **argv) {
continue;
if (Map->begin() == Map->end())
llvm::errs() << "warning: no debug symbols in executable (-arch "
<< MachOUtils::getArchName(Map->getTriple().getArchName())
warn_ostream() << "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