From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id BeMnDsxddmrXOxIAWB0awg (envelope-from ) for ; Fri, 07 Aug 2026 18:35:56 -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=aNkhm7ai; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=0hFO2ezC; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=lfkn3pas; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=Q8g1Rsc5; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 28A691E09B; Fri, 07 Aug 2026 18:35:56 -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 [IPv6:2620:52:6:3111::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 6A51C1E09B for ; Fri, 07 Aug 2026 18:35:54 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2C2144B9DB59 for ; Fri, 7 Aug 2026 22:35:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2C2144B9DB59 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=aNkhm7ai; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=0hFO2ezC; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=lfkn3pas; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=Q8g1Rsc5 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id 55E5C4BA9032 for ; Fri, 7 Aug 2026 22:35:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 55E5C4BA9032 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 55E5C4BA9032 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1786142126; cv=none; b=rvmTbZ/NLKntVLm1liMrDdgGLyeNaG4m6/VHKMjObPMPDcFCYE1sWnvLFphq04r6lYg2XjU419gJAlYFi5tH85T/PLwlgrl4GFBl5TwC7Gh3jnWJtgkKy6BD77ZODMtLxLVlODXi8sj+L2czisdUujrztNC1bSiA5KXQzPE5c/4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1786142126; c=relaxed/simple; bh=pRKvCe2fYCM0cpvhsg3h8UY9XGjdOYVC9htHBc16U4M=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-ID:MIME-Version; b=D/SIeVDmb2x7QUV2s2b8rq7tlWCLw1fx+2GhhYs5NWtdkF+GrswL3LObZdk8sI8rro090Kw0UuwhHlyRNQ0K6JIZafBfFBd4Ev2cpCOH1IVBrbM/mfavB9P+iscnMg277b4Tu2R/XAVb+N/BiqzffYeGBNJszHZLiDWElr+rN5E= 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=aNkhm7ai; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=0hFO2ezC; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=lfkn3pas; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=Q8g1Rsc5 DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 55E5C4BA9032 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 06F9580B36 for ; Fri, 7 Aug 2026 22:35:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1786142121; 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=tokjfOTA2Xc5Cw6r1NO8ghl1M+wFj5Zzpk5x2sgOadc=; b=aNkhm7aiNMrK6jDyrqt7eB60NUT6atMTFXAuJa/3Nh84kcn9lWqJemfwQRLsZcJAXyH5S0 Z2k0pl9PMNLJCXxLt8iK+we+pyOjxMhXwwWLQEraJoaXFWHwG9mtpFipnoczHw+W3Gmsjc Vohosp8CfnfW+FDu8PSu7OO9kUNSfwc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1786142121; 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=tokjfOTA2Xc5Cw6r1NO8ghl1M+wFj5Zzpk5x2sgOadc=; b=0hFO2ezCDRd4sCPrLcQlni4O2hkHyqWQJknXxLs9F/hPxjjAntccCajWKBhSp2As+h3bLL Y3z7xKILKstGXhCg== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1786142117; 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=tokjfOTA2Xc5Cw6r1NO8ghl1M+wFj5Zzpk5x2sgOadc=; b=lfkn3pash3WshNE4SCZ1zmpPjlIJAOU7g0bfuuzE0rvElwdb/8Fu4s3z72SOHdfh5F5frb gJxwRnlqWaZgHM0lcdGGDuaTT0FSDBUHJyFBmHB4fFgRKl9dUXvPD1itYpJd3be9c7sVWP ta1yrp24SjxFkWOEbR8hPirBe6SciIw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1786142117; 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=tokjfOTA2Xc5Cw6r1NO8ghl1M+wFj5Zzpk5x2sgOadc=; b=Q8g1Rsc52ZSeD1UO90geGtMTqDcYCvctFWeY3kcUezTjSeecSbV0UOL8ePa9zs02niDrsn 8WwyzfetdrvHFvDQ== 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 E64DC779B6 for ; Fri, 7 Aug 2026 22:35:16 +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 zR/1NqRddmpxbgAAD6G6ig (envelope-from ) for ; Fri, 07 Aug 2026 22:35:16 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH v2] [gdb/python] Handle error in gdbpy_initialize_gdb_readline Date: Sat, 8 Aug 2026 00:35:16 +0200 Message-ID: <20260807223516.3636935-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.79 / 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.19)[-0.944]; MIME_GOOD(-0.10)[text/plain]; ARC_NA(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.de:mid]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; RCVD_TLS_ALL(0.00)[] 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. Changes in v2: - use gdbpy_print_stack instead of PyErr_Print/PyErr_Clear - Fix error/warning message by ensure that command name is double-quoted and displayed using command_style Versions: - v1 https://sourceware.org/pipermail/gdb-patches/2026-August/229261.html 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 | 18 ++++++++++++++++++ gdb/python/python-internal.h | 5 +++++ gdb/python/python.c | 4 ++++ gdb/testsuite/gdb.python/py-failed-init.exp | 6 ++++++ 4 files changed, 33 insertions(+) diff --git a/gdb/python/py-gdb-readline.c b/gdb/python/py-gdb-readline.c index e8e2c23547c..f8732f79622 100644 --- a/gdb/python/py-gdb-readline.c +++ b/gdb/python/py-gdb-readline.c @@ -19,7 +19,9 @@ #include "python-internal.h" #include "top.h" +#include "ui-out.h" #include "cli/cli-utils.h" +#include "cli/cli-style.h" /* Readline function suitable for PyOS_ReadlineFunctionPointer, which is used for Python's interactive parser and raw_input. In both @@ -116,8 +118,24 @@ 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 ()) + gdbpy_print_stack (); + + warning (_("Disabling import readline failed, \"%ps\" command disabled"), + styled_string (command_style.style (), "python-interactive")); + } 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 1165f165e29..3be1cc3ad55 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -1391,4 +1391,9 @@ py_notimplemented () #include "py-wrappers.h" #include "py-safety.h" +/* 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 7b5de98b903..0d6134ef060 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, \"%ps\" command disabled"), + styled_string (command_style.style (), "python-interactive")); + 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: c7c7858871f77bb265bbce492d39716f39e0d462 -- 2.51.0