public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Nick Clifton <nickc@redhat.com>
To: Andrew Burgess <aburgess@redhat.com>, binutils@sourceware.org
Subject: Re: [PATCH 2/3] objdump: introduce OBJDUMP_COLORS environment variable
Date: Wed, 10 Aug 2022 16:48:28 +0100	[thread overview]
Message-ID: <1b16772c-59bb-4b66-7ea7-29701c94a3db@redhat.com> (raw)
In-Reply-To: <f7417b830a2f086bcc932be8a283184b4e056643.1660139020.git.aburgess@redhat.com>

Hi Andrew,

> Add OBJDUMP_COLORS environment variable, and allow this to control the
> default behaviour of objdump when --disassembler-color is not used,
> and we are disassembling to a terminal.

Whilst this is a nice idea, there is a problem with using environment
variables: users often fail to include them when reporting a bug.

Imagine for example a bug report about the colored disassembly being
broken somehow and the user has forgotten to mention that they have
OBJDUMP_COLORS set to "extended".  We could waste hours trying to
track down the problem only to find that we had been looking at the
wrong piece of code.

I cannot think of a nice way to resolve this problem.  One idea that
does spring to mind is to have objdump generate a message to stdout
when the environment variable is used.  That way there is a good
likelihood that the message will be included in a bug report.  But
this does mean new, extraneous output will now appear in the
disassembly output.



> +static enum color_selection
> +objdump_default_disassembler_color_mode (void)
> +{
> +  enum color_selection mode;
> +
> +  if (isatty (1))
> +    {
> +      const char *tmp = getenv (objdump_colors_var);
> +
> +      if (tmp == NULL || strncmp (tmp, "color", 5) == 0)

Why strncmp() rather than strcmp () ?  [Because of patch 3/3 I expect...]

> +	mode = on;
> +      if (strncmp (tmp, "extended", 8) == 0)
> +	mode = extended;
> +      else if (strncmp (tmp, "off", 3) == 0)
> +	mode = off;
> +      else
> +	mode = on;

It would probably be best to check for strncmp (tmp, "on") here
and report if there is no match - that way users will know that
they have a malformed OBJDUMP_COLOR environment variable.

Cheers
   Nick


  reply	other threads:[~2022-08-10 15:48 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-10 14:24 [PATCH 0/3] Disassembler styling, bug fixes and customisation Andrew Burgess
2022-08-10 14:24 ` [PATCH 1/3] objdump: fix extended (256) disassembler colors Andrew Burgess
2022-08-10 15:32   ` Nick Clifton
2022-08-10 16:12     ` Andrew Burgess
2022-08-10 14:24 ` [PATCH 2/3] objdump: introduce OBJDUMP_COLORS environment variable Andrew Burgess
2022-08-10 15:48   ` Nick Clifton [this message]
2022-08-10 14:24 ` [PATCH 3/3] objdump: allow the disassembler colors to be customized Andrew Burgess
2022-08-10 15:57   ` Nick Clifton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1b16772c-59bb-4b66-7ea7-29701c94a3db@redhat.com \
    --to=nickc@redhat.com \
    --cc=aburgess@redhat.com \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).