From patchwork Tue Mar 12 21:53:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Merey X-Patchwork-Id: 87096 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D4DED38582BB for ; Tue, 12 Mar 2024 21:54:04 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id ACB103858C36 for ; Tue, 12 Mar 2024 21:53:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ACB103858C36 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org ACB103858C36 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710280424; cv=none; b=bMpAzVh0lKtUXroaWpSQwf6yqgc9zmB9ND2gijsdk2WhkmSU4sXOBzJnoemYwyTchtmbux5EnKQYm5tYdcp3IPxOBNRKrwfMz2dFqYbNrFnWwLeZMJD2SsbHDAUMl7CInh7UEaqRV63aYRsG11/9SP0aUMeENkshBve9Yp7jnmE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710280424; c=relaxed/simple; bh=XmnP/Kip0kHuetUa1Rqr4VbaTK7Voylh8r1l/+LTyag=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=TlZJMqWQSGr4XnlIiEJN35p5avHxEemUGvyvL2ucDs7PjGf+MyQwJWF6yNI9O+fklTLBHbzEOWnZXDzNxl73f58Fgve3DMDz53a3etvIZ5WdwPOqJdmF/57kt45l7IRSeu6k0G2JZxMM/Brz3BQVDStQMMaWCOvcOxEPLk47sOc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710280421; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=YnqOtVEhsGS5HHckQffnwA1EUFicYu4voP7a26cBvaM=; b=XJSFdMDSOzCHaoo9tv5I6WoFti60otUmnqTqgBSHmluKvZp7eUz9o0eVGc13WM6eFVFM9P hd6dDolerZRDQ8qZeklY9L0K4HgPDP/Tv/TzgYnx79N08KW2JGaG2HSKcoOLhbMIhHihZT 9zj6V4LMLMSHQjujuwfvLzkWUZSZnI0= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-122-ex08tkMKPOKrBKlg5onaxw-1; Tue, 12 Mar 2024 17:53:39 -0400 X-MC-Unique: ex08tkMKPOKrBKlg5onaxw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9D72180026B for ; Tue, 12 Mar 2024 21:53:39 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.8.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id 41E1340C6DAD; Tue, 12 Mar 2024 21:53:39 +0000 (UTC) From: Aaron Merey To: gdb-patches@sourceware.org Cc: Aaron Merey Subject: [PATCH] gdb/tui: Fix crash from y/n prompt during TUI initialization Date: Tue, 12 Mar 2024 17:53:34 -0400 Message-ID: <20240312215334.37888-1-amerey@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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+patchwork=sourceware.org@sourceware.org A y/n prompt during TUI initialization can cause a crash due to attempting to divide by a screen width of 0 in tui_inject_newline_into_command_window. If 'debuginfod enabled' is set to 'ask', a y/n prompt can occur during TUI initialization if gdb queries debuginfod for a source file to be displayed in the TUI source window. Fix this by raising the prompt at the beginning of tui_enable_command, before leaving the current interpreter. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31449 --- gdb/debuginfod-support.c | 10 +++++--- gdb/debuginfod-support.h | 5 ++++ .../gdb.debuginfod/fetch_src_and_symbols.exp | 23 +++++++++++++++++++ gdb/tui/tui.c | 6 +++++ 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/gdb/debuginfod-support.c b/gdb/debuginfod-support.c index 9bb3748c8c3..aea0a85df0c 100644 --- a/gdb/debuginfod-support.c +++ b/gdb/debuginfod-support.c @@ -101,6 +101,11 @@ debuginfod_section_query (const unsigned char *build_id, { return scoped_fd (-ENOSYS); } + +bool debuginfod_is_enabled (void) +{ + return false; +} #define NO_IMPL _("Support for debuginfod is not compiled into GDB.") #else @@ -223,10 +228,9 @@ get_debuginfod_client () return global_client; } -/* Check if debuginfod is enabled. If configured to do so, ask the user - whether to enable debuginfod. */ +/* See debuginfod-support.h. */ -static bool +bool debuginfod_is_enabled () { const char *urls = skip_spaces (getenv (DEBUGINFOD_URLS_ENV_VAR)); diff --git a/gdb/debuginfod-support.h b/gdb/debuginfod-support.h index 2b816fd4b82..a4965a74eaa 100644 --- a/gdb/debuginfod-support.h +++ b/gdb/debuginfod-support.h @@ -105,4 +105,9 @@ extern scoped_fd debuginfod_section_query (const unsigned char *build_id, const char *section_name, gdb::unique_xmalloc_ptr *destname); + +/* Check if debuginfod is enabled. If configured to do so, ask the user + whether to enable debuginfod. */ + +bool debuginfod_is_enabled (); #endif /* DEBUGINFOD_SUPPORT_H */ diff --git a/gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp b/gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp index 401af0df0d2..62f0a14dbc3 100644 --- a/gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp +++ b/gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp @@ -21,6 +21,7 @@ load_lib dwarf.exp load_lib debuginfod-support.exp require allow_debuginfod_tests +tuiterm_env set sourcetmp [standard_output_file tmp-${srcfile}] set outputdir [standard_output_file {}] @@ -256,6 +257,28 @@ proc_with_prefix local_url { } { "file [file tail ${binfile}_alt.o]" \ $enable_debuginfod_question "y" + # Enabling TUI from CLI should trigger a debuginfod prompt. + if {[Term::prepare_for_tui] } { + Term::clean_restart 24 80 + send_gdb "tui disable\n" + + # Verify that the prompt is set to appear. + gdb_test "show debuginfod enabled" \ + "Debuginfod functionality is currently set to \"ask\"\." \ + "enabled ask tui" + send_gdb "tui enable\n" + + # Answer the prompt. + send_gdb "y\n" + + # Confirm that debuginfod was enabled along with tui. + Term::command "show debuginfod enabled" + Term::check_contents "enabled on tui" \ + "Debuginfod functionality is currently set to \"on\"\." + } else { + unsupported "TUI not supported" + } + # Configure debuginfod with commands. unsetenv DEBUGINFOD_URLS clean_restart diff --git a/gdb/tui/tui.c b/gdb/tui/tui.c index dea6ffbf954..8272ae4623e 100644 --- a/gdb/tui/tui.c +++ b/gdb/tui/tui.c @@ -36,6 +36,7 @@ #include "target.h" #include "frame.h" #include "breakpoint.h" +#include "debuginfod-support.h" #include "inferior.h" #include "symtab.h" #include "source.h" @@ -559,6 +560,11 @@ tui_disable (void) static void tui_enable_command (const char *args, int from_tty) { + /* Trigger any debuginfod-related y/n prompts now to avoid having + it occur during tui initialization. Handling the prompt while + tui windows are initializing can cause crashes. */ + debuginfod_is_enabled (); + tui_enable (); }