GDB (xrefs)
Loading...
Searching...
No Matches
gdb
dwarf2
index-cache.h
Go to the documentation of this file.
1
/* Caching of GDB/DWARF index files.
2
3
Copyright (C) 2018-2023 Free Software Foundation, Inc.
4
5
This file is part of GDB.
6
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.
11
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.
16
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/>. */
19
20
#ifndef DWARF_INDEX_CACHE_H
21
#define DWARF_INDEX_CACHE_H
22
23
#include "
dwarf2/index-common.h
"
24
#include "gdbsupport/array-view.h"
25
#include "
symfile.h
"
26
27
class
dwarf2_per_bfd
;
28
class
index_cache
;
29
30
/* Base of the classes used to hold the resources of the indices loaded from
31
the cache (e.g. mmapped files). */
32
33
struct
index_cache_resource
34
{
35
virtual
~index_cache_resource
() = 0;
36
};
37
38
/* Information to be captured in the main thread, and to be used by worker
39
threads during store (). */
40
41
struct
index_cache_store_context
42
{
43
friend
class
index_cache
;
44
45
index_cache_store_context
(
const
index_cache
&ic,
dwarf2_per_bfd
*per_bfd);
46
47
private
:
48
/* Captured value of enabled (). */
49
bool
m_enabled
;
50
51
/* Captured value of build id. */
52
std::string
build_id_str
;
53
54
/* Captured value of dwz build id. */
55
gdb::optional<std::string>
dwz_build_id_str
;
56
};
57
58
/* Class to manage the access to the DWARF index cache. */
59
60
class
index_cache
61
{
62
friend
struct
index_cache_store_context
;
63
public
:
64
/* Change the directory used to save/load index files. */
65
void
set_directory
(std::string dir);
66
67
/* Return true if the usage of the cache is enabled. */
68
bool
enabled
()
const
69
{
70
return
m_enabled
;
71
}
72
73
/* Enable the cache. */
74
void
enable
();
75
76
/* Disable the cache. */
77
void
disable
();
78
79
/* Store an index for the specified object file in the cache. */
80
void
store
(
dwarf2_per_bfd
*per_bfd,
81
const
index_cache_store_context
&);
82
83
/* Look for an index file matching BUILD_ID. If found, return the contents
84
as an array_view and store the underlying resources (allocated memory,
85
mapped file, etc) in RESOURCE. The returned array_view is valid as long
86
as RESOURCE is not destroyed.
87
88
If no matching index file is found, return an empty array view. */
89
gdb::array_view<const gdb_byte>
90
lookup_gdb_index
(
const
bfd_build_id *build_id,
91
std::unique_ptr<index_cache_resource> *resource);
92
93
/* Return the number of cache hits. */
94
unsigned
int
n_hits
()
const
95
{
return
m_n_hits
; }
96
97
/* Record a cache hit. */
98
void
hit
()
99
{
100
if
(
enabled
())
101
m_n_hits
++;
102
}
103
104
/* Return the number of cache misses. */
105
unsigned
int
n_misses
()
const
106
{
return
m_n_misses
; }
107
108
/* Record a cache miss. */
109
void
miss
()
110
{
111
if
(
enabled
())
112
m_n_misses
++;
113
}
114
115
private
:
116
117
/* Compute the absolute filename where the index of the objfile with build
118
id BUILD_ID will be stored. SUFFIX is appended at the end of the
119
filename. */
120
std::string
make_index_filename
(
const
bfd_build_id *build_id,
121
const
char
*suffix)
const
;
122
123
/* The base directory where we are storing and looking up index files. */
124
std::string
m_dir
;
125
126
/* Whether the cache is enabled. */
127
bool
m_enabled
=
false
;
128
129
/* Number of cache hits and misses during this GDB session. */
130
unsigned
int
m_n_hits
= 0;
131
unsigned
int
m_n_misses
= 0;
132
};
133
134
/* The global instance of the index cache. */
135
extern
index_cache
global_index_cache
;
136
137
#endif
/* DWARF_INDEX_CACHE_H */
index_cache
Definition
index-cache.h:61
index_cache::n_hits
unsigned int n_hits() const
Definition
index-cache.h:94
index_cache::n_misses
unsigned int n_misses() const
Definition
index-cache.h:105
index_cache::lookup_gdb_index
gdb::array_view< const gdb_byte > lookup_gdb_index(const bfd_build_id *build_id, std::unique_ptr< index_cache_resource > *resource)
Definition
index-cache.c:248
index_cache::disable
void disable()
Definition
index-cache.c:82
index_cache::m_enabled
bool m_enabled
Definition
index-cache.h:127
index_cache::store
void store(dwarf2_per_bfd *per_bfd, const index_cache_store_context &)
Definition
index-cache.c:156
index_cache::make_index_filename
std::string make_index_filename(const bfd_build_id *build_id, const char *suffix) const
Definition
index-cache.c:259
index_cache::m_dir
std::string m_dir
Definition
index-cache.h:124
index_cache::enabled
bool enabled() const
Definition
index-cache.h:68
index_cache::miss
void miss()
Definition
index-cache.h:109
index_cache::hit
void hit()
Definition
index-cache.h:98
index_cache::m_n_misses
unsigned int m_n_misses
Definition
index-cache.h:131
index_cache::enable
void enable()
Definition
index-cache.c:72
index_cache::set_directory
void set_directory(std::string dir)
Definition
index-cache.c:60
index_cache::m_n_hits
unsigned int m_n_hits
Definition
index-cache.h:130
global_index_cache
index_cache global_index_cache
Definition
index-cache.c:48
index-common.h
dwarf2_per_bfd
Definition
read.h:421
index_cache_resource
Definition
index-cache.h:34
index_cache_resource::~index_cache_resource
virtual ~index_cache_resource()=0
index_cache_store_context
Definition
index-cache.h:42
index_cache_store_context::m_enabled
bool m_enabled
Definition
index-cache.h:49
index_cache_store_context::index_cache_store_context
index_cache_store_context(const index_cache &ic, dwarf2_per_bfd *per_bfd)
Definition
index-cache.c:91
index_cache_store_context::build_id_str
std::string build_id_str
Definition
index-cache.h:52
index_cache_store_context::dwz_build_id_str
gdb::optional< std::string > dwz_build_id_str
Definition
index-cache.h:55
symfile.h
Generated by
1.10.0