public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@gmail.com>
To: binutils@sourceware.org
Subject: Correct objdump command line error handling
Date: Mon, 6 Mar 2023 13:57:44 +1030	[thread overview]
Message-ID: <ZAVdsMx3t7PJx6/N@squeak.grove.modra.org> (raw)

bfd_nonfatal is used when a bfd error is to be printed.  That's not
the case for command line errors.

	* objdump.c (nonfatal): Rename to my_bfd_nonfatal.
	(main): Use non_fatal and call usage on unrecognized arg errors.
	Don't set exit_status when calling usage.

diff --git a/binutils/objdump.c b/binutils/objdump.c
index d00eed054c4..c895221c679 100644
--- a/binutils/objdump.c
+++ b/binutils/objdump.c
@@ -558,7 +558,7 @@ static struct option long_options[]=
 };
 \f
 static void
-nonfatal (const char *msg)
+my_bfd_nonfatal (const char *msg)
 {
   bfd_nonfatal (msg);
   exit_status = 1;
@@ -5701,14 +5701,14 @@ display_object_bfd (bfd *abfd)
 
   if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
     {
-      nonfatal (bfd_get_filename (abfd));
+      my_bfd_nonfatal (bfd_get_filename (abfd));
       list_matching_formats (matching);
       return;
     }
 
   if (bfd_get_error () != bfd_error_file_not_recognized)
     {
-      nonfatal (bfd_get_filename (abfd));
+      my_bfd_nonfatal (bfd_get_filename (abfd));
       return;
     }
 
@@ -5718,7 +5718,7 @@ display_object_bfd (bfd *abfd)
       return;
     }
 
-  nonfatal (bfd_get_filename (abfd));
+  my_bfd_nonfatal (bfd_get_filename (abfd));
 
   if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
     list_matching_formats (matching);
@@ -5758,7 +5758,7 @@ display_any_bfd (bfd *file, int level)
 	  if (arfile == NULL)
 	    {
 	      if (bfd_get_error () != bfd_error_no_more_archived_files)
-		nonfatal (bfd_get_filename (file));
+		my_bfd_nonfatal (bfd_get_filename (file));
 	      break;
 	    }
 
@@ -5798,7 +5798,7 @@ display_file (char *filename, char *target, bool last_file)
   file = bfd_openr (filename, target);
   if (file == NULL)
     {
-      nonfatal (filename);
+      my_bfd_nonfatal (filename);
       return;
     }
 
@@ -5951,7 +5951,10 @@ main (int argc, char **argv)
 	      else if (streq (optarg, "off"))
 		visualize_jumps = false;
 	      else
-		nonfatal (_("unrecognized argument to --visualize-option"));
+		{
+		  non_fatal (_("unrecognized argument to --visualize-option"));
+		  usage (stderr, 1);
+		}
 	    }
 	  break;
 	case OPTION_DISASSEMBLER_COLOR:
@@ -5968,7 +5971,10 @@ main (int argc, char **argv)
 		   || streq (optarg, "extended-colour"))
 	    disassembler_color = extended;
 	  else
-	    nonfatal (_("unrecognized argument to --disassembler-color"));
+	    {
+	      non_fatal (_("unrecognized argument to --disassembler-color"));
+	      usage (stderr, 1);
+	    }
 	  break;
 	case 'E':
 	  if (strcmp (optarg, "B") == 0)
@@ -5977,7 +5983,7 @@ main (int argc, char **argv)
 	    endian = BFD_ENDIAN_LITTLE;
 	  else
 	    {
-	      nonfatal (_("unrecognized -E option"));
+	      non_fatal (_("unrecognized -E option"));
 	      usage (stderr, 1);
 	    }
 	  break;
@@ -5989,7 +5995,6 @@ main (int argc, char **argv)
 	  else
 	    {
 	      non_fatal (_("unrecognized --endian type `%s'"), optarg);
-	      exit_status = 1;
 	      usage (stderr, 1);
 	    }
 	  break;

-- 
Alan Modra
Australia Development Lab, IBM

                 reply	other threads:[~2023-03-06  3:27 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=ZAVdsMx3t7PJx6/N@squeak.grove.modra.org \
    --to=amodra@gmail.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).