public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Aaron Merey <amerey@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PING][PATCH] gdb/tui: Fix crash from y/n prompt during TUI initialization
Date: Fri, 17 May 2024 10:30:51 -0400	[thread overview]
Message-ID: <CAJDtP-S3_a-oyK1dUtHySUdZw42z7nnm4YSTYgMiNCdd-BbKSA@mail.gmail.com> (raw)
In-Reply-To: <20240312215334.37888-1-amerey@redhat.com>

Ping

Thanks,
Aaron

On Tue, Mar 12, 2024 at 5:53 PM Aaron Merey <amerey@redhat.com> wrote:
>
> 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<char>
>                                              *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
>


  reply	other threads:[~2024-05-17 14:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-12 21:53 [PATCH] " Aaron Merey
2024-05-17 14:30 ` Aaron Merey [this message]
2024-05-22 17:48 ` Guinevere Larsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAJDtP-S3_a-oyK1dUtHySUdZw42z7nnm4YSTYgMiNCdd-BbKSA@mail.gmail.com \
    --to=amerey@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).