public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH v4 3/4] [gdb/cli] Allow source highlighting to be interrupted (continued)
Date: Wed, 18 Oct 2023 19:11:50 +0200	[thread overview]
Message-ID: <20231018171151.25427-4-tdevries@suse.de> (raw)
In-Reply-To: <20231018171151.25427-1-tdevries@suse.de>

In PR cli/30934, a problem is reported where gdb becomes unresponsive for
2m13s because the GNU source-highlight library is taking a lot of time to
annotate the source:
...
$ gdb -q a.out -ex "b 56"
Reading symbols from a.out...
Breakpoint 1 at 0x400e2a: file test.cpp, line 56.
(gdb) run
Starting program: /data/vries/gdb/a.out

Breakpoint 1, Solution::numOfSubarrays () at test.cpp:56
<... wait for it ...>
56	        return (int) t;
(gdb)
...

This is due to a problem in the library [1], for which I've posted a
patch [2], which brings down the annotation time to 3s.

However, GDB should not become unresponsive due to such a problem.

The previous patch allows us to interrupt a list command during highlighting
by either SIGTERM or SIGINT.

In this case, we can use SIGTERM to interrupt the run command, but not SIGINT.

This is due to the fact that the infrun_quit_handler is still active.

The purpose of infrun_quit_handler is to:
- if !target_terminal::is_ours, pass ^C to the inferior, and
- if target_terminal::is_ours, ignore ^C.  If gdb is executing say a continue
  in the background, it generates events and we don't want to interrupt the
  handling of these events.

In this case however, the reason target_terminal::is_ours is not because
there's background execution, but because normal_stop has decided that we have
stopped execution, and it's preparing to hand back control to GDB.

Fix this by switching back to the default_quit_handler during notify_normal_stop.

Tested on x86_64-linux.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30934

[1] https://savannah.gnu.org/bugs/?64747
[2] https://savannah.gnu.org/patch/index.php?10400
---
 gdb/infrun.c | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/gdb/infrun.c b/gdb/infrun.c
index 4fde96800fb..816a76a1b2c 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -9063,12 +9063,23 @@ normal_stop ()
   if (saved_context.changed ())
     return true;
 
-  /* Notify observers about the stop.  This is where the interpreters
-     print the stop event.  */
-  notify_normal_stop ((inferior_ptid != null_ptid
-		       ? inferior_thread ()->control.stop_bpstat
-		       : nullptr),
-		      stop_print_frame);
+  {
+    /* If the current quit_handler is infrun_quit_handler, and
+       target_terminal::is_ours, pressing ^C is ignored by QUIT.  See
+       infrun_quit_handler for an explanation.  At this point, there's
+       no need for this behaviour anymore, and we want to be able to interrupt
+       notify_normal_stop, so install the default_quit_handler.  */
+    scoped_restore restore_quit_handler
+      = make_scoped_restore (&quit_handler, default_quit_handler);
+
+    /* Notify observers about the stop.  This is where the interpreters
+       print the stop event.  */
+    notify_normal_stop ((inferior_ptid != null_ptid
+			 ? inferior_thread ()->control.stop_bpstat
+			 : nullptr),
+			stop_print_frame);
+  }
+
   annotate_stopped ();
 
   if (target_has_execution ())
-- 
2.35.3


  parent reply	other threads:[~2023-10-18 17:11 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-18 17:11 [PATCH v4 0/4] [gdb/cli] Allow source highlighting to be interrupted Tom de Vries
2023-10-18 17:11 ` [PATCH v4 1/4] [gdb/cli] Add gnu-source-highlight selftest Tom de Vries
2023-10-18 17:11 ` [PATCH v4 2/4] [gdb/cli] Allow source highlighting to be interrupted Tom de Vries
2023-10-18 17:11 ` Tom de Vries [this message]
2023-10-20 19:16   ` [PATCH v4 3/4] [gdb/cli] Allow source highlighting to be interrupted (continued) Pedro Alves
2023-10-24 12:35     ` Tom de Vries
2023-10-18 17:11 ` [PATCH v4 4/4] [gdb/cli] Ask if source highlighting should be interrupted Tom de Vries
2023-10-20 19:17   ` Pedro Alves
2023-10-24 12:47     ` Tom de Vries

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=20231018171151.25427-4-tdevries@suse.de \
    --to=tdevries@suse.de \
    --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).