From 1aa207d451d0f0a12ebfd8e841ca92be975fe1bc Mon Sep 17 00:00:00 2001 From: Adrian McCarthy Date: Thu, 23 Mar 2017 15:28:15 +0000 Subject: Add option to control whether llvm-pdbdump outputs in color Adds -color-output option to llvm-pdbdump pretty commands that lets the user specify whether the output should have color. The default depends on whether the output is going to a TTY (per prior discussion in https://reviews.llvm.org/D31246). This will enable tests that pipe llvm-pdbdump output to FileCheck to work across platforms without regard to the differences in ANSI codes. Differential Revision: https://reviews.llvm.org/D31263 llvm-svn: 298610 --- llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp') diff --git a/llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp b/llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp index 8b166411f0b..3bd5fd7273b 100644 --- a/llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp +++ b/llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp @@ -125,8 +125,11 @@ cl::opt LoadAddress( cl::desc("Assume the module is loaded at the specified address"), cl::cat(OtherOptions), cl::sub(PrettySubcommand)); cl::opt Native("native", cl::desc("Use native PDB reader instead of DIA"), - cl::cat(OtherOptions), cl::sub(PrettySubcommand)); - + cl::cat(OtherOptions), cl::sub(PrettySubcommand)); +cl::opt + ColorOutput("color-output", + cl::desc("Override use of color (default = isatty)"), + cl::cat(OtherOptions), cl::sub(PrettySubcommand)); cl::list ExcludeTypes( "exclude-types", cl::desc("Exclude types by regular expression"), cl::ZeroOrMore, cl::cat(FilterCategory), cl::sub(PrettySubcommand)); @@ -500,7 +503,11 @@ static void dumpPretty(StringRef Path) { if (opts::pretty::LoadAddress) Session->setLoadAddress(opts::pretty::LoadAddress); - LinePrinter Printer(2, outs()); + auto &Stream = outs(); + const bool UseColor = opts::pretty::ColorOutput == cl::BOU_UNSET + ? Stream.has_colors() + : opts::pretty::ColorOutput == cl::BOU_TRUE; + LinePrinter Printer(2, UseColor, Stream); auto GlobalScope(Session->getGlobalScope()); std::string FileName(GlobalScope->getSymbolsFileName()); -- cgit v1.2.3