Discussion:
[Bug gdb/13000] New: Return value with -batch is always 0
michel.metzger at st dot com
2011-07-13 20:43:39 UTC
Permalink
http://sourceware.org/bugzilla/show_bug.cgi?id=13000

Summary: Return value with -batch is always 0
Product: gdb
Version: 7.2
Status: NEW
Severity: normal
Priority: P2
Component: gdb
AssignedTo: ***@sourceware.org
ReportedBy: ***@st.com
Host: pc-linux-gnu
Target: i686


The documentation states -batch has the following effect:
"Exit with status 0 after processing all the command files specified with `-x'
(and all commands from initialization files, if not inhibited with `-n'). Exit
with nonzero status if an error occurs in executing the gdb commands in the
command files."

The following test demonstrates that it is in fact not the case:

$ gdb -batch -x "gdb.script"

with a file gdb.script containing the line:
file toto

(of course toto doesn't exist, to raise an error).

The output is:
gdb.script:1: Error in sourced command file:
toto: No such file or directory.

Displaying the exit status shows that is is in fact 0.
$ echo $?
0
--
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
tuben at lysator dot liu.se
2014-06-25 12:23:14 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=13000

Johan Tufvesson <tuben at lysator dot liu.se> changed:

What |Removed |Added
----------------------------------------------------------------------------
CC| |tuben at lysator dot liu.se

--- Comment #1 from Johan Tufvesson <tuben at lysator dot liu.se> ---
I needed the documented behavior but failed because of this bug. I tried it on:
x86_64-linux-gnu version 7.4.1
sparc-sun-solaris2.10 version 6.3
host=i686-pc-mingw32 target=arm-none-eabi version 7.5.1
host=i686-mingw32 target=arm-none-eabi version 7.2

All with the same (bad) result.

Since the original bug is quite old, is there a work-around?
--
You are receiving this mail because:
You are on the CC list for the bug.
arma2ff0 at gmail dot com
2015-06-04 13:35:07 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=13000

Armando <arma2ff0 at gmail dot com> changed:

What |Removed |Added
----------------------------------------------------------------------------
CC| |arma2ff0 at gmail dot com

--- Comment #2 from Armando <arma2ff0 at gmail dot com> ---
Same here. I tested it with gdb 7.9.1 on Archlinux on a x86_64 laptop.
--
You are receiving this mail because:
You are on the CC list for the bug.
arma2ff0 at gmail dot com
2015-06-04 13:51:19 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=13000

Armando <arma2ff0 at gmail dot com> changed:

What |Removed |Added
----------------------------------------------------------------------------
Version|7.2 |7.9

--- Comment #3 from Armando <arma2ff0 at gmail dot com> ---
By quick analysis, it looks like the problem resides at line main.c:1137 (I am
looking at the source-code in gdb 7.9.1). It looks to me that the error values
returned by the catch_command_errors_const is ignored. In case of errors, the
file is parsed until the end no matter what, and gdb returns always 0 because
the script was executed until the end.

As a consequence, I believe that quit_force should, at least, return the last
error returned by the catch_command_errors_const, or "1" in case of an error.

If you are interested, I could try to provide a patch.

Thanks && Cheers.
A.
--
You are receiving this mail because:
You are on the CC list for the bug.
dje at google dot com
2015-06-04 18:12:41 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=13000

dje at google dot com changed:

What |Removed |Added
----------------------------------------------------------------------------
CC| |dje at google dot com

--- Comment #4 from dje at google dot com ---
*** Bug 18488 has been marked as a duplicate of this bug. ***
--
You are receiving this mail because:
You are on the CC list for the bug.
arma2ff0 at gmail dot com
2015-06-05 11:50:44 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=13000

--- Comment #5 from Armando <arma2ff0 at gmail dot com> ---
Created attachment 8343
--> https://sourceware.org/bugzilla/attachment.cgi?id=8343&action=edit
Attempt to fix the -batch issue

I am uploading an example of what could, in principle, fix the issue at least
in this case. I have tested the patch only on my laptop (Archlinux, x86_64) so
I do not pretend this is a general and acceptable solution. However, it should
help to prove my point.

I hope this can help further investigation in the issue.
--
You are receiving this mail because:
You are on the CC list for the bug.
jan.kratochvil at redhat dot com
2017-09-24 17:14:22 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=13000

Jan Kratochvil <jan.kratochvil at redhat dot com> changed:

What |Removed |Added
----------------------------------------------------------------------------
CC| |jan.kratochvil at redhat dot com
--
You are receiving this mail because:
You are on the CC list for the bug.
cvs-commit at gcc dot gnu.org
2018-08-29 15:13:09 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=13000

--- Comment #6 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Gary Benson <***@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=b0f492b90f3d13da8ac80437e6ecb9a87db4a75b

commit b0f492b90f3d13da8ac80437e6ecb9a87db4a75b
Author: Gary Benson <***@redhat.com>
Date: Wed Aug 29 16:11:50 2018 +0100

Indicate batch mode failures by exiting with nonzero status

This commit causes GDB in batch mode to exit with nonzero status
if the last command to be executed fails.

gdb/ChangeLog:

PR gdb/13000:
* gdb/main.c (captured_main_1): Exit with nonzero status
in batch mode if the last command to be executed failed.
* NEWS: Mention the above.

gdb/testsuite/ChangeLog:

PR gdb/13000:
* gdb.base/batch-exit-status.exp: New file.
* gdb.base/batch-exit-status.good-commands: Likewise.
* gdb.base/batch-exit-status.bad-commands: Likewise.
--
You are receiving this mail because:
You are on the CC list for the bug.
Loading...