public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH v2 2/2] Add Rust support to source highlighting
Date: Sat, 27 Jul 2019 15:52:00 -0000	[thread overview]
Message-ID: <20190727155155.32417-3-tom@tromey.com> (raw)
In-Reply-To: <20190727155155.32417-1-tom@tromey.com>

Currently, no release of GNU Source Highlight supports Rust.  However,
I've checked in a patch to do so there, and I plan to make a new
release sometime this summer.

This patch prepares gdb for that by adding support for Rust to the
source highlighting code.

Because Source Highlight will throw an exception if the language is
unrecognized, this also changes gdb to ignore exceptions here.  This
will cause gdb to fall back to un-highlighted source text.

This updates gdb's configure script to reject the combination of
Source Highlight and -static-libstdc++.  This is done because it's not
possible to use -static-libstdc++ and then catch exceptions from a
shared library.

Tested with the current and development versions of Source Highlight.

gdb/ChangeLog
2019-07-27  Tom Tromey  <tom@tromey.com>

	* configure: Rebuild.
	* configure.ac: Disallow the combination of -static-libstdc++ and
	source highlight.
	* source-cache.c (get_language_name): Handle rust.
	(source_cache::get_source_lines): Ignore highlighting exceptions.
---
 gdb/ChangeLog      |  8 ++++++++
 gdb/configure      |  6 ++++++
 gdb/configure.ac   |  8 ++++++++
 gdb/source-cache.c | 33 ++++++++++++++++++++++-----------
 4 files changed, 44 insertions(+), 11 deletions(-)

diff --git a/gdb/configure b/gdb/configure
index 12954d1f74a..cd92b70958c 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -11296,6 +11296,12 @@ $as_echo "no - pkg-config not found" >&6; }
       as_fn_error $? "pkg-config was not found in your system" "$LINENO" 5
     fi
   else
+    case "$LDFLAGS" in
+      *static-libstdc*)
+        as_fn_error $? "source highlight is incompatible with -static-libstdc++; either use --disable-source-highlight or --without-static-standard-libraries" "$LINENO" 5
+        ;;
+    esac
+
     if ${pkg_config_prog_path} --exists source-highlight; then
       SRCHIGH_CFLAGS=`${pkg_config_prog_path} --cflags source-highlight`
       SRCHIGH_LIBS=`${pkg_config_prog_path} --libs source-highlight`
diff --git a/gdb/configure.ac b/gdb/configure.ac
index 2a43d12df76..3dc4b7549b1 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -1217,6 +1217,14 @@ if test "${enable_source_highlight}" != "no"; then
       AC_MSG_ERROR([pkg-config was not found in your system])
     fi
   else
+    case "$LDFLAGS" in
+      *static-libstdc*)
+        AC_MSG_ERROR([source highlight is incompatible with -static-libstdc++; dnl
+either use --disable-source-highlight or dnl
+--without-static-standard-libraries])
+        ;;
+    esac
+
     if ${pkg_config_prog_path} --exists source-highlight; then
       SRCHIGH_CFLAGS=`${pkg_config_prog_path} --cflags source-highlight`
       SRCHIGH_LIBS=`${pkg_config_prog_path} --libs source-highlight`
diff --git a/gdb/source-cache.c b/gdb/source-cache.c
index f5bb641a22b..06a244ebbf0 100644
--- a/gdb/source-cache.c
+++ b/gdb/source-cache.c
@@ -154,8 +154,7 @@ get_language_name (enum language lang)
       break;
 
     case language_rust:
-      /* Not handled by Source Highlight.  */
-      break;
+      return "rust.lang";
 
     case language_ada:
       return "ada.lang";
@@ -224,18 +223,30 @@ source_cache::get_source_lines (struct symtab *s, int first_line,
 		  highlighter->setStyleFile ("esc.style");
 		}
 
-	      std::ostringstream output;
-	      highlighter->highlight (input, output, lang_name, fullname);
+	      try
+		{
+		  std::ostringstream output;
+		  highlighter->highlight (input, output, lang_name, fullname);
 
-	      source_text result = { fullname, output.str () };
-	      m_source_map.push_back (std::move (result));
+		  source_text result = { fullname, output.str () };
+		  m_source_map.push_back (std::move (result));
 
-	      if (m_source_map.size () > MAX_ENTRIES)
-		m_source_map.erase (m_source_map.begin ());
+		  if (m_source_map.size () > MAX_ENTRIES)
+		    m_source_map.erase (m_source_map.begin ());
 
-	      *lines = extract_lines (m_source_map.back (), first_line,
-				      last_line);
-	      return true;
+		  *lines = extract_lines (m_source_map.back (), first_line,
+					  last_line);
+		  return true;
+		}
+	      catch (...)
+		{
+		  /* Source Highlight will throw an exception if
+		     highlighting fails.  One possible reason it can
+		     fail is if the language is unknown -- which
+		     matters to gdb because Rust support wasn't added
+		     until after 3.1.8.  Ignore exceptions here and
+		     fall back to un-highlighted text. */
+		}
 	    }
 	}
     }
-- 
2.17.2

  reply	other threads:[~2019-07-27 15:52 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-27 15:52 [PATCH v2 0/2] " Tom Tromey
2019-07-27 15:52 ` Tom Tromey [this message]
2019-09-04 17:22   ` [PATCH v2 2/2] " Tom de Vries
2019-09-10 15:56     ` Tom Tromey
2019-09-12 19:20       ` Tom de Vries
2019-09-17 18:24         ` Tom Tromey
2019-09-18 22:16           ` Tom de Vries
2019-09-19 12:54             ` Tom Tromey
2019-09-19 16:18               ` [PATCH][gdb] Catch exception when constructing the highlighter Tom de Vries
2019-07-27 15:52 ` [PATCH v2 1/2] Add --with-static-standard-libraries to the top level Tom Tromey
2019-08-19 16:19 ` [PATCH v2 0/2] Add Rust support to source highlighting Tom Tromey
2019-08-19 18:29   ` Pedro Alves

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=20190727155155.32417-3-tom@tromey.com \
    --to=tom@tromey.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).