27#include "gdbsupport/scoped_mmap.h"
28#include "gdbsupport/pathstuff.h"
33#include "gdbsupport/selftest.h"
40#define index_cache_debug(FMT, ...) \
41 debug_prefixed_printf_cond_nofunc (debug_index_cache, "index-cache", \
62 gdb_assert (!dir.empty ());
64 m_dir = std::move (dir);
93 : m_enabled (ic.enabled ())
100 if (build_id ==
nullptr)
103 bfd_get_filename (per_bfd->
obfd));
116 if (dwz_build_id ==
nullptr)
127 if (ic.
m_dir.empty ())
129 warning (_(
"The index cache directory name is empty, skipping store."));
137 if (!mkdir_recursive (ic.
m_dir.c_str ()))
139 warning (_(
"index cache: could not make cache directory: %s"),
140 safe_strerror (errno));
145 catch (
const gdb_exception_error &except)
148 bfd_get_filename (per_bfd->
obfd), except.what ());
169 bfd_get_filename (per_bfd->
obfd));
177 catch (
const gdb_exception_error &except)
180 bfd_get_filename (per_bfd->
obfd), except.what ());
192 index_cache_resource_mmap (
const char *filename)
193 :
mapping (mmap_file (filename))
201gdb::array_view<const gdb_byte>
203 std::unique_ptr<index_cache_resource> *resource)
210 warning (_(
"The index cache directory name is empty, skipping cache "
224 index_cache_resource_mmap *mmap_resource
225 =
new index_cache_resource_mmap (filename.c_str ());
228 resource->reset (mmap_resource);
230 return gdb::array_view<const gdb_byte>
231 ((
const gdb_byte *) mmap_resource->mapping.get (),
232 mmap_resource->mapping.size ());
234 catch (
const gdb_exception_error &except)
237 filename.c_str (), except.what ());
247gdb::array_view<const gdb_byte>
249 std::unique_ptr<index_cache_resource> *resource)
260 const char *suffix)
const
264 return m_dir + SLASH_STRING + build_id_str + suffix;
284 (_(
"The index cache is currently %s.\n"),
332 const char *indent =
"";
342 gdb_printf (_(
"%s Cache hits (this session): %u\n"),
344 gdb_printf (_(
"%sCache misses (this session): %u\n"),
353 std::string cache_dir = get_standard_cache_dir ();
354 if (!cache_dir.empty ())
360 warning (_(
"Couldn't determine a path for the index cache directory."));
364 _(
"Set index-cache options."),
376 _(
"Enable the index cache."),
377 _(
"Show whether the index cache is enabled."),
378 _(
"When on, enable the use of the index cache."),
389 deprecate_cmd (set_index_cache_on_cmd,
"set index-cache enabled on");
396 deprecate_cmd (set_index_cache_off_cmd,
"set index-cache enabled off");
401 _(
"Set the directory of the index cache."),
402 _(
"Show the directory of the index cache."),
410 _(
"Show some stats about the index cache."),
416 _(
"Set display of index-cache debug messages."),
417 _(
"Show display of index-cache debug messages."),
419When non-zero, debugging output for the index cache is displayed."),
const struct bfd_build_id * build_id_bfd_get(bfd *abfd)
static std::string build_id_to_string(const bfd_build_id *build_id)
unsigned int n_hits() const
unsigned int n_misses() const
gdb::array_view< const gdb_byte > lookup_gdb_index(const bfd_build_id *build_id, std::unique_ptr< index_cache_resource > *resource)
void store(dwarf2_per_bfd *per_bfd, const index_cache_store_context &)
std::string make_index_filename(const bfd_build_id *build_id, const char *suffix) const
void set_directory(std::string dir)
struct cmd_list_element * showlist
struct cmd_list_element * setlist
struct cmd_list_element * showdebuglist
struct cmd_list_element * setdebuglist
set_show_commands add_setshow_filename_cmd(const char *name, enum command_class theclass, std::string *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
struct cmd_list_element * add_alias_cmd(const char *name, cmd_list_element *target, enum command_class theclass, int abbrev_flag, struct cmd_list_element **list)
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **list)
struct cmd_list_element * deprecate_cmd(struct cmd_list_element *cmd, const char *replacement)
struct cmd_list_element * add_prefix_cmd(const char *name, enum command_class theclass, cmd_simple_func_ftype *fun, const char *doc, struct cmd_list_element **subcommands, int allow_unknown, struct cmd_list_element **list)
set_show_commands add_setshow_boolean_cmd(const char *name, enum command_class theclass, bool *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
struct cmd_list_element * add_basic_prefix_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **subcommands, int allow_unknown, struct cmd_list_element **list)
void cmd_show_list(struct cmd_list_element *list, int from_tty)
struct dwz_file * dwarf2_get_dwz_file(dwarf2_per_bfd *per_bfd, bool require)
static cmd_list_element * show_index_cache_prefix_list
static void show_index_cache_command(const char *arg, int from_tty)
static bool debug_index_cache
#define index_cache_debug(FMT,...)
static cmd_list_element * set_index_cache_prefix_list
static void set_index_cache_directory_command(const char *arg, int from_tty, cmd_list_element *element)
static void show_index_cache_stats_command(const char *arg, int from_tty)
static std::string index_cache_directory
static bool in_show_index_cache_command
static void set_index_cache_enabled_command(bool value)
void _initialize_index_cache()
static void show_index_cache_enabled_command(ui_file *stream, int from_tty, cmd_list_element *cmd, const char *value)
static bool get_index_cache_enabled_command()
index_cache global_index_cache
void write_dwarf_index(dwarf2_per_bfd *per_bfd, const char *dir, const char *basename, const char *dwz_basename, dw_index_kind index_kind)
const char * filename() const
virtual ~index_cache_resource()=0
index_cache_store_context(const index_cache &ic, dwarf2_per_bfd *per_bfd)
gdb::optional< std::string > dwz_build_id_str
void gdb_printf(struct ui_file *stream, const char *format,...)