[PATCH 6/7] Use debug_prefixed_printf_cond_nofunc in index-cache
Joel Brobecker
brobecker@adacore.com
Wed Dec 29 04:17:46 GMT 2021
On Tue, Dec 28, 2021 at 03:49:56PM -0700, Tom Tromey wrote:
> This changes index-cache.c to use debug_prefixed_printf_cond_nofunc.
> As a side effect, logs are now written to gdb_stdlog. This is part of
> PR gdb/7233.
IIUC, the use of debug_prefixed_printf_cond_nofunc allows us to
avoid having repeat it in the message being passed?
For instance ...
>
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=7233
> ---
> gdb/dwarf2/index-cache.c | 43 ++++++++++++++++++----------------------
> 1 file changed, 19 insertions(+), 24 deletions(-)
>
> diff --git a/gdb/dwarf2/index-cache.c b/gdb/dwarf2/index-cache.c
> index 7cb0fd3d9a1..0024334d3c0 100644
> --- a/gdb/dwarf2/index-cache.c
> +++ b/gdb/dwarf2/index-cache.c
> @@ -37,6 +37,10 @@
> /* When set to true, show debug messages about the index cache. */
> static bool debug_index_cache = false;
>
> +#define cache_debug(FMT, ...) \
> + debug_prefixed_printf_cond_nofunc (debug_index_cache, "index-cache", \
> + FMT, ## __VA_ARGS__)
> +
> /* The index cache directory, used for "set/show index-cache directory". */
> static std::string index_cache_directory;
>
> @@ -59,8 +63,7 @@ index_cache::set_directory (std::string dir)
>
> m_dir = std::move (dir);
>
> - if (debug_index_cache)
> - printf_unfiltered ("index cache: now using directory %s\n", m_dir.c_str ());
> + cache_debug ("index cache: now using directory %s\n", m_dir.c_str ());
The "index cache:" prefix being used here and below now seems
redundant.
Should we remove them?
> }
>
> /* See dwarf-index-cache.h. */
> @@ -68,8 +71,7 @@ index_cache::set_directory (std::string dir)
> void
> index_cache::enable ()
> {
> - if (debug_index_cache)
> - printf_unfiltered ("index cache: enabling (%s)\n", m_dir.c_str ());
> + cache_debug ("index cache: enabling (%s)\n", m_dir.c_str ());
>
> m_enabled = true;
> }
> @@ -79,8 +81,7 @@ index_cache::enable ()
> void
> index_cache::disable ()
> {
> - if (debug_index_cache)
> - printf_unfiltered ("index cache: disabling\n");
> + cache_debug ("index cache: disabling\n");
>
> m_enabled = false;
> }
> @@ -99,9 +100,8 @@ index_cache::store (dwarf2_per_objfile *per_objfile)
> const bfd_build_id *build_id = build_id_bfd_get (obj->obfd);
> if (build_id == nullptr)
> {
> - if (debug_index_cache)
> - printf_unfiltered ("index cache: objfile %s has no build id\n",
> - objfile_name (obj));
> + cache_debug ("index cache: objfile %s has no build id\n",
> + objfile_name (obj));
> return;
> }
>
> @@ -118,9 +118,8 @@ index_cache::store (dwarf2_per_objfile *per_objfile)
>
> if (dwz_build_id == nullptr)
> {
> - if (debug_index_cache)
> - printf_unfiltered ("index cache: dwz objfile %s has no build id\n",
> - dwz->filename ());
> + cache_debug ("index cache: dwz objfile %s has no build id\n",
> + dwz->filename ());
> return;
> }
>
> @@ -144,9 +143,8 @@ index_cache::store (dwarf2_per_objfile *per_objfile)
> return;
> }
>
> - if (debug_index_cache)
> - printf_unfiltered ("index cache: writing index cache for objfile %s\n",
> - objfile_name (obj));
> + cache_debug ("index cache: writing index cache for objfile %s\n",
> + objfile_name (obj));
>
> /* Write the index itself to the directory, using the build id as the
> filename. */
> @@ -156,9 +154,8 @@ index_cache::store (dwarf2_per_objfile *per_objfile)
> }
> catch (const gdb_exception_error &except)
> {
> - if (debug_index_cache)
> - printf_unfiltered ("index cache: couldn't store index cache for objfile "
> - "%s: %s", objfile_name (obj), except.what ());
> + cache_debug ("index cache: couldn't store index cache for objfile "
> + "%s: %s", objfile_name (obj), except.what ());
> }
> }
>
> @@ -198,9 +195,8 @@ index_cache::lookup_gdb_index (const bfd_build_id *build_id,
>
> try
> {
> - if (debug_index_cache)
> - printf_unfiltered ("index cache: trying to read %s\n",
> - filename.c_str ());
> + cache_debug ("index cache: trying to read %s\n",
> + filename.c_str ());
>
> /* Try to map that file. */
> index_cache_resource_mmap *mmap_resource
> @@ -215,9 +211,8 @@ index_cache::lookup_gdb_index (const bfd_build_id *build_id,
> }
> catch (const gdb_exception_error &except)
> {
> - if (debug_index_cache)
> - printf_unfiltered ("index cache: couldn't read %s: %s\n",
> - filename.c_str (), except.what ());
> + cache_debug ("index cache: couldn't read %s: %s\n",
> + filename.c_str (), except.what ());
> }
>
> return {};
> --
> 2.31.1
>
--
Joel
More information about the Gdb-patches
mailing list