X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=gdb%2Fsource-cache.h;h=aa32fc5d60ebeb867cacbed927fe08c7a1c44c77;hb=2a5b130bcb6f376b6a28d8378172ed3f9b92e9d9;hp=b6656e035eed963949b87151ba906c62e5dc6a45;hpb=42a4f53d2bf8938c2aeda9f52be7a20534b214a9;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/source-cache.h b/gdb/source-cache.h index b6656e035e..aa32fc5d60 100644 --- a/gdb/source-cache.h +++ b/gdb/source-cache.h @@ -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. @@ -19,12 +19,20 @@ #ifndef SOURCE_CACHE_H #define SOURCE_CACHE_H -/* This caches highlighted source text, keyed by the source file's - full name. A size-limited LRU cache is used. +#include +#include + +/* This caches two things related to source files. + + First, it caches highlighted source text, keyed by the source + file's full name. A size-limited LRU cache is used. Highlighting depends on the GNU Source Highlight library. When not - available, this cache will fall back on reading plain text from the - appropriate file. */ + available or when highlighting fails for some reason, this cache + will instead store the un-highlighted source text. + + Second, this will cache the file offsets corresponding to the start + of each line of a source file. This cache is not size-limited. */ class source_cache { public: @@ -33,18 +41,31 @@ public: { } + /* This returns the vector of file offsets for the symtab S, + computing the vector first if needed. + + On failure, returns false. + + On success, returns true and sets *OFFSETS. This pointer is not + guaranteed to remain valid across other calls to get_source_lines + or get_line_charpos. */ + bool get_line_charpos (struct symtab *s, + const std::vector **offsets); + /* Get the source text for the source file in symtab S. FIRST_LINE and LAST_LINE are the first and last lines to return; line - numbers are 1-based. If the file cannot be read, false is - returned. Otherwise, LINES is set to the desired text. The - returned text may include ANSI terminal escapes. */ + numbers are 1-based. If the file cannot be read, or if the line + numbers are out of range, false is returned. Otherwise, + LINES_OUT is set to the desired text. The returned text may + include ANSI terminal escapes. */ bool get_source_lines (struct symtab *s, int first_line, - int last_line, std::string *lines); + int last_line, std::string *lines_out); /* Remove all the items from the source cache. */ void clear () { m_source_map.clear (); + m_offset_cache.clear (); } private: @@ -58,19 +79,22 @@ private: std::string contents; }; - /* A helper function for get_source_lines that is used when the - source lines are not highlighted. The arguments and return value - are as for get_source_lines. */ - bool get_plain_source_lines (struct symtab *s, int first_line, - int last_line, std::string *lines); - /* A helper function for get_plain_source_lines that extracts the - desired source lines from TEXT, putting them into LINES. The - arguments and return value are as for get_source_lines. */ - bool extract_lines (const struct source_text &text, int first_line, - int last_line, std::string *lines); - - /* The contents of the cache. */ + /* A helper function for get_source_lines reads a source file. + Returns the contents of the file; or throws an exception on + error. This also updates m_offset_cache. */ + std::string get_plain_source_lines (struct symtab *s, + const std::string &fullname); + + /* A helper function that the data for the given symtab is entered + into both caches. Returns false on error. */ + bool ensure (struct symtab *s); + + /* The contents of the source text cache. */ std::vector m_source_map; + + /* The file offset cache. The key is the full name of the source + file. */ + std::unordered_map> m_offset_cache; }; /* The global source cache. */