From d806ea2d0ef362fcddd2c1659f537b68aa114203 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Mon, 24 Jun 2019 16:02:47 -0600 Subject: 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. 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-08-19 Tom Tromey * 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/source-cache.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'gdb/source-cache.c') diff --git a/gdb/source-cache.c b/gdb/source-cache.c index 9039f8f..18e2be9 100644 --- a/gdb/source-cache.c +++ b/gdb/source-cache.c @@ -135,8 +135,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"; @@ -197,11 +196,22 @@ source_cache::ensure (struct symtab *s) highlighter->setStyleFile ("esc.style"); } - std::istringstream input (contents); - std::ostringstream output; - highlighter->highlight (input, output, lang_name, fullname); - - contents = output.str (); + try + { + std::istringstream input (contents); + std::ostringstream output; + highlighter->highlight (input, output, lang_name, fullname); + contents = output.str (); + } + 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. */ + } } } #endif /* HAVE_SOURCE_HIGHLIGHT */ -- cgit v1.1