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: [RFC] [gdb/cli] Allow source highlighting to be interrupted
Date: Wed, 11 Oct 2023 15:42:47 +0200	[thread overview]
Message-ID: <20231011134247.3832-1-tdevries@suse.de> (raw)

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.

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.

Fix this by installing a srchilite::HighlightEventListener that checks whether
^C was pressed, and if so abandons the highlighting by throwing an exception.

Abandoning the highlighting looks like this to the user:
...
$ gdb -q a.out -ex "b 56"
Reading symbols from a.out...
Breakpoint 1 at 0x400e2a: file test.cpp, line 56.
(gdb) r
Starting program: /data/vries/gdb/a.out

Breakpoint 1, Solution::numOfSubarrays (this=0x7fffffffdbcf, arr=...) at test.cpp:56
^Cwarning: Couldn't highlight source file /data/vries/gdb/test.cpp: Interrupted
56	        return (int) t;
(gdb)
...

RFC: is the warning a good idea, or overkill?

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/source-cache.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/gdb/source-cache.c b/gdb/source-cache.c
index 77b357cb42b..bd466869276 100644
--- a/gdb/source-cache.c
+++ b/gdb/source-cache.c
@@ -37,6 +37,7 @@
 #include <sstream>
 #include <srchilite/sourcehighlight.h>
 #include <srchilite/langmap.h>
+#include <srchilite/highlighteventlistener.h>
 #endif
 
 /* The number of source files we'll cache.  */
@@ -189,6 +190,25 @@ get_language_name (enum language lang)
   return nullptr;
 }
 
+/* Class with notify function called during highlighting.  */
+
+class gdb_highlight_event_listener : public srchilite::HighlightEventListener
+{
+public:
+  void notify(const srchilite::HighlightEvent &event) override
+  {
+    if (check_quit_flag ())
+      {
+	/* Got SIGINT, interrupt highlighting, it may take too long.  */
+	throw_quit ("Interrupted");
+      }
+  }
+};
+
+/* Object with notify function called during highlighting.  */
+
+static gdb_highlight_event_listener the_gdb_highlight_event_listener;
+
 #endif /* HAVE_SOURCE_HIGHLIGHT */
 
 /* See source-cache.h.  */
@@ -247,6 +267,8 @@ source_cache::ensure (struct symtab *s)
 		{
 		  highlighter = new srchilite::SourceHighlight ("esc.outlang");
 		  highlighter->setStyleFile ("esc.style");
+		  highlighter->setHighlightEventListener
+		    (&the_gdb_highlight_event_listener);
 		}
 
 	      std::istringstream input (contents);
@@ -255,6 +277,11 @@ source_cache::ensure (struct symtab *s)
 	      contents = output.str ();
 	      already_styled = true;
 	    }
+	  catch (const gdb_exception_quit &ex)
+	    {
+	      warning (_("Failed to highlight source file %s: %s"),
+		       fullname.c_str (), ex.what ());
+	    }
 	  catch (...)
 	    {
 	      /* Source Highlight will throw an exception if

base-commit: f6ca448ab70c52e923b7010aecdf7be9c0d4d4fc
-- 
2.35.3


             reply	other threads:[~2023-10-11 13:42 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-11 13:42 Tom de Vries [this message]
2023-10-11 17:02 ` Tom Tromey
2023-10-11 18:11   ` Tom de Vries
2023-10-13 12:25     ` Tom de Vries
2023-10-11 21:56   ` Tom de Vries
2023-10-12 14:52     ` Tom de Vries
2023-10-11 17:49 ` Konstantin Kharlamov

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=20231011134247.3832-1-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).