[PATCH 8/8] Unify startup and option-parsing warnings

Gary Benson gbenson@redhat.com
Wed Aug 6 10:12:00 GMT 2014


Various warnings are emitted during startup and option-parsing using
fprintf_unfiltered.  One warning is prefixed with the command name,
the others are not.  This commit replaces these hardwired warnings
with calls to warning.  It also sets warning_pre_print to prefix all
warnings with the command name until option parsing is complete.

gdb/
2014-08-06  Gary Benson  <gbenson@redhat.com>

	* main.c (captured_main): Use warning during startup.
	Prefix startup warning messages with command name.
---
 gdb/ChangeLog |    5 +++++
 gdb/main.c    |   31 ++++++++++---------------------
 2 files changed, 15 insertions(+), 21 deletions(-)

diff --git a/gdb/main.c b/gdb/main.c
index a850edf..a15b3fd 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -519,14 +519,12 @@ captured_main (void *data)
   gdb_program_name = xstrdup (argv[0]);
 #endif
 
+  /* Prefix warning messages with the command name.  */
+  warning_pre_print = xstrprintf ("%s: warning: ", gdb_program_name);
+
   if (! getcwd (gdb_dirbuf, sizeof (gdb_dirbuf)))
-    /* Don't use *_filtered or warning() (which relies on
-       current_target) until after initialize_all_files().  */
-    fprintf_unfiltered (gdb_stderr,
-			_("%s: warning: error finding "
-			  "working directory: %s\n"),
-                        argv[0], safe_strerror (errno));
-    
+    perror_warning_with_name (_("error finding working directory"));
+
   current_directory = gdb_dirbuf;
 
   /* Set the sysroot path.  */
@@ -809,13 +807,8 @@ captured_main (void *data)
 
 	      i = strtol (optarg, &p, 0);
 	      if (i == 0 && p == optarg)
-
-		/* Don't use *_filtered or warning() (which relies on
-		   current_target) until after initialize_all_files().  */
-
-		fprintf_unfiltered
-		  (gdb_stderr,
-		   _("warning: could not set baud rate to `%s'.\n"), optarg);
+		warning (_("could not set baud rate to `%s'."),
+			 optarg);
 	      else
 		baud_rate = i;
 	    }
@@ -827,13 +820,8 @@ captured_main (void *data)
 
 	      i = strtol (optarg, &p, 0);
 	      if (i == 0 && p == optarg)
-
-		/* Don't use *_filtered or warning() (which relies on
-		   current_target) until after initialize_all_files().  */
-
-		fprintf_unfiltered (gdb_stderr,
-				    _("warning: could not set "
-				      "timeout limit to `%s'.\n"), optarg);
+		warning (_("could not set timeout limit to `%s'."),
+			 optarg);
 	      else
 		remote_timeout = i;
 	    }
@@ -987,6 +975,7 @@ captured_main (void *data)
     }
 
   /* Set off error and warning messages with a blank line.  */
+  xfree (warning_pre_print);
   warning_pre_print = _("\nwarning: ");
 
   /* Read and execute the system-wide gdbinit file, if it exists.
-- 
1.7.1



More information about the Gdb-patches mailing list