[binutils-gdb] gas: add as_info() for informational diagnostics

Matthieu Longo mlongo@sourceware.org
Tue Dec 23 16:51:59 GMT 2025


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=dd0ccd82d7b8c56200c71de8f1f51c6c2865cff2

commit dd0ccd82d7b8c56200c71de8f1f51c6c2865cff2
Author: Matthieu Longo <matthieu.longo@arm.com>
Date:   Mon Dec 22 15:50:02 2025 +0000

    gas: add as_info() for informational diagnostics
    
    This patch adds as_info(), a shortened version of as_info_where(),
    for emitting informational diagnostics from Gas.
    This new helper provides the same formatting and source location
    handling as as_info_where(), while offering a simpler interface
    for the common case. It respects the --no-info flag, and supports
    indentation in the same way as its sibling.

Diff:
---
 gas/as.h       | 18 ++++++++++++------
 gas/messages.c | 42 ++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 52 insertions(+), 8 deletions(-)

diff --git a/gas/as.h b/gas/as.h
index b743ba95cc7..02c799984ec 100644
--- a/gas/as.h
+++ b/gas/as.h
@@ -471,10 +471,13 @@ typedef struct _pseudo_type pseudo_typeS;
 #define PRINTF_LIKE(FCN) \
   void FCN (const char *format, ...) \
     __attribute__ ((__format__ (__printf__, 1, 2)))
+#define PRINTF_INDENT_LIKE(FCN) \
+  void FCN (unsigned int indent, const char *format, ...) \
+    __attribute__ ((__format__ (__printf__, 2, 3)))
 #define PRINTF_WHERE_LIKE(FCN) \
   void FCN (const char *file, unsigned int line, const char *format, ...) \
     __attribute__ ((__format__ (__printf__, 3, 4)))
-#define PRINTF_INDENT_LIKE(FCN) \
+#define PRINTF_WHERE_INDENT_LIKE(FCN) \
   void FCN (const char *file, unsigned int line, unsigned int indent, \
 	    const char *format, ...) \
     __attribute__ ((__format__ (__printf__, 4, 5)))
@@ -482,13 +485,15 @@ typedef struct _pseudo_type pseudo_typeS;
 #else /* __GNUC__ < 2 || defined(VMS) */
 
 #define PRINTF_LIKE(FCN)	void FCN (const char *format, ...)
-#define PRINTF_WHERE_LIKE(FCN)	void FCN (const char *file, \
-					  unsigned int line, \
+#define PRINTF_INDENT_LIKE(FCN)	void FCN (unsigned int indent, \
 					  const char *format, ...)
-#define PRINTF_INDENT_LIKE(FCN)	void FCN (const char *file, \
+#define PRINTF_WHERE_LIKE(FCN)	void FCN (const char *file, \
 					  unsigned int line, \
-					  unsigned int indent, \
 					  const char *format, ...)
+#define PRINTF_WHERE_INDENT_LIKE(FCN) void FCN (const char *file, \
+						unsigned int line, \
+						unsigned int indent, \
+						const char *format, ...)
 
 #endif /* __GNUC__ < 2 || defined(VMS) */
 
@@ -496,9 +501,10 @@ PRINTF_LIKE (as_bad);
 PRINTF_LIKE (as_fatal) ATTRIBUTE_NORETURN;
 PRINTF_LIKE (as_tsktsk);
 PRINTF_LIKE (as_warn);
+PRINTF_INDENT_LIKE (as_info);
 PRINTF_WHERE_LIKE (as_bad_where);
 PRINTF_WHERE_LIKE (as_warn_where);
-PRINTF_INDENT_LIKE (as_info_where);
+PRINTF_WHERE_INDENT_LIKE (as_info_where);
 
 void   set_identify_name (const char *);
 void   as_abort (const char *, int, const char *) ATTRIBUTE_NORETURN;
diff --git a/gas/messages.c b/gas/messages.c
index c681e4a39b4..6302c06b58d 100644
--- a/gas/messages.c
+++ b/gas/messages.c
@@ -127,6 +127,45 @@ as_show_where (void)
     }
 }
 
+/* The common portion of as_info, and as_info_where.  */
+
+static void
+as_info_internal (const char *file, unsigned int line, unsigned int indent,
+		  const char *buffer)
+{
+  if (file == NULL)
+    file = as_where_top (&line);
+
+  if (file)
+    {
+      if (line != 0)
+	fprintf (stderr, "%s:%u: %*s%s%s\n",
+		 file, line, (int)indent, "", _("Info: "), buffer);
+      else
+	fprintf (stderr, "%s: %s%s\n", file, _("Info: "), buffer);
+    }
+  else
+    fprintf (stderr, "%s%s\n", _("Info: "), buffer);
+}
+
+/* Send to stderr a string as a information, and locate information
+   in input file(s).  */
+
+void
+as_info (unsigned int indent, const char *format, ...)
+{
+  if (flag_no_information)
+    return;
+
+  va_list args;
+  char buffer[2000];
+
+  va_start (args, format);
+  vsnprintf (buffer, sizeof (buffer), format, args);
+  va_end (args);
+  as_info_internal (NULL, 0, indent, buffer);
+}
+
 /* Send to stderr a string as information, with location data passed in.
    Note that for now this is not intended for general use.  */
 
@@ -143,8 +182,7 @@ as_info_where (const char *file, unsigned int line, unsigned int indent,
   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);
+  as_info_internal (file, line, indent, buffer);
 }
 
 /* The common portion of as_warn, as_warn_where, and as_tsktsk.  */


More information about the Binutils-cvs mailing list