This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Add Rust support to source highlighting


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.

Tested with the current and development versions of Source Highlight.

gdb/ChangeLog
2019-06-24  Tom Tromey  <tom@tromey.com>

	* source-cache.c (get_language_name): Handle rust.
	(source_cache::get_source_lines): Ignore highlighting exceptions.
---
 gdb/ChangeLog      |  5 +++++
 gdb/source-cache.c | 33 ++++++++++++++++++++++-----------
 2 files changed, 27 insertions(+), 11 deletions(-)

diff --git a/gdb/source-cache.c b/gdb/source-cache.c
index 86efe83bf9a..72211aa1c34 100644
--- a/gdb/source-cache.c
+++ b/gdb/source-cache.c
@@ -153,8 +153,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";
@@ -223,18 +222,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 an
+		     fall back to un-highlighted text. */
+		}
 	    }
 	}
     }
-- 
2.17.2


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]