This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: gdb -batch always exits with status 0
- From: Ruslan Kabatsayev <b7 dot 10110111 at gmail dot com>
- To: Gary Benson <gbenson at redhat dot com>
- Cc: gdb at sourceware dot org
- Date: Thu, 5 Jul 2018 17:55:38 +0300
- Subject: Re: gdb -batch always exits with status 0
- References: <20180705144659.GA29169@blade.nx>
Hi,
On 5 July 2018 at 17:47, Gary Benson <gbenson@redhat.com> wrote:
> Hi all,
>
> I've been working on fixing PR gdb/13000, which is that GDB in batch
> mode always exits with status 0 despite the manual saying it should
> exit with nonzero status on error. The latter is what I'd intuitively
> expect, so I'm looking at fixing GDB to match the docs rather than
> fixing the docs to match GDB.
>
> A narrow fix to make GDB match the docs is actually fairly simple,
> but I'm bothered that not only does gdb -batch always exit with
> status 0, it actually continues over any number of errors before
> doing so. So you can do something like:
>
> bash$ echo nonsense > cmds
> bash$ echo garbage > .gdbinit
> bash$ gdb -batch -iex invalid-command -ex also-invalid \
> -cd /no/such/directory -p 1 -batch -ix /does/not/exist \
> -x cmds
> Undefined command: "invalid-command". Try "help".
> warning: /does/not/exist: No such file or directory
> /no/such/directory: No such file or directory.
> ptrace: Operation not permitted.
> .gdbinit:1: Error in sourced command file:
> Undefined command: "garbage". Try "help".
> Undefined command: "also-invalid". Try "help".
> cmds:1: Error in sourced command file:
> Undefined command: "nonsense". Try "help".
> bash$ echo $?
> 0
>
> Would anybody object to my changing GDB's behaviour to terminate
> on the first error in batch mode?
On the one hand, this totally makes sense. But on the other, can we
prevent exit if we e.g. expect a possible error and do the necessary
steps to fix it? An example use case: before starti command appeared,
it could be simulated by the following:
b *0
r
d 1
The above (unconditional!) sequence of commands would error on `r`,
but the side effect of the whole sequence would be the same as the
modern starti command. Your change would invalidate similar use cases
in batch mode.
>
> (I'd also like to remove the 'Try "help".' suffix when in batch mode,
> though I'd likely do that in a separate patch.)
>
> Cheers,
> Gary
>
> --
> https://gbenson.net/