gdb/tui: Fix crash from y/n prompt during TUI initialization
Checks
Context |
Check |
Description |
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 |
success
|
Testing passed
|
linaro-tcwg-bot/tcwg_gdb_build--master-arm |
success
|
Testing passed
|
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 |
success
|
Testing passed
|
linaro-tcwg-bot/tcwg_gdb_check--master-arm |
success
|
Testing passed
|
Commit Message
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(-)
@@ -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));
@@ -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 */
@@ -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
@@ -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 ();
}