/* 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.
}
}
- 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)
{
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 (...)
{
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));
auto iter = m_offset_cache.find (fullname);
if (iter == m_offset_cache.end ())
{
- ensure (s);
+ 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 ());
}
#endif
+void _initialize_source_cache ();
void
_initialize_source_cache ()
{