From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id apa5M35G8mh6dTwAWB0awg (envelope-from ) for ; Fri, 17 Oct 2025 09:37:02 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=ZCmfhS7+; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=6aPPnlGc; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=ZCmfhS7+; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=6aPPnlGc; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id BFF0B1E0BA; Fri, 17 Oct 2025 09:37:02 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id D78001E047 for ; Fri, 17 Oct 2025 09:37:00 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5F3BF3857712 for ; Fri, 17 Oct 2025 13:37:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5F3BF3857712 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=ZCmfhS7+; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=6aPPnlGc; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=ZCmfhS7+; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=6aPPnlGc Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id CBD043858D1E for ; Fri, 17 Oct 2025 13:36:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CBD043858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CBD043858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1760708185; cv=none; b=KXcj2j+n7s/gMahjqZ4M2UBhv0d6GjK3odmuyWhVCRoOhqskiiCskE0eeK+SCED/4M/2HKxwDaidFkRcJeSMHFTZ3po7en6N+uI3yzbKxCOnJIM4zBL+P/HYX8jsQ1dE7MNZOnBdUgzitY/QzslCMRD+S0Vz/XDQYGOFHO5Iirc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1760708185; c=relaxed/simple; bh=78mZAxgk8UUKw6k7HAGzhcLxVLsA8hdCMiRfTire8WA=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-ID:MIME-Version; b=iwboQpeW5r0n2GPecCMoZ7pLlN3lWeLSxJ9PV6HUmAI2B2/bBYQa2Q3Rgibp5fmy2cs9CeAlCVaqrNXz1jRSwVy6okQxXHuFZ+Jq0BAb7EjJAIxpoc52djnBJPZEJrFIlkriCsSJYtf4dEDWwZ30yKIjKR/+TnsNHPYT9rqS7MA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CBD043858D1E Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id CFCFC21C55 for ; Fri, 17 Oct 2025 13:36:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1760708184; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=Nd7OtdhePKHNkQb7Jz7XvGJsuv7v2WEEB4iciG60/bA=; b=ZCmfhS7+SdHmOKRkaF2TuOMwYz2KBYL1Epl5HnARYbFXs2ttMQHJbTUvJMipQnvmrO+8ls a4Z3N63tqCnHlBTIDm26wwATw1USDvZhjUXBE3BEGDQU2UzB83wegvG5ok6SgpV7zSclQn ZUtH0SVqdUBEZ84X/CX83FQF4i5evy0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1760708184; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=Nd7OtdhePKHNkQb7Jz7XvGJsuv7v2WEEB4iciG60/bA=; b=6aPPnlGcrXqkoGsNvRCv4n2zEbnCSyKpCXF0fnPLYPhbhly4nHpkqloz8STwHxJRoEJ8KV 96UdDoxOfU2yh+Dg== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1760708184; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=Nd7OtdhePKHNkQb7Jz7XvGJsuv7v2WEEB4iciG60/bA=; b=ZCmfhS7+SdHmOKRkaF2TuOMwYz2KBYL1Epl5HnARYbFXs2ttMQHJbTUvJMipQnvmrO+8ls a4Z3N63tqCnHlBTIDm26wwATw1USDvZhjUXBE3BEGDQU2UzB83wegvG5ok6SgpV7zSclQn ZUtH0SVqdUBEZ84X/CX83FQF4i5evy0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1760708184; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=Nd7OtdhePKHNkQb7Jz7XvGJsuv7v2WEEB4iciG60/bA=; b=6aPPnlGcrXqkoGsNvRCv4n2zEbnCSyKpCXF0fnPLYPhbhly4nHpkqloz8STwHxJRoEJ8KV 96UdDoxOfU2yh+Dg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id BD28D136C6 for ; Fri, 17 Oct 2025 13:36:24 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id McoBLVhG8mgWJwAAD6G6ig (envelope-from ) for ; Fri, 17 Oct 2025 13:36:24 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH] [gdb/python] Use PyConfig for python 3.9 Date: Fri, 17 Oct 2025 15:36:24 +0200 Message-ID: <20251017133624.2460264-1-tdevries@suse.de> X-Mailer: git-send-email 2.51.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_RATELIMITED(0.00)[rspamd.com]; ARC_NA(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FROM_HAS_DN(0.00)[]; RCVD_TLS_ALL(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; FROM_EQ_ENVFROM(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:mid] X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org On ppc64le-linux (AlmaLinux 9.6) with python 3.9 and test-case gdb.python/py-failed-init.exp I run into: ... builtin_spawn $gdb -nw -nx -q -iex set height 0 -iex set width 0 \ -data-directory $build/gdb/data-directory -iex set interactive-mode on^M Python path configuration:^M PYTHONHOME = 'foo'^M PYTHONPATH = (not set)^M program name = '/usr/bin/python'^M isolated = 0^M environment = 1^M user site = 1^M import site = 1^M sys._base_executable = '/usr/bin/python'^M sys.base_prefix = 'foo'^M sys.base_exec_prefix = 'foo'^M sys.platlibdir = 'lib64'^M sys.executable = '/usr/bin/python'^M sys.prefix = 'foo'^M sys.exec_prefix = 'foo'^M sys.path = [^M 'foo/lib64/python39.zip',^M 'foo/lib64/python3.9',^M 'foo/lib64/python3.9/lib-dynload',^M ]^M Fatal Python error: init_fs_encoding: failed to get the Python codec of the \ filesystem encoding^M Python runtime state: core initialized^M ModuleNotFoundError: No module named 'encodings'^M ^M Current thread 0x00007fffabe18480 (most recent call first):^M ^M ERROR: (eof) GDB never initialized. Couldn't send python print (1) to GDB. UNRESOLVED: gdb.python/py-failed-init.exp: gdb-command Couldn't send quit to GDB. UNRESOLVED: gdb.python/py-failed-init.exp: quit ... The test-case expects gdb to present a prompt, but instead gdb calls exit with this back trace: ... (gdb) bt #0 0x00007ffff6e4bfbc in exit () from /lib64/glibc-hwcaps/power10/libc.so.6 #1 0x00007ffff7873fc4 in fatal_error.lto_priv () from /lib64/libpython3.9.so.1.0 #2 0x00007ffff78aae60 in Py_ExitStatusException () from /lib64/libpython3.9.so.1.0 #3 0x00007ffff78c0e58 in Py_InitializeEx () from /lib64/libpython3.9.so.1.0 #4 0x0000000010b6cab4 in py_initialize_catch_abort () at gdb/python/python.c:2456 #5 0x0000000010b6cfac in py_initialize () at gdb/python/python.c:2540 #6 0x0000000010b6d104 in do_start_initialization () at gdb/python/python.c:2595 #7 0x0000000010b6eaac in gdbpy_initialize (extlang=0x11b7baf0 ) at gdb/python/python.c:2968 #8 0x000000001069d508 in ext_lang_initialization () at gdb/extension.c:319 #9 0x00000000108f9280 in captured_main_1 (context=0x7fffffffe870) at gdb/main.c:1100 #10 0x00000000108fa3cc in captured_main (context=0x7fffffffe870) at gdb/main.c:1372 #11 0x00000000108fa4d8 in gdb_main (args=0x7fffffffe870) at gdb/main.c:1401 #12 0x000000001001d1d8 in main (argc=3, argv=0x7fffffffece8) at gdb/gdb.c:38 ... This may be a python issue [1]. The problem doesn't happen if we use the PyConfig approach instead of the py_initialize_catch_abort approach. Fix this by using the PyConfig approach starting 3.9 (previously, starting 3.10 to avoid Py_SetProgramName deprecation in 3.11). It's possible that we have the same problem and need the same fix for 3.8, but I don't have a setup to check that. Add a todo in a comment. Tested on ppc64le-linux. [1] https://github.com/python/cpython/issues/107827 --- gdb/python/python.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/gdb/python/python.c b/gdb/python/python.c index 51e7a0aa165..9c30d99982a 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -2432,7 +2432,17 @@ gdbpy_gdb_exiting (int exit_code) gdbpy_print_stack (); } -#if PY_VERSION_HEX < 0x030a0000 +/* Use PyConfig mechanisms for Python 3.9 and newer. + + We used to do this for 3.10 and newer to avoid Py_SetProgramName + deprecation in 3.11. + + With 3.9 and the py_initialize_catch_abort approach, we run into a problem + where exit is called instead of abort, making gdb exit (possibly + https://github.com/python/cpython/issues/107827). Using the PyConfig + mechanism (available starting 3.8) fixes that. Todo: see if we have the + same problem for 3.8, and if we can apply the same fix. */ +#if PY_VERSION_HEX < 0x03090000 /* Signal handler to convert a SIGABRT into an exception. */ static void @@ -2484,7 +2494,8 @@ py_initialize () ? AUTO_BOOLEAN_TRUE : AUTO_BOOLEAN_FALSE); -#if PY_VERSION_HEX < 0x030a0000 +/* Use PyConfig mechanisms for Python 3.9 and newer. */ +#if PY_VERSION_HEX < 0x03090000 /* Python documentation indicates that the memory given to Py_SetProgramName cannot be freed. However, it seems that at least Python 3.7.4 Py_SetProgramName takes a copy of the @@ -2525,9 +2536,8 @@ py_initialize () } #endif - /* Py_SetProgramName was deprecated in Python 3.11. Use PyConfig - mechanisms for Python 3.10 and newer. */ -#if PY_VERSION_HEX < 0x030a0000 +/* Use PyConfig mechanisms for Python 3.9 and newer. */ +#if PY_VERSION_HEX < 0x03090000 /* Note that Py_SetProgramName expects the string it is passed to remain alive for the duration of the program's execution, so it is not freed after this call. */ base-commit: 0e4fd060ee7244d00c76f0d4815063dfcc9877f1 -- 2.51.0