From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id sgELF5cMdmrcaREAWB0awg (envelope-from ) for ; Fri, 07 Aug 2026 12:49:27 -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=wEI3eWWK; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=W6fpeJRj; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=mzxp+L+C; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=/dVVRY/k; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 4B7A41E09B; Fri, 07 Aug 2026 12:49:27 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.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 autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (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 6F32D1E09B for ; Fri, 07 Aug 2026 12:49:25 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3B4954BB5921 for ; Fri, 7 Aug 2026 16:49:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3B4954BB5921 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=wEI3eWWK; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=W6fpeJRj; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=mzxp+L+C; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=/dVVRY/k Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2a07:de40:b251:101:10:150:64:1]) by sourceware.org (Postfix) with ESMTPS id D92F34BB58BD for ; Fri, 7 Aug 2026 16:48:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D92F34BB58BD 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 D92F34BB58BD Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1786121333; cv=none; b=lo8ryJS79TpuD1THZDvN4k4PYYK3M53LVH8Didpkrinf2w45iXgrSh+koIh0Ke6iEJ2joHNLuJ3237T7omusYa03kWPJ7GZABk/Syy61nyw9yw0TMEy7n9BqI51tAjQMzYe3sRq8zoSKzCPlslVflrFMdLopD0y/NzE67EAp6hs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1786121333; c=relaxed/simple; bh=pikNMIBAyw4lGlpdT5I+/p4XbvEDix0ztlYgUmDVxaI=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-ID:MIME-Version; b=WFhw42KUshciwwTGWG1ChWF/obbIsmHWQpouYsqYZ9jdDNu0Rm/j+ltQjGX7Tv9l0iZaLpSSxOlMrvz5Phm7GB0an9CkWhcNDbbXSj4L8I8LktE+6JpE+uOc2aaBU6tEliOL2WjlI0PT0k4zgNK14It96R/hCyi/PNYMh94D7Ww= ARC-Authentication-Results: i=1; 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=wEI3eWWK; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=W6fpeJRj; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=mzxp+L+C; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=/dVVRY/k DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D92F34BB58BD Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104: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 380F7806E4 for ; Fri, 7 Aug 2026 16:48:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1786121327; 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=6QRxogyLQ1znUR+kDhm55dhlxN4/R1TTMLG9H4aAZ4A=; b=wEI3eWWKLpy2bDjGzBBKSQgH+v2En4eSa4dxUTsgXdavDXVWDEbS5AOl9ofVjk1A0xrLG5 N1+Sho75x2P+zshTkcM5pUqHNZuXWOcpAMqyxBYvIp47+xF1g4JJbE6U0nwia3YYbBNjiS hEUyRrixvX0el4JK//UqgaUNZzQy5xM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1786121327; 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=6QRxogyLQ1znUR+kDhm55dhlxN4/R1TTMLG9H4aAZ4A=; b=W6fpeJRjhTYvDxYuS/dircPXpgpGcIjFMYZ+SXKk/4RVWukLx7zFjYPo7VEK2fqqxFa4c7 9/jY29el4ezaUtAg== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=mzxp+L+C; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b="/dVVRY/k" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1786121323; 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=6QRxogyLQ1znUR+kDhm55dhlxN4/R1TTMLG9H4aAZ4A=; b=mzxp+L+C/E+fBbUPXgpJQgK5slFA+mw+lkmyjLQM9nSws+WMlBI4uq1TWuzgiqkpa+PQzw Hz2qHdn+uTOUvJ/fpITTNi9FPzM2m3AKFsUj6XleFsRJsDWBmEMeX97gUNu/sLnYGLhjs7 ZZDZDwN0w8Y32OOLewdrrz4omIdUBsc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1786121323; 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=6QRxogyLQ1znUR+kDhm55dhlxN4/R1TTMLG9H4aAZ4A=; b=/dVVRY/klkIpdIDcj6wWv09V/9bYZbY4UYRk2Dczr1wKX4jW7k4AtCiw3K4snCpddbI4XS bvj6tfNPG1ZY5CDw== 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 1DB7B779B6 for ; Fri, 7 Aug 2026 16:48:43 +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 Y7nnBWsMdmpWNAAAD6G6ig (envelope-from ) for ; Fri, 07 Aug 2026 16:48:43 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH] [gdb/python] Handle error in gdbpy_initialize_gdb_readline Date: Fri, 7 Aug 2026 18:48:42 +0200 Message-ID: <20260807164842.3619235-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 [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RCVD_COUNT_TWO(0.00)[2]; ARC_NA(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; FROM_EQ_ENVFROM(0.00)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:rdns,imap1.dmz-prg2.suse.org:helo,suse.de:mid,suse.de:dkim,sourceware.org:url]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; RCVD_TLS_ALL(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Queue-Id: 380F7806E4 X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Action: no action 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 Fedora Rawhide aarch64-linux, with test-case gdb.python/py-failed-init.exp I ran into: ... builtin_spawn $build/gdb/gdb -nw -nx -q -iex set height 0 -iex set width 0 \ -data-directory $build/gdb/data-directory -iex set interactive-mode on WARN: Could not find the standard library directory! The Python 'home' \ directory was set to 'foo', is this correct? Error occurred computing Python error message. $build/gdb/gdb: warning: Could not load the Python gdb module from `$build/gdb/data-directory/python'. Limited Python support is available from the _gdb module. Suggest passing --data-directory=/path/to/gdb/data-directory. (gdb) set height 0 (gdb) set width 0 (gdb) dir Reinitialize source path to empty? (y or n) y Source directories searched: $cdir:$cwd (gdb) dir $src/gdb/testsuite/gdb.python Source directories searched: $src/gdb/testsuite/gdb.python:$cdir:$cwd (gdb) python print (1) 1 (gdb) FAIL: $exp: gdb-command quit Exception ignored on threading shutdown: Traceback (most recent call last): File "", line 2, in ModuleNotFoundError: No module named 'importlib' PASS: $exp: quit ... The test-case tries to break python: ... save_vars { env(PYTHONHOME) } { setenv PYTHONHOME foo clean_restart } ... enough to get it to this point: ... gdb_test "python print (1)" \ "Python not initialized" ... but apparently, that doesn't work anymore in this python version: ... $ python --version Python 3.15.0b4 ... The test-case needs updating, and I've submitted a testsuite patch [1] for that. The next question is why we're seeing a ModuleNotFoundError on quit. I investigated this, and found that it originates from gdbpy_initialize_gdb_readline, where we do: ... if (eval_python_command (code, Py_file_input) == 0) PyOS_ReadlineFunctionPointer = gdbpy_readline_wrapper; ... but don't report and reset the python error state, so instead the error is reported by Py_Finalize. Fix this by: - making sure that the error is reported immediately, though in the form of a warning rather than an error, and - disabling the python-interactive command if gdbpy_initialize_gdb_readline fails, to avoid broken readline behavior in a python-interactive session. Also make the test-case a bit stricter by checking that there's no output when quitting. Tested on aarch64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34485 [1] https://sourceware.org/pipermail/gdb-patches/2026-August/229193.html --- gdb/python/py-gdb-readline.c | 19 +++++++++++++++++++ gdb/python/python-internal.h | 5 +++++ gdb/python/python.c | 4 ++++ gdb/testsuite/gdb.python/py-failed-init.exp | 6 ++++++ 4 files changed, 34 insertions(+) diff --git a/gdb/python/py-gdb-readline.c b/gdb/python/py-gdb-readline.c index e8e2c23547c..df628efb1f4 100644 --- a/gdb/python/py-gdb-readline.c +++ b/gdb/python/py-gdb-readline.c @@ -116,8 +116,27 @@ sys.meta_path.insert(2, GdbRemoveReadlineFinder())\n\ "; if (eval_python_command (code, Py_file_input) == 0) PyOS_ReadlineFunctionPointer = gdbpy_readline_wrapper; + else + { + if (PyErr_Occurred ()) + { + PyErr_Print (); + PyErr_Clear (); + } + + warning (_("Disabling import readline failed, python-interactive" + " command disabled")); + } return 0; } +/* See python-internal.h. */ + +bool +gdbpy_import_readline_disabled () +{ + return PyOS_ReadlineFunctionPointer == gdbpy_readline_wrapper; +} + GDBPY_INITIALIZE_FILE (gdbpy_initialize_gdb_readline); diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h index 4ca28bb6957..e9e02785a43 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -1387,4 +1387,9 @@ py_notimplemented () #undef Py_RETURN_FALSE #undef Py_RETURN_NOTIMPLEMENTED +/* Return true if import readline was successfully disabled during + initialization. */ + +extern bool gdbpy_import_readline_disabled (); + #endif /* GDB_PYTHON_PYTHON_INTERNAL_H */ diff --git a/gdb/python/python.c b/gdb/python/python.c index 214abd03905..2b482a6f35c 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -383,6 +383,10 @@ eval_python_command (const char *command, int start_symbol, static void python_interactive_command (const char *arg, int from_tty) { + if (!gdbpy_import_readline_disabled ()) + error (_("Disabling import readline failed, python-interactive" + " command disabled")); + struct ui *ui = current_ui; int err; diff --git a/gdb/testsuite/gdb.python/py-failed-init.exp b/gdb/testsuite/gdb.python/py-failed-init.exp index 622743d8d9b..c2b9c990e29 100644 --- a/gdb/testsuite/gdb.python/py-failed-init.exp +++ b/gdb/testsuite/gdb.python/py-failed-init.exp @@ -24,8 +24,14 @@ save_vars { env(PYTHONHOME) } { gdb_test "python print (1)" \ "Python not initialized" +set output_seen 0 gdb_test_multiple "quit" "" { + -re ^quit\r\n { + exp_continue + } eof { + set output_seen [expr [string length $expect_out(buffer)] != 0] pass $gdb_test_name } } +gdb_assert {!$output_seen} "no output after quit" base-commit: 7800332405e135eaf3e1482b8195669b3662c142 -- 2.51.0