public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb/tui: Fix crash from y/n prompt during TUI initialization
@ 2024-03-12 21:53 Aaron Merey
  2024-05-17 14:30 ` [PING][PATCH] " Aaron Merey
  0 siblings, 1 reply; 2+ messages in thread
From: Aaron Merey @ 2024-03-12 21:53 UTC (permalink / raw)
  To: gdb-patches; +Cc: Aaron Merey

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PING][PATCH] gdb/tui: Fix crash from y/n prompt during TUI initialization
  2024-03-12 21:53 [PATCH] gdb/tui: Fix crash from y/n prompt during TUI initialization Aaron Merey
@ 2024-05-17 14:30 ` Aaron Merey
  0 siblings, 0 replies; 2+ messages in thread
From: Aaron Merey @ 2024-05-17 14:30 UTC (permalink / raw)
  To: gdb-patches

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
>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-05-17 14:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-12 21:53 [PATCH] gdb/tui: Fix crash from y/n prompt during TUI initialization Aaron Merey
2024-05-17 14:30 ` [PING][PATCH] " Aaron Merey

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).