]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/source-cache.h
PR24435, buffer overflow reading dynamic entries
[thirdparty/binutils-gdb.git] / gdb / source-cache.h
CommitLineData
62f29fda 1/* Cache of styled source file text
42a4f53d 2 Copyright (C) 2018-2019 Free Software Foundation, Inc.
62f29fda
TT
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18
19#ifndef SOURCE_CACHE_H
20#define SOURCE_CACHE_H
21
22/* This caches highlighted source text, keyed by the source file's
23 full name. A size-limited LRU cache is used.
24
25 Highlighting depends on the GNU Source Highlight library. When not
26 available, this cache will fall back on reading plain text from the
27 appropriate file. */
28class source_cache
29{
30public:
31
32 source_cache ()
33 {
34 }
35
36 /* Get the source text for the source file in symtab S. FIRST_LINE
37 and LAST_LINE are the first and last lines to return; line
38 numbers are 1-based. If the file cannot be read, false is
38561778 39 returned. Otherwise, LINES_OUT is set to the desired text. The
62f29fda
TT
40 returned text may include ANSI terminal escapes. */
41 bool get_source_lines (struct symtab *s, int first_line,
38561778 42 int last_line, std::string *lines_out);
62f29fda
TT
43
44 /* Remove all the items from the source cache. */
45 void clear ()
46 {
47 m_source_map.clear ();
48 }
49
50private:
51
52 /* One element in the cache. */
53 struct source_text
54 {
55 /* The full name of the file. */
56 std::string fullname;
57 /* The contents of the file. */
58 std::string contents;
59 };
60
61 /* A helper function for get_source_lines that is used when the
62 source lines are not highlighted. The arguments and return value
63 are as for get_source_lines. */
64 bool get_plain_source_lines (struct symtab *s, int first_line,
38561778 65 int last_line, std::string *lines_out);
62f29fda 66 /* A helper function for get_plain_source_lines that extracts the
38561778 67 desired source lines from TEXT, putting them into LINES_OUT. The
3b336828
TT
68 arguments are as for get_source_lines. The return value is the
69 desired lines. */
70 std::string extract_lines (const struct source_text &text, int first_line,
71 int last_line);
62f29fda
TT
72
73 /* The contents of the cache. */
74 std::vector<source_text> m_source_map;
75};
76
77/* The global source cache. */
78extern source_cache g_source_cache;
79
80#endif /* SOURCE_CACHE_H */