1 /* Caching of GDB/DWARF index files.
3 Copyright (C) 2018 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #ifndef DWARF_INDEX_CACHE_H
21 #define DWARF_INDEX_CACHE_H
23 #include "dwarf-index-common.h"
24 #include "common/array-view.h"
27 /* Base of the classes used to hold the resources of the indices loaded from
28 the cache (e.g. mmapped files). */
30 struct index_cache_resource
32 virtual ~index_cache_resource () = 0;
35 /* Class to manage the access to the DWARF index cache. */
40 /* Change the directory used to save/load index files. */
41 void set_directory (std::string dir);
43 /* Return true if the usage of the cache is enabled. */
49 /* Enable the cache. */
52 /* Disable the cache. */
55 /* Store an index for the specified object file in the cache. */
56 void store (struct dwarf2_per_objfile *dwarf2_per_objfile);
58 /* Look for an index file matching BUILD_ID. If found, return the contents
59 as an array_view and store the underlying resources (allocated memory,
60 mapped file, etc) in RESOURCE. The returned array_view is valid as long
61 as RESOURCE is not destroyed.
63 If no matching index file is found, return an empty array view. */
64 gdb::array_view<const gdb_byte>
65 lookup_gdb_index (const bfd_build_id *build_id,
66 std::unique_ptr<index_cache_resource> *resource);
68 /* Return the number of cache hits. */
69 unsigned int n_hits () const
72 /* Record a cache hit. */
79 /* Return the number of cache misses. */
80 unsigned int n_misses () const
81 { return m_n_misses; }
83 /* Record a cache miss. */
92 /* Compute the absolute filename where the index of the objfile with build
93 id BUILD_ID will be stored. SUFFIX is appended at the end of the
95 std::string make_index_filename (const bfd_build_id *build_id,
96 const char *suffix) const;
98 /* The base directory where we are storing and looking up index files. */
101 /* Whether the cache is enabled. */
102 bool m_enabled = false;
104 /* Number of cache hits and misses during this GDB session. */
105 unsigned int m_n_hits = 0;
106 unsigned int m_n_misses = 0;
109 /* The global instance of the index cache. */
110 extern index_cache global_index_cache;
112 #endif /* DWARF_INDEX_CACHE_H */