Add Rust support to source highlighting
authorTom Tromey <tom@tromey.com>
Mon, 24 Jun 2019 22:02:47 +0000 (16:02 -0600)
committerTom Tromey <tromey@adacore.com>
Mon, 19 Aug 2019 16:17:27 +0000 (10:17 -0600)
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  <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
gdb/configure
gdb/configure.ac
gdb/source-cache.c

index c43ee64b096e9485fde834ee30412f0ef089471a..c6548723d0e54825b2b8af5e248a435ecf0de70c 100644 (file)
@@ -1,3 +1,11 @@
+2019-08-19  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.
+
 2019-08-16  Tom Tromey  <tom@tromey.com>
 
        * tui/tui.h (enum tui_win_type) <EXEC_INFO_WIN>: Remove.
index 2832c836177602493e69ed4c26a2de6dc3025f7e..cb71bbf057a24e04d37f4e2d8ae2066732dc79f8 100755 (executable)
@@ -11326,6 +11326,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`
index 0979109d976582877a2abb636db4c3e4fa712978..5a18c1640572b8c067670a4a184baa2732176023 100644 (file)
@@ -1231,6 +1231,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`
index 9039f8fde2a75996d3d9b6642929132516cf1ee3..18e2be989b4b14349ee74815b97d9c169da505e8 100644 (file)
@@ -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 */
This page took 0.03826 seconds and 4 git commands to generate.