Skip to content
This repository was archived by the owner on Jan 1, 2023. It is now read-only.

Commit 85e70cc

Browse files
committed
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@327137 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent cba436d commit 85e70cc

File tree

4 files changed

+46
-19
lines changed

4 files changed

+46
-19
lines changed

test/tools/dsymutil/X86/module-warnings.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
# STATIC: warning: {{.*}}Bar.pcm:
4343
# STATIC: note: Linking a static library
4444
# STATIC: warning: {{.*}}Foo.pcm:
45-
# STATIC-NOT: note:
45+
# STATIC-NOT: warning:
4646

4747
---
4848
triple: 'x86_64-apple-darwin'

test/tools/dsymutil/X86/swift-ast-x86_64.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ READOBJ: |SWIFTMODULE DATA|
1616
READOBJ-NEXT: |.|
1717

1818
RUN: llvm-dsymutil -oso-prepend-path %p/.. %p/../Inputs/swift-ast.macho.x86_64 -no-output -verbose 2>&1 | FileCheck %s --check-prefix=TIMESTAMP
19-
TIMESTAMP: Warning: Timestamp mismatch
19+
TIMESTAMP: warning: Timestamp mismatch

tools/dsymutil/DwarfLinker.cpp

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
#include "llvm/Support/Path.h"
7777
#include "llvm/Support/TargetRegistry.h"
7878
#include "llvm/Support/ToolOutputFile.h"
79+
#include "llvm/Support/WithColor.h"
7980
#include "llvm/Support/raw_ostream.h"
8081
#include "llvm/Target/TargetMachine.h"
8182
#include "llvm/Target/TargetOptions.h"
@@ -564,8 +565,32 @@ static bool inFunctionScope(CompileUnit &U, unsigned Idx) {
564565
return false;
565566
}
566567

568+
static raw_ostream &error_ostream() {
569+
return WithColor(errs(), HighlightColor::Error).get() << "error: ";
570+
}
571+
572+
static raw_ostream &warn_ostream() {
573+
return WithColor(errs(), HighlightColor::Warning).get() << "warning: ";
574+
}
575+
576+
static raw_ostream &note_ostream() {
577+
return WithColor(errs(), HighlightColor::Note).get() << "note: ";
578+
}
567579
} // end anonymous namespace
568580

581+
void warn(Twine Warning, Twine Context) {
582+
warn_ostream() << Warning + "\n";
583+
if (!Context.isTriviallyEmpty())
584+
note_ostream() << Twine("while processing ") + Context + ":\n";
585+
}
586+
587+
bool error(Twine Error, Twine Context) {
588+
error_ostream() << Error + "\n";
589+
if (!Context.isTriviallyEmpty())
590+
note_ostream() << Twine("while processing ") + Context + ":\n";
591+
return false;
592+
}
593+
569594
void CompileUnit::markEverythingAsKept() {
570595
unsigned Idx = 0;
571596

@@ -2092,7 +2117,7 @@ void DwarfLinker::reportWarning(const Twine &Warning,
20922117
DumpOpts.RecurseDepth = 0;
20932118
DumpOpts.Verbose = Options.Verbose;
20942119

2095-
errs() << " in DIE:\n";
2120+
note_ostream() << " in DIE:\n";
20962121
DIE->dump(errs(), 6 /* Indent */, DumpOpts);
20972122
}
20982123

@@ -3882,9 +3907,9 @@ Error DwarfLinker::loadClangModule(StringRef Filename, StringRef ModulePath,
38823907
// cache has expired and was pruned by clang. A more adventurous
38833908
// dsymutil would invoke clang to rebuild the module now.
38843909
if (!ModuleCacheHintDisplayed) {
3885-
errs() << "note: The clang module cache may have expired since this "
3886-
"object file was built. Rebuilding the object file will "
3887-
"rebuild the module cache.\n";
3910+
note_ostream() << "The clang module cache may have expired since "
3911+
"this object file was built. Rebuilding the "
3912+
"object file will rebuild the module cache.\n";
38883913
ModuleCacheHintDisplayed = true;
38893914
}
38903915
} else if (isArchive) {
@@ -3893,11 +3918,12 @@ Error DwarfLinker::loadClangModule(StringRef Filename, StringRef ModulePath,
38933918
// was built on a different machine. We don't want to discourage module
38943919
// debugging for convenience libraries within a project though.
38953920
if (!ArchiveHintDisplayed) {
3896-
errs() << "note: Linking a static library that was built with "
3897-
"-gmodules, but the module cache was not found. "
3898-
"Redistributable static libraries should never be built "
3899-
"with module debugging enabled. The debug experience will "
3900-
"be degraded due to incomplete debug information.\n";
3921+
note_ostream() << "Linking a static library that was built with "
3922+
"-gmodules, but the module cache was not found. "
3923+
"Redistributable static libraries should never be "
3924+
"built with module debugging enabled. The debug "
3925+
"experience will be degraded due to incomplete "
3926+
"debug information.\n";
39013927
ArchiveHintDisplayed = true;
39023928
}
39033929
}
@@ -3921,7 +3947,7 @@ Error DwarfLinker::loadClangModule(StringRef Filename, StringRef ModulePath,
39213947
(Filename +
39223948
": Clang modules are expected to have exactly 1 compile unit.\n")
39233949
.str();
3924-
errs() << Err;
3950+
error(Err);
39253951
return make_error<StringError>(Err, inconvertibleErrorCode());
39263952
}
39273953
// FIXME: Until PR27449 (https://llvm.org/bugs/show_bug.cgi?id=27449) is
@@ -4034,15 +4060,16 @@ bool DwarfLinker::link(const DebugMap &Map) {
40344060
continue;
40354061
}
40364062
sys::fs::file_status Stat;
4037-
if (auto errc = sys::fs::status(File, Stat)) {
4038-
errs() << "Warning: " << errc.message() << "\n";
4063+
if (auto Err = sys::fs::status(File, Stat)) {
4064+
warn(Err.message());
40394065
continue;
40404066
}
40414067
if (!Options.NoTimestamp && Stat.getLastModificationTime() !=
40424068
sys::TimePoint<>(Obj->getTimestamp())) {
4043-
errs() << "Warning: Timestamp mismatch for " << File << ": "
4044-
<< Stat.getLastModificationTime() << " and "
4045-
<< sys::TimePoint<>(Obj->getTimestamp()) << "\n";
4069+
// Not using the helper here as we can easily stream TimePoint<>.
4070+
warn_ostream() << "Timestamp mismatch for " << File << ": "
4071+
<< Stat.getLastModificationTime() << " and "
4072+
<< sys::TimePoint<>(Obj->getTimestamp()) << "\n";
40464073
continue;
40474074
}
40484075

tools/dsymutil/dsymutil.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ bool dumpStab(StringRef InputFile, ArrayRef<std::string> Archs,
7070
bool linkDwarf(raw_fd_ostream &OutFile, const DebugMap &DM,
7171
const LinkOptions &Options);
7272

73-
void warn(const Twine &Warning, const Twine &Context);
74-
bool error(const Twine &Error, const Twine &Context);
73+
void warn(Twine Warning, Twine Context = {});
74+
bool error(Twine Error, Twine Context = {});
7575

7676
} // end namespace dsymutil
7777
} // end namespace llvm

0 commit comments

Comments
 (0)