[v0,2/3] gas: add new command line options to control diagnostic info messages

Message ID 20240627135017.1971420-3-matthieu.longo@arm.com
State Superseded
Headers
Series gas: add command line option to inhibit info messages |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm success Test passed

Commit Message

Matthieu Longo June 27, 2024, 1:50 p.m. UTC
  gas currently emits info messages for context information along warnings.
as_info_where() is used only once for "macro invoked from here". This
message polutes the tests when checking for error message patterns in
stderr output.

This patch aims at providing two new flags while preserving the existing
behavior if none of the options is provided.
  * --info, similar to the existing --warn flag to enable diagnostic info
    messages (default behavior).
  * --no-info, similar to the existing --no-warn flag to disable diagnostic
    info messages.

It also adds the flag to the existing documentation, and command manual.
---
 gas/as.c        | 18 +++++++++++++++++-
 gas/as.h        |  3 +++
 gas/doc/as.texi | 33 +++++++++++++++++++++++++++++++++
 gas/messages.c  | 13 ++++++++-----
 4 files changed, 61 insertions(+), 6 deletions(-)
  

Comments

Jan Beulich June 28, 2024, 12:38 p.m. UTC | #1
On 27.06.2024 15:50, Matthieu Longo wrote:
> 
> gas currently emits info messages for context information along warnings.
> as_info_where() is used only once for "macro invoked from here". This
> message polutes the tests when checking for error message patterns in
> stderr output.
> 
> This patch aims at providing two new flags while preserving the existing
> behavior if none of the options is provided.
>   * --info, similar to the existing --warn flag to enable diagnostic info
>     messages (default behavior).
>   * --no-info, similar to the existing --no-warn flag to disable diagnostic
>     info messages.
> 
> It also adds the flag to the existing documentation, and command manual.

Like said for patch 1, I think the commonly useful option wants to come
first everywhere. --info really only exists for completeness, and for
the rare cases where you'd need to override an earlier --no-info coming
from somewhere you can't directly control. Relative to the warning
counterparts, where adjacent I think the info stuff wants to come after
the warning stuff.

I further wonder whether --no-warn shouldn't then imply --no-info.

Finally the churn in as_info_where() could be shrunk be simply inserting

  if (flag_no_infos)
    return;

(Whether "infos" is a valid word in English I'm not sure; my spell
checker doesn't like it at least, yet then I'm not a native speaker.)

Jan
  
Richard Earnshaw (lists) June 28, 2024, 1:12 p.m. UTC | #2
On 28/06/2024 13:38, Jan Beulich wrote:

> (Whether "infos" is a valid word in English I'm not sure; my spell
> checker doesn't like it at least, yet then I'm not a native speaker.)

It's not really a word, but then info isn't really a word either, it's a short-hand version of information (and the plural of this is still information).

But on the same subject, warns as a plural isn't a word either; but it is a word because it is a conjugate form of the verb 'to warn' so a spelling chequer (sic) won't pick that up.  If we're going to be pedantic we should use no_warnings, not no_warns.

R.
  
Jan Beulich June 28, 2024, 1:35 p.m. UTC | #3
On 28.06.2024 15:12, Richard Earnshaw (lists) wrote:
> On 28/06/2024 13:38, Jan Beulich wrote:
> 
>> (Whether "infos" is a valid word in English I'm not sure; my spell
>> checker doesn't like it at least, yet then I'm not a native speaker.)
> 
> It's not really a word, but then info isn't really a word either, it's a short-hand version of information (and the plural of this is still information).
> 
> But on the same subject, warns as a plural isn't a word either; but it is a word because it is a conjugate form of the verb 'to warn' so a spelling chequer (sic) won't pick that up.  If we're going to be pedantic we should use no_warnings, not no_warns.

Just to mention it: It's --no-warn (command line option) and
flag_no_warnings (internal variable). Hence why I'm a little unhappy
with --no-infos / flag_no_infos.

Jan
  
Richard Earnshaw (lists) June 28, 2024, 2:03 p.m. UTC | #4
On 28/06/2024 14:35, Jan Beulich wrote:
> On 28.06.2024 15:12, Richard Earnshaw (lists) wrote:
>> On 28/06/2024 13:38, Jan Beulich wrote:
>>
>>> (Whether "infos" is a valid word in English I'm not sure; my spell
>>> checker doesn't like it at least, yet then I'm not a native speaker.)
>>
>> It's not really a word, but then info isn't really a word either, it's a short-hand version of information (and the plural of this is still information).
>>
>> But on the same subject, warns as a plural isn't a word either; but it is a word because it is a conjugate form of the verb 'to warn' so a spelling chequer (sic) won't pick that up.  If we're going to be pedantic we should use no_warnings, not no_warns.
> 
> Just to mention it: It's --no-warn (command line option) and
> flag_no_warnings (internal variable). Hence why I'm a little unhappy
> with --no-infos / flag_no_infos.
> 
> Jan

Yeah, --no-info and flag_no_info would be more idiomatic.

R.
  
Matthieu Longo June 28, 2024, 6:20 p.m. UTC | #5
>On 27.06.2024 15:50, Matthieu Longo wrote:
>>
>> gas currently emits info messages for context information along warnings.
>> as_info_where() is used only once for "macro invoked from here". This
>> message polutes the tests when checking for error message patterns in
>> stderr output.
>>
>> This patch aims at providing two new flags while preserving the
>> existing behavior if none of the options is provided.
>>   * --info, similar to the existing --warn flag to enable diagnostic info
>>     messages (default behavior).
>>   * --no-info, similar to the existing --no-warn flag to disable diagnostic
>>     info messages.
>>
>> It also adds the flag to the existing documentation, and command manual.
>
>Like said for patch 1, I think the commonly useful option wants to come first everywhere. --info really only exists for completeness, and for the rare cases where you'd need to override an earlier --no-info coming from somewhere you can't directly control. Relative to the warning counterparts, where adjacent I think the info stuff wants to come after the warning stuff.
>
>I further wonder whether --no-warn shouldn't then imply --no-info.
>
>Finally the churn in as_info_where() could be shrunk be simply inserting
>
>  if (flag_no_infos)
>    return;
>
>(Whether "infos" is a valid word in English I'm not sure; my spell checker doesn't like it at least, yet then I'm not a native speaker.)
>
>Jan

I will fix the order in a new revision, and also the return in as_info_where().
  

Patch

diff --git a/gas/as.c b/gas/as.c
index 81a0925184c..0ee3b208338 100644
--- a/gas/as.c
+++ b/gas/as.c
@@ -388,6 +388,10 @@  Options:\n\
   fprintf (stream, _("\
   --version               print assembler version number and exit\n"));
   fprintf (stream, _("\
+  --info                  don't suppress infos\n"));
+  fprintf (stream, _("\
+  --no-info               suppress information messages\n"));
+  fprintf (stream, _("\
   --warn                  don't suppress warnings\n"));
   fprintf (stream, _("\
   -W, --no-warn           suppress warnings\n"));
@@ -519,7 +523,9 @@  parse_args (int * pargc, char *** pargv)
       OPTION_NO_PAD_SECTIONS,
       OPTION_MULTIBYTE_HANDLING,  /* = STD_BASE + 40 */
       OPTION_SFRAME,
-      OPTION_SCFI
+      OPTION_SCFI,
+      OPTION_INFO,
+      OPTION_NOINFO
     /* When you add options here, check that they do
        not collide with OPTION_MD_BASE.  See as.h.  */
     };
@@ -595,6 +601,7 @@  parse_args (int * pargc, char *** pargv)
     ,{"mri", no_argument, NULL, 'M'}
     ,{"nocpp", no_argument, NULL, OPTION_NOCPP}
     ,{"no-pad-sections", no_argument, NULL, OPTION_NO_PAD_SECTIONS}
+    ,{"no-info", no_argument, NULL, OPTION_NOINFO}
     ,{"no-warn", no_argument, NULL, 'W'}
     ,{"reduce-memory-overheads", no_argument, NULL, OPTION_REDUCE_MEMORY_OVERHEADS}
     ,{"statistics", no_argument, NULL, OPTION_STATISTICS}
@@ -603,6 +610,7 @@  parse_args (int * pargc, char *** pargv)
     ,{"verbose", no_argument, NULL, OPTION_VERBOSE}
     ,{"target-help", no_argument, NULL, OPTION_TARGET_HELP}
     ,{"traditional-format", no_argument, NULL, OPTION_TRADITIONAL_FORMAT}
+    ,{"info", no_argument, NULL, OPTION_INFO}
     ,{"warn", no_argument, NULL, OPTION_WARN}
     ,{"multibyte-handling", required_argument, NULL, OPTION_MULTIBYTE_HANDLING}
   };
@@ -968,6 +976,14 @@  This program has absolutely no warranty.\n"));
 	  flag_readonly_data_in_text = 1;
 	  break;
 
+	case OPTION_INFO:
+	  flag_no_infos = 0;
+	  break;
+
+	case OPTION_NOINFO:
+	  flag_no_infos = 1;
+	  break;
+
 	case OPTION_WARN:
 	  flag_no_warnings = 0;
 	  flag_fatal_warnings = 0;
diff --git a/gas/as.h b/gas/as.h
index 24bf66eb8a7..d475c329cdf 100644
--- a/gas/as.h
+++ b/gas/as.h
@@ -314,6 +314,9 @@  COMMON bool flag_macro_alternate;
    section?  */
 COMMON unsigned char flag_readonly_data_in_text; /* -R */
 
+/* True if infos should be inhibited.  */
+COMMON int flag_no_infos; /* --no-info */
+
 /* True if warnings should be inhibited.  */
 COMMON int flag_no_warnings; /* -W, --no-warn */
 
diff --git a/gas/doc/as.texi b/gas/doc/as.texi
index ad86b8f5a74..8ac5e7f438e 100644
--- a/gas/doc/as.texi
+++ b/gas/doc/as.texi
@@ -260,6 +260,7 @@  gcc(1), ld(1), and the Info entries for @file{binutils} and @file{ld}.
  [@b{--size-check=[error|warning]}]
  [@b{--statistics}]
  [@b{-v}] [@b{-version}] [@b{--version}]
+ [@b{--info}] [@b{--no-info}]
  [@b{--warn}] [@b{-W}] [@b{--no-warn}] [@b{--fatal-warnings}]
  [@b{-w}] [@b{-x}]
  [@b{-Z}] [@b{@@@var{FILE}}]
@@ -980,6 +981,12 @@  Print the @command{as} version.
 @item --version
 Print the @command{as} version and exit.
 
+@item --info
+Don't suppress info messages.
+
+@item --no-info
+Suppress info messages.
+
 @item --warn
 Don't suppress warning messages or treat them as errors.
 
@@ -2464,6 +2471,7 @@  assembler.)
 * statistics::    --statistics to see statistics about assembly
 * traditional-format:: --traditional-format for compatible output
 * v::             -v to announce version
+* info::          --info, --no-info to control info messages
 * W::             --warn, -W, --no-warn, --fatal-warnings to control warnings
 * Z::             -Z to make object file even after errors
 @end menu
@@ -2863,6 +2871,31 @@  You can find out what version of as is running by including the
 option @samp{-v} (which you can also spell as @samp{-version}) on the
 command line.
 
+@node info
+@section Control Information Messages: @option{--info}, @option{--no-info}
+
+In some cases, @command{@value{AS}} might give an additional information message
+associated to a context that generated a warning or error message when assembling.
+The information message provides additional details about an earlier diagnostic message, usually in the
+form of some context (such as when the earlier diagnostic was within a macro).
+All such informations are directed to the standard error file.
+This flag only affects the information messages, it does not change any particular
+of how @command{@value{AS}} assembles your file.
+
+@kindex --info
+@cindex diagnostic informations, switching on (default behavior)
+The option @option{--info} is enabled by default, and enables printing of additional
+diagnostic informations.
+
+@kindex --no-info
+@cindex diagnostic informations, switching off
+You can switch the option @option{--info} off by specifying @option{--no-info},
+which disables printing of additional information in the context of an earlier
+diagnostic.
+
+Specifying @option{--info} after @option{--no-info} will turn on again printing
+of additional diagnostic informations.
+
 @node W
 @section Control Warnings: @option{--warn}, @option{-W}, @option{--no-warn}, @option{--fatal-warnings}
 
diff --git a/gas/messages.c b/gas/messages.c
index bbe2596f27b..1968d832449 100644
--- a/gas/messages.c
+++ b/gas/messages.c
@@ -141,11 +141,14 @@  as_info_where (const char *file, unsigned int line, unsigned int indent,
   va_list args;
   char buffer[2000];
 
-  va_start (args, format);
-  vsnprintf (buffer, sizeof (buffer), format, args);
-  va_end (args);
-  fprintf (stderr, "%s:%u: %*s%s%s\n",
-	   file, line, (int)indent, "", _("Info: "), buffer);
+  if (!flag_no_infos)
+    {
+      va_start (args, format);
+      vsnprintf (buffer, sizeof (buffer), format, args);
+      va_end (args);
+      fprintf (stderr, "%s:%u: %*s%s%s\n",
+	       file, line, (int)indent, "", _("Info: "), buffer);
+    }
 }
 
 /* Send to stderr a string as a warning, and locate warning