Skip to content

Commit 1e97d11

Browse files
authored
[dsymutil] Add -q/--quiet flag to suppress warnings (llvm#91658)
Add a -q/--quiet flag to suppress dsymutil output. For now the flag is limited to dsymutil, though there might be other places in the DWARF linker that could be conditionalized by this flag. The motivation is having a way to silence the "no debug symbols in executable" warning. This is useful when we want to generate a dSYM for a binary not containing debug symbols, but still want a dSYM that can be indexed by spotlight. rdar://127843467
1 parent 8a3277a commit 1e97d11

File tree

6 files changed

+51
-15
lines changed

6 files changed

+51
-15
lines changed

llvm/docs/CommandGuide/dsymutil.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ OPTIONS
115115
Specifies an alternate ``path`` to place the dSYM bundle. The default dSYM
116116
bundle path is created by appending ``.dSYM`` to the executable name.
117117

118+
.. option:: -q, --quiet
119+
120+
Enable quiet mode and limit output.
121+
118122
.. option:: --remarks-drop-without-debug
119123

120124
Drop remarks without valid debug locations. Without this flags, all remarks are kept.

llvm/test/tools/dsymutil/ARM/empty-map.test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# RUN: dsymutil -f -oso-prepend-path=%p/../Inputs -y %s -o - 2>&1 | FileCheck %s
2+
# RUN: dsymutil -q -f -oso-prepend-path=%p/../Inputs -y %s -o - 2>&1 | FileCheck %s --check-prefix QUIET
23

34
# RUN: dsymutil --linker parallel -f -oso-prepend-path=%p/../Inputs -y %s -o - 2>&1 | FileCheck %s
45

@@ -7,3 +8,4 @@ triple: 'thumbv7-apple-darwin'
78
...
89

910
# CHECK: warning: no debug symbols in executable (-arch armv7)
11+
# QUIET-NOT: no debug symbols in executable

llvm/test/tools/dsymutil/cmdline.test

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ CHECK: -object-prefix-map <prefix=remapped>
2323
CHECK: -oso-prepend-path <path>
2424
CHECK: -out <filename>
2525
CHECK: {{-o <filename>}}
26+
CHECK: -quiet
2627
CHECK: -remarks-drop-without-debug
2728
CHECK: -remarks-output-format <format>
2829
CHECK: -remarks-prepend-path <path>
@@ -46,3 +47,6 @@ NOINPUT: error: no input files specified
4647

4748
RUN: dsymutil -bogus -help 2>&1 | FileCheck --check-prefix=BOGUS %s
4849
BOGUS: warning: ignoring unknown option: -bogus
50+
51+
RUN: not dsymutil --quiet --verbose 2>&1 | FileCheck --check-prefix=CONFLICT %s
52+
CONFLICT: error: --quiet and --verbose cannot be specified together

llvm/tools/dsymutil/LinkUtils.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ struct LinkOptions {
3838
/// Verbosity
3939
bool Verbose = false;
4040

41+
/// Quiet
42+
bool Quiet = false;
43+
4144
/// Statistics
4245
bool Statistics = false;
4346

llvm/tools/dsymutil/Options.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ def verbose: F<"verbose">,
2424
HelpText<"Enable verbose mode.">,
2525
Group<grp_general>;
2626

27+
def quiet: F<"quiet">,
28+
HelpText<"Enable quiet mode.">,
29+
Group<grp_general>;
30+
def: Flag<["-"], "q">,
31+
Alias<quiet>,
32+
HelpText<"Alias for --quiet">,
33+
Group<grp_general>;
34+
2735
def keep_func_for_static: F<"keep-function-for-static">,
2836
HelpText<"Make a static variable keep the enclosing function even if it would have been omitted otherwise.">,
2937
Group<grp_general>;

llvm/tools/dsymutil/dsymutil.cpp

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,12 @@ static Expected<std::vector<std::string>> getInputs(opt::InputArgList &Args,
169169

170170
// Verify that the given combination of options makes sense.
171171
static Error verifyOptions(const DsymutilOptions &Options) {
172+
if (Options.LinkOpts.Verbose && Options.LinkOpts.Quiet) {
173+
return make_error<StringError>(
174+
"--quiet and --verbose cannot be specified together",
175+
errc::invalid_argument);
176+
}
177+
172178
if (Options.InputFiles.empty()) {
173179
return make_error<StringError>("no input files specified",
174180
errc::invalid_argument);
@@ -311,6 +317,7 @@ static Expected<DsymutilOptions> getOptions(opt::InputArgList &Args) {
311317
Options.LinkOpts.NoTimestamp = Args.hasArg(OPT_no_swiftmodule_timestamp);
312318
Options.LinkOpts.Update = Args.hasArg(OPT_update);
313319
Options.LinkOpts.Verbose = Args.hasArg(OPT_verbose);
320+
Options.LinkOpts.Quiet = Args.hasArg(OPT_quiet);
314321
Options.LinkOpts.Statistics = Args.hasArg(OPT_statistics);
315322
Options.LinkOpts.Fat64 = Args.hasArg(OPT_fat64);
316323
Options.LinkOpts.KeepFunctionForStatic =
@@ -483,16 +490,20 @@ static bool verifyOutput(StringRef OutputFile, StringRef Arch,
483490
DsymutilOptions Options, std::mutex &Mutex) {
484491

485492
if (OutputFile == "-") {
486-
std::lock_guard<std::mutex> Guard(Mutex);
487-
WithColor::warning() << "verification skipped for " << Arch
488-
<< " because writing to stdout.\n";
493+
if (!Options.LinkOpts.Quiet) {
494+
std::lock_guard<std::mutex> Guard(Mutex);
495+
WithColor::warning() << "verification skipped for " << Arch
496+
<< " because writing to stdout.\n";
497+
}
489498
return true;
490499
}
491500

492501
if (Options.LinkOpts.NoOutput) {
493-
std::lock_guard<std::mutex> Guard(Mutex);
494-
WithColor::warning() << "verification skipped for " << Arch
495-
<< " because --no-output was passed.\n";
502+
if (!Options.LinkOpts.Quiet) {
503+
std::lock_guard<std::mutex> Guard(Mutex);
504+
WithColor::warning() << "verification skipped for " << Arch
505+
<< " because --no-output was passed.\n";
506+
}
496507
return true;
497508
}
498509

@@ -507,10 +518,12 @@ static bool verifyOutput(StringRef OutputFile, StringRef Arch,
507518
if (auto *Obj = dyn_cast<MachOObjectFile>(&Binary)) {
508519
std::unique_ptr<DWARFContext> DICtx = DWARFContext::create(*Obj);
509520
if (DICtx->getMaxVersion() > 5) {
510-
std::lock_guard<std::mutex> Guard(Mutex);
511-
WithColor::warning()
512-
<< "verification skipped for " << Arch
513-
<< " because DWARF standard greater than v5 is not supported yet.\n";
521+
if (!Options.LinkOpts.Quiet) {
522+
std::lock_guard<std::mutex> Guard(Mutex);
523+
WithColor::warning() << "verification skipped for " << Arch
524+
<< " because DWARF standard greater than v5 is "
525+
"not supported yet.\n";
526+
}
514527
return true;
515528
}
516529

@@ -751,11 +764,13 @@ int dsymutil_main(int argc, char **argv, const llvm::ToolContext &) {
751764
continue;
752765

753766
if (Map->begin() == Map->end()) {
754-
std::lock_guard<std::mutex> Guard(ErrorHandlerMutex);
755-
WithColor::warning()
756-
<< "no debug symbols in executable (-arch "
757-
<< MachOUtils::getArchName(Map->getTriple().getArchName())
758-
<< ")\n";
767+
if (!Options.LinkOpts.Quiet) {
768+
std::lock_guard<std::mutex> Guard(ErrorHandlerMutex);
769+
WithColor::warning()
770+
<< "no debug symbols in executable (-arch "
771+
<< MachOUtils::getArchName(Map->getTriple().getArchName())
772+
<< ")\n";
773+
}
759774
}
760775

761776
// Using a std::shared_ptr rather than std::unique_ptr because move-only

0 commit comments

Comments
 (0)