gdbserver: exit with code 1 after missing packet name

When using the command:

  $ gdbserver --disable-packet

gdbserver lists all the packets that can be disabled, and then exits.
I think that this output is a helpful error message that is printed
when the user has forgotten to entry a packet name.  We get similar
output if we run the command:

  $ gdbserver --disable-packet=foo

where gdbserver tells us that 'foo' is invalid, and then lists the
packets that we can use.

The difference is that, in the first case, gdbserver exits with a code
of 0, and in the second, gdbserver exits with a code of 1.

I think both these cases should exit with a code of 1.

With the exception of '--help' and '--version', where we are asking
gdbserver to print some message then exit (which are, and should exit
with a code of 0), in all other cases where we do an early exit, I
think this is an indication that the user has done something
wrong (entered and invalid argument, or missed an argument value), and
gdbserver should exit with a non-zero exit code to indicate this.

This commit updates the exit code in the above case from 0 to 1.

Approved-By: Tom Tromey <tom@tromey.com>
This commit is contained in:
Andrew Burgess
2025-07-12 13:29:19 +01:00
parent 7a45c8e030
commit 190e5f3ca7

View File

@@ -4216,7 +4216,7 @@ captured_main (int argc, char *argv[])
else if (strcmp (*next_arg, "--disable-packet") == 0)
{
gdbserver_show_disableable (stdout);
exit (0);
exit (1);
}
else if (startswith (*next_arg, "--disable-packet="))
{