From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 B98823858C56 for ; Fri, 17 May 2024 14:31:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B98823858C56 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 B98823858C56 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=1715956266; cv=none; b=WDxOZFvOsWDf7HPJIKxO94dXa/mAseO81ZHg9Lf9BtP94GQc50w3UUqGnskwr+RboDt/RuRM/yEF1APNB8+s/kBg5Ppgj72UB0+qYSqZPhr1ycDnZ8J1mqZq98daRlXXrLzxXPhEzTYxK6R37dx5HxUOJFJ6hi0VCDtkDgMhaCw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715956266; c=relaxed/simple; bh=H0P9BT3K1qI8LVC2T6eJlCGoSUscCm1m7Nr1/W5e3Us=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=CqbavDCMT10EhW71Tt5L/CP92sW/ICC+9pkQVVIeRXFjwUVTJFiZ+Q8rw2Z/RIbchnaNRLyNAMOKCGhgtHTHnnWsA7J92hL6jLhYIQO9/+gEbGVwZybPmLGr4uU21Ec57EaB45CQlI+NYzCT7M3O3hPZ55pmWGCjQQPk2Y50ngg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715956264; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=InsV6QdcGiFdrDypW5M6dCwyIBH8TNbO7r1ACvf9MRY=; b=D0OX5ih/msGyxWFnWRHEZU+lVu5ahpFsqRqu5J814fUBKAcYbxN+/huxzZ4EJXphsFBrFC f34x66wKnTAHLS6YzgioUne/FqsC4q/op9BRHL3sVpLGy9aVRpNNwmzn2iGSeKeowwguDx r+EksdoUeoImXNIb2b0GTGVXY1040jM= Received: from mail-il1-f197.google.com (mail-il1-f197.google.com [209.85.166.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-462-OeTjak5oP_u99JcMaj_HqQ-1; Fri, 17 May 2024 10:31:02 -0400 X-MC-Unique: OeTjak5oP_u99JcMaj_HqQ-1 Received: by mail-il1-f197.google.com with SMTP id e9e14a558f8ab-36c80caae04so106977175ab.2 for ; Fri, 17 May 2024 07:31:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715956262; x=1716561062; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=InsV6QdcGiFdrDypW5M6dCwyIBH8TNbO7r1ACvf9MRY=; b=E6QEhjd4dw4wP5MkIe/39sm6Z+siHOhRn6dR8Ygp8jNaY9rQgj36U1/PqvWsm/xqhZ crruIBHfEk4f2vFWIhUf8lLplS2+Wz+BG098kiMI81QT6y5txv/8SVuHibJeaep11wZj P78ETZGY4b4/PMf0KiWWOd6etX6g9FSYPQTG3G1PxuqiPRetwK2JtBiC0bgrfna0+ddx qsfwLoDNFktpnFNbS1F+sUGZ5kMKfJ/x3K8nDmmBLLWIgflehZdTPpHCxsmo5K31rZRx zBFqHeEqqTJym6hcuoP2vJjPdpQFDH+KEMMknfX+kuNO5yCYzQ5Ds3He0OFG5NyX4zfL 0/QA== X-Gm-Message-State: AOJu0YzaAVPIdy0L5OlosCO+rzBFdzYPadCe3WD/uNibgKnMSGIRXyy4 EfD5CGWJCQ+VOAoc1BozO/C7EP7nFmz4N6vlmRZB5rL+S2nEhipG9oMPM/FZhGObx8Y9XiTiiC+ nEu3qAeF6gOmTbJnAFcsnrHrGswhy+aw5WgaZZEb+T/e7sxhHXQGNdpwEjcF/h1tAnINvrswJE0 9lT6kcyZFwS9LOhreyZnilEFxrjhgD8yIjj6OzII85 X-Received: by 2002:a05:6e02:1446:b0:36a:3fb1:6499 with SMTP id e9e14a558f8ab-36cc1484ee9mr252750505ab.2.1715956261960; Fri, 17 May 2024 07:31:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEIhLou0NLUAtMo7J0ug/IQcyOpt2gIivhH4EnWoEKkRma63PIe9PjECYvmoKS/7zaJkLQ0aUG9l8xCxdx9XH8= X-Received: by 2002:a05:6e02:1446:b0:36a:3fb1:6499 with SMTP id e9e14a558f8ab-36cc1484ee9mr252750185ab.2.1715956261547; Fri, 17 May 2024 07:31:01 -0700 (PDT) MIME-Version: 1.0 References: <20240312215334.37888-1-amerey@redhat.com> In-Reply-To: <20240312215334.37888-1-amerey@redhat.com> From: Aaron Merey Date: Fri, 17 May 2024 10:30:51 -0400 Message-ID: Subject: [PING][PATCH] gdb/tui: Fix crash from y/n prompt during TUI initialization To: gdb-patches@sourceware.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-11.9 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 autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Ping Thanks, Aaron On Tue, Mar 12, 2024 at 5:53=E2=80=AFPM Aaron Merey wro= te: > > 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=3D31449 > --- > 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 =3D 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 unsi= gned 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 (); > } > > -- > 2.43.0 >