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);
105 if (build_id ==
nullptr)
115 gdb::optional<std::string> dwz_build_id_str;
117 const char *dwz_build_id_ptr = NULL;
123 if (dwz_build_id ==
nullptr)
131 dwz_build_id_ptr = dwz_build_id_str->c_str ();
136 warning (_(
"The index cache directory name is empty, skipping store."));
143 if (!mkdir_recursive (
m_dir.c_str ()))
145 warning (_(
"index cache: could not make cache directory: %s"),
146 safe_strerror (errno));
156 build_id_str.c_str (), dwz_build_id_ptr,
157 dw_index_kind::GDB_INDEX);
159 catch (
const gdb_exception_error &except)
174 index_cache_resource_mmap (
const char *filename)
175 :
mapping (mmap_file (filename))
183gdb::array_view<const gdb_byte>
185 std::unique_ptr<index_cache_resource> *resource)
192 warning (_(
"The index cache directory name is empty, skipping cache "
206 index_cache_resource_mmap *mmap_resource
207 =
new index_cache_resource_mmap (filename.c_str ());
210 resource->reset (mmap_resource);
212 return gdb::array_view<const gdb_byte>
213 ((
const gdb_byte *) mmap_resource->mapping.get (),
214 mmap_resource->mapping.size ());
216 catch (
const gdb_exception_error &except)
219 filename.c_str (),
except.what ());
229gdb::array_view<const gdb_byte>
231 std::unique_ptr<index_cache_resource> *resource)
242 const char *suffix)
const
246 return m_dir + SLASH_STRING + build_id_str + suffix;
266 (_(
"The index cache is currently %s.\n"),
314 const char *indent =
"";
324 gdb_printf (_(
"%s Cache hits (this session): %u\n"),
326 gdb_printf (_(
"%sCache misses (this session): %u\n"),
335 std::string cache_dir = get_standard_cache_dir ();
336 if (!cache_dir.empty ())
342 warning (_(
"Couldn't determine a path for the index cache directory."));
346 _(
"Set index-cache options."),
358 _(
"Enable the index cache."),
359 _(
"Show whether the index cache is enabled."),
360 _(
"When on, enable the use of the index cache."),
371 deprecate_cmd (set_index_cache_on_cmd,
"set index-cache enabled on");
378 deprecate_cmd (set_index_cache_off_cmd,
"set index-cache enabled off");
383 _(
"Set the directory of the index cache."),
384 _(
"Show the directory of the index cache."),
392 _(
"Show some stats about the index cache."),
398 _(
"Set display of index-cache debug messages."),
399 _(
"Show display of index-cache debug messages."),
401When 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)
std::string make_index_filename(const bfd_build_id *build_id, const char *suffix) const
void store(dwarf2_per_objfile *per_objfile)
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_objfile *per_objfile, const char *dir, const char *basename, const char *dwz_basename, dw_index_kind index_kind)
const char * objfile_name(const struct objfile *objfile)
struct dwarf2_per_bfd * per_bfd
const char * filename() const
virtual ~index_cache_resource()=0
void gdb_printf(struct ui_file *stream, const char *format,...)