* Correct objdump command line error handling
@ 2023-03-06 3:27 Alan Modra
0 siblings, 0 replies; only message in thread
From: Alan Modra @ 2023-03-06 3:27 UTC (permalink / raw)
To: binutils
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-03-06 3:27 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-06 3:27 Correct objdump command line error handling Alan Modra
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).