Move DWARF line_header to new file
[deliverable/binutils-gdb.git] / gdb / source-cache.c
index 7a52ce9458e538153412e89d576a2af4b43afa41..9196e3a19e3f60fcdab1225bd306e6a594f7bf7e 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.
 
@@ -176,11 +176,21 @@ source_cache::ensure (struct symtab *s)
        }
     }
 
-  std::string contents = get_plain_source_lines (s, fullname);
+  std::string contents;
+  try
+    {
+      contents = get_plain_source_lines (s, fullname);
+    }
+  catch (const gdb_exception_error &e)
+    {
+      /* If 's' is not found, an exception is thrown.  */
+      return false;
+    }
 
-#ifdef HAVE_SOURCE_HIGHLIGHT
   if (source_styling && gdb_stdout->can_emit_style_escape ())
     {
+#ifdef HAVE_SOURCE_HIGHLIGHT
+      bool already_styled = false;
       const char *lang_name = get_language_name (SYMTAB_LANGUAGE (s));
       if (lang_name != nullptr)
        {
@@ -190,18 +200,19 @@ source_cache::ensure (struct symtab *s)
             conditional compilation in source-cache.h.  */
          static srchilite::SourceHighlight *highlighter;
 
-         if (highlighter == nullptr)
-           {
-             highlighter = new srchilite::SourceHighlight ("esc.outlang");
-             highlighter->setStyleFile ("esc.style");
-           }
-
          try
            {
+             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 ();
+             already_styled = true;
            }
          catch (...)
            {
@@ -213,8 +224,16 @@ source_cache::ensure (struct symtab *s)
                 un-highlighted text. */
            }
        }
-    }
+
+      if (!already_styled)
 #endif /* HAVE_SOURCE_HIGHLIGHT */
+       {
+         gdb::optional<std::string> ext_contents;
+         ext_contents = ext_lang_colorize (fullname, contents);
+         if (ext_contents.has_value ())
+           contents = std::move (*ext_contents);
+       }
+    }
 
   source_text result = { std::move (fullname), std::move (contents) };
   m_source_map.push_back (std::move (result));
@@ -231,26 +250,20 @@ bool
 source_cache::get_line_charpos (struct symtab *s,
                                const std::vector<off_t> **offsets)
 {
-  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 ());
-       }
+  std::string fullname = symtab_to_fullname (s);
 
-      *offsets = &iter->second;
-      return true;
-    }
-  catch (const gdb_exception_error &e)
+  auto iter = m_offset_cache.find (fullname);
+  if (iter == m_offset_cache.end ())
     {
-      return false;
+      if (!ensure (s))
+       return false;
+      iter = m_offset_cache.find (fullname);
+      /* cache_source_text ensured this was entered.  */
+      gdb_assert (iter != m_offset_cache.end ());
     }
+
+  *offsets = &iter->second;
+  return true;
 }
 
 /* A helper function that extracts the desired source lines from TEXT,
@@ -329,6 +342,7 @@ static void extract_lines_test ()
 }
 #endif
 
+void _initialize_source_cache ();
 void
 _initialize_source_cache ()
 {
This page took 0.024817 seconds and 4 git commands to generate.