From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2124) id 4DF643856DE8; Tue, 9 Aug 2022 13:58:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4DF643856DE8 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Nick Clifton To: bfd-cvs@sourceware.org Subject: [binutils-gdb] Default to enabling colored disassembly if output is to a terminal. X-Act-Checkin: binutils-gdb X-Git-Author: Nick Clifton X-Git-Refname: refs/heads/master X-Git-Oldrev: 80d362484999634e11d2b9f9e6d69e2cd4fdba12 X-Git-Newrev: a88c79b77036e4778e70d62081c3cfd1044bb8e3 Message-Id: <20220809135823.4DF643856DE8@sourceware.org> Date: Tue, 9 Aug 2022 13:58:23 +0000 (GMT) X-BeenThere: binutils-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Aug 2022 13:58:23 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Da88c79b77036= e4778e70d62081c3cfd1044bb8e3 commit a88c79b77036e4778e70d62081c3cfd1044bb8e3 Author: Nick Clifton Date: Tue Aug 9 14:57:48 2022 +0100 Default to enabling colored disassembly if output is to a terminal. =20 PR 29457 * objdump.c (disassembler_color): Change type to an enum. (disassembler_extended_color): Remove. (usage): Update. (objdump_color_for_assembler_style): Update. (main): Update initialisation of disassembler_color. If not initialised via a command line option, set based upon terminal output. * doc/binutils.texi: Update description of disassmbler-color option. * testsuite/binutils-all/arc/objdump.exp: Add --disassembler-color=3Doff option when disassembling. * testsuite/binutils-all/arm/objdump.exp: Likewise. Diff: --- binutils/ChangeLog | 16 ++++++ binutils/doc/binutils.texi | 3 ++ binutils/objdump.c | 67 ++++++++++++++++++---= ---- binutils/testsuite/binutils-all/arc/objdump.exp | 2 +- binutils/testsuite/binutils-all/arm/objdump.exp | 2 +- 5 files changed, 71 insertions(+), 19 deletions(-) diff --git a/binutils/ChangeLog b/binutils/ChangeLog index 2bf250649f2..e911f44de7c 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,3 +1,19 @@ +2022-08-09 Nick Clifton + + PR 29457 + * objdump.c (disassembler_color): Change type to an enum. + (disassembler_extended_color): Remove. + (usage): Update. + (objdump_color_for_assembler_style): Update. + (main): Update initialisation of disassembler_color. If not + initialised via a command line option, set based upon terminal + output. + * doc/binutils.texi: Update description of disassmbler-color + option. + * testsuite/binutils-all/arc/objdump.exp: Add + --disassembler-color=3Doff option when disassembling. + * testsuite/binutils-all/arm/objdump.exp: Likewise. + 2022-08-08 Nick Clifton =20 * README-how-to-make-a-release: Add a link to the NEWS files in diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi index 81be746a17b..41f38f479f6 100644 --- a/binutils/doc/binutils.texi +++ b/binutils/doc/binutils.texi @@ -2828,6 +2828,9 @@ If it is necessary to disable the @option{--disassemb= ler-color} option after it has previously been enabled then use @option{--disassembler-color=3Doff}. =20 +If this option is not specified then the default is to enable color +output if displaying to a terminal, but not otherwise. + @item -W[lLiaprmfFsoORtUuTgAckK] @itemx --dwarf[=3Drawline,=3Ddecodedline,=3Dinfo,=3Dabbrev,=3Dpubnames,=3D= aranges,=3Dmacro,=3Dframes,=3Dframes-interp,=3Dstr,=3Dstr-offsets,=3Dloc,= =3DRanges,=3Dpubtypes,=3Dtrace_info,=3Dtrace_abbrev,=3Dtrace_aranges,=3Dgdb= _index,=3Daddr,=3Dcu_index,=3Dlinks,=3Dfollow-links] @include debug.options.texi diff --git a/binutils/objdump.c b/binutils/objdump.c index 4076587151c..08c335476ff 100644 --- a/binutils/objdump.c +++ b/binutils/objdump.c @@ -130,8 +130,14 @@ static bool visualize_jumps =3D false; /* --visualize-= jumps. */ static bool color_output =3D false; /* --visualize-jumps=3Dcolor. */ static bool extended_color_output =3D false; /* --visualize-jumps=3Dextend= ed-color. */ static int process_links =3D false; /* --process-links. */ -static bool disassembler_color =3D false; /* --disassembler-color=3Dcolor.= */ -static bool disassembler_extended_color =3D false; /* --disassembler-color= =3Dextended-color. */ + +static enum color_selection + { + on_if_terminal_output, + on, /* --disassembler-color=3Dcolor. */ + off, /* --disassembler-color=3Doff. */ + extended /* --disassembler-color=3Dextended-color. */ + } disassembler_color =3D on_if_terminal_output; =20 static int dump_any_debugging; static int demangle_flags =3D DMGL_ANSI | DMGL_PARAMS; @@ -409,6 +415,8 @@ usage (FILE *stream, int status) --disassembler-color=3Doff Disable disassembler color output.\n\n"= )); fprintf (stream, _("\ --disassembler-color=3Dcolor Use basic colors in disassembler output= .\n\n")); + fprintf (stream, _("\ + --disassembler-color=3Dextended-color Use 8-bit colors in disassembl= er output.\n\n")); =20 list_supported_targets (program_name, stream); list_supported_architectures (program_name, stream); @@ -2158,44 +2166,66 @@ objdump_color_for_disassembler_style (enum disassem= bler_style style) if (style =3D=3D dis_style_comment_start) disassembler_in_comment =3D true; =20 - if (disassembler_color) + if (disassembler_color =3D=3D on) { if (disassembler_in_comment) return color; =20 switch (style) { - case dis_style_symbol: color =3D 32; break; + case dis_style_symbol: + color =3D 32; + break; case dis_style_assembler_directive: case dis_style_sub_mnemonic: - case dis_style_mnemonic: color =3D 33; break; - case dis_style_register: color =3D 34; break; + case dis_style_mnemonic: + color =3D 33; + break; + case dis_style_register: + color =3D 34; + break; case dis_style_address: case dis_style_address_offset: - case dis_style_immediate: color =3D 35; break; + case dis_style_immediate: + color =3D 35; + break; default: - case dis_style_text: color =3D -1; break; + case dis_style_text: + color =3D -1; + break; } } - else if (disassembler_extended_color) + else if (disassembler_color =3D=3D extended) { if (disassembler_in_comment) return 250; =20 switch (style) { - case dis_style_symbol: color =3D 40; break; + case dis_style_symbol: + color =3D 40; + break; case dis_style_assembler_directive: case dis_style_sub_mnemonic: - case dis_style_mnemonic: color =3D 142; break; - case dis_style_register: color =3D 27; break; + case dis_style_mnemonic: + color =3D 142; + break; + case dis_style_register: + color =3D 27; + break; case dis_style_address: case dis_style_address_offset: - case dis_style_immediate: color =3D 134; break; + case dis_style_immediate: + color =3D 134; + break; default: - case dis_style_text: color =3D -1; break; + case dis_style_text: + color =3D -1; + break; } } + else if (disassembler_color !=3D off) + bfd_fatal (_("disassembly color not correctly selected")); =20 return color; } @@ -5683,11 +5713,11 @@ main (int argc, char **argv) break; case OPTION_DISASSEMBLER_COLOR: if (streq (optarg, "off")) - disassembler_color =3D false; + disassembler_color =3D off; else if (streq (optarg, "color")) - disassembler_color =3D true; + disassembler_color =3D on; else if (streq (optarg, "extended-color")) - disassembler_extended_color =3D true; + disassembler_color =3D extended; else nonfatal (_("unrecognized argument to --disassembler-color")); break; @@ -5900,6 +5930,9 @@ main (int argc, char **argv) } } =20 + if (disassembler_color =3D=3D on_if_terminal_output) + disassembler_color =3D isatty (1) ? on : off; + if (show_version) print_version ("objdump"); =20 diff --git a/binutils/testsuite/binutils-all/arc/objdump.exp b/binutils/tes= tsuite/binutils-all/arc/objdump.exp index fe698550d30..6ade0132a7e 100644 --- a/binutils/testsuite/binutils-all/arc/objdump.exp +++ b/binutils/testsuite/binutils-all/arc/objdump.exp @@ -56,7 +56,7 @@ proc check_assembly { testname objfile expected { disas_f= lags "" } } { fail $testname return } - set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS --disassemble $disas_fla= gs \ + set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS --disassemble --disassem= bler-color=3Doff $disas_flags \ $objfile"] =20 if [regexp $expected $got] then { diff --git a/binutils/testsuite/binutils-all/arm/objdump.exp b/binutils/tes= tsuite/binutils-all/arm/objdump.exp index 059ef1e707c..9cd057e60f1 100644 --- a/binutils/testsuite/binutils-all/arm/objdump.exp +++ b/binutils/testsuite/binutils-all/arm/objdump.exp @@ -41,7 +41,7 @@ if {![binutils_assemble $srcdir/$subdir/thumb2-cond.s tmp= dir/thumb2-cond.o]} the =20 # Make sure that conditional instructions are correctly decoded. =20 - set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS --disassemble --start-ad= dress=3D6 $objfile"] + set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS --disassemble --disassem= bler-color=3Doff --start-address=3D6 $objfile"] =20 set want "bcc.w\[ \t\]*e12.*bx\[ \t\]*lr"