X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=gdb%2Fsource-cache.c;h=9196e3a19e3f60fcdab1225bd306e6a594f7bf7e;hb=refs%2Fheads%2Fconcurrent-displaced-stepping-2020-04-01;hp=d546ae59524854964ad224f0862523ce5decf4b5;hpb=6c2659886f7018fcca26ee0fc813bc9748fb8513;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/source-cache.c b/gdb/source-cache.c index d546ae5952..9196e3a19e 100644 --- a/gdb/source-cache.c +++ b/gdb/source-cache.c @@ -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) { @@ -202,6 +212,7 @@ source_cache::ensure (struct symtab *s) 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 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 **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,