Skip to content

Commit

Permalink
[dsymutil] Unify reporting of warnings and errors
Browse files Browse the repository at this point in the history
Make all error reporting in DwarfLinkerForBinary go through the
`reportWarning` and `reportError` wrappers.
  • Loading branch information
JDevlieghere committed Apr 5, 2023
1 parent a76f3d0 commit 25ad7c9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
44 changes: 26 additions & 18 deletions llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,25 +105,33 @@ static mc::RegisterMCTargetOptionsFlags MOF;

namespace dsymutil {

/// Report a warning to the user, optionally including information about a
/// specific \p DIE related to the warning.
void DwarfLinkerForBinary::reportWarning(const Twine &Warning,
StringRef Context,
const DWARFDie *DIE) const {

warn(Warning, Context);

if (!Options.Verbose || !DIE)
static void dumpDIE(const DWARFDie *DIE, bool Verbose) {
if (!DIE || !Verbose)
return;

DIDumpOptions DumpOpts;
DumpOpts.ChildRecurseDepth = 0;
DumpOpts.Verbose = Options.Verbose;
DumpOpts.Verbose = Verbose;

WithColor::note() << " in DIE:\n";
DIE->dump(errs(), 6 /* Indent */, DumpOpts);
}

/// Report a warning to the user, optionally including information about a
/// specific \p DIE related to the warning.
void DwarfLinkerForBinary::reportWarning(Twine Warning, Twine Context,
const DWARFDie *DIE) const {

warn(Warning, Context);
dumpDIE(DIE, Options.Verbose);
}

void DwarfLinkerForBinary::reportError(Twine Error, Twine Context,
const DWARFDie *DIE) const {
error(Error, Context);
dumpDIE(DIE, Options.Verbose);
}

bool DwarfLinkerForBinary::createStreamer(const Triple &TheTriple,
raw_fd_ostream &OutFile) {
if (Options.NoOutput)
Expand All @@ -132,10 +140,10 @@ bool DwarfLinkerForBinary::createStreamer(const Triple &TheTriple,
Streamer = std::make_unique<DwarfStreamer>(
Options.FileType, OutFile, Options.Translator,
[&](const Twine &Error, StringRef Context, const DWARFDie *) {
error(Error, Context);
reportError(Error, Context);
},
[&](const Twine &Warning, StringRef Context, const DWARFDie *) {
warn(Warning, Context);
reportWarning(Warning, Context);
});
return Streamer->init(TheTriple, "__DWARF");
}
Expand Down Expand Up @@ -481,8 +489,8 @@ Error DwarfLinkerForBinary::copySwiftInterfaces(StringRef Architecture) const {

// copy_file attempts an APFS clone first, so this should be cheap.
if ((EC = sys::fs::copy_file(InterfaceFile, Path.str())))
warn(Twine("cannot copy parseable Swift interface ") + InterfaceFile +
": " + toString(errorCodeToError(EC)));
reportWarning(Twine("cannot copy parseable Swift interface ") +
InterfaceFile + ": " + toString(errorCodeToError(EC)));
Path.resize(BaseLength);
}
return Error::success();
Expand Down Expand Up @@ -584,8 +592,8 @@ bool DwarfLinkerForBinary::link(const DebugMap &Map) {
reportWarning(Warning, Context, DIE);
});
GeneralLinker.setErrorHandler(
[&](const Twine &Error, StringRef Context, const DWARFDie *) {
error(Error, Context);
[&](const Twine &Error, StringRef Context, const DWARFDie *DIE) {
reportError(Error, Context, DIE);
});
GeneralLinker.setInputVerificationHandler([&](const DWARFFile &File) {
reportWarning("input verification failed", File.FileName);
Expand Down Expand Up @@ -677,12 +685,12 @@ bool DwarfLinkerForBinary::link(const DebugMap &Map) {
StringRef File = Obj->getObjectFilename();
auto ErrorOrMem = MemoryBuffer::getFile(File);
if (!ErrorOrMem) {
warn("Could not open '" + File + "'");
reportWarning("Could not open '" + File + "'");
continue;
}
sys::fs::file_status Stat;
if (auto Err = sys::fs::status(File, Stat)) {
warn(Err.message());
reportWarning(Err.message());
continue;
}
if (!Options.NoTimestamp) {
Expand Down
4 changes: 3 additions & 1 deletion llvm/tools/dsymutil/DwarfLinkerForBinary.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ class DwarfLinkerForBinary {
/// Link the contents of the DebugMap.
bool link(const DebugMap &);

void reportWarning(const Twine &Warning, StringRef Context,
void reportWarning(Twine Warning, Twine Context = {},
const DWARFDie *DIE = nullptr) const;
void reportError(Twine Error, Twine Context = {},
const DWARFDie *DIE = nullptr) const;

/// Returns true if input verification is enabled and verification errors were
/// found.
Expand Down

0 comments on commit 25ad7c9

Please sign in to comment.