Update ROCm for multi-target support
[deliverable/binutils-gdb.git] / gdb / source-cache.c
index 9039f8fde2a75996d3d9b6642929132516cf1ee3..965dc380b14c4100b0cc69220d738c1a0ba8a13c 100644 (file)
@@ -1,5 +1,5 @@
 /* Cache of styled source file text
-   Copyright (C) 2018-2019 Free Software Foundation, Inc.
+   Copyright (C) 2018-2020 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -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";
@@ -191,17 +190,28 @@ source_cache::ensure (struct symtab *s)
             conditional compilation in source-cache.h.  */
          static srchilite::SourceHighlight *highlighter;
 
-         if (highlighter == nullptr)
+         try
            {
-             highlighter = new srchilite::SourceHighlight ("esc.outlang");
-             highlighter->setStyleFile ("esc.style");
+             if (highlighter == nullptr)
+               {
+                 highlighter = new srchilite::SourceHighlight ("esc.outlang");
+                 highlighter->setStyleFile ("esc.style");
+               }
+
+             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. */
            }
-
-         std::istringstream input (contents);
-         std::ostringstream output;
-         highlighter->highlight (input, output, lang_name, fullname);
-
-         contents = output.str ();
        }
     }
 #endif /* HAVE_SOURCE_HIGHLIGHT */
@@ -221,19 +231,26 @@ bool
 source_cache::get_line_charpos (struct symtab *s,
                                const std::vector<off_t> **offsets)
 {
-  std::string fullname = symtab_to_fullname (s);
+  try
+    {
+      std::string fullname = symtab_to_fullname (s);
+
+      auto iter = m_offset_cache.find (fullname);
+      if (iter == m_offset_cache.end ())
+       {
+         ensure (s);
+         iter = m_offset_cache.find (fullname);
+         /* cache_source_text ensured this was entered.  */
+         gdb_assert (iter != m_offset_cache.end ());
+       }
 
-  auto iter = m_offset_cache.find (fullname);
-  if (iter == m_offset_cache.end ())
+      *offsets = &iter->second;
+      return true;
+    }
+  catch (const gdb_exception_error &e)
     {
-      ensure (s);
-      iter = m_offset_cache.find (fullname);
-      /* cache_source_text ensured this was entered.  */
-      gdb_assert (iter != m_offset_cache.end ());
+      return false;
     }
-
-  *offsets = &iter->second;
-  return true;
 }
 
 /* A helper function that extracts the desired source lines from TEXT,
This page took 0.023587 seconds and 4 git commands to generate.