public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>
Subject: [PATCH 09/15] gdb/tui: disable tui mode when an assert triggers
Date: Fri,  6 Jan 2023 10:25:36 +0000	[thread overview]
Message-ID: <212ca24d63f8068c2a3d5f2051435b2b26d4d3ee.1673000632.git.aburgess@redhat.com> (raw)
In-Reply-To: <cover.1673000632.git.aburgess@redhat.com>

When an assert triggers in tui mode the output is not great, the
internal backtrace that is generated is printed directly to the file
descriptor for gdb_stderr, and, as a result, does not currently format
itself correctly - the output uses only '\n' at the end of each line,
and so, when the terminal is in raw mode, the cursor does not return
to the start of each line after the '\n'.

This is mostly fixable, we could update bt-utils.c to use '\r\n'
instead of just '\n', and this would fix most of the problems.  The
one we can't easily fix is if/when GDB is built to use execinfo
instead of libbacktrace, in this case we use backtrace_symbols_fd to
print the symbols, and this function only uses '\n' as the line
terminator.  Fixing this would require switching to backtrace_symbols,
but that API uses malloc, which is something we're trying to
avoid (this code is called when GDB hits an error, so ideally we don't
want to rely on malloc).

However, the execinfo code is only used when libbacktrace is not
available (or the user specifically disables libbacktrace) so maybe we
can ignore that problem...

... but there is another problem.  When the backtrace is printed in
raw mode, it is possible that the backtrace fills the screen.  With
the terminal in raw mode we don't have the ability to scroll back,
which means we loose some of the backtrace, which isn't ideal.

In this commit I propose that we should disable tui mode whenever we
handle a fatal signal, or when we hit the internal error code
path (e.g. when an assert triggers).  With this done then we don't
need to update the bt-utils.c code, and the execinfo version of the
code (using backtrace_symbols_fd) works just fine.  We also get the
ability to scroll back to view the error message and all of the
backtrace, assuming the users terminal supports scrolling back.

The only downside I see with this change is if the tui_disable call
itself causes an error for some reason, or, if we handle a single at a
time when it is not safe to call tui_disable, in these cases the extra
tui_disable call might cause GDB to loose the original error.

However, I think (just from personal experience) that the above two
issues are pretty rare and the benefits from this change far out
weighs the possible drawbacks.
---
 gdb/event-top.c | 8 ++++++++
 gdb/utils.c     | 7 ++++++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/gdb/event-top.c b/gdb/event-top.c
index 4a46e1b9346..14984707df1 100644
--- a/gdb/event-top.c
+++ b/gdb/event-top.c
@@ -48,6 +48,10 @@
 #include "readline/readline.h"
 #include "readline/history.h"
 
+#ifdef TUI
+#include "tui/tui.h"
+#endif
+
 /* readline defines this.  */
 #undef savestring
 
@@ -940,6 +944,10 @@ unblock_signal (int sig)
 static void ATTRIBUTE_NORETURN
 handle_fatal_signal (int sig)
 {
+#ifdef TUI
+  tui_disable ();
+#endif
+
 #ifdef GDB_PRINT_INTERNAL_BACKTRACE
   const auto sig_write = [] (const char *msg) -> void
   {
diff --git a/gdb/utils.c b/gdb/utils.c
index 734c5bf7f70..95adbe58e4a 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -29,7 +29,8 @@
 #endif /* HAVE_SYS_RESOURCE_H */
 
 #ifdef TUI
-#include "tui/tui.h"		/* For tui_get_command_dimension.   */
+/* For tui_get_command_dimension and tui_disable.   */
+#include "tui/tui.h"
 #endif
 
 #ifdef __GO32__
@@ -354,6 +355,10 @@ internal_vproblem (struct internal_problem *problem,
       }
   }
 
+#ifdef TUI
+  tui_disable ();
+#endif
+
   /* Create a string containing the full error/warning message.  Need
      to call query with this full string, as otherwize the reason
      (error/warning) and question become separated.  Format using a
-- 
2.25.4


  parent reply	other threads:[~2023-01-06 10:26 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-06 10:25 [PATCH 00/15] Mixed bag of TUI tests and fixes Andrew Burgess
2023-01-06 10:25 ` [PATCH 01/15] gdb/testsuite: extend gdb.tui/tui-layout.exp test script Andrew Burgess
2023-01-25 11:29   ` Andrew Burgess
2023-01-06 10:25 ` [PATCH 02/15] gdb/testsuite: update gdb.tui/tui-disasm-long-lines.exp Andrew Burgess
2023-01-25 11:29   ` Andrew Burgess
2023-01-06 10:25 ` [PATCH 03/15] gdb/testsuite: update gdb.tui/tui-nl-filtered-output.exp Andrew Burgess
2023-01-25 11:30   ` Andrew Burgess
2023-01-06 10:25 ` [PATCH 04/15] gdb/testsuite/tui: more testing of the 'focus' command Andrew Burgess
2023-01-25 11:32   ` Andrew Burgess
2023-01-06 10:25 ` [PATCH 05/15] gdb/tui: convert if/error to an assert Andrew Burgess
2023-01-25 11:33   ` Andrew Burgess
2023-01-06 10:25 ` [PATCH 06/15] gdb/tui: better filtering of tab completion results for focus command Andrew Burgess
2023-01-25 11:33   ` Andrew Burgess
2023-01-06 10:25 ` [PATCH 07/15] gdb/testsuite: fix line feed scrolling in tuiterm.exp Andrew Burgess
2023-01-06 10:25 ` [PATCH 08/15] gdb/tui: improve errors from tui focus command Andrew Burgess
2023-01-06 10:25 ` Andrew Burgess [this message]
2023-01-06 10:25 ` [PATCH 10/15] gdb/tui: make m_horizontal_offset private Andrew Burgess
2023-01-06 10:25 ` [PATCH 11/15] gdb/tui: rewrite of tui_source_window_base to handle very long lines Andrew Burgess
2023-01-06 10:25 ` [PATCH 12/15] gdb/tui: avoid extra refresh_window on horizontal scroll Andrew Burgess
2023-01-06 10:25 ` [PATCH 13/15] gdb/tui: avoid extra refresh_window on vertical scroll Andrew Burgess
2023-01-06 10:25 ` [PATCH 14/15] gdb/tui: more debug output Andrew Burgess
2023-01-06 10:25 ` [PATCH 15/15] gdb/tui: make use of a scoped_restore Andrew Burgess
2023-01-25 12:01   ` Andrew Burgess
2023-01-25 12:08 ` [PATCHv2 0/8] Mixed bag of TUI tests and fixes Andrew Burgess
2023-01-25 12:08   ` [PATCHv2 1/8] gdb/testsuite: fix line feed scrolling in tuiterm.exp Andrew Burgess
2023-01-25 19:46     ` Tom Tromey
2023-01-25 12:08   ` [PATCHv2 2/8] gdb/tui: improve errors from tui focus command Andrew Burgess
2023-01-25 12:08   ` [PATCHv2 3/8] gdb/tui: disable tui mode when an assert triggers Andrew Burgess
2023-01-25 12:08   ` [PATCHv2 4/8] gdb/tui: make m_horizontal_offset private Andrew Burgess
2023-01-25 12:08   ` [PATCHv2 5/8] gdb/tui: rewrite of tui_source_window_base to handle very long lines Andrew Burgess
2023-01-25 12:08   ` [PATCHv2 6/8] gdb/tui: avoid extra refresh_window on horizontal scroll Andrew Burgess
2023-01-25 20:05     ` Tom Tromey
2023-01-25 12:08   ` [PATCHv2 7/8] gdb/tui: avoid extra refresh_window on vertical scroll Andrew Burgess
2023-01-25 12:08   ` [PATCHv2 8/8] gdb/tui: more debug output Andrew Burgess
2023-01-25 20:07   ` [PATCHv2 0/8] Mixed bag of TUI tests and fixes Tom Tromey
2023-01-27 16:31     ` Andrew Burgess

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=212ca24d63f8068c2a3d5f2051435b2b26d4d3ee.1673000632.git.aburgess@redhat.com \
    --to=aburgess@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).