Correct objdump command line error handling

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.
This commit is contained in:
Alan Modra
2023-03-06 10:42:22 +10:30
parent ec95986dc2
commit a734d906cc

View File

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