Skip to content

[dsymutil] Add -q/--quiet flag to suppress warnings #91658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions llvm/docs/CommandGuide/dsymutil.rst
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ OPTIONS
Specifies an alternate ``path`` to place the dSYM bundle. The default dSYM
bundle path is created by appending ``.dSYM`` to the executable name.

.. option:: -q, --quiet

Enable quiet mode and limit output.

.. option:: --remarks-drop-without-debug

Drop remarks without valid debug locations. Without this flags, all remarks are kept.
Expand Down
2 changes: 2 additions & 0 deletions llvm/test/tools/dsymutil/ARM/empty-map.test
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# RUN: dsymutil -f -oso-prepend-path=%p/../Inputs -y %s -o - 2>&1 | FileCheck %s
# RUN: dsymutil -q -f -oso-prepend-path=%p/../Inputs -y %s -o - 2>&1 | FileCheck %s --check-prefix QUIET

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

Expand All @@ -7,3 +8,4 @@ triple: 'thumbv7-apple-darwin'
...

# CHECK: warning: no debug symbols in executable (-arch armv7)
# QUIET-NOT: no debug symbols in executable
4 changes: 4 additions & 0 deletions llvm/test/tools/dsymutil/cmdline.test
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ CHECK: -object-prefix-map <prefix=remapped>
CHECK: -oso-prepend-path <path>
CHECK: -out <filename>
CHECK: {{-o <filename>}}
CHECK: -quiet
CHECK: -remarks-drop-without-debug
CHECK: -remarks-output-format <format>
CHECK: -remarks-prepend-path <path>
Expand All @@ -46,3 +47,6 @@ NOINPUT: error: no input files specified

RUN: dsymutil -bogus -help 2>&1 | FileCheck --check-prefix=BOGUS %s
BOGUS: warning: ignoring unknown option: -bogus

RUN: not dsymutil --quiet --verbose 2>&1 | FileCheck --check-prefix=CONFLICT %s
CONFLICT: error: --quiet and --verbose cannot be specified together
3 changes: 3 additions & 0 deletions llvm/tools/dsymutil/LinkUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ struct LinkOptions {
/// Verbosity
bool Verbose = false;

/// Quiet
bool Quiet = false;

/// Statistics
bool Statistics = false;

Expand Down
8 changes: 8 additions & 0 deletions llvm/tools/dsymutil/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ def verbose: F<"verbose">,
HelpText<"Enable verbose mode.">,
Group<grp_general>;

def quiet: F<"quiet">,
HelpText<"Enable quiet mode.">,
Group<grp_general>;
def: Flag<["-"], "q">,
Alias<quiet>,
HelpText<"Alias for --quiet">,
Group<grp_general>;

def keep_func_for_static: F<"keep-function-for-static">,
HelpText<"Make a static variable keep the enclosing function even if it would have been omitted otherwise.">,
Group<grp_general>;
Expand Down
45 changes: 30 additions & 15 deletions llvm/tools/dsymutil/dsymutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ static Expected<std::vector<std::string>> getInputs(opt::InputArgList &Args,

// Verify that the given combination of options makes sense.
static Error verifyOptions(const DsymutilOptions &Options) {
if (Options.LinkOpts.Verbose && Options.LinkOpts.Quiet) {
return make_error<StringError>(
"--quiet and --verbose cannot be specified together",
errc::invalid_argument);
}

if (Options.InputFiles.empty()) {
return make_error<StringError>("no input files specified",
errc::invalid_argument);
Expand Down Expand Up @@ -311,6 +317,7 @@ static Expected<DsymutilOptions> getOptions(opt::InputArgList &Args) {
Options.LinkOpts.NoTimestamp = Args.hasArg(OPT_no_swiftmodule_timestamp);
Options.LinkOpts.Update = Args.hasArg(OPT_update);
Options.LinkOpts.Verbose = Args.hasArg(OPT_verbose);
Options.LinkOpts.Quiet = Args.hasArg(OPT_quiet);
Options.LinkOpts.Statistics = Args.hasArg(OPT_statistics);
Options.LinkOpts.Fat64 = Args.hasArg(OPT_fat64);
Options.LinkOpts.KeepFunctionForStatic =
Expand Down Expand Up @@ -483,16 +490,20 @@ static bool verifyOutput(StringRef OutputFile, StringRef Arch,
DsymutilOptions Options, std::mutex &Mutex) {

if (OutputFile == "-") {
std::lock_guard<std::mutex> Guard(Mutex);
WithColor::warning() << "verification skipped for " << Arch
<< " because writing to stdout.\n";
if (!Options.LinkOpts.Quiet) {
std::lock_guard<std::mutex> Guard(Mutex);
WithColor::warning() << "verification skipped for " << Arch
<< " because writing to stdout.\n";
}
return true;
}

if (Options.LinkOpts.NoOutput) {
std::lock_guard<std::mutex> Guard(Mutex);
WithColor::warning() << "verification skipped for " << Arch
<< " because --no-output was passed.\n";
if (!Options.LinkOpts.Quiet) {
std::lock_guard<std::mutex> Guard(Mutex);
WithColor::warning() << "verification skipped for " << Arch
<< " because --no-output was passed.\n";
}
return true;
}

Expand All @@ -507,10 +518,12 @@ static bool verifyOutput(StringRef OutputFile, StringRef Arch,
if (auto *Obj = dyn_cast<MachOObjectFile>(&Binary)) {
std::unique_ptr<DWARFContext> DICtx = DWARFContext::create(*Obj);
if (DICtx->getMaxVersion() > 5) {
std::lock_guard<std::mutex> Guard(Mutex);
WithColor::warning()
<< "verification skipped for " << Arch
<< " because DWARF standard greater than v5 is not supported yet.\n";
if (!Options.LinkOpts.Quiet) {
std::lock_guard<std::mutex> Guard(Mutex);
WithColor::warning() << "verification skipped for " << Arch
<< " because DWARF standard greater than v5 is "
"not supported yet.\n";
}
return true;
}

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

if (Map->begin() == Map->end()) {
std::lock_guard<std::mutex> Guard(ErrorHandlerMutex);
WithColor::warning()
<< "no debug symbols in executable (-arch "
<< MachOUtils::getArchName(Map->getTriple().getArchName())
<< ")\n";
if (!Options.LinkOpts.Quiet) {
std::lock_guard<std::mutex> Guard(ErrorHandlerMutex);
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
Expand Down