]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Add Rust support to source highlighting
authorTom Tromey <tom@tromey.com>
Thu, 19 Sep 2019 14:18:33 +0000 (16:18 +0200)
committerTom de Vries <tdevries@suse.de>
Thu, 19 Sep 2019 14:18:33 +0000 (16:18 +0200)
[ Backport of master commit d806ea2d0e. ]

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>

PR gdb/25009
* 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 969515a65e93ff2337f7824ee0dac9e1754b41ba..765e2c95e14ff24232bd9e58ed9016c01d517f40 100644 (file)
@@ -1,3 +1,12 @@
+2019-08-19  Tom Tromey  <tom@tromey.com>
+
+       PR gdb/25009
+       * 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-06-28  Sergio Durigan Junior  <sergiodj@redhat.com>
 
        PR breakpoints/24541
index 854837c50a386038a7e0088ebcda2bae3b337eee..866564fbe68d0432240ff03d1f8bb74c8477514e 100755 (executable)
@@ -11503,6 +11503,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 1527585839db6f16d9d1691d349320d42f93fc71..0805827adf60da60dec6d1df34c297a37b6df07e 100644 (file)
@@ -1251,6 +1251,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 5eae02082df85d912805804c7a5619f1ceb1885d..d443c5e7fbb184e4723ccf9e47cc962ae6b4f51d 100644 (file)
@@ -156,8 +156,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";
@@ -213,21 +212,33 @@ source_cache::get_source_lines (struct symtab *s, int first_line,
                     use-after-free.  */
                  fullname = symtab_to_fullname (s);
                }
-             srchilite::SourceHighlight highlighter ("esc.outlang");
-             highlighter.setStyleFile("esc.style");
+             try
+               {
+                 srchilite::SourceHighlight highlighter ("esc.outlang");
+                 highlighter.setStyleFile("esc.style");
 
-             std::ostringstream output;
-             highlighter.highlight (input, output, lang_name, fullname);
+                 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. */
+               }
            }
        }
     }