]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
[gdb/python] Make sure python sys.exit makes gdb exit
authorTom de Vries <tdevries@suse.de>
Wed, 25 Sep 2024 17:29:57 +0000 (19:29 +0200)
committerTom de Vries <tdevries@suse.de>
Wed, 25 Sep 2024 17:29:57 +0000 (19:29 +0200)
commitdfba4847f6a22eef700917e2718ea847d9f5cc9d
tree4f8d775a0fcf607b4299391b078b942767288e84
parentf82fd76c96ce848d77f86b8f1beefcff7656159c
[gdb/python] Make sure python sys.exit makes gdb exit

With gdb 15.1, python sys.exit no longer makes gdb exit:
...
$ gdb -q -batch -ex "python sys.exit(2)" -ex "print 123"; echo $?
Python Exception <class 'SystemExit'>: 2
Error occurred in Python: 2
$1 = 123
0
...

This is a change in behaviour since commit a207f6b3a38 ("Rewrite "python"
command exception handling"), first available in gdb 15.1.

This patch reverts to the old behaviour by handling PyExc_SystemExit in
gdbpy_handle_exception, such what we have instead:
...
$ gdb -q -batch -ex "python sys.exit(2)" -ex "print 123"; echo $?
2
...

Tested on x86_64-linux, with python 3.6 and 3.13.

Tested-By: Guinevere Larsen <blarsen@redhat.com>
Approved-By: Tom Tromey <tom@tromey.com>
PR python/31946
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31946
gdb/python/py-utils.c
gdb/testsuite/gdb.python/sys-exit.exp [new file with mode: 0644]