]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdbserver: exit with code 1 after missing packet name
authorAndrew Burgess <aburgess@redhat.com>
Sat, 12 Jul 2025 12:29:19 +0000 (13:29 +0100)
committerAndrew Burgess <aburgess@redhat.com>
Fri, 1 Aug 2025 09:15:31 +0000 (10:15 +0100)
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>
gdbserver/server.cc

index a59f94160530ade6a1e0e04ccb364923800ae528..c7720808f6f6f88ebd1aa61650a0f144e83200e1 100644 (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="))
        {